RPGLE %check() %scan() %checkr() BIFs

List of RPGLE String BIFs

%CHECK()


compare-value : data-to-search { : start-position }
First position in the searched-data that contains a character not in the list of the characters in the compare value.

%CHECKR()

compare-value : data-to-search { : start-position }
Last position in the searched-data that contains a character not in the list of the characters in the compare value. (Search begins with the right-most character and proceeds to the left. Basically does the same thing as %CHECK() but goes from right to left in the string data.

%SCAN()


search argument : string to be searched {:start position}
First position of search argument in string or zero, if not found.

There are two very big differences between these two BIFs.
  • The first is that with %CHECK, the compare string is treated as a list of individual characters, whereas %SCAN operates on it as a single string. 
  • The second is that %SCAN tries to locate an occurrence of the characters in the compare string, whereas %CHECK tries to identify any characters that are not present in the compare string.
Remember: The operations are case-sensitive.

Example for %SCAN()

D $source         S            100A                   
D $pos            S              5U 0                 
                                                      
 /FREE                                                
                                                      
   $source = 'RPGLE is a Popular Programming ' +      
             'language of the IBM Power i platform';  
                                                      
   $pos = %scan ('IBM' : $source);                    
   dsply $pos; //DSPLY     48                         
                                                      
   $pos = %scan ('IBM' : $source :15);                
   dsply $pos; //DSPLY     48                         
                                                      
   $pos = %scan ('Po' : $source);                     
   dsply $pos; //DSPLY     12                         
                                                      
   $pos = %scan ('Po' : $source : 20);                
   dsply $pos; //DSPLY     52                         
                                                      
    *inlr = *on;                                      
 /END-FREE                                            

Example for %CHECK() and %CHECKR()

D $source         S             20A                     
D $pos            S              5U 0                   
                                                        
 /FREE                                                  
                                                        
   $source = 'AABC1ABD2AB3A';                           
                                                        
   $pos = %check ('ABCD' : %trim($source));             
   dsply $pos; //DSPLY      5                           
                                                        
   $pos = %check ('ABCD' : %trim($source) :6);          
   dsply $pos; //DSPLY      9                           
                                                        
   $pos = %checkr ('ABCD' : %trim($source));            
   dsply $pos; //DSPLY     12                           
                                                        
   $pos = %checkr ('ABCD' : %trim($source) : 11);       
   dsply $pos; //DSPLY      9                           
                                                        
    *inlr = *on;                                        
 /END-FREE           

No comments:

Post a Comment

NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.