Show Library Size DirectoryDirectory .ZIP
These source modules are examples of using the Retrieve Library Description (QLIRLIBD) API to get the size of a library and display it in a message. The SHOLIBSIZ CLP and command demonstrate how to use the remaining objects.
The API is shelled by the RTVLIBSIZ command. The parms of the command are set to retrieve two of the variable length records available from the API. That makes the RTVLIBSIZ command pretty limited in use, but it's a reasonable use and provides a simple example of handling variable records from an API.Note: If the library is large, the QLIRLIBD API can take a very long time to complete. Although the API might be the fastest and most efficient way to return the information, it apparently must still look at each library entry. Also note that files with large numbers of members cause delays as well.
Please read the @GENERAL DISCLAIMER document for any items you should be aware of if you download any of these items.
JSTLFT -- Justify Left:This program takes a string and performs left-justification on it. The operation is done in place, so the incoming parm is changed. There's nothing special here; I just wanted the values in the message displayed by SHOLIBSIZ to look clean. There are probably dozens of better ways to do a left-justify, but it wasn't worth thinking about. Leading blanks are counted and the parm is set to the remaining substring.
SHOLIBSIZ -- Show Library Size:This program combines the result of RTVLIBSIZ with RTVOBJD SIZE() to build a message that shows the aggregate size of a library along with the size of the *LIB object and a count of objects in the library.
The message is built after using some Edit Function APIs to make the numeric values look nicer. I originally put the editing commands together in order to build a replacement for the EDTVAR command that was part of QUSRTOOL.
CVTEDTCDE -- Convert Edit Code (QECCVTEC) API:The command definition object source for CVTEDTCDE encapsulates the QECCVTEC API. It accepts parms for zero-balance fill character, edit code, floating currency symbol, source precision and source decimal precision and returns an edit mask, the length of the edit mask and the length that would result from using the edit mask.
Use this command to first select an edit code and then get the edit mask that the edit code results in. The edit mask is then used to do the actual editing with the EDTVAROBJ command (or QECEDT API).
CVTEDTWRD -- Convert Edit Word (QECCVTEW) API:The command definition object source for CVTEDTWRD encapsulates the QECCVTEW API. It accepts parms for edit word and edit word length and returns an edit mask, the length of the edit mask and the length that would result from using the edit mask.
Use this command to first select an edit word and then get the edit mask that the edit word results in. The edit mask is then used to do the actual editing with the EDTVAROBJ command (or QECEDT API).Note: CVTEDTWRD is not used in the examples here. It is included for completeness only.
EDTVAROBJ -- Edit (QECEDT) API:The command definition object source for EDTVAROBJ encapsulates the QECEDT API. It accepts parms for receiver length, source variable, source variable class, source precision, edit mask, edit mask length and zero-balance fill character and returns the receiver variable value (the edited value). This performs the actual editing.
Source variable class allows *ZONED, *PACKED and *BINARY. Because we're using a command shell in a CLP, *PACKED and *BINARY are more difficult to use although possible. I suspect most commonly a CL *DEC variable value will be converted to *CHAR and passed into the command as *ZONED class.
JSTLFT -- Justify Left:The command definition object source for JSTLFT encapsulates the JSTLFT CLP. The command accepts a string and a string length. Up to the length specified, leading blanks are removed from the string and the string is shifted to the left. If any blanks are removed, the string value is changed when the command returns.
RTVLIBSIZ -- Retrieve Library Description (QLIRLIBD) API:The command definition object source for RTVLIBSIZ encapsulates the QLIRLIBD API. The command parms are fixed to retrieve only the 'library size information' and 'number of objects in library' variable records from the API. This is a deliberate limitation because this is first only an example and second, well, it works fine for its intended purpose.
The variable records are returned to the CL variable named on the LIBSIZDTA() parm. The value returned is a structure that includes some structure information fields and two variable records. One variable record is the key ID 6, library size information, record. The second is the key ID 7, number of objects in library, record.
Documentation for QLIRLIBD tells that 'library size information' includes the aggregate size of all objects in the library plus the size of the library (*LIB) object in QSYS. The key ID 6 record is a structure that contains two subfields that must be multiplied together to get the actual size.
SHOLIBSIZ -- Show Library Size:The command definition object source for SHOLIBSIZ encapsulates the SHOLIBSIZ CLP. The command accepts a single parameter for library name. An information message is sent to the *EXT message queue with the size information.