Skip to content

Instantly share code, notes, and snippets.

@dantesco
Created December 3, 2013 23:28
Show Gist options
  • Save dantesco/7779611 to your computer and use it in GitHub Desktop.
Save dantesco/7779611 to your computer and use it in GitHub Desktop.
select data from large tables
PARAMETERS : P_TABLE TYPE DDOBJNAME.
DATA : DB_CURSOR TYPE CURSOR.
DATA : LT_DFIES TYPE TABLE OF DFIES,
LS_DFIES TYPE DFIES,
STRUC_SIZE TYPE I VALUE 0,
G_PACKAGE_SIZE TYPE I.
FIELD-SYMBOLS : <XTAB> TYPE ANY TABLE.
DATA : L_REFITAB TYPE REF TO DATA.
CREATE DATA L_REFITAB TYPE TABLE OF (P_TABLE).
ASSIGN L_REFITAB->* TO <XTAB>.
* get nametab
CALL FUNCTION 'DDIF_NAMETAB_GET'
EXPORTING
TABNAME = P_TABLE
TABLES
DFIES_TAB = LT_DFIES
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
EXIT.
ENDIF.
** Logic for calculating Package size
* To calculate the memory taken by one record
LOOP AT LT_DFIES INTO LS_DFIES.
STRUC_SIZE = STRUC_SIZE + LS_DFIES-LENG.
ENDLOOP.
***** To calculaten maximum no of records that can be accomodated in 2gb
G_PACKAGE_SIZE = 2147483648 / STRUC_SIZE.
OPEN CURSOR WITH HOLD DB_CURSOR FOR
SELECT * FROM (P_TABLE)
BYPASSING BUFFER.
DO.
*** To Fetch data in chunks of 2gb
FETCH NEXT CURSOR DB_CURSOR
INTO CORRESPONDING FIELDS OF TABLE <XTAB>
PACKAGE SIZE G_PACKAGE_SIZE.
IF SY-SUBRC NE 0.
CLOSE CURSOR DB_CURSOR.
EXIT.
ENDIF.
*** Here do the operation you want on internal table <xtab_buf>
ENDDO.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment