Query on online screen



Software AG's platform-independent programming language with full support for open-source and Internet applications

Query on online screen

Postby diptisaini » Tue Mar 29, 2011 3:26 pm

Hi,

The below is an online screen :-
CLASS ON
SHORT NAME: ..................
SEDOL: STOCK SHORT DESC: ...........................
CHASE: LONG NAME: ...................................
DOMES: .......... STOCK LONG DESC: ........................................
IND : 0. LEGAL: ...................................
AGENT ASSET REF: ............ NAME ...................................
PREV ID: ASSET TYPE: ..

In this screen i want to add the validation for below fileds:-
1) SHORT NAME (A18)
2)LONG NAME(A40)
3)LEGAL (A10)

The validation on above fileds are as follows:-
1)These fileds should don't allow any specail character other then (,),-.
2)If user is entering any special character then a error message will be display on the screen.
3)The cursor should be placed on the error filed.


Could anyone plz help me on how to do this?
diptisaini
 
Posts: 90
Joined: Sun Mar 14, 2010 5:12 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Query on online screen

Postby RGZbrog » Tue Mar 29, 2011 11:58 pm

Natural doesn't handle your situation automatically. The MASK clause won't help you because Natural would consider your definition of "special character" to be non-standard. So you have to define each invalid characters and test the input fields byte by byte. But you want to avoid loop constructs that would burn up CPU.

I can think of two relatively painless ways to accomplish this. In one, you define every invalid character: in the other, you define all valid characters. Since you'll be checking multiple fields, my examples wrap the verifications in subroutines.

INVALID CHARACTERS METHOD
Code a SCAN clause for each character that is considered invalid. Here's a code snippet.
IF  #TMP = SCAN '~'             /* list of invalid characters
      OR = SCAN '`'
      OR = SCAN '!'
      OR = SCAN '@'
      OR = SCAN '#'
      OR = SCAN '$'
      /* etc ...
  THEN

VALID CHARACTERS METHOD
Translate all valid characters to blanks. If any non-blank character remains, it indicates an error.
1 #TRANSLATE (A78)                     /* list of valid characters
      INIT <'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z '
           -'0 1 2 3 4 5 6 7 8 9 '
           -'( - ) '
           >
                   1 REDEFINE #TRANSLATE
  2 #TR (A2/39)
...
EXAMINE #TMP TRANSLATE USING #TR (*)   /* remove valid characters
IF  #TMP <> ' '                        /* anything left?
  THEN

============================
And here's a working program you can use to help you decide which method to use.
DEFINE DATA LOCAL
1 #SHORT-NAME (A18)
1 #SHORT-DESC (A27)
1 #TRANSLATE (A78)                     /* list of valid characters
      INIT <'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z '
           -'0 1 2 3 4 5 6 7 8 9 '
           -'( - ) '
           >
                   1 REDEFINE #TRANSLATE
  2 #TR (A2/39)
1 #TMP (A27)
1 #INV-ERR (L)
1 #VAL-ERR (L)
END-DEFINE
REPEAT
  INPUT 'Name:' #SHORT-NAME (AD=MDLT)
     // 'Desc:' #SHORT-DESC (AD=MDLT)
  /*
  ASSIGN #TMP = #SHORT-NAME
  PERFORM INVALID-CHARS
  IF  #INV-ERR
    THEN
      REINPUT 'Specific invalid characters'
              MARK *#SHORT-NAME
  END-IF
  ASSIGN #TMP = #SHORT-NAME
  PERFORM VALID-CHARS
  IF  #VAL-ERR
    THEN
      REINPUT 'Invalid special characters'
              MARK *#SHORT-NAME
  END-IF
  /*
  ASSIGN #TMP = #SHORT-DESC
  PERFORM INVALID-CHARS
  IF  #INV-ERR
    THEN
      REINPUT 'Specific invalid characters'
              MARK *#SHORT-DESC
  END-IF
  ASSIGN #TMP = #SHORT-DESC
  PERFORM VALID-CHARS
  IF  #VAL-ERR
    THEN
      REINPUT 'Invalid special characters'
              MARK *#SHORT-DESC
  END-IF
END-REPEAT
*
DEFINE SUBROUTINE INVALID-CHARS
RESET #INV-ERR
IF  #TMP = SCAN '~'             /* list of invalid characters
      OR = SCAN '`'
      OR = SCAN '!'
      OR = SCAN '@'
      OR = SCAN '#'
      OR = SCAN '$'
      /* etc ...
  THEN
    ASSIGN #INV-ERR = TRUE
END-IF
END-SUBROUTINE
*
DEFINE SUBROUTINE VALID-CHARS
RESET #VAL-ERR
EXAMINE #TMP TRANSLATE USING #TR (*)   /* remove valid characters
IF  #TMP <> ' '                        /* anything left?
  THEN
    ASSIGN #VAL-ERR = TRUE
END-IF
END-SUBROUTINE
END

============================
Both techniques could be implemented as processing rules in an external map, if your shop standards allowed processing rules.
User avatar
RGZbrog
 
Posts: 101
Joined: Mon Nov 23, 2009 1:34 pm
Location: California, USA
Has thanked: 0 time
Been thanked: 0 time

Re: Query on online screen

Postby diptisaini » Tue Apr 05, 2011 2:24 pm

Hi,

I am having around 20 INVALID Characters. So i have to use SCAN statement for all 20 invalid characters and that is not an efficient way of coding.
Could you please tell me any alternative way or Can i use SCAN with array?
diptisaini
 
Posts: 90
Joined: Sun Mar 14, 2010 5:12 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Query on online screen

Postby RGZbrog » Tue Apr 05, 2011 11:19 pm

Can i use SCAN with array?
No, but I have often wished that Natural syntax allowed this.

I have to use SCAN statement for all 20 invalid characters and that is not an efficient way of coding.
Performance is relative. SCAN is expensive compared to other clauses of the IF statement, but it can be much less expensive than EXAMINE, which can be much less expensive than a FOR loop.

Could you please tell me any alternative way ...
You can use an EXAMINE for an array of values.
DEFINE DATA LOCAL
1 #TMP (A10)   INIT <'~CEGI@MJQS'>
1 #BAD (A1/20) INIT <'~', '`', '!', '@', '#'>
1 #N (I4)
END-DEFINE
EXAMINE #TMP FOR #BAD (*) GIVING NUMBER #N
IF  #N <> 0
  THEN
    WRITE 'bad characters'
  ELSE
    WRITE 'good characters'
END-IF
END
I don't have access to a mainframe, so I'm unable to run benchmarks, but I expect the SCAN method to execute faster than any other.

In the example above, the first invalid character is found in the first position of the string. Regardless of that, EXAMINE will search the entire string for all 20 invalid characters. But with IF/SCAN, the first SCAN clause would be satisfied immediately and the remaining 19 SCAN clauses would be ignored. So, if you can write the SCAN clauses in "highest frequency first" order, then the IF/SCAN could be much faster, but would not be any slower, than EXAMINE.
User avatar
RGZbrog
 
Posts: 101
Joined: Mon Nov 23, 2009 1:34 pm
Location: California, USA
Has thanked: 0 time
Been thanked: 0 time

Re: Query on online screen

Postby diptisaini » Wed Apr 06, 2011 11:47 am

Hi,
I was trying to execute the above program but i am getting below error:-

NAT0293 Index range entry specified where not allowed.

The error is coming on below line :-
E 0060 EXAMINE #TMP FOR #BAD(*) GIVING NUMBER #N

So could you please tell me how to resolve this error ?
diptisaini
 
Posts: 90
Joined: Sun Mar 14, 2010 5:12 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Query on online screen

Postby RGZbrog » Wed Apr 06, 2011 10:54 pm

I'll presume that you used copy/paste to avoid introducing errors into my sample program. In that case, what version of Natural are you running? This is displayed on the (optional) splash screen as you logon, or you can try this:
WRITE '=' *NATVERS .


Does it work for a single occurrence? Or an explicit range?
EXAMINE #TMP FOR #BAD (1) GIVING NUMBER #N
EXAMINE #TMP FOR #BAD (1:20) GIVING NUMBER #N
User avatar
RGZbrog
 
Posts: 101
Joined: Mon Nov 23, 2009 1:34 pm
Location: California, USA
Has thanked: 0 time
Been thanked: 0 time

Re: Query on online screen

Postby diptisaini » Thu Apr 07, 2011 8:08 am

Hi,
Its working fine for single occurence. But if i am giving below examine statement :-
EXAMINE #TMP FOR #BAD (1:20) GIVING NUMBER #N
Then i am getting same error I.e NAT0293 Index range entry specified where not allowed.
diptisaini
 
Posts: 90
Joined: Sun Mar 14, 2010 5:12 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Query on online screen

Postby RGZbrog » Thu Apr 07, 2011 10:23 am

As a last resort, I went to the manual: http://documentation.softwareag.com/natural/nat427mf/sm/examine.htm#operand4_examine.

Sorry for misleading you, Diptisaini. Although EXAMINE for an array is valid syntax for Natural for Windows (Natural 6.3, where I do all my initial coding and testing), it is not acceptable on the mainframe (Natural 4.2). So you must choose between the first two alternatives - a long IF statement with 20 SCAN clauses, or an EXAMINE TRANSLATE statement.
User avatar
RGZbrog
 
Posts: 101
Joined: Mon Nov 23, 2009 1:34 pm
Location: California, USA
Has thanked: 0 time
Been thanked: 0 time

Re: Query on online screen

Postby diptisaini » Fri Apr 08, 2011 5:04 pm

Hi,

I am not able to understand why to use examine translate as its use for character translation.
diptisaini
 
Posts: 90
Joined: Sun Mar 14, 2010 5:12 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Query on online screen

Postby RGZbrog » Sat Apr 09, 2011 12:21 am

Review the sample program again. The user's input is moved to a temporary field. All the "valid" characters in the temporary field are translated to blanks. If the result is a blank field, then the user's input must have contained only valid characters. If the result is non-blank, then the user's input must have contained invalid characters. Your requirement to check for invalid characters is satisfied in three statements: MOVE, EXAMINE TRANSLATE, and IF.
User avatar
RGZbrog
 
Posts: 101
Joined: Mon Nov 23, 2009 1:34 pm
Location: California, USA
Has thanked: 0 time
Been thanked: 0 time

Next

Return to Natural

 


  • Related topics
    Replies
    Views
    Last post