TechTalk: An RPG IV date calculation routine.

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

One of the long-awaited features of RPG IV (ILE RPG) is the ability to do date math. Now that RPG has date math, there are many ways to take advantage of it, even if your date fields aren't date data types. One way is by writing a generic date calculation routine, such as the one shown in 5. This routine will return a calculated date based on the values passed into it. There are four parameters to this routine:

One of the long-awaited features of RPG IV (ILE RPG) is the ability to do date math. Now that RPG has date math, there are many ways to take advantage of it, even if your date fields aren't date data types. One way is by writing a generic date calculation routine, such as the one shown in Figure 5. This routine will return a calculated date based on the values passed into it. There are four parameters to this routine:

1. A starting date

2. A duration value

3. A duration code

4. A return date

The first parameter (starting date) should be passed as an 8-byte character field in the format YYYYMMDD. The second parameter is the duration value that you want to use to increment the date. This routine supports both calculating dates later than the start date and calculating dates earlier than the start date. To calculate a date later than the start date, pass a positive value in the second parameter. To calculate a date earlier than the start date, pass in a negative value in the second parameter. The third parameter is a duration code. Pass a value of D to increment by days, M to increment by months, or Y to increment by years. The calculated date is returned through the fourth parameter as an 8-byte character field in YYYYMMDD format. If the routine determines that an invalid date has been passed in through the first parameter, it will pass back a date of all nines through the fourth parameter.

As with most ILE routines, there are several ways to implement this code. You could compile it as a standalone program with the Create Bound RPG Program (CRTBNDRPG) command. This would allow you to make external calls to it from your own programs, whether they're ILE programs or not.

Alternatively, you could compile this routine using the Create RPG Module (CRTRPGMOD) command, followed by either the Create Service Program (CRTSRVPGM) or the Create Program (CRTPGM) command. This would give you better performance by allowing you to bind the executable code into your own programs.

- Izzy Munoz and T.V.S. Murphy


Figure 5: RPG IV Date Calculation Routine

 *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 D WorkDate S 10D DATFMT(*ISO) D InputDate S 8S 0 D Duration S 5 0 D DurCode S 1A D ReturnDate DS 8 D Year 4 D Month 2 D Day 2 * C *Entry PLIST C PARM InputDate C PARM Duration C PARM DurCode C PARM ReturnDate * C *ISO TEST(D) InputDate 99 * C IF *IN99 = *OFF C *ISO MOVE InputDate WorkDate * C SELECT C WHEN DurCode = 'D' C ADDDUR Duration:*D WorkDate C WHEN DurCode = 'M' C ADDDUR Duration:*M WorkDate C WHEN DurCode = 'Y' C ADDDUR Duration:*Y WorkDate C OTHER C ADDDUR Duration:*D WorkDate C ENDSL * C EXTRCT WorkDate:*Y Year C EXTRCT WorkDate:*M Month C EXTRCT WorkDate:*D Day * C ELSE * C MOVE *ALL'9' ReturnDate C ENDIF * C EVAL *INLR = *ON 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: