Retrieving values

163 Views


Retrieving values that can be used as variables

You can retrieve values, such as system values and job attributes, to use as variables in a program or procedure.

Retrieving system values A system value contains control information for the operation of certain parts of the system. IBM supplies several types of system values.

For example, QDATE and QTIME are date and time system values, which you set when the IBM i operating system is started.

You can bring system values into your program or procedure and manipulate them as variables using the Retrieve System Value (RTVSYSVAL) command:

RTVSYSVAL SYSVAL(system-value-name) RTNVAR(CL-variable-name)

The CL variable for returned value (RTNVAR) parameter specifies the name of the variable in your CL program or procedure that is to receive the value of the system value.

Example: Retrieving QTIME system value:

In this example, QTIME is received and moved to a variable.

RTVSYSVAL  SYSVAL(QTIME)    RTNVAR(&SYSTIME)    
CHGVAR     VAR(&YY) VALUE(%SST(&SYSDATE 5 2))   
CHGVAR     VAR(&MM) VALUE(%SST(&SYSDATE 1 2))   
CHGVAR     VAR(&DD) VALUE(%SST(&SYSDATE 3 2))   
                                                
0119.00 /* Check if the file has been uploaded 2 mins before for cur time */ 
0120.00              RTVSYSVAL  SYSVAL(QTIME) RTNVAR(&LTIME)                                                                               
0127.00              IF         COND(&LTIME *LT 120) THEN(DO)             
0128.00              GOTO       CMDLBL(START)                              
0129.00              ENDDO                                                   

Retrieving the QDATE system value into a CL variable:

QDATE is received and moved to a variable.

0009.00              PGM     
0010.00              DCLPRCOPT  DFTACTGRP(*NO) ACTGRP(*CALLER)
0017.00              DCL        VAR(&JOBDATE) TYPE(*CHAR) LEN(6) 
0018.00              RTVSYSVAL  SYSVAL(QDATE) RTNVAR(&JOBDATE)   
0144.00               RTVSYSVAL  SYSVAL(QDATE) RTNVAR(&QDATE)                   
0145.00               RTVSYSVAL  SYSVAL(QTIME) RTNVAR(&QTIME)                   
0146.00               CHGVAR     VAR(&TEXT) VALUE(&MLNAME *BCAT 'Transmitted +  
0147.00                           on' *BCAT &QDATE *BCAT 'at' *BCAT &QTIME)     

 

Convert Date (CVTDAT)

To convert the format of a date in a CL program or procedure, use the Convert Date (CVTDAT) command.

The format for the system date is the system value QDATFMT.

The format for the Convert Date (CVTDAT) command is:

CVTDAT DATE(date-to-be-converted) TOVAR(CL-variable) +

FROMFMT(old-format) TOFMT(new-format) +

TOSEP(new-separators)

CVTDAT DATE(&DATE) TOVAR(&CVTDAT) FROMFMT(*MDY) TOFMT(*DMY)
TOSEP(*SYSVAL)

The date separator remains as specified in the system value QDATSEP.

dspsysval QDATSEP  

0044.00 /* Populate Date in *CYMD format */                                   
0045.00              CVTDAT     DATE(&DATE) TOVAR(&JOBDATE) FROMFMT(*MDY) +   
0046.00                           TOFMT(*CYMD) TOSEP(*NONE)                   
0109.00 /* Convert From Date and Thru Date to 7 Length Format.               */   
0110.00              CVTDAT     DATE(&TEST8) TOVAR(&TEST7) +            
0111.00                           FROMFMT(*YYMD) TOFMT(*CYMD) TOSEP(*NONE)        
0042.00              CVTDAT     DATE(&TESTDT) TOVAR(&TEMPDATE) + 
0043.00                           FROMFMT(*YYMD) TOFMT(*USA)        
0500.00        /* Entry Parm &FrmDate =should be valid adte in fmt: YYYYMMDD  */         
0510.00        Cvtdat &FrmDate ToVar(&FrmDate) FromFmt(*YYMD) ToFMt(*YYMD) ToSep(*None)  
0520.00        Monmsg Msgid(Cpf0500) Exec(SndPgmMsg +                                    
0530.00               MsgID(CPF9898) MsgF(QCPFMSG) MsgType(*ESCAPE) +                    
0540.00               Msgdta('Entry Parm FRMDATE (YYYYMMDD) is invalid:' *bcat +         
0550.00               &FrmDate ))                                                        

The Convert Date (CVTDAT) command can be useful when creating objects or adding a member that uses a date as part of its name.

PGM
DCL &DATE6 *CHAR LEN(6)
DCL &DATE5 *CHAR LEN(5)
RTVSYSVAL QDATE RTNVAR(&DATE6)
CVTDAT DATE(&DATE6) TOVAR(&DATE5) TOFMT(*JUL) TOSEP(*NONE)
ADDPFM LIB1/FILEX MBR(’MBR’ *CAT &DATE5)
.
.
.
ENDPGM

If the current date is 5 January 1988, the added member would be named MBR88005.

1. For Non-Julian Dates possessing 2-digit years

a. Use six characters when using no separators. July 28, 1978 would be written as 072878.

b. Use 8 characters when using separators. July 28, 1978 would be written as 07-28-78.

2. For Non-Julian Dates with 4-digit years

a. Use eight characters when using no separators. July 28, 1978 would be written as 07281978.

b. Use ten characters when using separators. July 28, 1978 would be written as 07-28-1978.

3. For Julian dates with 2–digit years

a. Use five characters when using no separators. December 31, 1996 would be written as 96365.

b. Use six characters when using separators. December 31, 1996 would be written as 96-365.

4. For Julian dates with 4–digit years,

a. Seven characters are required when no separators are used. February 4, 1997 would be written as 1997035.

b. Eight characters are required when separators are used. February 4, 1997 would be written as 1997-035.

 

Retrieving configuration source

Using the Retrieve Configuration Source (RTVCFGSRC) command, you can generate CL command source for creating existing configuration objects and place the source in a source file member.

Retrieving configuration status

Using the Retrieve Configuration Status (RTVCFGSTS) command, you can give applications the capability to retrieve configuration status from three configuration objects: line, controller, and device.

Retrieving network attributes

Using the Retrieve Network Attributes (RTVNETA) command, you can retrieve the network attributes of the system.

These attributes can be changed using the Change Network Attributes (CHGNETA) command and displayed using the Display Network Attributes (DSPNETA) command.

0049.04     RTVNETA    SYSNAME(&SYS)                                        
0049.05     CHGVAR     VAR(&SYSNAME) VALUE(%SUBSTRING(&SYS 1 6))            
0049.06                                                                     
0049.07     IF         COND(&SYSNAME *EQ 'TESTPRD') +                        
0049.08                THEN(DO)                                             
0018.00              RTVNETA    SYSNAME(&SYS)                                  
0019.00              CHGVAR     VAR(&SYSNAME) VALUE(%SUBSTRING(&SYS 1 6))      
0020.00                                                                        
0021.00              IF         COND((&SYSNAME *EQ 'TESTPRD') *OR (&SYSNAME +   
0022.00                           *EQ 'TSTDEV')) THEN(DO)                      
0023.00              CHGVAR     VAR(&SYSNM) VALUE('Y')                         
0024.00              ENDDO                                                     

 

Retrieving job attributes

To retrieve the job attributes and place their values in a CL variable to control your applications, use the Retrieve Job Attributes (RTVJOBA) command.

With this command you can retrieve all job attributes or any combination of them.

In the following CL procedure, a Retrieve Job Attributes (RTVJOBA) command retrieves the name of the user who called the procedure.

0035.00 /* Retrieve job attributes */          
0036.00              RTVJOBA    TYPE(&TYPE)    
0035.00 /* Retrieve job attributes */                                     
0036.00              RTVJOBA    TYPE(&TYPE)                               
0037.00 /* IF THE JOB IS INTERACTIVE, SUBMIT THE JOB           */         
0038.00              IF         COND(&TYPE *EQ '1') THEN(DO)              
0039.00              SBMJOB     CMD(CALL PGM(TESTPGM))  JOB(TESTJOB)  
0040.00              GOTO       CMDLBL(END)                               
0041.00              ENDDO                                                
0044.00              RTVJOBA    TYPE(&TYPE) DATE(&DATE) 
 
0028.00              RTVJOBA    USRLIBL(&BFRLIBL)  
 
0410.00              Rtvjoba    Datetime(&Sysdate)    

0041.00              RTVJOBA    USER(&USER) DATE(&DATE) TYPE(&TYPE)   +   
0042.00                         CYMDDATE(&SYSDATE)  
                      
0080.00              RTVJOBA    JOB(&JobName) TYPE(&Type) 
 
0098.00              RTVJOBA    JOB(&JOBNAME) USER(&JOBUSER) NBR(&JOBNUM) +  
0099.00                           DATE(&DATE)                                
0100.00                                                                      
0018.00              RTVJOBA    CYMDDATE(&CYMD7A) 
        
0036.00              RTVJOBA    USER(&USRI) TYPE(&JOBT)               

Assume in the following CL procedure, an interactive job submits a program including the CL procedure to batch. A Retrieve Job Attributes (RTVJOBA) command retrieves the name of the message queue to which the job's completion message is sent, and uses that message queue to communicate with the user who submitted the job.

PGM
DCL &MSGQ *CHAR 10
DCL &MSGQLIB *CHAR 10
DCL &MSGKEY *CHAR 4
DCL &REPLY *CHAR 1
DCL &ACCTNO *CHAR 6
.
.
.
RTVJOBA SBMMSGQ(&MSGQ) SBMMSGQLIB(&MSGQLIB)
IF (&MSGQ *EQ ’*NONE’) THEN(DO)
    CHGVAR &MSGQ ’QSYSOPR’
    CHGVAR &MSGQLIB ’QSYS’
ENDDO
.
.
. Control language 223
IF (. . . ) THEN(DO)
SNDMSG:SNDPGMMSG MSG(’Account number ’ *CAT &ACCTNO *CAT ’is +
                     not valid. Do you want to cancel the update +
                     (Y or N)?’) TOMSGQ(&MSGQLIB/&MSGQ) MSGTYPE(*INQ) +
                    KEYVAR(&MSGKEY)
RCVMSG MSGQ(*PGMQ) MSGTYPE(*RPY) MSGKEY(&MSGKEY) +
MSG(&REPLY) WAIT(*MAX)
IF (&REPLY *EQ ’Y’) THEN(RETURN)
ELSE IF (&REPLY *NE ’N’) THEN(GOTO SNDMSG)
ENDDO
.
.
.

Retrieving user profile attributes

Using the Retrieve User Profile (RTVUSRPRF) command, you can retrieve the attributes of a user profile (except for the password) and place their values in CL variables to control your applications.

This example shows how to retrieve user profile information by using the Retrieve User Profile (RTVUSRPRF) command.

0008.00              PGM        PARM(&USRPRF &TEXT &FLAG)                  
0009.00                                                                    
0010.00              DCL        VAR(&USRPRF) TYPE(*CHAR) LEN(10)           
0011.00              DCL        VAR(&TEXT)   TYPE(*CHAR) LEN(50) VALUE(' ')
0013.01              MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(EXIT))          
0014.00              RTVUSRPRF  USRPRF(&USRPRF) TEXT(&TEXT)                     
0015.00              MONMSG     MSGID(CPF2204) EXEC(DO)                         
0016.00              CHGVAR     VAR(&FLAG) VALUE('N')                           
0017.00              ENDDO                                                      
0018.00                             
0019.00  EXIT:       ENDPGM         

 

Retrieving member description information

Using the Retrieve Member Description (RTVMBRD) command, you can retrieve information about a member of a database file for use in your applications.

Example: Using the Retrieve Member Description command:

This example shows how to retrieve member description information by using the Retrieve Member Description (RTVMBRD) command.

DCL &LIB TYPE(*CHAR) LEN(10)
DCL &MBR TYPE(*CHAR) LEN(10)
DCL &SYS TYPE(*CHAR) LEN(4)
DCL &MTYPE TYPE(*CHAR) LEN(5)
DCL &CRTDATE TYPE(*CHAR) LEN(13)
DCL &CHGDATE TYPE(*CHAR) LEN(13)
DCL &TEXT TYPE(*CHAR) LEN(50)
DCL &NBRRCD TYPE(*DEC) LEN(10 0)
DCL &SIZE TYPE(*DEC) LEN(10 0)
DCL &USEDATE TYPE(*CHAR) LEN(13)
DCL &USECNT TYPE(*DEC) LEN(5 0)
DCL &RESET TYPE(*CHAR) LEN(13)
.
.
.
RTVMBRD FILE(*CWeb siteIB/MYFILE) MBR(AMEMBER *NEXT) +
             RTNLIB(&LIB) RTNSYSTEM(&SYS) RTNMBR(&MBR) +
             FILEATR(&MTYPE) CRTDATE(&CRTDATE) TEXT(&TEXT) +
             NBRCURRCD(&NBRRCD) DTASPCSIZ(&SIZE) USEDATE(&USEDATE) +
             USECOUNT(&USECNT) RESETDATE(&RESET)
0066.00 /* RETREIVE MEMBER COUNT*/                                            
0067.00              RTVMBRD    FILE(&LIB/&FILE) MBR(*LAST) RTNMBR(&LASTMBR) +
0068.00                           NBRCURRCD(&COUNT)    
------------------------------------------------------------------------                       
0207.00              RTVMBRD    FILE(&TRNLIB/&FILENAME) MBR(*LAST) +        
0208.00                           RTNMBR(&OLDMBR)                         
0086.00 /* Check if the Input file has records                             */          
------------------------------------------------------------------------                       
0087.00              RTVMBRD    FILE(&ILIB/TESTP) NBRCURRCD(&TOTALRECS) 
------------------------------------------------------------------------                                     
0063.00              RTVMBRD    FILE(&ILIB/TESTP) MBR(&MLNAME) TEXT(&TXT) 
------------------------------------------------------------------------                                               
0089.00              RTVMBRD    FILE(&LIB/&FILE) MBR(&MEMBER) CRTDATE(&CRTDATE)       
------------------------------------------------------------------------                       
0029.00              RTVMBRD    FILE(&LIB/TESTP) MBR(&TNAME) +     
0030.00                           NBRCURRCD(&NBRRCD)                
0031.00              IF         COND(&NBRRCD *EQ 0) THEN(DO)        
0032.00              RMVM       FILE(&LIB/TESTP) MBR(&TNAME)       
0033.00              GOTO       CMDLBL(EXIT)                        
0034.00              ENDDO                                          

 

Post Comments