System Date in COBOL/400

Tags:
AS/400
COBOL
RPG
How to get the system date in the format of CCYYMMDD(*ISO) or MMDDCCYY(*USA) same like RPG/400? Can anyone please help?

Answer Wiki

Thanks. We'll let you know when a new response is added.

I would suggest reviewing the ILE COBOL Reference and in the chapter on Procedure Division Statements the description of ACCEPT identifier-1 FROM DATE YYYYMMDD. You may also want to explore the chapter on Intrinsic Functions.

Bruce Vining
Providing integrated solutions for the System i user community

ACCEPT <field> from DATE
will only return a date in YYMMDD format.
To get the full system date, try this….

Identification Division.
Program-Id. TimeDateCB.
Author. Charles Siu.

Environment Division.
Configuration Section.
Source-Computer. AS400.
Object-Computer. AS400.

Data Division.
Working-Storage Section.
01 Current-Timestamp.
05 Current-Year Pic 9(4).
05 Current-Month Pic 9(2).
05 Current-Date Pic 9(2).
05 Current-Hour Pic 9(2).
05 Current-Minute Pic 9(2).
05 Current-Second Pic 9(2).
05 Current-100thSec Pic 9(2).
05 GMT-Variation Pic X.
05 GMT-Hour-Difference Pic 9(2).
05 GMT-Min-Difference Pic 9(2).
Procedure Division.
MOVE FUNCTION CURRENT-DATE TO Current-Timestamp.
STOP RUN.

By the way, I am an RPG programmer too, in search of COBOL/400 knowledge.

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Rlsantucijr
    01 WS-DATE. 05 WS-CC PIC 9(002). 05 WS-YY PIC 9(002). 05 WS-MM PIC 9(002). 05 WS-DD PIC 9(002). 01 ISO-TODAY FORMAT DATE "@Y-%m-%d". ACCEPT WS-DATE FROM DATE YYYYMMDD. MOVE FUNCTION CONVERT-DATE-TIME ( WS-DATE DATE "%Y%m%d" ) TO ISO-TODAY.
    445 pointsBadges:
    report
  • anandx
    1. I don't see, contrary to popular belief, any logical 
    difference between RPGLE and CBLLE when it comes to 
    conversion of one date format to another date format. %BIF in 
    RPGLE converts a date data type into a numeric or character 
    data type and vice versa. We need to use first %date(), then 
    either %dec() or %char() and last %date() again. For instance,
    dtx=%date(%dec(%date(num:*eur):*usa):*usa) involves 3 steps, 
    though those 3 steps are combined in one single statement
    In COBOL too there are 3 (function) steps. The only 
    difference is that COBOL needs multiple statements and 
    variable declarations and that make the code look messy.
    2. Here is the COBOL code. Pgm2 converts *iso format to *usa 
    format. Pgm1 is expected to do the same as written in "ILE 
    COBOL Reference version 5, pg532 "convert-date-time"", but 
    doesn't do faithfully and only gives LNR7093 run-time error.
    Until that is resolved Pgm2 can be used for date conversion 
    from one format to another
    ----------------------------------------
    PGM1:
    Following code will compile error-free; but will give 
    run-time error LNR7093: "The contents of date-time item
    does not match its format"
    01  dt3  format date  "%m/%d/@Y".
    01  num01       pic 9(08). 
    
    move  function current-date(1:8) to num01  
    move function convert-date-time(num01  date '%m/%d/@Y')
         to dt3
    
    ------------------
    Pgm2:
    Following code will yield desired result, 
    but in a stone-age style
    
    01  dt_iso.                               
        05  yyyy_iso     pic x(04).           
        05  sep1_iso     pic x(01) value "-". 
        05  mm_iso       pic x(02).           
        05  sep2_iso     pic x(01) value "-". 
        05  dd_iso       pic x(02).           
    01  dt_usa.                               
        05  mm_usa       pic x(02).           
        05  sep1_usa     pic x(01) value "/". 
        05  dd_usa       pic x(02).           
        05  sep2_usa     pic x(01) value "/". 
        05  yyyy_usa     pic x(04).           
    
     move  function current-date(1:4) to yyyy_iso, yyyy_usa 
     move  function current-date(5:2) to mm_iso, mm_usa     
     move  function current-date(7:2) to dd_iso, dd_usa     
     display  'dt_iso: ', dt_iso, ' dt_usa: ', dt_usa       
    *result of display: dt_iso: 2017-12-18 
                        dt_usa: 12/18/2017  
    -------------------------------
    715 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: