Presentation is loading. Please wait.

Presentation is loading. Please wait.

Date Conversion Program

Similar presentations


Presentation on theme: "Date Conversion Program"— Presentation transcript:

1 Date Conversion Program
No speaker notes - comments embedded in program!

2 IDENTIFICATION DIVISION.
PROGRAM-ID. STRINGG. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 DATE1. 05 YR1 PIC 99 VALUE 0. 05 MO1 PIC 99 VALUE 0. 05 DA1 PIC 99 VALUE 0. 01 DATE2. 05 YR2 PIC 99 VALUE 0. 05 MO2 PIC 99 VALUE 0. 05 DA2 PIC 99 VALUE 0. 01 JULIAN1. 05 JYR1 PIC 99. 05 JDA1 PIC 999. 01 JULIAN2. 05 JYR2 PIC 99. 05 JDA2 PIC 999. 01 DAYS1 PIC 9(5) VALUE 0. 01 DAYS2 PIC 9(5) VALUE 0. 01 ANS1 PIC 9(5) VALUE 0. 01 ANS2 PIC 9(5) VALUE 0. 01 JUNK-ANS PIC 9(5) VALUE 0. 01 REM-WS1 PIC 9(5) VALUE 0. 01 REM-WS2 PIC 9(5) VALUE 0. 01 REM-YR PIC 9(5) VALUE 0. 01 YRS-DAYS PIC 9(5) VALUE 0. 01 YR-DIFF PIC 9(5) VALUE 0. 01 DAYS-ANSWER PIC 9(6) VALUE 0. 01 DO-ANS PIC X VALUE "Y". Convdate.cbl 01 DATE-PASSED. 05 FILLER PIC VALUE 000. 05 FILLER PIC VALUE 031. 05 FILLER PIC VALUE 059. 05 FILLER PIC VALUE 090. 05 FILLER PIC VALUE 120. 05 FILLER PIC VALUE 151. 05 FILLER PIC VALUE 181. 05 FILLER PIC VALUE 212. 05 FILLER PIC VALUE 243. 05 FILLER PIC VALUE 273. 05 FILLER PIC VALUE 304. 05 FILLER PIC VALUE 334. 01 RDF-DATE-PASSED REDEFINES DATE-PASSED. 05 DAYS-PASSED PIC 999 OCCURS 12 TIMES.

3 PROCEDURE DIVISION. Using 2 dates 000102 and 991231 MAINLINE.
PERFORM B-100-DATE-DIFF UNTIL DO-ANS = "N". STOP RUN. B-100-DATE-DIFF. DISPLAY "ROUTINE TO SUBTRACT SECOND DATE FROM FIRST DATE". DISPLAY "ENTER FIRST DATE - YYMMDD" (YR1=00 MO1=01 DA1=02) ACCEPT DATE1. DISPLAY "ENTER SECOND DATE - YYMMDD" (YR2=99 MO2=12 DA2=31) ACCEPT DATE2. PERFORM B-200-CONVERT-1. PERFORM B-210-CONVERT-2. IF YR1 = YR NOT EQUAL SUBTRACT JDA2 FROM JDA1 GIVING DAYS-ANSWER DISPLAY "NO YEAR TO CONVERT" DISPLAY "DAYS BETWEEN " DAYS-ANSWER ELSE DISPLAY "GOING TO CONVERT YEAR" GOING TO CONVERT YEAR PERFORM B-220-CONVERT-YEAR DISPLAY "DAYS BETWEEN " YRS-DAYS. DAYS BETWEEN 00002 DISPLAY "ANOTHER DATE Y OR N?". ACCEPT DO-ANS.

4 Using 2 dates 000102 and 991231 B-200-CONVERT-1. DIVIDE YR1 BY 4
GIVING JUNK-ANS REMAINDER REM-WS1. 00/4=0 REM-WS1=0 MOVE YR1 TO JYR JYR1=00 ADD DAYS-PASSED (MO1) DA1 GIVING JDA JDA1= = 002 IF REM-WS1 = 0 AND MO1 > 2 ADD 1 TO JDA1. DISPLAY "FIRST DATE IN JULIAN " JDA1. FIRST DATE IN JULIAN 002 B-210-CONVERT-2. DIVIDE YR2 BY 4 GIVING JUNK-ANS REMAINDER REM-WS2. 99/4= 24 REM-WS2=3 MOVE YR2 TO JYR JYR2=99 ADD DAYS-PASSED (MO2) DA2 GIVING JDA JDA2= = 365 IF REM-WS2 = 0 AND MO2 > 2 ADD 1 TO JDA2. DISPLAY "SECOND DATE IN JULIAN " JDA2. SECOND DATE IN JULIAN 365

