IBM Support

Using API QBNLPGMI in ILE RPG

Troubleshooting


Problem

The list API QBNLPGMI (List ILE Program Information) can be used to obtain a number of details regarding ILE program objects. The sample program in this document prints the qualified names of all modules contained in an ILE program. Note that, while providing a data structure in which to store exception details, this program does not perform error checking.

Resolving The Problem

The list API QBNLPGMI (List ILE Program Information) can be used to obtain a number of details regarding ILE program objects. The sample program in this document prints the qualified names of all modules contained in an ILE program. Note that, while providing a data structure in which to store exception details, this program does not perform error checking.

DDS for Printer File Definition BNLPGMIPRT:
     A* Printer file for sample ILE RPG program calling the API QBNLPGMI.
     A*
     A          R HEADERRCD
     A                                  4 10'LIBRARY'
     A                                  4 21'PROGRAM'
     A                                  4 40'LIBRARY'
     A                                  4 51'MODULE'
     A          R PGMNAMERCD
     A            P_LIB_NAME    10A  O    10SPACEB(1)
     A            PGM_NAME      10A  O    21SPACEA(1)
     A          R MODNAMERCD
     A            M_LIB_NAME    10A  O    40SPACEB(1)
     A            MOD_NAME      10A  O    51SPACEA(1)    
