Length Of leyword in cobol



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

Length Of leyword in cobol

Postby arya_starc » Sat Nov 26, 2016 3:49 pm

What is the output came after giving the LENGTH OF keyword to some variable
In program ws-variable define in working storage section as

01  WS-HOLI-TABLE.                                            
    03 WS-HOLIDAY-RECORD        OCCURS 3 TIMES                
                                INDEXED BY                    
                                X-HOLIDAY.                    
       07 WS-HOLIDAY            PIC 9(07).                    

 

And in procedure division they are using this line of code


     INITIALIZE WS-HOLIDAY-RECORD(1)                              
     MOVE WS-HOLI-TABLE          TO                              
          WS-HOLI-TABLE ( LENGTH OF WS-HOLIDAY-RECORD(1) + 1 : )  
 



Please tell the output that I get from the below line
LENGTH OF WS-HOLIDAY-RECORD(1) + 1 :
is it this below I am not sure...!!
INITIALIZE WS-HOLIDAY-RECORD(1)
MOVE WS-HOLI-TABLE TO WS-HOLI-TABLE(8:)
arya_starc
 
Posts: 136
Joined: Mon Sep 21, 2015 1:39 pm
Has thanked: 5 times
Been thanked: 0 time

Re: Length Of leyword in cobol

Postby Robert Sample » Sat Nov 26, 2016 8:23 pm

Do you not know how to use the DISPLAY statement? Why not use DISPLAY to find out what the value is, rather than asking on a forum?

I suspect that the results of the MOVE are not what the coder expected. INDEXED BY doesn't change the way subscripts work.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Length Of leyword in cobol

Postby BillyBoyo » Sun Nov 27, 2016 3:11 am

LENGTH OF WS-HOLIDAY-RECORD is seven. It need not, in IBM Enterprise COBOL, be subscripted - all the entries are fixed-length, so id doesn't matter if you use ( 1 ), ( 2 ), ( 3 ) or nothing. All the same.

Adding one to seven gets eight. The advantage of calculating using LENGTH OF (which is evaluated at compile-time for fixed-length fields) is that if someone changes the length of WS-HOLIDAY-RECORD, the code still works, "automatically".

The code is doing what was intended. It is an "offset move", a way of establishing a "pattern" across a table.

When COBOL's WORKING-STORAGE was more limited in size (1MB maximum) the "offset move" was the most effective way to initialise a table of packed-decimal values, or of a table with a more complicated structure.

For this example, with an exceedingly simple pattern (zeroes) I'd just MOVE ZERO TO WS-HOLI-TABLE and have done with it.

A better technique to use to efficiently initialise a table these days is to have a another table the same size (or larger), set your entire table to initial values (once) by your preferred method, and then MOVE the entire table to the second table. Then, when you need to re-initialise, MOVE the second to the first.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post