Skip to content

BB929P RPGLE

The provided document is an RPGLE program named BB929P, part of a Billing and Invoicing system, designed to manage Customer Service Representative (CSR) IDs. Below, I will explain the process steps of the program, list the external programs called, and identify the tables (files) used.


Process Steps of the RPGLE Program (BB929P)

The program is a workstation-based interactive application that uses a subfile (SFL) to display and manage CSR IDs. It operates in either maintenance (MNT) or inquiry (INQ) mode, with functionality to create, change, inactivate/reactivate, and display CSR records. Below is a step-by-step explanation of its process flow, based on the mainline logic and subroutines:

  1. Program Initialization (*inzsr Subroutine):
  2. Parameter Reception: The program receives two input parameters:
    • p$mode (3 characters): Specifies the run mode (MNT for maintenance or INQ for inquiry).
    • p$fgrp (1 character): Specifies the file group (Z or G) for database overrides.
  3. Genie Check: The program checks if it is being called from the Genie environment by calling GSGENIE2C. If genievar is not YES, the program closes all files and terminates.
  4. Field Initialization: Initializes various fields, including:
    • Subfile control fields (e.g., rrn1, rrnsv1, pagsz1 set to 14 for page size).
    • Message handling fields (e.g., dspmsg, m@pgmq).
    • Current date and time (t#time, t#cymd).
    • Key lists (klsfl1, kls1s1) for file access.
  5. Header Setup: Sets the display header (c$hdr1) from the hdr array.

  6. Open Database Tables (opntbl Subroutine):

  7. File Overrides: Based on the p$fgrp parameter (Z or G), applies database overrides using the QCMDEXC API to redirect file access to the appropriate library (gbbcsr, zbcsr, gbicont, zbicont).
  8. File Opening: Opens three files:

    • bbcsr (CSR master file, input-only).
    • bbcsrrd (CSR master file with renamed record format, input-only).
    • bicont (control file, input-only).
  9. Process Subfile (srsfl1 Subroutine):

  10. Clear Message Subfile: Calls clrmsg to clear any existing messages and wrtmsg to display the message subfile.
  11. Subfile Mode Initialization:
    • Sets sfmod1 to '1' and #fold to '0' to control folded/unfolded display mode.
    • Initializes subfile control fields (c1co, c1crid) to zeros or blanks.
    • Sets w$inact to *ON (display all records, including inactive ones, per revision jb01).
  12. Global Protection: Sets indicator *IN70 based on p$mode:
    • *OFF for maintenance mode (MNT).
    • *ON for inquiry mode (INQ), protecting input fields.
  13. Subfile Repositioning: Calls sf1rep to position the file and load the subfile initially.
  14. Main Loop (sf1agn):

    • Reposition Subfile: If repsfl is *ON, updates control fields (c1co, c1crid) and calls sf1rep to reposition the subfile.
    • Display Command Line: Writes the sflcmd1 format (command line).
    • Display Message Subfile: If dspmsg is *ON, calls wrtmsg; otherwise, writes msgclr to clear messages.
    • Subfile Display Check: Sets *IN41 (SFLDSP) based on whether rrn1 (relative record number) is greater than zero.
    • Folded/Unfolded Mode: Sets *IN45 based on sfmod1 and #fold to control subfile display mode.
    • Display Subfile Control: Sets *IN40 (SFLDSPCTL) to *ON and executes exfmt sflctl1 to display the subfile control format and accept user input.
    • Clear Messages: If dspmsg is *ON, calls clrmsg to clear the message subfile.
    • Clear Indicators: Resets screen error indicators (*IN21 to *IN39, *IN50 to *IN69) to zero.
    • Cursor Positioning: Calculates row (row1) and column (col1) for the cursor using csrloc.
    • Set Record Number: Sets rcdnb1 to pagrrn to ensure the correct subfile page is displayed.
    • Process User Input (Before Subfile Read):
    • F03 (Exit): Sets sf1agn to *OFF to exit the loop.
    • F04 (Field Prompting): Calls prompt to handle field prompting and iterates.
    • F05 (Refresh): Clears r$co, sets repsfl to *ON, and iterates to refresh the subfile.
    • F08 (Toggle Inactive Filter): Toggles w$inact between *ON and *OFF to include/exclude inactive records, sets repsfl to *ON, and iterates. (Note: F8 functionality is commented out for Profound UI, defaulting to include all records.)
    • F15 (Print Listing): Calls BB9295 with parameters to print a CSR ID listing, sends a confirmation message, and iterates.
    • Direct Access: If d1opt, d1co, or d1crid is non-blank/zero, calls sf1dir to process direct access options.
    • Page Down: If the PAGEDN key is pressed, calls sf1lod to load the next page of subfile records.
    • Process Subfile on Enter: If the ENTER key is pressed, calls sf1prc to process subfile changes.
    • Process User Input (After Subfile Read):
    • Position Request: If c1co or c1crid is non-blank/zero, calls sf1rep to reposition the subfile.
    • F10 (Position Cursor): Clears row1 and col1 to reposition the cursor to the control record.
    • The loop continues until sf1agn is *OFF.
  15. Process Subfile on Enter (sf1prc Subroutine):

  16. Reads changed subfile records using readc sfl1 (indicator *IN81).
  17. For each changed record, calls sf1chg to process the selected option.

  18. Process Subfile Record Change (sf1chg Subroutine):

  19. Retains selected values (s1co, s1crid) in s$co and s$crid.
  20. Processes based on the subfile option (s1opt):
    • Option 2 (Change): If in MNT mode and the record is not deleted (s1del is not D or I), calls sf1s02.
    • Option 4 (Inactivate/Reactivate): If in MNT mode, calls sf1s04.
    • Option 5 (Display): Calls sf1s05.
  21. Updates the subfile record by chaining to bbcsr and sfl1, clearing s1opt, formatting the record (sf1fmt), applying color coding (sf1col), and updating the subfile.

  22. Reposition Subfile (sf1rep Subroutine):

  23. Clears the subfile (sf1clr) and resets rrn1.
  24. Edits subfile control input (sf1cte).
  25. If no errors (*IN50 is *OFF), positions the file using setll on bbcsrrd and loads the subfile (sf1lod).
  26. Retains control fields (c1co, c1crid) in r$co and r$crid for repositioning.

  27. Edit Subfile Control Input (sf1cte Subroutine):

  28. Currently empty, likely intended for input validation (not implemented in the provided code).

  29. Load Subfile Records (sf1lod Subroutine):

  30. Sets rrn1 to the last saved relative record number (rrnsv1).
  31. Sets rcdnb1 to rrn1 + 1 to ensure the new page is displayed.
  32. Loads up to pagsz1 (14) records:
    • Reads the next record from bbcsrrd (indicator *IN43 for end-of-file).
    • Skips deleted or inactive records (crdel = D or I) if w$inact is *OFF.
    • Formats the subfile line (sf1fmt), applies color coding (sf1col), and writes the record to sfl1.
    • Increments rrn1.
  33. Saves the last rrn1 in rrnsv1.

  34. Format Subfile Detail Line (sf1fmt Subroutine):

  35. Clears the subfile record (sfl1).
  36. Moves fields from the file record (crco, crcrid, crcrnm, cremal, crdel) to subfile fields (s1co, s1crid, s1crnm, s1emal, s1del).

  37. Subfile Color Coding (sf1col Subroutine):

    • Sets *IN72 to *ON (blue color) if the record is deleted or inactive (s1del = D or I).
  38. Direct Access Processing (sf1dir Subroutine):

    • Retains direct input values (d1co, d1crid) in s$co and s$crid.
    • Validates input:
    • For option 1 (Create), ensures d1co and d1crid are not blank/zero; otherwise, sets error ERR0103.
    • For option 1, checks if d1co exists in bicont; if not, sets error ERR0021.
    • Checks if the record exists in bbcsr using setll:
      • For non-create options, if the record exists, proceeds; otherwise, sets error ERR0102.
      • For create, if the record exists, sets error ERR0101 (cannot create duplicate).
    • If no errors (*IN50 is *OFF), processes the option:
    • Option 1 (Create): Calls sf1s01.
    • Option 2 (Change): Calls sf1s02.
    • Option 4 (Inactivate/Reactivate): Calls sf1s04.
    • Option 5 (Display): Calls sf1s05.
    • Clears input fields and cursor position if no errors.
  39. Subfile Option 01 - Create (sf1s01 Subroutine):

    • Calls BB929 with parameters:
    • s$co, s$crid (key fields).
    • o$mode set to MNT.
    • p$fgrp (file group).
    • o$flag (return flag).
    • If o$flag is 1, sends a confirmation message (Code <crid> has been created), sets c1co and c1crid, and sets repsfl to *ON to reposition the subfile.
  40. Subfile Option 02 - Change (sf1s02 Subroutine):

    • Chains to bbcsr to check if the record is deleted or inactive (crdel = D or I). If so, sends error message Cannot Modify An Inactive Record.
    • If valid, calls BB929 with parameters similar to sf1s01.
    • If o$flag is 1, sends a confirmation message (Code <crid> has been changed).
  41. Subfile Option 04 - Inactivate/Reactivate (sf1s04 Subroutine):

    • Calls BB9294 with parameters:
    • s$co, s$crid (key fields).
    • p$fgrp (file group).
    • o$flag (return flag).
    • Processes the return flag:
    • I: Sends message Code <crid> has been InActivated.
    • A: Sends message Code <crid> has been ReActivated.
    • E: Sends message Code <crid> <vendor table error>.
    • Stores o$co in a$co.
  42. Subfile Option 05 - Display Customer Order (sf1s05 Subroutine):

    • Calls BB929 with parameters, setting o$mode to INQ for inquiry mode.
  43. Field Prompting (prompt Subroutine):

    • Sets *IN19 to *ON to indicate panel format input change.
    • (Note: Cursor positioning code is commented out.)
  44. Message Handling (addmsg, wrtmsg, clrmsg Subroutines):

    • Add Message (addmsg):
    • Sets dspmsg to *ON.
    • Calculates the length of m@data and sends a message to the program message queue using QMHSNDPM.
    • Clears message data fields.
    • Write Message Subfile (wrtmsg):
    • Sets *IN49 to *ON and writes the msgctl format to display messages.
    • Clear Message Subfile (clrmsg):
    • Sets dspmsg to *OFF.
    • Saves and restores the current record format (rcdnam) and pagrrn.
    • Clears messages using QMHRMVPM.
  45. Program Termination:

    • Closes all files.
    • Sets *INLR to *ON and returns.

External Programs Called

The program calls the following external programs: 1. GSGENIE2C: - Called during initialization to check if the program is running in the Genie environment. - Parameter: genievar (3 characters, returns YES if in Genie). 2. BB929: - Called for options 1 (Create), 2 (Change), and 5 (Display). - Parameters: - o$co (company number, output). - o$crid (CSR ID, output). - o$mode (MNT or INQ, output). - o$fgrp (file group Z or G, output). - o$flag (return flag, output). 3. BB9294: - Called for option 4 (Inactivate/Reactivate). - Parameters: - o$co (company number, output). - o$crid (CSR ID, output). - o$fgrp (file group Z or G, output). - o$flag (return flag: I, A, or E, output). 4. BB9295: - Called for F15 (Print Listing). - Parameter: o$fgrp (file group Z or G, output). 5. QCMDEXC: - IBM i API called to execute file override commands. - Parameters: - dbov## (80 characters, override command). - dbol## (15.5, command length). 6. QMHSNDPM: - IBM i API called to send messages to the program message queue. - Parameters: Message ID, message file, message data, data length, message type, program queue, stack counter, message key, error code. 7. QMHRMVPM: - IBM i API called to clear messages from the program message queue. - Parameters: Program queue, stack counter, message key, remove option, error code.


Tables (Files) Used

The program uses the following files: 1. bb929pd: - Type: Workstation file (display file). - Usage: Contains the subfile sfl1 and control format sflctl1 for the user interface. - Handler: PROFOUNDUI(HANDLER) for Profound UI integration. 2. bbcsr: - Type: Physical file (input-only). - Usage: Master file for CSR records, accessed using key list klsfl1. - Override: Redirected to gbbcsr or zbcsr based on p$fgrp. 3. bbcsrrd: - Type: Physical file (input-only) with renamed record format (bbcsrpf to bbcsrpr). - Usage: Used for sequential reading and positioning, accessed using key list kls1s1. - Override: Redirected to gbbcsr or zbcsr based on p$fgrp. 4. bicont: - Type: Physical file (input-only). - Usage: Control file to validate company numbers (d1co). - Override: Redirected to gbicont or zbicont based on p$fgrp.


Summary

The BB929P program is an interactive RPGLE application that manages CSR IDs using a subfile-based interface. It supports creating, changing, inactivating/reactivating, and displaying records, with options to filter inactive records (though modified to always include them per jb01). The program uses database overrides to access files in different libraries (Z or G), integrates with Profound UI, and provides message handling for user feedback. It calls external programs (BB929, BB9294, BB9295, GSGENIE2C) and IBM i APIs (QCMDEXC, QMHSNDPM, QMHRMVPM) to perform its functions, and interacts with three database files (bbcsr, bbcsrrd, bicont) and one display file (bb929pd).