Sometimes it can be necessary to extract a part of a string provided by the EXEC PGM PARM parameter.
The following simple example extracts the characters between the first and the second comma within the PARM data, while the position of the commas is flexible.
When executing the following source with:
...
//EASY1 EXEC PGM=EZTPA00,REGION=0M,PARM='1234567890,ABC,12345'
...
the result will be:
...
JPRM-VPART: +ABC +
...
And with this PARM:
...
//EASY1 EXEC PGM=EZTPA00,REGION=0M,PARM='12345,ABCDEFGHIJ,1234578'
...
the result will be:
...
JPRM-VPART: +ABCDEFGHIJ+
...
The source:
...
DEFINE JPRM S 100 A VARYING
DEFINE JPRM-I JPRM 1 A OCCURS 100 INDEX W-IDX
DEFINE JPRM-VPART S 10 A
DEFINE JPRM-VPART-I JPRM-VPART 1 A OCCURS 10 INDEX V-IDX
*
PROGRAM NAME TESTPARM USING(JPRM)
EXECUTE TESTPARM1
*
JOB INPUT(NULL) NAME TESTPARM1
*
* FIND THE FIRST COMMA -->
*
DO UNTIL JPRM-I EQ ','
W-IDX = W-IDX + 1
END-DO
W-IDX = W-IDX + 1
*
* MOVE CHARACTERS TO JPRM-VPART UNTIL THE NEXT COMMA IS FOUND -->
*
DO UNTIL JPRM-I EQ ','
MOVE JPRM-I TO JPRM-VPART-I
V-IDX = V-IDX + 1
W-IDX = W-IDX + 1
END-DO
*
DISPLAY 'JPRM-VPART: +' JPRM-VPART '+'
*
STOP
...
Please note:
The extracted field can contain only up to 10 characters in this sample.
This sample requires at least two commas within the PARM data string. Otherwise, the program terminates with RC=16 and this error message:
EZABX009 An index or subscript is out of range.