5 Using 2 dates 000102 and 991231 B-220-CONVERT-YEAR.
DISPLAY "IN CONVERT YEAR" IN CONVERT YEAR IF REM-WS2 = 0 SUBTRACT JDA2 FROM 366 GIVING YRS-DAYS ELSE SUBTRACT JDA2 FROM 365 GIVING YRS-DAYS YRS-DAYS= = 00000 DISPLAY "YRS-DAYS WITH JDA2 " YRS-DAYS. YRS-DAYS WITH JDA ADD JDA1 TO YRS-DAYS. YRS-DAYS = = 00002 DISPLAY "YRS-DAYS AFTER JDA1 ADDDED " YRS-DAYS. YRS-DAYS AFTER JDA1 ADDED 00002 SUBTRACT YR2 FROM YR1 GIVING YR-DIFF YR-DIFF = = 00099 DISPLAY "YR-DIFF " YR-DIFF. YR-DIFF 00099 IF YR-DIFF > 1 ADD 1 TO YR YR2 = = 100 = 00 (stored in 2 char field as 00) DISPLAY "YR-DIFF > 1 YR2 IS " YR2 YRDIFF > 1 YR2 IS 00 PERFORM B-300-ADD-A-YEAR UNTIL YR2 = YR1. Until 00 = 00 so no perform done B-300-ADD-A-YEAR. DISPLAY "IN ADD A YEAR AND YR2 = " YR2 " AND YR1 = " YR1. DIVIDE YR2 BY 4 GIVING JUNK-ANS REMAINDER REM-YR. IF REM-YR = 0 ADD 366 TO YRS-DAYS ADD 365 TO YRS-DAYS. ADD 1 TO YR2. DISPLAY "YRS-DAYS " YRS-DAYS " YR2 " YR2.

6 PROCEDURE DIVISION. Using 2 dates 000102 and 981231 MAINLINE.
PERFORM B-100-DATE-DIFF UNTIL DO-ANS = "N". STOP RUN. B-100-DATE-DIFF. DISPLAY "ROUTINE TO SUBTRACT SECOND DATE FROM FIRST DATE". DISPLAY "ENTER FIRST DATE - YYMMDD" (YR1=00 MO1=01 DA1=02) ACCEPT DATE1. DISPLAY "ENTER SECOND DATE - YYMMDD" (YR2=98 MO2=12 DA2=31) ACCEPT DATE2. PERFORM B-200-CONVERT-1. PERFORM B-210-CONVERT-2. IF YR1 = YR NOT EQUAL SUBTRACT JDA2 FROM JDA1 GIVING DAYS-ANSWER DISPLAY "NO YEAR TO CONVERT" DISPLAY "DAYS BETWEEN " DAYS-ANSWER ELSE DISPLAY "GOING TO CONVERT YEAR" GOING TO CONVERT YEAR PERFORM B-220-CONVERT-YEAR DISPLAY "DAYS BETWEEN " YRS-DAYS. DAYS BETWEEN 00367 DISPLAY "ANOTHER DATE Y OR N?". ACCEPT DO-ANS.

7 Using 2 dates 000102 and 981231 B-200-CONVERT-1. DIVIDE YR1 BY 4
GIVING JUNK-ANS REMAINDER REM-WS1. 00/4=0 REM-WS1=0 MOVE YR1 TO JYR JYR1=00 ADD DAYS-PASSED (MO1) DA1 GIVING JDA JDA1= = 002 IF REM-WS1 = 0 AND MO1 > 2 ADD 1 TO JDA1. DISPLAY "FIRST DATE IN JULIAN " JDA1. FIRST DATE IN JULIAN 002 B-210-CONVERT-2. DIVIDE YR2 BY 4 GIVING JUNK-ANS REMAINDER REM-WS2. 98/4= 24 REM-WS2=2 MOVE YR2 TO JYR JYR2=98 ADD DAYS-PASSED (MO2) DA2 GIVING JDA JDA2= = 365 IF REM-WS2 = 0 AND MO2 > 2 ADD 1 TO JDA2. DISPLAY "SECOND DATE IN JULIAN " JDA2. SECOND DATE IN JULIAN 365

