Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date field: just a complain 2

Status
Not open for further replies.

thelearner

Programmer
Jan 10, 2004
153
US
Hi everyone,

I'm very new in RPG free format and I found that the date function is rather pain in the bud. If I want to move a numeric field to a date field I have to check that my original field contain a valid date before I move.

Another case is that when I define an output field, in O spec, as a date field and my input field does not have a data. Even I check the input field and not do the move if there is no data, the output field still contain some default value (or should I say junk data).

I didn't have to do these extra steps in RPG400.

Any comment, anyone!
 
We all should be doing these steps anyway. You will thank yourself down the road when you don't have to clean up the data later on (or deal with users calling about run-time RPG errors).

To make it easier, why not write a service program to validate the dates and just call it?

Long ago, I wrote several modules that validate and convert numeric dates for our system (our dates are stored in our files as packed CYYMMDD). All our programs use them, however, I am starting to use RPG's built-in date-handling more and more.

As for the O-spec, simply do a TEST(DE) with a resulting indicator, and condition the O-spec to print the field only when the indicator is not on (if you have a numeric date). If it's a native date, turn on the indicator if the date = D'0001-01-01' (I used *ISO format here as an example).

Code:
*IN01 = isodate = D'0001-01-01'; // *IN01 = don't print ISODATE


"When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return."

--Leonardo da Vinci

 
rapeek,

In free format you can also use a MONITOR block to catch and handle errors. Monitor for an error then call a error handling routine much like the date handling routines sugested by flapeyre.

HTH,
MdnghtPgmr
 
MdnghtPgmr:

For the record, MONITOR also works in fixed-format on V5R1 and later. I have used it to trap a decimal-data error situation (occasionaly, a file we refresh nightly comes in from an NT server corrupted), and to catch overflows on EVAL expressions, but I've never tried to use in to test dates - that's what TEST(DE) was meant for.


"When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return."

--Leonardo da Vinci

 
flapeyre,

We use it on unattended batch jobs at night to let someone know we had a problem. Example:


Monitor;
BegAnnDate = %DATE( %EDITC( BegAnvYr : 'X' ) + '-' +
%EDITC( BegAnvMo : 'X' ) + '-' +
%EDITC( BegAnvDa : 'X' ) : *ISO );
On-Error *ALL;
ErrorDate = %EDITC( BegAnvYr : 'X' ) + '-' +
%EDITC( BegAnvMo : 'X' ) + '-' +
%EDITC( BegAnvDa : 'X' );
// 12345678901234567890
FieldName = 'BegAnvYr, Mo, Da';
ExSr SendMessage;
*INLR = *ON;
Return;
EndMon;

Thanks,
MdnghtPgmr
 
Thank flapeyre and MdnghtPgmr for responses and the sample codeings. That's new thing for me to learn (and remember).
 
MdnghtPgmr:

I can see where dates may be a problem there, using separate month, day and year fields. Since all of our dates are one-field dates, we can just validate them by using TEST(DE). For your situation, it's just as easy to use MONITOR, I agree.




"When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return."

--Leonardo da Vinci

 
flapeyre,

Oh God how I wish we would convert to date type fields. Life would be so much better. We have a mish-mash of date type fields, 8 digit fields and 4 2 digit fields and some 2-2-4 digit fields. A person could go crazy (grin).

Thanks for the feedback! You too rapeek!
MdnghtPgmr
 
iSeriesCodePoet,

Don't I know it! Add to that a mish-mash of RPG-II, RPG-III, RPGILE and now free format and you have the making of a wonderfully confused staff. I saw some RPG-II code written not two days ago. Nobody conforms to standard (well, a couple of us do). It's so fun! I have given demos on free format to the whole staff but only two of us use it. Oh well, they pay me.

End of rant,
MdnghtPgmr
 
I worked in a place like that once - it can't be the same place you work, because mine went bankrupt in 1997 (after they laid me off).

We had the same date in the same file 3 different ways - MMDDYY, YYMMDD, and Julian (I hate Julian dates[curse]!!!).


"When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return."

--Leonardo da Vinci

 
Ouch... I use free-form and another uses it some, the problem with us we have applications that we must conform to how they work. :-( Oh well... like you said. I get get paid.

iSeriesCodePoet
iSeries Programmer/Lawson Software Administrator
[pc2]
See my progress to converting to linux.
 
That system was a nightmare. It had error messages in a flat file that was chained to by RRN, would you beleive? I was not permitted to make this a keyed file - mustn't mess with the vendor's software!


"When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return."

--Leonardo da Vinci

 
Hi everyone,

For those of you who work with mix version of RPG, LE and older one, how can you locate the program that you looking for, without searching all over the places.
For example, most of our programs that print report will have a name that start with 'RP' follow with 3 digits, like RP010. If I have to create a new report printing pgm in RPGLE, should I follow the same rule?

In that case, later on if we need to work with that pgm, what happen is first we will go to the usual place (QRPGSRC) then we won't find it. Then we will have to do WRKOBJ to see where it is. And probably they will complain!

If I create another naming standard, let's say 'LERP' follow by 3 digits. If later on we want to find this report but we don't remember the name of the report. Currently we just start go to the PDM and start searching from 'RP' something. In this case they will never find it. Then we will have to go to QRPLESRC to start seaching again. And they will probably complain again!

What's your suggestion?
 
rapeek,

For us it's a combination of scan source and/or knowing what menu option a user is taking. In the case of nightly, month end and so on it's a matter of just knowing what jobs run. These are documented so it's not too bad.

We also have a tool that works wonders for finding where and how a file, field, program is accessed. It's called Abstract and I recommend it. It's pricey but it was the first gift from the new boss. Then we got access from home. We're almost up to the '90 around here now!

Keep grinning,
MdnghtPgmr
 
All out reports print the program name on them - we get that from the PSDS. And I try to keep the title of the report the same as the member description.

If the spool file is still on the system, you can take option 8 and then you will see all kinds of useful info - such as:

Device type
Printer device type
Device file
Library
User-specified data
Accounting code
Program that opened file
Library
Date file was opened
Time file was opened
Date file was last used
System where file created
User who created file
User-defined file


"When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return."

--Leonardo da Vinci

 
Well, it's not that easy. A lot of time our user or client will ask for a report that contain such and such info. We know or kind of remember that we have that kind of report. We just don't remember what pgm do that. So we start searching from 'RP' and check from the text description.
If we have to do that on both QRPG and QRPGLE, we will probably go nut. But putting LE pgm in the same place with non LE is probably a bad idea.
 
As I said, you can always make sure the program name is on the report in the same place on each page. Easy to see what program you need to modify, then.


"When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return."

--Leonardo da Vinci

 
May be I wasn't clear enough, whoever ask for the report sometime they don't have the report in their hand. They just tell us what they want to see on the report.
 
rapeek,

I agree with flapeyre. That is one of our "standards". The program name (again like flapeyre) is gotten from the PSDS and is always in the upper left hand corner in the headings.

We do the same thing with display files. With diplay files we also display the current format name on the upper right side with the date under the program name and the time under the format name.

This really helps when you have a user on the phone. You can just say, "Read me off the letters and numbers at the very top of your screen.

HTH,
MdnghtPgmr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top