130 pts.
can anyone explain me when to use CHECK and SCAN and differentiate between them? Please provide examples too...thanks

Answer Wiki

Thanks. We'll let you know when a new response is added.

Check confirms that every character in the factor two string is in the list in factor 1
Example ‘ABCDEF’ Check TestString
If testString contained ‘BBB’ or ‘BAC’ it would pass– every character are in the factor 1 val.
If testString contained ‘A123’ or ‘Fabcdef’ it would fail and return the position 2 – where the first unacceptable character was found.

Scan looks for an exact match’
Example ‘ABCDEF’ Scan TestString

If testString contained ‘BBB’ or ‘BAC’ it would fail
If testString contained ‘123’ or ‘abcdef’ it would fail.
If testString contained ‘123ABCDEF456’ it would pass and return the position 4 (where it’s found)

Discuss This Question: 3  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • TRam
    Hi Philip or anybody thanks for your answer. But still i am confused by the example you have given and Factor1 and Factor2 and result. Can you please elaborate and excplain it clearly with a better example... regards Ram
    130 pointsBadges:
  • philpl1jb
    Check might be used to test a text string to determine if it's a valid UPC number - (only digits) ValidSTR = '1234567890' ValidSTR Check UPCSTR BadPos if BadPos > 0 Exsr BadUPCSTR Endif Here the string UPCSTR is tested for any value other than the 10 digits If UPCSTR = '92AB569ZZ999' then BadPos would contain the value 3 - the first position containing the character 'A' because that character wasn't in the ValidSTR ' Newer function that does the same thing BadPos = %CHECK( ValidSTR : UPCSTR) ---------------------------------------------------------------------- Scan would be used in a text search situation like partial name SearchStr = 'BOB' SearchStr SCAN FullNameStr If %found Exsr AddRecSFL Endif Found values would be 'BOB BLAKE', 'JIM ROBOBD', 'SUE BOBBY BOOP' Not Found values would be 'Bob Blake', 'PHIL GORILLA', 'MAX SMITH' Alternative format PosFnd = %SCAN( SearchStr : FullNameStr) If PosFnd > 0 ... or If %SCAN( SearchStr : FullNameStr) > 0
    54,090 pointsBadges:
  • anandx
    If one wants to find out whether a user, 'userX', is one amongst a group, 'group1', of users, or 'CUBA' is part of 'North America', or a currency code 'CUX' belongs to a family of major currency code...,and such, then use %SCAN(). SCAN is akin to 'where X in' clause of SQL, a table/array/database search.
    Let's say a string in question can have all kinds of characters except % and *, and one wants to validate that string, then %CHAR() comes handy.
    %found (or not %found) gets triggered after search and, in addition, it furnishes position at which a condition is met (or not met). If multiple hits of success (or failure) is expected, the functions can begin search after where they left last and the result can be stored in an array instead of a scalar variable
    SCAN() is a string search (one or more characters) and %CHECK() is a character search. SCAN looks for %found CHAR looks for not %found. 
    It is not so much a question what the difference is between them rather it is knowing where to use which.
    Function: Check whether a string has character either'A' 
    or 'B' or 'C'
    dcl-s  base char ( 20 ) inz('ABCAABCAABCAA1ABC') ; 
    dcl-s  comparator char ( 03 ) inz('ABC') ;               
    dcl-s  posfound   uns  ( 03 ) inz( 0 ) ;                 
    dcl-s  i          uns  ( 03 ) ;
    dcl-s  array      uns  ( 03 ) dim ( 05 ) inz( 0 ) ;                           
    comparator  =  %trimR(comparator) ;                          
    base        =  %trimR(base) ; 
    posfound  =  %check ( comparator: %trimR(base): 1 ) ;        
    dow  (posFound > 0) and (posfound < %len(%trim(base))) ;     
         dsply  posfound ;                                       
         posfound  =  %check ( comparator: %trimR(base): 
         (posfound+1) ) ; 
    endDO ;                   
    dsply  posfound ;
    array(1)  =  %check ( comparator:  %trimR(base): 1  ) ;     for  i = 2 by 1 to %elem(array) ;                                 array(i)  =  %check ( comparator:  %trimR(base): (array(i-1)+1 ));
         if  array(i) = 0 ;                                      
             leave ;                                                  endIF ;                                                 endFOR ;                                                     for  i = 1 by 1 to %elem(array) ;                                 dsply  (%char(i) + ' ' + %char(array(i))) ;             endFOR ;
    Function: check whether or not 'BA' is amongst 'BABBA'
    dcl-s  source           char ( 20 ) inz('BABBA') ;
    dcl-s  search           char ( 02 ) ;             
    dcl-s  posfound         uns  ( 03 ) inz( 0 ) ;    
    search  =  'BA' ;                                     
    search  =  %trimR(search) ;                           
    dsply ( 'search aft trim: ' + %char(%len(search)) ) ; 
    posfound  =  %scan ( 'LA': 'BABBA': 1 ) ;             
    dsply ( 'search start 1: ' + %char(posfound) ) ;      
    posfound  =  %scan ( search: source: 3 ) ;       
    dsply ( 'search start 3: ' + %char(posfound) ) ; 

    765 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: