Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
    
Designing a COBOL program, as in writing new COBOL, not merely maintaining it? Poor you... :( –  pwny Jul 17 '12 at 18:50
1  
I disagree. New code > maintenance. –  zarchasmpgmr Jul 18 '12 at 1:48
    
New code becomes -> maintenance code. Why prolong the suffering?? –  Darknight Jul 18 '12 at 16:24
add comment

2 Answers

up vote 4 down vote accepted

You should separate the 2 tasks. You should have 2 cursors and initialize each separately since 1 is used for read and the other 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.

share|improve this answer
add comment

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.

    .
share|improve this answer
    
Thank you. useful in addition to the other answer. + –  Frantumn Jul 18 '12 at 13:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.