Move Corresponding Example


Scenario - Changing the date format from MM-DD-YYYY to DD/MM/YYYY.

Code -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. MOVECORR.
       AUTHOR. MTH.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-DATE-MDY.
          05 WS-DATE-MM          PIC 9(02)  VALUE 10.  
          05 FILLER              PIC X      VALUE '-'. 
          05 WS-DATE-DD          PIC 9(02)  VALUE 13.  
          05 FILLER              PIC X      VALUE '-'. 
          05 WS-DATE-YYYY        PIC 9(04)  VALUE 2023.
       01 WS-DATE-DMY.
          05 WS-DATE-DD          PIC 9(02).
          05 FILLER              PIC X      VALUE '/'. 
          05 WS-DATE-MM          PIC 9(02).
          05 FILLER              PIC X      VALUE '/'. 
          05 WS-DATE-YYYY        PIC 9(04).

       PROCEDURE DIVISION.
           MOVE CORR WS-DATE-MDY TO WS-DATE-DMY. 

           DISPLAY 'SOURCE GROUP:  ' WS-DATE-MDY 
           DISPLAY 'TARGET GROUP:  ' WS-DATE-DMY.

           STOP RUN.

Output -

SOURCE GROUP:  10-13-2023 
TARGET GROUP:  13/10/2023 

Explaining Example -

In the above example: After executing the MOVE CORRESPONDING statement -

  • WS-DATE-MM of WS-DATE-MDY value moved to WS-DATE-MM of WS-DATE-DMY.
  • WS-DATE-DD of WS-DATE-MDY value moved to WS-DATE-DD of WS-DATE-DMY.
  • WS-DATE-YYYY of WS-DATE-MDY value moved to WS-DATE-YYYY of WS-DATE-DMY.