action.skip

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:

  1. Identifier-n is a data item, literal, or data returned from a function call that is alphanumeric.
  2. literal-n is a character string.

General Rules:

  1. The TRANSFORM statemnt causes a conversion of characters within identifier-1 according to rules established by the ordinal positions of characters in identifier-2 and identifier-3. To clarify with an example, the statement:

    TRANSFORM identifier-1 FROM “AB” TO “CD”

    causes every instance of “A” in identifier-1 (the first character in identifier-2), to be converted to “C” (the first character in identifier-3), and causes every instance of “B” in identifier-1 (the second character in identifier-2) to be replaced by “D” (the second character in identifier-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.