INITIALIZE a REDEFINED Variable



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

INITIALIZE a REDEFINED Variable

Postby Khupe » Tue Feb 09, 2021 1:50 pm

Hi,

I have a query regarding INITIALIZing REDEFINED variable.

I've below code in the program which redefines WS-A with WS-B. And WS-B is INITIALIZEd later in the program.

01  WS-A.                                        
    05  WS-A-OUTLINE.                                      
         10  WS-A-SYSTEM-ID          PIC  X(02).            
         10  WS-A-SUBSYS-ID          PIC  X(04).            
         10  WS-A-TYPE               PIC  X(01).            
             88  WS-A-TYPE-OK             VALUE "O", "B".  
             88  WS-A-ONLINE              VALUE "O".        
             88  WS-A-BATCH               VALUE "B".        
                                                               
    05  WS-A-INLINE.                                    
        10  WS-A-RC                  PIC  X(02).            
            88  WS-A-DATA                 VALUE SPACE, "20".
            88  WS-A-ERROR                VALUE "10", "90".
    05  WS-REST                      PIC X(<remaining>).   <-- P.S: I've omitted declaration of rest of the variables as it'd be lengthier.

01  WS-B  REDEFINES WS-A.
    05 FILLER                       PIC X(400).
.
.
.
.
.
INITIALIZE WS-B.
.
.
.

 



But while compiling this program in COBOL 4.2, I'm getting no warnings. However, in COBOL 6.2, I'm getting below warning.



IGYPS2047-W   "INITIALIZE" statement operand "WS-B" did not meet conditions for initialization.
              "WS-B" was not initialized.                    



I think it is because COBOL 6.2 will not allow to INITIALIZE a redefined variable (WS-B).
So in that case, will I be able to achieve same by INITIALIZing WS-A instead of WS-B?

Thanks.
Khupe
 
Posts: 2
Joined: Mon Nov 23, 2020 1:07 pm
Has thanked: 1 time
Been thanked: 0 time

Re: INITIALIZE a REDEFINED Variable

Postby TERMEN » Thu Mar 04, 2021 2:29 am

The root cause is actually not because of the use of the REDEFINED data item. It is because there is only 1 data item that is subject to WS-B and it is named "FILLER".

COBOL V5+ closed some earlier loopholes in regards to INITIALIZE. One of them is that if a data item only has "FILLER" subject to it, then you can't initialize it with only the INITIALIZE statement.

To fix the code there are 2 choices:
1) Rename "FILLER" to a real data-item name, like "WS-B-FILLER", so that it no longer adheres to INITIALIZE's "FILLER" rules.
2) Change "INITIALIZE WS-B" to "INITIALIZE WS-B WITH FILLER".

Essentially, without the "WITH FILLER" clause, there is nothing in the WS-B data item to initialize and the program will get the warning:
IGYPS2047-W "INITIALIZE" STATEMENT OPERAND "WS-B" DID NOT MEET CONDITIONS FOR INITIALIZATION. "WS-B" WAS NOT INITIALIZED.
TERMEN
 
Posts: 1
Joined: Wed Mar 03, 2021 9:41 pm
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post