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?
Query on online screen
-
- Posts: 90
- Joined: Sun Mar 14, 2010 5:12 pm
- Skillset: Natural,Adabas,jcl
- Referer: friend
- RGZbrog
- Posts: 101
- Joined: Mon Nov 23, 2009 1:34 pm
- Skillset: Natural, Adabas, Predict, Natural Security, Construct, EntireX, SPoD, NaturalONE
- Referer: SAG Developer Forum
- Location: California, USA
- Contact:
Re: Query on online screen
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.
VALID CHARACTERS METHOD
Translate all valid characters to blanks. If any non-blank character remains, it indicates an error.
============================
And here's a working program you can use to help you decide which method to use.
============================
Both techniques could be implemented as processing rules in an external map, if your shop standards allowed processing rules.
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.
Code: Select all
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.
Code: Select all
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.
Code: Select all
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.
-
- Posts: 90
- Joined: Sun Mar 14, 2010 5:12 pm
- Skillset: Natural,Adabas,jcl
- Referer: friend
Re: Query on online screen
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?
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?
- RGZbrog
- Posts: 101
- Joined: Mon Nov 23, 2009 1:34 pm
- Skillset: Natural, Adabas, Predict, Natural Security, Construct, EntireX, SPoD, NaturalONE
- Referer: SAG Developer Forum
- Location: California, USA
- Contact:
Re: Query on online screen
No, but I have often wished that Natural syntax allowed this.Can i use SCAN with array?
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.I have to use SCAN statement for all 20 invalid characters and that is not an efficient way of coding.
You can use an EXAMINE for an array of values.Could you please tell me any alternative way ...
Code: Select all
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
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.
-
- Posts: 90
- Joined: Sun Mar 14, 2010 5:12 pm
- Skillset: Natural,Adabas,jcl
- Referer: friend
Re: Query on online screen
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 ?
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 ?
- RGZbrog
- Posts: 101
- Joined: Mon Nov 23, 2009 1:34 pm
- Skillset: Natural, Adabas, Predict, Natural Security, Construct, EntireX, SPoD, NaturalONE
- Referer: SAG Developer Forum
- Location: California, USA
- Contact:
Re: Query on online screen
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:
Does it work for a single occurrence? Or an explicit range?
Code: Select all
WRITE '=' *NATVERS .
Does it work for a single occurrence? Or an explicit range?
Code: Select all
EXAMINE #TMP FOR #BAD (1) GIVING NUMBER #N
Code: Select all
EXAMINE #TMP FOR #BAD (1:20) GIVING NUMBER #N
-
- Posts: 90
- Joined: Sun Mar 14, 2010 5:12 pm
- Skillset: Natural,Adabas,jcl
- Referer: friend
Re: Query on online screen
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.
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.
- RGZbrog
- Posts: 101
- Joined: Mon Nov 23, 2009 1:34 pm
- Skillset: Natural, Adabas, Predict, Natural Security, Construct, EntireX, SPoD, NaturalONE
- Referer: SAG Developer Forum
- Location: California, USA
- Contact:
Re: Query on online screen
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.
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.
-
- Posts: 90
- Joined: Sun Mar 14, 2010 5:12 pm
- Skillset: Natural,Adabas,jcl
- Referer: friend
Re: Query on online screen
Hi,
I am not able to understand why to use examine translate as its use for character translation.
I am not able to understand why to use examine translate as its use for character translation.
- RGZbrog
- Posts: 101
- Joined: Mon Nov 23, 2009 1:34 pm
- Skillset: Natural, Adabas, Predict, Natural Security, Construct, EntireX, SPoD, NaturalONE
- Referer: SAG Developer Forum
- Location: California, USA
- Contact:
Re: Query on online screen
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.
-
- Similar Topics
- Replies
- Views
- Last post
-
- 7
- 11790
-
by AusZosGuy
View the latest post
Fri Sep 10, 2021 6:40 pm
-
- 0
- 2574
-
by JIMDOOEY
View the latest post
Tue Mar 01, 2022 8:48 am
-
- 1
- 2502
-
by enrico-sorichetti
View the latest post
Fri Apr 02, 2021 6:56 pm