Midrange News for the IBM i Community


Posted by: Bob Cozzi
Rogue Programmer
Cozzi Productions, Inc.
Chicagoland
Get 1st of Month and End of Month in RPGIV
has no ratings.
Published: 19 Sep 2012
Revised: 23 Jan 2013 - 1703 days ago
Last viewed on: 22 Sep 2017 (3644 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

Get 1st of Month and End of Month in RPGIV Published by: Bob Cozzi on 19 Sep 2012 view comments(6)

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: DaleB
Premium member *
Reading, PA
Comment on: Get 1st of Month and End of Month in RPGIV
Posted: 5 years 1 days 8 hours 43 minutes ago

Performance question: Is the compiler smart enough to recognize that the repeated subexpression in endMonth has no side effects, and therefore can be reused, or would it be better to explicitly do the intermediate calc with a work field?

wrkDat   = myDate + %Months(1);
endMonth = wrkDat - %days(%subdt(wrkDat:*days));

 

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Get 1st of Month and End of Month in RPGIV
Posted: 5 years 1 days 6 hours 21 minutes ago

I would personally do the extra step myself because then its going to use the variable no matter what. RPG IV's optimizer does however optimize simple redundancies like this specific one. So I think it wouldn't really matter.

Posted by: Ringer
Premium member *
Comment on: Get 1st of Month and End of Month in RPGIV
Posted: 4 years 11 months 29 days 11 hours 26 minutes ago

endMonth = BeginMonth + %Months(1)  - %Days(1) ;

Chris Ringer

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Get 1st of Month and End of Month in RPGIV
Posted: 4 years 11 months 29 days 7 hours 59 minutes ago

Chris, I actually have/had that in my original example, however it doesn't stand-alone for a given date. You'd have to first calculate the 1st of the month, then pass that date to the EOM routine. So I made it more stand-alone.

Posted by: Ringer
Premium member *
Comment on: Get 1st of Month and End of Month in RPGIV
Posted: 4 years 11 months 29 days 5 hours 49 minutes ago

Well hey, I know you'd make those sub-procedures so... Cozzi_BeginMonth() would be available anytime. Laughing

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Get 1st of Month and End of Month in RPGIV
Posted: 4 years 11 months 29 days 3 hours 33 minutes ago

As would getEndOfMonth()