The CL Corner: Controlling the CL Testing Environment

CL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Prompt override programs and database update from a CL program.

 

In our last column, "A Much More Flexible SNDESCAPE Program," we introduced the Add Test Case (ADDTSTCASE) command and significantly improved on the flexibility of the SNDESCAPE program. Today, we will implement the command Change Test Case (CHGTSTCASE).

 

The command definition for CHGTSTCASE is shown below:

 

 

             CMD        PROMPT('Change Test Case')                    

             PARM       KWD(CMD) TYPE(*NAME) LEN(10) MIN(1) +         

                          KEYPARM(*YES) PROMPT('Command to test')     

             PARM       KWD(PGM) TYPE(*NAME) LEN(10) MIN(1) +         

                          KEYPARM(*YES) PROMPT('Program to test')     

             PARM       KWD(USER) TYPE(*NAME) LEN(10) DFT(*CURUSR) +  

                          SPCVAL((*CURUSR)) KEYPARM(*YES) +           

                          PROMPT('Profile running test')              

             PARM       KWD(MSGID) TYPE(*NAME) LEN(7) DFT(*SAME) +    

                          SPCVAL((*SAME)) PROMPT('Message for testing')

             PARM       KWD(MSGF) TYPE(QUALNAME) PROMPT('Message file')

 QUALNAME:   QUAL       TYPE(*NAME) DFT(*SAME) SPCVAL((*SAME))        

             QUAL       TYPE(*NAME) DFT(*SAME) SPCVAL((*SAME) +       

                          (*LIBL)) PROMPT('Library')                  

 

The CHGTSTCASE command requires two parameters: the name of the command being tested and the name of the program under test. The remaining parameters are optional. The USER parameter defaults to the current user of the command. The remaining parameters, MSGID and MSGFILE, default to the special value *SAME.

 

Notice that the keywords CMD, PGM, and USER are defined as key parameters in the definition of CHGTSTCASE. This is done so that a Prompt Override Program (POP) can be provided, allowing you to see what test values are being changed. The three key parameters are passed to the POP, among other parameters, so that the associated test values can be shown when prompting the CHGTSTCASE command. The POP program, CHGTSTPOP, is shown below:

 

 

(A) Pgm        Parm(&CmdName &TestCmd &TestPgm &TestUsr &Cmd_Parms)   

    Dcl        Var(&CmdName)    Type(*Char) Len(20)                   

     Dcl        Var(&Cmd)        Type(*Char) Len(10) Stg(*Defined) +  

                                 DefVar(&CmdName)                     

(B) Dcl        Var(&Cmd_Parms ) Type(*Char) Len(5002)                 

     Dcl        Var(&Len_Parms)  Type(*Int) Len(2) Stg(*Defined) +    

                                 DefVar(&Cmd_Parms)                    

     Dcl        Var(&Parms)      Type(*Char) Len(5000) Stg(*Defined) +

                                 DefVar(&Cmd_Parms 3)                 

                                                                      

    DclFCLF    FileID(ActCmdTsts)                                     

    Dcl        Var(&RNF)       Type(*Lgl)                             

    Dcl        Var(&Parm_Len)  Type(*Int)                             

                                                                       

(C) If         Cond(&Cmd *EQ CHGTSTCASE) Then(Do)                     

               OpnFCLF ActCmdTsts AccMth(*Key)                        

               If Cond(&TestUsr = *CURUSR) Then( +                    

                    RtvJoba CurUser(&TestUsr))                        

(D)            ReadRcdCLF ActCmdTsts Type(*Key) KeyRel(*EQ) +         

                            KeyList(&TestCmd &TestUsr &TestPgm) +     

                            RcdNotFnd(&RNF)                           

               CloFCLF ActCmdTsts                                     

                                                                      

(E)            If Cond(*Not &RNF) Then(Do)                            

                  ChgVar Var(&Parms) Value( +                         

                         'MSGID(' *TCat &TestMsg *TCat +              

                         ') MSGF(' *TCat &TestMsgFL *TCat +           

                         '/' *TCat &TestMsgF *TCat ')')               

                  RtvVarLen  Var(&Parms) Length(&Parm_Len)            

                  ChgVar Var(&Len_Parms) Value(&Parm_Len)             

                  EndDo                                               

               Else Cmd(Do)                                            

                  SndPgmMsg Msg('Test case not found') MsgType(*Diag) 

                  SndPgmMsg MsgID(CPF0011) MsgF(QCPFMSG) + 

                              MsgType(*Escape)             

                  EndDo                                     

               EndDo                                       

    Return                                                 

    Endpgm                                                 

 

