>>SOURCE FORMAT IS FREE *> cobol-move-truncation-rules.cob - MOVE between items of different size *> and class, showing where COBOL truncates, pads, and drops a sign *> Dialect: GnuCOBOL 3.x, free format *> Status : desk-checked against the GnuCOBOL 3.2 Programmer's Guide; *> compiled and run with GnuCOBOL 3.2 on 2026-10-30 *> Inputs : none *> Outputs: nine lines on standard output *> Build : cobc -x cobol-move-truncation-rules.cob *> Run : ./cobol-move-truncation-rules *> (Windows: cobol-move-truncation-rules.exe) IDENTIFICATION DIVISION. PROGRAM-ID. MOVE-RULES. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-Long-Text PIC X(12) VALUE "ACCOUNTS-RCV". 01 WS-Short-Text PIC X(5). 01 WS-Wide-Text PIC X(8). 01 WS-Three-Digits PIC 9(3). 01 WS-Money PIC 9(3)V99. 01 WS-Unsigned PIC 9(3). 01 WS-Signed PIC S9(3). 01 WS-Num-As-Text PIC X(6). *> Two group items with the same length but a different field order. 01 WS-Source-Rec. 05 WS-Src-Id PIC 9(4) VALUE 1234. 05 WS-Src-Name PIC X(6) VALUE "SMITH". 01 WS-Target-Rec. 05 WS-Tgt-Name PIC X(6). 05 WS-Tgt-Id PIC 9(4). PROCEDURE DIVISION. MAIN-PARAGRAPH. *> 1. Alphanumeric to a shorter alphanumeric: right end is lost. MOVE WS-Long-Text TO WS-Short-Text DISPLAY "1 X(12) to X(5) : [" WS-Short-Text "]" *> 2. Alphanumeric to a longer alphanumeric: padded with spaces. MOVE "AB" TO WS-Wide-Text DISPLAY "2 'AB' to X(8) : [" WS-Wide-Text "]" *> 3. Integer too big for the receiver: leading digits are lost. MOVE 12345 TO WS-Three-Digits DISPLAY "3 12345 to 9(3) : " WS-Three-Digits *> 4. Too many decimals: trailing decimals are lost, no rounding. MOVE 123.456 TO WS-Money DISPLAY "4 123.456 to 9(3)V99 : " WS-Money *> 5. Negative value into an unsigned item: the sign is dropped. MOVE -42 TO WS-Unsigned MOVE -42 TO WS-Signed DISPLAY "5 -42 to 9(3) : " WS-Unsigned DISPLAY "5 -42 to S9(3) : " WS-Signed *> 6. Numeric integer to alphanumeric: digits, left-justified. MOVE WS-Three-Digits TO WS-Num-As-Text DISPLAY "6 9(3) to X(6) : [" WS-Num-As-Text "]" *> 7. Group to group: a byte copy that ignores both layouts. MOVE WS-Source-Rec TO WS-Target-Rec DISPLAY "7 group move : [" WS-Target-Rec "]" IF WS-Tgt-Id IS NOT NUMERIC DISPLAY "7 WS-Tgt-Id is not numeric after the group move" END-IF STOP RUN.