GSDTCLC1 RPGLE
The provided document is an RPGLE program named GSDTCLC1
, referenced by the BB943
, BB943V
, and BB9433
programs in the IBM System/36 (or AS/400 compatibility mode) environment, as part of the OCL procedure BB943INQ.ocl36.txt
. This program, titled "Date Add/Subtract Duration Calculations," is a utility program designed to perform date arithmetic by adding or subtracting a specified duration (in days, months, or years) from a given date. Below, I’ll explain the process steps, business rules, tables used, and external programs called, based on the provided RPGLE source code and its context within the customer sales agreement maintenance system.
Process Steps of the RPGLE Program¶
The GSDTCLC1
program is a simple utility that takes an input date (Date1
), a duration (Diff
), and a format (DifFmt
) to compute a resulting date (Date2
) by adding or subtracting the duration. It validates inputs and returns an error flag if the operation fails. Here’s a detailed breakdown of the process steps:
- Initialization:
- Receive Parameters: The program accepts five parameters via the
*ENTRY
plist:Date1
(8.0, YYYYMMDD): The input date to perform calculations on.Date2
(8.0, YYYYMMDD): The output date, calculated based onDate1
andDiff
. If input as non-zero, it’s ignored; the program overwrites it with the result.DifFmt
(1 character): The duration format,'D'
(days),'M'
(months), or'Y'
(years).Diff
(8.0): The duration to add (positive) or subtract (negative).Err
(1 character): Error flag, set to'Y'
(error) or'N'
(no error) on return.
- Set Error Flag: Initializes
Err
to'Y'
(assume error until validation succeeds). -
Define Work Fields:
FromDate
(date field): Temporary date field forDate1
.ToDate
(date field): Temporary date field for the result.Date1T
,Date2T
(8.0): Temporary fields for date validation and conversion.DiffT
(8.0): Temporary field for the absolute duration value.
-
Validate Input Format:
-
Check
DifFmt
: Verifies thatDifFmt
is'D'
,'M'
, or'Y'
. If not, the program exits withErr = 'Y'
(no further processing). -
Validate Input Date:
- Copy
Date1
: MovesDate1
toDate1T
for validation. - Test Date: Uses the
TEST(D)
operation with*ISO
format to validateDate1T
as a valid date (YYYYMMDD). Sets*IN99
to*ON
if invalid. -
Handle Invalid Date: If
*IN99
is*ON
(invalid date), the program exits withErr = 'Y'
. -
Perform Date Calculation:
- Set
FromDate
: IfDate1T
is valid, movesDate1T
toFromDate
(date field) and setsErr = 'N'
. - Select Operation Based on
DifFmt
:- Days (
DifFmt = 'D'
): - If
Diff >= 0
, addsDiff
days toFromDate
usingADDDUR DiffT:*days ToDate
. - If
Diff < 0
, subtracts|Diff|
days usingSUBDUR DiffT:*days ToDate
. - Months (
DifFmt = 'M'
): - If
Diff >= 0
, addsDiff
months usingADDDUR DiffT:*months ToDate
. - If
Diff < 0
, subtracts|Diff|
months usingSUBDUR DiffT:*months ToDate
. - Years (
DifFmt = 'Y'
): - If
Diff >= 0
, addsDiff
years usingADDDUR DiffT:*years ToDate
. - If
Diff < 0
, subtracts|Diff|
years usingSUBDUR DiffT:*years ToDate
.
- Days (
-
Convert Result: Moves
ToDate
toDate2T
(8.0, YYYYMMDD format) and setsDate2 = Date2T
. -
Program Termination:
- Sets
*INLR = *ON
to indicate last record processing. - Returns to the calling program (
BB943
,BB943V
, orBB9433
) with:Date2
: The calculated date.Err
:'N'
if successful,'Y'
ifDifFmt
is invalid orDate1
is not a valid date.
Business Rules¶
The program enforces the following business rules for date calculations:
- Input Validation:
DifFmt
must be'D'
(days),'M'
(months), or'Y'
(years). Any other value results inErr = 'Y'
and no calculation.-
Date1
must be a valid date in YYYYMMDD format. Invalid dates result inErr = 'Y'
and no calculation. -
Duration Handling:
- If
Diff
is positive or zero, the duration is added toDate1
to computeDate2
. -
If
Diff
is negative, the absolute value of the duration is subtracted fromDate1
to computeDate2
. -
Output:
Date2
is overwritten with the calculated date in YYYYMMDD format.-
Err
is set to'N'
only if bothDifFmt
andDate1
are valid and the calculation succeeds. -
Context in Sales Agreement System:
- Used by
BB943
,BB943V
, andBB9433
to calculate date differences or adjust start/end dates (e.g., setting expiration dates one minute earlier than a new record’s start date, permg12
inBB943
). - Typically called with
DifFmt = 'D'
for day-based calculations, as seen inBB943
’spldtclc1
PLIST.
Tables Used¶
The program does not use any database files or tables. It is a pure computational utility that operates on input parameters and returns results without accessing external data.
External Programs Called¶
The program does not explicitly call any external programs. It relies solely on RPGLE’s built-in date operations (TEST(D)
, ADDDUR
, SUBDUR
) to perform calculations.
Summary¶
- Process Steps:
- Initialize by receiving
Date1
,Date2
,DifFmt
,Diff
, andErr
, settingErr = 'Y'
. - Validate
DifFmt
as'D'
,'M'
, or'Y'
. - Validate
Date1
as a valid YYYYMMDD date usingTEST(D)
. - If valid, perform date addition/subtraction based on
DifFmt
andDiff
, storing the result inDate2
. -
Return
Date2
andErr
('N'
for success,'Y'
for failure). -
Business Rules:
- Validates
DifFmt
as'D'
,'M'
, or'Y'
. - Ensures
Date1
is a valid YYYYMMDD date. - Adds or subtracts
Diff
based on its sign (positive = add, negative = subtract). -
Returns
Err = 'N'
only on successful calculation, otherwiseErr = 'Y'
. -
Tables Used:
-
None.
-
External Programs Called:
- None.
The GSDTCLC1
program is a straightforward utility fully contained within the provided source code (no truncation issues). It integrates with the customer sales agreement maintenance system (BB943
, BB943V
, BB9433
) to handle date calculations, such as validating or adjusting start/end dates for agreements. If you need further analysis of its integration with these programs or have additional related files (e.g., BB943
full source), let me know how you’d like to proceed!