When prompting is requested for CHGTSTCASE, the CHGTSTPOP program will be called with the five parameters shown at (A). The first parameter, &CMDNAME, is an input parameter providing the qualified name of the command being prompted (CHGTSTCASE). The next three parameters are also input parameters and correspond to the three KEYPARM parameters PGM, CMD, and USER. These values will be used to read the associated test record in the ACTCMDTSTS file. The last parameter, &CMD_PARMS, is a 5002-byte output parameter used to return the values found in the ACTCMDTSTS record. &CMD_PARMS is actually a structure in which the first 2 bytes represent the length of the values being returned and bytes 3 through 5002 the actual values to be shown in keyword format. The structure definition of &CMD_PARMS is shown at (B).

 

After verifying at (C) that the CHGTSTCASE command is being prompted, CHGTSTPOP attempts at (D) to read a record from the ACTCMDTSTS file where the key values are equal to the specified &TESTPGM, &TESTCMD, and &TESTUSR values. If a record is found, the condition at (E) is true, and the read values for &TESTMSG, &TESTMSGF, and &TESTMSGFL are returned in keyword form to the i command prompter. The length of the formatted string is determined using the Retrieve Variable Length (RTVVARLEN) command, which was previously introduced in the article "The CL Corner: Understanding the CHKKILL Program, Continued." If a record is not found, an appropriate diagnostic message is logged to the job log.

 

To create the CHGTSTPOP program into library VINING, you can use this command:

 

CRTBNDCLF PGM(VINING/CHGTSTPOP)

 

This is the source for the CHGTSTCASE CPP, CHGTSTCPP:

 

 

    Pgm        Parm(&TestCmd &TestPgm &TestUsr &NewMsg &NewMsgF)    

    Dcl        Var(&NewMsg)     Type(*Char) Len(7)                  

    Dcl        Var(&NewMsgF)    Type(*Char) Len(20)                 

     Dcl        Var(&MsgF)     Type(*Char) Len(10) Stg(*Defined) +  

                               DefVar(&NewMsgF 1)                   

     Dcl        Var(&MsgFL)    Type(*Char) Len(10) Stg(*Defined) +  

                               DefVar(&NewMsgF 11)                  

                                                                     

    DclFCLF    FileID(ActCmdTsts)                                   

    Dcl        Var(&RNF)      Type(*Lgl)                            

                                                                    

    If         Cond(&TestUsr = *CURUSR) Then( +                     

               RtvJobA CurUser(&TestUsr))                           

                                                                    

    OpnFCLF    FileID(ActCmdTsts) AccMth(*Key) Usage(*Both)          

                                                                    

    ReadRcdCLF ActCmdTsts Type(*Key) KeyRel(*EQ) +                

                 KeyList(&TestCmd &TestUsr &TestPgm) +            

                 RcdNotFnd(&RNF)                                   

                                                                  

    If         Cond(&RNF) Then(SndPgmMsg Msg( +                   

                          'Testcase' *BCat &TestPgm *BCat +       

                          &TestCmd *BCat +                        

                          'not found for user' *BCat &TestUsr))   

    Else       Cmd(Do)                                            

               If Cond(&NewMsg *NE *Same) Then( +                 

                  ChgVar Var(&TestMsg) Value(&NewMsg))            

               If Cond(&MsgF *NE *Same) Then( +                   

                  ChgVar Var(&TestMsgF)  Value(&MsgF))            

               If Cond(&MsgFL *NE *Same) Then( +                   

                  ChgVar Var(&TestMsgFL) Value(&MsgFL))           

                                                                  

               UpdRcdCLF ActCmdTsts                               

               SndPgmMsg Msg('Testcase' *BCat &TestPgm *BCat +     

                         &TestCmd *BCat 'changed for user' *BCat + 

                         &TestUsr)                                 

               EndDo                                               

                                                                    

    CloFCLF    ActCmdTsts                                          

                                                                   

    Return                                                         

    EndPgm                                                         

 

 

