Redefine with the larger value.

This is a Mainframe COBOL forum - you can post your queries on Mainframe COBOL, VS COBOL II, COBOL/370 , Enterprise COBOL

Moderators: dbzTHEdinosauer, Moderator Group

Post Reply
sjadhav
Member
Posts: 2
Joined: Tue Mar 20, 2007 11:35 pm

Redefine with the larger value.

Post by sjadhav » Wed Mar 21, 2007 6:49 pm

Hi,

Could any body please tell me if i can redefine X(11) to X(20).
E.g Before change

05 Var-1.
10 Var-2 PIC X(11).
05 Var-3 PIC X(5)

After Change

05 Var-1.
10 Var-2 PIC X(11).
10 Var-4 REDEFINES Var-2 PIC X(20).
05 Var-3 PIC X(5)

But now in this case, is there a chance that i lose my data because of this change.
If my Input file contains "ABCDEFGHIJKLMNOPQRSTUVWXYZ", my variables will contain these values before any change
Var-2 : ABCDEFGHIJK
Var-3 : LMNOP

Now after redefines will i lose the data for Var-3
Var-4 : ABCDEFGHIJKLMNOPQRST
Var-3 : UVWXY

Please let me know.
Thanks,
Sachin.

Veera
Moderator
Posts: 111
Joined: Wed Feb 22, 2006 2:59 pm

Post by Veera » Thu Mar 22, 2007 4:47 am

Sachin,

In ur second case i.e after Change still Var-3 will hold : LMNOP only.

If u redefine with greater length than the variable which is being redefined,

the new variable which u redefined will have VALUE as menitoned below

This VALUE can be KLMNOPQRST as u have given, but it cant be guaranteed that it will always hold the value of KLMNOPQRST because what ever data that will be present in the
file is not always stored continously in the memory sequentailly.But in most of the cases u will get the value KLMNOPQRST but under extreeme cases based on the memory usage by other programs the value may vary.

But yes Var-3 will hold : LMNOP only this value doesnot cahnge.

Well we can run a sample test and confirm the same..will update you
on this once i do a test.

Thanks
Veera.

sjadhav
Member
Posts: 2
Joined: Tue Mar 20, 2007 11:35 pm

Post by sjadhav » Thu Mar 22, 2007 7:31 pm

Veera,

Thank you for your reply.

Here i am not clear that why you are saying the VALUE will be "KLMNOPQRST", which variable are you taking about.

Could you please help me understand, what will be the values of Var2, Var3, Var4 specifically after redefining the variables.

Also once you test the programs, please confirm the correct value.

Thanks,
Sachin.

Veera
Moderator
Posts: 111
Joined: Wed Feb 22, 2006 2:59 pm

Post by Veera » Fri Mar 23, 2007 12:53 am

Sachin,

05 Var-1.
10 Var-2 PIC X(11).
10 Var-4 REDEFINES Var-2 PIC X(20).
05 Var-3 PIC X(5)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
A B C D E F G H I J K L M N O P Q R S T

Sorry it was a typo error the value is "LMNOPQRST" and not KLMNOPQRST

I am referring this value to the partial positions of what u have defined for VAR-4
starting from postion 12 to 20.

The VAR-4 from 1 to 11 will definitely have the same value as 1 to 11 of VAR-2.

But the value of VAR-4 from 12 to 20 can vary it can be "LMNOPQRST" but
we cannot guarantee that it will always be "LMNOPQRST" since the data
in the INPUT file is not always stored continously in the memory.
It depends on how the data is stored in the meomory after 11th postion
i mean 12 to 20 postion of redefined varaible var-4.

As per ur information given in the post

You have given the value LMNOPQRST from postion 12 to 20 of var-4
based on the assumption that the data in the I/P file will be
stored continously "ABCDEFGHIJKLMNOPQRSTUVWXYZ", and since
from postion 12 u have "LMNOPQRST" so we get

1 to 11 from VAR-2 AND

12 TO 20 FROM I/P->FILE POSTIONS

But this is not always true, the data in postions from 12 to 20 can vary depending
on memory usage but most of the case we get the value as "LMNOPQRST" as per the
file data.But it will vary once in n times if we test randomly.

Values in Varaibles
*******************

Var-2 : ABCDEFGHIJK
Var-4 : ABCDEFGHIJK LMNOPQRST -> We cant 100% say for sure that from postion 12 we will
always have this value.
Var-3 : UVWXY

Thanks
Veera.

Veera
Moderator
Posts: 111
Joined: Wed Feb 22, 2006 2:59 pm

Post by Veera » Fri Mar 23, 2007 1:05 am

Sachin,

But there will be implications if you move any value to data
VAR-4 which of length 20, say if u move any value into
var-4 which is also of length 20 bytes then var-3 will hold
some data from it.


Thanks
Veera

User avatar
DavidatK
Active Member
Posts: 65
Joined: Tue Mar 27, 2007 8:41 am
Location: Troy, MI USA

Post by DavidatK » Wed Mar 28, 2007 4:52 am

Hi Sachin,

COBOL will slap you hand if you redefine a variable with a larger variable, but it will compile it. In my case we get a return 12 and will not link edit however.

Code: Select all

01  INPUT-RECORD.	    
    05  Var-1. 
        10 Var-2 PIC X(11). 
        10 Var-4 REDEFINES Var-2 PIC X(20). 
    05  Var-3 PIC X(5)
The code above, that redefines var-2 with a larger var-4 has the same offsets as the code below. Var-3 offset starts at var-1 + the largest data area in var-1.

Code: Select all

01  INPUT-RECORD.
    05  Var-1. 
        10 Var-4 PIC X(20). 
        10 Var-2 REDEFINES Var-4 PIC X(11). 
    05  Var-3 PIC X(5)
If you move ?ABCDEFGHIJKLMNOPQRSTUVWXY? to INPUT-RECORD.

In both coding cases above:
Var-1 will contain ?ABCDEFGHIJKLMNOPQRST?
Var-2 will contain ?ABCDEFGHIJK?
Var-4 will contain ?ABCDEFGHIJKLMNOPQRST?
Var-3 will contain ?UVWXY?

Dave

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others