Exemple – INITIALIZE (Partie 2)

Voici un programme utilisant INITIALIZE :

IDENTIFICATION DIVISION.
PROGRAM-ID. INITIALIZE.
AUTHOR.     LA COMMUNAUTE DU COBOL

ENVIRONMENT DIVISION.                                            
CONFIGURATION SECTION.                                           
SPECIAL-NAMES.                                                   
    DECIMAL-POINT IS COMMA. 

DATA DIVISION.
WORKING-STORAGE SECTION.

01  WS-REGISTRE.
    05  VALEUR-1         PIC 9(009). 
    05  VALEUR-2         PIC X(009).
    05  VALEUR-3         PIC 9(009)V99.

PROCEDURE DIVISION.

TEST 01

    INITIALIZE WS-REGISTRE
               REPLACING ALPHANUMERIC BY SPACES
                              NUMERIC BY ZEROES 
    DISPLAY "VALEUR-1    " VALEUR-1
    DISPLAY "VALEUR-2    " VALEUR-2
    DISPLAY "VALEUR-3    " VALEUR-3

Resultat de test:

VALEUR-1    000000000
VALEUR-2             
VALEUR-3    000000000,00

TEST 02

    MOVE 123456789  TO VALEUR-1
    MOVE "TESTE 01" TO VALEUR-2
    MOVE 9999,99    TO VALEUR-3
    INITIALIZE WS-REGISTRE
               REPLACING ALPHANUMERIC BY SPACES
    DISPLAY "VALEUR-1    " VALEUR-1
    DISPLAY "VALEUR-2    " VALEUR-2
    DISPLAY "VALEUR-3    " VALEUR-3

Resultat de test:

VALEUR-1    123456789
VALEUR-2             
VALEUR-3    000009999,99

TEST 03

    MOVE 123456789  TO VALEUR-1
    MOVE "TESTE 03" TO VALEUR-2
    INITIALIZE WS-REGISTRE
               REPLACING NUMERIC BY ZEROES
    DISPLAY "VALEUR-1    " VALEUR-1
    DISPLAY "VALEUR-2    " VALEUR-2
    DISPLAY "VALEUR-3    " VALEUR-3

Resultat de test:

VALEUR-1    000000000
VALEUR-2    TESTE 03 
VALEUR-3    000000000,00

TEST 04

    MOVE 123456789  TO VALEUR-1
    MOVE 9999       TO VALEUR-3
    INITIALIZE WS-REGISTRE
               REPLACING NUMERIC BY ZEROES
    DISPLAY "VALEUR-1    " VALEUR-1
    DISPLAY "VALEUR-2    " VALEUR-2
    DISPLAY "VALEUR-3    " VALEUR-3

Resultat de test:

VALEUR-1    000000000
VALEUR-2    TESTE 03 
VALEUR-3    000000000,00

TEST 05

    MOVE 123456789  TO VALEUR-1
    MOVE "TESTE 04" TO VALEUR-2
    MOVE 9999       TO VALEUR-3
    INITIALIZE WS-REGISTRE
               REPLACING ALPHANUMERIC BY SPACES
    DISPLAY "VALEUR-1    " VALEUR-1
    DISPLAY "VALEUR-2    " VALEUR-2
    DISPLAY "VALEUR-3    " VALEUR-3

Resultat de test:

VALEUR-1    123456789
VALEUR-2             
VALEUR-3    000009999,00

TEST 06

    MOVE 123456789  TO VALEUR-1
    MOVE "TESTE 04" TO VALEUR-2
    MOVE 9999       TO VALEUR-3
    INITIALIZE WS-REGISTRE
               REPLACING ALPHANUMERIC BY ALL "X"
                              NUMERIC BY ALL "9"
    DISPLAY "VALEUR-1    " VALEUR-1
    DISPLAY "VALEUR-2    " VALEUR-2
    DISPLAY "VALEUR-3    " VALEUR-3

Resultat de test:

VALEUR-1    999999999
VALEUR-2    XXXXXXXXX
VALEUR-3    999999999,00

TEST 07

    MOVE 123456789  TO VALEUR-1
    MOVE "TESTE 04" TO VALEUR-2
    MOVE 9999       TO VALEUR-3
    INITIALIZE WS-REGISTRE
               REPLACING ALPHANUMERIC BY  "X"
                              NUMERIC BY 9
    DISPLAY "VALEUR-1    " VALEUR-1
    DISPLAY "VALEUR-2    " VALEUR-2
    DISPLAY "VALEUR-3    " VALEUR-3

Resultat de test:

VALEUR-1    000000009
VALEUR-2    X        
VALEUR-3    000000009,00

TEST 08

    MOVE 123456789  TO VALEUR-1
    MOVE "TESTE 04" TO VALEUR-2
    MOVE 9999       TO VALEUR-3
    INITIALIZE WS-REGISTRE
               REPLACING ALPHANUMERIC BY  "X"
                              NUMERIC BY 9,99
    DISPLAY "VALEUR-1    " VALEUR-1
    DISPLAY "VALEUR-2    " VALEUR-2
    DISPLAY "VALEUR-3    " VALEUR-3

Resultat de test:

VALEUR-1    000000009
VALEUR-2    X        
VALEUR-3    000000009,99

TEST 09

    MOVE 123456789  TO VALEUR-1
    MOVE "TESTE 04" TO VALEUR-2
    MOVE 8888       TO VALEUR-3
    INITIALIZE VALEUR-2 REPLACING ALPHANUMERIC BY "TESTE 09"
    INITIALIZE VALEUR-3 REPLACING NUMERIC      BY 0,99
    DISPLAY "VALEUR-1    " VALEUR-1
    DISPLAY "VALEUR-2    " VALEUR-2
    DISPLAY "VALEUR-3    " VALEUR-3

Resultat de test:

VALEUR-1    123456789
VALEUR-2    TESTE 09 
VALEUR-3    000000000,99
STOP RUN.