I am selecting data from COEP(CO Object: Line Items (by Period)) table, which has huge data.
The selection is done using OBJNR field, which is part of secondary index.
...
SELECT
objnr
kstar "Cost Element
rbest "Reference Document Number
....
....
INTO CORRESPONDING FIELDS OF TABLE i_covp
FROM covp
FOR ALL ENTRIES IN i_kstar
WHERE lednr EQ c_ledger
AND objnr IN r_objnr
.....
.....
Now this since r_objnr can be represented by Cost Center/Internal Orders or WBS. This can be very large.
If I try to run the program using this in foreground or background. It dumps, because the select statement is not able to cope up with this range r_objnr....
There are 2 options to solve this problem:
1. Convert r_objnr into an internal table and use "for all entries"
2. There is another option I have seen in one of standard SAP program, where the r_objnr is split into several chunks and select is called repeatedly..
PERFORM prepare_sel TABLES r_objnr
r_sel_objnr
USING l_index
CHANGING l_subrc.
WHILE l_subrc EQ 0.
SELECT
objnr
kstar "Cost Element
rbest "Reference Document Number
....
....
INTO CORRESPONDING FIELDS OF TABLE i_covp PACKAGE SIZE 1000
FROM covp
FOR ALL ENTRIES IN i_kstar
WHERE lednr EQ c_ledger
AND objnr IN r_objnr
.....
.....
ADD 1 TO l_record_counter.
IF sy-batch IS INITIAL AND
sy-binpt IS INITIAL.
PERFORM flash_records_read(sapfgrws)
USING l_record_counter.
ENDIF.
endselect.
ADD 1 TO l_index.
PERFORM prepare_sel TABLES r_objnr
r_sel_objnr
USING l_index
CHANGING l_subrc.
ENDWHILE.
Where subroutine prepare_Sel basically picks one record from r_objnr and populates r_sel_objnr.
I wanted to know which of these method is better??
Regards
Add a comment