Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple help for a begginner on cobol date function

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
I want to get the century part of the year from the as/400...

the usual statement is

ACCEPT TODAYS-DATE FROM DATE.

where TODAYS-DATE is

01 SYSTEM-DATE.
03 TODAYS-DATE.
05 YEAR PIC 99.
05 MONTH PIC 99.
05 DAY PIC 99.

What i want to do is add a century part onto the above statement. I have tried this way..

01 SYSTEM-DATE.
03 TODAYS-DATE.
05 CENTURY PIC 99.
05 YEAR PIC 99.
05 MONTH PIC 99.
05 DAY PIC 99.

But it did'nt work :(

 
If you do not need to worry about century "19", then you could simply move your accepted date into another date field with "20" hard coded as the century.
Code:
01  SYSTEM-DATE.
     03 TODAYS-DATE.
          05 YEAR       PIC 99.
          05 MONTH    PIC 99.
          05 DAY         PIC 99.

     03 ADJUSTED DATE.
          05 ADJ-CENTURY PIC 99 VALUE 20.
          05 ADJ-YEAR       PIC 99.
          05 ADJ-MONTH    PIC 99.
          05 ADJ-DAY         PIC 99.

MOVE YEAR TO ADJ-YEAR.
MOVE MONTH TO ADJ-MONTH.
MOVE DAY TO ADJ-DAY.

If the century does need to be validated then you can code a check of YEAR, and determine a logical cut off point for your situation. Perhaps....
Code:
IF YEAR > 90
    MOVE 19 TO ADJ-CENTURY
ELSE
    MOVE 20 TO ADJ-CENTURY
END-IF.

Again, probably not the absolute best solution, but it is functional.

s-)
 
Tom,

check your compiler for a Y2K-compliant date function. If it's available, it'll give you a complete system date including the century.

Otherwise, stick to Greenguy's solution (any of the two); within it's limits, it is the most pragmatic and widely used one.

Good luck,
Ronald.
 
If the release of the AS/400 COBOL compiler is fairly current this will work:

01 Some-Date.
03 Some-yyyy pic 9(4).
03 Some-mm pic 9(2).
03 some-dd pic 9(2).


....

Move Function Current-date (1:8) to Some-date.

 
This is like Green Guy's, only lazier.

01 SYSTEM-DATE.
05 ADJ-CENTURY PIC 99 VALUE 20.
05 TODAYS-DATE.
10 YEAR PIC 99.
10 MONTH PIC 99.
10 DAY PIC 99.

Then you can accept into the TODAYS-DATE field and use the SYSTEM-DATE field. Since the ACCEPT gets the current date, the century should always be 20. Of course, this will quit working in 2100, but don't write back then, as I may not be around.


Betty Scherber
Brainbench MVP for COBOL II
 
... introducing a Y2K1 problem there, eh Betty ? :-D

Regards,
Ronald.
 
Actually coding Green Guy's Y2K1 problem with greater efficiency. If code is going to quit working that many years after I die, at least it might as well be efficient while I'm still alive. Betty Scherber
Brainbench MVP for COBOL II
 
Betty,

point taken; and indeed, your solution doesn't need the extra moves. Anyway, by that time we probably have self-learning COBOL, which finds out the error and corrects it automaticly ... yeah, right ?!

Regards,
Ronald.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top