View previous topic :: View next topic |
Author |
Message |
bobi Beginner
Joined: 15 Jun 2005 Posts: 12 Topics: 7
|
Posted: Thu Jan 12, 2006 5:23 am Post subject: Yesterday's date in VS Cobol - II |
|
|
Hi,
I want to process the data from a file based on DATE Validation. The DATE inside the file if equal to yesterdays date then i have to process.
Can some one tell me how to find yesterdays date in the cobolII
The date format in the input file is YYYYMMDD.
Thanks
Bobi |
|
Back to top |
|
 |
bobi Beginner
Joined: 15 Jun 2005 Posts: 12 Topics: 7
|
Posted: Thu Jan 12, 2006 5:50 am Post subject: |
|
|
Hi ,
I'm using VS COBOL II, forgot to mention it.
Thanks
bobi |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Thu Jan 12, 2006 9:19 am Post subject: |
|
|
Bobi,
Try this code.
Code: |
WORKING-STORAGE SECTION.
01 WS-CURR-DATE.
05 WS-CURR-CC PIC 9(02) VALUE 20.
05 WS-CURR-YYMMDD.
10 WS-CURR-YY PIC 9(02).
10 WS-CURR-MM PIC 9(02).
10 WS-CURR-DD PIC 9(02).
01 WS-PREV-DATE.
05 WS-PREV-CC PIC 9(02) VALUE 20.
05 WS-PREV-YYMMDD.
10 WS-PREV-YY PIC 9(02).
10 WS-PREV-MM PIC 9(02).
10 WS-PREV-DD PIC 9(02).
01 WS-GREG-CCYY.
05 WS-GREG-CC PIC 9(02) VALUE 20.
05 WS-GREG-YY PIC 9(02).
01 WS-CURR-YEAR REDEFINES WS-GREG-CCYY PIC 9(04).
01 WS-LEAP-YR-SWITCH PIC X.
88 ITS-A-LEAP-YR VALUE 'Y'.
88 ITS-NOT-A-LEAP-YR VALUE 'N'.
01 WS-MONTH-END-DD PIC X(24) VALUE
'312831303130313130313031'.
01 WS-TBL-MONTH-END REDEFINES WS-MONTH-END-DD.
05 TBL-MONTH-END-DAY PIC 9(02) OCCURS 12 TIMES.
01 WS-REMAINDERS.
05 WS-QUOT PIC 9(01).
05 WS-4-REM PIC S9(01) COMP.
88 DIVISIBLE-BY-4 VALUE +0.
05 WS-100-REM PIC S9(02) COMP.
88 DIVISIBLE-BY-100 VALUE +0.
05 WS-400-REM PIC S9(03) COMP.
88 DIVISIBLE-BY-400 VALUE +0.
PROCEDURE DIVISION.
ACCEPT WS-CURR-YYMMDD FROM DATE
COMPUTE WS-PREV-DD = WS-CURR-DD - 1
MOVE WS-CURR-YY TO WS-GREG-YY WS-PREV-YY
IF WS-PREV-DD = 0
EVALUATE WS-CURR-MM
WHEN 1
COMPUTE WS-PREV-YY = WS-CURR-YY - 1
MOVE 12 TO WS-PREV-MM
WHEN 3
COMPUTE WS-PREV-MM = WS-CURR-MM - 1
PERFORM 1000-LEAP-YEAR-CHECK
WHEN OTHER
COMPUTE WS-PREV-MM = WS-CURR-MM - 1
END-EVALUATE
IF ITS-A-LEAP-YR
MOVE 29 TO WS-PREV-DD
ELSE
MOVE TBL-MONTH-END-DAY(WS-PREV-MM) TO WS-PREV-DD
END-IF
ELSE
MOVE WS-CURR-MM TO WS-PREV-MM
END-IF
DISPLAY 'THE CURRENT DATE IS : ' WS-CURR-DATE
DISPLAY 'THE PREVIOUS DATE IS: ' WS-PREV-DATE
GOBACK
.
1000-LEAP-YEAR-CHECK.
SET ITS-NOT-A-LEAP-YR TO TRUE
DIVIDE WS-CURR-YEAR BY +4 GIVING WS-QUOT
REMAINDER WS-4-REM
DIVIDE WS-CURR-YEAR BY +100 GIVING WS-QUOT
REMAINDER WS-100-REM
DIVIDE WS-CURR-YEAR BY +400 GIVING WS-QUOT
REMAINDER WS-400-REM
IF DIVISIBLE-BY-400 OR
(DIVISIBLE-BY-4 AND NOT DIVISIBLE-BY-100)
SET ITS-A-LEAP-YR TO TRUE
END-IF
.
|
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
German Castillo Beginner

