Skip to content

BB9433 RPGLE

The RPG program BB9433.rpgle is an IBM i (AS/400) program designed for copying or updating customer sales agreement records in the bicuag file. It is called from the main OCL program (likely via BB943P) to handle the copying of sales agreement records to new locations, ship-tos, or customer ship-tos, as well as updating existing records with new details. The program supports expiration logic and history logging. Below, I will explain the process steps, business rules, tables used, and external programs called based on the provided RPG source code.


Process Steps of the RPG Program

The BB9433 program processes input parameters to copy or update sales agreement records, handling multiple locations, ship-tos, or customer ship-tos, and ensures proper expiration and history logging. The key process steps are:

  1. Initialization (*inzsr Subroutine):
  2. Parameters: Receives three parameters:
    • parmlist: A data structure containing fields such as company (p$cono), customer (p$cust), location (p$loc), container (p$cntr), unit of measure (p$unms), ship-to (p$ship), product codes (p$pr01p$pr10), purchase order (p$pord), price (p$prce), off-price (p$offp), freight code (p$frcd), delivery (p$delv), prepaid (p$ppd), primary flag (p$prim), min/max quantities (p$mnqy, p$mxqy), arrays for other locations (p$locs), ship-tos (p$shp), customer ship-tos (p$cshp), sequence number (p$seqn), start/end dates and times (p$std8, p$sttm, p$end8, p$entm), add/update flag (p$addupd), date flag (p$dateflag), and original key fields for expiration (o@cono, o@cust, etc.).
    • p$fgrp: File group ('G' or 'Z') to determine database file overrides.
    • p$flag: Return flag to indicate the action taken.
  3. Field Setup: Initializes work fields (w$loc, w$cust, w$ship), arrays for locations (loc), ship-tos (shp), and customer ship-tos (cshp) from p$locs, p$shp, and p$cshp. Sets current date/time (t#time, t#cymd) for validation and history logging.
  4. Data Structures: Defines wkcuag (external data structure for bicuag) and svcuag (256-byte structure to store bicuag record data).

  5. Open Database Tables (opntbl Subroutine):

  6. Applies file overrides (ovg or ovz) based on p$fgrp using the QCMDEXC API, mapping files to appropriate libraries (e.g., gbicuag or zbicuag).
  7. Opens files (bicont, bicuag, bicua3, bicuagh) with USROPN for validation, update, and history logging.

  8. Main Processing (main Subroutine, Implicit):

  9. Check for Arrays: Checks if data exists in location (*in60), ship-to (*in61), or customer ship-to (*in62) arrays to determine if copying to multiple locations/ship-tos is required.
  10. Process Original Record:
    • Chains to bicuag using klcuag (p$cono, p$seqn) to retrieve the original record if it exists.
    • If p$expr = 'Y' (expire original record), checks expiration logic (jk04):
    • Expires the original record only if its end date (baend8) is greater than the new record’s start date (p$std8) or zero.
    • Updates the original record’s end date/time to one minute before the new record’s start date/time (per mg12 in BB943 context).
    • Writes the expired record to bicuagh using writehist.
    • Copies the original record to wkcuag for modification.
  11. Copy to Other Locations/Ship-Tos:
    • Iterates through the loc, shp, or cshp arrays if populated (*in60, *in61, *in62).
    • For each valid entry:
    • Updates wkcuag with new location (baloc), ship-to (baship), or customer/ship-to (bacust, baship).
    • Generates a new sequence number (w$sq) for the copied record.
    • Checks for duplicates in bicua3 using klcua3 to avoid conflicts.
    • Writes the new record to bicuag using writecuag.
    • Writes a history record to bicuagh using writehist.
  12. Single Record Update:

    • If no arrays are populated, updates or adds a single record using writecuag.
    • Validates against bicont for company and ensures no duplicate records exist in bicua3.
  13. Write Sales Agreement (writecuag Subroutine):

  14. Populates wkcuag fields with input parameters (e.g., bacono = p$cono, bacust = p$cust, bapr01 = p$pr01, etc.).
  15. Sets additional fields like creation date (bacrdt), creation time (bacrtm), last update date (baludt), last update time (balutm), and contract number (bacntn, per jk04).
  16. Writes or updates the record in bicuag.

  17. Write History (writehist Subroutine):

  18. Clears the bicuaghpf record format.
  19. Copies fields from wkcuag to the history record (hhcono, hhcust, hhloc, etc.).
  20. Sets history fields:
    • hhdel = badel (deletion status, per jk02).
    • hhuser = jbuser8 (user ID, 8 characters).
    • hhchd8 = t#cymd (change date, CCYYMMDD).
    • hhchtm = t#hms (change time, HHMMSS).
  21. Writes the record to bicuagh.

  22. Program Termination:

  23. Closes all files (close *all).
  24. Sets *inlr = *on and returns, passing back p$flag to indicate success or failure.

Business Rules

The program enforces the following business rules for copying or updating customer sales agreement records:

  1. Copy to Multiple Locations/Ship-Tos:
  2. Supports copying a sales agreement to multiple locations (p$locs), ship-tos (p$shp), or customer ship-tos (p$cshp) using arrays, indicated by *in60, *in61, and *in62.
  3. Each copied record gets a new sequence number (w$sq) to avoid conflicts.
  4. Duplicate records are prevented by checking bicua3 with klcua3 (key fields: company, customer, location, container, unit of measure, ship-to, product codes, PO, min/max quantities, start date/time, freight code).

  5. Expiration Logic (jk04):

  6. If p$expr = 'Y', the original record is expired only if its end date (baend8) is greater than the new record’s start date (p$std8) or zero.
  7. The expired record’s end date/time is set to one minute before the new record’s start date/time (aligned with mg12 in BB943).
  8. Expired records are written to bicuagh.

  9. Freight Code Differentiation (mg12):

  10. Allows multiple records with identical start dates if their freight codes (p$frcd) differ, ensuring flexibility in agreement management.

  11. Field Validation:

  12. Company (p$cono) must exist in bicont.
  13. Price (p$prce) and off-price (p$offp) use expanded 9.4 packed format (jk05).
  14. Min/max quantities (p$mnqy, p$mxqy) are supported (jk03).
  15. Contract number (p$cntn) is included in the input parameters and written to bicuag (jk04).

  16. History Logging:

  17. Every add, update, or expiration action writes a record to bicuagh with the user ID, change date/time, and deletion status (hhdel, per jk02).

  18. File Group Overrides:

  19. Uses p$fgrp ('G' or 'Z') to apply appropriate file overrides, ensuring access to the correct dataset (e.g., gbicuag or zbicuag).

Tables Used

The program uses the following database files, with overrides applied based on p$fgrp ('G' or 'Z'):

  1. bicont: Company master file (update/input, validates company number).
  2. bicuag: Sales agreement file (update/add, primary file for storing agreements).
  3. bicua3: Sales agreement logical file (update/input, checks for duplicates, includes min/max quantities, per jk03).
  4. bicuagh: Sales agreement history file (output, logs changes, per jk02).

Overrides map these files to specific libraries (e.g., gbicont or zbicont).


External Programs Called

The program calls the following external program:

  1. QCMDEXC: System API to execute file override commands for the specified file group ('G' or 'Z').
  2. GSDTCLC1: Called via the pldtclc1 parameter list to calculate date differences for expiration logic (e.g., checking start vs. end dates).

No other user-defined programs are explicitly called in the provided source code.


Summary

  • Process Steps: Initializes parameters and arrays, applies file overrides, opens database files, retrieves the original sales agreement record, expires it if required, copies or updates records for multiple locations/ship-tos or a single record, writes to bicuag, logs to bicuagh, and handles date calculations.
  • Business Rules: Supports copying to multiple locations/ship-tos, expires original records based on date logic, allows same start dates with different freight codes, validates company and duplicate records, logs all changes to history, and uses expanded price fields.
  • Tables Used: bicont, bicuag, bicua3, bicuagh.
  • External Programs Called: QCMDEXC, GSDTCLC1.

If you need further analysis of specific subroutines, file structures, or integration with BB943P, BB943, or BB944, please provide additional details or source code. Alternatively, I can perform a DeepSearch for related information if enabled. Let me know how to proceed!