You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

&<img src="../resources/images/opentocr.png" title="Open Contents list" border="0"&>
You are here:

4.3.8.3 Second Improved Example

A further improvement can be made by using "demand" subroutines that exactly emulate the FETCH commands. This could be done like this:
GROUP_BY   NAME(#TRANS) FIELDS(#TRANNUM #TRANDATE #TRANTIME 
           #TRANTYPE #TRANDESC #TRANUSER #TRANSTATE #STATDESC)
 
SELECT     FIELDS(#TRANS) FROM_FILE(TRANS)
EXECUTE    SUBROUTINE(GET_STATE) WITH_PARMS(#TRANSTATE)
EXECUTE    SUBROUTINE(GET_TYPE)  WITH_PARMS(#TRANTYPE)
UPRINT     FIELDS(#TRANS)
ENDSELECT
 
SUBROUTINE NAME(GET_STATE) PARMS((#GETSTATE *RECEIVED))
DEFINE     FIELD(#GETSTATE) REFFLD(#STATCODE)
DEF_LIST   NAME(#STATES) FIELDS(#STATCODE #STATDESC) 
           TYPE(*WORKING) ENTRYS(10)
LOC_ENTRY  IN_LIST(#STATES) WHERE('#STATCODE = #GETSTATE')
IF_STATUS  IS_NOT(*OKAY)
FETCH      FIELDS(#STATES) FROM_FILE(STATES) 
           WITH_KEY(#GETSTATE)
ADD_ENTRY  TO_LIST(#STATES)
ENDIF
ENDROUTINE
 
SUBROUTINE NAME(GET_TYPE) PARMS((#GETTYPE *RECEIVED))
DEFINE     FIELD(#GETTYPE) REFFLD(#TRANTYPE)
DEF_LIST   NAME(#TRNTYP) FIELDS(#TRANTYPE #TRANDESC) 
           TYPE(*WORKING) ENTRYS(50)
LOC_ENTRY  IN_LIST(#TRNTYP) WHERE('#TRANTYPE = #GETTYPE')
IF_STATUS  IS_NOT(*OKAY)
FETCH      FIELDS(#TRNTYP) FROM_FILE(TRNTYP) WITH_KEY(#GETTYPE)
ADD_ENTRY  TO_LIST(#TRNTYP)
ENDIF
ENDROUTINE
 
Since these subroutines are "demand" driven the number of I/Os done depends upon the number of different state and type codes found in the TRANS files.
If the TRANS file contained 3 different state codes and 5 different transaction types then in the case where 10,000 TRANS records were processed the RDML program would do (10,000 + 3 + 5) = 10,008 database accesses. This is a net saving of 19,992 I/Os. This version of the program would probably run in about 1/3 of the time of the original version.
&<img src="../resources/images/opentoc-dark.png" title="Open Contents List" border="0"&>

  • No labels