system date in RPG

200 pts.
Tags:
RPG
We have a dataq job that runs constantly. There are trigger programs on some files that control what is sent to the dataq which in turn prints certain forms at the correct outq. is there a 'date' variable that will reflect NOW? Udate and *date gives the same thing - the job start date. i realize i can retrieve system value, but wondered if that was the only solution. thanks.

Answer Wiki

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

Assuming you’re using RPG, use the TIME opcode to get the current date and/or time. You are correct in that UDATE gives the session date, and not the system date.
Rick

========================================================

A date field can be initialized to the current system date. This is not the same as the “job date” that is available through UDATE or *DATE. The INZ(*SYS) initialization brings system date into the variable. Example:
<pre>
h dftactgrp( *NO )
h actgrp( *CALLER )
h debug

d curDate s d inz( *sys )
d ctr s 5i 0 inz( 0 )

/free

curDate = d’2009-10-01′ ;

for ctr = 1 to 16 by 5 ;
reset curDate ;
curDate += %days( ctr ) ;
endfor ;

eval *inlr = *on ;
return ;

/end-free
</pre>
Run that example in debug to watch how curDate changes. It initializes to system date when the program starts. The first executeable statement sets curDate to ‘2009-10-01′. In the FOR-loop, the RESET operation sets curDate to its initialization value — the system date again.

The curDate is incremented by a duration based on the loop counter which counts by five. Each time through, curDate is reinitialized before being incremented by larger and larger values.

RESET is one simple way to set date fields to system date.

Tom

Discuss This Question: 5  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
  • WaltZ400
    If you are using ILE RPG, in D-specs define a date variable in whatever date format you use and add keyword INZ(*SYS) to it. When the program starts this variable is set to the system date. Likewise if you want job date, do a INZ(*JOB) on a date variable.
    655 pointsBadges:
    report
  • WilsonAlano
    Hi, You can do Eval Date = %Date() It will returns the current date which IMHO is a little more readable than the Reset technique. Wilson
    2,600 pointsBadges:
    report
  • TomLiotta
    Eval Date = %Date() There's certainly nothing wrong with that. It works especially well in longer expressions. As for readability -- reset Date -- is a bit shorter. I suppose it just depends on preferences of a developer. I'd use either under different circumstances. Tom
    125,585 pointsBadges:
    report
  • WilsonAlano
    As for readability — reset Date — is a bit shorter. I suppose it just depends on preferences of a developer. I’d use either under different circumstances If using reset Date you must go to Date definition to know which value is in INZ! Wilson
    2,600 pointsBadges:
    report
  • TomLiotta
    ...you must go to Date definition... I'd hope that every developer knows what their variable definitions are when they use or alter a variable value. If you store a %DATE() value in a variable, you might also want to know what the variable's DATFMT() is, and you should go to the definition. Different DATFMTs allow different valid date ranges, and different *LOVAL/*HIVAL values. You should always know the data definitions. One could always assume, I suppose; but I wouldn't. Regardless, you are right. That's one of the considerations that I use to decide which method I'd use in a particular case. 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