ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

%scan

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • %scan

    I want to scan a character string to see if the string contains any letters of the alphabet. Is there a way to do this without doing %SCAN 26 times using a different letter each time

  • #2
    Re: %scan

    Hi Gregwga50:

    Give this a try:

    Code:
         D A2Z             C                   CONST('ABCDEFGHIJKLMNOPQRST+
         D                                     UVWXYZ')                    
         D blnk            C                   CONST('                    +
         D                                           ')                    
         d testfld         s             15a   inz('1234567890ABCDE')      
         D WRKFLD          S                   LIKE(TESTFLD)               
         D OK              S              1                                
          /FREE                                                            
                WRKFLD = %XLATE(A2Z : BLNK : TESTFLD) ;                    
                IF WRKFLD <> TESTFLD ;                                     
                   DSPLY 'YOU HAVE ALPHA' '' OK   ;                        
                  ELSE ;                                                   
                   DSPLY 'NOALPHA DETECTED' '' OK   ;                      
                ENDIF ;                                                    
                *INLR = *ON ;                                              
          /END-FREE
    If you need lower case add to the a2z and blnk fields.

    Best of Luck
    GLS
    The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

    Comment


    • #3
      Re: %scan

      To be more specific, here is what I am trying to do:

      We have an alpha field, I'll call DESCRP. Sometimes it contains customer number (%trimmed) followed by a space and then a name, other times, it just contains customer#. I want to detemine when it contains a name

      Comment


      • #4
        Re: %scan

        Are your customer numbers alpha?

        If they are all numeric that method should work

        GLS
        The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

        Comment


        • #5
          Re: %scan

          How about:

          Code:
          Namepos = %CHECK('0123456789 ' : [COLOR=#000000]DESCRP);
          [/COLOR]CustName = '';
          If Namepos > 0;
            CustName =  %Subst(DESCRP : Namepos);
          Endif;
          Given the assumption that DESCRP starts with customer number with optional customer name following. The %CHECK will return the first character that isn't in the first string - which is 0-9 and a blank. If all it has is blanks and numbers it will return 0 to reflect that. If something is found use %Subst to extract it.

          Comment


          • #6
            Re: %scan

            Yeah, I was gonna say what Rocky said, more or less. You're looking for %CHECK rather than %SCAN....

            Comment

            Working...
            X