8 B-220-CONVERT-YEAR. DISPLAY "IN CONVERT YEAR" IN CONVERT YEAR
IF REM-WS2 = 0 SUBTRACT JDA2 FROM 366 GIVING YRS-DAYS ELSE SUBTRACT JDA2 FROM 365 GIVING YRS-DAYS YRS-DAYS= = 00000 DISPLAY "YRS-DAYS WITH JDA2 " YRS-DAYS. YRS-DAYS WITH JDA ADD JDA1 TO YRS-DAYS. YRS-DAYS = = 00002 DISPLAY "YRS-DAYS AFTER JDA1 ADDDED " YRS-DAYS. YRS-DAYS AFTER JDA1 ADDED 00002 SUBTRACT YR2 FROM YR1 GIVING YR-DIFF YR-DIFF = = 00098 DISPLAY "YR-DIFF " YR-DIFF. YR-DIFF 00098 IF YR-DIFF > 1 ADD 1 TO YR YR2 = = 99 (stored in 2 char field as 99) DISPLAY "YR-DIFF > 1 YR2 IS " YR2 YRDIFF > 1 YR2 IS 99 PERFORM B-300-ADD-A-YEAR UNTIL YR2 = YR1. Until 99 = 00 (to start) B-300-ADD-A-YEAR. DISPLAY "IN ADD A YEAR AND YR2 = " YR2 " AND YR1 = " YR1. IN ADD A YEAR AND YR2 = 99 AND YR1 = 00 DIVIDE YR2 BY 4 GIVING JUNK-ANS REMAINDER REM-YR. 99/4=24 REM-YR = 3 IF REM-YR = 0 ADD 366 TO YRS-DAYS ADD 365 TO YRS-DAYS. YRS-DAYS = = 00367 ADD 1 TO YR2. YR2 = 00 ( IN 2 CHAR FIELD = 00) DISPLAY "YRS-DAYS " YRS-DAYS " YR2 " YR2. YRS-DAYS YR2 00

9 PROCEDURE DIVISION. Using 2 dates 000325 and 981028 MAINLINE.
PERFORM B-100-DATE-DIFF UNTIL DO-ANS = "N". STOP RUN. B-100-DATE-DIFF. DISPLAY "ROUTINE TO SUBTRACT SECOND DATE FROM FIRST DATE". DISPLAY "ENTER FIRST DATE - YYMMDD" (YR1=00 MO1=03 DA1=25) ACCEPT DATE1. DISPLAY "ENTER SECOND DATE - YYMMDD" (YR2=98 MO2=10 DA2=28) ACCEPT DATE2. PERFORM B-200-CONVERT-1. PERFORM B-210-CONVERT-2. IF YR1 = YR NOT EQUAL SUBTRACT JDA2 FROM JDA1 GIVING DAYS-ANSWER DISPLAY "NO YEAR TO CONVERT" DISPLAY "DAYS BETWEEN " DAYS-ANSWER ELSE DISPLAY "GOING TO CONVERT YEAR" GOING TO CONVERT YEAR PERFORM B-220-CONVERT-YEAR DISPLAY "DAYS BETWEEN " YRS-DAYS. DAYS BETWEEN 00514 DISPLAY "ANOTHER DATE Y OR N?". ACCEPT DO-ANS.

10 B-200-CONVERT-1. Using 2 dates 000325 and 981028 DIVIDE YR1 BY 4
GIVING JUNK-ANS REMAINDER REM-WS1. 00/4=0 REM-WS1=0 MOVE YR1 TO JYR JYR1=00 ADD DAYS-PASSED (MO1) DA1 GIVING JDA JDA1= = 084 IF REM-WS1 = 0 AND MO1 > 2 ADD 1 TO JDA JDA1= = 085 DISPLAY "FIRST DATE IN JULIAN " JDA1. FIRST DATE IN JULIAN 085 B-210-CONVERT-2. DIVIDE YR2 BY 4 GIVING JUNK-ANS REMAINDER REM-WS2. 98/4= 24 REM-WS2=2 MOVE YR2 TO JYR JYR2=98 ADD DAYS-PASSED (MO2) DA2 GIVING JDA JDA2= = 301 IF REM-WS2 = 0 AND MO2 > 2 ADD 1 TO JDA2. DISPLAY "SECOND DATE IN JULIAN " JDA2. SECOND DATE IN JULIAN 301

