ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

How do I SCAN in CL?

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

  • How do I SCAN in CL?

    I'm looking for a way to do a SCAN in CL. Basically, I have a list of job descriptions, a whole bunch of them, I do a retrieve, get the library list into a variable, and now I need to scan that variable for a specific library.

    Or, is there a way to dump job descriptions into a table where I can run SQL over it?

    Any suggestions?

    Thanks.

  • #2
    Re: How do I SCAN in CL?

    take a peak here



    jamie
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: How do I SCAN in CL?

      Hi rpgKnight:

      Check out the program JCRFJOBDL in Craig Retledge's down load package. I haven't tried it myself but there is lots of good stuff there.

      It prompts for the library name to find and prints a report of all job descriptions using that library.

      Source code is provided....I'm sure you can adapt that program to your needs.



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

      Comment


      • #4
        Re: How do I SCAN in CL?

        Thanks for the ideas. I've actually downloaded and compiled all of Craig Retledge's stuff and I have it on a test box. I just haven't had time to test any of them out, but I am going to try the one suggested.

        Comment


        • #5
          Re: How do I SCAN in CL?

          Actually there is a system API to do this.

          Here is a CL to call it.

          Code:
          /* CPP for QCLSCAN                                                   */    
          /* Command intervace to QCLSCAN API                                  */    
                       PGM        PARM(&STRING &STRLEN &STRPOS &PATTERN +            
                                    &PATLEN &TRANSLATE &TRIM &WILDCARD &RETURN)      
                       DCL        &STRING     *CHAR 999                              
                       DCL        &STRLEN     *DEC  3                                
                       DCL        &STRPOS     *DEC  3                                
                       DCL        &PATTERN    *CHAR 999                              
                       DCL        &PATLEN     *DEC  3                                
                       DCL        &TRANSLATE  *LGL                                   
                       DCL        &TRIM       *LGL                                   
                       DCL        &WILDCARD   *CHAR 1                                
                       DCL        &RETURN     *DEC  3                                
                       DCL        &ABEND      *LGL                                   
                       DCL        &MSGDTA     *CHAR 132                              
                       DCL        &MSGID      *CHAR 7                                
                       DCL        &MSGF       *CHAR 10                               
                       DCL        &MSGFLIB    *CHAR 10                               
                       MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(ABEND))            
                                                                                     
                       CALL       PGM(QCLSCAN) PARM(&STRING &STRLEN &STRPOS +        
                                    &PATTERN &PATLEN &TRANSLATE &TRIM +              
                                    &WILDCARD &RETURN)                               
                                                                                          
            EXIT:       RETURN     /* NORMAL END OF JOB */                                
                                                                                          
            ABEND:      IF         COND(&ABEND) THEN(SNDPGMMSG MSGID(CPF9898) +           
                                     MSGF(QCPFMSG) MSGDTA('Function check.') +            
                                     MSGTYPE(*ESCAPE))                                    
                        CHGVAR     VAR(&ABEND) VALUE('1')                                 
                        DMPCLPGM                                                          
           /* Forward diagnostic messages from this program message queue to previous */  
            FORWARD:    RCVMSG     MSGTYPE(*DIAG) RMV(*NO) MSGDTA(&MSGDTA) +              
                                     MSGID(&MSGID) MSGF(&MSGF) MSGFLIB(&MSGFLIB)          
                        IF         (&MSGID ¬= ' ') DO                                     
                          SNDPGMMSG  MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +                 
                                       MSGDTA(&MSGDTA) MSGTYPE(*DIAG)                     
                          GOTO       FORWARD                                              
                          ENDDO                                                           
                        RCVMSG     MSGTYPE(*EXCP) RMV(*NO) MSGDTA(&MSGDTA) +              
                                     MSGID(&MSGID) MSGF(&MSGF) MSGFLIB(&MSGFLIB)          
                        IF         (&MSGID ¬= ' ') DO                                     
                          SNDPGMMSG  MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +                 
                                       MSGDTA(&MSGDTA) MSGTYPE(*ESCAPE)                   
                          ENDDO                                                           
                        ENDPGM
          and the command is

          Code:
          /*********************************************************************/       
          /* To Compile: (Using PROMIS/COMPILE)                                */       
          /*                                                                   */       
          /*           CRTCMD     CMD(XXXLIB/QCLSCAN) PGM(QCLSCANC) +          */       
          /*                        SRCFILE(XXXLIB/QCMDSRC) ALLOW(*BPGM *IPGM +*/       
          /*                        *BREXX *IREXX *BMOD *IMOD)                 */       
          /*                                                                   */       
          /*********************************************************************/       
                       CMD        PROMPT('QCLSCAN API')                                 
                       PARM       KWD(STRING) TYPE(*CHAR) LEN(999) MIN(1) +             
                                    PROMPT('Target String')                             
                       PARM       KWD(STRLEN) TYPE(*DEC) LEN(3) MIN(1) +                
                                    PROMPT('Target String Length')                      
                       PARM       KWD(STRPOS) TYPE(*DEC) LEN(3) DFT(0) +                
                                    PROMPT('Start position in Target')                  
                       PARM       KWD(PATTERN) TYPE(*CHAR) LEN(999) DFT(' ') +          
                                    PROMPT('Search Pattern String')                     
                       PARM       KWD(PATLEN) TYPE(*DEC) LEN(3) DFT(0) +                
                                    PROMPT('Pattern String Length')                     
                       PARM       KWD(TRANSLATE) TYPE(*CHAR) LEN(1) RSTD(*YES) +        
                                    DFT(N) VALUES(Y N) SPCVAL((N '0') (Y +              
                                    '1')) PROMPT('Translatge to upper case')            
                       PARM       KWD(TRIM) TYPE(*CHAR) LEN(1) RSTD(*YES) +             
                                    DFT(Y) VALUES(Y N) SPCVAL((N '0') (Y +          
                                    '1')) PROMPT('Trim trailing blanks')            
                       PARM       KWD(WILDCARD) TYPE(*CHAR) LEN(1) +                
                                    PROMPT('Wildcard character')                    
                       PARM       KWD(RETURN) TYPE(*DEC) LEN(3) RTNVAL(*YES) +      
                                    PROMPT('Found position variable    3.0')
          Denny

          If authority was mass, stupidity would be gravity.

          Comment


          • #6
            Re: How do I SCAN in CL?

            I can't think of anything worse than waking a long dead thread...
            well unless it was a long dead CLLE thread.




            %SCAN built-in function
            The scan built-in function (%SCAN) returns the first position of a search argument in the source string, or 0 if it was not found.
            This function can only be used within a CL program or procedure

            The %SCAN built-in function can be used anywhere that CL supports an arithmetic expression. %SCAN can be used alone or as
            part of a more complex arithmetic expression. For example, %SCAN can be used to compare to a numeric CL variable in the COND
            parameter of an IF or WHEN command. %SCAN can also be used to set the value of a CL command parameter, if the associated
            command object defines the parameter with EXPR(*YES) and TYPE of *DEC, *INT2, *INT4, *UINT2, or *UINT4.

            The format of the scan built-in function is:
            Code:
            %SCAN(search-argument source-string [starting-position])
            The search argument must be either a CL character variable or a character literal. The source string can be a CL character variable or
            *LDA. When *LDA is specified, the scan function is performed on the contents of the local data area for the job. The starting position
            is optional and defaults to 1. Searching begins at the starting position (start) of the source string. The result is always relative to the
            first byte in the source string, even if the starting position is specified. The starting position, if specified, must be either a CL integer
            variable or a CL decimal variable with zero decimal positions or a numeric literal with zero decimal positions. The starting position
            cannot be zero or negative. If the starting position is greater than the length of the entire source-string variable or the local
            data area, an error occurs. The length of the local data area is 1024.

            The following examples are about the scan built-in function:

            Search for a specific string, CL variable &FNAME is scanned for the string ’John’. If the string ’John’ is not found anywhere in
            variable &FNAME, a message is sent.

            Note: The scan is case-sensitive, so a scan for ’John’ does not return a positive result if &FNAME contains the value ’JOHN’.

            PHP Code:
            PGM PARM(&FNAME
            DCL VAR(&FNAMETYPE(*CHARLEN(10
            IF 
            COND(%SCAN('John' &FNAME) *EQ 0) + 
               
            THEN(SNDPGMMSG ('NOT FOUND!')) 
            Search from a specific position in the string. The %SCAN function is used multiple times to take a date value that contains a
            date separator and retrieve the month value into a numeric variable. The first %SCAN finds the position of the date separator
            between the day and month. The second %SCAN starts with the character that follows the first date separator and finds the
            position of the date separator between the month and year. The substring (%SST) built-in function is then used to convert
            the month value from character form to a decimal variable.
            PHP Code:
            DCL VAR(&YYYYMMDDTYPE(*CHARLEN(10VALUE(‘2012/8/29’) 
            DCL VAR(&DATSEPTYPE(*CHARLEN(1VALUE('/'
            DCL VAR(&SPOSTYPE(UINTLEN(2
            DCL VAR(&EPOSTYPE(UINTLEN(2
            DCL VAR(&LENTYPE(UINTLEN(2
            DCL VAR(&MONTHTYPE(*DECLEN(2
            CHGVAR VAR(&SPOSVALUE(%SCAN(&DATSEP &YYYYMMDD)) 
            CHGVAR VAR(&SPOSVALUE(&SPOS 1)) 
            CHGVAR VAR(&EPOSVALUE(%SCAN(&DATSEP &YYYYMMDD &SPOS)) 
            CHGVAR VAR(&LENVALUE(&EPOS - &SPOS
            CHGVAR VAR(&MONTHVALUE(%SST(&YYYYMMDD &SPOS &LEN)) 
            Search characters from the local data area (*LDA). The local data area (LDA) is scanned starting from byte 1 of the LDA
            for the string ’Escape’. If the string is found, the position of the string in the LDA is assigned to CL variable &POS.
            If the string ’Escape’ is not found in the whole LDA, a value of zero is assigned to variable &POS.
            PHP Code:
            DCL VAR(&POSTYPE(*UINTLEN(2
            CHGVAR VAR(&POSVALUE((%SCAN('Escape' *LDA)) 
            All my answers were extracted from the "Big Dummy's Guide to the As400"
            and I take no responsibility for any of them.

            www.code400.com

            Comment


            • #7
              Re: How do I SCAN in CL?

              Jamie...isn't your example limited to V7R1 only -or- is there a backwards PTF for V6/V5?

              Comment


              • #8
                Re: How do I SCAN in CL?

                I do not know of a PTF for anything other than V7R1.

                Even on 7.1 remember this will not work in SEU only Rational Development Studio for i.
                All my answers were extracted from the "Big Dummy's Guide to the As400"
                and I take no responsibility for any of them.

                www.code400.com

                Comment


                • #9
                  Re: How do I SCAN in CL?

                  http://www.code400.com/forum/showthr...ll=1#post70076
                  I'm not anti-social, I just don't like people -Tommy Holden

                  Comment


                  • #10
                    Re: How do I SCAN in CL?

                    Need PTF:
                    Three new control language (CL) compiler built-in functions (%CHECK, %CHECKR, and %SCAN) were added by PTF SI49061 for IBM i 7.1.
                    Support for three new trim built-in functions (%TRIM, %TRIML, and %TRIMR) was added for IBM i 7.1 by PTF SI48166 in October 2012, and SI49061 supersedes SI48166.

                    New built-in functions have been added to both OPM CL and ILE CL that make string handling easier and faster:

                    • %CHECK - Check Characters
                    • %CHECKR - Check Reverse
                    • %SCAN - Scan for Characters
                    • %TRIM - Trim Characters at Edges
                    • %TRIML - Trim Leading Characters
                    • %TRIMR - Trim Trailing Characters



                    If you want to use these new CL built-in functions on a 7.1 system, PTF SI49061 must be loaded and applied. Support will not be PTF'ed to 6.1 or 5.4 releases, but you can compile CL code that uses these new functions on your 7.1 system and specify TGTRLS(V6R1M0) or TGTRLS(V5R4M0) and then save the CL objects off your 7.1 system and restore them on an IBM i system running the 5.4 or 6.1 release of IBM i.
                    All my answers were extracted from the "Big Dummy's Guide to the As400"
                    and I take no responsibility for any of them.

                    www.code400.com

                    Comment


                    • #11
                      Re: How do I SCAN in CL?

                      Even on 7.1 remember this will not work in SEU
                      Yes, all SEU syntax checking was frozen.

                      BUT, you can still compile using option 14 or the command line.

                      Comment


                      • #12
                        Re: How do I SCAN in CL?

                        Originally posted by dandevoe View Post
                        Yes, all SEU syntax checking was frozen.

                        BUT, you can still compile using option 14 or the command line.
                        As far as I know, only ILE RPG and ILE COBOL syntax checking was frozen for SEU. The syntax checker for each language is part of the same product as the compiler for the language, and the CL compiler is part of the OS. It looks like the PTFs for %SCAN must have also updated the CL syntax checker.

                        On my 7.1 system, SEU handles %SCAN fine.

                        Comment


                        • #13
                          Re: How do I SCAN in CL?

                          @Barbara -- That is interesting... I'm installing the PTF this weekend for the CLLE.

                          So If that is true, then why doesn't seu handle %SCANRPL in SEU, but works fine in RDP?
                          IBM's choice to modify CLLE is so baffling to me.

                          Jamie
                          All my answers were extracted from the "Big Dummy's Guide to the As400"
                          and I take no responsibility for any of them.

                          www.code400.com

                          Comment

                          Working...
                          X