Page 1 of 1

basic cobol program issue

PostPosted: Wed May 08, 2013 2:27 pm
by NEWBSTER
Hello,
I am trying to run a COBOL program I made to add two numbers that are input by user, then display the result. I cannot get it to run in the foreground I guess you would say. So it sits waiting and I have to go to SDSF input queue to see that it is waiting on "enter first number", then go to SDSF system requests and type "R (num)", then go back to input queue to see it wants another number, then back to SR and type "R (num)", then I can finally go to Output queue to see it say "the answer is (num)". Below is my JCL and then my COBOL program any help would be greatly appreciated.

JCL:
000001 //KCO3B97 JOB TESTJCL                                       
000002 //STEP1 EXEC IGYWCLG                                         
000003 //COBOL.SYSIN DD DSN=KC03B97.FILES.COBOL(TEST1),DISP=SHR   
000004 //SYSPRINT DD SYSOUT=*                                       
000005 //                                                           


COBOL:
 000100 000100 IDENTIFICATION DIVISION.                                   
 000200 000200 PROGRAM-ID. TEST1.                                       
 000300 000300 ENVIRONMENT DIVISION.                                       
 000310 000310 SPECIAL-NAMES.                                             
 000320 000320     CONSOLE IS KEYBOARD.                                   
 000400 000400 DATA DIVISION.                                             
 000600 000600 WORKING-STORAGE SECTION.                                   
 000800 000800 01  NUM1      PICTURE IS 99.                               
 000900 000900 01  NUM2      PICTURE IS 99.                               
 001000 001000 01  ANSWER    PICTURE IS 999.                               
 001300 001300                                                             
 001310 001310 PROCEDURE DIVISION.                                         
 001400 001400 PROGRAM-BEGIN.                                             
 001500 001500                                                             
 001600 001600     DISPLAY "ENTER THE FIRST NUMBER :" UPON CONSOLE.       
 001800 001800     ACCEPT NUM1 FROM KEYBOARD.                             
 001900 001900                                                             
 002000 002000     DISPLAY "ENTER THE SECOND NUMBER :" UPON CONSOLE.       
 002300 002300     ACCEPT NUM2 FROM KEYBOARD.                             
 002400 002400                                                             
 002500 002500     COMPUTE ANSWER = NUM1 + NUM2.                           
 002600 002600     DISPLAY "THE ANSWER EQUALS : " UPON CONSOLE.           
 002700 002700     DISPLAY ANSWER UPON CONSOLE.                           
 002900 002900 PROGRAM-DONE.                                               
 003000 003000     STOP RUN.                                               

Re: basic cobol program issue

PostPosted: Wed May 08, 2013 2:35 pm
by enrico-sorichetti
instead of ACCEPT using the console use ACCEPT from SYSIN
and a plain DISPLAY will <display> things on sys print

serach the forum and You will find quite a few examples.

Re: basic cobol program issue

PostPosted: Wed May 08, 2013 4:30 pm
by Anuj Dhawan
Are you allowed to use "UPON CONSOLE" at your shop? Or you're practicing at mainframe of some Coaching Institute?

And if you really want a 'prompt' for end-user, try CICS and/or IMS DC -- COBOL batch programming is, well, for Batch.

Re: basic cobol program issue

PostPosted: Wed May 08, 2013 4:40 pm
by BillyBoyo
Yes, as Anuj indicates, you should not use CONSOLE.

If there is a "user" who is entering values, that user is going to be sitting in front of a CICS or IMS DC "program", which can be written in Cobol.

If you want to do some practice, using ACCEPT, don't use "FROM", as the default is SYSIN. Just plain
ACCEPT data-name


In your JCL, have your data like this:

//SYSIN DD *
01
02


Simply DISPLAY the output required. Don't use UPON CONSOLE.

DISPLAY "This is some text " data-name


By default DISPLAY output goes to the SYSOUT DD. I'd expect there to be one in the PROC which you are executing from your JCL. The SYSPRINT DD is for the Cobol listing output.

Re: basic cobol program issue

PostPosted: Wed May 08, 2013 7:25 pm
by NEWBSTER
I had ACCEPT NUM1 before didn't use any FROM statements or UPON statements for ACCEPT or DISPLAY but it was not prompting me on the screen.

Yes if I put the numbers to be entered in the JCL it would run but that sort of negates the whole purpose for the "Enter the First number" display message because you would already have to know what it said to run the JCL....

