If you have created custom commands and you want to prompt for several entries, you will soon discover that the...
variable returned from your command when using the "Element" keyword (ELEM) is nasty. It will insert a count and off sets within your list. And, these inserted numbers are in binary format.
To handle this, you may have seen some old CL programs test for Hex"01" through Hex"FF", or a call to an RPG program to convert the Binary values to Decimal values, or use the newer %BINARY for this. But by making an assumption, the parsing of these variables and their counts and offsets is eliminated. The trick is, be sure that each of your command parms REQUIRE an entry ... PARM MIN(1) so each parameter uses its full 10A length.
An example of a qualified parameter
If you have created a few custom commands, you are probably used to parsing qualified parameters from commands with some code to extract from a variable &FILELIB both the file-name from position 1-to-10 and a library-name from 11-to-20.
CHGVAR &FILE %SST(&FILELIB 1 10) CHGVAR &LIB %SST(&FILELIB 11 10) /* from a prompt that appears FILE _____________ */ /* *LIBL________ */ The command source is CMD PROMPT('PRINT DDS SOURCE') PARM KWD(FILE) TYPE(QUAL1) PROMPT('DDS Source + File with Msg.s') QUAL1: QUAL TYPE(*NAME) LEN(10) QUAL TYPE(*CHAR) LEN(10) DFT(*LIBL) + SPCVAL((*LIBL *LIBL)) PROMPT('Library')
But a mixed list is nasty
Let's take the example where you may have some complicated parameters that ask for spool file info that would generate a prompt screen like:
Spooled File: SPLF _ Spooled File . . . . . . . . . __________ Job Name . . . . . . . . . . . *_________ User . . . . . . . . . . . . __________ Number . . . . . . . . . . . ______ Spooled file number . . . . . *LAST_ + for more values _ whose command source is ... PARM KWD(SPLF) TYPE(L1) MAX(300) PROMPT('Spooled + File') L1: ELEM TYPE(*NAME) MIN(1) PROMPT('Spooled File') ELEM TYPE(Q1) DFT(*) SNGVAL((* *)) PROMPT('Job + Name') ELEM TYPE(*CHAR) LEN(6) DFT(*LAST) SPCVAL((*ONLY + *ONLY) (*LAST *LAST)) MIN(0) PROMPT('Spooled + file number') Q1: QUAL TYPE(*NAME) MIN(1) QUAL TYPE(*NAME) PROMPT('User') QUAL TYPE(*CHAR) LEN(6) RANGE(000001 999999) + PROMPT('Number')
Here you want to prompt for multiple spool files, where the user could key in a "+" plus-sign to key in 6 reports. You now have a mixed list of entries. This mixed list would return a variable &SPLF that would be formatted with a count of six in the front, followed by the offsets of where each string would begin:
x'0006 00D6 00AE 0086 005E 0036 000E' 000006 SPLFILE6 999006 USER6 JOB6 000006 x'0003' SPLFILE5 999005 USER5 JOB5 000005 x'0003' SPLFILE4 999004 USER4 JOB4 000004 x'0003' SPLFILE3 999003 USER3 JOB3 000003 x'0003' SPLFILE2 999002 USER2 JOB2 000002 x'0003' SPLFILE1 999001 USER1 JOB1 000001
when what you ultimately want is a simple phrase like " (SPLFILE6 999006/USER6/JOB6 000006) (SPLFILE5 999005/USER5/JOB5 000005) (SPLFILE4 999004/USER4/JOB4 000004) (SPLFILE3 999003/USER3/JOB3 000003) (SPLFILE2 999002/USER2/JOB2 000002) (SPLFILE1 999001/USER1/JOB1 000001) "
The trick is that we assume that these binary numbers (which take 2 bytes) will always be lower than x'0FFF' (or 16x16x16), which is 4096. In the variable, we find and eliminate any binary numbers, simply stripping them out. This leaves our parameters in blocks at regular position intervals. In this case, within each block our fields are at positions 1,11,21,31,37 with the following block starting at position 43.
For simplicity, I created a separate program to eliminate the binary numbers in the variable &SPLF. The entire variable is stripped of binary counters when we pass it to this separate program: CALL PDFSPLFNC3 PARM(&SPLF).
/* PDFSPLFNC3 *CLP */ /* STRIP AWAY ANY BINARY INTEGERS */ /* FROM THE &SPLF VARIABLE PASSED IN + /* BINARY NUMBERS INSERTED VIA THE COMMAND LIST-PROCESSOR */ PGM &FIELD DCL &FIELD *CHAR 5000 DCL &OUTPUT *CHAR 5000 DCL &PUT *DEC (5 0) VALUE(1) DCL &START *DEC (5 0) VALUE(1) DCL &CHAR2A *CHAR 2 DCL &TEST *CHAR 1 VALUE(X'0F') /* FIRST BYTE OF DOUBLE BYTE MUST BE LESS THAN 0F-xx */ DCL &WHITE *CHAR 10 VALUE(X'40404040404040404040') /* ELIMINATE LEFTOVER SPACE */ CHGVAR &OUTPUT ' ' READ: /* AND WHEN A LOT OF WHITE SPACE OF BLANKS IS FOUND, /* DEFAULT TO BLANKS TO THE END OF THE VARIABLE AND ENDPGM */ IF ( %sst(&FIELD ⋆t 10) *EQ &WHITE) DO GOTO ENDPGM ENDDO /* MOVE 2 BYTES AT A TIME THROUGH THE VARIABLE */ /* TESTING THE HIGH-ORDER BYTE FOR AN INTEGER FROM THE LIST-COUNT */ CHGVAR &CHAR2A %SST(&FIELD &START 2) IF ( %sst(&FIELD ⋆t 1) *GE &TEST ) DO CHGVAR %SST(&OUTPUT &PUT 2) &CHAR2A CHGVAR &PUT (&PUT + 2) ENDDO CHGVAR &START (&START + 2) IF (&START *EQ 4999) GOTO ENDPGM GOTO READ ENDPGM: CHGVAR &FIELD &OUTPUT RETURN ENDPGM
Finally, you will want to insert your string of parameters with parentheses and slashes. Also, you will see that the spool files are sequenced in reverse order.
MORE INFORMATION ON THIS TOPIC
The Best Web Links: tips, tutorials and more.
Ask your programming questions--or help out your peers by answering them--in our live discussion forums.
Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.