07-14-2008 2:31 PM
I have a report program which is calling a function module . This function module returns all the records from a table. As the table has millions of records, it cant be returned at a time. How can we return N records from a function module and then return Next n records .The Function module and the report program are in different system .
Thanks in Advance.
07-14-2008 2:35 PM
Use open cursor and fetch cursor.
Check the program as in SAP Help.
DATA: BEGIN OF count_line,
carrid TYPE spfli-carrid,
count TYPE i,
END OF count_line,
spfli_tab TYPE TABLE OF spfli.
DATA: dbcur1 TYPE cursor,
dbcur2 TYPE cursor.
OPEN CURSOR dbcur1 FOR
SELECT carrid count(*) AS count
FROM spfli
GROUP BY carrid
ORDER BY carrid.
OPEN CURSOR dbcur2 FOR
SELECT *
FROM spfli
ORDER BY carrid.
DO.
FETCH NEXT CURSOR dbcur1 INTO count_line.
IF sy-subrc <> 0.
EXIT.
ENDIF.
FETCH NEXT CURSOR dbcur2
INTO TABLE spfli_tab PACKAGE SIZE count_line-count.
ENDDO.
CLOSE CURSOR: dbcur1,
dbcur2.
Regards
Kannaiah
07-14-2008 2:34 PM
Hi,
Use package size in your select query.
Check the syntax by pressing F1.
Regards,
Subramanian
07-14-2008 2:35 PM
Use open cursor and fetch cursor.
Check the program as in SAP Help.
DATA: BEGIN OF count_line,
carrid TYPE spfli-carrid,
count TYPE i,
END OF count_line,
spfli_tab TYPE TABLE OF spfli.
DATA: dbcur1 TYPE cursor,
dbcur2 TYPE cursor.
OPEN CURSOR dbcur1 FOR
SELECT carrid count(*) AS count
FROM spfli
GROUP BY carrid
ORDER BY carrid.
OPEN CURSOR dbcur2 FOR
SELECT *
FROM spfli
ORDER BY carrid.
DO.
FETCH NEXT CURSOR dbcur1 INTO count_line.
IF sy-subrc <> 0.
EXIT.
ENDIF.
FETCH NEXT CURSOR dbcur2
INTO TABLE spfli_tab PACKAGE SIZE count_line-count.
ENDDO.
CLOSE CURSOR: dbcur1,
dbcur2.
Regards
Kannaiah
07-14-2008 2:36 PM
Hi Kavuri,
Out of interst iam asking How does open cursor/fetch works.
Regards,
Naveen
07-14-2008 3:03 PM
Hi Naveen,
Open Cursor will get the data from the respective table places that in memory area.
Fetch cursor will fetch the data based on the package size.
Suppose there are 10 sales order and for each sales order there are 10 items and the package size is 10. This means for each header only 10 times can be picked.
Suppose package size is 3. this means it should pick 30 items.
So for the first fetch it will pick 30 items and it will come out of the loop. in the second fetch it will again pick next30 items and continues the same for consecutive loops.
I hope you understood.
Regards
Kannaiah