The CHGTSTCPP program, after determining which test values are to be changed, updates the associated ACTCMDTSTS record with the new values. The one new command used by the program, Update Record using CLF (UPDRCDCLF), is documented here. If you have any difficulty understanding the program, you should review the ADDTSTCPP program of the previous article "The CL Corner: A Much More Flexible SNDESCAPE Program."

 

To create CHGTSTCPP into library VINING, you can use this command:

 

CRTBNDCLF PGM(VINING/CHGTSTCPP)

 

Having created both the CPP and POP for CHGTSTCASE, you can now also create the CHGTSTCASE command into VINING using this command:

 

CRTCMD CMD(VINING/CHGTSTCASE) PGM(VINING/CHGTSTCPP) PMTOVRPGM(VINING/CHGTSTPOP)

 

To change the test message for command DONOTHING in program MONESCAPE to CPF3012 (File &1 in library &2 not found), you can use the following command:

 

CHGTSTCASE CMD(DONOTHING) PGM(MONESCAPE) USER(VININGTEST)

 

If you request prompting with F4, you will see the existing MSGID value of CPF414E and you can then replace the value with CPF3012. Alternatively, you could bypass prompting with this command:

 

CHGTSTCASE CMD(DONOTHING) PGM(MONESCAPE) USER(VININGTEST) MSGID(CPF3012)

 

As with the previous article, here are the equivalent programs using CLF RPG-like CL commands and the base run-time support. The source lines that have been changed are highlighted.

CHGTSTPOP Using RPG-like Commands

 

    Pgm        Parm(&CmdName &TestCmd &TestPgm &TestUsr &Cmd_Parms)   

    Dcl        Var(&CmdName)    Type(*Char) Len(20)                   

     Dcl        Var(&Cmd)        Type(*Char) Len(10) Stg(*Defined) +  

                                 DefVar(&CmdName)                     

    Dcl        Var(&Cmd_Parms ) Type(*Char) Len(5002)                 

     Dcl        Var(&Len_Parms)  Type(*Int) Len(2) Stg(*Defined) +    

                                 DefVar(&Cmd_Parms)                   

     Dcl        Var(&Parms)      Type(*Char) Len(5000) Stg(*Defined) +

                                 DefVar(&Cmd_Parms 3)                 

                                                                      

    File       ActCmdTsts                                             

    Dcl        Var(&RNF)       Type(*Lgl)                             

    Dcl        Var(&Parm_Len)  Type(*Int)                             

                                                                      

    If         Cond(&Cmd *EQ CHGTSTCASE) Then(Do)                     

               Open ActCmdTsts AccMth(*Key)                            

               If Cond(&TestUsr = *CURUSR) Then( +                   

                    RtvJoba CurUser(&TestUsr))                       

               Chain (&TestCmd &TestUsr &TestPgm) ActCmdTsts +       

                            RcdNotFnd(&RNF)                          

               Close ActCmdTsts                                      

                                                                     

               If Cond(*Not &RNF) Then(Do)                           

                  ChgVar Var(&Parms) Value( +                        

                         'MSGID(' *TCat &TestMsg *TCat +             

                         ') MSGF(' *TCat &TestMsgFL *TCat +          

                         '/' *TCat &TestMsgF *TCat ')')              

                  RtvVarLen  Var(&Parms) Length(&Parm_Len)           

                  ChgVar Var(&Len_Parms) Value(&Parm_Len)            

                  EndDo                                              

               Else Cmd(Do)                                          

                  SndPgmMsg Msg('Test case not found') MsgType(*Diag)

                  SndPgmMsg MsgID(CPF0011) MsgF(QCPFMSG) +           

                              MsgType(*Escape)              

                  EndDo                                    

               EndDo                                       

    Return                                                 

    Endpgm                                                 

 

The previous program can be created into library VINING using the following command:

 

CRTBNDCLF PGM(VINING/CHGTSTPOP)

