Reputation: 55
I visited many sites but could not get any satisfactory answer. Please, help me to understand this one. I tried to make a program but could not understand. I tried:
String = 'AABC1ABD2AB3A';
Pos = %check ('ABCD' : %trim(String));
dsply pos;
Upvotes: 0
Views: 4480
Reputation: 2163
It's not clear what you mean by I tried to make a program but could not understand.
You don't say what is wrong with the example code, so we can't help much. The code that you show looks fine, although it doesn't show the definitions for String
and for pos
, nor does it show how the program will end.
Here is a more complete example:
D string S 15
D pos1 S 10 0 inz( 0 )
D pos2 S 10 0 inz( 0 )
/free
String = 'AABC1ABD2AB3A' ;
// ^ ^
// The above characters will trigger mismatches for
// %CHECK() and %CHECKR.
Pos1 = %check ( 'ABCD' : %trim( String )) ;
Pos2 = %checkr( 'ABCD' : %trim( String )) ;
// Will display the value "1 3"
dsply ( %subst( %trim(String): pos1: 1 ) + ' ' +
%subst( %trim(String): pos2: 1 ) );
*inlr = *on ;
return ;
/end-free
The value in String
is checked first from the left with %CHECK() and then from the right with %CHECKR(). The value is trimmed with %TRIM() to avoid getting hits on any leading or trailing blanks. Then the tests look for any characters that don't match the supplied test characters ABCD
. The program tries to make sure that String
only contains the test characters, and it marks the positions of the first characters that fail the tests.
The indexes of the failing characters are stored in Pos1
and Pos2
. (If all characters pass the checks, a zero will be returned.)
The DSPLY op-code will output the first characters that don't match. It uses the index values to pull single-character substrings for the failing characters. It shows different characters for %CHECK() and %CHECKR() because they start at different ends of the String
.
Upvotes: 1
Reputation: 23783
%check() parses left to right, %checkr() parses right to left.
Given the example, %check() will return 5 and %checkr() will return 12.
Upvotes: 2