× 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.



If the program was and SQLRPGLE would this be more efficient?

Exec sql
SET :NEWDATE = Date(
(CASE WHEN extract(day from :OLDDATE ) >=16
THEN '16' ELSE '01' END)
|| digits( DEC( extract(month from :OLDDATE ) ,2,0))
|| digits( DEC( extract(year from :OLDDATE ) ,4,0)));


Chris Hiebert
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Barbara Morris
Sent: Tuesday, June 12, 2012 4:15 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: Re: Change the day of a date

On 6/12/2012 1:52 PM, Dennis wrote:
Oops. . . in my haste to get to work -- because, don't we all love
ourjobs that much? -- I stopped the changes too soon. I will leave
completion as an exercise for no extra points.

This is the only way I can think of to do it without work variables.

if %subdt(MyNewDateField: *Days)>= 16 ; // set day to 16
MyNewDateField -= %days( %subdt(MyNewDateField: *Days) - 16 ) ;
else ; //<= 15 ; set day to 01
MyNewDateField -= %days( %subdt(MyNewDateField: *Days) - 01 ) ;
endif ;

But, gagorama, I should be awarded negative points for even typing this.

Not only does it do the costly %subdt twice, it has the same complex
expression three times in the code, maximizing the potential for
maintenance errors. Hoping there's a better solution to Dennis'
challenge.

Here's a way of using the work variable twice, to further simplify the
code by having only one statement where the %days is subtracted.

Days = %subdt(MyNewDateField: *Days);
if Days >= 16 ; // set day to 16, eg 2012/06/27
Days -= 16; // by subtracting this many days, eg 11
else; // set day to 1, eg 2012/06/09
Days -= 1; // by subtracting this many days, eg 8
endif;
MyNewDateField -= %days( Days );

I'm a fan of using work variables and extra statements to simplify code.

I'm a bit uneasy about using the vague "Days" for two purposes, though.
Maybe two work variables, "DayNbr" and "DaysToSubtract", would be
better.



--
This is the RPG programming on the IBM i / System i (RPG400-L) mailing
list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/rpg400-l.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.