• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Get to Know Some Powerful CL Commands

    October 12, 2005 Bruce Guetzkow

    I use CL (and now CLLE) procedures, rather than RPG, to do as much work as I can. It’s usually quicker to write CL than RPG because IBM has given us a great wealth of commands that perform all kinds of activities. Perhaps the most powerful commands are the RTV (Retrieve) commands, which retrieve information about objects (e.g., libraries and files) and non-objects (e.g., jobs and file members) alike. The Retrieve commands can only be used in CL, CLLE, and REXX procedures. Here’s a sampling of some of the data that you can retrieve.

    RTVJOBA: Retrieve Job Attributes. This command retrieves information about the job in which it is running.

    Here are some of my favorite values that can be retrieved:

    • JOB, USER, NUMBER: These values uniquely identify the currently running job and can be used in other commands to get even more information.
    • DATE: This is the job date, which is the date the job started, in the job-date format. Be aware that if your job begins before midnight and ends after, this date does not change.
    • TYPE: If you need to do different processing based on whether the job is running interactively or in batch, this value can be tested. A ‘0’ indicates batch, ‘1’ is interactive.
    • CURUSER: You can get the user profile that is running the job from this value.
    • DATETIME: If you need more than just the job date, this value contains the date and time in the format YYYYMMDDHHNNSSXXXXXX which has the time down to microseconds. If you want the job date in YYYYMMDD format, you can extract the first eight characters directly from this value.

    Here’s an example:

    RTVJOBA JOB(&JOB)          
       USER(&USER)
       NBR(&NBR)
       DATE(&DATE)
       TYPE(&TYPE)
       CURUSER(&CURUSER)
       DATETIME(&DATETIME)
    

    RTVOBJD: Retrieve Object Description. Specify an object and object type and you can find out lots of valuable information.

    • RTNLIB: This value will tell you the library where the object resides. This is especially useful if you specify *LIBL for the object name and need to determine the library in which the object is stored.
    • OBJATR: If the object specified is of certain types (e.g., a program or file), this value will identify the type of object (RPG, COBOL, PF, LF, etc.).
    • TEXT: This is the text used to describe the object when it was created.
    • OWNER: This value indicates the current owner of the object.
    • CRTDATE: If you need to know the date and time that an object was created, this value contains that information in the format CYYMMDDHHMMSS.
    • CRTUSER: As you might have guessed, this is the user that created the object.


    The following example illustrates RTVOBJD.

    RTVOBJD OBJ(your-library/your-object)
       OBJTYPE(*FILE)
       RTNLIB(&RTNLIB)
       OBJATR(&OBJATR)
       TEXT(&TEXT)
       OWNER(&OWNER)
       CRTDATE(&CRTDATE)
       CRTUSER(&CRTUSER)
    

    RTVMBRD: Retrieve Member Description. Specify a file (and optionally a member) and you can find out more about that file.

    • RTNLIB: This value will tell you the library where the file resides. Like RTVOBJD, this parameter is especially useful if you specify *LIBL for the file name and need to determine the library.
    • RTNMBR: Just like the previous parameter, if you didn’t specify a member by name, this value will contain that member name.
    • SRCTYPE: If the file is a source file, this value will contain the source type of the specified member.
    • TEXT: This is the text used when the member was created.
    • NBRCURRCD: This is perhaps my favorite parameter from all of the RTV commands. Many times I only need to perform actions if a file actually has data in it. This value contains the current number of data records in the file and member specified.

    Here’s an example of the RTVMBRD command.

    RTVMBRD FILE(your-library/your-file)
       MBR(*FIRSTMBR)
       RTNLIB(&RTNLIB)
       RTNMBR(&RTNMBR)
       SRCTYPE(&SRCTYPE)
       TEXT(&TEXT)
       NBRCURRCD(&NBRCURRCD)
    

    The RTVMBRD command can be used in a loop to process all members of a multi-member file (physical or source). On the first execution of the command specify the MBR parameter as MBR(*FIRST *SAME) (to process in creation-date order) or MBR(*FIRSTMBR *SAME) (to process in alphabetical-name order). On subsequent executions of the command, specify MBR(&RTNMBR *NEXT). Be sure to specify parameter RTNMBR each time you execute the command so that you’ll have the value for the next iteration. Alternatively you can specify MBR(*LAST *SAME) or MBR(*LASTMBR *SAME) followed by MBR(&RTNMBR *PRV) to read through the members in reverse order.

    The following short example illustrates how to process all members of a file in alphabetical order.

    Pgm                                                                     
                                                                            
       Dcl  &Member    *char   10                                           
       Dcl  &Position  *char   10                                           
       Dcl  &CurUser   *char   10                                           
       Dcl  &RtnMbr    *char   10                                           
                                                                            
       RtvJobA   curuser(&CurUser)                                          
                                                                            
       /* process members in alphabetical order */
       ChgVar    &Member     *FIRSTMBR                                      
       ChgVar    &Position   *SAME                                          
                                                                            
    NextMember:                                                             
       RtvMbrD   file(SomeFile) mbr(&Member &Position) rtnmbr(&RtnMbr)
       MonMsg    cpf3049 exec(goto EndOfFile)                               
                                                                            
       /* place commands to process &RtnMbr here */
       SndMsg msg('Processing member' *bcat &RtnMbr *tcat '.') +            
                 tousr(&CurUser)                                            
                                                                            
       /* move to the next member */
       ChgVar    &Member     &RtnMbr
       ChgVar    &Position   *NEXT 
       goto NextMember             
                                   
    EndOfFile:                     
                                   
    EndPgm
    

    It doesn’t get much easier than that. You can specify as few or as many parameters for the RTV commands as you like; just remember to define the return variables. When you prompt on the command the parameter descriptions tell you the variable sizes. If you want to see all of the RTV commands available, just go to a command line, key in RTV*, press Enter, explore, and enjoy!

    Bruce Guetzkow has programmed on the AS/400 and iSeries since 1990, in manufacturing, distribution, and other industries. He is currently the IS director at United Credit Service in Elkhorn, Wisconsin. Click here to contact Bruce by e-mail.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    ARCAD Software

    Are you ready for AI on the IBM i? Optimization and guardrails. . .

    what you need to know today

    with Jeff Tickner

    As organizations assess the role and impact of AI, they must make informed choices, particularly around implementing guardrails to ensure secure and controlled usage.

    In this Lunch & Learn session, Jeff Tickner, CTO North America of ARCAD Software, and Alan Ashley, Sr. Solution Architect, will explore how to effectively prepare for the adoption of AI in IBM i environments.

    This session will cover key AI considerations, including:

    • Preparing source
    • Defining security rules and ensuring data privacy
    • Leveraging MCP Servers for optimization

    A deeper dive will also address:

    • The use of MCP Servers with BOB and other AI assistants
    • ARCAD’s approach to integrating AI into DevOps processes through MCP

    Register Now!

    By registering for this session, I acknowledge that my contact information will be shared with the sponsor, ARCAD.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Absolute Versus Relative Paths Admin Alert: Reader Feedback on Limiting Users with *ALLOBJ Authority

    Leave a Reply Cancel reply

Volume 5, Number 38 -- October 12, 2005
THIS ISSUE
SPONSORED BY:

Advanced Systems Concepts
iSeries DevCon 2005
DRV Technologies

Table of Contents

  • Absolute Versus Relative Paths
  • Get to Know Some Powerful CL Commands
  • Admin Alert: Reader Feedback on Limiting Users with *ALLOBJ Authority

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Power Systems Still Waiting For The GenAI Bump
  • The IBM i and the Hybrid Cloud World: Things To Keep In Mind
  • CData Adds Db2 for i Support to CDC Tool
  • As I See It: The Cost of Having Ethics
  • Brace Yourself: Another Power Systems Price Hike Coming May 1
  • Updates Announced for IBM i BRMS And SMTP Email Client
  • AI Will Be Front And Center At POWERUp 2026 Next Week
  • IBM i PTF Guide, Volume 28, Number 16
  • Spring IBM i Tech Refreshes Will Come A Bit Later This Year
  • You Are Much More Than Power Systems, And So Are We

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle