Skip to content

BI890P RPGLE

The BI890P.rpgle.txt is an RPGLE (RPG IV) program named BI890P, designed as a "Ship-to Master Inquiry Prompt" for the Customer Orders and Invoicing system on an IBM AS/400 (iSeries) platform. It provides an interactive interface to query and manage ship-to master records, utilizing a subfile (SFL) to display records and handle user interactions. Below, I will explain the process steps, business rules, tables used, and external programs called, based on the provided RPGLE source code.

Process Steps

The program follows a structured flow to manage the inquiry process for ship-to master records. The steps are organized into subroutines, executed in a specific sequence:

  1. Initialization (*inzsr Subroutine):
  2. Parameters: Receives two input parameters:
    • p$fgrp (1 character): File group identifier ('G' or 'Z') to determine file overrides.
    • p$mode (3 characters): Mode of operation ('INQ' for inquiry or 'MNT' for maintenance).
  3. Local Data Area (LDA): Retrieves data from the LDA (fields l$co, l$cust, l$ship, l$fkey) for company, customer, ship-to, and function key values.
  4. File Overrides: Applies database file overrides based on p$fgrp ('G' for garcust, gbicont, gshipto or 'Z' for zarcust, zbicont, zshipto) using the opntbl subroutine.
  5. Field Setup: Initializes work fields, subfile control fields (e.g., rrn1, pagsz1), and date/time fields using the program status data structure (psds##).
  6. Key Lists: Defines key lists (kls1s1, kls1s2, kls1r1, klcust, klcust2, klshipto) for file access.
  7. Mode Check: If p$mode is 'MNT', sets indicator *in78 to enable maintenance options.

  8. Open Database Tables (opntbl Subroutine):

  9. Executes file overrides for arcust, bicont, and shipto based on p$fgrp using the QCMDEXC API.
  10. Opens the arcust, bicont, and shipto files with usropn for input-only access.

  11. Process Subfile (srsfl1 Subroutine):

  12. Subfile Setup: Initializes the subfile mode (sfmod1) to '1' (folded) and clears the message subfile (clrmsg).
  13. Main Loop (sf1agn):
    • Displays the command line (sflcmd1) and message subfile if errors exist (wrtmsg).
    • Checks if subfile records exist (rrn1 > 0) to set *in41 (SFLDSP).
    • Sets folded/unfolded mode based on sfmod1 (*in45).
    • Displays the subfile control format (sflctl1) using exfmt.
    • Clears message subfile and format indicators after display.
    • Determines cursor location (csrloc) and sets the subfile record number (rcdnb1) based on pagrrn.
  14. User Input Handling:

    • F03 (Exit): Sets l$fkey to 'F03', writes to LDA, and exits the loop.
    • F04 (Prompt): Calls the prompt subroutine to assist with field input (e.g., company or customer lookup).
    • F05 (Refresh): Triggers subfile repositioning (repsfl).
    • User Positioning: If company (c$co), customer (c$cust), or ship-to (c$ship) changes, repositions the subfile (sf1rep).
    • Direct Access: If d1opt or d1ship is specified, processes direct access (sf1dir).
    • Page Down: Loads additional subfile records (sf1lod).
    • Enter Key: Processes subfile selections (sf1prc).
    • F10: Clears cursor position (row1, col1).
  15. Subfile Processing (sf1prc Subroutine):

  16. Reads subfile records (readc sfl1) if rrn1 > 0.
  17. Processes each record change (sf1chg) if a record is read (*in81 = *off).

  18. Subfile Record Change (sf1chg Subroutine):

  19. Handles subfile options (s1opt):
    • Option 2 (Update): In maintenance mode (*in78), sets s$ship and calls sf1s02.
    • Option 3 (Copy): In maintenance mode, sets s$ship and calls sf1s03.
    • Option 5 (Display): In inquiry mode, sets s$ship and calls sf1s05.
  20. Clears the selection field (s1opt) and updates the subfile record after applying color coding (sf1color).

  21. Subfile Repositioning (sf1rep Subroutine):

  22. Clears the subfile (sf1clr) and validates control fields (sf1cte).
  23. If no errors (*in50 = *off), positions the shipto file using kls1s1 and loads subfile records (sf1lod).
  24. Retains control fields (r$co, r$cust, r$ship) for repositioning and clears c$ship.

  25. Control Field Validation (sf1cte Subroutine):

  26. Validates company number (c$co) against bicont. If invalid or zero, sets error 'ERR0010' and indicators *in50, *in51.
  27. Validates customer number (c$cust) against arcust. If invalid or zero, sets error 'ERR0010' and indicators *in50, *in52.

  28. Subfile Loading (sf1lod Subroutine):

  29. Sets the relative record number (rrn1) to the last saved value (rrnsv1).
  30. Loads up to pagsz1 (32) records into the subfile:
    • Reads the next shipto record (reade shipto).
    • If no records are found (*in43 = *on and rrn1 = 0), adds a "No Results" record (com(01)).
    • Formats each record (sf1fmt) and writes to the subfile.
  31. Updates rrnsv1 with the last record number.

  32. Subfile Formatting (sf1fmt Subroutine):

  33. Clears the subfile record and populates fields (s1ship, s1name, s1ctst, s1adr1, s1adr2, s1adr3, s1stat, s1cszp) from shipto data.
  34. Applies color coding (sf1color).

  35. Color Coding (sf1color Subroutine):

    • Sets *in77 if the record is flagged for deletion (s1del = 'D').
  36. Direct Access (sf1dir Subroutine):

    • Validates direct input (d1opt, d1ship):
    • For option 1 (Create) in maintenance mode, ensures c$co, c$cust, and d1ship are non-zero; otherwise, sets error 'ERR0103'.
    • Checks if the ship-to exists (setll shipto).
    • For option 2 (Update), errors if the ship-to does not exist ('ERR0102').
    • For option 1 (Create), errors if the ship-to already exists ('ERR0101').
    • If no errors, processes options (calls sf1s01, sf1s02, sf1s03, or sf1s05).
  37. Option Processing:

    • Create (sf1s01): Sets LDA fields (l$co, l$cust, l$ship), clears l$fkey, writes to LDA, and exits the loop.
    • Update (sf1s02): Same as sf1s01.
    • Copy (sf1s03): Calls sf1cpy to handle copying a ship-to record.
    • Display (sf1s05): Sets LDA fields and exits the loop.
  38. Copy Processing (sf1cpy Subroutine):

    • Initializes window fields (c$tcnm, w$tcst, w$tshp) and enters a loop (winagn).
    • Displays the copy window (sflcpy1) and processes input:
    • F04: Calls prompt.
    • F12: Exits the window.
    • F22: No action defined.
    • Validates input (sf1cpyedt).
    • If no errors, calls BI8903 with parameters (c$co, c$cust, s$ship, w$tcst, w$tshp, p$fgrp), updates LDA, and exits both window and main loops.
  39. Copy Input Validation (sf1cpyedt Subroutine):

    • Validates target customer (w$tcst) against arcust. If invalid, sets error 'ERR0010'.
    • Ensures target ship-to (w$tshp) is non-zero; otherwise, sets error 'ERR0000' with message com(02).
    • Checks if the target ship-to exists (chain shipto). If it does, sets error 'ERR0000' with message com(03).
  40. Field Prompting (prompt Subroutine):

    • For SFLCTL1 format:
    • If C$CO, calls LBICONT to prompt for company.
    • If C$CUST, calls LARCUST to prompt for customer.
    • For SFLCPY1 format:
    • If W$TCST, calls LARCUST and updates c$tcnm.
  41. Message Handling:

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

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

Business Rules

  1. Access Control:
  2. The program operates in two modes: Inquiry (INQ) and Maintenance (MNT).
  3. Maintenance mode (*in78 = *on) enables options 1 (Create), 2 (Update), and 3 (Copy). Inquiry mode enables option 5 (Display).

  4. Validation:

  5. Company (c$co) must exist in bicont or an error ('ERR0010') is displayed.
  6. Customer (c$cust, w$tcst) must exist in arcust or an error ('ERR0010') is displayed.
  7. For Create (d1opt = 1), the ship-to (d1ship) must not exist (ERR0101) and must be non-zero (ERR0103).
  8. For Update (d1opt = 2), the ship-to must exist (ERR0102).
  9. For Copy, the target ship-to (w$tshp) must be non-zero (ERR0000, com(02)) and must not exist (ERR0000, com(03)).

  10. Subfile Management:

  11. The subfile displays up to 32 records per page (pagsz1).
  12. If no records are found, a "No Results" message (com(01)) is displayed.
  13. Deleted records (s1del = 'D') are color-coded (*in77).

  14. Navigation and Input:

  15. Users can reposition the subfile by entering company, customer, or ship-to values.
  16. Function keys:
    • F03: Exit the program.
    • F04: Prompt for company or customer selection.
    • F05: Refresh the subfile.
    • F10: Position cursor to the control record.
    • F12: Cancel copy window.
    • Page Down: Load the next page of records.
  17. Direct access (d1opt, d1ship) allows quick navigation to specific records.

  18. Copy Functionality:

  19. Copying a ship-to record requires a valid target customer and a non-existing target ship-to number.
  20. The BI8903 program is called to perform the copy operation.

  21. Error Handling:

  22. Errors are displayed in a message subfile (msgctl) with codes like 'ERR0010', 'ERR0101', 'ERR0102', 'ERR0103', and 'ERR0000'.
  23. Messages are cleared after each display cycle unless errors persist.

Tables (Files) Used

The program uses the following database files (tables) with input-only access (if and usropn): 1. arcust: Customer master file (contains customer data, e.g., arname). 2. bicont: Contract or company master file (contains company data, e.g., bcname). 3. shipto: Ship-to master file (contains ship-to data, e.g., `csship梗

System: hip,csname,csctst,csadr1,csadr2,csadr3,csstat,cscszp). 4. **bi890pd**: Display file (workstation file with subfilesfl1and control formats likesflctl1,sflcmd1,sflcpy1,msgctl,msgclr,wdwovr`).

External Programs Called

The program calls the following external programs: 1. QCMDEXC: System API to execute file override commands (ovrdbf) for arcust, bicont, and shipto. 2. QMHSNDPM: System API to send error messages to the program message queue. 3. QMHRMVPM: System API to clear messages from the program message queue. 4. LBICONT: Called during prompting (F04) for company selection, passing c$co and p$fgrp. 5. LARCUST: Called during prompting (F04) for customer selection, passing c$co, c$cust or w$tcst, and p$fgrp. 6. BI8903: Called during copy processing (sf1cpy), passing c$co, c$cust, s$ship, w$tcst, w$tshp, and p$fgrp.

Summary

The BI890P program is an interactive inquiry and maintenance tool for ship-to master records, using a subfile to display data and handle user interactions. It supports: - Inquiry and maintenance modes, with validation for company, customer, and ship-to data. - Subfile navigation, error handling, and color-coded displays for deleted records. - Copy functionality via a window, calling BI8903 for record creation. - Prompting for company and customer selection via LBICONT and LARCUST. - File overrides based on the file group ('G' or 'Z').

The program integrates with arcust, bicont, and shipto files, ensuring robust data access and validation. It uses system APIs for command execution and message handling, and external programs for specific tasks like prompting and copying records.

If you need further details or analysis of specific subroutines or business logic, please let me know!