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 for tables

Former Member
0 Likes
677

Hi

i have one requirement like based on the selection screen entered table i should display the contents of the table thru ALV.

Suppose if entered MARA table in the selection screen it should display the entries stpred in the MARA table thru ALV.

Can any one suggest solution for this.

Thanks.

Regards

Raj.

Hi

i have one requirement like based on the selection screen entered table i should display the contents of the table thru ALV.

Suppose if entered MARA table in the selection screen it should display the entries stpred in the MARA table thru ALV.

Can any one suggest solution for this.

Thanks.

Regards

Raj.

4 REPLIES 4
Read only

Former Member
0 Likes
657

Hi,

Execute the code below:

REPORT ZYKTEST3 .

DATA: d_ref TYPE REF TO data,

d_ref2 TYPE REF TO data,

i_alv_cat TYPE TABLE OF lvc_s_fcat,

ls_alv_cat LIKE LINE OF i_alv_cat.

TYPES: tabname LIKE dcobjdef-name ,

fieldname LIKE dcobjdef-name,

desc LIKE dntab-fieldtext.

PARAMETER: p_tablen TYPE tabname.

DATA: BEGIN OF itab OCCURS 0.

INCLUDE STRUCTURE dntab.

DATA: END OF itab.

FIELD-SYMBOLS : <f_fs> TYPE table,

<f_fs1> TYPE table,

<f_fs2> TYPE ANY,

<f_fs3> TYPE ANY,

<f_fs4> type any,

<f_field> TYPE ANY.

REFRESH itab.

CALL FUNCTION 'NAMETAB_GET'

EXPORTING

langu = sy-langu

tabname = p_tablen

TABLES

nametab = itab

EXCEPTIONS

no_texts_found = 1.

LOOP AT itab .

ls_alv_cat-fieldname = itab-fieldname.

ls_alv_cat-ref_table = p_tablen.

ls_alv_cat-ref_field = itab-fieldname.

ls_alv_cat-seltext = itab-fieldtext.

ls_alv_cat-reptext = itab-fieldtext.

APPEND ls_alv_cat TO i_alv_cat.

ENDLOOP.

  • internal table build

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = i_alv_cat

IMPORTING

ep_table = d_ref.

ASSIGN d_ref->* TO <f_fs>.

DATA: l_field TYPE fieldname,

l_field1 type fieldname.

SELECT * FROM (p_tablen) INTO CORRESPONDING FIELDS OF TABLE <f_fs>.

LOOP AT <f_fs> ASSIGNING <f_fs2>.

ASSIGN COMPONENT 2 OF STRUCTURE <f_fs2> TO <f_fs3>.

ASSIGN COMPONENT 3 OF STRUCTURE <f_fs2> TO <f_fs4>.

IF sy-subrc = 0.

MOVE <f_fs3> TO l_field.

MOVE <f_fs4> TO l_field1.

WRITE:/1 l_field(20),

22 l_field1(10).

ENDIF.

ENDLOOP.

Regards

Kannaiah

Read only

Former Member
0 Likes
657

If that is the only requirement why don't you call SE16 from your program. Just pass the table name to SE16.

Read only

0 Likes
657

And yes, if this is the only requirement, Darshil's is right, simply use SE16 or SE16N(for alv grid).

Regards,

Rich Heilman

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
657

This is really easy....... check this program.




report zrich_0001 .

type-pools: slis, abap.

data: it_fldcat type lvc_t_fcat,
      wa_fldcat type lvc_s_fcat.

data: new_table type ref to data,
      new_line  type ref to data.

data: ifc type slis_t_fieldcat_alv.
data: xfc type slis_fieldcat_alv.

field-symbols: <dyn_table> type standard table.

parameters: p_table type dd02l-tabname.

start-of-selection.

call function 'REUSE_ALV_FIELDCATALOG_MERGE'
     exporting
          i_structure_name = p_table
     changing
          ct_fieldcat      = ifc.
loop at ifc into xfc.
  move-corresponding xfc to wa_fldcat.
  append wa_fldcat to it_fldcat.
endloop.

* Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
             exporting
                it_fieldcatalog = it_fldcat
             importing
                ep_table        = new_table.

assign new_table->* to <dyn_table>.

* Select Data from table.
select * into corresponding fields of table <dyn_table>
           from (p_table).

* Fire ALV
call function 'REUSE_ALV_GRID_DISPLAY'
     exporting
          it_fieldcat = ifc
     tables
          t_outtab    = <dyn_table>.

Regards,

Rich Heilman