Skip to content

BB943 RPGLE

The RPG program BB943.rpgle is an IBM i (AS/400) program designed for "Customer Sales Agreement Maintenance," providing an interactive interface to add, update, or inquire about customer sales agreement records. It is called from the main OCL program (via BB943P) and supports maintenance ('MNT') and inquiry ('INQ') modes. 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 BB943 program follows a structured flow for managing customer sales agreements using a display file (bb943d) with subfiles for user interaction. The process steps are as follows:

  1. Initialization (*inzsr Subroutine):
  2. Parameters: Receives input parameters:
    • p$cono: Company number.
    • p$stat: Status code (3 characters).
    • p$validpw: Valid password flag (1 character, 'Y' or blank).
    • p$sqky: Sequence number for the record.
    • p$frsq: Sequence number for copying a record.
    • c1f6flag: Flag for F6 defaults (carrier, billed, or all values).
    • c1cust, c1loc, c1cntr, c1prcd, c1prim, c1ship: Fields from BB943P for pre-populating the screen.
    • p$mode: Run mode ('MNT' or 'INQ').
    • p$fgrp: File group ('G' or 'Z') for database overrides.
    • p$flag: Return flag.
    • p$dspmsg: Message flag.
  3. Special Case: If the user is 'KRAJTEST', sets p$validpw = 'Y' for testing purposes.
  4. Field Setup: Initializes display file fields (f$sq, s1stat), current date/time (t#time, t#cymd), and work fields (e.g., l$cntr, w$cnty). Clears subfile fields (s1cono, s1cust, etc.) and sets message handling fields.
  5. File Overrides: Prepares file overrides (ovg or ovz) based on p$fgrp.

  6. Open Database Tables (opntbl Subroutine):

  7. Executes the QCMDEXC API to apply file overrides for the specified file group ('G' or 'Z'), mapping files like arcust to garcust or zarcust.
  8. Opens input files (arcust, bicont, gscntr1, gsprod, apvend, gstabl, inloc, shipto, trrtcd, arcupr, arcomm, bicua3) and output file (bicuagh) with USROPN.
  9. Opens bicuag for add/update operations.
  10. Clears the message subfile (clrmsg).

  11. Main Processing Loop:

  12. Mode Setup: Sets protection indicators based on p$mode:
    • In 'INQ' mode, *in70 = *on (protects all fields).
    • In 'MNT' mode, *in71 = *on (protects key fields for updates), and *in72 depends on p$validpw (protects values if no password).
  13. Display Screen: Displays the control record (msgctl) and message subfile (wrtmsg) if dspmsg = *on.
  14. User Input: Uses EXFMT to display the format (fmt1) and process user input via function keys:

    • F03 (Exit): Exits the program.
    • F04 (Prompt): Calls prompt to assist with field entry (e.g., customer, ship-to).
    • F05 (Refresh): Resets fields and redisplays.
    • F06 (Defaults): Toggles default values (carrier, billed, or all) based on c1f6flag.
    • ENTER: Validates input (validate) and processes the record (addfmt for add, updfmt for update).
  15. Validation (validate Subroutine):

  16. Calls BB9643V to validate fields in the p$vlist data structure (e.g., company, customer, location, container, product codes, dates, etc.).
  17. Checks for:
    • Duplicate product codes, locations, or ship-to entries.
    • Valid company (bicont), customer (arcust), location (inloc), ship-to (shipto), and product codes (gsprod).
    • Valid start/end dates and times (using GSDTEDIT and GSDTCLC1).
    • Minimum quantity (s1mnqy) not exceeding maximum quantity (s1mxqy).
    • Valid PO/Order code (s1poor, 'P' or 'O').
  18. Sets error messages (e.g., com(04) for duplicate product codes, com(06) for invalid dates).

  19. Add Record (addfmt Subroutine):

  20. Validates input fields and checks for existing records in bicuag using klcua3 keylist.
  21. If valid, writes a new record to bicuag with fields like s1cono, s1cust, s1loc, s1cntr, s1prod, etc.
  22. If s1expr = 'Y', expires the original record by updating its end date/time and writing to history (bicuagh).
  23. Writes commission data to arcomm if applicable (mg09).
  24. Sets success message (com(02) for record created).

  25. Update Record (updfmt Subroutine):

  26. Retrieves the existing record from bicuag using f$sqkey.
  27. Updates the record with new values if valid, preserving key fields (*in71).
  28. Handles expiration logic (jk04): Expires the original record only if the new expiration date is greater than the start date or zero.
  29. Writes to history (bicuagh) and commission (arcomm) as needed.
  30. Sets success message (com(03) for record changed).

  31. Message Handling:

  32. Add Message (addmsg): Sends messages to the program message queue using QMHSNDPM.
  33. Write Message (wrtmsg): Writes messages to the message subfile.
  34. Clear Message (clrmsg): Clears the message subfile using QMHRMVPM.

  35. Program Termination:

  36. Closes all files (close *all).
  37. Sets *inlr = *on and returns.

Business Rules

The program enforces the following business rules to ensure proper management of customer sales agreements:

  1. Mode-Based Access Control:
  2. In 'MNT' mode, users can add or update records, with key fields protected (*in71 = *on) during updates.
  3. In 'INQ' mode, all fields are protected (*in70 = *on), allowing only viewing.
  4. If no valid password (p$validpw not 'Y'), values are protected (*in72 = *on).

  5. Field Validation:

  6. Company and Customer: Must exist in bicont and arcust (com(01), com(02) for invalid entries).
  7. Product Codes: At least one valid product code must be entered (com(05)), and duplicates are not allowed (com(04)).
  8. Locations and Ship-To: No duplicate locations (com(07)) or ship-to entries (com(08), com(09) for customer ship-to).
  9. Dates and Times: Expiration date cannot be before start date (com(06)). Start time defaults to 0000 (mg10).
  10. Quantities: Maximum quantity (s1mxqy) must not be less than minimum quantity (s1mnqy) (com(11)).
  11. PO/Order Code: Must be 'P' (PO) or 'O' (Order) (com(12)).

  12. Container Type Handling:

  13. Per jb04, allows blank container codes for non-fluid products.
  14. Per jb06, checks arcupr with container type first, then with blank container type if not found.
  15. Per jb13 (07/22/2024), users cannot enter container types in sales agreements.

  16. Expiration Logic (jk04, mg12):

  17. A record is expired (s1expr = 'Y') only if its expiration date is greater than the new record’s start date or zero.
  18. Expired records are written to bicuagh (history file).
  19. Allows multiple records with the same start date if freight codes differ (mg12).
  20. Sets the end date of an expired record to one minute before the new record’s start time (mg12).

  21. Commission and Primary Flag:

  22. Includes commission information in arcomm when applicable (mg09).
  23. Sets s1prim = 'I' if blank (jb08).

  24. Duplicate Record Prevention:

  25. Checks for existing records in bicuag to prevent duplicates based on key fields (company, customer, location, container, product codes, etc.).

  26. Error and Success Messages:

  27. Displays messages for invalid input (e.g., com(01)com(12)), record creation (com(02)), updates (com(03)), or expiration failures (com(03)).

Tables Used

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

  1. arcust: Customer master file (input, contains customer details).
  2. bicont: Company master file (update/input, contains company details).
  3. gscntr1: Container file (input, alpha key, replaced gscntr per jk06).
  4. gsprod: Product file (input, contains product details).
  5. apvend: Vendor file (input, contains vendor details).
  6. gstabl: Table file (input, for reference data like container types).
  7. inloc: Location file (input, contains location details).
  8. shipto: Ship-to file (input, contains ship-to addresses).
  9. trrtcd: Freight code file (input, contains freight codes).
  10. arcupr: Customer price file (input, contains pricing data).
  11. arcomm: Commission file (input, contains commission data, added per jk03).
  12. bicuag: Sales agreement file (update/add, primary file for agreements).
  13. bicua3: Sales agreement file with additional fields (min/max quantity, renamed format bicuaglf, added per jk03).
  14. bicuagh: Sales agreement history file (output, stores expired records).

Overrides map these files to specific libraries (e.g., garcust or zarcust).


External Programs Called

The program calls the following external programs:

  1. QCMDEXC: System API to execute file override commands.
  2. QMHSNDPM: System API to send messages to the program message queue.
  3. QMHRMVPM: System API to remove messages from the message queue.
  4. BB9643V: Validates input fields in the p$vlist data structure, checking for duplicates, valid codes, and date logic.
  5. GSDTEDIT: Validates date formats (called via pldted parameter list).
  6. GSDTCLC1: Calculates date differences (called via pldtclc1 parameter list).
  7. LARCUST: Called for customer field prompting (F4 on customer field).
  8. LCSTSHP: Called for ship-to field prompting (F4 on ship-to field).
  9. LINLOC: Called for location field prompting (F4 on location field).
  10. LGSCNCD: Called for container field prompting (F4 on container field).
  11. LGSPROD: Called for product field prompting (F4 on product field).

Summary

  • Process Steps: Initializes parameters and files, opens database tables, displays an interactive screen, validates input, adds or updates sales agreement records in bicuag, handles expiration and history (bicuagh), and manages messages.
  • Business Rules: Enforces mode-based access, validates company/customer/product codes, prevents duplicates, restricts container types (jb13), allows blank containers for non-fluid products (jb04), handles expiration logic (jk04, mg12), and includes commission data (mg09).
  • Tables Used: arcust, bicont, gscntr1, gsprod, apvend, gstabl, inloc, shipto, trrtcd, arcupr, arcomm, bicuag, bicua3, bicuagh.
  • External Programs Called: QCMDEXC, QMHSNDPM, QMHRMVPM, BB9643V, GSDTEDIT, GSDTCLC1, LARCUST, LCSTSHP, LINLOC, LGSCNCD, LGSPROD.

If you need further analysis of specific subroutines, file structures, or called programs (e.g., BB9643V), please provide their source code or additional details. Alternatively, I can perform a DeepSearch for related information if enabled. Let me know how to proceed!