Beginning the Instruction Stream
Begin the instruction stream definition by doing the following:
1. Use the store parameter list length (STPLLEN) instruction to determine the
number of parameters that were passed to the program:
STPLLEN NUM_PARMS;
2. If the number of parameters is 1, assign FILNAM to the value MISRC (the
default that this program supports for the source physical file) and branch to
label PARM1 to set the source member name:
CMPNV(B) NUM_PARMS, 2 / EQ(PARM2);
CPYBLAP FILNAM, 'MISRC', ' ';
B PARM1;
3. If the number of parameters is 2, assign FILNAM to the value of the second
parameter:
PARM2: CPYBLA FILNAM, FIL;
4. Assign the source member name:
PARM1: CPYBLA MBRNAM, MBR;
5. Assign the proper context for the space:
CPYBWP CONTEXT, QTEMP@;
6. After establishing the context of the space, now create the space:
CRTS USRSPC@, CRTSTMPLT@;
7. Assign the space pointer USRSPC to address the first byte of the space:
SETSPPFP USRSPC, USRSPC@;
8. Set the OVRDBF CL command to start with POSITION(1):
CPYNV RECNUM, 1;

Using Static Storage to Your Advantage

In “Beginning the Instruction Stream,” the instructions in steps 5, 6, and 7 can be
done once and the space reused on subsequent invocations of the program. As a
performance enhancement, add a check to see if this program has been previously
invoked. To do the check, add a control field, and conditionally branch around the
CRTS-oriented instructions if this call is not the initial call:
STPLLEN NUM_PARMS;
CMPNV(B) NUM_PARMS, 2 / EQ(PARM2);
CPYBLAP FILNAM, 'MISRC', ' ';
B PARM1;
PARM2: CPYBLA FILNAM, FIL;
PARM1: CPYBLA MBRNAM,MBR;
CMPBLA(B) READY, '1' / EQ(SKIP);
CPYBWP CONTEXT, QTEMP@;
CRTS USRSPC@, CRTSTMPLT@;
SETSPPFP USRSPC,USRSPC@;
CPYBLA READY, '1';
SKIP: CPYNV RECNUM, 1;
Resuming the program flow of the MICRTPG2 program from “Beginning the Instruc-
tion Stream” on page 7-22, you should have the program perform the following:
7-22 System API Programming V4R1