Joined: 23 Dec 2005 Posts: 83 Topics: 2 Location: Caracas, Venezuela
|
Posted: Thu Jan 12, 2006 10:07 am Post subject: |
|
|
adding on to Kolusus' post, and as an Alternative, LE can be called to do so
like :
Code: |
CALL "CEEDAYS" using WS-TODAY, MY-PICTURE,
WS-LILIAN, WS-FC
SUBTRACT 1 FROM WS-LILIAN
CALL "CEEDATE" using WS-LILIAN, MY-PICTURE,
WS-YESTERDAY, WS-FC
|
Use the date picture you want to, Like MM/DD/YYYY (as a char string), WS_LILIAN should be a S9(9) Binary, and if you really do not want to check the callable services RC, Define WS-FC a bit large, else COPY the area CEEIGZCT and append to it around 30 bytes. For the proper format of the comunication area look under LE Programming Reference manual. I you are using Current date as your input, you shouldn't have any big problem. _________________ Best wishes,
German Castillo |
|
Back to top |
|
 |
bobi Beginner
Joined: 15 Jun 2005 Posts: 12 Topics: 7
|
Posted: Fri Jan 13, 2006 1:56 am Post subject: |
|
|
Hi Kolusu,
Thanks for the code.
Hi Castillo,
I have tried with your code but the out put WS-LILIAN is displaying as zero.
i have declared WS-LILIAN S9(9) BINARY.
Can you please help me on this.
Thanks
bobi |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
|
Back to top |
|
 |
German Castillo Beginner

Joined: 23 Dec 2005 Posts: 83 Topics: 2 Location: Caracas, Venezuela
|
Posted: Fri Jan 13, 2006 12:33 pm Post subject: |
|
|
Hello bobi,
All the variable length fields have to be prefixed with its lengh as a half-word. That is, pictures, and date themselves, this is sorta standard in variable length field usage, at least for a vast deal of common utilities. You need to do something like:
Code: |
01 MY-PICTURE.
05 MY-PICTURE-LENGHT PIC S9(04) COMP.
05 MY-PICTURE-DATA PIC X(80).
01 WS-TODAY.
05 WS-TODAY-LENGTH PIC S9(04) COMP.
05 WS-TODAY-DATA PIC X(80).
|
Likewaise for ws-yesterday, just be sure to populate both Data and lengths. or follow the Above links for good samples. _________________ Best wishes,
German Castillo |
|
Back to top |
|
 |
haatvedt Beginner
Joined: 14 Nov 2003 Posts: 66 Topics: 0 Location: St Cloud, Minnesota USA
|
Posted: Sun Jan 15, 2006 2:38 am Post subject: |
|
|
Bobi,
I would suggest that you first check to see if your shop has a "inhouse date routine". Every shop that I have worked for has had one. Our standard date routine has the ability to check the JCL for a certain DDNAME and accept an override for the current date if it is present.
The problem with using the System Intrinsic is that if you have to rerun the job for some reason later (on a different day), it is very difficult to modify the system date.
Chuck H. _________________ Chuck Haatvedt
email --> clastnameatcharterdotnet
(replace lastname, at, dot with appropriate
characters) |
|
Back to top |
|
 |
|
|