Here is the Main concept of eliminating the high percentage of identical selects by local buffer.
Two internal tables (A and B) are defined to buffer the result of the “select statement “ on table bseg. Table A is for the search criteria that is existing in the database and table B is for the search criteria that is not existing in the database.
- Read internal table A, if existing, return the value. If not go to step 3.
- Read internal table B for the record that does not exist in the database, if it doesnot exist in the buffer, go to step 4.
- Make the database access and fetch the record and log the result in the two internal tables.
types: begin of s_bseg,
bukrs like bseg-bukrs,
gjahr like bseg-gjahr,
belnr like bseg-belnr,
buzei like bseg-buzei,
wskto like bseg-wskto,
shkzg like bseg-shkzg,
end of s_bseg.
data: itb_bseg_found type sorted table of s_bseg with non-unique key bukrs gjahr belnr buzei,
itb_bseg_notfound type sorted table of s_bseg with non-unique key bukrs gjahr belnr buzeiwa_bseg s_bseg.
Read table itb_bseg_found into wa_bseg with key
bukrs = bsas-bukrs
gjahr = bsas-gjahr
belnr = bsas-belnr
buzei = bsas-buzei.
if sy-subrc = 0.
bseg-wskto = wa_bseg-wskto.
bseg-shkzg = wa_bseg-shkzg.
else.
Read table itb_bseg_notfound transporting no fields with key
bukrs = bsas-bukrs
gjahr = bsas-gjahr
belnr = bsas-belnr
buzei = bsas-buzei.
if sy-subrc <> 0.
SELECT SINGLE wskto shkzg
FROM bseg
INTO (bseg-wskto, bseg-shkzg)
WHERE bukrs = bsas-bukrs AND
gjahr = bsas-gjahr AND
belnr = bsas-belnr AND
buzei = bsas-buzei.
wa_bseg-bukrs = bsas-bukrs.
wa_bseg-gjahr = bsas-gjahr.
wa_bseg-belnr = bsas-belnr.
wa_bseg-buzei = bsas-buzei.
wa_bseg-wskto = bseg-wskto.
wa_bseg-shkzg = bseg-shkzg.
if sy-subrc = 0.
insert wa_bseg into table itb_bseg_found.
else.
insert wa_bseg into table itb_bseg_notfound.
endif.
endif.
endif.
Note: Change the data type of internal tables itb_bseg_found and itb_bseg_notfound to statistics if this is
called in the funcational module or form.
Welcome to comment on this topic.