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: 

How to write dynamic report

Former Member
0 Kudos

Hi experts ,

I am Manish and I want to write a dynamic report . i want to to write a report just like Table Contral Wizard in screen painter .

My requirement is

i want to see the data of different db tables . But i dont have the authorization of Se11 , Se12 , Se16 , Se80 , etc .

So i will write a report and declare a internal table like that db table and in the selection screen i declare i the primary keys of the table . the output will be ALV

grid .

So i want to doo this dynamicall .

I will write a report and when i execute it

it will ask for report name ,

internal table name ,

selection- screen fields ,

type of output .

thanks and regards

Manish Kumar

2 REPLIES 2

former_member189059
Active Contributor
0 Kudos

Search the forums for subroutines.. you will get some help

Former Member
0 Kudos

Hi Manish,

First of all to perform any dynamic creation you should understand fieldsymbol and then proceed.

The following sample report shows you how to create complex structures (and table types) dynamically.

REPORT zus_sdn_rtti_create_structur_1.

TYPE-POOLS: abap.

DATA:

celltab TYPE lvc_t_styl.

DATA:

gd_tabnam TYPE string,

gd_tabfield TYPE string,

go_table TYPE REF TO cl_salv_table,

go_sdescr TYPE REF TO cl_abap_structdescr,

go_sdescr_new TYPE REF TO cl_abap_structdescr,

go_tdescr TYPE REF TO cl_abap_tabledescr,

gdo_data TYPE REF TO data,

gdo_handle TYPE REF TO data,

gs_component TYPE abap_compdescr,

gs_comp TYPE abap_componentdescr,

gt_components TYPE abap_component_tab.

*

  • name TYPE string,

  • type TYPE REF TO cl_abap_datadescr,

  • as_include TYPE abap_bool,

  • suffix TYPE string,

FIELD-SYMBOLS:

<gt_itab> TYPE STANDARD TABLE.

PARAMETER:

p_tabnam TYPE tabname DEFAULT 'KNB1'.

START-OF-SELECTION.

" Describe structure

go_sdescr ?= cl_abap_structdescr=>describe_by_name( p_tabnam ).

gd_tabnam = go_sdescr->get_relative_name( ).

  • Simulate dynamic addition of columns to ALV list

DO 5 TIMES.

READ TABLE go_sdescr->components INTO gs_component INDEX syst-index.

" Build fieldname

CONCATENATE gd_tabnam gs_component-name INTO gd_tabfield

SEPARATED BY '-'.

CLEAR: gs_comp.

gs_comp-type ?= cl_abap_datadescr=>describe_by_name( gd_tabfield ).

gs_comp-name = gs_component-name.

APPEND gs_comp TO gt_components.

go_sdescr_new = cl_abap_structdescr=>create( gt_components ).

go_tdescr = cl_abap_tabledescr=>create( go_sdescr_new ).

" Create data refence followed by table creation

CREATE DATA gdo_handle TYPE HANDLE go_tdescr.

ASSIGN gdo_handle->* TO <gt_itab>.

  • Dynamic select

SELECT * FROM (p_tabnam)

INTO CORRESPONDING FIELDS OF TABLE <gt_itab>

WHERE bukrs = '2000'.

TRY.

CALL METHOD cl_salv_table=>factory

IMPORTING

r_salv_table = go_table

CHANGING

t_table = <gt_itab>.

go_table->display( ).

CATCH cx_salv_msg .

ENDTRY.

ENDDO.

" Display component list in order to prove that indeed the field names

" are used (instead of the data element names)

TRY.

CALL METHOD cl_salv_table=>factory

IMPORTING

r_salv_table = go_table

CHANGING

t_table = gt_components.

go_table->display( ).

CATCH cx_salv_msg .

ENDTRY.

" Add table type as field to structure ==> complex structure

CLEAR: gs_comp.

gs_comp-type ?= cl_abap_typedescr=>describe_by_data( celltab ).

gs_comp-name = 'CELLTAB'.

APPEND gs_comp TO gt_components.

go_sdescr = cl_abap_structdescr=>create( gt_components ).

go_tdescr = cl_abap_tabledescr=>create( go_sdescr ).

CREATE DATA gdo_handle TYPE HANDLE go_tdescr.

ASSIGN gdo_handle->* TO <gt_itab>.

  • Dynamic select

SELECT * FROM (p_tabnam)

INTO CORRESPONDING FIELDS OF TABLE <gt_itab>

WHERE bukrs = '2000'.

" Simplified version of table creation:

CLEAR: gdo_data.

UNASSIGN <gt_itab>.

CREATE DATA gdo_data TYPE STANDARD TABLE OF (p_tabnam).

ASSIGN gdo_data->* TO <gt_itab>.

END-OF-SELECTION.

Reward pts if found usefull

Regards

Sathish