%CHECKR Built-In Functions in rpgle

%CHECKR function is used to find the position for non-occurrence of a character in a string from Right.

The format of this function is %CHECK(comparator : base string {: Start position})

This function will return the first position of the base string that contains a characters that is not available in the comparator.

It is similar to %CHECK, only difference is that it is performed in Reverse direction i.e. from right of string.

How %CHECKR function works -

First parameter(comparator) is used to find a match in base string from right side. First parameter(comparator) can be a combination of characters e.g. "abcd". Each characters of comparater i.e. a,b,c & d is checked in the base string starting from last position(Position 1 from right).

If we want to start the search from some position other than last position, then we can mention the 'Start position' in 3rd parameter. By default 3rd parameter will be 1 i.e. search starts from position-1 from right.

When search starts, 1st position of the base sring is searched. If any of the comparaters(a,b,c,d) finds a match at 1st position then it continues search at 2nd position. Again 3rd postion if there is match at 2nd position, and so on it continues the search..

While searching, when the comparaters(a,b,c,d) finds a position where there is no match then that position is returned as a search result. Hence, %CHECK function is used to find the position for non-occurrence of a character in source string from right.


Example –%CHECKR built-in function in rpgle



 


 Columns . . . :    6  80                                              AMIT/QRPGSRC
 SEU==>                                                                     TESTRPG
 FMT *   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
        *************** Beginning of data *****************************************
0001.00                                                                                 
0002.00      D name            S             30A                                        
0003.00      D pos             S              5U 0                                      
0004.00                                                                                 
0005.00       /FREE                                                                     
0006.00          name = 'Amit Jaiswal            ';                                     
0007.00          pos = %checkr('  ' : name);                                            
0008.00          name = %subst ( name:1:pos);                                           
0009.00          DSPLY  name;                                                           
0010.00       /END-FREE                                                                 
0011.00                                                                                 
0012.00                                                                                 
0013.00       /FREE                                                                     
0014.00          name = 'Amit Jaiswal            ';                                     
0015.00          pos = %checkr(' wlais' : name);                                        
0016.00          name = %subst ( name: pos);                                            
0017.00          DSPLY  name;                                                           
0018.00       /END-FREE                                                                 
0019.00      C                                                                          
0020.00                                                                                 
0021.00       /FREE                                                                     
0022.00          name = 'Amit Jaiswal            ';                                     
0023.00          pos = %checkr(' timJswal' : name);                                     
0024.00          name = %subst ( name: pos:4);                                          
0025.00          DSPLY  name;                                                           
0026.00       /END-FREE                                                                 
0027.00      C                   SETON                                        LR        

Output

DSPLY  Amit Jaiswal    
DSPLY  Jaiswal         
DSPLY  Amit  

 

 

In above example, we have used %SUBST funtion, to know about %SUBST click here .











User Comments:



Subscribe

.  


Copyright © www.go4as400.com, 2013-2023. Copyright notice   Terms of services   Privacy policy