View previous topic :: View next topic
|
Author |
Message |
Agni
New User
Joined: 22 Nov 2007 Posts: 83 Location: Chennai
|
|
|
|
Dear All,
I am working on a requirement in which I have to create a new copy book and have to move the file operations like Open, Read, Write, close etc. for four different programs. I have a code as mentioned below from which I have to take the Read part alone (first four lines) and move it to the copy book. It is in the paragraph READ-FILE in the program. This paragraph is called 4 times in the program.
Code: |
READ-FILE.
READ <File name>
NEXT
AT END
MOVE 2 TO <File-Status>
NOT AT END
IF A = 2 OR 3
Do Something
ELSE
Do Something else
END-IF.
|
I split the code into two parts as below. Moved the below Read part to the copy book and added an IF condition to check the for the 'not end of file' status as below.
(Below READ statement is moved to copybook with a paragraph name)
Code: |
READ-FILE.
READ <File name>
NEXT
AT END
MOVE 2 TO <File-Status>.
|
Below code snippet is retained in the program itself and is added after where the original READ-FILE is called.
Code: |
IF File-status NOT = 2
IF A = 2 OR 3
Do Something
ELSE
Do Something else
END-IF
END-IF.
|
Here I am facing a problem wherein there is a PERFORM READ-FILE UNTIL END-OF-FILE OR VALID-NAME in the ELSE part of an IF condition.
If I add the second part of split code after the above PERFORM paragraph, I feel that the IF condition I added may not be executed
because of the END-OF-FILE switch is set. Please note that the File-status here is nothing but the END-OF-FILE.
Code: |
ELSE
PERFORM READ-FILE
UNTIL END-OF-FILE
OR VALID-NAME
IF File-status NOT = 2
IF A = 2 OR 3
Do Something
ELSE
Do Something else
END-IF
END-IF.
|
Is there any way that I can get rid of this? I hope I have explained properly. Pls let me know if you have any queries.
Cheers
Agni. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
By using a copy book in the way you are using it, you are changing the logic. In the original code you posted, PERFORM READ-FILE UNTIL END-OF-FILE will test A to be 2 or 3 and perform appropriate code each time a record is read. Your revised logic will test A to be 2 or 3 only after the end of file is reached (or VALID-FILE is set, whatever that is), not for each record.
What you want to do can be done, but you will have to rewrite the logic of the program to properly separate open / read / write / close logic from the business logic. Such a rewrite may require anything from changing a few statements to a complete rewrite of the code depending upon the logic. You need to go to whoever gave you the task, explain the problem, and find out if you should attempt to rewrite the code or accept that using a copy book for file operations in that program will not work. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Priming read.
Code: |
PERFORM READ
PERFORM UNTIL END-OF-FILE (10 on FILE-STATUS field)
Do some stuff
PEFORM READ
END-PERFORM |
Gets all the "file" processing (including headers and trailers, empty files) away from the business logic. Just keep all of the stuff away from "Do some stuff". |
|
Back to top |
|
|
|