Archives par mot-clé : INSPECT REPLACING

Exemple – INSPECT REPLACING

Voici un programme utilisant le INSPECT REPLACING :

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

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

DATA DIVISION.
WORKING-STORAGE SECTION.

01  WS-AUXILIARES.
    05  DATE-JOUR        PIC X(010)   VALUE '06-03-1951'.
    05  NUMERO-1         PIC X(008)   VALUE '44 21 11'.
    05  NUMERO-2         PIC X(006)   VALUE '442111'.
    05  NUMERO-3         PIC X(006)   VALUE '112111'.
    05  NUMERO-4         PIC X(006)   VALUE 'ABCXYZ'.

PROCEDURE DIVISION.

001-INIT.

    INSPECT DATE-JOUR REPLACING ALL '-' BY '/'                
    DISPLAY 'DATE-JOUR ' DATE-JOUR 
	 
    INSPECT NUMERO-1 REPLACING ALL SPACES BY '-'
    DISPLAY 'NUMERO-1  ' NUMERO-1 

    INSPECT NUMERO-2 REPLACING LEADING '4' BY '5'
    DISPLAY 'NUMERO-2  ' NUMERO-2 

    INSPECT NUMERO-3 REPLACING CHARACTERS BY '3'
            BEFORE INITIAL '2'
    DISPLAY 'NUMERO-3  ' NUMERO-3 

    INSPECT NUMERO-4 REPLACING FIRST 'X' BY 'Y'
    DISPLAY 'NUMERO-4  ' NUMERO-4 

    STOP RUN.

* Resultat de test:

* DATE-JOUR 06/03/1951
* NUMERO-1  44-21-11
* NUMERO-2  552111
* NUMERO-3  332111
* NUMERO-4  ABCYYZ