CHGTSTPOP Using Base Run-Time Support

 

    Pgm        Parm(&CmdName &TestCmd &TestPgm &TestUsr &Cmd_Parms)  

    Dcl        Var(&CmdName)    Type(*Char) Len(20)                  

     Dcl        Var(&Cmd)        Type(*Char) Len(10) Stg(*Defined) + 

                                 DefVar(&CmdName)                    

    Dcl        Var(&TestCmd)   Type(*Char) Len(10)                   

    Dcl        Var(&TestPgm)   Type(*Char) Len(10)                   

    Dcl        Var(&TestUsr)   Type(*Char) Len(10)                   

    Dcl        Var(&Cmd_Parms ) Type(*Char) Len(5002)                

     Dcl        Var(&Len_Parms)  Type(*Int) Len(2) Stg(*Defined) +   

                                 DefVar(&Cmd_Parms)                  

     Dcl        Var(&Parms)      Type(*Char) Len(5000) Stg(*Defined) +

                                 DefVar(&Cmd_Parms 3)                

                                                                      

/*  DclFCLF    FileID(ActCmdTsts)                                   */

    Dcl        Var(&CmdTstRcd) Type(*Char) Len(61)                   

    Dcl        Var(&RNF)       Type(*Lgl)                             

    Dcl        Var(&Parm_Len)  Type(*Int)                            

                                                                     

    If         Cond(&Cmd *EQ CHGTSTCASE) Then(Do)                    

               OpnFCLF ActCmdTsts AccMth(*Key) LvlChk(*No)           

               If Cond(&TestUsr = *CURUSR) Then( +                   

                    RtvJoba CurUser(&TestUsr))                       

               ReadRcdCLF ActCmdTsts Type(*Key) KeyRel(*EQ) +        

                            KeyList(&TestCmd &TestUsr &TestPgm) +    

                            RcdNotFnd(&RNF) RcdBuf(&CmdTstRcd)       

               CloFCLF ActCmdTsts                                    

                                                                      

               If Cond(*Not &RNF) Then(Do)                           

                  ChgVar Var(&Parms) Value( +                        

                         'MSGID(' *TCat +                            

                         %sst(&CmdTstRcd 31 7) *TCat +               

                         ') MSGF(' *TCat +                           

                         %sst(&CmdTstRcd 48 10) *TCat +              

                         '/' *TCat +                                  

                         %sst(&CmdTstRcd 38 10) *TCat ')')           

                  RtvVarLen  Var(&Parms) Length(&Parm_Len)           

                  ChgVar Var(&Len_Parms) Value(&Parm_Len)            

                  EndDo                                               

               Else Cmd(Do)                                          

                  SndPgmMsg Msg('Test case not found') MsgType(*Diag)

                  SndPgmMsg MsgID(CPF0011) MsgF(QCPFMSG) +           

                              MsgType(*Escape)                       

                  EndDo                                              

               EndDo                                                 

    Return                                                            

    Endpgm                                                           

 

The previous program can be created into library VINING using this command:

 

CRTBNDCL PGM(VINING/CHGTSTPOP)

CHGTSTCPP Using RPG-like Commands

 

    Pgm        Parm(&TestCmd &TestPgm &TestUsr &NewMsg &NewMsgF)    

    Dcl        Var(&NewMsg)     Type(*Char) Len(7)                  

    Dcl        Var(&NewMsgF)    Type(*Char) Len(20)                 

     Dcl        Var(&MsgF)     Type(*Char) Len(10) Stg(*Defined) +   

                               DefVar(&NewMsgF 1)                   

     Dcl        Var(&MsgFL)    Type(*Char) Len(10) Stg(*Defined) +  

                               DefVar(&NewMsgF 11)                  

                                                                     

    File       ActCmdTsts                                           

    Dcl        Var(&RNF)      Type(*Lgl)                            

                                                                    

    If         Cond(&TestUsr = *CURUSR) Then( +                     

               RtvJobA CurUser(&TestUsr))                           

                                                                    

    Open       ActCmdTsts AccMth(*Key) Usage(*Both)                  

                                                                    

    Chain      (&TestCmd &TestUsr &TestPgm) ActCmdTsts +           

                 RcdNotFnd(&RNF)                                   

                                                                    

    If         Cond(&RNF) Then(SndPgmMsg Msg( +                    

                          'Testcase' *BCat &TestPgm *BCat +        

                          &TestCmd *BCat +                         

                          'not found for user' *BCat &TestUsr))    

    Else       Cmd(Do)                                             

               If Cond(&NewMsg *NE *Same) Then( +                  

                  ChgVar Var(&TestMsg) Value(&NewMsg))             

               If Cond(&MsgF *NE *Same) Then( +                    

                  ChgVar Var(&TestMsgF)  Value(&MsgF))             

               If Cond(&MsgFL *NE *Same) Then( +                   

                  ChgVar Var(&TestMsgFL) Value(&MsgFL))            

                                                                   

               Update ActCmdTsts                                   

               SndPgmMsg Msg('Testcase' *BCat &TestPgm *BCat +     

                         &TestCmd *BCat 'changed for user' *BCat +  

                         &TestUsr)                                  

               EndDo                                                

                                                                    

    Close      ActCmdTsts                                           

                                                                    

    Return                                                          

    EndPgm                                                           

 

