APIs by Example: Retrieve Job's User Library List

Article ID: 14242

In the March 28 issue, I started showing you routines you can use for a library list manipulation utility with a look at API QWDRJobD (Retrieve Job Description Information). This installment of APIs by Example continues the routines the utility will use with a look at how to use Work Management APIs to retrieve the libraries specified in a job's user library list. The example consists of service program Job, which is used to perform functions related to jobs, program JobEx, and snippets that show how to use the service program in your applications.

Procedure RtvUsrLibL in service program Job retrieves the user library list from a specified job and returns it to the caller. Note that this example presumes a maximum of 25 libraries in the library list.

Here are the parameters for procedure RtvUsrLibL:

Parameters

JobName         INPUT
Job name.
Special value * indicates the current job.

JobUser         INPUT
Job user.

JobNumber       INPUT
Job number.

APIError        INPUT/OUTPUT (optional)
API error structure.

Standard API error structure to contain error details. When the return code indicates an error, this structure further defines the specific error.

Return value    OUTPUT

Structure containing list of libraries.
A maximum of 25 libraries is returned. Each entry is 11 bytes in length.

The Work Management API used in service program Job is

* Retrieve Job Information (QUSRJobI)

This API retrieves job information.

You can find documentation for API QUSRJobI at

http://publib.boulder.ibm.com/pubs/html/as400/v5r1/ic2924/info/apis/qusrjobi.htm.

Below is service program Job:

      *  ===================================================================
      *  = Service Program... Job                                          =

      *  = Description....... Job routines                                 =
      *  =                                                                 =
      *  = Compile........... CrtRPGMod Module(YourLib/Job)                =
      *  =                              SrcFile(YourLib/YourSrcFile)       =
      *  =                    CrtSrvPgm SrvPgm(YourLib/Job)                =
      *  =                              Export(*All)                       =
      *  ===================================================================

     H NoMain

      *  ===================================================================
      *  = Prototypes                                                      =
      *  ===================================================================

      *  -------------------------------------------------------------------
      *  - RtvUsrLibL - Retrieve user library list                         -
      *  -------------------------------------------------------------------

     D RtvUsrLibL...
     D                 Pr           275
     D                               10    Value
     D                               10    Value
     D                                6  0 Value
     D                              272    Options( *NoPass )

      *  -------------------------------------------------------------------
      *  - RtvJobAPI - Retrieve job information API                        -
      *  -------------------------------------------------------------------

     D RtvJobAPI...
     D                 Pr                  ExtPgm( 'QUSRJOBI' )
     D                            32767
     D                               10I 0
     D                                8
     D                               26
     D                               16
     D                              272

      *  ===================================================================
      *  = Procedure..... RtvUsrLibL                                       =
      *  = Description... Retrieve user library list                       =
      *  ===================================================================

     P RtvUsrLibL...
     P                 B                   Export
     D                 PI           275
     D  JobName                      10    Value
     D  JobUser                      10    Value
     D  JobNumber                     6  0 Value
     D  APIError                    272    Options( *NoPass )

      *  -------------------------------------------------------------------
      *  - Data definitions                                                -
      *  -------------------------------------------------------------------

     D CharJobNumber   DS
     D  NbrJobNumber                  6  0

     D IntJobID        S             16    Inz( *Blank )
     D QualJobName     S             26    Inz ( '*' )

     D RcvVar          DS         32767
     D                               64    Inz( *Blank )
     D  NbrSysLibs                   10I 0 Inz( *Zero )
     D  NbrPrdLibs                   10I 0 Inz( *Zero )
     D  NbrCurLibs                   10I 0 Inz( *Zero )
     D  NbrUsrLibs                   10I 0 Inz( *Zero )

     D LibsToSkip      S             10I 0

     D RcvVarLen       S             10I 0 Inz( %Len( RcvVar ) )
     D Format          S              8    Inz( 'JOBI0700' )

     D UsrLibs         S            275    Inz( *Blank )

     D Pos             S             10I 0

     D NoAPIError      C                   Const( *Zero )
     D APIErrorPassed  S               N

     D APIErrorDS      DS
     D  BytesProvided                10I 0 Inz( %Size( APIErrorDS ) )
     D  BytesAvail                   10I 0 Inz( *Zero )
     D  MsgID                         7    Inz( *Blanks )
     D                                1    Inz( X'00' )
     D  MsgDta                      256    Inz( *Blanks )

      *  -------------------------------------------------------------------
      *  - Determine whether API error parameter was passed                -
      *  -------------------------------------------------------------------

     C                   If        %Parms > 3
     C                   Eval      APIErrorPassed = *On
     C                   EndIf

      *  -------------------------------------------------------------------
      *  - Retrieve job information                                        -
      *  -------------------------------------------------------------------

     C                   Reset                   APIErrorDS

     C                   If        JobName <> '*'
     C                   Eval      NbrJobNumber = JobNumber
     C                   Eval      QualJobName = JobName       +
     C                                           JobUser       +
     C                                           CharJobNumber
     C                   EndIf

     C                   CallP     RtvJobAPI(
     C                                        RcvVar         :
     C                                        RcvVarLen      :
     C                                        Format         :
     C                                        QualJobName    :
     C                                        IntJobID       :
     C                                        APIErrorDS
     C                                      )

     C                   If        BytesAvail <> NoAPIError
     C                   ExSr      ReturnError
     C                   EndIf

      *  -------------------------------------------------------------------
      *  - Extract user library list and return it to caller               -
      *  -------------------------------------------------------------------

     C                   Eval      LibsToSkip = NbrSysLibs +
     C                                          NbrPrdLibs +
     C                                          NbrCurLibs

     C                   Eval      Pos = ( LibsToSkip * 11 ) + 81

     C                   Eval      UsrLibs = %Subst(
     C                                               RcvVar          :
     C                                               Pos             :
     C                                               NbrUsrLibs * 11
     C                                             )

     C                   Return    UsrLibs

      *  -------------------------------------------------------------------
      *  - Subroutine.... ReturnError                                      -
      *  - Description... Return error condition to caller                 -
      *  -------------------------------------------------------------------

     C     ReturnError   BegSr

     C                   If        APIErrorPassed
     C                   Eval      APIError = APIErrorDS
     C                   EndIf

     C                   Return    *Blank

     C                   EndSr

     P RtvUsrLibL...
     P                 E

