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
*ENTRYplist:Date1(8.0, YYYYMMDD): The input date to perform calculations on.Date2(8.0, YYYYMMDD): The output date, calculated based onDate1andDiff. 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
Errto'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 thatDifFmtis'D','M', or'Y'. If not, the program exits withErr = 'Y'(no further processing). -
Validate Input Date:
- Copy
Date1: MovesDate1toDate1Tfor validation. - Test Date: Uses the
TEST(D)operation with*ISOformat to validateDate1Tas a valid date (YYYYMMDD). Sets*IN99to*ONif invalid. -
Handle Invalid Date: If
*IN99is*ON(invalid date), the program exits withErr = 'Y'. -
Perform Date Calculation:
- Set
FromDate: IfDate1Tis valid, movesDate1TtoFromDate(date field) and setsErr = 'N'. - Select Operation Based on
DifFmt:- Days (
DifFmt = 'D'): - If
Diff >= 0, addsDiffdays toFromDateusingADDDUR DiffT:*days ToDate. - If
Diff < 0, subtracts|Diff|days usingSUBDUR DiffT:*days ToDate. - Months (
DifFmt = 'M'): - If
Diff >= 0, addsDiffmonths usingADDDUR DiffT:*months ToDate. - If
Diff < 0, subtracts|Diff|months usingSUBDUR DiffT:*months ToDate. - Years (
DifFmt = 'Y'): - If
Diff >= 0, addsDiffyears usingADDDUR DiffT:*years ToDate. - If
Diff < 0, subtracts|Diff|years usingSUBDUR DiffT:*years ToDate.
- Days (
-
Convert Result: Moves
ToDatetoDate2T(8.0, YYYYMMDD format) and setsDate2 = Date2T. -
Program Termination:
- Sets
*INLR = *ONto indicate last record processing. - Returns to the calling program (
BB943,BB943V, orBB9433) with:Date2: The calculated date.Err:'N'if successful,'Y'ifDifFmtis invalid orDate1is not a valid date.
Business Rules¶
The program enforces the following business rules for date calculations:
- Input Validation:
DifFmtmust be'D'(days),'M'(months), or'Y'(years). Any other value results inErr = 'Y'and no calculation.-
Date1must be a valid date in YYYYMMDD format. Invalid dates result inErr = 'Y'and no calculation. -
Duration Handling:
- If
Diffis positive or zero, the duration is added toDate1to computeDate2. -
If
Diffis negative, the absolute value of the duration is subtracted fromDate1to computeDate2. -
Output:
Date2is overwritten with the calculated date in YYYYMMDD format.-
Erris set to'N'only if bothDifFmtandDate1are valid and the calculation succeeds. -
Context in Sales Agreement System:
- Used by
BB943,BB943V, andBB9433to calculate date differences or adjust start/end dates (e.g., setting expiration dates one minute earlier than a new record’s start date, permg12inBB943). - Typically called with
DifFmt = 'D'for day-based calculations, as seen inBB943’spldtclc1PLIST.
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
DifFmtas'D','M', or'Y'. - Validate
Date1as a valid YYYYMMDD date usingTEST(D). - If valid, perform date addition/subtraction based on
DifFmtandDiff, storing the result inDate2. -
Return
Date2andErr('N'for success,'Y'for failure). -
Business Rules:
- Validates
DifFmtas'D','M', or'Y'. - Ensures
Date1is a valid YYYYMMDD date. - Adds or subtracts
Diffbased 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!