11 B-220-CONVERT-YEAR. DISPLAY "IN CONVERT YEAR" IN CONVERT YEAR
IF REM-WS2 = 0 SUBTRACT JDA2 FROM 366 GIVING YRS-DAYS ELSE SUBTRACT JDA2 FROM 365 GIVING YRS-DAYS YRS-DAYS= = 00064 DISPLAY "YRS-DAYS WITH JDA2 " YRS-DAYS. YRS-DAYS WITH JDA ADD JDA1 TO YRS-DAYS. YRS-DAYS = = 00149 DISPLAY "YRS-DAYS AFTER JDA1 ADDDED " YRS-DAYS. YRS-DAYS AFTER JDA1 ADDED 00149 SUBTRACT YR2 FROM YR1 GIVING YR-DIFF YR-DIFF = = 00098 DISPLAY "YR-DIFF " YR-DIFF. YR-DIFF 00098 IF YR-DIFF > 1 ADD 1 TO YR YR2 = = 99 (stored in 2 char field as 99) DISPLAY "YR-DIFF > 1 YR2 IS " YR2 YRDIFF > 1 YR2 IS 99 PERFORM B-300-ADD-A-YEAR UNTIL YR2 = YR1. Until 99 = 00 (to start) B-300-ADD-A-YEAR. DISPLAY "IN ADD A YEAR AND YR2 = " YR2 " AND YR1 = " YR1. IN ADD A YEAR AND YR2 = 99 AND YR1 = 00 DIVIDE YR2 BY 4 GIVING JUNK-ANS REMAINDER REM-YR. 99/4=24 REM-YR = 3 IF REM-YR = 0 ADD 366 TO YRS-DAYS ADD 365 TO YRS-DAYS. YRS-DAYS = = 00514 ADD 1 TO YR2. YR2 = 00 ( IN 2 CHAR FIELD = 00) DISPLAY "YRS-DAYS " YRS-DAYS " YR2 " YR2. YRS-DAYS YR2 00

12 Using 2 dates 050325 and 981028 PROCEDURE DIVISION. MAINLINE.
PERFORM B-100-DATE-DIFF UNTIL DO-ANS = "N". STOP RUN. B-100-DATE-DIFF. DISPLAY "ROUTINE TO SUBTRACT SECOND DATE FROM FIRST DATE". DISPLAY "ENTER FIRST DATE - YYMMDD" (YR1=05 MO1=03 DA1=25) ACCEPT DATE1. DISPLAY "ENTER SECOND DATE - YYMMDD" (YR2=98 MO2=10 DA2=28) ACCEPT DATE2. PERFORM B-200-CONVERT-1. PERFORM B-210-CONVERT-2. IF YR1 = YR NOT EQUAL SUBTRACT JDA2 FROM JDA1 GIVING DAYS-ANSWER DISPLAY "NO YEAR TO CONVERT" DISPLAY "DAYS BETWEEN " DAYS-ANSWER ELSE DISPLAY "GOING TO CONVERT YEAR" GOING TO CONVERT YEAR PERFORM B-220-CONVERT-YEAR DISPLAY "DAYS BETWEEN " YRS-DAYS. DAYS BETWEEN 02340 DISPLAY "ANOTHER DATE Y OR N?". ACCEPT DO-ANS.

