View previous topic :: :: View next topic
|
Author |
Message |
sureshmurali Warnings : 1 New User
Joined: 25 Nov 2010 Posts: 70 Location: Sivakasi, India
|
|
|
|
Hi
I hava a cobol program.
In it there are three lines of input string in SYSIN.
say
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
I have a dataname VAR1 PIC IS X(80).
I need to ACCEPT these inputs using the data name VAR1 and print them out on the spool.
I know how to do this using READ statement by taking SYSIN as a dataset. While taking SYSIN as a dataset, i can use READ statement and check for End of File using AT END.
But i just want to know how it can be done using ACCEPT statement.
Is there any way of checking the End of the input when using ACCEPT statment.
PERFORM 3 TIMES
ACCEPT VAR1 FROM SYSIN
DISPLAY VAR1
END-PERFORM.
It prints all the three lines of input. But here i mentioned 3 times which represent 3 lines of input strings. But i need the system will take care of end of file at the run time. How can i do it? |
|
Back to top |
|
 |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
According to the manual ( which you should have read ):
"If EOF is encountered before any data has been moved to the
receiving area, padding will not take place and the contents of the
receiving area are unchanged"
So, the way to "test" for EOF is to pre-load the receiving area with some value that would NEVER be input via SYSIN ( e.g. low values ), and then, AFTER the ACCEPT, test to see if the area still contains that pre-loaded value - if it does, then you have reached EOF. |
|
Back to top |
|
 |
sureshmurali Warnings : 1 New User
Joined: 25 Nov 2010 Posts: 70 Location: Sivakasi, India
|
|
|
|
Thanks for your reply Ronald. But i dont get you.
If possible could you please explain this with a small example.
Your kind help makes me to understand the solution better.
Thanks |
|
Back to top |
|
 |
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
What's to explain?
Code: |
MOVE LOW-VALUE TO VAR1(1:1)
ACCEPT VAR1 FROM SYSIN
IF VAR1(1:1) = LOW-VALUE
THEN
do what should be done if SYSIN is at EOF
ELSE
do what should be done if SYSIN is NOT at EOF
END-IF |
|
|
Back to top |
|
 |
dick scherrer
Site Director
Joined: 23 Nov 2006 Posts: 19270 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
But i just want to know how it can be done using ACCEPT statement. |
FWIW - none of the systems i've supported for many years (over 20) allow data entering the program via ACCEPT/sysin.
A parm is used for small amounts of data and a "real file" is used for things like your situation. |
|
Back to top |
|
 |
Phrzby Phil
Active Member
Joined: 31 Oct 2006 Posts: 972 Location: Richmond, Virginia
|
|
|
|
But it is good robust programming to check for the lack of the three parms the program is expecting via ACCEPT.
If three parms are not present, or if other validity checks fail, then the program should be appropriately terminated. |
|
Back to top |
|
 |
sureshmurali Warnings : 1 New User
Joined: 25 Nov 2010 Posts: 70 Location: Sivakasi, India
|
|
|
|
Thanks buddies. |
|
Back to top |
|
 |
Jose Mateo
Active User
Joined: 29 Oct 2010 Posts: 114 Location: Puerto Rico
|
|
|
|
You could do what Mr. Burr suggested or you could put a end-of-file marker in your sysin like 'END' which you would test for in your program to know that you have reached the end of data. |
|
Back to top |
|
 |
|