IBMi (AS400) fans only : Reverse date 6 0 in one instruction
#IBMiSample
In this example, the OTDTP0 field is numeric 6 with 0 decimal places.
It should contain a number rapresenting a DATE in yymmdd (i.e 210208 - February 8, 2021) or ddmmyy format (i.e 080221 - February 8, 2021).
The following instructions turns yymmdd to ddmmyy or viceversa (the other way around).
OTDTP0 zoned(6);OTDTP0 = %dec(%char(%date(OTDTP0:*ymd):*dmy0):6:0); // yymmdd to ddmmyy
OTDTP0 = %dec(%date(OTDTP0:*ymd):*dmy); // yymmdd to ddmmyy
I appreciate all the comments made on this blog.
//-- %char is not necesssary, mmddyy to yymmdd:
ReplyDeleteYYMMDD = %Dec(%date(MMDDYY:*mdy):*ymd);
Thanks for your help. I updated the post according to your suggestion
DeleteI find using a monitor/on-error on the conversion line catches invalid dates better than checking for not zero.
ReplyDeleteInstead of qualifying that your decimal field <> *zeros, if you monitor on the conversion, you can set the value to zero, or a date you can identify as a problem without the program bombing. (Monitor/conversion/on-error/eval to zero/endmon)
ReplyDelete