Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE
Highlighted
Austin1 Honored Contributor.
Honored Contributor.
311 views

Reference Modification with Managed COBOL

As a user, rather than just always asking questions, I thought it would be nice to give back to the Community for a change.

Reference Modification - In a Managed COBOL program, you can use either the traditional "one-based" reference modification (using parentheses) that you can also use with Native COBOL, -OR- you can use zero-based reference modification (using brackets).  This is touched on in "Visual COBOL - A Developer's Guide To Modern COBOL", a book from Micro Focus (see pages 336 - 337).

In Visual Studio, create a new COBOL project - Managed Console Application and paste the following code into it.  This is a quick and dirty example and was not intended to be elegant or efficient.  Rather, it was meant to show how reference modification can be used and to provide something that you can easily experiment with.

       program-id. Program1 as "TestRefMod1.Program1".

       data division.
       working-storage section.

       01 Work-Area.
            05 Date-YMD-X.
                10 Date-YMD PIC 9(08).
            05 Redefines Date-YMD-X.
                10 Date-YMD-YYYY-X.
                    15 Date-YMD-YYYY PIC 9(04).
                10 Date-YMD-MM-X.
                    15 Date-YMD-MM PIC 9(02).
                10 Date-YMD-DD-X.
                    15 Date-YMD-DD PIC 9(02).

            05 Date-MDY-Formatted-X.
                10 Date-MDY-Formatted-MM-X.
                    15 Date-MDY-Formatted-MM PIC 9(02).
                10 Date-MDY-Formatted-Slash-1 PIC X(01).
                10 Date-MDY-Formatted-DD-X.
                     15 Date-MDY-Formatted-DD PIC 9(02).
                10 Date-MDY-Formatted-Slash-2 PIC X(01).
                10 Date-MDY-Formatted-YYYY-X.
                     15 Date-MDY-Formatted-YYYY PIC 9(04).

             05 JUNK PIC X(01) VALUE SPACES.

       procedure division.

     * Example # 1 - traditional one-based ref. mod. using parentheses

            MOVE 20170215             TO Date-YMD.

            MOVE SPACES                TO Date-MDY-Formatted-X.

            MOVE Date-YMD (1:4)    TO Date-MDY-Formatted-X (7:4) *> YYYY
            MOVE Date-YMD (5:2)    TO Date-MDY-Formatted-X (1:2) *> MM
            MOVE Date-YMD (7:2)    TO Date-MDY-Formatted-X (4:2) *> DD
            MOVE "/"                       TO Date-MDY-Formatted-X (3:1)
                                                     Date-MDY-Formatted-X (6:1).

            DISPLAY Date-MDY-Formatted-X LINE 03 COL 01.
            ACCEPT JUNK LINE 25 COL 21.

    * Example # 2 - zero-based ref. mod. using square brackets

            MOVE 20180131             TO Date-YMD.

            MOVE SPACES                TO Date-MDY-Formatted-X.

            MOVE Date-YMD [0:4]    TO Date-MDY-Formatted-X [6:4] *> YYYY
            MOVE Date-YMD [4:2]    TO Date-MDY-Formatted-X [0:2] *> MM
            MOVE Date-YMD [6:2]    TO Date-MDY-Formatted-X [3:2] *> DD
            MOVE "/"                       TO Date-MDY-Formatted-X [2:1]
                                                     Date-MDY-Formatted-X [5:1].

            DISPLAY Date-MDY-Formatted-X LINE 05 COL 01.
            ACCEPT JUNK LINE 25 COL 21.

            goback.

            end program Program1.

 

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.