How To Work with Dynamic List - Automated Way

Sometimes the legacy program has a list with a length defined by a dynamic counter field.
This guide shows how to handle this scenario with OpenLegacy in an automated way.

Fully Automated

When the counter field is well defined on the legacy source, as in the following example:

01 DFHCOMMAREA. 03 ITEM-NUM PIC S9(8) COMP. 03 ITEM-VEC. 05 ITEM-ELEM OCCURS 1 TO 10 DEPENDING ON ITEM-NUM. 07 ITEM-NAME PIC X(10). 07 ITEM-PRICE PIC 9(4).

The process will be fully automated. After generating an entity from the legacy source, the entity’s List field will be generated with the following property:

@FieldAttributes(attributes = { @Attribute(key = DynamicConstants.DEPENDING_ON, value = "path.to.the.counter field") })

For example:

@Getter @Setter @RpcPart public class DepndonItemVec { @FieldAttributes(attributes = { @Attribute(key = DynamicConstants.DEPENDING_ON, value = "dfhcommarea.itemNum") }) @RpcField(originalName = "ITEM-ELEM", displayName = "ITEMELEM") @RpcList(count = 10) private List<DepndonItemElem> itemElem; }

The length of the list will be equal to the value of itemNum (our counter field).

That will have a corresponding field attribute


Manual Changes

When the counter field is not well defined on the legacy source, some manual changes are required.

  1. Go to the Dynamic List field in the entity and add the following annotations above it:

2. Go to the counter field and add:

Now you are ready to go.