How to find object’s library?

Tags:
AS/400
CL Program
Inside a CL, I want to know the library of the compiled object, to see if it's in a test or production library. How can I do this?
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 5  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.
  • TheRealRaven
    There are a few methods I've used over the years. I've finally settled on a method that is both easy and reliable. The method uses the Materialize Program Name (MATPGMNM) builtin MI function that is intended to provide just this data.

    I use two INCLUDE members, one to declare data items and one to hold the subroutine.

    The data item member, FNDCLPLIBD:

    /*  FndCLPLib DCLs                                                          */
    
       dcl   &thisPgm     *char    10     value( ' ' )
       dcl   &thisPgmLib  *char    10     value( ' ' )
    
       dcl   &fclPgmInfo  *char    80
       dcl   &fclBytPrv   *int            stg( *defined ) defvar( &fclPgmInfo   1 )
       dcl   &fclBytAvl   *int            stg( *defined ) defvar( &fclPgmInfo   5 )
       dcl   &fclFormat   *int            stg( *defined ) defvar( &fclPgmInfo   9 )
       dcl   &fclRsv      *char     4     stg( *defined ) defvar( &fclPgmInfo  13 )
       dcl   &fclCtxOT    *char     1     stg( *defined ) defvar( &fclPgmInfo  17 )
       dcl   &fclCtxOST   *char     1     stg( *defined ) defvar( &fclPgmInfo  18 )
       dcl   &fclLib      *char    30     stg( *defined ) defvar( &fclPgmInfo  19 )
       dcl   &fclPgmOT    *char     1     stg( *defined ) defvar( &fclPgmInfo  49 )
       dcl   &fclPgmOST   *char     1     stg( *defined ) defvar( &fclPgmInfo  50 )
       dcl   &fclPgm      *char    30     stg( *defined ) defvar( &fclPgmInfo  51 )
    
    The subroutine member, FNDCLPLIB:

     /* FndCLPLib                                                                */
    
    subr     FndCLPLib
    
       chgvar            &fclBytPrv            ( 80 )
       chgvar            &fclBytAvl            ( 0 )
       chgvar            &fclFormat            ( 0 )
       chgvar            &fclRsv               ( x'00000000' )
    
       callprc     '_MATPGMNM'   ( &fclPgmInfo )
    
       chgvar            &thisPgmLib       %sst( &fclLib  1 10 )
       chgvar            &thisPgm          %sst( &fclPgm  1 10 )
    
    endsubr
    Here's a simple test program:

    pgm
    
       include  FNDCLPLIBD
    
       callSubr FNDCLPLIB
       sndmsg   ( &thisPgmLib *tcat '/' *cat &thisPgm ) tousr( *REQUESTER )
    
       return
    
       include  FNDCLPLIB
    
    endpgm
    The test program requires i 6.1 because of the uses of the INCLUDE commands. At V5R4, you can simply insert the the copied code directly into your CL. And at V5R3, you can use the two INCLUDE members to create a CL module that returns the program name and library as output parms.

    Of course, you can create a CL module and bind it to your CL programs at any version above V5R3, too. The subroutine example is just to show an alternative and to show it working as part of the most simple *PGM.


    36,035 pointsBadges:
    report
  • philpl1jb

    I would use the RTVOBJD (Retrieve Object Description) command

    One of the optional variables is RTNLIB

    So my cl command might look like this

    RTVOBJD (MyObj) RTNLIB(&MyLib)

    54,090 pointsBadges:
    report
  • philpl1jb

    Sure wish there was an edit button RTVOBJD requires OBJTYPE

    RTVOBJD (MyObj) ObjType(*PGM)  RTNLIB(&MyLib)

    54,090 pointsBadges:
    report
  • TheRealRaven
    But RTVOBJD doesn't return the library of the running program unless (1) it's passed the name of the currently running program and (2) you supply the library of the currently running program or the currently running program is the first one of its name found in the current library list.

    The current program name generally is known at compile-time, so it can be hard codded, most of the time. But it's not always the same.

    And a job might have both the test and production (and/or QA and/or developer and/or other) libraries in its library list. The CALL command would qualify which program version was executed, but RTVOBJD couldn't tell the difference.
    36,035 pointsBadges:
    report
  • philpl1jb

    or perhaps the lib list would be sufficient .. if the test library is in the library list .. then it's probably a test.

    RTVJOBA

    CL var for SYSLIBL (165)
    CL var for CURLIB (10)
    CL var for USRLIBL (2750)


    54,090 pointsBadges:
    report

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.

Following

Share this item with your network: