Move Verb in COBOL

Move Verb

  • Move verb is used for copying the data from source to destination data.
  • It is used on both elementary and group data items.
  • MOVE CORRESPONDING/CORR is used for group data items.
  • MOVE CORR may not work on some online tools but it will work on a mainframe server.
  • MOVE(x:l) is used for moving the data from a string. Where, x is the starting position and l is length.
  • If the destination data item PIC clause is less than the source data item PIC clause then data will be cut or truncated.
  • ZEROs or SPACEs will be added for extra bytes if the destination data item PIC clause is larger than the PIC clause of source data item.

Example : Demonstration of MOVE verb

IDENTIFICATION DIVISION.
PROGRAM-ID. MV.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-N1 PIC 9(8).
   01 WS-N2 PIC 9(8).
   01 WS-N3 PIC 9(5).
   01 WS-N4 PIC 9(4).
   01 WS-EMP-ADDRESS.
   05 WS-EMP-HOUSE-NUMBER PIC 9(3).
   05 WS-EMP-STATE PIC X(11).
   05 WS-EMP-PIN PIC 9(6).
   01 WS-STUDENT-ADDRESS.
   05 WS-STUD-HOUSE-NUMBER PIC 9(3).
   05 WS-STUD-STATE PIC X(11).
   05 WS-STUD-PIN PIC 9(5).

PROCEDURE DIVISION.
   A000-FIRST-PARA.
   MOVE 23657891 TO WS-N1.
   MOVE WS-N1 TO WS-N2 WS-N3.
   MOVE WS-N1(2:4) TO WS-N4.
   MOVE 510 TO WS-EMP-HOUSE-NUMBER.
   MOVE 'MAHARASHTRA' TO WS-EMP-STATE.
   MOVE 444601 TO WS-EMP-PIN.
   MOVE WS-EMP-ADDRESS TO WS-STUDENT-ADDRESS.

   DISPLAY "WS-N1     : " WS-N1
   DISPLAY "WS-N2     : " WS-N2
   DISPLAY "WS-N3     : " WS-N3
   DISPLAY "WS-N4     : " WS-N4
   DISPLAY "WS-EMP-ADDRESS  : " WS-EMP-ADDRESS
   DISPLAY "WS-STUDENT-ADDRESS : " WS-STUDENT-ADDRESS

STOP RUN.


Output:
WS-N1     : 23657891
WS-N2     : 23657891
WS-N3     : 57891
WS-N4     : 3657
WS-EMP-ADDRESS  : 510MAHARASHTRA444601
WS-STUDENT-ADDRESS : 510MAHARASHTRA44460

Information about the legal moves are as:

NumericAlphabeticAlphanumeric
NumericPossibleNot PossiblePossible
AlphabeticNot PossiblePossiblePossible
AlphanumericPossiblePossiblePossible