QUESTION RELATED TO OCCURS ..



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

QUESTION RELATED TO OCCURS ..

Postby pradeepgowda » Mon Apr 12, 2010 3:31 pm

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
pradeepgowda
 
Posts: 40
Joined: Mon Jan 04, 2010 4:17 pm
Has thanked: 0 time
Been thanked: 0 time

Re: QUESTION RELATED TO OCCURS ..

Postby Robert Sample » Mon Apr 12, 2010 4:50 pm

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?
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: QUESTION RELATED TO OCCURS ..

Postby ramtulasi » Wed May 26, 2010 9:36 am

answer 5,
becasue array start 0 to 5th position 5 value.
Ram T
ramtulasi
 
Posts: 10
Joined: Fri May 21, 2010 9:21 am
Location: Malaysia
Has thanked: 0 time
Been thanked: 0 time

Re: QUESTION RELATED TO OCCURS ..

Postby dick scherrer » Wed May 26, 2010 9:50 am

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. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: QUESTION RELATED TO OCCURS ..

Postby ramtulasi » Wed May 26, 2010 12:38 pm

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......
Ram T
ramtulasi
 
Posts: 10
Joined: Fri May 21, 2010 9:21 am
Location: Malaysia
Has thanked: 0 time
Been thanked: 0 time

Re: QUESTION RELATED TO OCCURS ..

Postby Robert Sample » Wed May 26, 2010 4:52 pm

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".
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: QUESTION RELATED TO OCCURS ..

Postby ramtulasi » Mon May 31, 2010 9:21 am

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
Ram T
ramtulasi
 
Posts: 10
Joined: Fri May 21, 2010 9:21 am
Location: Malaysia
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post