Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to run a job from COBOL

 
Post new topic   This topic is locked: you cannot edit posts or make replies.    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions
View previous topic :: :: View next topic  
Author Message
krishna_Murty
Warnings : 2

New User


Joined: 17 Sep 2006
Posts: 24

PostPosted: Mon Sep 25, 2006 9:25 am    Post subject: How to run a job from COBOL
Reply with quote

Can some one give a sample and simple code to run a job from a Cobol Program.

Actually if we write a output file and write the output lines which makes
up a JCL, once the output lines are completed are there any instructions given like submit from cobol itself to run this output file.
Back to top
View user's profile Send private message

ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2360
Location: Israel

PostPosted: Mon Sep 25, 2006 10:54 am    Post subject:
Reply with quote

Since SUBMIT is also a TSO command, you can issue it from within COBOL, just like any other TSO command. See example here.

Another option is to direct your output lines to INTRDR.

O.
Back to top
View user's profile Send private message
krishna_Murty
Warnings : 2

New User


Joined: 17 Sep 2006
Posts: 24

PostPosted: Mon Sep 25, 2006 12:14 pm    Post subject:
Reply with quote

Thanks but the example site here is not active. Is there any alternative. viz give other links or copy and paste the code here.
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2360
Location: Israel

PostPosted: Mon Sep 25, 2006 1:00 pm    Post subject:
Reply with quote

Here is the example in the link above:
Code:
 
//IBMUSERJ JOB (ACCT#),COB2TSO,
// NOTIFY=&SYSUID,
// CLASS=A,MSGCLASS=X,COND=(0,NE)
//COB2 EXEC PGM=IGYCRCTL
 CBL NOLIB,APOST,NODECK,OBJECT,NOSEQ,DYNAM
 CBL NOMAP,NOLIST,NOOFFSET,NOXREF
       Identification Division.
         Program-ID. CB2TSOEV.
         Author. Gilbert Saint-Flour.
      ******************************************************************
      *                                                                *
      *   MODULE NAME = COB2TSO                                        *
      *                                                                *
      *   DESCRIPTIVE NAME = Issue TSO commands from a COBOL program.  *
      *                                                                *
      *   FUNCTION = This sample program demonstrates how to invoke    *
      *              TSO commands from a COBOL program using           *
      *              standard TSO services as documented in the        *
      *              TSO/E Programming Services manual.                *
      *                                                                *
      *              Most TSO commands, including CLISTs and REXX      *
      *              execs can be executed using this technique.       *
      *              TSO commands which require authorization          *
      *              (such as OUTPUT, SEND, TRANSMIT and RECEIVE)      *
      *              will not work.                                    *
      *                                                                *
      *   Origin = http://gsf-soft.com/Freeware/                       *
      *                                                                *
      ******************************************************************
       Data Division.
        Working-Storage Section.
         01 Filler.
           05 ws-dummy        Pic s9(8) Comp.
           05 ws-return-code  Pic s9(8) Comp.
           05 ws-reason-code  Pic s9(8) Comp.
           05 ws-info-code    Pic s9(8) Comp.
           05 ws-cppl-address Pic s9(8) Comp.
           05 ws-flags        Pic X(4) Value X'00010001'.
           05 ws-buffer       Pic X(256).
           05 ws-length       Pic s9(8) Comp Value 256.

       Procedure Division.
      *----------------------------------------------------------------*
      *          Call IKJTSOEV to create the TSO/E environment         *
      *----------------------------------------------------------------*
           CALL 'IKJTSOEV' Using ws-dummy
                                 ws-return-code
                                 ws-reason-code
                                 ws-info-code
                                 ws-cppl-address.
           IF ws-return-code > zero
             DISPLAY 'IKJTSOEV Failed, Return-code=' ws-return-code
                                     ' Reason-code=' ws-reason-code
                                     'Info-code='    ws-info-code
             MOVE ws-return-code to Return-code
             STOP RUN.
      *----------------------------------------------------------------*
      *          Build the TSO/E command in ws-buffer                  *
      *----------------------------------------------------------------*

           MOVE 'ALLOCATE DD(SYSPUNCH) SYSOUT HOLD' to ws-buffer.

      *----------------------------------------------------------------*
      *   Call the TSO/E Service Routine to execute the TSO/E command  *
      *----------------------------------------------------------------*
           CALL 'IKJEFTSR' Using ws-flags
                                 ws-buffer
                                 ws-length
                                 ws-return-code
                                 ws-reason-code
                                 ws-dummy.
           IF ws-return-code > zero
             DISPLAY 'IKJEFTSR Failed, Return-code=' ws-return-code
                                     ' Reason-code=' ws-reason-code
             MOVE ws-return-code to Return-code
             STOP RUN.

      *----------------------------------------------------------------*
      *          Check that the ALLOCATE command worked                *
      *----------------------------------------------------------------*
           DISPLAY 'ALLOCATE Worked ! ' Upon Syspunch.

           STOP RUN.
