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: 

Dynamic ALV with field catalog and inner join

Former Member
0 Kudos
1,706

Greetings fellow abap programmers.

Lets start of with that i am a new programmer learning my way trough error jungle.

I have a assignment to link three tables and display it in a ALV grid.

My question is as followed: How can i create a dynamic field catalog by using the internal table that has been defined and then pass this structure / catalog to reuse_alv_grid_merge.

What i like the program to do:

1. create a field catalog / structure based on the defined internal table structure.

2. pass this structure and the internal table data to 'REUSE_ALV_GRID_MERGE' or display.

And yes i have done research before posting.

like there are three ways to use ALV: Manuel, automatic, semi, automatic.

1. First off all i refuse to code the Manuel way,

2. the automatic works but it forces me to create a database table that is matching internal table.

3. semi automatic does not quite what i what to do.

My code and comments are in bold for extra information:

REPORT z_training_4_material_report.

< Table structure is defined, but removed to compact code>


data :

           pt_fieldcat         type                   lvc_t_fcat,

           wa_mara           type                   ts_mara,

           it_mara2            type standard table of ts_mara,

           it_mara              type standard table of ts_mara with header line initial size 0.

selection-screen begin of block range_select.

select-options : so_matnr for lv_mat_nr.

select-options : so_plnnr for lv_plant.

selection-screen end of block range_select.

select mara~matnr makt~maktx mara~brgew mara~ntgew marc~werks t024d~dsnam mara~meins marc~strgr marc~disls

into corresponding fields of table it_mara from mara

inner join marc on marc~matnr = mara~matnr

inner join makt on makt~matnr = mara~matnr

inner join t024d on marc~werks = t024d~werks

where mara~matnr between so_matnr-low and so_matnr-high.

<found this form code on forum and tried to use it to create the field catalog but it has a type issue. when looking this up i tried changing the type but that did not do it. >


perform create_fieldcatalog

using it_mara2

changing pt_fieldcat.

call function 'REUSE_ALV_GRID_MERGE'

   exporting

     it_fieldcat = pt_fieldcat

   tables

     t_outtab    = it_mara.

.

*&---------------------------------------------------------------------*

*& Form  create_fieldcatalog

*&---------------------------------------------------------------------*

* Create a field catalogue from any internal table

*----------------------------------------------------------------------*

*      -->PT_TABLE     Internal table

*      -->PT_FIELDCAT  Field Catalogue

*----------------------------------------------------------------------*

form  create_fieldcatalog

        using     pt_table     type standard table

        changing  pt_fieldcat  type lvc_t_fcat.

   data:

     lr_tabdescr type ref to cl_abap_structdescr

   , lr_data     type ref to data

   , lt_dfies    type ddfields

   , ls_dfies    type dfies

   , ls_fieldcat type lvc_s_fcat

   .

   clear pt_fieldcat.

   create data lr_data like line of pt_table.

   lr_tabdescr ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ).

   lt_dfies = cl_salv_data_descr=>read_structdescr( lr_tabdescr ).

   loop at lt_dfies

   into    ls_dfies.

     clear ls_fieldcat.

     move-corresponding ls_dfies to ls_fieldcat.

     append ls_fieldcat to pt_fieldcat.

   endloop.

endform.                    "create_fieldcatalog

1 ACCEPTED SOLUTION

Former Member
0 Kudos
517

Hello,

After some further research i finally found a solution to create a field catalog automatically.

there were different approaches like using a class. if other poeple stumble uppon this problem i hereby link the references used by myself to come to the solution.

Sources:

Working example and simple use

Create conversion based on abap class

Variant ALV programs

ALV guide

1 REPLY 1

Former Member
0 Kudos
518

Hello,

After some further research i finally found a solution to create a field catalog automatically.

there were different approaches like using a class. if other poeple stumble uppon this problem i hereby link the references used by myself to come to the solution.

Sources:

Working example and simple use

Create conversion based on abap class

Variant ALV programs

ALV guide