Skip to content

AR9006 RPG36

The provided document is an RPG/36 program named AR9006.rpg36.txt, called from the main OCL script AR900.ocl36.txt for the purpose of copying alternate product descriptions from a selected customer to another customer in the Customer Master Add/Update process on an IBM midrange system (likely System/36 or AS/400, now IBM i). Below, I will explain the process steps, business rules, tables used, and external programs called by this RPG program.


Process Steps of the RPG Program

The AR9006 program is designed to copy alternate product descriptions (FMCPDS) from one customer’s record in the PFARCUPR file to another customer’s record in the PTARCUPR file, based on matching keys. It is invoked from AR900 (Customer Master File Maintenance) and BI900 (Customer Shipto Master File Maintenance). The program operates in a straightforward manner, focusing on reading, validating, and updating/adding records.

  1. Program Entry and Parameter Handling:
  2. Purpose: Receives input parameters to identify the source and target customer records.
  3. Steps:

    • The program defines a parameter list (*ENTRY PLIST) with the following parameters:
    • CO (2 bytes): Company number.
    • CUST (6 bytes): Target customer number.
    • SHIP (3 bytes): Target shipto number.
    • KICUST (6 bytes): Source customer number (from which to copy descriptions).
    • KISHIP (3 bytes): Source shipto number.
    • These parameters are used to construct keys for accessing records in the PFARCUPR and PTARCUPR files.
  4. Execution of the Main Subroutine (DOCOPY):

  5. Purpose: Performs the core logic of copying alternate product descriptions.
  6. Steps:

    • Calls the DOCOPY subroutine to process the copy operation.
    • Sets the Last Record indicator (LR) to terminate the program after processing.
    • Proceeds to the OUT tag to exit.
  7. DOCOPY Subroutine:

  8. Purpose: Copies alternate product descriptions from the source customer to the target customer.
  9. Steps:

    • Build Source Key (CPLM16):
    • Constructs an 8-byte key (CPLM8) by combining CO (company) and KICUST (source customer).
    • Extends to an 11-byte key (CPLM11) by appending KISHIP (source shipto).
    • Extends to a 16-byte key (CPLM16) by appending four blank spaces (per JB01, likely for FMCNTY container type compatibility).
    • Uses SETLL to position the file pointer at the first record in PFARCUPR matching CPLM16.
    • Read Source Records:
    • Enters a loop (AGNP tag) to read records from PFARCUPR until end-of-file (EOF, indicator 10).
    • Skips records marked as deleted (FMDEL = 'D').
    • Validates that the record matches the source company (FMCONO = CO), customer (FMCUST = KICUST), and shipto (FMSHIP = KISHIP). If any mismatch occurs, skips to the next record (NOMRP tag).
    • Build Target Key (CPKY16):
    • Constructs an 8-byte key (CPKY8) using CO and CUST (target customer).
    • Extends to an 11-byte key (CPKY11) by appending SHIP (target shipto).
    • Extends to a 15-byte key (CPKY15) by appending FMPROD (product code from the source record).
    • Extends to a 16-byte key (CPKY16) by appending FMCNTY (container type from the source record, per JB01).
    • Check Target Record:
    • Uses CHAIN to locate a matching record in PTARCUPR using CPKY16.
    • If no record exists (indicator 90 on):
      • Copies the alternate product description (FMCPDS) to CPCPDS.
      • Writes a new record to PTARCUPR using the ADDREC exception output.
    • If a record exists (indicator 90 off):
      • Checks if the existing alternate description (CPCPDS) is blank.
      • If blank, updates CPCPDS with FMCPDS and writes the updated record to PTARCUPR using the UPDREC exception output.
    • Loop Continuation:
    • Returns to the AGNP tag to process the next record in PFARCUPR.
  10. Program Termination:

  11. After processing all matching records, the program exits via the OUT tag, setting the LR indicator to close files and terminate.

Business Rules

The program enforces the following business rules to ensure accurate copying of alternate product descriptions:

  1. Record Matching:
  2. Only non-deleted records (FMDEL ≠ 'D') from the source file (PFARCUPR) are considered for copying.
  3. The source record must match the input parameters: company (FMCONO = CO), customer (FMCUST = KICUST), and shipto (FMSHIP = KISHIP).

  4. Target Record Handling:

  5. If a matching record does not exist in PTARCUPR (based on company, customer, shipto, product code, and container type), a new record is created with the copied alternate description (FMCPDS).
  6. If a matching record exists in PTARCUPR but its alternate description (CPCPDS) is blank, it is updated with the source description (FMCPDS).
  7. If the existing CPCPDS is non-blank, no update is performed (preserving the existing description).

  8. Key Structure:

  9. The key for both files includes company, customer, shipto, product code, and container type (FMCNTY, added in JB01).
  10. The container type (FMCNTY) is part of the key to ensure precise matching, reflecting a business requirement to differentiate products by container type.

  11. Data Integrity:

  12. The program ensures that only valid, non-deleted source records are copied to maintain data consistency.
  13. The alternate description (CPCPDS) is only updated or added if necessary, avoiding unnecessary overwrites.

Tables (Files) Used

The program uses the following files, as defined in the File Specification (F) section:

  1. PFARCUPR (IF, Input, 80 bytes, Key at position 2, Logical File):
  2. Source file containing customer product records with alternate descriptions.
  3. Fields include:

    • FMDEL (1 byte): Delete code (D for deleted).
    • FMCONO (2 bytes): Company number.
    • FMCUST (6 bytes): Customer number.
    • FMSHIP (3 bytes): Shipto number.
    • FMPROD (4 bytes): Product code.
    • FMCPDS (30 bytes): Customer product description (alternate description).
    • FMCNTY (1 byte): Container type (added in JB01).
  4. PTARCUPR (UF, Update/Add, 80 bytes, Key at position 2, Physical File):

  5. Target file for adding or updating customer product records.
  6. Fields include:
    • CPDEL (1 byte): Delete code.
    • CPCPDS (30 bytes): Customer product description (target for copying).
    • Other fields (implied by key structure): Company, customer, shipto, product code, and container type.

External Programs Called

The AR9006 program does not call any external programs. It operates independently, performing direct file operations on PFARCUPR and PTARCUPR to copy alternate product descriptions.


Summary

  • Process Steps: The program receives parameters for source and target customers, reads non-deleted records from PFARCUPR, validates them against input parameters, and either adds new records or updates existing records in PTARCUPR with the alternate product description.
  • Business Rules: Ensures only valid, non-deleted source records are copied; updates target records only if their description is blank; includes container type in the key for precise matching; and preserves existing non-blank descriptions.
  • Tables Used: PFARCUPR (input, source records), PTARCUPR (update/add, target records).
  • External Programs Called: None.

This RPG/36 program is a specialized utility for copying alternate product descriptions, supporting the customer master and shipto maintenance processes by ensuring consistent product descriptions across customer records. If you need further details on specific logic or file structures, let me know!