Page 1 of 2

Getting USERID while within the COBOL program

PostPosted: Tue Feb 23, 2010 11:20 pm
by ctrevino
I have successfully coded the acquiring of the jobname from within my program using the control blocks. However, now I need to get the USERID within the program as well.
How would I do this? I have seen some references using the JSAB but I must be doing something wrong.

This works well for JOBNAME:
SET ADDRESS OF PSA TO NULL
SET ADDRESS OF TCB TO TCB-POINTER IN PSA
SET ADDRESS OF TIOT TO TIOT-POINTER IN TCB
MOVE JOBNAME IN TIOT TO HOLD-JOBNAME
DISPLAY 'JOBNAME = ' HOLD-JOBNAME.

But I get a S0C4 when getting the USERID using the below:
SET WS-JSAB-ADDR-POINTER TO NULL.
SET ADDRESS OF TCB TO TCB-POINTER IN PSA.
SET ADDRESS OF STCB TO STCB-POINTER IN TCB.
IF JSAB-POINTER OF STCB IS NOT = NULL
SET ADDRESS OF JSAB TO JSAB-POINTER OF STCB
SET WS-JSAB-ADDR-POINTER TO JSAB-POINTER OF STCB
END-IF.

MOVE USERID IN JSAB TO HOLD-USERID.
DISPLAY 'USERID = ' HOLD-USERID.

Re: Getting USERID while within the COBOL program

PostPosted: Wed Feb 24, 2010 1:57 am
by dick scherrer
Hi Christy,

Give this a try. . . It works on my z/OS 1.9 system.
 CBL NOLIB,APOST,NODECK,OBJECT,NOSEQ,NONAME
 CBL NOMAP,NOLIST,NOOFFSET,NOXREF
       Identification Division.
         Program-ID. Cob2Job.
         Author. Gilbert Saint-Flour.
      *----------------------------------------------------------------*
      *                                                                *
      *    This program retrieves specific job-related data from MVS   *
      *    control blocks and moves it to Working-storage.             *
      *                                                                *
      *    The name of the control-block is indicated in pos 1-6 of    *
      *    the Procedure Division lines.                               *
      *    The layout of the MVS control blocks is described in the    *
      *    MVS Data Areas manuals, which can be found on any MVS or    *
      *    OS/390 CD collection or viewed on-line by going to:         *
      *        http://www.s390.ibm.com/bookmgr-cgi/bookmgr.cmd/library *
      *    and searching for:                                          *
      *        MVS DATA AREAS                                          *
      *                                                                *
      *    Origin = http://gsf-soft.com/Freeware/                      *
      *                                                                *
      *----------------------------------------------------------------*
       Data Division.
        Working-Storage Section.
         01 Results.
           05 job-name Pic x(8).
           05 proc-step Pic x(8).
           05 step-name Pic x(8).
           05 program-name Pic x(8).
           05 program-name2 Pic x(8).
           05 job-number Pic x(8).
           05 job-class Pic x.
           05 msg-class Pic x.
           05 programmer-name Pic x(20).
           05 user-id Pic x(8).
           05 group-name Pic x(8).
           05 user-name Pic x(20).
           05 batch-or-cics Pic x(5).
              88 Batch Value 'BATCH'.
              88 CICS  Value 'CICS '.
           05 micro-seconds Pic S9(15) COMP-3.
         01 four-bytes.
           05 full-word Pic s9(8) Binary.
           05 ptr4      Redefines full-word Pointer.
         01 eight-bytes.
           05 double-word Pic s9(18) Binary.

        Linkage Section.
         01 cb1.  05 ptr1 Pointer Occurs 256.
         01 cb2.  05 ptr2 Pointer Occurs 256.

       Procedure Division.
 PSA       SET Address of cb1 to NULL
 TCB       SET Address of cb1 to ptr1(136)
           MOVE cb1(317:8) to eight-bytes
           COMPUTE micro-seconds = double-word / 4096
 TIOT      SET Address of cb2 to ptr1(4)
           MOVE cb2(1:8) to job-name
           MOVE cb2(9:8) to proc-step
           MOVE cb2(17:8) to step-name
 JSCB      SET Address of cb2 to ptr1(46)
           MOVE cb2(361:8) to program-name
 SSIB      SET Address of cb2 to ptr2(80)
           MOVE cb2(13:8) to job-number
 PRB       SET Address of cb2 to ptr1(1)
           MOVE cb2(97:8) to program-name2
 JSCB      SET Address of cb2 to ptr1(46)
 JCT       SET Address of cb2 to ptr2(66)
           MOVE cb2(48:1) to job-class
           MOVE cb2(23:1) to msg-class
 ACT       MOVE zero to full-word
           MOVE cb2(57:3) to four-bytes(2:3)
           SET Address of cb2 to ptr4
           MOVE cb2(25:20) to programmer-name
 EXT2      SET Address of cb2 to ptr1(53)
 CAUF      IF cb2(21:4) = low-values THEN
             SET Batch to TRUE
           ELSE
             SET CICS to TRUE
           END-IF
 PSA       SET Address of cb1 to NULL
 ASCB      SET Address of cb1 to ptr1(138)
 ASXB      SET Address of cb2 to ptr1(28)
           MOVE cb2(193:8) to user-id
 ACEE      SET Address of cb2 to ptr2(51)
           MOVE cb2(31:8) to group-name
 UNAM      SET Address of cb1 to ptr2(26)
           MOVE zero to full-word
           MOVE cb1(1:1) to four-bytes(4:1)
           MOVE cb1(2:full-word) to user-name
           DISPLAY job-name ' '
                   proc-step ' '
                   step-name ' '
                   program-name ' '
                   program-name2 ' '
                   job-number ' '
                   job-class ' '
                   msg-class ' '
                   micro-seconds ' '
           DISPLAY quote programmer-name  quote ' '
                   batch-or-cics ' '
                   user-id ' '
                   group-name  ' '
                   quote user-name  quote ' '
           GOBACK.

