Skip to content

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:

  1. Initialization:
  2. 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 on Date1 and Diff. 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.
  3. Set Error Flag: Initializes Err to 'Y' (assume error until validation succeeds).
  4. Define Work Fields:

    • FromDate (date field): Temporary date field for Date1.
    • 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.
  5. Validate Input Format:

  6. Check DifFmt: Verifies that DifFmt is 'D', 'M', or 'Y'. If not, the program exits with Err = 'Y' (no further processing).

  7. Validate Input Date:

  8. Copy Date1: Moves Date1 to Date1T for validation.
  9. Test Date: Uses the TEST(D) operation with *ISO format to validate Date1T as a valid date (YYYYMMDD). Sets *IN99 to *ON if invalid.
  10. Handle Invalid Date: If *IN99 is *ON (invalid date), the program exits with Err = 'Y'.

  11. Perform Date Calculation:

  12. Set FromDate: If Date1T is valid, moves Date1T to FromDate (date field) and sets Err = 'N'.
  13. Select Operation Based on DifFmt:
    • Days (DifFmt = 'D'):
    • If Diff >= 0, adds Diff days to FromDate using ADDDUR DiffT:*days ToDate.
    • If Diff < 0, subtracts |Diff| days using SUBDUR DiffT:*days ToDate.
    • Months (DifFmt = 'M'):
    • If Diff >= 0, adds Diff months using ADDDUR DiffT:*months ToDate.
    • If Diff < 0, subtracts |Diff| months using SUBDUR DiffT:*months ToDate.
    • Years (DifFmt = 'Y'):
    • If Diff >= 0, adds Diff years using ADDDUR DiffT:*years ToDate.
    • If Diff < 0, subtracts |Diff| years using SUBDUR DiffT:*years ToDate.
  14. Convert Result: Moves ToDate to Date2T (8.0, YYYYMMDD format) and sets Date2 = Date2T.

  15. Program Termination:

  16. Sets *INLR = *ON to indicate last record processing.
  17. Returns to the calling program (BB943, BB943V, or BB9433) with:
    • Date2: The calculated date.
    • Err: 'N' if successful, 'Y' if DifFmt is invalid or Date1 is not a valid date.

Business Rules

The program enforces the following business rules for date calculations:

  1. Input Validation:
  2. DifFmt must be 'D' (days), 'M' (months), or 'Y' (years). Any other value results in Err = 'Y' and no calculation.
  3. Date1 must be a valid date in YYYYMMDD format. Invalid dates result in Err = 'Y' and no calculation.

  4. Duration Handling:

  5. If Diff is positive or zero, the duration is added to Date1 to compute Date2.
  6. If Diff is negative, the absolute value of the duration is subtracted from Date1 to compute Date2.

  7. Output:

  8. Date2 is overwritten with the calculated date in YYYYMMDD format.
  9. Err is set to 'N' only if both DifFmt and Date1 are valid and the calculation succeeds.

  10. Context in Sales Agreement System:

  11. Used by BB943, BB943V, and BB9433 to calculate date differences or adjust start/end dates (e.g., setting expiration dates one minute earlier than a new record’s start date, per mg12 in BB943).
  12. Typically called with DifFmt = 'D' for day-based calculations, as seen in BB943’s pldtclc1 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, and Err, setting Err = 'Y'.
  • Validate DifFmt as 'D', 'M', or 'Y'.
  • Validate Date1 as a valid YYYYMMDD date using TEST(D).
  • If valid, perform date addition/subtraction based on DifFmt and Diff, storing the result in Date2.
  • Return Date2 and Err ('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, otherwise Err = '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!