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 fromSA717P
for 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 (GSA5SHP
orZSA5SHP
).&FILE03
(10 characters): Tertiary file (GSHIPTO
orZSHIPTO
).
-
Determine File Names Based on Parameters:
- Purpose: Assigns file names based on the input parameters
&P$TYPE
and&P$FGRP
. -
Steps:
- If
&P$TYPE
= 'S' (sales): - Sets
&FILE01
to&P$FGRP
concatenated withSA5FILD
(e.g.,GSA5FILD
orZSA5FILD
). - If
&P$TYPE
= 'P' (product moves): - Sets
&FILE01
to&P$FGRP
concatenated withSA5MOVD
(e.g.,GSA5MOVD
orZSA5MOVD
). - Sets
&FILE02
to&P$FGRP
concatenated withSA5SHP
(e.g.,GSA5SHP
orZSA5SHP
). - Sets
&FILE03
to&P$FGRP
concatenated withSHIPTO
(e.g.,GSHIPTO
orZSHIPTO
).
- If
-
Copy Query Format File to QTEMP:
- Purpose: Creates a temporary copy of the query format file (
SA717QF
) in theQTEMP
library. -
Steps:
- If
&P$FGRP
= 'G': - Copies
SA717QF
from libraryDATA
toQTEMP/SA717QF
usingCPYF
(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
SA717QF
from libraryDATADEV
toQTEMP/SA717QF
with the same options. - The temporary file in
QTEMP
is 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
SA717QF
to point to&FILE01
(e.g.,GSA5FILD
orGSA5MOVD
) withSHARE(*YES)
to allow shared access. - Executes
OPNQRYF
(Open Query File) to join three files: &FILE01
(primary file, e.g.,GSA5FILD
orGSA5MOVD
).&FILE02
(e.g.,GSA5SHP
orZSA5SHP
).&FILE03
(e.g.,GSHIPTO
orZSHIPTO
).- 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
) toSA717QRYF
in the*LIBL
library. - 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
SA717Q
to generate the sales analysis report. -
Steps:
- Runs the query
GSSQRY/SA717Q
usingRUNQRY
, 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 forSA717QF
isDATA
. - 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
) fromSA717P
filters 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
CPF2817
during theCPYF
operation 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
SA717Q
query 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
QTEMP
and used as the format forOPNQRYF
. -
GSA5FILD or ZSA5FILD:
- Type: Physical file (PF).
- Library:
DATA
orDATADEV
. - 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:
DATA
orDATADEV
. - 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:
DATA
orDATADEV
. - 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:
DATA
orDATADEV
. - 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
CPYFRMQRYF
and used by theSA717Q
query.
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
SA717QF
file fromDATA
orDATADEV
toQTEMP
. -
Monitors for
CPF2817
to handle copy errors. -
OPNQRYF (Open Query File):
-
Performs a dynamic join and query on
&FILE01
,&FILE02
, and&FILE03
using the&QRYSLT
selection string. -
CPYFRMQRYF (Copy From Query File):
-
Copies the query results to
SA717QRYF
. -
RUNQRY (Run Query):
-
Executes the predefined query
GSSQRY/SA717Q
to 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!