Below are code snippets showing how to use procedure RtvUsrLibL:

      *  ===================================================================
      *  = Program....... JobEx                                            =
      *  = Description... Sample demonstrating use of procedure RtvUsrLibL =
      *  =                                                                 =
      *  = Compile....... CrtRPGMod Module(YourLib/JobEx)                  =
      *  =                          SrcFile(YourLib/YourSrcFile)           =
      *  =                CrtPgm    Pgm(YourLib/JobEx)                     =
      *  =                          BndSrvPgm(YourLib/Job)                 =
      *  =                          ActGrp(*New)                           =
      *  ===================================================================

     D RtvUsrLibL...
     D                 Pr           275
     D                               10    Value
     D                               10    Value
     D                                6  0 Value
     D                              272    Options( *NoPass )

     D JobName         S             10    Inz( '*' )
     D JobUser         S             10    Inz( *Blank )
     D JobNumber       S              6  0 Inz( *Zero )
     D UsrLibL         S            275

     D APIErrorDS      DS
     D  BytesProvided                10I 0 Inz( %Size( APIErrorDS ) )
     D  BytesAvail                   10I 0 Inz( *Zero )
     D  MsgID                         7    Inz( *Blanks )
     D                                1    Inz( X'00' )
     D  MsgDta                      256    Inz( *Blanks )

     D NoAPIError      C                   Const( *Zero )

      *  -------------------------------------------------------------------
      *  - Retrieve user library list                                      -
      *  -------------------------------------------------------------------

     C                   Reset                   APIErrorDS

     C                   Eval      UsrLibL = RtvUsrLibL(
     C                                                   JobName    :
     C                                                   JobUser    :
     C                                                   JobNumber  :
     C                                                   APIErrorDS
     C                                                 )

     C                   If        BytesAvail <> NoAPIError
     C                   ExSr      HandleError
     C                   EndIf

This sample shows that you can invoke procedure RtvUsrLibL with or without specifying the API error structure. If an error occurs in procedure RtvUsrLibL, the return information is blank. I recommend using the API error structure so that when an error occurs, you can obtain specific details.

The returned library list structure will contain one of the following

values:
  1. Blanks -- A blank value indicates an error condition or an empty user library list. To determine whether an error occurred, you should interrogate the API error structure.
  2. Library list -- The user library list.

ProVIP Sponsors

ProVIP Sponsors