Convert an *iso date to *longjul in CLP

30 pts.
Tags:
CL Errors
CL Program
I am trying to convert an *iso date to a *longjul date in a CL program so I can subtract 6 days from today. It is crashing with a message "Date contains too many or too few numeric characters." My code is : Definitions dcl var(&julend) type(*char) len(7) dcl var(&jul) type(*dec) len(8 0) Code cvtdat date(&today) tovar(&julend) fromfmt(*iso) + tofmt(*longjul) tosep(*none) chgvar var(&jul) value(&julend) chgvar var(&jul) value(&jul - 6) chgvar var(&julend) value(&jul) cvtdat date(&julend) tovar(&begdte) + fromfmt(*longjul) tofmt(*iso) tosep(*none) I think my problem is I'm going from 2013-01-04 back 6 days to 2012-12-28. Am I using the correct number in my subtraction of 6 days ? Cheers, Jenny

Answer Wiki

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

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
  • TomLiotta
    If your starting date is '2013-01-04', the *LONGJUL value will be 2013004. The result of (2013004 - 6) will be 2012998. You probably can guess that the 998th day of 2012 will be quite a ways beyond the end of the year.   In general, you can't subtract numeric values from dates. You should only subtract "durations". However, CL doesn't support date duration operations.   You could write a small RPG (or COBOL, C or REXX) procedure and bind it into your program. Or you could code some ugly CL that manipulates values to simulate date duration math. Personally, since this already about CL, I would use the ILE CEE* date APIs to turn dates into numeric values and back into dates.   Here's a simple example that you can do some testing with: pgm ( + &FromDate + &NbrDays + &ResultDate + ) dcl &FromDate *char 10 dcl &NbrDays *dec ( 3 ) dcl &ResultDate *char 10 dcl &RtnVal1 *int dcl &RtnVal2 *int dcl &PicStr *char 10 value( 'YYYY-MM-DD' ) callprc CEEDAYS ( + &FromDate + &PicStr + &RtnVal1 + *omit + ) chgvar &RtnVal2 ( &RtnVal1 - &NbrDays ) callprc CEEDATE ( + &RtnVal2 + &PicStr + &ResultDate + *omit + ) Exit: return endpgm That proc receives a date in 'YYYY-MM-DD' format and a number of days. It subtracts the number of days from the date and returns the new resulting date. You can look at the documentation for CEEDAYS to see how it turns the date into a number. After the CL subtracts &NbrDays from that number, the API docs will describe how CEEDATE turns the new number back into a date.   Any discussion that you need for details can be continued here. I hope the formatting of the source code works out and you can read it. Be aware that this doesn't do any validation of the incoming values; the error code (function code, fc) is omitted. That can be covered if the docs are too confusing.   Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    Well, I guess it came out readable, but not presented in [code] formatting. I'll leave it alone for now.   Tom
    125,585 pointsBadges:
    report
  • bluedragon6
    Thanks, I ended up writing a small rpg program to just add or subtract number of days to an *iso date and called that from the CL.  Cheers, Jenny
    30 pointsBadges:
    report
  • bvining
    Vendor response. Using the eXtreme CL Date and Time Support (one time charge, $19.95), available with V5R4 and all following releases, you could use the Change Date command (ChgDatXCL) as shown iin the following program (using your data values): Pgm                                                              Dcl        Var(&Today)   Type(*Char) Len(10) Value('2013-01-04') Dcl        Var(&Answer)  Type(*Char) Len(10)                                                                                      ChgDatXCL  Var(&Answer) Fmt(*ISO) +                                           DatAdj((*Sub 6 *Days)) BasVal(&Today) +                          BasFmt(*ISO)                                                                                                         SndPgmMsg  Msg(&Answer) ToPgmQ(*Ext)                                                                                              EndPgm                                                           To give you a feel for what the command supports, the online documentation can be found at http://www.powercl.com/xcl/xclcommands/chgdatxcl I realize you've already written a RPG program to meet your specific need, but this (and other commands in Date and Time) might be useful in the future. Bruce End vendor response  
    6,410 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