Skip to content

IN873 RPG36

The provided RPG II program (IN873.rpg36.txt) is executed by the OCL procedure (IN873.ocl36.txt) in an IBM System/36 environment. It is designed to convert between pounds and net gallons for inventory or production purposes, using data from input files and user interaction via workstation screens. Below, I will explain the process steps, business rules, tables (files) used, and external programs called, based on the RPG source code and the context provided by the OCL script.

Process Steps of the RPG Program

The IN873 RPG program is an interactive program that uses two screen formats (IN873S1 and IN873S2) to collect user input and display results. It processes data from the INCONT and GSPROD files to perform conversions between pounds and gallons, using product-specific gravity or density values. The program follows a structured flow with subroutines to handle screen navigation, data validation, and calculations. Here are the detailed process steps:

  1. Program Initialization
  2. File Setup: The program defines three files:
    • SCREEN: A workstation file (display file) for user interaction, with a size of 1000 bytes.
    • INCONT: An indexed input file (512 bytes, 2-byte key, alternate index) for inventory control data.
    • GSPROD: An indexed input file (512 bytes, 6-byte key, alternate index) for product master data, replacing the previously used GSTABL file (per change log JK01).
  3. Data Structures:
    • Defines MSG array for error messages (5 messages, 35 characters each).
    • Defines @INFDS for screen status information (e.g., @VKEY for function key status).
  4. Initial Screen Preparation:

    • The program starts by checking if the screen format ID (@SFID) is blank, indicating the first execution.
    • If blank, the $SBLK subroutine is called to initialize screen fields and display the first screen (IN873S1).
  5. Main Processing Loop (@SFNEX DOWNE 'EJ')

  6. The program enters a loop that continues until the user presses a key to exit (@SFNEX = 'EJ').
  7. Based on the screen format ID (@SFID), it calls subroutines to handle different screens:
    • If @SFID is blank, call $SBLK (initial blank screen).
    • If @SFID is S1, call $S1 (first screen processing).
    • If @SFID is S2, call $S2 (second screen processing).
  8. After processing the appropriate subroutine, the $XCPT subroutine displays the next screen.
  9. The program reads the SCREEN file to capture user input, setting the LR (Last Record) indicator on subsequent reads after the first.

  10. Blank Screen Processing ($SBLK)

  11. Initializes screen fields:
    • Clears KCO (company number), KPROD (product code), KGRAV (specific gravity), KLBS (pounds), KGAL (gallons), KFACT (factor), OLBS (output pounds), OGAL (output gallons), and PRDS (product description).
    • Hardcodes the company number (KCO) to 10.
  12. Sets the next screen format to S1 (@SFNEX = 'S1').
  13. Calls $S1ENT to validate the company number and prepare the first screen (IN873S1).

  14. Screen 1 Processing ($S1)

  15. Handles the first screen (IN873S1), which prompts the user to enter or confirm the company number (KCO).
  16. Based on the function key pressed (@VKEY):
    • If Enter (key 0), calls $S1ENT to validate the company number.
    • If command key 2, calls $S1CK to process command key actions (e.g., exit).
  17. Subroutine $S1ENT:
    • Validates the company number (KCO) by performing a CHAIN operation on the INCONT file.
    • If the company number is invalid (indicator 90 set), displays error message "INVALID COMPANY NO" (MSG,1).
    • If valid, sets indicators 03 and 04 (likely for screen formatting) and sets the next screen to S2 (@SFNEX = 'S2').
  18. Subroutine $S1CK:

    • If the user presses command key KG (likely F3 or an exit key), sets @SFNEX to EJ to exit the program.
  19. Screen 2 Processing ($S2)

  20. Handles the second screen (IN873S2), where the user enters the product code (KPROD), specific gravity (KGRAV), and either pounds (KLBS) or gallons (KGAL) to convert.
  21. Based on the function key pressed (@VKEY):
    • If Enter (key 0), calls $S2ENT to validate input and perform the conversion.
    • If command key 2, calls $S2CK to process command key actions.
  22. Subroutine $S2ENT:
    • Validation:
    • Checks if both KLBS and KGAL are non-zero. If so, sets error indicator 90 and displays "ENTER EITHER POUNDS OR GALLONS" (MSG,4), then skips to the end.
    • Validates the product code (KPROD) by constructing a 6-byte key (GSKEY6 = KCO + KPROD) and performing a CHAIN on the GSPROD file.
    • If the product code is invalid (indicator 96 set), displays "INVALID PRODUCT CODE" (MSG,2).
    • Retrieves the product description (TPDESC) from GSPROD and moves it to PRDS for display.
    • Specific Gravity Handling:
    • If the user-entered specific gravity (KGRAV) is zero, retrieves the gravity from the GSPROD file (TPGRAV) (per change log JB01).
    • Conversion Calculation:
    • Calls the external program MINLBGL1 to perform the conversion.
    • If KLBS is non-zero (pounds to gallons):
      • Passes KGRAV (specific gravity), KLBS (input pounds), and P@GAL (output gallons, initialized to zero).
      • MINLBGL1 calculates the gallons (P@GAL) and returns updated pounds (P@LBS).
      • Moves results to OLBS (output pounds) and OGAL (output gallons).
    • If KGAL is non-zero (gallons to pounds, per change log JB02):
      • Passes KGRAV, P@LBS (output pounds, initialized to zero), and KGAL (input gallons).
      • MINLBGL1 calculates the pounds (P@LBS) and returns updated gallons (P@GAL).
      • Moves results to OLBS and OGAL.
    • If errors occur (indicator 90 set), sets indicator 03 and skips to the end.
    • If successful, clears indicator 03 for normal display.
  23. Subroutine $S2CK:

    • If command key KA (likely F12 or back) is pressed, clears KPROD, KGRAV, KLBS, KFACT, OGAL, sets indicators 03 and 04, and returns to screen S1.
    • If command key KG is pressed, sets @SFNEX to EJ to exit the program.
  24. Screen Display ($XCPT)

  25. Increments a counter (@CCNT) to track screen displays.
  26. Displays the appropriate screen based on @SFNEX:
    • If @SFNEX = 'S1', outputs the IN873S1 screen format with KCO and MSG1.
    • If @SFNEX = 'S2', outputs the IN873S2 screen format with KCO, KPROD, KGRAV, KLBS, KGAL, OLBS, OGAL, MSG1, and PRDS.
  27. Calls CLRIND to reset error indicators and clear the message field (MSG1).

  28. Indicator Reset (CLRIND)

  29. Clears error indicator 90 and cursor indicators (51-57).
  30. Clears the message field (MSG1) to prepare for the next screen display.

  31. Program Termination

  32. The program exits when @SFNEX = 'EJ', typically triggered by the user pressing an exit key (e.g., F3 via KG).
  33. The LR indicator is set after the first screen read, ensuring proper file handling and program termination.

