Now, Get RPG Codes in all three formats only on this website on every RPGLE related programming article.

Fixed, /Free and Fully Free RPG


Checking object Existence in CL

Checking object Existence in CL.
Checking object Existence in CL, Check Object (CHKOBJ), OBJ , MBR , AUT , as400, ibmi, as400 and sql tricks, as400 tutorial, ibmi tutorial
Checking object Existence in CL

Check Object (CHKOBJ) command?

The Check Object (CHKOBJ) command checks object existence and verifies the user's authority for the object before trying to access it. You can use this command at any place in a procedure or program.

                              Check Object (CHKOBJ)                           
                                                                              
 Type choices, press Enter.                                                   
                                                                              
 Label  . . . . . . . . . . . . .                                             
 Object . . . . . . . . . . . . . OBJ          > CLPF1                        
   Library  . . . . . . . . . . .              >   EASYCLASSG                 
 Object type  . . . . . . . . . . OBJTYPE      > *FILE                        
 Member, if data base file  . . . MBR            *NONE                        
 Authority  . . . . . . . . . . . AUT            *NONE                        
                           + for more values                                  
 Comment  . . . . . . . . . . . .                                             

OBJ Specifies the qualified name of the object being checked. Here, object named CLPF1. If no library name is given, *LIBL is used to find the object. But here, my library EASYCLASSG. OBJTYPE defines the object type of the system object being checked. Enter the predefined value that specifies the object type. MBR Specifies which logical file member is checked, when checking data authorities. *NONE: Database file members are not checked, but the existence and (optionally) the authority of the file are checked. AUT Specifies the authority being checked. *NONE: The user's authority is not checked.

Check Object Existence in CL Program

              PGM                                                                    
              DCL        VAR(&QUOTE) TYPE(*CHAR) LEN(1) VALUE('''')                  
              DCL        VAR(&Msg) TYPE(*CHAR) LEN(20)                               
                                                                                     
              CHKOBJ     OBJ(EASYCLASS1/CLPF10) OBJTYPE(*FILE)                       
              MONMSG     MSGID(CPF9801) EXEC(SNDPGMMSG MSG('OBJECT +                 
                           NOT FOUND'))                                              
                                                                                     
              CHKOBJ     OBJ(EASYCLASSG/CLPF1) OBJTYPE(*FILE)                        
              MONMSG     MSGID(CPF9810) EXEC(SNDPGMMSG MSG('LIBRARY +                
                           NOT FOUND'))                                              
                                                                                     
        /*   CPF9815(Member not found) etc(CF9803) -> Cannot allocate    */          
                                                                                                                                                         
              ENDPGM                                                                 

Explanation:

  • Object not found in library
  •              CHKOBJ     OBJ(EASYCLASS1/CLPF10) OBJTYPE(*FILE)        
                 MONMSG     MSGID(CPF9801) EXEC(SNDPGMMSG MSG('OBJECT +  
                              NOT FOUND'))                               

    Here, we monitor message CPF9801 which means "Object &2 in library &3 not found." Here, object named CLPF10 does not exists in library EASYCLASS1 of type *FILE.

  • Library not found
  •              CHKOBJ     OBJ(EASYCLASSG/CLPF1) OBJTYPE(*FILE)        
                 MONMSG     MSGID(CPF9810) EXEC(SNDPGMMSG MSG('LIBRARY +
                              NOT FOUND'))                              

    Here, we monitor message CPF9810 which means "Library &1 not found." Here, Library named EASYCLASSG not found.

    Note:

    We can monitor other messages as well for CHKOBJ command such as CPF9815(Member &5 file &2 in library &3 not found) etc.

    Post a Comment

    © AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain