|
Check out the manual as suggested, however here is an example:
Adds a number of days to a date. Used primarily to support 8 digit dates.
Accepts: An 8 digit numeric representing a date in *ISO format, or,
YYYYMMDD.
A 5 digit numeric representing the number of days to add to the
date. This number may be negative.
Returns: A 8 digit numeric representing a date in *ISO format, or,
YYYYMMDD. A date of all 9's indicates that the date you passed in was not a
valid date.
Sample:
...
D* Line 1 with PR indicates a procedure PRototype. The fact that it has the
definition 8S 0 indicates that this
D* subprocedure will return a value. And the format is 8S 0.
D* The next two lines have no PR, S, C or anything defining field type.
Therefore they are part of the prototype
D* above. These are the input parameters. CONST means that we will not let
the subprocedure change the value
D* of these variables. Also we don't have to match variable size exactly.
D AddDays PR 8S 0
D FromDate CONST Like(AddDays)
D Spread 5S 0 CONST
D Date1 S 8S 0 inz(19990101)
D Date2 S 8S 0 inz(19990231)
D Result S 8S 0 inz(0)
D Spread S 5S 0
...
C* Main body
...
C Eval Spread = 5
C* In the following Result will equal 19990106
C Eval Result = AddDays(Date1:Spread)
C* In the following Result will equal 99999999
C Eval Result = AddDays(Date2:Spread)
...
C* Bottom of your program
...
* Yes you put the P specs at the bottom. And it may be a little confusing to
see D specs down here also.
* Stick with us.
* The first P spec indicates the Beginning of the subprocedure.
/eject
P AddDays B
***** AddDays - Adds a number of days to a YYYYMMDD date. A date of
* - all 9's indicates an invalid date was passed in.
* - Input: 8 digit date in *ISO format
* 5 digit number of days to add.
* - Result: 8 digit date in *ISO format
* The PI should match the PRototype you defined earlier. Why you have to do
this twice becomes more evident
* when you start doing external subprocedures in service programs and the
like.
D AddDays PI 8S 0
D Digit8Date 8S 0 CONST
D Spread 5S 0 CONST
* Now we have local variables! These are defined here only. Outside of this
subprocedure, back in the
* main body they have no value. You could have multiple subprocedures, each
defining X. And X could be
* alpha in one, numeric in another ...
D WorkDate S D Datfmt(*ISO)
D EightDigits S 8S 0
* I hope you don't find the jumping from one spec to another as confusing as
WSU.
* Just remember that this subprocedure is much like having your own called
program within a program.
C *iso Test(D E) Digit8Date
C If not %Error
C *iso Move Digit8Date WorkDate
C AddDur Spread:*D WorkDate
C *iso Move WorkDate EightDigits
C Return EightDigits
*
C Else
C Return *All'9'
C EndIf
* The final P spec indicates the End of this subprocedure.
P AddDays E
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.