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 CHAMPS-01 PIC X(015).
05 CHAMPS-02 PIC 9(009)V9(002).
05 CHAMPS-03 PIC X(001).
05 CHAMPS-04 PIC 9(005)V9(005).
05 FILLER PIC X(009) VALUE ' DU COBOL'.
PROCEDURE DIVISION.
001-INIT.
Exemple 1
MOVE "LA COMMUNAUTE " TO CHAMPS-01
MOVE 1234,67 TO CHAMPS-02
MOVE "Y" TO CHAMPS-03
MOVE 6789,12345 TO CHAMPS-04
DISPLAY "AVANT "
DISPLAY "WS-REGISTRE " WS-REGISTRE
DISPLAY "CHAMPS-01 " CHAMPS-01
DISPLAY "CHAMPS-02 " CHAMPS-02
DISPLAY "CHAMPS-03 " CHAMPS-03
DISPLAY "CHAMPS-04 " CHAMPS-04
INITIALIZE WS-REGISTRE
DISPLAY "APRES "
DISPLAY "WS-REGISTRE " WS-REGISTRE
DISPLAY "CHAMPS-01 " CHAMPS-01
DISPLAY "CHAMPS-02 " CHAMPS-02
DISPLAY "CHAMPS-03 " CHAMPS-03
DISPLAY "CHAMPS-04 " CHAMPS-04
* Resultat de test:
* AVANT
* WS-REGISTRE LA COMMUNAUTE 00000123467Y0678912345 DU COBOL
* CHAMPS-01 LA COMMUNAUTE
* CHAMPS-02 000001234,67
* CHAMPS-03 Y
* CHAMPS-04 06789,12345
* APRES
* WS-REGISTRE 00000000000 0000000000 DU COBOL
* CHAMPS-01
* CHAMPS-02 000000000,00
* CHAMPS-03
* CHAMPS-04 00000,00000
Observation:
Les champs définis comme FILLER ne subissent aucune action de la commande INITIALIZE, c'est-à-dire :
05 FILLER PIC X(009) VALEUR ' DU COBOL'. Restera avec le contenu de ' DU COBOL'
Exemple 2
MOVE "LA COMMUNAUTE" TO CHAMPS-01
MOVE 1234,67 TO CHAMPS-02
MOVE "Y" TO CHAMPS-03
MOVE 6789,12345 TO CHAMPS-04
DISPLAY "AVANT "
DISPLAY "WS-REGISTRE " WS-REGISTRE
DISPLAY "CHAMPS-01 " CHAMPS-01
DISPLAY "CHAMPS-02 " CHAMPS-02
DISPLAY "CHAMPS-03 " CHAMPS-03
DISPLAY "CHAMPS-04 " CHAMPS-04
INITIALIZE WS-REGISTRE
REPLACING ALPHANUMERIC BY SPACES
NUMERIC BY ZEROES
DISPLAY "APRES "
DISPLAY "WS-REGISTRE " WS-REGISTRE
DISPLAY "CHAMPS-01 " CHAMPS-01
DISPLAY "CHAMPS-02 " CHAMPS-02
DISPLAY "CHAMPS-03 " CHAMPS-03
DISPLAY "CHAMPS-04 " CHAMPS-04
* Resultat de test:
* AVANT
* WS-REGISTRE LA COMMUNAUTE 00000123467Y0678912345 DU COBOL
* CHAMPS-01 LA COMMUNAUTE
* CHAMPS-02 000001234,67
* CHAMPS-03 Y
* CHAMPS-04 06789,12345
* APRES
* WS-REGISTRE 00000000000 0000000000 DU COBOL
* CHAMPS-01
* CHAMPS-02 000000000,00
* CHAMPS-03
* CHAMPS-04 00000,00000
Observation:
Les champs définis comme FILLER ne subissent aucune action de la commande INITIALIZE, c'est-à-dire :
05 FILLER PIC X(009) VALEUR ' DU COBOL'. Restera avec le contenu de ' DU COBOL'
Exemple 3
MOVE "LA COMMUNAUTE" TO CHAMPS-01
MOVE 1234,67 TO CHAMPS-02
MOVE "Y" TO CHAMPS-03
MOVE 6789,12345 TO CHAMPS-04
DISPLAY "AVANT "
DISPLAY "WS-REGISTRE " WS-REGISTRE
DISPLAY "CHAMPS-01 " CHAMPS-01
DISPLAY "CHAMPS-02 " CHAMPS-02
DISPLAY "CHAMPS-03 " CHAMPS-03
DISPLAY "CHAMPS-04 " CHAMPS-04
INITIALIZE WS-REGISTRE
REPLACING ALPHANUMERIC BY "X"
NUMERIC BY "9"
DISPLAY "APRES "
DISPLAY "WS-REGISTRE " WS-REGISTRE
DISPLAY "CHAMPS-01 " CHAMPS-01
DISPLAY "CHAMPS-02 " CHAMPS-02
DISPLAY "CHAMPS-03 " CHAMPS-03
DISPLAY "CHAMPS-04 " CHAMPS-04
* Resultat de test:
* AVANT
* WS-REGISTRE LA COMMUNAUTE 00000123467Y0678912345 DU COBOL
* CHAMPS-01 LA COMMUNAUTE
* CHAMPS-02 000001234,67
* CHAMPS-03 Y
* CHAMPS-04 06789,12345
* APRES
* WS-REGISTRE X 00000000900X0000900000 DU COBOL
* CHAMPS-01 X
* CHAMPS-02 000000009,00
* CHAMPS-03 X
* CHAMPS-04 00009,00000
Observation:
Les champs définis comme FILLER ne subissent aucune action de la commande INITIALIZE, c'est-à-dire :
05 FILLER PIC X(009) VALEUR ' DU COBOL'. Restera avec le contenu de ' DU COBOL'
Exemple 4
MOVE "LA COMMUNAUTE" TO CHAMPS-01
MOVE 1234,67 TO CHAMPS-02
MOVE "Y" TO CHAMPS-03
MOVE 6789,12345 TO CHAMPS-04
DISPLAY "AVANT "
DISPLAY "WS-REGISTRE " WS-REGISTRE
DISPLAY "CHAMPS-01 " CHAMPS-01
DISPLAY "CHAMPS-02 " CHAMPS-02
DISPLAY "CHAMPS-03 " CHAMPS-03
DISPLAY "CHAMPS-04 " CHAMPS-04
INITIALIZE WS-REGISTRE
REPLACING ALPHANUMERIC BY ALL "X"
NUMERIC BY ALL "9"
DISPLAY "APRES "
DISPLAY "WS-REGISTRE " WS-REGISTRE
DISPLAY "CHAMPS-01 " CHAMPS-01
DISPLAY "CHAMPS-02 " CHAMPS-02
DISPLAY "CHAMPS-03 " CHAMPS-03
DISPLAY "CHAMPS-04 " CHAMPS-04
* Resultat de test:
* AVANT
* WS-REGISTRE LA COMMUNAUTE 00000123467Y0678912345 DU COBOL
* CHAMPS-01 LA COMMUNAUTE
* CHAMPS-02 000001234,67
* CHAMPS-03 Y
* CHAMPS-04 06789,12345
* APRES
*A WS-REGISTRE XXXXXXXXXXXXXXX99999999900X9999900000DU COBOL
* CHAMPS-01 XXXXXXXXXXXXXXX
* CHAMPS-02 999999999,00
* CHAMPS-03 X
* CHAMPS-04 99999,00000
* CHAMPS-04 00009,00000
Observation:
Les champs définis comme FILLER ne subissent aucune action de la commande INITIALIZE, c'est-à-dire :
05 FILLER PIC X(009) VALEUR ' DU COBOL'. Restera avec le contenu de ' DU COBOL'