AR190 RPG36
The RPG program AR190.rpg36.txt
is an RPG/36 program (likely for an IBM System/36 or AS/400 environment) that handles the A/R Salesman Change Transaction Add/Update process, as referenced in the previously provided .OCL
file (AR190.ocl36.txt). Below, I’ll explain the process steps, business rules, tables used, and external programs called based on the provided RPG code. The program manages the addition and updating of salesman change transactions in an Accounts Receivable (A/R) system, allowing users to assign or reassign salesmen to customers and mark transactions for deletion.
Process Steps of RPG Program AR190¶
The AR190
program is an interactive application that uses a workstation (display) file to manage salesman change transactions. It operates with two primary screens (S1
and S2
) and performs validation, data retrieval, and file updates. Below is a detailed breakdown of the process steps, derived from the RPG code:
- Program Initialization and File Setup:
- The program defines four files:
SCREEN
: A workstation file (display device) for user interaction, with a record length of 1000 bytes.ARSLST
: A disk file (update mode,UF
) for salesman change transactions, with a record length of 256 bytes and an 8-byte key starting at position 2.ARCONT
: A disk file (input mode,IF
) for A/R control data, with a 256-byte record length and a 2-byte key.ARCUST
: A disk file (input mode,IF
) for customer master data, with a 384-byte record length and an 8-byte key.GSTABL
: A disk file (input mode,IF
) for general table data (e.g., salesman codes), with a 256-byte record length and a 12-byte key.
-
The program initializes variables and clears the screen fields for the first display (
$SBLK
subroutine, lines 0084–0105).- Clears arrays (
CUS
,CUNM
,SLO
,SLN
,SLNM
,DL
) and sets the initial screen format toS1
(@SFNEX = 'S1'
). - Turns off error indicators and sets display indicators (e.g., 99, 81) to control screen behavior.
- Clears arrays (
-
Main Processing Loop (
$SFNEX DOWNE 'EJ'
, lines 0068–0079): - The program enters a loop that continues until the user presses a command key to exit (
@SFNEX = 'EJ'
). - Based on the screen format identifier (
@SFID
):- If
@SFID
is blank, it calls$SBLK
to initialize the screen (first-time display). - If
@SFID = 'S1'
, it processes the first screen ($S1
subroutine). - If
@SFID = 'S2'
, it processes the second screen ($S2
subroutine).
- If
-
After processing the screen, it calls
$XCPT
to display the next screen and reads user input from theSCREEN
file (READ SCREEN
, with or without the Last Record indicator based on@CCNT
). -
Screen 1 Processing (
$S1
, lines 0108–0115): - Purpose: Collects the company number (
CO
) and an optional customer number (SCUS
) to filter transactions. -
Steps:
- Reads the
S1
screen input (AR190S1
format, lines 0678–0682). - Checks the function key pressed (
@VKEY
): - If
ENTER
(@VKEY = 0
), calls$S1ENT
to validate and process the input. - If a command key is pressed (
@VKEY = 2
), calls$S1CK
to handle command key functions (e.g., exit). - Validation (
$S1ENT
, lines 0118–0146): - Ensures the company number (
CO
) is not zero; if it is, displays error message MSG1 ("COMPANY NUMBER CANNOT BE BLANK") and sets indicator 90 (error) and 81 (highlight field). - Validates
CO
against theARCONT
file usingCHAIN
. If not found, displays MSG2 ("COMPANY NOT IN CONTROL FILE") and sets error indicators. - If valid, sets up keys (
FRKEY
,TOPKEY
,BOTKEY
) for accessingARSLST
and moves to screenS2
by setting@SFNEX = 'S2'
. - Calls
$S2RFW
to populate screenS2
with transaction data. - Command Keys (
$S1CK
, lines 0149–0154): - If command key
KG
is pressed, sets@SFNEX = 'EJ'
to exit the program.
- Reads the
-
Screen 2 Processing (
$S2
, lines 0157–0166): - Purpose: Displays and allows editing of up to 10 salesman change transactions, including customer number (
CUS
), old salesman code (SLO
), new salesman code (SLN
), salesman name (SLNM
), and delete code (DL
). -
Steps:
- Reads the
S2
screen input (AR190S2
format, lines 0683–0694). - Checks the function key pressed (
@VKEY
): - If
ENTER
(@VKEY = 0
), calls$S2ENT
to validate and update transactions. - If a command key is pressed (
@VKEY = 2
), calls$S2CK
to handle command keys (e.g., exit or return toS1
). - If
ROLL UP
(@VKEY = 01122
), calls$S2RFW
to display the next set of records. - If
ROLL DOWN
(@VKEY = 01123
), calls$S2RBW
to display the previous set of records.
- Reads the
-
Screen 2 Validation and Update (
$S2ENT
, lines 0169–0334): - Validation Loop (lines 0173–0288):
- Iterates through the 10 transaction lines (
X = 1 to 10
). - For each line where
DL,X ≠ 'D'
(not marked for deletion): - Customer Validation:
- If a salesman is keyed (
SLN,X ≠ 0
) but no customer is provided (CUS,X = 0
), sets error indicators (70–79) and displays MSG3 ("CUSTOMER CANNOT BE ZERO") and MSG4 ("WHEN NEW SALESMAN IS KEYED"). - If a customer is keyed (
CUS,X ≠ 0
), validates it againstARCUST
usingCHAIN
. If not found, sets error indicators (70–79) and displays MSG5 ("INVALID CUSTOMER NUMBER"). - If valid, retrieves the customer name (
ARNAME
toCUNM,X
) and old salesman code (ARSLMN
toSLO,X
).
- If a salesman is keyed (
- New Salesman Validation:
- If a customer is keyed, validates the new salesman code (
SLN,X
) againstGSTABL
usingCHAIN
with keySLSMAN + SLN,X
. If not found, sets error indicators (60–69) and displays MSG6 ("INVALID NEW SALESMAN CODE"). - If valid, retrieves the salesman name (
TBDESC
toSLNM,X
). - Note: A validation check for
SLN,X ≠ SLO,X
(new salesman different from old) was removed on 09/27/17, per the comment on line 0247.
- If a customer is keyed, validates the new salesman code (
- Delete Code Validation:
- If a customer is keyed, checks if the delete code (
DL,X
) is' '
,'A'
, or'D'
. If invalid, sets error indicators (40–49) and displays MSG7 ("DELETE CODE MUST BE ' ',A, OR D").
- If a customer is keyed, checks if the delete code (
- If any validation errors occur, jumps to
ENDS2E
to redisplay the screen with error messages.
- Iterates through the 10 transaction lines (
-
Update Transactions (lines 0294–0315):
- Iterates through the 10 transaction lines again.
- For each line with a customer number (
CUS,X ≠ 0
): - Builds a key (
FRKEY = CO + CUS,X
) and checksARSLST
usingCHAIN
. - If
DL,X ≠ 'D'
:- If the record exists (
95 off
), updates it (EXCPTUPDREC
). - If the record doesn’t exist (
95 on
), adds it (EXCPTADDREC
).
- If the record exists (
- If
DL,X = 'D'
and the record doesn’t exist (95 off
), deletes it (EXCPTDELREC
). - Updates
BOTKEY
andSVKEY
to track the highest key processed. - If the last line has a customer (
CUS,10 > 0
), setsS2FULL = 'Y'
to indicate a full screen. - If no records are entered (
CUS,10 = 0
andSLN,10 = 0
), returns to screenS1
(@SFNEX = 'S1'
) and clears fields (CLRFLD
). - Otherwise, calls
$S2RFW
to refresh the screen with the next set of records and sets@SFNEX = 'S2'
.
-
Roll Up (Forward) (
$S2RFW
, lines 0351–0484): - Populates screen
S2
with the next set of records fromARSLST
starting atBOTKEY
. - Clears arrays (
CUS
,CUNM
,SLO
,SLN
,SLNM
,DL
) and resets indicators. - Reads
ARSLST
sequentially, filtering by company number (ASCO = CO
). - For each valid record (up to 10):
- Copies data to screen arrays (
ASCUST
toCUS,Y
,ASSLSO
toSLO,Y
,ASSLSN
toSLN,Y
,ASDEL
toDL,Y
). - Retrieves customer name from
ARCUST
and salesman name fromGSTABL
. - If the record is marked deleted (
ASDEL = 'D'
), displays MSG8 ("THIS RECORD PREVIOUSLY DELETED"). - Sets indicators (50–59, 60–69) to protect fields for existing records.
- Copies data to screen arrays (
- Updates
TOPKEY
andBOTKEY
to track the range of displayed records. - If the end of the file is reached, displays MSG9 ("END OF FILE HAS BEEN REACHED") and calls
RESET
to redisplay the last screen. -
If fewer than 10 records are read and
S2FULL ≠ 'Y'
, clears remaining fields. -
Roll Down (Backward) (
$S2RBW
, lines 0539–0615): - Populates screen
S2
with the previous set of records fromARSLST
starting atTOPKEY
. - Reads
ARSLST
in reverse (READP
) until 10 records are loaded or the beginning of the file is reached. - Similar to
$S2RFW
, copies data to screen arrays, retrieves names, and sets indicators. - If the beginning of the file is reached, displays MSG10 ("BEGINNING OF FILE HAS BEEN REACHED").
-
Updates
TOPKEY
andBOTKEY
accordingly. -
Screen 2 Command Keys (
$S2CK
, lines 0337–0348): - If command key
KA
is pressed, clears fields (CLRFLD
) and returns to screenS1
(@SFNEX = 'S1'
). -
If command key
KG
is pressed, exits the program (@SFNEX = 'EJ'
). -
Display Next Screen (
$XCPT
, lines 0618–0637): - Increments a counter (
@CCNT
) to track screen displays. - Displays the appropriate screen based on
@SFNEX
:- If
@SFNEX = 'S1'
, outputs theAR190S1
format. - If
@SFNEX = 'S2'
, outputs theAR190S2
format.
- If
-
Calls
CLRIND
to reset error indicators and clear message fields (MSG1
,MSG2
). -
Field and Indicator Clearing:
- CLRIND (lines 0640–0662): Resets error indicators (40–49, 60–69, 70–79, 90, 91, etc.) and clears message fields.
- CLRFLD (lines 0665–0675): Clears screen arrays (
CUS
,CUNM
,SLO
,SLN
,SLNM
,DL
) andS2FULL
.
-
Output Operations:
- ADDREC (lines 0696–0701): Adds a new record to
ARSLST
with company number (CO
), customer number (CUS,X
), old salesman (SLO,X
), and new salesman (SLN,X
). - UPDREC (lines 0703–0706): Updates an existing
ARSLST
record with delete code (DL,X
), old salesman (SLO,X
), and new salesman (SLN,X
). - DELREC (line 0708): Deletes a record from
ARSLST
.
- ADDREC (lines 0696–0701): Adds a new record to
Business Rules¶
The program enforces the following business rules for managing salesman change transactions:
- Company Number Validation:
- The company number (
CO
) must not be blank/zero (MSG1: "COMPANY NUMBER CANNOT BE BLANK"). -
The company number must exist in the
ARCONT
file (MSG2: "COMPANY NOT IN CONTROL FILE"). -
Customer Number Validation:
- If a new salesman code (
SLN,X
) is entered, a customer number (CUS,X
) must be provided (MSG3: "CUSTOMER CANNOT BE ZERO" and MSG4: "WHEN NEW SALESMAN IS KEYED"). -
The customer number must exist in the
ARCUST
file (MSG5: "INVALID CUSTOMER NUMBER"). -
Salesman Code Validation:
- The new salesman code (
SLN,X
) must exist in theGSTABL
file under theSLSMAN
table (MSG6: "INVALID NEW SALESMAN CODE"). -
A previous rule requiring the new salesman to differ from the old salesman (
SLN,X ≠ SLO,X
) was removed on 09/27/17 (lines 0247–0264). -
Delete Code Validation:
- The delete code (
DL,X
) must be' '
(blank),'A'
, or'D'
(MSG7: "DELETE CODE MUST BE ' ',A, OR D"). -
If
DL,X = 'D'
, the record is marked for deletion, and if it doesn’t exist inARSLST
, it is deleted viaEXCPTDELREC
. -
Transaction Processing:
- If a customer number is entered:
- If the record exists in
ARSLST
andDL,X ≠ 'D'
, it is updated (UPDREC
). - If the record does not exist and
DL,X ≠ 'D'
, it is added (ADDREC
). - If the record does not exist and
DL,X = 'D'
, it is deleted (DELREC
).
- If the record exists in
-
Deleted records in
ARSLST
(ASDEL = 'D'
) are flagged with MSG8 ("THIS RECORD PREVIOUSLY DELETED"). -
Screen Navigation:
- Screen
S1
collects the company number and optional customer number. - Screen
S2
displays up to 10 transactions and supports roll-up/roll-down for navigation. - If no records are entered or the end of the file is reached, the program returns to screen
S1
. - The end of the file (
ARSLST
) triggers MSG9 ("END OF FILE HAS BEEN REACHED"). -
The beginning of the file triggers MSG10 ("BEGINNING OF FILE HAS BEEN REACHED").
-
Field Protection:
- Customer numbers for existing records are protected (indicators 50–59) to prevent modification.
-
Error indicators (40–49, 60–69, 70–79) highlight invalid fields on screen
S2
. -
Data Retrieval:
- Customer names are retrieved from
ARCUST
(ARNAME
). - Salesman names are retrieved from
GSTABL
(TBDESC
) for theSLSMAN
table. - The old salesman code is retrieved from
ARCUST
(ARSLMN
) orARSLST
(ASSLSO
).
Tables (Files) Used¶
The following files are used by the AR190
program:
1. SCREEN: Workstation file for user interaction (display/input).
2. ARSLST: Salesman change transaction file (update mode, UF
), stores transaction records with fields:
- ASDEL
(1 byte, delete code: ' '
, 'A'
, or 'D'
).
- ASCO
(company number, positions 2–3).
- ASCUST
(customer number, positions 4–9).
- ASSLSO
(old salesman code, positions 10–11).
- ASSLSN
(new salesman code, positions 12–13).
3. ARCONT: A/R control file (input mode, IF
), contains company data with fields:
- ACNAME
(company name, positions 4–33).
4. ARCUST: Customer master file (input mode, IF
), contains customer data with fields:
- ARNAME
(customer name, positions 10–39).
- ARSLMN
(salesman code, positions 263–264).
5. GSTABL: General table file (input mode, IF
), contains reference data (e.g., salesman codes) with fields:
- TBDESC
(table description, e.g., salesman name, positions 14–43).
External Programs Called¶
The AR190
program does not explicitly call any external programs (e.g., via CALL
operations). It operates as a standalone program, handling all logic internally through subroutines.
Summary¶
- Process Steps:
- Initializes files and screen fields.
- Uses a main loop to process two screens:
S1
(company/customer input) andS2
(transaction display/edit). - Validates input on
S1
(company number) andS2
(customer, salesman, delete code). - Updates
ARSLST
with add (ADDREC
), update (UPDREC
), or delete (DELREC
) operations. - Supports roll-up/roll-down for browsing transactions.
-
Displays error messages and protects fields as needed.
-
Business Rules:
- Validates company number, customer number, salesman code, and delete code.
- Ensures data consistency with
ARCONT
,ARCUST
, andGSTABL
. - Handles add, update, and delete operations for salesman change transactions.
-
Manages screen navigation and error handling.
-
Tables Used:
SCREEN
,ARSLST
,ARCONT
,ARCUST
,GSTABL
. -
External Programs: None.
If you have additional details (e.g., the AR191.rpg36
code for editing transactions or specific screen layouts), I can provide further analysis or comparisons. Let me know if you’d like me to search for related information or analyze any other uploaded files!