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 ALV

0 Likes
856

Hi All,

I am working on a scenario where I have to display data(say materials) horizontally. So the columns in the ALV grid will be decided at run time.

Please find the pseudo code below.

Step1: Creating Field catalog


DO lf_line TIMES.

    CONCATENATE 'MATNR' lf_count INTO lv_fieldname.

    CONDENSE lv_fieldname NO-GAPS.

    ls_fcat-fieldname     = lv_fieldname.

    ls_fcat-seltext         = lv_fieldname.

    ls_fcat-datatype      = 'CHAR'.

    ls_fcat-outputlen     = 30.

    ls_fcat-col_pos       = sy-index.

    lf_count = lf_count + 1.

    APPEND ls_fcat TO gt_fldcat1.

  ENDDO.

Step2: Creating data table dynamically

I am using cl_alv_table_create=>create_dynamic_table to get the ref of the table.

Then I am creating table using field symbols and populating the table <fs_table>.

Step3: Display the ALV grid

I am using the below code

CALL METHOD z_grid2->set_table_for_first_display

    EXPORTING

      is_variant      = gs_variant

      is_layout       = ls_layout

    CHANGING

      it_outtab       = <fs_table>

      it_fieldcatalog = gt_fldcat1.

The above code is not working for me. Is there anything I am doing wrong here.

The same code works if I am passing ls_fcat-fieldname = 'MATNR' . But this will be correct only if there is one column.

For that reason I need to concatenate and assign to filedname.

Thanks,

Vijetha.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
799

Does <fs_table> look the way you expected it to look? Also, not sure if this is going to make any difference, but does the ALV class give you the same issues? It's not dependent on the field catalogue, just accepts whatever table you throw at it.

DATA alv TYPE REF TO cl_salv_table.

TRY.

     cl_salv_table=>factory(

       IMPORTING

         r_salv_table = alv

       CHANGING

         t_table      = <fs_table> ).

   CATCH cx_salv_msg.                                    "#EC NO_HANDLER

ENDTRY.

alv->display( ).

4 REPLIES 4
Read only

Former Member
0 Likes
800

Does <fs_table> look the way you expected it to look? Also, not sure if this is going to make any difference, but does the ALV class give you the same issues? It's not dependent on the field catalogue, just accepts whatever table you throw at it.

DATA alv TYPE REF TO cl_salv_table.

TRY.

     cl_salv_table=>factory(

       IMPORTING

         r_salv_table = alv

       CHANGING

         t_table      = <fs_table> ).

   CATCH cx_salv_msg.                                    "#EC NO_HANDLER

ENDTRY.

alv->display( ).

Read only

0 Likes
799

Hello,

I was able to solve the issue using CL_SALV_TABEL.

DATA alv TYPE REF TO cl_salv_table.

  TRY.

      cl_salv_table=>factory(

        EXPORTING

          r_container  = z_cont_head                    "Splitter container ref

        IMPORTING

          r_salv_table = alv

        CHANGING

          t_table      = <fs_table> ).

    CATCH cx_salv_msg.                                  "#EC NO_HANDLER

  ENDTRY.

  alv->display( ).

Thanks,

Vijetha

Read only

RaymondGiuseppi
Active Contributor
0 Likes
799

The above code is not working for me.

Can you elaborate a little on the "not working", are you able to fill the table, are you able to display something incorrect, whatr error are raised by the consistency check, etc.

Regards,

Raymond

Read only

0 Likes
799

Thanks for asking. I am able to populate the table.Gird is not showing any data and there is no exception raised.

Now I am able to populate it using CL_SALV_TABLE.

Regards,

Vijetha