/*
//SYSPRINT DD SYSOUT=*
//SYSUT1 DD UNIT=VIO,SPACE=(TRK,1)
//SYSUT2 DD UNIT=VIO,SPACE=(TRK,1)
//SYSUT3 DD UNIT=VIO,SPACE=(TRK,1)
//SYSUT4 DD UNIT=VIO,SPACE=(TRK,1)
//SYSUT5 DD UNIT=VIO,SPACE=(TRK,1)
//SYSUT6 DD UNIT=VIO,SPACE=(TRK,1)
//SYSUT7 DD UNIT=VIO,SPACE=(TRK,1)
//SYSLIN DD UNIT=VIO,SPACE=(TRK,1),DISP=(,PASS),BLKSIZE=3200
//*
//GO    EXEC PGM=LOADER,PARM=NOPRINT
//SYSLIN DD DSN=*.COB2.SYSLIN,DISP=(OLD,PASS)
//SYSLIB DD DSN=CEE.SCEELKED,DISP=SHR
//SYSOUT DD SYSOUT=*
//SYSTSPRT DD SYSOUT=*



O.
Back to top
View user's profile Send private message
murali922

New User


Joined: 25 Jul 2005
Posts: 92
Location: India

PostPosted: Tue Sep 26, 2006 3:34 pm    Post subject:
Reply with quote

Your question : How do I submit a JOB from my COBOL program ?

If I have understood your question I have a suggestion.

1. Do all processing you want to in your COBOL program.
2. Define the JOB card, EXEC, DD statements as working storage varialbles, like the below one :-

Code:
01  BATCH-JCL-AREA.                                             
...CARD 1                                                       
    05 JOB-CARD.                                                 
      10 FILLER           PIC X(04) VALUE "//DL".               
      10 WS-XXX                PIC X(02).                             
      10 WS-JOB-NAME-2    PIC X(05) VALUE "EXAMP".               
      10 FILLER           PIC X(10) VALUE "JOB CLASS=".         
      10 WS-XXX              PIC X(01).                             
      10 FILLER           PIC X(10) VALUE ",MSGCLASS=".         
      10 WS-MSGCLASS-1    PIC X(01).                             
      10 FILLER           PIC X(47) VALUE SPACES.               
...CARD 2                                                       
    05 JCLLIB-CARD.                                             
      10 FILLER           PIC X(20) VALUE "// JCLLIB ORDER=(ZX.".
      10 WS-ENV-1         PIC X(07) VALUE "PROD.DL".             
      10 WS-DEPOT-2       PIC X(02).                             
      10 FILLER           PIC X(12) VALUE ".PROCLIB,ZX.".       
      10 WS-ENV-2         PIC X(04) VALUE "PROD".   


define the job cards just like the above. You coding this depends on what your JCL should have.

Code:
EXEC CICS WRITEQ TD       
          QUEUE("DSUB")   
          FROM(JCL-CARD)
END-EXEC                 


DSUB is my INTRDR. You might need to ask your system administrator about yours.

Write all the contents into the INTRDR (Internal reader).
You would require a TDQ to which you write your job statements and the TDQ name is the name of your INTRDR.

Once you start writing it into the INTRDR, the job would get submitted.

Hope this info helps...
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2360
Location: Israel

PostPosted: Tue Sep 26, 2006 4:19 pm    Post subject:
Reply with quote

I think he was asking about COBOL under TSO, not CICS...

O.
Back to top
View user's profile Send private message
Kevin

Active User


Joined: 25 Aug 2005
Posts: 234

PostPosted: Tue Sep 26, 2006 5:50 pm    Post subject: Re: How to run a JCL from COBOL
Reply with quote

Quote:

How to run a JCL from COBOL


You run a JOB. Jobs are written in JCL. This is like saying you want to "execute a COBOL". Doesn't really make sense, does it?
Back to top
View user's profile Send private message
krishna_Murty
Warnings : 2

New User


Joined: 17 Sep 2006
Posts: 24

PostPosted: Wed Sep 27, 2006 9:35 am    Post subject: Re: How to run a JCL from COBOL
Reply with quote

Thank you so much, after posting the question i became little busy and could not see the forum again. i will review the code and get back.

Once again thanks for taking so much importance for my query and replying to it.
Back to top
View user's profile Send private message
krishna_Murty
Warnings : 2

New User


Joined: 17 Sep 2006
Posts: 24

PostPosted: Sat Sep 30, 2006 12:23 pm    Post subject:
Reply with quote

ofer71

I wrote a COBOL program, Just for ur understanding the main statements in COBL PRG ARE

FILE-CONTROL
SELECT JCL-OUT ASSIGN TO UT-S-JCLDD.

DATA DIVISION.
FD JCL-OUT
RECORD CONTAINS 80 CHARACTERS
RECORDING MODE IS F
DATA RECORD IS JCL-RECOUT.

01 JCL-RECOUT PIC X(80).

00000-MAINLINE.
OPEN INPUT JCL-IN
OPEN OUTPUT JCL-OUT
PERFORM 1000-READ-MOVE UNTIL EOF
CLOSE JCL-IN
CLOSE JCL-OUT
GOBACK.

1000-READ-MOVE.
IF NOT EOF
READ JCL-IN INTO WS-RECORD
AT END MOVE 'Y' TO WS-EOF
END-READ
MOVE WS-RECORD TO JCL-RECOUT
END-IF

This above cobol program reads JCL input file and move the records to output file, (Note I did not write the records to output only moved)

Now from the JCL point of view to run the above cobol , i wrote

//JCLDD DD SYSOUT=(*,INTRDR)

The job thus the Program is running fine but not executing the JCLDD file, ie. the output JCL file is not firing.

Can u please guide me, where i went wrong.

Also this is not from CICS point of view, this is batch programing i am looking for.

Thanks
Back to top
View user's profile Send private message
kamran

New User


Joined: 01 May 2005
Posts: 55

PostPosted: Sat Sep 30, 2006 6:54 pm    Post subject:
Reply with quote

Hi,
You coded completly right except you must write the record instead of just "MOVE WS-RECORD TO JCL-RECOUT"
so change the code to:
"write JCL-RECOUT from WS-RECORD."


krishna_Murty wrote:
ofer71

I wrote a COBOL program, Just for ur understanding the main statements in COBL PRG ARE

FILE-CONTROL
SELECT JCL-OUT ASSIGN TO UT-S-JCLDD.

DATA DIVISION.
FD JCL-OUT
RECORD CONTAINS 80 CHARACTERS
RECORDING MODE IS F
DATA RECORD IS JCL-RECOUT.

01 JCL-RECOUT PIC X(80).

00000-MAINLINE.
OPEN INPUT JCL-IN
OPEN OUTPUT JCL-OUT
PERFORM 1000-READ-MOVE UNTIL EOF
CLOSE JCL-IN
CLOSE JCL-OUT
GOBACK.

1000-READ-MOVE.
IF NOT EOF
READ JCL-IN INTO WS-RECORD
AT END MOVE 'Y' TO WS-EOF
END-READ
MOVE WS-RECORD TO JCL-RECOUT
END-IF

This above cobol program reads JCL input file and move the records to output file, (Note I did not write the records to output only moved)

Now from the JCL point of view to run the above cobol , i wrote

//JCLDD DD SYSOUT=(*,INTRDR)

The job thus the Program is running fine but not executing the JCLDD file, ie. the output JCL file is not firing.

Can u please guide me, where i went wrong.

Also this is not from CICS point of view, this is batch programing i am looking for.

Thanks
Back to top
View user's profile Send private message
kris.2020

New User


Joined: 09 May 2006
Posts: 2

PostPosted: Tue Oct 03, 2006 1:15 pm    Post subject: Re: How to run a job from COBOL
Reply with quote

Thanks for info
icon_biggrin.gif
Back to top
View user's profile Send private message
krishna_Murty
Warnings : 2

New User


Joined: 17 Sep 2006
Posts: 24

PostPosted: Tue Oct 03, 2006 5:04 pm    Post subject:
Reply with quote

Thanks to all
I got the job running fine

Regards
Krishna
Back to top
View user's profile Send private message
jijesh

New User


Joined: 09 May 2006
Posts: 4

PostPosted: Mon Nov 13, 2006 3:44 pm    Post subject: Re: How to run a job from COBOL
Reply with quote

Hi all

I am very news to Mainframes.

i was just not able to figure out the advantage of submitting a JCl through a cobol??????

if we need to run multiple programs, we can use a Proc. why then do we need one program like this?????

also can we submit the job for the same program???? or is it that this program will be run normally and all the others jobs will be triggered subsequently by this program.

please help me in having a better clarity about the entire concept.

thanks
Back to top
View user's profile Send private message
supreethi.srid

New User


Joined: 15 Oct 2009
Posts: 5
Location: Chennai,India

PostPosted: Mon Feb 20, 2017 5:46 pm    Post subject: Reply to: How to run a job from COBOL
Reply with quote

I am trying to execute a TSO command from IMS online by invoking transaction from the terminal. Getting RC of 16 while executing IKJTSOEV. Ignoring that assuming that the environment is already set, I continue to execute IKJEFTSR, I am getting the following :
RETURN CODE - 000000012
REASON CODE - 00000000J
ABEND CODE - 00000000J
For the above, I am trying to execute a sample TSO command to allocate a new dataset. Passed this flag combination - X'00010001'. (My original intent is to execute a set of ACF sub-commands, say, to reset expired password by resetting invalid pw count).

Please provide help on setting up appropriate flags for a sample allocate function. Does the command work at all for executing the TSO ACF sub-commands? - a question on feasibility now. If, so what flags for this one?
Back to top
View user's profile Send private message
steve-myers

Active Member


Joined: 30 Nov 2013
Posts: 534
Location: The Universe

PostPosted: Mon Feb 20, 2017 6:10 pm    Post subject:
Reply with quote

Running the TSO SUBMIT command from a Cobol program is more complex than it has to be.

In z/OS, the system provides a capability called an "internal reader." An internal reader is a pseudo data set specified in JCL as

//ddname DD SYSOUT=(x,INTRDR)

The x in SYSOUT=(x,INTRDR) becomes the output message class for the submitted job unless the job's // JOB statement specifies MSGCLASS=y.

With the internal reader specified in the JCL used to run a Cobol program, all the Cobol program has to do is open the data set assigned to DD name ddname for output and write the JCL for the job the Cobol program wants to run to the data set.

This capability has been in the system since the first release of MVS. Use it!
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8117
Location: East Dubuque, Illinois, USA

PostPosted: Mon Feb 20, 2017 6:28 pm    Post subject:
Reply with quote

supreethi.srid, you replied to a topic TEN AND A HALF YEARS OLD! And your question really has nothing to do with the original topic. You need to find and read the forum rules before you post anything else.
Quote:
Ignoring that assuming that the environment is already set, I continue to execute IKJEFTSR
This is stupid. You ignore return codes ONLY if you don't expect anything else you're doing to work. You should figure out what the return code means, and why you got it, and how to fix it BEFORE attempting to do anything else.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Mon Feb 20, 2017 10:36 pm    Post subject: Reply to: How to run a job from COBOL
Reply with quote

Please start a completely new question, and be exactly clear about what you are trying to achieve, rather than how you are trying to achieve it.

"I want to be able to reset an 'ACF-password' from an IMS transaction". Is that it?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies.    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm
No new posts Dynamic output file creation in cobol... smileheal COBOL Programming 7 Thu Jun 15, 2017 10:53 pm
No new posts Search utility(3.14) using JCl and Cobol RKS3 COBOL Programming 12 Sat Jun 10, 2017 10:24 pm
No new posts COBOL DB2 program - zIIP eligible vasanthz COBOL Programming 7 Wed May 31, 2017 5:12 am
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us