• 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
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Aldon Supports iASPs with Change Management System SEA and RevSoft End Partnership for OS/400 Utilities

    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

  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25
  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24

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