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   Reply to topic    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
View previous topic :: :: View next topic  
Post new topic   Reply to topic    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 Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm
No new posts Need Suggestion on COBOL program vickey_dw COBOL Programming 5 Thu Jan 05, 2017 10:55 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm


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