SA717C CLP
The provided CLP (Control Language Program) named SA717C is called by the RPGLE program SA717P to build a sales analysis work file and run a query (SA717Q). Below is a detailed explanation of the process steps, business rules, tables used, and external programs called.
Process Steps of the SA717C Program¶
The SA717C program is designed to prepare a temporary work file (SA717QF) by joining multiple files, applying a query selection string, and running a predefined query to generate sales analysis data. Here’s a step-by-step breakdown of the process:
- Program Declaration and Parameters:
- Purpose: Defines the program and its input parameters.
-
Steps:
- Declares the program with three parameters:
&P$FGRP(1 character): Group identifier ('G' or 'Z').&QRYSLT(1024 characters): Query selection string passed fromSA717Pfor filtering data.&P$TYPE(1 character): Data type ('S' for sales, 'P' for product moves).- Declares variables for file names:
&FILE01(10 characters): Primary file (eitherGSA5FILD,ZSA5FILD,GSA5MOVD, orZSA5MOVD).&FILE02(10 characters): Secondary file (GSA5SHPorZSA5SHP).&FILE03(10 characters): Tertiary file (GSHIPTOorZSHIPTO).
-
Determine File Names Based on Parameters:
- Purpose: Assigns file names based on the input parameters
&P$TYPEand&P$FGRP. -
Steps:
- If
&P$TYPE= 'S' (sales): - Sets
&FILE01to&P$FGRPconcatenated withSA5FILD(e.g.,GSA5FILDorZSA5FILD). - If
&P$TYPE= 'P' (product moves): - Sets
&FILE01to&P$FGRPconcatenated withSA5MOVD(e.g.,GSA5MOVDorZSA5MOVD). - Sets
&FILE02to&P$FGRPconcatenated withSA5SHP(e.g.,GSA5SHPorZSA5SHP). - Sets
&FILE03to&P$FGRPconcatenated withSHIPTO(e.g.,GSHIPTOorZSHIPTO).
- If
-
Copy Query Format File to QTEMP:
- Purpose: Creates a temporary copy of the query format file (
SA717QF) in theQTEMPlibrary. -
Steps:
- If
&P$FGRP= 'G': - Copies
SA717QFfrom libraryDATAtoQTEMP/SA717QFusingCPYF(Copy File) withMBROPT(*REPLACE)to overwrite any existing file andCRTFILE(*YES)to create the file if it doesn’t exist. - Monitors for
CPF2817(copy failure, e.g., if the file doesn’t exist) to prevent program termination. - If
&P$FGRP≠ 'G' (assumed to be 'Z'): - Copies
SA717QFfrom libraryDATADEVtoQTEMP/SA717QFwith the same options. - The temporary file in
QTEMPis used to store the query results.
- If
-
Override and Open Query File:
- Purpose: Configures the database query environment by overriding the file and applying the query selection.
-
Steps:
- Overrides the file
SA717QFto point to&FILE01(e.g.,GSA5FILDorGSA5MOVD) withSHARE(*YES)to allow shared access. - Executes
OPNQRYF(Open Query File) to join three files: &FILE01(primary file, e.g.,GSA5FILDorGSA5MOVD).&FILE02(e.g.,GSA5SHPorZSA5SHP).&FILE03(e.g.,GSHIPTOorZSHIPTO).- Specifies the output format as
SA717QF. - Applies the query selection string (
&QRYSLT) passed fromSA717P. - Defines key fields for sorting:
SACO(company),SACUST(customer),SASHIP(ship-to). - Specifies join conditions:
&FILE01/SACO=&FILE02/SHCO(company match).&FILE01/SACUST=&FILE02/SHCUST(customer match).&FILE01/SAINVN=&FILE02/SHINV(invoice number match).&FILE01/SAORD=&FILE02/SHORD(order number match).&FILE01/SACO=&FILE03/CSCO(company match).&FILE01/SACUST=&FILE03/CSCUST(customer match).&FILE01/SASHIP=&FILE03/CSSHIP(ship-to match).- Uses
JDFTVAL(*YES)to include records with missing join matches (left outer join).
- Overrides the file
-
Copy Query Results to Output File:
- Purpose: Transfers the query results to a physical file for further processing.
-
Steps:
- Uses
CPYFRMQRYF(Copy From Query File) to copy the results of the open query (&FILE01) toSA717QRYFin the*LIBLlibrary. - Specifies
MBROPT(*REPLACE)to overwrite the target file andCRTFILE(*NO)to assume the target file exists.
- Uses
-
Run the Query:
- Purpose: Executes the predefined query
SA717Qto generate the sales analysis report. -
Steps:
- Runs the query
GSSQRY/SA717QusingRUNQRY, which processes the data inSA717QRYF.
- Runs the query
-
Cleanup and Termination:
- Purpose: Closes the query file and removes overrides.
- Steps:
- Closes the open query file (
&FILE01) usingCLOF(Close File). - Deletes all file overrides using
DLTOVR FILE(*ALL). - Ends the program with
ENDPGM.
- Closes the open query file (
Business Rules¶
The program enforces the following business rules:
1. File Selection Based on Data Type:
- If &P$TYPE = 'S', the primary file is GSA5FILD or ZSA5FILD (sales data).
- If &P$TYPE = 'P', the primary file is GSA5MOVD or ZSA5MOVD (product movement data).
- This ensures the correct dataset is used based on whether the user wants sales or product movement analysis.
- Group-Based Library Selection:
- If
&P$FGRP= 'G', the source library forSA717QFisDATA. - If
&P$FGRP= 'Z', the source library isDATADEV. -
This supports different environments or datasets (e.g., production vs. development).
-
Query Filtering:
- The query selection string (
&QRYSLT) fromSA717Pfilters records based on conditions like non-deleted records (SADEL *NE "D"), specific freight codes, carrier codes, and date ranges. -
The join conditions ensure data consistency across the primary file (
&FILE01), shipment file (&FILE02), and ship-to file (&FILE03) by matching company, customer, invoice, order, and ship-to fields. -
Error Handling:
-
Monitors for
CPF2817during theCPYFoperation to handle cases where the source file may not exist or other copy errors occur, ensuring the program continues execution. -
Data Output:
- The query results are stored in
SA717QRYF, which is overwritten each time the program runs. - The
SA717Qquery processes this file to produce the final sales analysis report.
Tables Used¶
The program interacts with the following files (tables):
- SA717QF:
- Type: Physical file (PF).
- Library:
DATA(for&P$FGRP= 'G') orDATADEV(for&P$FGRP= 'Z'), copied toQTEMP/SA717QF. - Usage: Temporary query format file that defines the structure for the joined query output.
-
Access: Copied to
QTEMPand used as the format forOPNQRYF. -
GSA5FILD or ZSA5FILD:
- Type: Physical file (PF).
- Library:
DATAorDATADEV. - Usage: Primary file for sales data when
&P$TYPE= 'S'. - Fields: Includes
SACO(company),SACUST(customer),SAINV(invoice),SAORD(order),SASHIP(ship-to),SADEL(delete flag),SAIND8(date field). -
Access: Joined in
OPNQRYF. -
GSA5MOVD or ZSA5MOVD:
- Type: Physical file (PF).
- Library:
DATAorDATADEV. - Usage: Primary file for product movement data when
&P$TYPE= 'P'. - Fields: Similar to
SA5FILD, with fields likeSACO,SACUST,SAINV,SAORD,SASHIP. -
Access: Joined in
OPNQRYF. -
GSA5SHP or ZSA5SHP:
- Type: Physical file (PF).
- Library:
DATAorDATADEV. - Usage: Secondary file containing shipment data.
- Fields: Includes
SHCO(company),SHCUST(customer),SHINV(invoice),SHORD(order). -
Access: Joined in
OPNQRYF. -
GSHIPTO or ZSHIPTO:
- Type: Physical file (PF).
- Library:
DATAorDATADEV. - Usage: Tertiary file containing ship-to data.
- Fields: Includes
CSCO(company),CSCUST(customer),CSSHIP(ship-to). -
Access: Joined in
OPNQRYF. -
SA717QRYF:
- Type: Physical file (PF).
- Library:
*LIBL(library list). - Usage: Output file for the query results from
OPNQRYF. - Access: Populated by
CPYFRMQRYFand used by theSA717Qquery.
External Programs Called¶
The program does not directly call external programs but executes the following CL commands that invoke IBM i system utilities:
- CPYF (Copy File):
- Copies the
SA717QFfile fromDATAorDATADEVtoQTEMP. -
Monitors for
CPF2817to handle copy errors. -
OPNQRYF (Open Query File):
-
Performs a dynamic join and query on
&FILE01,&FILE02, and&FILE03using the&QRYSLTselection string. -
CPYFRMQRYF (Copy From Query File):
-
Copies the query results to
SA717QRYF. -
RUNQRY (Run Query):
-
Executes the predefined query
GSSQRY/SA717Qto process the data inSA717QRYF. -
CLOF (Close File):
-
Closes the open query file (
&FILE01). -
DLTOVR (Delete Override):
- Removes file overrides.
Summary¶
The SA717C CLP program is a critical component of the sales analysis process initiated by SA717P. It:
- Dynamically selects input files based on the group (&P$FGRP) and data type (&P$TYPE).
- Copies a query format file to QTEMP and joins three files (SA5FILD/SA5MOVD, SA5SHP, SHIPTO) using OPNQRYF.
- Applies the query selection string to filter data, stores results in SA717QRYF, and runs the SA717Q query to generate the sales analysis report.
- Cleans up by closing files and removing overrides.
This program supports flexible data processing for sales or product movement analysis across different datasets, with robust error handling and environment-specific library usage. If you need further clarification or analysis, let me know!