I am designing a COBOL program that does 2 things.
1 reads specific rows from a table, and inserts a new row based on the original.
2 reads different rows from the same table, and updates those rows.
Is it bad standards to have 2 initialization procedures? I need to declare 2 SQL cursors, one for each task. So I was thinking:
1 initialize cursor, 2 process, 3 initialize cursor, 4 process.
But that seems like bad logic. something is telling me it should be more like:
1 initialize cursor, 2 process
But I’m having trouble thinking it out because to me, they are 2 separate tasks.
I tried to think of a way that my SQL query could do the work, and then I could just do some validation. But I’m not sure the query would be any more efficient than having a second read of the table.
Here’s my structure ideas
I’ve added a 3rd chart that I believe follows the answer given to me on this question. Does the 3rd chart seem to me the most logical?
3
You should separate the two tasks. You should have two cursors and initialize each separately since one is used for read and the other is for read/write.
You’d go like:
Move 0 to rc.
Perform Task1
If rc > 0
logic to display message and end run.
end
perform Task2
If rc > 0
logic to display message and end run.
end
perform end of job messages and close open files if any.
Stop Run.
.....................
Task1 is:
Open cursor 1 ...
...
Close cursor 1.
.....................
Task2 is:
Open cursor 2 ...
...
Close cursor 2.
In outline it sh:ould look like:
A01-MAIN
PEFFORM B01-PROCESS-CURSOR1
IF OK
PERFORM C01-PROCESS-CURSOR2
END-IF
B01-PROCESS-CURSOR1.
PERFORM B02-INITIAL.
PERFORM UNTIL SQLCODE NOT = 0
PERFORM B03-NEXT-ROW
PERFORM B04-INSERT-NEW
END-PERFORM.
PERFORM B09-CLOSE.
.
.
.
C01-PROCESS-CURSOR2.
PERFORM C02-INITIAL.
PERFORM UNTIL SQLCODE NOT = 0
PERFORM C03-NEXT-ROW
PERFORM C04-UPDATE
END-PERFORM.
PERFORM C09-CLOSE.
.
0