Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

download records from the database tables dynamically

Former Member
0 Kudos

Hi,

I need to download records from the several database tables dynamically into a flat file sequentially? How can I do this. I am already pulling the total number of entries and key fields for each table. How can I do this? The data can be a long string of each record from each table.

Tables: DD02l.

data: lv_tabname(30).

data: itab like dfies occurs 0,

wa_itab like dfies.

DATA : GT_TABROWS LIKE STANDARD TABLE OF DDCDIM,

WA_TABROWS LIKE DDCDIM.

concatenate p_table '%' into lv_tabname.

SELECT TABNAME FROM DD02L

INTO CORRESPONDING FIELDS OF TABLE GT_TABROWS

WHERE TABNAME like lv_tabname.

CALL FUNCTION 'EM_GET_NUMBER_OF_ENTRIES'

TABLES

IT_TABLES = GT_TABROWS.

LOOP AT GT_TABROWS INTO WA_TABROWS.

WRITE : / WA_TABROWS-TABNAME , WA_TABROWS-TABROWS.

CALL FUNCTION 'GET_KEY_FIELDS_OF_TABLE'

EXPORTING

TABNAME = WA_TABROWS-TABNAME

MANDT_NEEDED = '100'

TABLES

KEY_FIELDTAB = itab

  • EXCEPTIONS

  • NOT_SUPPORTED = 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.

ENDIF.

Loop at itab into wa_itab.

write: /10 wa_itab-fieldname.

endloop.

uline.

ENDLOOP.

2 REPLIES 2

Former Member
0 Kudos

Hi Vinu,

Instead of using this approach, you can dynamcially create an internal table of any type using the database table. You can do this using SAP runtime type identifier (RTTI). Belw is some sample code.

FORM f110_create_table_type .

DATA: go_struct TYPE REF TO cl_abap_structdescr,

go_table TYPE REF TO cl_abap_tabledescr,

FIELD-SYMBOLS:

<gi_data> TYPE STANDARD TABLE.

  • Dynamically getting the line type of the specified table

go_struct ?= cl_abap_typedescr=>describe_by_name( p_tname ) .

TRY.

CALL METHOD cl_abap_tabledescr=>create

EXPORTING

p_line_type = go_struct

p_table_kind = 'S'

RECEIVING

p_result = go_table.

CATCH cx_sy_table_creation .

MESSAGE e000 WITH text-004.

ENDTRY.

  • creating internal table of table type just created

CREATE DATA gi_data TYPE HANDLE go_table.

  • Assigning the internal table to field symbol

ASSIGN gi_data->* TO <gi_data>.

ENDFORM. " F110_CREATE_TABLE_TYPE

    • get the data into the internal table from db table

SELECT * INTO TABLE <gi_data> FROM (p_tname).

In this approach you won't have to worry about the no. of fields etc

0 Kudos

Solved myself.

Thanx

VG