Detect Source Of Parameter: JCL PARM= Vs. Call By Program



High Level Assembler(HLASM) for MVS & VM & VSE

Detect Source Of Parameter: JCL PARM= Vs. Call By Program

Postby Shady » Fri Jul 06, 2012 10:23 pm

Hello,

I'm relative new to assembler. I bought some books for reading and also coded a bit... The code isn't a problem in this post. At the moment the program works fine. I just want to advance it and I need an info.

I've written a program for a collegue. He wrotes a metal C program and needs a WTO in his C program. OK, so I wrote a very little program for him. OK. Works fine. Now he also want to call that program from job control with EXEC PGM=...,PARM='PARM TEXT'.
I know that the first halfword from the parameter is the length of the content of PARM=. In the WTO for the metal C program is no prefix with the length. There I just loop through the parameter and search for the end of the parameter.

So my question: How can I differ wheather the PARM comes from a call from a program (like Metal C) or it comes from batch with PARM=
Is there a control block or sth. where I can find something to identify the source?

Regards
Shady
 
Posts: 9
Joined: Sat Mar 13, 2010 11:55 am
Has thanked: 1 time
Been thanked: 0 time

Re: Detect Source Of Parameter: JCL PARM= Vs. Call By Progra

Postby steve-myers » Sat Jul 07, 2012 2:19 am

See this topic.

In concept, a program should not care, or even know, if it is called from JCL or another program. There are no 100% certain methods for a program to determine if it is called by JCL or another program. Some possibilities:
  • Compare the save area address used when your program is entered with the address in TCBFSA in the current TCB. If they match, AND the current TCB address matches the address in TCBJSTA in the current TCB, your program probably - though not certainly - was called from JCL. It still could have been called from another program using the XCTL macro, but ...
  • Obtain the current request block address from TCBRBP in the current TCB. Compare the 24-bit "next" RB address with the address of the current TCB. If they are equal, your program was probably called from JCL.
I wrote the following program to test these ideas
TESTJCL  CSECT                     DEFINE PROGRAM CSECT
         PUSH  PRINT
         PRINT NOGEN
         CVT   DSECT=YES           DEFINE CVT DATA AREA
         IKJTCB ,                  DEFINE TVB DATA AREA
         IHARB DSECT=YES           DEFINE RB DATA AREA
         POP   PRINT
TESTJCL  CSECT                     RETURN TO PROGRAM CSECT
         USING *,12                ESTASBLISH ADDRESSABILITY
         SAVE  (14,12),,*          SAVE REGISTERS
         LR    12,15               COPY ENTRY POINT ADDRESS TO REG 12
* WE DO NOT HAVE TO OBTAIN A NEW SAVE AREA
         L     2,CVTPTR            LOAD CVT ADDRESS
         L     2,CVTTCBP-CVTMAP(,2)  LOAD ADDR OF THE TCB POINTER WORDS
         L     2,4(,2)             LOAD ADDR OF THE CURRENT TCB
         N     2,=A(X'FFFFFF')     ISOLATE THE 24-BIT TCB ADDRESS
         L     3,TCBRBP-TCB(,2)    LOAD ADDR OF THE CURRENT RB
         N     3,=A(X'FFFFFF')     ISOLATE THE 24-BIT RB ADDRESS
         L     4,TCBFSA-TCB(,2)    LOAD ADDR OF THE FIRST SAVE AREA
         N     4,=A(X'FFFFFF')     ISOLATE THE 24-BITE ADDRESS
         L     5,TCBJSTCB-TCB(,2)  LOAD ADDR OF THE JOB STEP TCB
         N     5,=A(X'FFFFFF')     ISOLATE THE 24-BIT TCB ADDRESS
         CR    2,5                 TEST IF CURRENT TCB = THE JOB STEP ->
                                    TCB
         BNE   NOTJCL              BR IF NOT
         WTO   'CURRENT TCB IS THE JOBSTEP TCB',ROUTCDE=11,DESC=7
         CR    4,13                TEST IF SAVE AREA = FIRST SAVE AREA
         BNE   FSAERR              BR IF NOT
         WTO   'SAVE AREA PONTER = TCBFSA',ROUTCDE=11,DESC=7
         B     FSAOK
FSAERR   WTO   'SAVE AREA POINTER ¬= TCBFSA',ROUTCDE=11,DESC=7
FSAOK    CLM   2,B'0111',RBLINK-RBBASIC+1(3)  TEST RBLINK
         BNE   RBERROR             BR IF NOT
         WTO   'RBLINK POINTS TO TCB',ROUTCDE=11,DESC=7
         B     EXIT
RBERROR  WTO   'RBLINK DOES NOT POINT TO TCB',ROUTCDE=11,DESC=7
         B     EXIT
NOTJCL   WTO   'TCB IS NOT THE JOB STEP TCB',ROUTCDE=11,DESC=7
EXIT     RETURN (14,12),T,RC=0
         DC    0D'0'
         LTORG ,
         DC    0D'0'
         END   TESTJCL

I assembled the program, then used this JCL to run it.
//A       EXEC PGM=LOADER,PARM='MAP'
//SYSLOUT  DD  SYSOUT=*
//SYSLIN   DD  DISP=(SHR,PASS),DSN=&SYSUID..TESTJCL.OBJ
//B       EXEC PGM=IEWL,PARM=MAP
//SYSPRINT DD  SYSOUT=*
//SYSLMOD  DD  DISP=(,PASS),UNIT=SYSDA,SPACE=(TRK,(1,1,1)),DSN=&&G(G)
//SYSLIN   DD  DISP=(SHR,PASS),DSN=&SYSUID..TESTJCL.OBJ
//C       EXEC PGM=*.B.SYSLMOD

The LOADER program loads the object deck directly into storage and then runs it as a subtask, so it should not be considered as called from JCL. Step B prepares a load module from the object deck, and step C runs the program from JCL.
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: Detect Source Of Parameter: JCL PARM= Vs. Call By Progra

Postby Shady » Sat Jul 07, 2012 9:17 am

Thank you very much!
If I can find a free time frame I'll try to change my prog next week.

Again: Thank you. :)
Shady
 
Posts: 9
Joined: Sat Mar 13, 2010 11:55 am
Has thanked: 1 time
Been thanked: 0 time

Re: Detect Source Of Parameter: JCL PARM= Vs. Call By Progra

Postby steve-myers » Sun Jul 08, 2012 8:16 am

A few additional thoughts.

When a program is called using full standard linkage, register 1 points to a parameter list. A parameter list contains one or more words that point to parameters. The high order bit in the last word of a standard parameter list is on. When a program is called from JCL, the parameter list contains 1 word, and the high order bit is on. Your program can test this: if the high order bit of the first word is not on, it was not called from JCL. Of course, if the parameter list contains just 1 word, that does not mean it was called from JCL. This code mimics JCL.
         CALL PGM,PARMTEXT,VL
         ...
PARMTEXT DC   H'3',CL3'JCL'
The VL parameter in the CALL macro directs the macro to insert the high order bit in the parameter list.

In truth, few self respecting Assembler programmers would tolerate the expansion of that CALL macro: it is -
+         CNOP  0,4                   
+         B     *+8                   
+IHB0001B DC    V(PGM)                 
+         LA    1,IHB0003             
+         B     IHB0003A               
+IHB0003  DS    0F                     
+         DC    A(PARMTEXT+X'80000000')
+IHB0003A EQU   *                     
+         L     15,IHB0001B           
+         BALR  14,15                 

The reason: it is horribly inefficient. A branch around an inline data area is slow, and there are two of these branches. A self respecting Assembler programmer does something like this -
         L     15,=V(PGM)         
         CALL  (15),MF=(E,PARMLIST)
         ...
PARMLIST CALL  ,PARMTEXT,VL,MF=L   
PARMTEXT DC    H'3',C'JCL'         

The first CALL macro becomes -
          CALL  (15),MF=(E,PARMLIST)
+         DS    0H                 
+         LA    1,PARMLIST         
+         BALR  14,15               

The second CALL macro becomes -
 PARMLIST CALL  ,PARMTEXT,VL,MF=L     
+PARMLIST DS    0F                     
+         DC    A(PARMTEXT+X'80000000')

These users thanked the author steve-myers for the post:
Shady (Sun Jul 08, 2012 8:38 am)
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times


Return to Assembler

 


  • Related topics
    Replies
    Views
    Last post