I am trying to approach this as someone running this and not knowing what the requested data is. And this is for a project at college and I am a beginner. I just submitted the simple project as is but am still curious if I can get this to run in the foreground and say

Enter the first number:
(wait for reponse) 15
Enter the second number:
(wait for response) 25
The Answer equals: 040

And yes, I realize COBOL was not the proper language to do this in a real life situation, but we had to do a simple program that we thought up ourselves and we had to do proposals way before we knew anything about zOS at all so I was stuck with it. Anyway... can it be run and displayed in real time?

Re: basic cobol program issue

PostPosted: Wed May 08, 2013 7:48 pm
by BillyBoyo
COBOL is a proper language to do it in.

It is just that, when running on a Mainframe, "interaction" is done through CICS or IMS DC or you might try running your program under TSO.

You will never write a program like that (which ACCEPT/DISPLAY to do the "work") for a user on a Mainframe.

If you want to do it on a PC, download OpenCobol and compile your program with that.

Re: basic cobol program issue

PostPosted: Wed May 08, 2013 9:34 pm
by Robert Sample
Anyway... can it be run and displayed in real time?
A mainframe screen is NOT interactive. You may type as many characters as you want on a mainframe screen, but the system will not look at the first character until you hit an appropriate key (such as enter, or PF key, or clear, etc). Hence what you want to do -- real-time processing -- is not at all possible on a mainframe.

However, what I think you want to do is interactively execute the program. This can be done via TSO/E; once compiled, you allocate SYSIN and SYSOUT to your terminal and then invoke the program. When you do that, the TSO/E screen will have your prompt and you can type your response (remembering, of course, to match the COBOL data definition so if you want a 3-digit number input that is defined as PIC 9(3) then you have to enter 001 instead of just 1) on the terminal. The specific details on how to do this are dependent upon your site, so you would be best off talking to your site support group about it.
WORKING-STORAGE SECTION.
01  VAR1                        PIC 9(3).
01  VAR2                        PIC 9(3).
01  VAR3                        PIC 9(3).
PROCEDURE      DIVISION.
    DISPLAY 'ENTER YOUR FIRST 3-DIGIT NUMBER'.
    ACCEPT VAR1.
    DISPLAY 'ENTER YOUR SECOND 3-DIGIT NUMBER'.
    ACCEPT VAR2.
    COMPUTE VAR3 = VAR1 + VAR2.
    DISPLAY VAR1 ' + ' VAR2 ' = ' VAR3.
    GOBACK.
produces
 ENTER YOUR FIRST 3-DIGIT NUMBER
003
 ENTER YOUR SECOND 3-DIGIT NUMBER
018
 003 + 018 = 021
 ***

Re: basic cobol program issue

PostPosted: Thu May 09, 2013 4:24 am
by NEWBSTER
Robert, that program is what I had originally before I started forum hunting and adding things to it such as console and such to try to get the program to execute and wait for input on screen. My program itself did and still does work, its just that my JCL is missing something I think. I was also running it from within ISPF while editing the JCL and then just typing SUB in the command line.
I think I need to add something like :
//LKED.SYSLMOD DD DSN=KC03B97.FILES.LOAD(TEST1),DISP=SHR

The program is running, it is just doing it in the background. I will try this when I go home, as well as making the COBOL back to the more simple form it used to be with just basic ACCEPT and DISPLAY statements. Anyone see anything in my JCL that looks prohibitive for this to function correctly?

Re: basic cobol program issue

PostPosted: Thu May 09, 2013 5:02 am
by Robert Sample
As long as you are using JCL, you cannot interact with the program -- period. If you want to interact with the program, and you can get to a native TSO prompt (READY), you can enter these commands:
ALLOC DA(*) FI(SYSIN)
ALLOC DA(*) FI(SYSOUT)
CALL 'KC03B97.FILES.LOAD(TEST1)'
and you will interact with the program. Note that doing this is not always possible as some sites prevent access to native TSO by forcing use of ISPF. You can do the same thing through option 6 of ISPF as an alternative.

Re: basic cobol program issue

PostPosted: Thu May 09, 2013 7:10 pm
by dick scherrer
Hello,

FWIW - i would encourage you to work within ISPF. You may get "stuck" in native TSO (if you can get there at all).

Unfortunately, many of the newer "system programmers" have never worked in native TSO and may not be much help.