Page 1 of 2

Retrieve JCL PARM properly

PostPosted: Tue Feb 22, 2011 3:10 pm
by sensuixel
Hi

I'm a french junior System Adm. and i'm actually trying to build skills in HLASM.

I've coded a little program to retrieve the JCL PARM field and display it in a file, it almost works properly except for the length.

e.g if i code //APIASMX0 EXEC PGM=APIASMX0,PARM='4095'

The display will only be *** PARM = 40 instead of 4095, i only get the first 2 characters of the parm field.

Moreover i get ** ASMA033I Storage alignment for MSGPRM unfavorable at compilation, it's just an informationnal
message but still it bothers me a little.

note : INITL and RCNTL are our standard linkage and exit macro.

Am I missing something obvious ?

*---------------------------------------------------------------------- 00010000
*-        PURPOSE : READ JCL PARM FIELD                                 00020092
*---------------------------------------------------------------------- 00030000
APIREC   DSECT                                                          00031038
APICNT   DS    CL131         BUFFER SYSTEM MAPPING FOR LOCATE MODE      00032099
*                                                                       00032199
APIX0    CSECT                                                          00033024
         INITL 10,EQU=R      BASE REGISTER  = 10, R15 = 15              00040039
         USING APIREC,R5     ADDRESSAGE POUR DSECT VIA R5               00041099
*---------------------------------------------------------------------- 00050000
*         MAIN                                                          00060000
*---------------------------------------------------------------------- 00070000
         BAL   R6,READPARM      RETRIEVE JCL PARM FIELD                 00071025
         BAL   R6,OPENFIC       OPEN SYSPRINT FILE                      00071199
         BAL   R6,WRITEFIC      WRITE PARM IN SYSPRINT                  00071225
         BAL   R6,CLOSEFIC      CLOSE SYSPRINT FILE                     00071325
         BAL   R6,EXITPGM       EXIT                                    00071425
*                                                                       00071599
*---------------------------------------------------------------------- 00071699
*         READPARM  : RETRIEVE JCL PARM                                 00071799
*---------------------------------------------------------------------- 00071899
READPARM EQU   *                                                        00071999
         DS    0H                                                       00072099
         L     R2,0(0,R1)       R2 = adr of parm field                  00072199
         LH    R9,0(0,R2)       R9 = Length of parm field               00072299
         L     R3,0(0,R2)       R3 = Content of parm field              00072399
         ST    R3,MSGPRM        MSGPRM = content of parm field          00072499
         LTR   R9,R9            Was parm specified  ?                    00072599
         BZ    NOPARM           If NO branch to NOPARM                     00072699
         BR    R6                                                       00072799
*---------------------------------------------------------------------- 00072822
*         OPENFIC  : OPEN SYSPRINT                                      00072992
*---------------------------------------------------------------------- 00073022
OPENFIC  EQU  *                                                         00073122
         OPEN  (APIPRINT,(OUTPUT)) Open sysprint file as output         00073255
         BR    R6                                                       00073355
*                                                                       00073922
*---------------------------------------------------------------------- 00074022
*         NOPARM : WRITE ERROR MSG IN SYSPRINT                          00074192
*---------------------------------------------------------------------- 00074222
NOPARM   EQU  *                                                         00074350
         BAL   R6,OPENFIC                                               00074499
         PUT   APIPRINT                                                 00074599
         LR    R5,R1                                                    00074699
         MVC   0(ERRMSG1,R5),ERRMSG                                     00074799
         BAL   R6,CLOSEFIC                                              00074899
         RCNTL RC=4                                                     00074999
*                                                                       00075022
*---------------------------------------------------------------------- 00075150
*         WRITEFIC  : WRITE SYSPRINT FILE                               00075292
*---------------------------------------------------------------------- 00075350
WRITEFIC EQU  *                                                         00075450
         PUT   APIPRINT                                                 00075550
         LR    R5,R1                                                    00075699
         MVC   0(LLINE1,R5),LINE1                                       00075799
         BR    R6                                                       00075850
*                                                                       00075950
*---------------------------------------------------------------------- 00076050
*         CLOSEFIC  : CLOSE SYSPRINT                                    00076192
*---------------------------------------------------------------------- 00076250
CLOSEFIC EQU *                                                          00076350
         CLOSE APIPRINT                                                 00076450
         BR    R6                                                       00076599
*                                                                       00076650
*---------------------------------------------------------------------- 00076750
*         EXITPGM   : END OF PGM                                        00076850
*---------------------------------------------------------------------- 00076950
EXITPGM EQU    *                                                        00077050
        RCNTL  RC=0                                                     00077199
*                                                                       00077250
*---------------------------------------------------------------------- 00077350
*         WORKING STORAGE                                               00077450
*---------------------------------------------------------------------- 00077550
*                                                                       00077650
LINE1    EQU   *                                                        00077750
         DC    C'*** PARM = '                                           00077899
MSGPRM   DC    CL120' '                                                 00077999
LLINE1   EQU   *-LINE1                                                  00078150
*                                                                       00078299
ERRMSG   EQU   *                                                        00078399
         DC    C'*** RC = 4 NO PARM SPECIFIED'                          00078499
         DC    CL103' '                                                 00078599
ERRMSG1  EQU   *-ERRMSG                                                 00078699
*                                                                       00078799
APIPRINT DCB DDNAME=APIPRINT,DSORG=PS,MACRF=(PL),                      X00078899
               RECFM=FB,LRECL=131,BLKSIZE=1310                          00078999
         END APIX0                                                      00079050


Re: Retrieve JCL PARM properly

PostPosted: Tue Feb 22, 2011 3:37 pm
by enrico-sorichetti
why use a load and store, and not a simple mvc ?
if the length is at offset 0 the data will be at offset 2 ( at least )
the warning is about fullword alignment for load and store operations
once upon a time You would get a specification exception at execution time
then You might lose ( IIRC ) two cycles in accessing the data
right now You will get a warning that can be turned off using the proper assembler parms

and ... why use locate mode, much simpler to use move mode and issue the put from Your IO area

Re: Retrieve JCL PARM properly

PostPosted: Tue Feb 22, 2011 3:50 pm
by sensuixel
Thank you !

It works perfectly, no more Informationnal message

I've replaced the Load and store operation with

MVC   MSGPRM,0(R2)


So i get the parm field properly.

I used LOCATE mode just to get used to it, I also have a version with MOVE mode (easier to use i agree).

Thank you really much for your contribution.

Re: Retrieve JCL PARM properly

PostPosted: Tue Feb 22, 2011 6:49 pm
by stevexff
I prefer to use symbolic names as much as possible, so I probably would have used a DSECT to map the PARM
PARM     DSECT
PARM_LEN DS H          halfword length
PARM_VAL DS CL100   passed parm
..
         L   R2,0(,R1)
         USING PARM,R2
and possibly an EXecuted MVC based on the length to move it around.

Re: Retrieve JCL PARM properly

PostPosted: Tue Feb 22, 2011 6:57 pm
by enrico-sorichetti
         LH    R9,0(0,R2)       R9 = Length of parm field               00072299
         L     R3,0(0,R2)       R3 = Content of parm field              00072399
I hinted about a wrong offset for the data
if the length is at offset 0 the data will be at offset 2 ( at least )
the TS disregarded it and coded
          MVC   MSGPRM,0(R2)
telling
So i get the parm field properly.


if he is happy with errors why should we make him unhappy by fixing things :ugeek:

Re: Retrieve JCL PARM properly

PostPosted: Tue Feb 22, 2011 8:17 pm
by steve-myers
GETPARM  CSECT                     DEFINE PROGRAM CSECT
         USING *,12                ESTABLISH PROGRAM ADDRESSABILITY
         SAVE  (14,12),,*          SAVE REGISTERS
         LR    12,15               COPY ENTRY POINT ADDRESS TO REG 12
         LA    15,SAVEAREA         LOAD ADDRESS OF THE NEW SAVE AREA
         ST    15,8(,13)           ADD THE NEW SAVE AREA TO THE
         ST    13,4(,15)            SAVE AREA CHAIN
         LR    13,15               ESTABLISH A NEW SAVE AREA POINTER
         L     2,0(,1)             LOAD ADDRESS OF PARM DATA
         LH    3,0(,2)             LOAD LENGTH OF PARM DATA
         LA    2,2(,2)             COMPUTE ADDRESS OF FIRST BYTE OF    X
                                    TEXT IN THE PARM DATA
         LTR   3,3                 TEST LENGTH OF PARM DATA
         BNZ   MOVEPARM            BR IF NO PARM DATA
         LA    2,ERRTEXT           LOAD ADDRESS OF ERROR TEXT
         LA    3,L'ERRTEXT         LOAD LENGTH OF ERROR TEXT
