Record RecordA type SerialRecord { fileName = "myFile" } record_type char(1); field1 char(20); end Record RecordB type BasicRecord 10 record_type char(1); 10 field2 bigint; 10 field3 decimal(7); 10 field4 char(8); end Program ProgramX type basicProgram myRecordA RecordA; myRecordB RecordB {redefines = myRecordA}; function main(); get next myRecordA; while (myRecordA not endOfFile) if (myRecordA.record_type == "A") myFunction01(myRecordA.field1); else myFunction02(myRecordB.field2, myRecordB.field3, myRecordB.field4); end get next myRecordA; end end end
To declare one record variable as a redefinition of another, you use the redefines property. The property accepts the name of another record variable. This property is only available in a record variable declaration, not in a Record part definition.
Record StructuredRecordA 10 x INT; end Record StructuredRecordB 10 y INT; end Record TestRecord myRec1 StructuredRecordA; myRec2 StructuredRecordB { redefines=myRec1}; endSimilarly, if you declare one record in a library but outside of a function, you must also declare the other in the same library and also outside of a function.
The properties you assign to the original record do not affect the overlay record; only the memory area is redefined.
You cannot use an overlay record for I/O.
Record exampleRecord1 10 a INT; 20 aa INT; 20 ab CHAR(4) { redefines = a.aa }; 10 b CHAR(4) { redefines = a }; end
If you pass a variable based on exampleRecord1 in a call statement, the data of the redefined area is converted as if it were an INT and not a CHAR(4). If you initialize a.ab (for example, with a set empty statement), the data of the redefined area will be set to binary zeros and not blanks.
Record exampleRecord2 10 a int; 20 x int; 10 b char(4) { redefines = a }; 20 z char(4); 10 c char(4) { redefines = a }; end
Record exampleRecord3 10 a int[2]; 10 b char(2) { redefines = a }; // Illegal because a is an array end Record exampleRecord4 10 a bigint; 10 b char(1)[8] { redefines = a }; // Legal end Record exampleRecord5 10 top char(4)[3]; 20 a int; 20 b smallint { redefines = a }; // Legal even though a is an array end Record exampleRecord6 10 top char(12)[5]; 20 middle char(4)[3]; 30 a int; 30 b smallint { redefines = a }; // Legal even though a is an array end
package com.companyb.customer; Record RecC type basicRecord 10 dateFormat SMALLINT; 10 billingDate CHAR(8); 10 usBillingDate CHAR(8) {redefines=billingDate}; 20 month CHAR(2); 20 day CHAR(2); 20 year CHAR(4); 10 euroBillingDate CHAR(8) {redefines=billingDate}; 20 day CHAR(2); 20 month CHAR(2); 20 year CHAR(4); 10 deliveryDate CHAR(8); 10 usDeliveryDate CHAR(8) {redefines=deliveryDate}; 20 month CHAR(2); 20 day CHAR(2); 20 year CHAR(4); 10 euroDeliveryDate CHAR(8) {redefines=deliveryDate}; 20 day CHAR(2); 20 month CHAR(2); 20 year CHAR(4); End program RedefinesExample type BasicProgram ( inDateFormat SMALLINT, inDeliveryMonth CHAR(2), inDeliveryDay CHAR(2), inDeliveryYear CHAR(4), inBillingMonth CHAR(2), inBillingDay CHAR(2), inBillingYear CHAR(4)) {alias="REDXMP3"} // aRec is a structured record whose billingDate and deliveryDate items // are each redefined by two other items with substructure, // whose level is the same, and whose parent is the same aRec RecC; const USDateFormat SMALLINT=1; const EURODateFormat SMALLINT=2; function main() aRec.dateFormat = inDateFormat; // If date to be in US format if ( inDateFormat == USDateFormat ) usBillingDate.month = inBillingMonth; usBillingDate.day = inBillingDay; usBillingDate.year = inBillingYear; usDeliveryDate.month = inDeliveryMonth; usDeliveryDate.day = inDeliveryDay; usDeliveryDate.year = inDeliveryYear; else // Date must be in European format euroBillingDate.month = inBillingMonth; euroBillingDate.day = inBillingDay; euroBillingDate.year = inBillingYear; euroDeliveryDate.month = inDeliveryMonth; euroDeliveryDate.day = inDeliveryDay; euroDeliveryDate.year = inDeliveryYear; end end end