Re: Getting USERID while within the COBOL program

PostPosted: Wed Feb 24, 2010 9:49 pm
by ctrevino
I am getting a SOC4 when setting the pointer for the TIOT. I am trying to resolve it but the listing didn't give me much information.

Re: Getting USERID while within the COBOL program

PostPosted: Wed Feb 24, 2010 10:23 pm
by Robert Sample
Interesting ... I took the code Dick posted, compiled it, and ran it without any problems (other than verbs starting in column 11 instead of 12).

Re: Getting USERID while within the COBOL program

PostPosted: Wed Feb 24, 2010 10:29 pm
by ctrevino
I was picking up the TIOT information with some other code that I found on the internet but unfortunately, it didn't provide the other data areas which I need to get to the userid. I haven't given up though. Do you think any compiler options may interfere with this?

(my shop requires WS initialization of fields. I am going to take that off and try again although I doubt that is the issue).

Re: Getting USERID while within the COBOL program

PostPosted: Wed Feb 24, 2010 11:48 pm
by Robert Sample
I would not think compile options would have an impact on this code. Working storage initialization, however, could.

Re: Getting USERID while within the COBOL program

PostPosted: Wed Feb 24, 2010 11:56 pm
by ctrevino
ok. I know this is a really, really dumb question BUUTTT.......
does it make a difference if the field names are upper or lower case? Right now I am set to upper case.

The only reason I ask is because we combine case when we are writting wrappers for web services.

Re: Getting USERID while within the COBOL program

PostPosted: Thu Feb 25, 2010 12:33 am
by Robert Sample
COBOL is not case sensitive for the most part (there are exceptions, such as DD names in the SELECT statement). For example, part of my program compile is
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---->
   000042                    05 ptr4      Redefines full-word Pointer.
   000043                  01 eight-bytes.
   000044                    05 double-word Pic s9(18) Binary.
   000045
   000046                 Linkage Section.
   000047                  01 cb1.  05 ptr1 Pointer Occurs 256.
   000048                  01 cb2.  05 ptr2 Pointer Occurs 256.
   000049
   000050                Procedure Division.
   000051         PSA        SET Address of cb1 to NULL
   000052         TCB        SET Address of cb1 to ptr1(136)
   000053                    MOVE cb1(317:8) to eight-bytes
   000054                    COMPUTE micro-seconds = double-word / 4096
   000055         TIOT       SET Address of cb2 to ptr1(4)
   000056                    MOVE cb2(1:8) to job-name
   000057                    MOVE cb2(9:8) to proc-step
1PP 5655-G53 IBM Enterprise COBOL for z/OS  3.4.1               COB2JOB   Date 0
   LineID  PL SL  ----+-*A-1-B--+----2----+----3----+----4----+----5----+----6--

Re: Getting USERID while within the COBOL program

PostPosted: Thu Feb 25, 2010 12:52 am
by ctrevino
This is me about now -> :shock:

I feeling pretty dumb about now but I am not going to let this beat me.

Honestly, y'all have been great though. I so appreciate the help. I am not afraid of it but I feel at a disadvantage (this stuff wasn't taught in my cobol class lol ) and have been combing my shop for any book to help.

I will keep y'all informed if I make any progress.

Re: Getting USERID while within the COBOL program

PostPosted: Thu Feb 25, 2010 12:56 am
by ctrevino
Here is the code that works fine for me but it only gets the job name. I want the userid also.

01 PSA.
05 FILLER PIC X(540).
05 TCB-POINTER POINTER.

01 TCB.
05 FILLER PIC X(12).
05 TIOT-POINTER POINTER.

01 TIOT.
05 JOBNAME PIC X(8).


SET ADDRESS OF PSA TO NULL.
SET ADDRESS OF TCB TO TCB-POINTER IN PSA.
SET ADDRESS OF TIOT TO TIOT-POINTER IN TCB.
MOVE JOBNAME IN TIOT TO [your user area].