TRANSFORM Statement
The TRANSFORM
statement converts characters in a data item from one character string to another.
General Format:
TRANSFORM identifier-1 FROM literal-1 TO literal-2
Syntax:
Identifier-n
is a data item, literal, or data returned from a function call that is alphanumeric.literal-n
is a character string.
General Rules:
- The
TRANSFORM
statemnt causes a conversion of characters withinidentifier-1
according to rules established by the ordinal positions of characters inidentifier-2
andidentifier-3
. To clarify with an example, the statement:TRANSFORM identifier-1 FROM “AB” TO “CD”
causes every instance of “A
” inidentifier-1
(the first character inidentifier-2
), to be converted to “C
” (the first character inidentifier-3
), and causes every instance of “B
” inidentifier-1
(the second character inidentifier-2
) to be replaced by “D
” (the second character inidentifier-3
).
Code Sample:
IDENTIFICATION DIVISION.
PROGRAM-ID. TRANSFORM-1.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 IDENTIFIER-1 PIC X(10) VALUE"AAAXXXXBBB".
77 DUMMY PIC X.
PROCEDURE DIVISION.
MAIN.
TRANSFORM IDENTIFIER-1 FROM "AB" TO "CD".
DISPLAY IDENTIFIER-1 LINE 10 COL 10.
DISPLAY "TRANSFORM-1 FINISHED!" LINE 15 COL 10.
ACCEPT DUMMY LINE 15 COL 30.
STOP RUN.