ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

lookup

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

  • lookup

    hi all

    is there an equivalent command to lookup in cl?

    thank's
    Rachel

  • #2
    Re: lookup

    I am no CL expert but you would have to loop thru the data then
    use the API QCLSCAN API to scan for character matches.


    Code:
    The Scan for String Pattern (QCLSCAN) API is used to scan 
    a string of characters to see if the string contains a pattern. 
    This function is similar to the scan function supported within 
    source entry utility (SEU) and on the display presented by 
    the Display Spooled File (DSPSPLF) command. In addition, 
    the QCLSCAN API also allows you to specify a 1-byte character 
    in the pattern that matches with any character in the string 
    to be searched, and a start position, which allows you to 
    search the same string more than once.

    I dont have an example but here is a link to IBM just search on QCLSCAN.



    I found old version
    Code:
    PGM        PARM(&BDTT &EDTT)                          
                                                          
    DCL        VAR(&BDTT) TYPE(*CHAR) LEN(6) /* MDY */    
    DCL        VAR(&EDTT) TYPE(*CHAR) LEN(6) /* MDY */    
                                                          
    OVRPRTF    FILE(QPDSPLOG) HOLD(*YES)                  
    DSPLOG     PERIOD((*AVAIL &BDTT) (*AVAIL &EDTT)) +    
                 OUTPUT(*PRINT) MSGID(CPF1124 CPF1164)    
    CPYSPLF    FILE(QPDSPLOG) TOFILE(TIMLOG) SPLNBR(*LAST)
    DLTSPLF    FILE(QPDSPLOG) SPLNBR(*LAST)               
    DLTOVR     FILE(*ALL)                                 
                                                          
    CALL       PGM(TIMRPG)                                
                                                          
    ENDPGM
    
    File TIMFIL -- Time file by user 
    
    R TIMEFM                                           
      TIMUSR        10          COLHDG('USER')         
      TIMDTT         6S 0       COLHDG('DATE')         
      TIMBTM         6S 0       COLHDG('BEGIN TIME')   
      TIMETM         6S 0       COLHDG('END TIME')     
      TIMTMN         6S 0       COLHDG('TOTAL MINUTES')
    K TIMUSR                                           
    K TIMDTT
    
    File TIMLOG -- Time log -- Temporary file
    
    R LOGFM                                          
      LOGMSG         7A         COLHDG('MSG NUMBER') 
      LOGTXT       125          COLHDG('TEXT')
    
    Program  - TIMRPG -- Calculate time from QHST logs
    FTIMLOG  IF  E                    DISK                        
    FTIMFIL  UF  E           K        DISK                      A 
    I            DS                                               
    I                                       16  25 DSPID          
    I                                       27  36 USER           
    I                                       38  43 JOBNBR         
    I                                       63  64 MM             
    I                                       66  67 DD             
    I                                       69  70 YY             
    I                                       72  73 HH             
    I                                       75  76 MN             
    I                                       78  79 SS             
    I                                        1 125 TIMTXX         
    I            DS                                               
    I                                        1   20YEAR           
    I                                        3   40MONTH          
    I                                        5   60DAY            
    I                                        1   60DATE           
    I            DS                                               
    I                                        1   20HOUR
    I                                        3   40MINUTE          
    I                                        5   60SECOND          
    I                                        1   60TIME            
    C           TIMKY     KLIST                                    
    C                     KFLD           USER                      
    C                     KFLD           DATE                      
    C           *LIKE     DEFN LOGMSG    HLDMSG                    
    C*                                                             
    C           *IN51     DOUEQ*ON                                 
    C                     READ TIMLOG                   51         
    C*                                                             
    C           *IN51     IFEQ *OFF                                 
    C           LOGMSG    IFEQ 'CPF1124'                           
    C           LOGMSG    OREQ 'CPF1164'                           
    C                     MOVELLOGMSG    HLDMSG                    
    C                     MOVEL*BLANKS   ARGUMN                    
    C                     MOVEL'/DSP'    ARGUMN 10        PATTERN  
    C                     Z-ADD4         PATLEN  30                
    C                     EXSR SCNVAR                              
    C           RESULT    IFEQ 0                                   
    C                     MOVEL*BLANKS   ARGUMN
    C                     MOVEL'/QPADEV' ARGUMN 10        PATTERN      
    C                     Z-ADD7         PATLEN  30                    
    C                     EXSR SCNVAR                                  
    C                     END                                          
    C           RESULT    IFGT 0                                       
    C                     EXSR WRTUPD                                  
    C                     END                                          
    C*                                                                 
    C                     END                                          
    C                     END                                          
    C                     END                                          
    C*                                                                 
    C                     SETON                     LR                 
    C***************************************************************** 
    C*  SCNVAR - SCAN A VARIABLE ROUTINE                               
    C***************************************************************** 
    C*                                                                 
    C           SCNVAR    BEGSR                                        
    C* Initialize                                                      
    C                     MOVELLOGTXT    SRCDTA125        PATTERN      
    C                     Z-ADD125       STRLEN  30       String len
    C                     Z-ADD1         STRPOS  30       Start pos    
    C                     MOVE '0'       TRANS   1        No translate 
    C                     MOVE '1'       TRIM    1        Trim pattrn  
    C* Normal processing including call to QCLSCAN                     
    C                     CALL 'QCLSCAN'                  QCLSCAN      
    C                     PARM           SRCDTA           String       
    C                     PARM           STRLEN           String len   
    C                     PARM           STRPOS           Start pos    
    C                     PARM           ARGUMN           Pattern      
    C                     PARM           PATLEN           Pattern len  
    C                     PARM           TRANS            Translate    
    C                     PARM           TRIM             Trim         
    C                     PARM           WILD    1        Wild char    
    C                     PARM           RESULT  30       Result       
    C                     ENDSR                                        
    C*                                                                 
    C***************************************************************** 
    C*  WRTUPD - WRITE/UPDATE                                          
    C***************************************************************** 
    C*                                                                 
    C           WRTUPD    BEGSR
    C*                                                           
    C                     READ TIMLOG                   51       
    C                     MOVELLOGTXT    TIMTXX                  
    C*                                                           
    C                     MOVELYY        YEAR                    
    C                     MOVELMM        MONTH                   
    C                     MOVELDD        DAY                     
    C                     MOVELHH        HOUR                    
    C                     MOVELMN        MINUTE                  
    C                     MOVELSS        SECOND                  
    C*                                                           
    C           TIMKY     CHAINTIMFIL               52           
    C           *IN52     IFEQ *OFF                               
    C* BEGINNING                                                 
    C           HLDMSG    IFEQ 'CPF1124'                         
    C           TIMBTM    ANDEQ0                                 
    C                     MOVELTIME      TIMBTM                  
    C                     UPDATTIMEFM                            
    C                     END                                    
    C* COMPLETION                                                
    C           HLDMSG    IFEQ 'CPF1164'                         
    C           TIME      ANDGTTIMETM               
    C                     MOVELTIMBTM    HLD4    4  
    C                     MOVELHLD4      HLDHR   20 
    C                     MOVE HLD4      HLDMN   20 
    C           HLDHR     MULT 60        CLCBTM  60 
    C                     ADD  HLDMN     CLCBTM     
    C           HOUR      MULT 60        CLCETM  60 
    C                     ADD  MINUTE    CLCETM     
    C           CLCETM    SUB  CLCBTM    TIMTMN     
    C                     MOVELTIME      TIMETM     
    C                     UPDATTIMEFM               
    C                     END                       
    C*                                              
    C                     ELSE                      
    C*                                              
    C                     CLEARTIMEFM               
    C                     MOVELUSER      TIMUSR     
    C           HLDMSG    IFEQ 'CPF1124'            
    C                     MOVELTIME      TIMBTM     
    C                     ELSE                      
    C                     MOVELTIMBTM    HLD4
    C                     MOVELHLD4      HLDHR   20    
    C                     MOVE HLD4      HLDMN   20    
    C           HLDHR     MULT 60        CLCBTM  60    
    C                     ADD  HLDMN     CLCBTM        
    C           HOUR      MULT 60        CLCETM  60    
    C                     ADD  MINUTE    CLCETM        
    C           CLCETM    SUB  CLCBTM    TIMTMN        
    C                     MOVELTIME      TIMETM        
    C                     END                          
    C                     MOVELDATE      TIMDTT        
    C*                                                 
    C                     WRITETIMEFM                  
    C*                                                 
    C                     END                          
    C                     ENDSR
    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: lookup

      thank's jaimie
      i will look at it

      Comment


      • #4
        Re: lookup

        Originally posted by rachely_p
        hi all

        is there an equivalent command to lookup in cl?

        thank's
        Rachel
        LOOKUP is an op-code that searches for a match within an array. Arrays are not valid in CL. So, no, there is no equivalent to LOOKUP in CL.

        QCLSCAN, as Jamie mentioned, is used to search through a character string for a given pattern. This would be the equivalent to the %scan built-in function in RPG IV.

        Michael
        "Time passes, but sometimes it beats the <crap> out of you as it goes."

        Comment


        • #5
          Re: lookup

          Michael you are correct

          as my post says you would need to read thru the data and use QCLSCAN to scan the data to look for a match.

          so the combination of the reading data back...maybe from a dataqueue(API), message file(API) or even a table(file - RCVF) and using the QCLSCAN against the data....would be "sorta"
          like %lookup.
          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


          • #6
            Re: lookup

            Simulating Arrays in CL
            --------------------------------

            CL dos not support arrays. If u need an array in a CL program, u can simulate one by using a very long character variable and the %SST function.

            Suppose u need an array of 50 object names (each one being 10 chars long) , u could declare a 500 char long variable as follows:

            DCL VAR(&OBJ_ARR) TYPE(*CHAR) LEN(500)

            Now u can reference the first element of this pseduo-array by using %SST(&OBJ_ARR 1 10)). The second element is (&OBJ_ARR 11 10)), and so on.. all the way to the 50th element, which would be (&OBJ_ARR 491 10)).

            If u needed to reference the nth element (i.e. where the element number is a varible ) , u can code something like (&OBJ_ARR &n 10)) where &n has been declared as a decimal variable.

            /* Changing the 2nd element */
            CHGVAr VAR(%SST((&OBJ_ARR 11 10))) VALUE('XYZ')


            /* Assigning the 2nd element to another variable */
            CHGVAr VAR(&X) VALUE(%SST((&OBJ_ARR 11 10)) )
            Thanks,
            Giri

            Comment

            Working...
            X