Alternative Solution for 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.

MOVE MY_FIELD(2:1) TO NEW_FIELD.

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.

Author: Srini

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