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

Class:cl_salv_table

Former Member
0 Likes
2,260

Hi Experts,

I have to use Class cl_salv_table for displaying the ALV grid.I have created a Dynamic Fieldcatalog,with their field headings values coming from a internal table.When we use this class,we do not pass the internal table of Fieldcatalog.how do we define the fieldcatalog for the same.

*Dynamic fields
    LOOP AT i_tckh3 INTO w_tckh3.
      LOOP AT i_tckh1 INTO w_tckh1 WHERE elemt = w_tckh3-elemt.
        lcount = lcount + 1.
        WRITE w_tckh1-txele TO w_fieldcat-seltext   LEFT-JUSTIFIED.
        CONCATENATE 'KST' w_tckh3-el_hv INTO w_fieldcat-fieldname.
        TRANSLATE w_fieldcat-fieldname              TO UPPER CASE.
        w_fieldcat-col_pos   =  lcount.
        w_fieldcat-ref_field = 'KST001'.
        w_fieldcat-ref_table = 'KEPH'.
        w_fieldcat-datatype  = 'CURR'.
        APPEND w_fieldcat TO i_fieldcat.
        CLEAR  w_fieldcat.
        CLEAR: w_tckh1.
      ENDLOOP.
      CLEAR:w_tckh3.
    ENDLOOP.

CALL METHOD cl_salv_table=>factory
*      EXPORTING
*        list_display   = IF_SALV_C_BOOL_SAP=>FALSE
*        r_container    =
*        container_name =
            IMPORTING
              r_salv_table   = gr_table
            CHANGING
            t_table        = <i_table>.

When I was using Method:set_table_for_first_display the output was coming correct.Now I am having problem displaying the header of the columns.Please advice.

Thanks.

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
2,108

Hi again:)

You don't need to create fieldcatalog when using cl_salv... classes. You simply pass your internal table and factory method will create fieldcat for you.

So you only need to change column header if you want. Please refer

Regards

Marcin

Hi Experts,

I have to use Class cl_salv_table for displaying the ALV grid.I have created a Dynamic Fieldcatalog,with their field headings values coming from a internal table.When we use this class,we do not pass the internal table of Fieldcatalog.how do we define the fieldcatalog for the same.

*Dynamic fields
    LOOP AT i_tckh3 INTO w_tckh3.
      LOOP AT i_tckh1 INTO w_tckh1 WHERE elemt = w_tckh3-elemt.
        lcount = lcount + 1.
        WRITE w_tckh1-txele TO w_fieldcat-seltext   LEFT-JUSTIFIED.
        CONCATENATE 'KST' w_tckh3-el_hv INTO w_fieldcat-fieldname.
        TRANSLATE w_fieldcat-fieldname              TO UPPER CASE.
        w_fieldcat-col_pos   =  lcount.
        w_fieldcat-ref_field = 'KST001'.
        w_fieldcat-ref_table = 'KEPH'.
        w_fieldcat-datatype  = 'CURR'.
        APPEND w_fieldcat TO i_fieldcat.
        CLEAR  w_fieldcat.
        CLEAR: w_tckh1.
      ENDLOOP.
      CLEAR:w_tckh3.
    ENDLOOP.

CALL METHOD cl_salv_table=>factory
*      EXPORTING
*        list_display   = IF_SALV_C_BOOL_SAP=>FALSE
*        r_container    =
*        container_name =
            IMPORTING
              r_salv_table   = gr_table
            CHANGING
            t_table        = <i_table>.

When I was using Method:set_table_for_first_display the output was coming correct.Now I am having problem displaying the header of the columns.Please advice.

Thanks.

8 REPLIES 8
Read only

MarcinPciak
Active Contributor
0 Likes
2,109

Hi again:)

You don't need to create fieldcatalog when using cl_salv... classes. You simply pass your internal table and factory method will create fieldcat for you.

So you only need to change column header if you want. Please refer

