×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
Tom Liotta wrote:
3. Dates (Kelley)
I have a vendor that wants to send me a file to be uploaded to our
iSeries.
The problem is with the dates that get sent. Normally, today's date
would be
08/07/2007 which the %date biff would handle just fine. Unfortunately,
the
dates I'm receiving drop the leading 0 in both the month and day,
resulting
in 8/7/2007 which the %date doesn't like. Any ideas how to handle this
other
then parsing it out?
Kelley:
I know this below isn't RPG, but it's all I have available this minute.
Discussion can get it into RPG after the principles become clear. This
example is just to get it started.
The basic answer is probably to use a couple date/time CEE* APIs. They
make this too easy to be concerned over. You ought to be able to
copy/paste this into an ILE CL member, compile with PDM option 14 (or
CRTBNDCL), run it and review the resulting dump. The two variations show
converting [8/7/2007] to [08/07/2007] and converting [08/7/2007] to
[08/07/2007], both using the same parms except the input date itself
changes:
pgm
dcl &inDate *char 32
dcl &picStr1 *char 32 value( 'ZM/ZD/YYYY' )
dcl &outDate *char 32
dcl &picStr2 *char 32 value( 'MM/DD/YYYY' )
dcl &outDays *int 4
/* Convert '8/7/2007'... */
chgvar &inDate '8/7/2007'
callprc ceedays ( +
&inDate +
&picStr1 +
&outDays +
)
callprc ceedate ( +
&outDays +
&picStr2 +
&outDate +
)
dmpclpgm
/* Convert '08/7/2007' to show leading-zero effect... */
chgvar &inDate '08/7/2007'
callprc ceedays ( +
&inDate +
&picStr1 +
&outDays +
)
callprc ceedate ( +
&outDays +
&picStr2 +
&outDate +
)
dmpclpgm
return
endpgm
It's all in the "picture strings". The APIs do the parsing for you. All
you gotta do is tell it what the incoming string looks like (more or
less; there's some useful flexibility).
Somebody else might demo a shorter version. This one takes an incoming
date string ( &inDate ), converts it according to the picture string
into what's called 'Lilian Date', then that's immediately converted to
an outgoing date string ( &outDate ). A 'Lilian Date' is "the number of
days since 14 October 1582". My &outDate becomes '08/07/2007', but a
picture string 'MMDDYYYY' would give '08072007'. Your choice.
Note that my picture string variables and date variables are declared as
the same length. They don't have to be *char(32) but they should match
up. The date variables do need to be big enough that the picture strings
fully describe every significant position.
It's almost too simple when you get to working with this group of APIs.
Tom Liotta
As an Amazon Associate we earn from qualifying purchases.