Alternative solution to COBOL Reference modification

In COBOL an alternative solution is available for reference modification. In reference modification, you need to give position and length to get required length. I found one disadvantage with this usage.

The disadvantage is other programmers does not know which field value you are moving. Since from main string you are moving part of its value.

MOVE MY_FIELD(2:1) TO NEW_FIELD.

You are moving part of input string value into output field. So you may not known which value you are moving. Program maintenance point of view this way of coding is not good practice.

Let us assume,

MY_FIELD X(20)
The break-up of MY_FIELD is as follows.
A X(01).
B X(01).
C X(18).

In the above move, you are moving ‘B’ value. With 88 level only you will know the field name, but with reference modification it is hard to know.

Alternative solution

Use redefines in your Copy book and 88 Level fields that you want to use in your program. Define these in your COBOL copy book.

05 ORG_FIELD X(20).
05 MY_FIELD REDEFINES ORG_FIELD.
88 A X(01).
88 B X(01).
88 C X(18).

Then, directly you can use those fields in your program. This question was asked in COBOL screening test. So I am sharing with you.

MOVE B  TO  NEW_FIELD.
Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.