Application Development and Automation 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: 
Read only

Dynamic Report

Former Member
0 Likes
648

Hi,

I'm trying to create a report where I enter a table name as a text field then the program must look if this table exist and export the table data to csv. The csv part is easy, it's linking a text value to a table object that proves difficult. Any ideas?

Thanks,

Jan

1 ACCEPTED SOLUTION
Read only

egenoves
Participant
0 Likes
609

Hi Jan,

You can use dynamic SQL statements to read the table

SELECT (table) into table <fs_table>.

Declare <fs_table> like a field symbol of type any table and map it to your CSV file .

Hope its useful,

Best Regards,

4 REPLIES 4
Read only

egenoves
Participant
0 Likes
610

Hi Jan,

You can use dynamic SQL statements to read the table

SELECT (table) into table <fs_table>.

Declare <fs_table> like a field symbol of type any table and map it to your CSV file .

Hope its useful,

Best Regards,

Read only

Former Member
0 Likes
609

Hi,

Thanks I searched for abap dynamic sql select and got this. http://scn.sap.com/thread/1821253

This should work just fine.

Regards,

Jan

Read only

Former Member
0 Likes
609

This message was moderated.

Read only

Former Member
0 Likes
609

Hello,

Please find the logic below.

* We use some parameters to dynamically control the select, this is not very

* clever but this is just a test program !!

PARAMETER : p_tabnam TYPE tabname DEFAULT 'SFLIGHT'.

FIELD-SYMBOLS : <lt_outtab> TYPE ANY TABLE,

                 <ls_outtab> TYPE ANY,

                 <l_fld> TYPE ANY.

DATA:

       lt_sel_list TYPE TABLE OF edpline,

       l_having    TYPE string,

       l_wa_name   TYPE string,

       dref        TYPE REF TO data,

       itab_type   TYPE REF TO cl_abap_tabledescr,

       struct_type TYPE REF TO cl_abap_structdescr,

       elem_type   TYPE REF TO cl_abap_elemdescr,

       comp_tab    TYPE cl_abap_structdescr=>component_table,

       comp_fld    TYPE cl_abap_structdescr=>component.

TYPES: f_count TYPE i.

* Creation of the output table including a non standard field, f_count

* see ABAP FAQ #14 for more information on this topic

struct_type ?= cl_abap_typedescr=>describe_by_name( p_tabnam ).

elem_type   ?= cl_abap_elemdescr=>describe_by_name( 'F_COUNT' ).

comp_tab = struct_type->get_components( ).

comp_fld-name = 'F_COUNT'.

comp_fld-type = elem_type.

APPEND comp_fld TO comp_tab.

struct_type = cl_abap_structdescr=>create( comp_tab ).

itab_type   = cl_abap_tabledescr=>create( struct_type ).

l_wa_name = 'l_WA'.

CREATE DATA dref TYPE HANDLE itab_type.

ASSIGN dref->* TO <lt_outtab>.

CREATE DATA dref TYPE HANDLE struct_type.

ASSIGN dref->* TO <ls_outtab>.

* Creation of the selection fields and the "group by" clause

APPEND 'COUNT(*) AS F_COUNT' TO lt_sel_list.

* Creation of the "having" clause

l_having = 'count(*) >= 1'.

* THE dynamic select

SELECT          *

        FROM     (p_tabnam)

        INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>.

* display of the results

LOOP AT <lt_outtab> ASSIGNING <ls_outtab>.

   LOOP AT comp_tab INTO comp_fld.

     ASSIGN COMPONENT comp_fld-name OF STRUCTURE <ls_outtab> TO <l_fld>.

     WRITE: <l_fld>.

   ENDLOOP.

   SKIP.

ENDLOOP.