Skip to content

BB204 RPGLE

The BB204.rpgle program is an RPG IV program designed to auto-post customer sales agreement pricing in the Customer Pricing system. It is called from the BB204.ocl36 OCL script, as previously discussed, and processes pricing records, updates existing records, and maintains a history of changes. Below, I will explain the process steps, business rules, tables used, and external programs called, referencing the provided RPGLE source code.


Process Steps of the BB204 RPG Program

The program follows a structured process to validate input, process pricing records, update the customer agreement file, and maintain a historical record. Here’s a detailed breakdown of the process steps based on the RPGLE code:

  1. Initialization (*inzsr Subroutine):
  2. Purpose: Sets up the environment, opens files, and initializes variables.
  3. Receives a parameter p$fgrp (file group, either 'G' or 'Z') to determine file overrides.
  4. Executes file overrides for database files (bicuag, bicont, bicuagh, bb204t) and the printer file (qsysprt) using the QCMDEXC API to apply overrides defined in ovg or ovz arrays based on p$fgrp.
  5. Opens database files (bicuag, bb204t, bicont, bicuagh) and the printer file (qsysprt).
  6. Initializes date and time fields using the system timestamp (t#time) and formats the current date into t#cymd (CCYYMMDD format).
  7. Clears message handling fields and sets up the message queue for error handling.
  8. Initializes the display file (bb204d) and printer file headers for reporting.

  9. Main Processing Loop (Process Subroutine):

  10. Purpose: Manages the display file interaction and orchestrates the main processing logic.
  11. Displays a message subfile if errors exist (wrtmsg subroutine) or clears the screen (clrscr) if no messages are pending.
  12. Presents the pstscn format (likely a screen for user input) using EXFMT and checks for function keys (F12 to exit, F09 to post).
  13. Validates the start date entered by the user (editstrdate subroutine).
  14. If the start date is valid (*in50 = *off):
    • Converts the input start date (p#cymd) to working fields (w1strcymd, w1strymd).
    • Calculates the expiration date as one day prior to the start date using the GSDTCLC1 program (called via PLDTCLC1 parameter list).
    • Stores the calculated expiration date in w1endcymd, newendd8, and newendd6.
  15. If the start date is invalid, sets error indicators (*in51, *in53), adds an error message (ERR0020), and iterates the loop to redisplay the screen.
  16. If F09 is pressed and the start date is valid, calls the postit subroutine to process the pricing updates.

  17. Date Validation (editstrdate Subroutine):

  18. Purpose: Validates the user-entered start date (s1stdt) to ensure it is a valid date and matches the start date in the bb204t work file.
  19. Breaks down the input date into month, day, and year components.
  20. Validates the month (must be 1–12).
  21. Validates the day based on the month:
    • For February, checks for leap years (divisible by 4 for non-century years, or by 400 for century years) to allow 29 days in leap years or 28 days otherwise.
    • For other months, allows 30 or 31 days based on standard calendar rules.
  22. If the date is invalid, sets indicator *in51 (error) and *in50 to trigger an error message.
  23. If valid, converts the date to p#cymd (CCYYMMDD format) and checks if it matches the start date in bb204t (new_banstd). If not, sets an error (ERR0000) with the expected start date from bb204t.

  24. Posting Logic (postit Subroutine):

  25. Purpose: Processes records from bb204t, updates the customer agreement file (bicuag), and writes to the history file (bicuagh).
  26. Reads records from bb204t sequentially until end-of-file (%eof).
  27. For each record:
    • Update Existing Record:
    • Chains to bicuag using keys new_bacono (company number) and new_baseqn (sequence number).
    • If a record is found (%found):
      • Stores old values (oldprice, oldoffp, oldenddt, oldstrdt, oldcntn) for reporting.
      • Checks if the existing record’s expiration date (baend8) is greater than the new record’s start date (w1strcymd) or is zero.
      • If true, updates the expiration date (baendt, baend8) to the calculated end date (w$endt, w1endcymd) with an end time of 23:59 and sets indicator *in65.
      • Updates the last updated date (baludt) and time (balutm) with the current timestamp.
      • Writes the updated record to bicuag.
      • If *in65 is on, writes the original record to the history file (bicuagh) via writehistorg.
    • If no record is found, clears old values and proceeds.
    • Create New Price Record:
    • Retrieves the next sequence number (w$sq) from bicont via rtvnxtsqky.
    • Chains to bicuag with the new sequence number to ensure no conflict.
    • If no record exists, clears the bicuag record and populates fields from bb204t (e.g., new_badel, new_bacono, new_bacust, etc.).
    • Sets creation and update timestamps (bacrdt, bacrtm, baludt, balutm), start date (bastdt, bastd8), and end date (baendt, baend8).
    • Writes the new record to bicuag and the history file (bicuagh) via writehist.
    • Prints a detail line (dtl01) to qsysprt for reporting, including old and new pricing details.
  28. Sets fmtagn to *off to exit the main loop after processing.

  29. Sequence Number Retrieval (rtvnxtsqky Subroutine):

  30. Purpose: Retrieves and increments the sequence number for new records in bicuag.
  31. Chains to bicont using new_bacono to get the current sequence number (bcseqn).
  32. If found, increments the sequence number (w$sq = bcseqn + 1), updates bicont, and stores the new value.

  33. History File Writing (writehist and writehistorg Subroutines):

  34. writehist: Writes a new pricing record to bicuagh with fields from bb204t, including timestamps and the new sequence number (w$sq). Sets the start date, end date, and change timestamp (hhchd8, hhchtm) to the current date/time.
  35. writehistorg: Writes the original (expired) bicuag record to bicuagh when an existing record is updated, preserving its original fields and setting the change timestamp to the current date/time.

  36. Printer Overflow Handling (ovrflo Subroutine):

  37. Purpose: Manages printer file overflow for the report.
  38. If the overflow indicator (*inof) is on, sets prtovr to trigger a header print.
  39. If prtovr is on, prints the report header (hdr01) and resets prtovr.

  40. Message Handling (addmsg, wrtmsg, clrmsg Subroutines):

  41. addmsg: Sends an error message to the program message queue using QMHSNDPM, specifying the message ID, file (GSMSGF), and data.
  42. wrtmsg: Displays the message subfile (msgctl) when errors are present.
  43. clrmsg: Clears the message subfile using QMHRMVPM, preserving the current record format and subfile page.

  44. Program Termination:

  45. Closes all files (close *all).
  46. Sets *inlr = *on to indicate the last record and returns control to the caller.

Business Rules

The program enforces the following business rules, based on the code and comments:

  1. Start Date Validation:
  2. The user-entered start date (s1stdt) must be a valid date (correct month, day, and leap year handling).
  3. It must match the start date in the bb204t work file (new_banstd). If not, an error (ERR0000) is displayed with the expected date.

  4. Expiration Date Calculation:

  5. The expiration date for new records is set to one day before the start date of the new record (calculated via GSDTCLC1).
  6. For existing records in bicuag, the expiration date is updated only if:

    • The current expiration date (baend8) is greater than the new record’s start date (w1strcymd), or
    • The current expiration date is zero (indicating no expiration).
  7. Record Update and History:

  8. If an existing bicuag record is found for the company and sequence number, it is updated with a new expiration date and written to the history file (bicuagh) if modified.
  9. New pricing records are created in bicuag with a new sequence number retrieved from bicont.
  10. Both new and expired records are written to bicuagh for audit purposes, with timestamps and user IDs.

  11. Sequence Number Management:

  12. The sequence number (baseqn) for new bicuag records is incremented from the last value stored in bicont to ensure uniqueness.

  13. Date Format:

  14. Dates are handled in CCYYMMDD format (w1strcymd, w1endcymd) with century indicators (w$strcen, w$endcen) to distinguish between 19xx and 20xx years.
  15. Start times for new records are set to 00:00, and end times are set to 23:59.

  16. Reporting:

  17. A printed report is generated with headers and detail lines, including company, customer, location, pricing, and sequence number details (old and new values).

  18. Error Handling:

  19. Invalid dates trigger error messages (ERR0020 for format errors, ERR0000 for mismatched start dates).
  20. The program uses a message subfile to display errors to the user and allows re-entry until valid data is provided.

  21. File Group Handling:

  22. The program supports two file groups (G or Z), which determine the library for file overrides (gbicuag vs. zbicuag, etc.).

Tables (Files) Used

The program uses the following files, as defined in the file specifications (F specs) and overrides: 1. bicuag (Customer Agreement File): - File: bicuag (renamed to bicuagrd internally). - Usage: Update (uf), add (a), externally described (e), keyed (k), user-opened (usropn). - Purpose: Stores customer pricing agreement records. Updated with new expiration dates or new records. - Override: gbicuag (for p$fgrp = 'G') or zbicuag (for p$fgrp = 'Z').

  1. bb204t (Work File):
  2. File: bb204t.
  3. Usage: Input (if), externally described (e), keyed (k), user-opened (usropn), prefixed with new_.
  4. Purpose: Contains input pricing records to be processed.
  5. Override: gbb204t (for p$fgrp = 'G') or zbb204t (for p$fgrp = 'Z').

  6. bicont (Control File):

  7. File: bicont.
  8. Usage: Update (uf), add (a), externally described (e), keyed (k), user-opened (usropn).
  9. Purpose: Stores the last sequence number (bcseqn) for generating new bicuag records.
  10. Override: gbicont (for p$fgrp = 'G') or zbicont (for p$fgrp = 'Z').

  11. bicuagh (History File):

  12. File: bicuagh.
  13. Usage: Output (o), externally described (e), keyed (k), user-opened (usropn).
  14. Purpose: Stores historical records of both new and expired pricing agreements.
  15. Override: gbicuagh (for p$fgrp = 'G') or zbicuagh (for p$fgrp = 'Z').

  16. bb204d (Display File):

  17. File: bb204d.
  18. Usage: Combined (cf), externally described (e), workstation file (workstn), with an information data structure (infds).
  19. Purpose: Provides the user interface for entering and validating the start date.

  20. qsysprt (Printer File):

  21. File: qsysprt.
  22. Usage: Output (o), fixed-length 184 characters, user-opened (usropn), with overflow indicator (*inof).
  23. Purpose: Generates a report of posted pricing changes.
  24. Override: Configured with PAGESIZE(68 184), LPI(8), CPI(15), OVRFLW(62), OUTQ(*JOB), HOLD(*YES), SAVE(*YES).

Note: The file biagnew is commented out (jb01), indicating it was previously used but is no longer part of the process.


External Programs Called

The program calls the following external program: 1. GSDTCLC1: - Called via the pldtclc1 parameter list in the Process subroutine. - Purpose: Calculates the date difference (in days) to determine the expiration date as one day prior to the input start date. - Parameters: - p#dat1: Input date (CCYYMMDD). - p#dat2: Output date (CCYYMMDD). - p#fmt: Format ('D' for days). - p#diff: Date difference (set to -1 for one day prior). - p#err: Error flag ('Y' if an error occurs).

Additionally, the program uses system APIs: - QCMDEXC: Executes file override commands for database and printer files. - QMHSNDPM: Sends messages to the program message queue. - QMHRMVPM: Removes messages from the message queue.


Summary

The BB204 RPG program automates the posting of customer sales agreement pricing by: - Validating a user-entered start date against the bb204t work file. - Processing records from bb204t to update or create pricing records in bicuag. - Maintaining a history of changes in bicuagh. - Managing sequence numbers via bicont. - Generating a printed report via qsysprt. - Handling errors through a message subfile and user interaction.

Business Rules: - Start dates must be valid and match bb204t. - Expiration dates are calculated as one day prior to the start date. - Existing records are updated only if their expiration date is greater than the new start date or zero. - All changes are logged to the history file with timestamps and user IDs. - Sequence numbers are incremented uniquely for new records.

Tables Used: bicuag, bb204t, bicont, bicuagh, bb204d (display), qsysprt (printer). External Programs Called: GSDTCLC1 (date calculation), plus system APIs QCMDEXC, QMHSNDPM, and QMHRMVPM.