ISO date Formats and Move

0 pts.
Tags:
RPG
RPGLE
I need to do 2 things . Perform day additions and deductions on a date format yyyymmdd. Am I correct in thinking this is *ISO format? And is there any example code of arithmetic? 2. Also I have been advised on RPG4 not to use MOVE to change char to dec. Is this correct, and what alternatives are suggested? Sorry this is basic stuff but I am on a very steep learning curve to RPG4 after 5 years out Thanks
ASKED: September 29, 2006  8:53 AM
UPDATED: October 2, 2006  9:19 AM

Answer Wiki

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

Hi

No it’s not ISO. ISO is “YYYY-MM-DD” with the separators specified. Having said that it’s as ISO as you would get in a numeric field.

The easiest way to do arithmetic is using date type fields and then using the %Days, %Months and %Years built in functions. The following RPG IV program demonstrates the use of date fields and arithmetic:

D MyDecDate s 8s 0 Inz(20061231)

D MyDateISO s d DatFmt(*ISO)
D MyDateEUR s d DatFmt(*EUR)
D MyDateUSA s d DatFmt(*USA)

C* Convert the decimal date to ISO format…
C Eval MyDateISO = %Date(MyDecDate : *ISO)
C MyDateISO Dsply

C* Moving between date type fields automatically changes the format…
C Eval MyDateEUR = MyDateISO
C MyDateEUR Dsply

C Eval MyDateUSA = MyDateEUR
C MyDateUSA Dsply

C* Date calculations can be done using Eval and %Days, %Months and %Years functions…
C Eval myDateISO = myDateISO + %Years(1) +
C %Months(6) + %Days(14)
C MyDateISO Dsply

C Eval *InLR = *On
C Return

A lot of the experts say to use free format RPG, which doesn’t allow MOVE. If, like me, you still use the extended fixed format layout then I would say to use Eval as it allows you to do more than a simple MOVE.

Unfortunately you can’t use “Eval Char=Numeric”, instead the accepted technique is to use edit codes to convert it:

Eval Char = %EditC(Numeric : ‘X’)

Edit code “X” does a straight conversion. To convert from numeric to character, use:

Eval Char = %Char(Numeric)

Hope it helps, any more questions please shout.

All the best

Jonathan

Discuss This Question: 1  Reply

 
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
  • Ricksmith
    My boss loaned me a book a year ago(which I have not given back) that has been an indispensable source for RPGIV advice and reference. It is "RPG IV Jump Start" by Bryan Meyers. It is the fourth edition and is updated for V5. It contains alot of date manipulation examples. It is loaded with free-form examples, also. You should get this book!
    0 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