MOVEPARM LA    14,PARMDATA         LOAD ADDRESS OF MY COPY OF PARM DATA
         LA    15,L'PARMDATA       LOAD LENGTH OF MY COPY OF PARM DATA
         ICM   3,B'1000',=C' '     LOAD THE FILL CHARACTER
         MVCL  14,2                COPY PARM DATA TO MY STORAGE AREA
         OPEN  (ADCB,OUTPUT)       OPEN THE DCB
         PUT   ADCB,PARMDATA       WRITE THE PARM DATA
         CLOSE ADCB                CLOSE THE DCB
EXIT     L     13,4(,13)           LOAD ADDR OF THE PREVIOUS SAVE AREA
         RETURN (14,12),T,RC=0     RESTORE REGISTERS AND RETURN
ADCB     DCB   DSORG=PS,MACRF=PM,RECFM=F,LRECL=100,BLKSIZE=100,        X
               DDNAME=SYSPRINT
SAVEAREA DS    18F                 OS/360 SAVE AREA
         LTORG ,                   DEFINE THE LITERAL POOL
ERRTEXT  DC    C'THERE IS NO PARM DATA!'
PARMDATA DS    CL100               MY COPY OF PARM DATA
         END   GETPARM

I don't think I ever bothered to code a parm data DSECT like stevexff.

I suspect the fundamental problem (which I did not bother to check in a formal sense because the expansion of the non-standard entry macro is unknown. so I'm not sure what may have happened to register 1) in the original code is there is no equivalent to my LA 2,2(,2) before the data is copied to the program area.

As for the "unfavorable" storage alignment message. At one level it is nothing to worry about. The original System/360 had strict rules about storage alignment for operands. For the most part these storage alignment rules were lifted in System/370 around 1970, but there were warnings, which are still present, that ignoring the old storage alignment rules will cause a performance penalty. The alleged performance penalty is why the Assembler writes the warning message.

Re: Retrieve JCL PARM properly

PostPosted: Tue Feb 22, 2011 8:23 pm
by enrico-sorichetti
I suspect the fundamental problem (which I did not bother to check in a formal sense because the expansion of the non-standard entry macro is unknown. so I'm not sure what may have happened to register 1) in the original code is there is no equivalent to my LA 2,2(,2) before the data is copied to the program area.


any half decently written prolog/entry macro will restore the R1 content to its original value !

Re: Retrieve JCL PARM properly

PostPosted: Tue Feb 22, 2011 8:30 pm
by sensuixel
stevexff wrote:I prefer to use symbolic names as much as possible, so I probably would have used a DSECT to map the PARM
PARM     DSECT
PARM_LEN DS H          halfword length
PARM_VAL DS CL100   passed parm
..
         L   R2,0(,R1)
         USING PARM,R2
and possibly an EXecuted MVC based on the length to move it around.


Thank you for your contribution, i'll try it but first I have to understand how the EX instruction works.


@steve-myers
You're right I don't have the equivalent of LA 2,2(,2) in my code.
I have to take a closer look at it.

Re: Retrieve JCL PARM properly

PostPosted: Tue Feb 22, 2011 8:36 pm
by sensuixel
enrico-sorichetti wrote:
         LH    R9,0(0,R2)       R9 = Length of parm field               00072299
         L     R3,0(0,R2)       R3 = Content of parm field              00072399
I hinted about a wrong offset for the data
if the length is at offset 0 the data will be at offset 2 ( at least )
the TS disregarded it and coded
          MVC   MSGPRM,0(R2)
telling
So i get the parm field properly.


if he is happy with errors why should we make him unhappy by fixing things :ugeek:


Oups I didn't read tour answer thoroughly ;)
You're right, when I activate HEX MODE in my file I do see the length of the PARM FIELD, it's not a clean ouput.

Re: Retrieve JCL PARM properly

PostPosted: Tue Feb 22, 2011 9:03 pm
by stevexff
The EX instruction allows you to execute another out-of-line instruction (like an MVC for example), overriding the length field with the contents of a register. This allows you do a MVC where the length is not known until run time, like the length of your PARM field. steve-myers has worked around this by using MVCL, which also allows you to specify the length in a register, and works just as well as long as you happen to have four registers to spare; this isn't always the case :)