000010*---------------------------------------------------------------------- 000020* Date data is defined in this library. 000030*---------------------------------------------------------------------- 000040 01 FMT-DATE. 000050 02 YYYY PIC 9(4). 000060 02 MMDD. 000070 03 MM PIC 9(2). 000080 03 DD PIC 9(2).
<Source program>
000010 @OPTIONS MAIN 000020*---------------------------------------------------------------------- 000030* The COPY statement is specified to read the library. 000040*---------------------------------------------------------------------- 000050 IDENTIFICATION DIVISION. 000060 PROGRAM-ID. SAMPLE. 000070 DATA DIVISION. 000080 WORKING-STORAGE SECTION. 000090*---------------------------------------------------------------------- 000100* Specifying REPLACING in the COPY statement enables words (text words) 000110* in a library to be replaced and expanded. 000120* In this example, one group item name is replaced with "TODAY" and 000130* another group item name is replaced with "BIRTHDAY". 000140*---------------------------------------------------------------------- 000150 COPY CP-SMPL1 REPLACING FMT-DATE BY TODAY. 000160 COPY CP-SMPL1 REPLACING FMT-DATE BY BIRTHDAY. 000170*---------------------------------------------------------------------- 000180 01 AGE PIC 9(3). 000190 PROCEDURE DIVISION. 000200 DISPLAY "When is your birthday? Example: 19690123 >>" 000205 WITH NO ADVANCING. 000210 ACCEPT BIRTHDAY. 000220 MOVE FUNCTION CURRENT-DATE TO TODAY. 000230 COMPUTE AGE = YYYY OF TODAY - YYYY OF BIRTHDAY. 000240 IF MMDD OF TODAY < MMDD OF BIRTHDAY THEN 000250 COMPUTE AGE = AGE - 1 000260 END-IF. 000270 DISPLAY " ". 000280 DISPLAY "You are " AGE " years old.". 000290 END PROGRAM SAMPLE.