Skip to content

AP107

The provided RPG program (AP107.rpg36.txt) is executed as part of the Accounts Payable (A/P) voucher entry upload process for FlexiCapture imports on the IBM i (AS/400) system, as referenced in the OCL file (AP106.ocl36.txt). Below is a detailed explanation of the process steps, business rules, tables/files used, and external programs called in this RPG program.


Overview

The AP107 RPG program is a simple utility that reads records from the FlexiCapture import file (APINVUP) and writes them to the FlexiCapture history table (APFLEXH) for record-keeping. It captures metadata such as the date, time, user, and workstation, ensuring an audit trail of uploaded data. This program is called before AP106 to archive the import data prior to further processing.


Process Steps

  1. Initialization
  2. Upon reading each record from the input file (APINVUP) (indicated by 01), the program retrieves the current system date and time using the TIME operation, storing them in TIMDAT (12 digits, HHMMSSYYYYMMDD format).
  3. Extracts the time (SYTIME, HHMMSS) and date (SYDATE, MMDDYY) from TIMDAT.
  4. Converts the date to YYMMDD format (SYDYMD) by multiplying SYDATE by 10000.01.
  5. Extracts the month (MONTH) from SYDATE.
  6. Formats the date as an 8-digit field (DATE8, YYYYMMDD) by combining a century prefix (20) with SYDYMD.
  7. Stores the time in a 6-digit field (TIME6, HHMMSS).
  8. Retrieves the user ID (USER) and workstation ID (WRKSTN) from the User Data Structure (UDS, fields at positions 400–409 and 410–414).

  9. Write to History Table

  10. For each record read from APINVUP, the program writes a record to the FlexiCapture history table (APFLEXH) using the DADD exception output (indicated by 01).
  11. The output record includes:

    • The entire input record split into six segments (REC1REC6, covering positions 1–1090 of APINVUP).
    • The formatted date (DATE8, positions 1091–1098).
    • The formatted time (TIME6, positions 1099–1104).
    • The user ID (USER, positions 1105–1114).
    • The workstation ID (WRKSTN, positions 1115–1129).
  12. Loop and Termination

  13. The program continues reading and processing APINVUP records until the end of the file.
  14. No explicit termination logic is shown, but the program ends naturally when all input records are processed, closing files automatically.

Business Rules

  1. Audit Trail Creation:
  2. Every record from the FlexiCapture import file (APINVUP) is archived in the history table (APFLEXH) without modification.
  3. Metadata (date, time, user, workstation) is appended to each record to track when and by whom the data was uploaded.

  4. Data Preservation:

  5. The program does not validate or modify the input data; it copies all fields (REC1REC6) directly to the output file.
  6. This ensures a complete and unaltered record of the import data for auditing or recovery purposes.

  7. System Metadata:

  8. The program uses system-provided date/time (TIMDAT) and user/workstation information from the UDS to populate audit fields.
  9. The date is formatted as YYYYMMDD (DATE8) with a hardcoded century prefix (20), assuming all dates are in the 2000s.

Tables/Files Used

The program interacts with the following database files, identified by their file names, labels, and purposes:

File Name Label Purpose Access Type Used For
APINVUP APINVUP Input file containing FlexiCapture import data (e.g., invoice, vendor, amount). Input (IP) Reading import records.
APFLEXH APFLEXH FlexiCapture history table storing archived import records with audit metadata. Output (O) Writing history records.

File Details: - APINVUP: - Record length: 1090 bytes. - Fields include invoice number (AUINV#), vendor number (AUVEND), total amount (AUTOTL), PO number (AUPONM), and others. - Also mapped to six segments (REC1REC6) for direct copying (positions 1–256, 257–512, 513–750, 751–810, 811–1000, 1001–1090). - APFLEXH: - Record length: 1129 bytes. - Includes the 1090 bytes from APINVUP (REC1REC6) plus additional fields: - DATE8 (8 bytes, YYYYMMDD, positions 1091–1098). - TIME6 (6 bytes, HHMMSS, positions 1099–1104). - USER (10 bytes, user ID, positions 1105–1114). - WRKSTN (15 bytes, workstation ID, positions 1115–1129).


External Programs Called

  • None:
  • The AP107 program does not explicitly call any external programs or subroutines via CALL operations.
  • All processing is self-contained, relying on basic RPG operations (TIME, MOVEL, MOVE, MULT) and file I/O.

Additional Notes

  • Simplicity: The program is straightforward, designed solely to archive APINVUP records in APFLEXH with audit metadata. It lacks complex logic or validation, deferring such tasks to other programs (e.g., AP106).
  • Y2K Assumption: The program assumes all dates are in the 21st century by prefixing 20 to the year in DATE8. This may cause issues for dates before 2000 or after 2099, though unlikely given the context.
  • UDS Usage: The User Data Structure (UDS) provides user and workstation information, which is standard in IBM i RPG programs for audit purposes.
  • File Access:
  • APINVUP is read sequentially as a primary file (IP).
  • APFLEXH is an output file (O) with records added (A) via exception output (DADD).

Summary

  • Process Steps: Reads each record from APINVUP, captures system date/time and user/workstation metadata, and writes the record plus metadata to APFLEXH.
  • Business Rules: Archives all import records without modification, appending audit metadata (date, time, user, workstation) for tracking.
  • Files Used: APINVUP (input, import data), APFLEXH (output, history with audit metadata).
  • External Programs: None; all logic is internal.

Let me know if you need further clarification or additional details about specific sections or logic!