Skip to content

BB943P RPGLE

The RPG program BB943P.rpgle is an IBM i (AS/400) program designed for "Work With Customer Sales Agreements." It provides an interactive interface using a display file with subfiles to manage customer sales agreement records. The program supports maintenance and inquiry modes, allowing users to view, add, copy, delete, or display sales agreement records. 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 BB943P program follows a structured flow typical of RPG interactive applications on IBM i, using a display file with a subfile to present and manage data. Here are the key process steps:

  1. Initialization (*inzsr Subroutine):
  2. Parameters: The program receives two input parameters:
    • p$mode (3 characters): Determines the run mode, either 'MNT' (maintenance) or 'INQ' (inquiry).
    • p$fgrp (1 character): Specifies the file group ('G' or 'Z'), which determines the database files to use via overrides.
  3. File Overrides: Based on p$fgrp, the program applies database file overrides (ovg for 'G' or ovz for 'Z') to point to the appropriate files (e.g., garcust or zarcust).
  4. File Opens: Opens all required database files (arcust, bicont, bicuag, gscntr1, gsprod, gstabl, inloc, shipto, bicuax, bicua10) with USROPN to control file access.
  5. Variable Initialization: Sets up work fields, subfile control fields, and message handling fields. Initializes the current date and time for use in processing.

  6. Open Database Tables (opntbl Subroutine):

  7. Executes the QCMDEXC API to apply file overrides based on p$fgrp.
  8. Opens all input files for reading, ensuring the program can access customer, sales agreement, and related data.

  9. Process Subfile (srsfl1 Subroutine):

  10. Clear Message Subfile: Calls clrmsg to clear any existing messages in the message subfile.
  11. Initialize Subfile: Sets the subfile mode to 'folded' (sfmod1 = '1', *in45 = *on) for the initial load and initializes control fields (e.g., c1cono to 10).
  12. Set Filters: Initializes the expired entries filter (w$expd = *off, F8=Incl Del) and the ascending/descending sort order (f13sel = 'D', F13=Descend).
  13. Global Protection: Sets *in70 (global protect) based on p$mode. In 'INQ' mode, fields are protected (*in70 = *on); in 'MNT' mode, fields are editable (*in70 = *off).
  14. Position File: Calls sf1rep to position the file cursor based on user input or defaults.
  15. Main Loop:

    • Displays the command line and message subfile.
    • Checks for existing subfile records to enable/disable display (*in41).
    • Sets folded/unfolded mode for the subfile (*in45).
    • Displays the subfile control record (sflctl1) using EXFMT.
    • Processes user input (function keys, cursor location, and subfile records).
  16. Handle User Input:

  17. Function Keys:

    • F03 (Exit): Exits the program by setting sf1agn = *off.
    • F04 (Prompt): Calls prompt to allow field-specific prompting (e.g., customer, ship-to, location).
    • F05 (Refresh): Triggers a subfile refresh by setting repsfl = *on.
    • F08 (Toggle Expired Entries): Toggles the w$expd flag to include/exclude expired entries and updates the subfile.
    • F09 (History Inquiry): Calls histinq to invoke GB730P for customer history inquiry.
    • F13 (Toggle Ascend/Descend): Toggles the sort order (f13sel between 'A' and 'D') and refreshes the subfile.
    • PAGEDN (Page Down): Calls sf1lod to load additional subfile records.
    • ENTER: Validates the password (validatepw) and processes subfile records (sf1prc).
    • F06 (Add): Validates the password and calls sf1add to add a new record.
    • F10 (Position Cursor): Clears cursor position to focus on the control record.
    • Control Field Changes: If control fields (e.g., c1cono, c1cust) change, repositions the subfile via sf1rep.
  18. Process Subfile Records (sf1prc Subroutine):

  19. Reads changed subfile records (readc sfl1) and processes them via sf1chg.
  20. Handles options selected in the subfile (e.g., 2=Change, 3=Copy, 4=Delete, 5=Display).

  21. Process Subfile Options (sf1chg Subroutine):

  22. Option 2 (Change): If in 'MNT' mode and the record is not deleted, calls sf1s02 to modify the record.
  23. Option 3 (Copy): If in 'MNT' mode and not deleted, calls sf1s03 to copy the record.
  24. Option 4 (Delete): If in 'MNT' mode, calls sf1s04 to delete the record.
  25. Option 5 (Display): Calls sf1s05 to display the record details.
  26. Updates the subfile record after processing.

  27. Reposition Subfile (sf1rep Subroutine):

  28. Clears the subfile (sf1clr).
  29. Validates control field input (sf1cte).
  30. Positions the file cursor based on sort order (f13sel) and user input (e.g., c1cono, c1cust, c1cntr).
  31. Loads the subfile (sf1lod).

  32. Edit Control Fields (sf1cte Subroutine):

  33. Validates the company (c1cono) and customer (c1cust) fields against bicont and arcust files.
  34. Sets error messages if validation fails (e.g., ERR0010 for invalid company).

  35. Subfile Option Processing:

  36. Copy (sf1s03): Calls BB943 to copy a record, passing parameters like company, status, and sequence number. Displays success (ERR0000, com(04)) or failure (com(09)) messages.
  37. Delete (sf1s04): Calls BB944 to mark a record as deleted ('D') or reactivated ('A'), displaying appropriate messages (com(05) or com(06)).
  38. Display (sf1s05): Calls BB943 in 'INQ' mode to display record details.
  39. History Inquiry (histinq): Calls GB730P with customer history parameters.

  40. Message Handling:

    • Add Message (addmsg): Sends messages to the program message queue using QMHSNDPM.
    • Write Message (wrtmsg): Writes messages to the message subfile.
    • Clear Message (clrmsg): Clears the message subfile using QMHRMVPM.
  41. Program Termination:

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