The previous program can be created into library VINING using this command:

 

CRTBNDCLF PGM(VINING/CHGTSTCPP)

CHGTSTCPP Using Base Run-Time Support

 

    Pgm        Parm(&TestCmd &TestPgm &TestUsr &NewMsg &NewMsgF)     

    Dcl        Var(&TestCmd)   Type(*Char) Len(10)                   

    Dcl        Var(&TestPgm)   Type(*Char) Len(10)                   

    Dcl        Var(&TestUsr)   Type(*Char) Len(10)                   

    Dcl        Var(&NewMsg)     Type(*Char) Len(7)                    

    Dcl        Var(&NewMsgF)    Type(*Char) Len(20)                  

     Dcl        Var(&MsgF)     Type(*Char) Len(10) Stg(*Defined) +   

                               DefVar(&NewMsgF 1)                    

     Dcl        Var(&MsgFL)    Type(*Char) Len(10) Stg(*Defined) +   

                               DefVar(&NewMsgF 11)                   

                                                                     

/*  DclFCLF    FileID(ActCmdTsts)                                   */

    Dcl        Var(&CmdTstRcd) Type(*Char) Len(61)                   

    Dcl        Var(&RNF)      Type(*Lgl)                             

                                                                     

    If         Cond(&TestUsr = *CURUSR) Then( +                       

               RtvJobA CurUser(&TestUsr))                             

                                                                      

    OpnFCLF    FileID(ActCmdTsts) AccMth(*Key) Usage(*Both) +         

                 LvlChk(*No)                                          

                                                                      

    ReadRcdCLF ActCmdTsts Type(*Key) KeyRel(*EQ) +                    

                 KeyList(&TestCmd &TestUsr &TestPgm) +                 

                 RcdNotFnd(&RNF) RcdBuf(&CmdTstRcd)                   

                                                                      

    If         Cond(&RNF) Then(SndPgmMsg Msg( +                       

                          'Testcase' *BCat &TestPgm *BCat +           

                          &TestCmd *BCat +                            

                          'not found for user' *BCat &TestUsr))       

    Else       Cmd(Do)                                                 

               If Cond(&NewMsg *NE *Same) Then( +                     

                  ChgVar Var(%sst(&CmdTstRcd 31 7)) Value(&NewMsg))   

               If Cond(&MsgF *NE *Same) Then( +                       

                  ChgVar Var(%sst(&CmdTstRcd 38 10)) Value(&MsgF)) 

               If Cond(&MsgFL *NE *Same) Then( +                   

                  ChgVar Var(%sst(&CmdTstRcd 48 10)) Value(&MsgFL))

                                                                   

               UpdRcdCLF ActCmdTsts RcdBuf(&CmdTstRcd)             

               SndPgmMsg Msg('Testcase' *BCat &TestPgm *BCat +     

                         &TestCmd *BCat 'changed for user' *BCat + 

                         &TestUsr)                                  

               EndDo                                               

                                                                   

    CloFCLF    ActCmdTsts                                          

                                                                    

    Return                                                         

    EndPgm                                                         

 

The previous program can be created into library VINING using this command:

 

CRTBNDCL PGM(VINING/CHGTSTCPP)

Update a Database Record

In this article, you have seen how to update a database record from your CL program. In the next article, we'll look at how to implement a CL-based Display Test Case (DSPTSTCASE) command that uses both a subfile to display test cases and an external printer file to create a report of test cases.

More CL Questions?              

Wondering how to accomplish a function in CL? Send your CL-related questions to me at This email address is being protected from spambots. You need JavaScript enabled to view it.. I'll try to answer your burning questions in future columns.

 

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$