Page History
The "demand" subroutines described in the previous examples can be generalized and used for any file.
Consider a "generalized" FETCH command like this:
FETCH FIELDS(
...
#FIELD1 #FIELD2 ...
...
#FIELDn)
...
FROM_FILE(FILE)
...
WITH_KEY(
...
#KEY1 ...
...
#KEYn)
...
This can be replaced by executing a "demand" subroutine that exactly emulates the FETCH command like this:EXECUTE SUBROUTINE
EXECUTE SUBROUTINE(GET_FILE)
...
WITH_PARMS(
...
#KEY1 ...
...
#KEYn)
...
The actual "demand" subroutine in generalized format would look like this:SUBROUTINE NAME
SUBROUTINE NAME(GET_FILE)
...
PARMS((
...
#GETKEY1 *RECEIVED)
" "
(
...
#GETKEYn *RECEIVED))
...
DEFINE FIELD(#GETKEY1)
...
REFFLD(#KEY1)
" " " "
...
DEFINE FIELD(#GETKEYn)
...
REFFLD(#KEYn)
...
DEF_LIST NAME(#FILE)
...
FIELDS(
...
#KEY1 ...
...
#KEYn #FIELD1 ...
...
#FIELDn)
TYPE(*WORKING)
...
ENTRYS(as required)
LOC_ENTRY IN_LIST(#FILE)
...
WHERE('(
...
#KEY1 =
...
#GETKEY1)
...
*AND
" " "
(
...
#KEYn =
...
#GETKEYn)')
IF_STATUS IS_NOT(*OKAY)
FETCH FIELDS(
...
#FIELD1 #FIELD2 ...
...
#FIELDn)
...
FROM_FILE(FILE)
WITH_KEY(
...
#GETKEY1 ...
...
#GETKEYn)
ADD_ENTRY TO_LIST(#FILE)
ENDIF
Points to Note:
- This routine does not account for 2 possibilities.
- The first is that the working list may overflow. This could be solved by using the COUNTER parameter on the DEF_LIST command. Before the ADD_ENTRY command the value could be checked and the list cleared (CLR_LIST command) if greater than or equal to the ENTRYS value.
- The second is the fact that the requested record may not be found in either the working list or the database. This could be solved by an IF_STATUS after the FETCH command. If found the record would be added to the working list. If not found appropriate action could be taken (e.g.: ABORT command).