IBM MINAKSHI wrote:For Do while logic.. do we need to put array replacement in COBOL?
By no means.
As the input data are very simple, the correspondence between the PL/I structure and the COBOL record is also very simple. I wrote:
Code: Select all
dcl 1 input_record unal,
2 source char (3),
2 account_number char (15),
2 id char (8),
2 ccode char (3),
2 message (10) char (30);
dcl 1 input_record unal,
2 source char (3),
2 account_number char (15),
2 id char (8),
2 ccode char (3),
2 message (10) char (30);
In COBOL, this becomes:
01 INPUT_RECORD.
02 SOURCE PIC X(3).
02 ACCOUNT_NUMBER PIC X(15).
02 ID PIC X(8).
02 CCODE PIC X(3).
02 MESSAGE OCCURS 10 TIMES PIC X(30).
02 SOURCE PIC X(3).
02 ACCOUNT_NUMBER PIC X(15).
02 ID PIC X(8).
02 CCODE PIC X(3).
02 MESSAGE OCCURS 10 TIMES PIC X(30).
Note that the unaligned (unal) keyword is applied to the PL/I structure, eliminating the insertion of “slack” bytes by the compiler to force subordinate variables to start on “natural” boundaries. There is no direct COBOL equivalent, although the PL/I keyword aligned does have the COBOL equivalent of SYNCHRONIZED. Note also that, as the individual fields are all character/PIC X, they will all start on byte boundaries; however, I declare all my structures unaligned from habit.
Now, PL/I is a block-structured language, unlike COBOL (although programmers usually find that many of the block-structure features of PL/I are more trouble than they are worth). The PL/I program is simply
read file (tulin) into (input_record);
do while (¬eof_tulin);
[everything else]
end;
do while (¬eof_tulin);
[everything else]
end;
However, COBOL’s own structure makes this fairly easy to emulate; the corresponding code is:
PROCEDURE DIVISION.
0000-MAIN.
READ INPUT-FILE INTO INPUT-RECORD
AT END MOVE 'Y' TO EOF-INPUT-FILE.
PERFORM 1000-PROCESS UNTIL EOF-INPUT-FILE.
GOBACK.
1000-PROCESS.
[everything else]
0000-MAIN.
READ INPUT-FILE INTO INPUT-RECORD
AT END MOVE 'Y' TO EOF-INPUT-FILE.
PERFORM 1000-PROCESS UNTIL EOF-INPUT-FILE.
GOBACK.
1000-PROCESS.
[everything else]
Note that COBOL PERFORM…UNTIL is not the equivalent of do until in PL/I and other languages. The default is for the condition to be tested before the PERFORM, thus making it the equivalent of do while (you can force the test to be done after the PERFORM, thus making it the equivalent of do until.
Ah, but what, you ask, about the array handling? (In COBOL, the proper terminology is “internal table”). In PL/I, I use an iterated do while;
do i = 2 to 5 while (input_record.message(i)¬=' ');
output_detail.message = input_record.message (i);
call do_output;
end;
output_detail.message = input_record.message (i);
call do_output;
end;
In COBOL, you would use a PERFORM VARYING:
1000-PROCESS.
[other stuff]
PERFORM 1100-MESSAGE-LOOP
VARYING I FROM 2 BY 1
UNTIL I = 5 OR MESSAGE (I) OF INPUT-RECORD IS EQUAL TO SPACES.
READ INPUT-FILE INTO INPUT-RECORD
AT END MOVE 'Y' TO EOF-INPUT-FILE.
1100-MESSAGE-LOOP.
MOVE MESSAGE (I) OF INPUT-RECORD TO MESSAGE OF OUTPUT-DETAIL.
PERFORM 2000-OUTPUT.
[other stuff]
PERFORM 1100-MESSAGE-LOOP
VARYING I FROM 2 BY 1
UNTIL I = 5 OR MESSAGE (I) OF INPUT-RECORD IS EQUAL TO SPACES.
READ INPUT-FILE INTO INPUT-RECORD
AT END MOVE 'Y' TO EOF-INPUT-FILE.
1100-MESSAGE-LOOP.
MOVE MESSAGE (I) OF INPUT-RECORD TO MESSAGE OF OUTPUT-DETAIL.
PERFORM 2000-OUTPUT.