%CHECK Built-In Functions in rpgle

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

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.

How %CHECK function works -

First parameter(comparator) is used to find a match in base string. 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 position 1.

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

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.


Example –%check 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 = %check('  ' : name);                                             
0008.00          name = %subst ( name: pos :5);                                         
0009.00          DSPLY  name;                                                           
0010.00       /END-FREE                                                                 
0011.00                                                                                 
0012.00                                                                                 
0013.00       /FREE                                                                     
0014.00          name = '       Amit Jaiswal';                                          
0015.00          pos = %check(' Atim' : name);                                          
0016.00          name = %subst ( name: pos);                                            
0017.00          DSPLY  name;                                                           
0018.00       /END-FREE                                                                 
0019.00                                                                                 
0020.00                                                                                 
0021.00       /FREE                                                                     
0022.00          name = 'Amit Jaiswal';                                                 
0023.00          pos = %check('Jtim' : name:6);                                         
0024.00          name = %subst ( name: pos);                                            
0025.00          DSPLY  name;                                                           
0026.00       /END-FREE                                                                 
0027.00                                                                                 
0028.00                                                                                 
0029.00       /FREE                                                                     
0030.00          name = '       Amit Jaiswal';                                          
0031.00          pos = %check(' AtimJsa' : name);                                       
0032.00          name = %subst ( name: pos);                                            
0033.00          DSPLY  name;                                                           
0034.00       /END-FREE                                                                 
0035.00      C                   SETON                                        LR        


Output

DSPLY  Amit              
DSPLY  Jaiswal           
DSPLY  wal               

 

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