What is the use of RTVJOBA and RTVMSG?

Both RTVJOBA and RTVMSG are CL commands in IBM i (formerly AS400) used to retrieve information, but they target different types of information:

1. RTVJOBA (Retrieve Job Attributes)

  • Purpose: RTVJOBA is used to retrieve various attributes of a job currently running on the system. This information can then be stored in CL variables and used to control the flow or behavior of your CL program.
  • Common Uses:
    • Determining job type: You can retrieve the job type (interactive or batch) and perform different actions accordingly.
    • Getting user information: You can retrieve the name of the user who submitted the job.
    • Checking job status: You can check if a job is active, waiting in a job queue, or has completed.
    • Retrieving output queue information: You can get the name of the output queue associated with the job.
    • Accessing system values: You can indirectly access system values that are related to the job.
  • Key Parameters:
    • JOB: Specifies the job for which to retrieve attributes (defaults to the current job).
    • USER: Specifies the user of the job.
    • NBR: Specifies the job number.
    • TYPE: Specifies the type of job (e.g., *INT for interactive, *BAT for batch).
    • STATUS: Specifies the status of the job (e.g., *ACTIVE, *JOBQ, *OUTQ).
    • OUTQ: Specifies the output queue.
    • INLLIBL: Specifies the initial library list.
    • CURLIB: Specifies the current library.
    • RTGDTA: Specifies the routing data.
  • Example :
  • RTVJOBA USER(&USER) TYPE(&JOBTYPE)
    IF (&JOBTYPE *EQ '*INT') THEN(DO)
        /* Perform interactive processing */
    ENDDO
    ELSE(DO)
        /* Perform batch processing */
    ENDDO
  • This example retrieves the user and job type and then performs different actions based on whether the job is interactive or batch.


2. RTVMSG (Retrieve Message)

  • Purpose: RTVMSG is used to retrieve the text of a message from a message file. This allows you to dynamically display messages to users or use message text in your programs.
  • Common Uses:
    • Displaying messages: You can retrieve the text of a predefined message and display it to the user using SNDUSRMSG.
    • Error handling: You can retrieve the text of an error message and include it in your error handling routines.
    • Internationalization: You can store messages in different message files for different languages and retrieve the appropriate message based on the user's locale.
  • Key Parameters:
    • MSGID: Specifies the message ID of the message to retrieve.
    • MSGF: Specifies the message file containing the message.
    • MSG: Specifies the CL variable where the message text will be stored.
    • MSGDTA: Specifies the message data to be substituted into the message text.
  • Example :
  • RTVMSG MSGID(CPF2812) MSGF(QCPFMSG) MSG(&MSGTEXT)
    SNDPGMMSG MSG(&MSGTEXT) MSGTYPE(*ESCAPE)
  •  
  • This example retrieves the text of message CPF2812 (File not found) from the QCPFMSG message file and stores it in the &MSGTEXT variable. It then sends an escape message containing this text.

Key Differences Summarized :

Feature RTVJOBA RTVMSG
Purpose Retrieve job attributes Retrieve message text
Target Job characteristics Message from a message file
Use Cases Job control, user information, status checks Displaying messages, error handling, internationalization

 

In essence:

  • RTVJOBA provides information about a job.
  • RTVMSG provides information from a message file.

Both commands are valuable tools in CL programming, enabling you to create more dynamic and responsive programs by accessing job attributes and retrieving message text.