ILE RPG Source for Program BNLPGMRPG2:
       Ctl-Opt debug dftactgrp(*no);
       //
       //
       // Printer file to output API results.
       //
       Dcl-F bnlpgmiprt PRINTER usropn;
       //
       //
       // Standard data type definitions.
       //
       //
       // Maximum amount (in bytes) of error information returned by an API when raising an exceptio
       //
       Dcl-S max_error       Char(32767);
       //
       // Standard C-style 4-byte binary integer.
       //
       Dcl-S std_int         Int(10);
       //
       // Standard length of format name for APIs (8 characters).
       //
       Dcl-S std_format_name Char(8);
       //
       // According to the manual "System API Programming" (SC41-5800-00), the maximum size
       // allowed for user spaces is 16 megabytes.  This is the value set in max_usrspc_size.
       // The constant std_usrspc_size is the size for the user space in this program.
       // std_usrspc_size may be modified as needed.
       //
       Dcl-C max_usrspc_size const(16777216);
       Dcl-C std_usrspc_size const(32768);
       //
       // Standard definition of unqualified name for an object.
       //
       Dcl-S unqual_name     Char(10);
       //
       // Standard definition of qualified name for an object (includes the library name).
       //
       Dcl-S qual_name       Char(20);
       //
       //
       // The following copybooks are taken from library QSYSINC (Openness Includes, supplied
       // as 5769SS1 option 13).
       //
       //
      /COPY QSYSINC/QRPGLESRC,QUSEC
     D QUSEXCPT                            like(max_error)
       //
       // The above field QUSEXCPT is tagged on to error data structure QUSEC and is intended to
       // contain error/exception information.The field is 32767 characters long because this is the
       // maximum amount of error/exception data an API can return.
       //
       //
      /COPY QSYSINC/QRPGLESRC,QUSGEN
       //
      /COPY QSYSINC/QRPGLESRC,QBNLPGMI
       //
      /COPY QSYSINC/QRPGLESRC,QCLRPGMI
       //
       //
       // End of copybooks from QSYSINC.
       //
       //
       // Number of bytes provided for error information.  Setting this value to 0
       // causes the program to take an exception and error out in case of failure.
       // Otherwise, the program does not end with a hard error but rather returns the
       // error data in the QUSEC data structure.
       //
       Dcl-C bytes_provided  const(%size(QUSEC));
       //
       // Qualified name of the user space used in this program.
       //
       Dcl-C user_space      const('XXUSRSPCXX*CURLIB   ');
       //
       //
       // Format used for API QCLRPGMI.
       //
       Dcl-C QCLR_format     const('PGMI0100');
       //
       // Format used for API QBNLPGMI.
       //
       Dcl-C QBNL_format     const('PGML0100');
       //
       //
       // Starting position for retrieval from user space.
       //
       Dcl-S str_pos         like(std_int);
       //
       // Length of each item to retrieve from user space.
       //
       Dcl-S item_len        like(std_int);
       //
       // Length of receiver variable for API QCLRPGMI.
       //
       Dcl-S len_rec_var     like(std_int);
       //
       // Qualified name of program object to process.
       //
       Dcl-S long_pgm_name   like(qual_name);
       //
       //
       // Prototype definitions.
       //
       // Prototype for OPM API QBNLPGMI (list ILE program information).
       //
       Dcl-Pr ILEpgminfo extpgm('QBNLPGMI');
          pr_user_space   like(qual_name) const;
          pr_format_name  like(std_format_name) const;
          pr_ILE_p_name   like(qual_name) const;
          pr_error_code   like(QUSEC);
       End-Pr;
       //
       // Prototype for OPM API QCLRPGMI (retrieve program information).
       //
       Dcl-Pr rtvpgminfo extpgm('QCLRPGMI');
          pr_rec_var      like(QCLI0100);
          pr_len_rec_var  like(std_int) const;
          pr_format_name  like(std_format_name) const;
          pr_p_name       like(qual_name) const;
          pr_error_code   like(QUSEC);
       End-Pr;
       //
       // Prototype for OPM API QUSCRTUS (create user space).
       //
       Dcl-Pr crtusrspc extpgm('QUSCRTUS');
          pr_user_space   like(qual_name) const;
          pr_us_ext_attr  Char(10)        const;
          pr_us_size      like(std_int) const;
          pr_us_init_val  Char(1)         const;
          pr_us_auth      Char(10)        const;
          pr_us_text      Char(50)        const;
          pr_us_reply     Char(10)        const;
          pr_error_code   like(QUSEC);
       End-Pr;
       //
       // Prototype for OPM API QUSDLTUS (delete user space).
       //
       Dcl-Pr dltusrspc extpgm('QUSDLTUS');
          pr_user_space   like(qual_name) const;
          pr_error_code   like(QUSEC);
       End-Pr;
       //
       // Prototype for OPM API QUSRTVUS (retrieve user space).
       //
       Dcl-Pr rtvusrspc extpgm('QUSRTVUS');
          pr_user_space   like(qual_name) const;
          pr_us_str_pos   like(std_int);
          pr_us_item_len  like(std_int);
          pr_rec_var      like(QBNL0100);
          pr_error_code   like(QUSEC);
       End-Pr;
       //
       // Prototype of subprocedure to convert a mixed-case object name and return its
       // upper-case equivalent.
       //
       Dcl-Pr lower_to_upper Char(10);
          pr_mixed_str    like(unqual_name) value;
       End-Pr;
       Dcl-S NForIdx0001     Int(10);
       // Prototype for BNLPGMRPG1
       Dcl-Pr Pgm_BNLPGMRPG1 ExtPgm('BNLPGMRPG1');
          pgm_parm        Char(10);
          lib_parm        Char(10);
       End-Pr;
       // Procedure interface for BNLPGMRPG1
       Dcl-Pi Pgm_BNLPGMRPG1;
          pgm_parm        Char(10);
          lib_parm        Char(10);
       End-Pi;
       //
       // Main program.
       //
       //
       // User enters the name of the program to process (argument program), and the name of the
       // library where the program resides.
       //
       //
       // Set number of bytes provided to the API for returning error/exception information.
       //
       QUSBPRV = bytes_provided;
       //
       // Convert argument program name and library name to one all upper-case qualified name.
       //
       long_pgm_name = lower_to_upper(pgm_parm) +
           lower_to_upper(lib_parm);
       //
       //
       // Starting position to retrieve first item from user space.  After the call to QBNLPGMI,
       // the user space will contain information placeable in the following data structures in
       // the order shown:
       //
       // Data structure   Size (in bytes, as of V4R4)  Defined in: Member    File      Library
       //
       // QUSH0100                                 192              QUSGEN    QRPGLESRC QSYSINC
       // QBNGMIIS                                  48              QBNLPGMI  QRPGLESRC QSYSINC
       // QBNGMIHS                                  20              QBNLPGMI  QRPGLESRC QSYSINC
       // QBNL0100                                1070              QBNLPGMI  QRPGLESRC QSYSINC
       // ....
       //
       // There will be one QBNL0100-type entry in the user space for each module bound into the
       // program being processed.  Therefore the API QUSRTVUS has to be invoked from inside a
       // loop, once for each module whose information is to be printed.
       // Note: QUSH0100 is intended for OPM APIs.  The ILE equivalent of this data structure is
       // QUSH0300, which can be found in the same source member.
       //
       str_pos = 1 +
                     %size(QUSH0100) +
                     %size(QBNGMIIS) +
                     %size(QBNGMIHS);
       //
       // Length of one QBNL0100-type entry in the user space.
       //
       item_len = %size(QBNL0100);
       //
       // Create user space to store data from QBNLPGMI.
       //
       crtusrspc(
                     user_space :
                     '          ' :
                     std_usrspc_size :
                     ' ' :
                     '*CHANGE   ' :
                     *blanks :
                     '*YES      ' :
                     QUSEC
                    );
       //
       // Set length of receiver variable for QCLRPGMI.
       //
       len_rec_var = %size(QCLI0100);
       //
       // Invoke QCLRPGMI to obtain the number of modules bound into the argument program.
       //
       rtvpgminfo(
                      QCLI0100 :
                      len_rec_var :
                      QCLR_format :
                      long_pgm_name :
                      QUSEC
                     );
       //
       // Invoke QBNLPGMI to obtain details for each module in the argument program.
       //
       ILEpgminfo(
                      user_space :
                      QBNL_format :
                      long_pgm_name :
                      QUSEC
                     );
       //
       // Open printer file in preparation for output; write header and qualified program name.
       //
       Open bnlpgmiprt;
       Write headerrcd;
       p_lib_name = lib_parm;
       pgm_name = pgm_parm;
       Write pgmnamercd;
       //
       // Loop from 1 up to total number of modules in the argument program.
       //
       For NForIdx0001 = 1 to QCLNBRM;
          //
          // Retrieve next QBNL0100-type entry from the user space.
          //
          rtvusrspc(
                        user_space :
                        str_pos :
                        item_len :
                        QBNL0100 :
                        QUSEC
                       );
          //
          // Write qualified module name to the printer file.
          //
          m_lib_name = QBNBMLN;
          mod_name = QBNBMN;
          Write modnamercd;
          //
          // Advance offset to next QBNL0100-type entry in the user space.
          //
          str_pos = str_pos + item_len;
       EndFor;                                                                  // 1..QCLNBRM
       //
       // End of output.
       //
       Close bnlpgmiprt;
       //
       // Delete user space.
       //
       dltusrspc(
                     user_space :
                     QUSEC
                    );
       *inlr = *on;
       //
       // Definition of subprocedure to convert object names to upper case.
       //
       Dcl-Proc lower_to_upper export;
       //
          Dcl-Pi lower_to_upper Char(10);
             pi_mixed_str    like(unqual_name) value;
          End-Pi;
       //
          Dcl-C up              'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
          Dcl-C lo              'abcdefghijklmnopqrstuvwxyz';
          Dcl-S intermediate    like(unqual_name);
       //
          intermediate = %XLate(lo:up:pi_mixed_str);
          Return intermediate;
          //
       End-Proc lower_to_upper; 
Compile with CRTBNDRPG.
Call from command line:
CALL PGM(BNLPGMRPG2) PARM(('MATHTEST  ') ('BIMBRA    '))
Display the spoolfile to examine the result.
 
image-20241125213610-1

[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m0z0000000CHtAAM","label":"Programming ILE Languages"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]

Historical Number

19955317

Document Information

Modified date:
25 November 2024

UID

nas8N1017729