Different Length Redefinitions

Question: I have a variable(REC1) which is defined as CHAR(1016). And Isecond variable(REC2) defined "BASED" on REC1. But the length is of REC2 is greater (i.e. 1020) than REC1. So how two define these variables using pointers in PL/1.

Answer: Whenever you access the longer record you will be destroying the content of whatever field that is using that adjacent memory space. Depending on just exactly what that part of memory contains the result could vary between having no apparent effect and causing totally unexpected results in some unrelated part of the program that was using that memory for something else entirely.

When you use BASED in Pl/1 you are not defining new storeage. What you are defining is simply a different way of referencing some existing storage. BASED acts as a pointer to the start of the storage area that this definition is to be based on.

What you need to do is to ensure that the initial area is at least as big as the largest content you expect it to have. In this case where you are reading two different record layouts into the same part of storage, the most appropriate way to define them is to first define a simple CHAR field that is at least the size of the longest record. You would then use BASED to attach each of the individual record layouts over that field. By doing this the storage will be big enough to hold the longest record and you will not end up with records that overflow into whatever fields are in the storage immediately after the one you are overlaying with the different definition.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow