Skip to content

BB713 RPG36

The provided BB713.rpg36.txt is an RPG program (for IBM System/36 or AS/400) called by the BB715.ocl36.txt OCL program as part of the preprocessing for the "Daily Requirements Report." It processes multi-load and non-multi-load orders to create an intermediate file (BB713M) for further processing. Below, I’ll explain the process steps, business rules, tables (files) used, and external programs called.

Process Steps of the RPG Program

The BB713 RPG program reads order data from BBORDR and BBORDR2, processes multi-load orders (with or without a request date) and non-multi-load orders, and writes output to BB713M. Here’s a step-by-step breakdown:

  1. Program Initialization:
  2. Header (H-spec): Line 0002 defines the program name (BB713) and page length (P064).
  3. File Definitions (F-spec):
    • BBORDR (input, primary file, 512 bytes, indexed with 11 keys, disk, Line 0006).
    • BBORDR2 (input, full procedural, 512 bytes, indexed with 11 keys, disk, Line 0007).
    • BB713M (output, 530 bytes, disk, Line 0008).
  4. Input Definitions (I-spec):
    • BBORDR (primary file, Lines 0009–0019):
    • BDKEY (2–12): Key field for chaining.
    • BORDNO (4–9): Order number.
    • BORQDT (22–27): Request date.
    • BOMULO (284): Multi-load indicator ('Y' or 'N').
    • BOTOLO (285–287): Total loads.
    • BOLODA (288–290): Loads per day.
    • BOLOVO (291–297): Load volume.
    • BOWEPU (298): Weekend pickup ('Y' or 'N').
    • BORQD8 (299–306): Request date in CYMD format.
    • BBORDR2 (Lines 0021–0024):
    • DFLDS1 (1–256), DFLDS2 (257–512): Generic data fields.
    • BDDEL (1): Delete flag ('D' for deleted).
    • BDCO (2–3): Company number.
    • BDORD# (4–9): Order number.
    • BDSEQ (10–12): Detail line sequence.
    • BDQTY (35–41): Order container quantity.
  5. Data Structures:
    • DS (Lines 0033–0036): Defines $CYMD (1–8), $CN (1–2, century), $YMD (3–8, year/month/day).
    • UDS (Lines 0038–0040): Defines Y2KCEN (509–510, century) and Y2KCMP (511–512, comparison year for Y2K).
  6. Indicators 01, 02, 03, 04, and 05 control input processing; 97 indicates end-of-file; 99 indicates chain failure.

  7. Multi-Load Order with Request Date (Lines 0044–0102):

  8. Condition: Indicator 01 is on, BOMULO = 'Y', and BORQDT ≠ 0 (Lines 0044–0046).
  9. Steps:

    • Chains BBORDR2 with BDKEY = '001' to ensure a detail line exists (Lines 0047–0048).
    • If found (N99, Line 0050):
    • Sets LODDT8 to BORQD8 (request date, Line 0051).
    • Sets LODA to BOLODA (loads per day, Line 0052) and LOVO to BOLOVO (load volume, Line 0053).
    • Calculates remaining days (REMDYS = BOTOLO / LODA, Lines 0054–0058), adding 1 if there’s a remainder (REMWRK ≠ 0).
    • Sets REMLO to BOTOLO (total loads, Line 0059).
    • Calculates shipped loads (SHLO = (BOTOLO * BOLOVO - BDQTY) / BOLOVO) and volume (SKLOVO = SHLO * BOLOVO, Lines 0061–0065).
    • Calls GETLOD to write the first day’s load (Line 0067).
    • If REMDYS > 0 (Line 0069), loops to process remaining days (Lines 0070–0097):
      • Converts LODDT8 to $CYMD and $MDY (Lines 0072–0073).
      • Calls @GTOJ to get Julian date (G$JD) and day of week (G$JW, Line 0074).
      • Adjusts G$JD to skip weekends if BOWEPU ≠ 'Y' (Lines 0075–0091):
      • Friday (G$JW = 2): Adds 3 days (to Monday).
      • Saturday (G$JW = 3): Adds 2 days (to Monday).
      • Sunday (G$JW = 4): Adds 1 day (to Monday).
      • Other days: Adds 1 day.
      • Calls @JTOG to convert back to Gregorian ($MDY, $CYMD, Line 0092).
      • Updates LODDT8 (Line 0094) and calls GETLOD (Line 0096).
    • Ends loop when REMDYS = 0 (Line 0097).
  10. Multi-Load Order without Request Date (Lines 0104–0111):

  11. Condition: Indicator 01 is on, BOMULO = 'Y', and BORQDT = 0 (Lines 0104–0106).
  12. Steps:

    • Chains BBORDR2 with BDKEY = '001' (Lines 0107–0108).
    • If found (N99), writes a detail record to BB713M using exception output REGDTL (Line 0109), copying DFLDS1, DFLDS2, and BORQD8 (Lines 0297–0300).
  13. Non-Multi-Load Order (Lines 0113–0129):

  14. Condition: Indicator 01 is on, BOMULO ≠ 'Y' (Lines 0113–0114).
  15. Steps:

    • Sets ORDNO to BORDNO (Line 0115).
    • Sets BDKEY = '001' and positions BBORDR2 with SETLL (Lines 0116–0117).
    • Loops through BBORDR2 records (Lines 0118–0129):
    • Resets indicators 97, 03, 04, and 05 (Lines 0119–0120).
    • Reads BBORDR2 (Line 0121).
    • If end-of-file (97) or indicators 04/05 are on, jumps to ENDIT (Lines 0122–0124).
    • If ORDNO = BDORD#, writes a detail record to BB713M using REGDTL (Line 0126) and continues reading (AGN, Line 0127).
  16. GETLOD Subroutine (Lines 0136–0165):

  17. Handles daily load calculations and writes to BB713M:

    • If LODA > REMLO, sets LODA = REMLO (Lines 0141–0143, for the last day’s uneven loads).
    • Calculates day’s load volume (LOVO = LODA * BOLOVO, Line 0146).
    • If SKLO > 0 (shipped loads exist, Lines 0148–0158):
    • If LODA < SKLO, zeros LOVO and adjusts SKLO and SKLOVO.
    • Else, subtracts SKLOVO from LOVO and SKLO from itself.
    • Updates REMLO (subtracts LODA) and REMDYS (subtracts 1, Lines 0160–0161).
    • Writes a record to BB713M using exception output LODDTL (Line 0163), including DFLDS1, DFLDS2, LOVO, and LODDT8 (Lines 0291–0295).
  18. @GTOJ Subroutine (Lines 0170–0234):

  19. Converts Gregorian date ($MDY, $CN) to Julian date (G$JD) and day of week (G$JW):

    • Breaks down $MDY into $YR, $MONTH, $DAY (Lines 0182–0184).
    • Calculates century ($CN) using Y2KCEN and Y2KCMP (Lines 0187–0193).
    • Converts month to Julian days (G$JD = (MONTH - 3) * 30.6 + DAY, Lines 0203–0215).
    • Adds year days ((YEAR - 1900) * 365.25, Lines 0218–0227).
    • Determines day of week (G$JW = G$JD % 7, Lines 0231–0232).
  20. @JTOG Subroutine (Lines 0238–0288):

  21. Converts Julian date (G$JD) to Gregorian ($MDY, $CN):

    • Calculates year (G$YYWK = G$JD / 365.25, Lines 0248–0253).
    • Computes remaining days (G$YD, Lines 0255–0260).
    • Derives month (G$M) and day (G$D) using iterative calculations (Lines 0263–0275).
    • Combines into $MDY (MMDDYY) and $CN (century, Lines 0277–0286).
  22. Output to BB713M:

  23. Two exception outputs:
    • LODDTL (Lines 0291–0295): For multi-load orders with calculated dates, writes DFLDS1, DFLDS2, LOVO (load volume), LODDT8 (date).
    • REGDTL (Lines 0297–0300): For non-multi-load or dateless multi-load orders, writes DFLDS1, DFLDS2, BORQD8 (request date).

Business Rules

  1. Multi-Load Orders with Request Date:
  2. Must have BOMULO = 'Y' and a non-zero BORQDT.
  3. Requires a detail line with BDKEY = '001' in BBORDR2.
  4. Calculates loads per day (LODA = BOLODA), total volume (TOVO = BOTOLO * BOLOVO), and shipped loads (SHLO = (TOVO - BDQTY) / BOLOVO).
  5. Distributes loads across days (REMDYS = BOTOLO / LODA, rounded up if remainder exists).
  6. Skips weekends unless BOWEPU = 'Y' (weekend pickup allowed), advancing to the next valid day (e.g., Friday to Monday).
  7. Writes one record per day to BB713M with calculated volume (LOVO) and date (LODDT8).

  8. Multi-Load Orders without Request Date:

  9. Must have BOMULO = 'Y' and BORQDT = 0.
  10. Requires a detail line with BDKEY = '001'.
  11. Writes a single record to BB713M with the original request date (BORQD8).

  12. Non-Multi-Load Orders:

  13. Must have BOMULO ≠ 'Y'.
  14. Processes all detail lines in BBORDR2 matching the order number (BDORD# = BORDNO).
  15. Writes each matching detail line to BB713M with BORQD8.

  16. Date Handling:

  17. Uses Y2K-compliant century calculation (Y2KCEN, Y2KCMP) for date conversions.
  18. Converts between Gregorian ($MDY) and Julian (G$JD) formats to handle date arithmetic and day-of-week checks.

  19. Load Skipping:

  20. Accounts for already shipped loads (SKLO) and volume (SKLOVO), reducing the day’s load volume (LOVO) if applicable.

Tables (Files) Used

  • Input Files:
  • BBORDR: Primary input file containing order headers (512 bytes, indexed with 11 keys).
    • Fields: BDKEY (2–12), BORDNO (4–9), BORQDT (22–27), BOMULO (284), BOTOLO (285–287), BOLODA (288–290), BOLOVO (291–297), BOWEPU (298), BORQD8 (299–306).
  • BBORDR2: Detail input file (512 bytes, indexed with 11 keys).

    • Fields: DFLDS1 (1–256), DFLDS2 (257–512), BDDEL (1), BDCO (2–3), BDORD# (4–9), BDSEQ (10–12), BDQTY (35–41).
  • Output File:

  • BB713M: Output file (530 bytes) containing processed order data.

    • LODDTL records: DFLDS1 (1–256), DFLDS2 (257–512), LOVO (513–519, load volume), LODDT8 (520–527, date).
    • REGDTL records: DFLDS1 (1–256), DFLDS2 (257–512), BORQD8 (520–527, request date).
  • Internal Data Structures:

  • DS: $CYMD (1–8), $CN (1–2), $YMD (3–8) for date handling.
  • UDS: Y2KCEN (509–510), Y2KCMP (511–512) for Y2K date logic.

External Programs Called

  • None: The BB713 program does not explicitly call other programs. It performs all processing internally, using subroutines (GETLOD, @GTOJ, @JTOG) and file I/O.

Notes

  • Integration with OCL: The BB715.ocl36.txt calls BB713 to preprocess order data, creating BB713M for subsequent programs (BB714, BB714A, #GSORT, BB715).
  • Multi-Load Logic: The program splits multi-load orders into daily records, respecting weekend restrictions unless explicitly allowed (BOWEPU = 'Y').
  • Error Handling: Uses indicator 99 to check for missing detail lines and indicator 97 for end-of-file. No explicit error messages are output, as this is a preprocessing step.
  • Y2K Compliance: The @GTOJ and @JTOG subroutines handle century calculations to ensure correct date processing.

Summary

The BB713 RPG program preprocesses order data for the Daily Requirements Report, handling: - Multi-load orders with request dates by calculating daily loads, skipping weekends if needed, and writing daily records. - Multi-load orders without request dates by writing a single record. - Non-multi-load orders by copying all matching detail lines. It uses BBORDR and BBORDR2 as inputs, writes to BB713M, and follows rules for load distribution, date validation, and weekend handling. No external programs are called.

Files Used: BBORDR, BBORDR2, BB713M. External Programs: None.

If you need further details (e.g., field formats, subsequent programs like BB714), or additional files, let me know!