13 Using 2 dates 050325 and 981028 B-200-CONVERT-1. DIVIDE YR1 BY 4
GIVING JUNK-ANS REMAINDER REM-WS1. 05/4=1 REM-WS1=1 MOVE YR1 TO JYR JYR1=05 ADD DAYS-PASSED (MO1) DA1 GIVING JDA JDA1= = 084 IF REM-WS1 = 0 AND MO1 > 2 ADD 1 TO JDA1. DISPLAY "FIRST DATE IN JULIAN " JDA1. FIRST DATE IN JULIAN 084 B-210-CONVERT-2. DIVIDE YR2 BY 4 GIVING JUNK-ANS REMAINDER REM-WS2. 98/4= 24 REM-WS2=2 MOVE YR2 TO JYR JYR2=98 ADD DAYS-PASSED (MO2) DA2 GIVING JDA JDA2= = 301 IF REM-WS2 = 0 AND MO2 > 2 ADD 1 TO JDA2. DISPLAY "SECOND DATE IN JULIAN " JDA2. SECOND DATE IN JULIAN 301

14 Using 2 dates 050325 and 981028 B-220-CONVERT-YEAR.
DISPLAY "IN CONVERT YEAR" IN CONVERT YEAR IF REM-WS2 = 0 SUBTRACT JDA2 FROM 366 GIVING YRS-DAYS ELSE SUBTRACT JDA2 FROM 365 GIVING YRS-DAYS YRS-DAYS= = 00064 DISPLAY "YRS-DAYS WITH JDA2 " YRS-DAYS. YRS-DAYS WITH JDA ADD JDA1 TO YRS-DAYS. YRS-DAYS = = 00148 DISPLAY "YRS-DAYS AFTER JDA1 ADDDED " YRS-DAYS. YRS-DAYS AFTER JDA1 ADDED 00148 SUBTRACT YR2 FROM YR1 GIVING YR-DIFF YR-DIFF = = 00093 DISPLAY "YR-DIFF " YR-DIFF. YR-DIFF 00093 IF YR-DIFF > 1 ADD 1 TO YR YR2 = = 99 (stored in 2 char field as 99) DISPLAY "YR-DIFF > 1 YR2 IS " YR2 YRDIFF > 1 YR2 IS 99 PERFORM B-300-ADD-A-YEAR UNTIL YR2 = YR1. Until 99 = 05 (to start) END WHEN 05 = 05

15 B-300-ADD-A-YEAR. DISPLAY "IN ADD A YEAR AND YR2 = " YR2 " AND YR1 = " YR1. PASS 1: IN ADD A YEAR AND YR2 = 99 AND YR1 = 05 PASS 2: IN ADD A YEAR AND YR2 = 00 AND YR1 = 05 PASS 3: IN ADD A YEAR AND YR2 = 01 AND YR1 = 05 PASS 4: IN ADD A YEAR AND YR2 = 02 AND YR1 = 05 PASS 5: IN ADD A YEAR AND YR2 = 03 AND YR1 = 05 PASS 6: IN ADD A YEAR AND YR2 = 04 AND YR1 = 05 DIVIDE YR2 BY 4 GIVING JUNK-ANS REMAINDER REM-YR. PASS 1: 99/4=24 REM-YR = 3 PASS 2: 00/4=0 REM-YR = 0 PASS 3: 01/4=0 REM-YR = 1 PASS 4: 02/4=0 REM-YR = 2 PASS 5: 03/4=0 REM-YR = 3 PASS 6: 04/4=1 REM-YR = 0 IF REM-YR = 0 ADD 366 TO YRS-DAYS PASS 2: YRS-DAYS = = 00879 PASS 6: YRS-DAYS = = 02340 ELSE ADD 365 TO YRS-DAYS. PASS 1: YRS-DAYS = = 00513 PASS 3: YRS-DAYS = = 01244 PASS 4: YRS-DAYS = = 01609 PASS 5: YRS-DAYS = = 01974 ADD 1 TO YR2. PASS 1: YR2 = 00 ( IN 2 CHAR FIELD = 00) PASS 2: YR2 = = 01 PASS 3: YR2 = = 02 PASS 4: YR2 = = 03 PASS 5: YR2 = = 04 PASS 6: YR2 = = 05 DISPLAY "YRS-DAYS " YRS-DAYS " YR2 " YR2. PASS 1: YRS-DAYS YR2 00 PASS 2: YRS-DAYS YR2 01 PASS 3: YRS-DAYS YR2 02 PASS 4: YRS-DAYS YR2 03 PASS 5: YRS-DAYS YR2 04 PASS 6: YRS-DAYS YR2 05


Download ppt "Date Conversion Program"

Similar presentations


Ads by Google