Business Rules

The program enforces the following business rules, derived from the code and comments:

  1. Company Number Validation:
  2. The company number (KCO) is hardcoded to 10 but validated against the INCONT file.
  3. If invalid, displays "INVALID COMPANY NO" and prevents further processing until corrected.

  4. Product Code Validation:

  5. The product code (KPROD) is validated against the GSPROD file using a composite key (GSKEY6 = KCO + KPROD).
  6. If invalid, displays "INVALID PRODUCT CODE" and prevents conversion.

  7. Input Exclusivity:

  8. Users must enter either pounds (KLBS) or gallons (KGAL), but not both (per change log JB02).
  9. If both are entered, displays "ENTER EITHER POUNDS OR GALLONS" and skips calculation.

  10. Specific Gravity Handling:

  11. If the user-entered specific gravity (KGRAV) is zero, the program retrieves the gravity from the GSPROD file (TPGRAV) (per change log JB01).
  12. The gravity is used in the conversion calculation by the external program MINLBGL1.

  13. Conversion Logic:

  14. The program supports bidirectional conversion (pounds to gallons or gallons to pounds, per change log JB02).
  15. The external program MINLBGL1 performs the actual conversion, using the specific gravity (KGRAV) and either pounds (KLBS) or gallons (KGAL) as input.
  16. Results are stored in OLBS (output pounds) and OGAL (output gallons) for display.

  17. Screen Navigation:

  18. The program uses two screens:
    • IN873S1: For entering/validating the company number.
    • IN873S2: For entering product code, specific gravity, and quantity (pounds or gallons), and displaying results.
  19. Users can return to IN873S1 using command key KA (e.g., F12) or exit using KG (e.g., F3).

  20. Error Handling:

  21. Displays specific error messages for invalid company number, invalid product code, or incorrect input (both pounds and gallons entered).
  22. Uses indicators (e.g., 90, 03, 04) to control error display and screen formatting.

Tables Used

