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.
- Program Entry and Parameter Handling:
- Purpose: Receives input parameters to identify the source and target customer records.
-
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
PFARCUPRandPTARCUPRfiles.
- The program defines a parameter list (
-
Execution of the Main Subroutine (
DOCOPY): - Purpose: Performs the core logic of copying alternate product descriptions.
-
Steps:
- Calls the
DOCOPYsubroutine to process the copy operation. - Sets the Last Record indicator (
LR) to terminate the program after processing. - Proceeds to the
OUTtag to exit.
- Calls the
-
DOCOPY Subroutine:
- Purpose: Copies alternate product descriptions from the source customer to the target customer.
-
Steps:
- Build Source Key (
CPLM16): - Constructs an 8-byte key (
CPLM8) by combiningCO(company) andKICUST(source customer). - Extends to an 11-byte key (
CPLM11) by appendingKISHIP(source shipto). - Extends to a 16-byte key (
CPLM16) by appending four blank spaces (perJB01, likely forFMCNTYcontainer type compatibility). - Uses
SETLLto position the file pointer at the first record inPFARCUPRmatchingCPLM16. - Read Source Records:
- Enters a loop (
AGNPtag) to read records fromPFARCUPRuntil end-of-file (EOF, indicator10). - 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 (NOMRPtag). - Build Target Key (
CPKY16): - Constructs an 8-byte key (
CPKY8) usingCOandCUST(target customer). - Extends to an 11-byte key (
CPKY11) by appendingSHIP(target shipto). - Extends to a 15-byte key (
CPKY15) by appendingFMPROD(product code from the source record). - Extends to a 16-byte key (
CPKY16) by appendingFMCNTY(container type from the source record, perJB01). - Check Target Record:
- Uses
CHAINto locate a matching record inPTARCUPRusingCPKY16. - If no record exists (indicator
90on):- Copies the alternate product description (
FMCPDS) toCPCPDS. - Writes a new record to
PTARCUPRusing theADDRECexception output.
- Copies the alternate product description (
- If a record exists (indicator
90off):- Checks if the existing alternate description (
CPCPDS) is blank. - If blank, updates
CPCPDSwithFMCPDSand writes the updated record toPTARCUPRusing theUPDRECexception output.
- Checks if the existing alternate description (
- Loop Continuation:
- Returns to the
AGNPtag to process the next record inPFARCUPR.
- Build Source Key (
-
Program Termination:
- After processing all matching records, the program exits via the
OUTtag, setting theLRindicator to close files and terminate.
Business Rules¶
The program enforces the following business rules to ensure accurate copying of alternate product descriptions:
- Record Matching:
- Only non-deleted records (
FMDEL ≠ 'D') from the source file (PFARCUPR) are considered for copying. -
The source record must match the input parameters: company (
FMCONO = CO), customer (FMCUST = KICUST), and shipto (FMSHIP = KISHIP). -
Target Record Handling:
- 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). - If a matching record exists in
PTARCUPRbut its alternate description (CPCPDS) is blank, it is updated with the source description (FMCPDS). -
If the existing
CPCPDSis non-blank, no update is performed (preserving the existing description). -
Key Structure:
- The key for both files includes company, customer, shipto, product code, and container type (
FMCNTY, added inJB01). -
The container type (
FMCNTY) is part of the key to ensure precise matching, reflecting a business requirement to differentiate products by container type. -
Data Integrity:
- The program ensures that only valid, non-deleted source records are copied to maintain data consistency.
- 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:
- PFARCUPR (
IF, Input, 80 bytes, Key at position 2, Logical File): - Source file containing customer product records with alternate descriptions.
-
Fields include:
FMDEL(1 byte): Delete code (Dfor 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 inJB01).
-
PTARCUPR (
UF, Update/Add, 80 bytes, Key at position 2, Physical File): - Target file for adding or updating customer product records.
- 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 inPTARCUPRwith 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!