User-defined commands to the rescue

I have been noticing that many programmers are neglecting one of the nicest things on the AS/400: user define commands.

We use AS/400 commands all day long. Why not use commands for our own applications?

Have you ever had to convert numbers to strings just to send them as parameters?

Have you ever had to define CLP numeric parameter as 15(5) just to send a numeric parameter from the command line?

Have you ever had to call a program using hexadecimal format just to send a numeric parameter as pack (e.g. X'12345F') ?

If you answered yes, continue reading ...

We will be viewing a technique for submitting a report using a homegrown command.

* Please note that the parmeters go through with no hassle.
* It is possible to prompt on the command like any other AS/400 command.
* Commands source usually reside in QCMDSRC.

Source for command DEM601C 
- Note the usage of DFT keyword 
- The JOBTYP will control the flow of the program 
         I = prompt the user & submit the job 
         B = Go directly to the batch processing part 
         (Very useful if you want to debug the application interactively without 
         using STRSRVJOB) 
             CMD        PROMPT('Command usage sample') 

             PARM       KWD(JOBTYP) TYPE(*CHAR) LEN(1) RSTD(*YES) + 
                          DFT(I) VALUES(I B) PROMPT('Job type') 

             PARM       KWD(DATE_F) TYPE(*DEC) LEN(8 0) PROMPT('From + 
             PARM       KWD(DATE_T) TYPE(*DEC) LEN(8 0) PROMPT('To   + 

             PARM       KWD(PART_C) TYPE(*CHAR) LEN(10) PROMPT('Part + 
             PARM       KWD(TRAN_C) TYPE(*CHAR) LEN(4) DFT(IS02) + 
                          PROMPT('Transaction code') 

Source for display file DEM601C 

     A                                      DSPSIZ(24 80 *DS3) 
     A                                      INDARA 
     A                                      PRINT 
     A                                      ERRSFL 
     A                                      CF03(03) 
     A                                      CF21(21) 
     A          R REQUSET 
     A            JOBTYP         1A  H      TEXT('Job type') 
     A                                  5  2'Date range.........' 
     A            DATE_F         8Y 0B  5 22EDTWRD('  /  /    ') 
     A                                      DSPATR(CS) 
     A                                  5 33'-' 
     A            DATE_T         8Y 0B  5 35EDTWRD('  /  /    ') 
     A                                      DSPATR(CS) 
     A                                  7  2'Part code..........' 
     A            PART_C        10A  B  7 22 
     A                                  9  2'Transaction code...' 
     A            TRAN_C         4A  B  9 22 
     A                                 23  3'F3=Exit' 
     A                                      COLOR(BLU) 
     A                                 23 16'F21=Print list' 
     A                                      COLOR(BLU) 

Source for CL program DEM601C 

             PGM        PARM(&JOBTYP &DATE_F &DATE_T &PART_C &TRAN_C) 

             DCLF       FILE(DEM601C) 

             IF         COND(&JOBTYP = B) THEN(DO) /* Jump to Batch */ 
             GOTO       CMDLBL(BATCH) 


             IF         COND(&IN21) THEN(DO) 
             SBMJOB     CMD(DEM601C JOBTYP(B) DATE_F(&DATE_F) + 
                          DATE_T(&DATE_T) PART_C(&PART_C) + 
                          TRAN_C(&TRAN_C)) LOG(4 00 *MSG) 

             IF         COND(&IN03) THEN(DO) 

             GOTO       CMDLBL(REQUEST) 


 BATCH: /* Batch processing part */ 


This was first published in May 2001

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.