Business Rules

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

  1. Mode-Based Access Control:
  2. In 'MNT' mode, users can add, change, copy, or delete records (*in70 = *off for editable fields).
  3. In 'INQ' mode, fields are protected (*in70 = *on), allowing only viewing.

  4. Validation of Input:

  5. Company (c1cono) and customer (c1cust) must exist in bicont and arcust files, respectively, or an error (ERR0010) is displayed.
  6. Ship-to codes require a valid customer code (com(01)).

  7. Password Validation:

  8. For add or copy operations, a password (c1agpw) is required unless blank, in which case it defaults to 'N' (w$validpw).
  9. The password is validated via validatepw and passed to called programs.

  10. Expired Records Filter:

  11. Users can toggle inclusion/exclusion of expired records using F8 (w$expd and fky labels).
  12. Expired records are filtered based on the w$expd flag during subfile loading.

  13. Sort Order:

  14. Users can toggle ascending (f13sel = 'A') or descending (f13sel = 'D') sort order using F13, affecting how records are loaded into the subfile.

  15. Record Status:

  16. Deleted records (s1del = 'D') cannot be modified (com(08)).
  17. Copy operations check for expired records and display a message if applicable (com(11)).

  18. Partial PO Data Entry:

  19. As of revision jk06 (08/31/18), the program supports partial purchase order (PO) data entry for scanning purposes.

  20. Container Type Restriction:

  21. As of revision jb07 (07/22/24), users cannot enter container types in sales agreements, restricting input flexibility.

  22. Subfile Options:

  23. Option 2 (Change): Allowed in 'MNT' mode for non-deleted records.
  24. Option 3 (Copy): Copies a record to a new sequence number, with success or failure messages.
  25. Option 4 (Delete): Marks records as deleted ('D') or reactivated ('A').
  26. Option 5 (Display): Displays record details in inquiry mode.

  27. Error and Success Messages:

    • Messages are displayed for actions like record creation (com(02)), change (com(03)), copy (com(04)), deletion (com(05)), reactivation (com(06)), or errors (e.g., com(09), com(11)).

Tables Used

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

  1. arcust: Customer master file, containing customer details (e.g., customer ID, name).
  2. bicont: Company master file, containing company details.
  3. bicuag: Sales agreement file, primary file for customer sales agreements.
  4. gscntr1: Container file (replaced gscntr per revision jk05), with an alpha key.
  5. gsprod: Product file, containing product details.
  6. gstabl: Table file, likely for reference data (e.g., container types).
  7. inloc: Location file, containing location details.
  8. shipto: Ship-to file, containing ship-to addresses.
  9. bicuax: Renamed sales agreement file (record format bicuagp1), used for specific key access.
  10. bicua10: Renamed sales agreement file (record format bicuagp2), used for alternate key access (per revision jk02).

The overrides (ovg and ovz) map these files to specific libraries (e.g., garcust or zarcust), ensuring the correct dataset is used based on the file group.


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. BB943: Called for copy (option 3) and display (option 5) operations, passing parameters like company, status, sequence number, and mode ('MNT' or 'INQ').
  5. BB944: Called for delete (option 4) operations, handling record deletion or reactivation.
  6. GB730P: Called for history inquiry (F9), passing customer history parameters.
  7. LARCUST: Called for customer field prompting (F4 on C1CUST), returning a selected customer.
  8. LCSTSHP: Called for ship-to field prompting (F4 on C1SHIP), returning customer and ship-to codes.
  9. LINLOC: Called for location field prompting (F4 on C1LOC), returning a selected location.
  10. LGSCNCD: Called for container field prompting (F4 on C1CNTR), returning a container code.
  11. LGSPROD: Called for product field prompting (F4 on C1PRCD), returning a product code.

Note: A commented-out call to BB947 suggests it was previously used for copy operations but has been replaced by BB943.


Summary

  • Process Steps: The program initializes parameters and files, opens database tables, displays a subfile for user interaction, processes function keys (F3, F4, F5, F8, F9, F13, etc.), validates input, and handles subfile options (change, copy, delete, display). It uses message subfiles for feedback and closes files upon termination.
  • Business Rules: Enforces mode-based access ('MNT' vs. 'INQ'), validates company/customer input, requires passwords for certain actions, supports expired record filtering, toggles sort order, restricts container type entry, and provides feedback via messages.
  • Tables Used: arcust, bicont, bicuag, gscntr1, gsprod, gstabl, inloc, shipto, bicuax, bicua10.
  • External Programs Called: QCMDEXC, QMHSNDPM, QMHRMVPM, BB943, BB944, GB730P, LARCUST, LCSTSHP, LINLOC, LGSCNCD, LGSPROD.

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