Files Involved
Physical file TARGET (sales targets file) that has the following fields:
|
RDML Program
<< Define work fields for this function >>
DEFINE FIELD(#ERRCOUNT) TYPE(*DEC) LENGTH(7)
DECIMALS(0)
<< Define group to appear on top of screen >>
GROUP_BY NAME(#TIME) FIELDS(#YEAR #MONTH)
<< Define group that contains all fields to be inserted >>
GROUP_BY NAME(#TARGET) FIELDS(#YEAR #MONTH #BRAND
#QUANTITY #DOLLARS)
<< Define list to be used for data entry >>
DEF_LIST NAME(#VALUES) FIELDS(#BRAND #QUANTITY #DOLLARS)
<< Loop until EXIT or MENU function key used >>
BEGIN_LOOP
<< Clear screen and initialize list with 20 entries >>
CHANGE FIELD(#TARGET) TO(*NULL)
SET_MODE TO(*ADD)
INZ_LIST NAMED(#VALUES) NUM_ENTRYS(20)
<< Accept input until no errors exist in data >>
DOUNTIL COND('#ERRCOUNT = 0')
SET_MODE TO(*ADD)
DISPLAY FIELDS(#TIME) BROWSELIST(#VALUES)
<< Process all not "null" and not "accepted" records >>
CHANGE FIELD(#ERRCOUNT) TO(0)
SELECTLIST NAMED(#VALUES) GET_ENTRYS(*NOTNULL *ADD)
INSERT FIELDS(#TARGET) TO_FILE(TARGET)
VAL_ERROR(L10)
L10 IF_STATUS IS_NOT(*OKAY)
CHANGE FIELD(#ERRCOUNT)
TO('#ERRCOUNT + 1')
SET_MODE TO(*ADD)
ELSE
SET_MODE TO(*DISPLAY)
ENDIF
UPD_ENTRY IN_LIST(#VALUES)
ENDIF
ENDSELECT
ENDUNTIL
END_LOOP
Points to Note:
The fact that a record has been "accepted" or "rejected" by the INSERT command can be indicated to the user by making the following modifications to the RDML commands:
<< Define work fields for this function >>
DEFINE FIELD(#ERRCOUNT) TYPE(*DEC) LENGTH(7) DECIMALS(0)
DEFINE FIELD(#ACCEPTED) TYPE(*CHAR) LENGTH(3)
COLHDG('Target' 'has been' 'Accepted')
<< Define group to appear on top of screen >>
GROUP_BY NAME(#TIME) FIELDS(#YEAR #MONTH)
<< Define group that contains all fields to be inserted >>
GROUP_BY NAME(#TARGET) FIELDS(#YEAR #MONTH #BRAND
#QUANTITY #DOLLARS)
<< Define list to be used for data entry >>
DEF_LIST NAME(#VALUES) FIELDS(#BRAND #QUANTITY
#DOLLARS (#ACCEPTED *OUTPUT))
<< Loop until EXIT or MENU function key used >>
BEGIN_LOOP
<< Clear screen and initialize list with 20 entries >>
CHANGE FIELD(#TIME) TO(*NULL)
CHANGE FIELD(#VALUES) TO(*NULL)
SET_MODE TO(*ADD)
INZ_LIST NAMED(#VALUES) NUM_ENTRYS(20)
<< Accept input until no errors exist in data >>
DOUNTIL COND('#ERRCOUNT = 0')
SET_MODE TO(*ADD)
DISPLAY FIELDS(#TIME) BROWSELIST(#VALUES)
<< Process all not "null" and not "accepted" records >>
CHANGE FIELD(#ERRCOUNT) TO(0)
SELECTLIST NAMED(#VALUES) GET_ENTRYS(*NOTNULL *ADD)
INSERT FIELDS(#TARGET) TO_FILE(TARGET)
VAL_ERROR(L10)
L10 IF_STATUS IS_NOT(*OKAY)
CHANGE FIELD(#ERRCOUNT) TO('#ERRCOUNT + 1')
SET_MODE TO(*ADD)
ELSE
SET_MODE TO(*DISPLAY)
CHANGE FIELD(#ACCEPTED) TO(YES)
ENDIF
UPD_ENTRY IN_LIST(#VALUES)
ENDIF
ENDSELECT
ENDUNTIL
END_LOOP
The main processing loop of the program could be modified to allow updates to "accepted" records like this:
<< Define work fields for this function >>
DEFINE FIELD(#ERRCOUNT) TYPE(*DEC) LENGTH(7) DECIMALS(0)
DEFINE FIELD(#ADD_RRN) TYPE(*DEC) LENGTH(15) DECIMALS(0)
DEFINE FIELD(#ACCEPTED) TYPE(*CHAR) LENGTH(3)
COLHDG('Target' 'has been' 'Accepted')
<< Define group to appear on top of screen >>
GROUP_BY NAME(#TIME) FIELDS(#YEAR #MONTH)
<< Define group that contains all fields to be inserted >>
GROUP_BY NAME(#TARGET) FIELDS(#YEAR #MONTH #BRAND
#QUANTITY #DOLLARS)
<< Define list to be used for data entry >>
DEF_LIST NAME(#VALUES) FIELDS(#BRAND #QUANTITY #DOLLARS
(#ACCEPTED *OUTPUT)(#ADD_RRN *HIDDEN))
<< Loop until EXIT or MENU function key used >>
BEGIN_LOOP
<< Clear screen and initialize list with 20 entries >>
CHANGE FIELD(#TIME) TO(*NULL)
CHANGE FIELD(#VALUES) TO(*NULL)
SET_MODE TO(*ADD)
INZ_LIST NAMED(#VALUES) NUM_ENTRYS(20)
DOUNTIL COND('#ERRCOUNT = 0')
SET_MODE TO(*ADD)
DISPLAY FIELDS(#TIME) BROWSELIST(#VALUES)
<< Process all not "null" records >>
CHANGE FIELD(#ERRCOUNT) TO(0)
SELECTLIST NAMED(#VALUES) GET_ENTRYS(*NOTNULL)
IF COND('#ACCEPTED = YES')
UPDATE FIELDS(#TARGET) IN_FILE(TARGET) VAL_ERROR(L10)
WITH_RRN(#ADD_RRN)
ELSE
INSERT FIELDS(#TARGET) TO_FILE(TARGET)
VAL_ERROR(L10) RETURN_RRN(#ADD_RRN)
ENDIF
L10 IF_STATUS IS_NOT(*OKAY)
CHANGE FIELD(#ERRCOUNT) TO('#ERRCOUNT + 1')
ELSE
CHANGE FIELD(#ACCEPTED) TO(YES)
ENDIF
SET_MODE TO(*ADD)
UPD_ENTRY IN_LIST(#VALUES)
ENDIF
ENDSELECT
ENDUNTIL
END_LOOP