In the System/36 context, "tables" typically refer to files or data structures used by the program. The RPG program uses the following files, which serve as data sources:

  1. INCONT:
  2. Description: Inventory control file, used to validate the company number (KCO).
  3. Fields Used:
    • ICINUM (positions 35-37): Inventory unit/measure.
    • ICTKRD (position 91): Daily tank reading flag (e.g., '', Q, H).
  4. Access: Indexed file with a 2-byte key, read via CHAIN to validate KCO.
  5. Purpose: Ensures the company number is valid before proceeding to product and quantity input.

  6. GSPROD:

  7. Description: Product master file, replacing the previous GSTABL file (per change log JK01). Contains product-specific data.
  8. Fields Used:
    • TPDEL (position 1): Likely a deletion flag or status.
    • TPDESC (positions 14-43): Product description, displayed on the screen.
    • TPPRCL (positions 127-129): Likely a product class or code.
    • TPGRAV (positions 132-134.1): Specific gravity, used for conversion if KGRAV is zero.
    • TPVCFC (positions 250-251): Likely a volume correction factor, though not used in the provided code.
  9. Access: Indexed file with a 6-byte key (GSKEY6), read via CHAIN to validate KPROD and retrieve TPGRAV and TPDESC.
  10. Purpose: Provides product-specific data, including gravity and description, for conversion and display.

No additional arrays or internal tables (e.g., RPG E specification arrays beyond MSG) are defined in the program.

External Programs Called

The program calls one external program:

  1. MINLBGL1:
  2. Description: Called to perform the conversion between pounds and gallons (per change log JB02). This program replaced an earlier MINLBGL module and directly calculates gallons or pounds rather than returning a factor.
  3. Parameters:
    • KYGRAV (3.1 numeric): Specific gravity, passed as input.
    • P@LBS (7.0 numeric): Pounds, passed as input (for pounds-to-gallons) or output (for gallons-to-pounds).
    • P@GAL (7.0 numeric): Gallons, passed as output (for pounds-to-gallons) or input (for gallons-to-pounds).
  4. Purpose: Performs the mathematical conversion using the specific gravity and input quantity, returning the converted value.
  5. Change Log Reference: JB02 (10/27/2011) notes that MINLBGL1 includes a corrected formula and supports bidirectional conversion.

Additional Notes

  • Change Log Insights:
  • JB01 (06/08/2011): Added logic to retrieve specific gravity from GSTABL (now GSPROD) if the user-entered KGRAV is zero.
  • JB02 (10/27/2011): Updated to call MINLBGL1 instead of MINLBGL, added gallons-to-pounds conversion, and modified the program to calculate results directly.
  • JK01 (08/15/2014): Replaced GSTABL with GSPROD for product data access.
  • System/36 Context: The program uses RPG II syntax and conventions typical of the IBM System/36, with flat files (INCONT, GSPROD) and a workstation file (SCREEN) for user interaction.
  • Limitations: Without the source code for MINLBGL1, the exact conversion formula (e.g., pounds = gallons × specific gravity × 8.34 for water-based calculations) is not visible. The program assumes MINLBGL1 handles the calculation correctly.
  • Error Messages: The program defines four error messages:
  • "INVALID COMPANY NO" (MSG,1)
  • "INVALID PRODUCT CODE" (MSG,2)
  • "VCF MUST BE IN GSTABL - INVCF TYPE" (MSG,3, not used in the code)
  • "ENTER EITHER POUNDS OR GALLONS" (MSG,4)

Summary

  • Process Steps:
  • Initialize files, data structures, and screen fields.
  • Enter a loop to process screens until exit (@SFNEX = 'EJ').
  • Display and process IN873S1 to validate the company number.
  • Display and process IN873S2 to validate product code and perform conversion.
  • Call MINLBGL1 for conversion calculations (pounds to gallons or gallons to pounds).
  • Display results or errors and handle navigation (back to S1 or exit).
  • Terminate when the user exits.

  • Business Rules:

  • Validate company number against INCONT.
  • Validate product code against GSPROD.
  • Allow only one input (pounds or gallons).
  • Use product-specific gravity from GSPROD if user input is zero.
  • Perform bidirectional conversion using MINLBGL1.
  • Support navigation between screens and program exit.

  • Tables Used:

  • INCONT: Inventory control file for company validation.
  • GSPROD: Product master file for product data and specific gravity.

  • External Programs Called:

  • MINLBGL1: Performs the pounds-to-gallons or gallons-to-pounds conversion.

If you have additional details, such as the source code for MINLBGL1 or the screen format definitions (IN873S1, IN873S2), I can provide further analysis of the conversion logic or screen layouts.