Page 1 of 1

QUESTION RELATED TO OCCURS ..

PostPosted: Mon Apr 12, 2010 3:31 pm
by pradeepgowda
18. 77 A1 PIC X(10) VALUE "0123456789".
77 I PIC 99 VALUE 0.
01 B1.
02 C1 OCCURS 10 TIMES PIC 9.
PROCEDURE DIVISION.
M.
MOVE A1 TO B1.
DISPLAY B1(5).
STOP RUN.
WHAT WOULD BE THE OUTPUT OF THE ABOVE PROGRAM
A. DISPLAYS 12345
B. ILLEGAL MOVE HENCE A RUN-TIME ERROR
C. SYNTAX ERROR
D. 5
E. 4

Re: QUESTION RELATED TO OCCURS ..

PostPosted: Mon Apr 12, 2010 4:50 pm
by Robert Sample
Since B1 is not subscripted, and your DISPLAY statement doesn't have the proper format for reference modification, what do YOU think happens? Have you tried this yourself to see?

Re: QUESTION RELATED TO OCCURS ..

PostPosted: Wed May 26, 2010 9:36 am
by ramtulasi
answer 5,
becasue array start 0 to 5th position 5 value.

Re: QUESTION RELATED TO OCCURS ..

PostPosted: Wed May 26, 2010 9:50 am
by dick scherrer
Hello,

Did you look at the posted code? Did you read the reply from Robert?

If yes, how did you choose D. The code is completely wrong. . . :(

becasue array start 0 to 5th position 5 value.
The array is not even mentioned in the DISPLAY. . .

Re: QUESTION RELATED TO OCCURS ..

PostPosted: Wed May 26, 2010 12:38 pm
by ramtulasi
dick scherrer wrote:Hello,

Did you look at the posted code? Did you read the reply from Robert?

If yes, how did you choose D. The code is completely wrong. . . :(

becasue array start 0 to 5th position 5 value.
The array is not even mentioned in the DISPLAY. . .


Hello,

in code A1 assigns data,
B1 name table name
in procedure division.
map A1 to B1.
then second line DISPLAY B1(5).
what is wrong in this......

Re: QUESTION RELATED TO OCCURS ..

PostPosted: Wed May 26, 2010 4:52 pm
by Robert Sample
Ram T, are you aware that in COBOL arrays always start with element 1? Unlike C, for example, it is not possible for COBOL to use element zero of an array. If you do so, you will use memory that is not part of the array, potentially generating abends. If you check the COBOL Language Reference manual, you will find that subscripts are required to be a positive integer -- which means zero is not a valid subscript. Does COBOL check this? Only if the program was compiled with subscript range checking and the CHECK(ON) run time option is specified.

ramtolasi, since you're not willing to listen to experience, I ran your code exactly as you provided it:
       77  A1                          PIC X(10) VALUE "0123456789".
       77  I                           PIC 99 VALUE 0.
       01  B1.
           02  C1                      OCCURS 10 TIMES
                                       PIC 9.
       LINKAGE SECTION.
      /
       PROCEDURE DIVISION.
       S1000-MAIN       SECTION.
           MOVE A1                     TO  B1.
           DISPLAY B1(5).
and got results of
                 DISPLAY B1(5).

 IGYPS2120-S Expected a reference-modification specification but found ")".  The
             "DISPLAY" statement was discarded.
so the answer to your question, as I implied in my earlier post, is "C" -- syntax error. B1 is not an array and cannot be subscripted in this manner. If you had DISPLAY C1 (5) then a 4 would have been displayed. But as you gave the code, the answer is "C".

Re: QUESTION RELATED TO OCCURS ..

PostPosted: Mon May 31, 2010 9:21 am
by ramtulasi
Hi Robert,

sorry, my one is wrong, your's correct answer.
I think table group name B1, and mapped to B1 by A1.
but B1 don't have any occurs clasue so my answer was wrong...
i agree with you, your answer was correct.......
thank you for giving replay.....

by
Ram T