API to get the GMT date and time in AS/400 system

310 pts.
Tags:
AS/400
AS400 - retrieve GMT date and Time
Hi, I need to get the GMT date and time from the AS/400 system. Is their any API available to retrieve the GMT date and Time. Please suggest the way to retrieve the date and time. It's very urgent.

Answer Wiki

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

GMT (UTC) can be retrieved in a variety of ways. I don’t have a RPG example handy that I can post, but I have one in ILE CL that uses two different methods. Either method will translate fairly directly to ILE RPG:

pgm

dcl &QTIME *char 6
dcl &QDATE *char 6
dcl &QDATETIME *char 20
dcl &QTIMZON *char 10
dcl &QUTCOFFSET *char 5

/* For Convert Date & Time... */

dcl &CDT_I_FORM *char 10 value( '*CURRENT' )
dcl &CDT_I_VAR *char 8
dcl &CDT_O_FORM *char 10 value( '*YYMD' )
dcl &CDT_O_VAR *char 20
dcl &CDT_I_TZ *char 10 value( '*JOB' )
dcl &CDT_O_TZ *char 10 value( '*UTC' )
dcl &CDT_O_TZi *char 111 value( ' ' )
dcl &CDT_O_TZl *int value( 111 )
dcl &CDT_O_Pi *char 1 value( '0' )

/* And we'll need to specify an errcode receiver at one point... */

dcl &ERRCODE *char 116 value( x'00000074' )
dcl &ERRLEN *int value( 0 ) /* +
Will tell us how long any exception data +
is... */

/* These are all for CEE* transformations... */

dcl &RtnDt *int value( 0 )
dcl &RtnVal1 *char 8
dcl &RtnVal *char 15

dcl &PicStr *char 26 value( 'YYYYMMDDHHMISS999999' )

rtvsysval QTIME rtnvar( &QTIME )
rtvsysval QDATE rtnvar( &QDATE )
rtvsysval QDATETIME rtnvar( &QDATETIME )
rtvsysval QTIMZON rtnvar( &QTIMZON )
rtvsysval QUTCOFFSET rtnvar( &QUTCOFFSET )

chgvar &CDT_I_VAR &QTIME

call QWCCVTDT ( +
&CDT_I_FORM +
&CDT_I_VAR +
&CDT_O_FORM +
&CDT_O_VAR +
&ERRCODE +
&CDT_I_TZ +
&CDT_O_TZ +
&CDT_O_TZi +
&CDT_O_TZl +
&CDT_O_Pi +
)

chgvar &ERRLEN %bin( &ERRCODE 5 4 )

callprc CEEUTC ( +
&RtnDT +
&RtnVal1 +
*omit +
)
callprc CEEDATM ( +
&RtnVal1 +
'Mmm ZD HH:MI:SS' +
&RtnVal +
*omit +
)

dmpclpgm

return

endpgm

The module does three things — retrieves basic system values at run-time, CALLs QWCCVTDT to get the *UTC representation of *CURRENT date/time and CALLs CEEUTC to retrieve GMT (UTC) which is then converted to a ‘Mmm ZD HH:MI:SS’ picture string.

The module dumps all variables before returning.

From that, you can take your choice of the Convert Date and Time Format (QWCCVTDT) API or the Get Universal Time Coordinated (CEEUTC) API, whichever suits you.

The module should compile with CRTCLMOD without change on V5R3 or later. Then just use CRTPGM to create the program. Or if you prefer, just compile with CRTBNDCL.

The API documentation should tell any details. If they work in CL, RPG should be simple; but questions might arise.

Tom

Discuss This Question: 4  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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • As400pgmmer
    Hi, In V5R3 we dont have these two API's , so we need to install these APIs. Please give us the steps to install these two APIs( CEEUTC & CEEDATM). Thanks, Amutha
    310 pointsBadges:
    report
  • TomLiotta
    In V5R3 we dont have these two API’s , so we need to install these APIs. At V5R3, you already have those APIs. You don't install them -- they are part of the system. Documentation for all ILE CEE Date and Time APIs is in the V5R3 Information Center. Other CEE* APIs are given in surrounding topics. The example program came from a V5R3 system. You can't search for them because they're not program objects -- they're procedures. That's why the CALLPRC command was used instead of CALL. The system will bind them into your programs automatically. Tom
    125,585 pointsBadges:
    report
  • As400pgmmer
    Hi Tom, Thanks. The code was working fine. CEEUTC & CEEDATM, I had seen that it is Procedure, but you have mentioned it as API. So I was searching for it in QSYS and QPARMS. So i have raised a query. Thanks and Regards, P.Amutha
    310 pointsBadges:
    report
  • TomLiotta
    As the link to the Information Center shows, IBM calls them "APIs". I'm not aware that an API must be a "program". An API is simply an interface that is made available to application programs -- Application Program Interface. For some APIs, you need to bind with a system service program. For others, the system binds automatically -- these would usually be considered to be "built-ins". For still others, you make an external program CALL. Anyway, I hope the example and the documentation link provide what you need. Tom
    125,585 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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

Following