Regards

Marcin

Read only

0 Likes
2,108

Hi Marcin,

nice to see your reply.Its the same problem of the previous thread.BUT now we are using a different Class.

I get the ALV displayed by default without passing the internal table fieldcatalog for the columns, but the Field names need to be assigned to the dynamic fields.

*Dynamic fields
    LOOP AT i_tckh3 INTO w_tckh3.
      LOOP AT i_tckh1 INTO w_tckh1 WHERE elemt = w_tckh3-elemt.
        lcount = lcount + 1.
        WRITE w_tckh1-txele TO w_fieldcat-seltext   LEFT-JUSTIFIED.
        WRITE w_tckh1-txele TO w_fieldcat-coltext   LEFT-JUSTIFIED.
        CONCATENATE 'KST' w_tckh3-el_hv INTO w_fieldcat-fieldname.
        TRANSLATE w_fieldcat-fieldname              TO UPPER CASE.
        w_fieldcat-col_pos   =  lcount.
        w_fieldcat-ref_field = 'KST001'.
        w_fieldcat-ref_table = 'KEPH'.
        w_fieldcat-datatype  = 'CURR'.
        APPEND w_fieldcat TO i_fieldcat.
        CLEAR  w_fieldcat.
        CLEAR: w_tckh1.
      ENDLOOP.
      CLEAR:w_tckh3.
    ENDLOOP.

any specific method i can use to solve this issue.

thanks.

I Hope you got the points assigned for the last thread.

Read only

0 Likes
2,108

Yes, I got the points, thank you:)

As for the issue, I think you don't need to worry about fieldcatalog. You pass the dynamic table, system creates internally fieldcatalog for you. The only required change is that you need to assign repective coulmn header to based on dynamic table (or fieldcatlaog).

So after factory method is called, you first...


"...get  all the ALV columns 
 data: lr_columns type ref to cl_salv_columns_table,
        lr_column  type ref to cl_salv_column_table.
 
  lr_columns = gr_table->get_columns( ). 

...and then change caption for each column one by one


LOOP AT i_tckh1 INTO w_tckh1 WHERE elemt = w_tckh3-elemt.
       ....     
        CONCATENATE 'KST' w_tckh3-el_hv INTO w_fieldcat-fieldname.
        TRANSLATE w_fieldcat-fieldname              TO UPPER CASE.

      
      lr_column ?= lr_columns->get_column( w_fieldcat-fieldname ).  "get this column from ALV
      lr_column->set_short_text( w_tckh1-txele ).  "set  text for it
      lr_column->set_medium_text( w_tckh1-txele ).
      lr_column->set_long_text( w_tckh1-txele  ).
...
endloop.

So this way you do a change directly on fieldcatalog which was created by the system. Now when you refresh the output you will have correct headers for your dynamic table.

Regards

Marcin

Read only

0 Likes
2,108

HI Marcin,

Thats perfectly Great option

but when we have assigend

lr_column->set_long_text( w_tckh1-txele  )

its giving error:

W_tckh1-txele is not TYPE COMPATIBLE with formal parameter "VALUE".

Read only

2,108

You need to cast it first, as the method expects parameter of different type:


data: m_text type SCRTEXT_M,
         s_text type SCRTEXT_S,
         l_text type SCRTEXT_L.

s_text = m_text = l_text = w_tckh1-txele.
lr_column->set_short_text( s_text ).  
lr_column->set_medium_text( m_text ).
lr_column->set_long_text( l_text  ).

This should help

Marcin

Read only

0 Likes
2,108

Thanks Marcin,

You are an SAP Expert

Read only

0 Likes
2,108

Wish I would be one;)

Cheers

Read only

0 Likes
2,108

You sure are!!!

I have worked on Dynamic Fieldcatalog and internal table for the first time,and I don't think I would have been able to complete the code without your help.

Your prompt responses made it easy and clear to understand as to what the procedure is.

Thanks