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

Missing columns headers -when trying to display dynamic tab - cl_salv_table

Former Member
0 Likes
2,470

Hi,

I wrote a small Report that reads dataset from Exelfile into a dynamic Table. After it I would like to display the table with cl_salv_table=>factory function, but there are no columns headers displaying.

Any Ideas ? thanks a lot !

          • MAKE THE DYNAMIC TABLE

DATA:

gr_tabtype TYPE REF TO cl_abap_tabledescr,

gr_struc TYPE REF TO cl_abap_structdescr,

lr_itab TYPE REF TO data,

lv_index TYPE string,

it_component TYPE cl_abap_structdescr=>component_table,

wa_component LIKE LINE OF it_component.

CONSTANTS lc_colums TYPE i VALUE 20."

DO lc_colums TIMES.

lv_index = sy-index.

CONCATENATE 'col' lv_index INTO wa_component-name.

CONDENSE wa_component-name NO-GAPS.

wa_component-type ?= cl_abap_typedescr=>describe_by_name( 'CHAR30' ).

INSERT wa_component INTO TABLE it_component.

ENDDO.

  • Creating new structure-ref ->

CLEAR gr_struc.

CALL METHOD cl_abap_structdescr=>create

EXPORTING

p_components = it_component

RECEIVING

p_result = gr_struc.

  • Creating new table-ref ->

CALL METHOD cl_abap_tabledescr=>create

EXPORTING

p_line_type = gr_struc

RECEIVING

p_result = gr_tabtype.

  • Creating itab with table-ref ->

CREATE DATA lr_itab TYPE HANDLE gr_tabtype.

ASSIGN lr_itab->* TO <gr_xlstab>. "

      • READ FROM EXCEL

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

  • I_FIELD_SEPERATOR =

i_line_header = 'X'

i_tab_raw_data = lt_raw[] " WORK TABLE

i_filename = p_file

TABLES

i_tab_converted_data = <gr_xlstab> "ACTUAL DATA

EXCEPTIONS

conversion_failed = 1

OTHERS = 2.

      • DISPLAY TABLE (with the missing columns header ?)

TRY.

cl_salv_table=>factory(

EXPORTING

list_display = abap_true

IMPORTING

r_salv_table = lo_alv

CHANGING

t_table = <gr_xlstab> ).

CATCH cx_salv_msg .

ENDTRY.

Hi,

I wrote a small Report that reads dataset from Exelfile into a dynamic Table. After it I would like to display the table with cl_salv_table=>factory function, but there are no columns headers displaying.

Any Ideas ? thanks a lot !

          • MAKE THE DYNAMIC TABLE

DATA:

gr_tabtype TYPE REF TO cl_abap_tabledescr,

gr_struc TYPE REF TO cl_abap_structdescr,

lr_itab TYPE REF TO data,

lv_index TYPE string,

it_component TYPE cl_abap_structdescr=>component_table,

wa_component LIKE LINE OF it_component.

CONSTANTS lc_colums TYPE i VALUE 20."

DO lc_colums TIMES.

lv_index = sy-index.

CONCATENATE 'col' lv_index INTO wa_component-name.

CONDENSE wa_component-name NO-GAPS.

wa_component-type ?= cl_abap_typedescr=>describe_by_name( 'CHAR30' ).

INSERT wa_component INTO TABLE it_component.

ENDDO.

  • Creating new structure-ref ->

CLEAR gr_struc.

CALL METHOD cl_abap_structdescr=>create

EXPORTING

p_components = it_component

RECEIVING

p_result = gr_struc.

  • Creating new table-ref ->

CALL METHOD cl_abap_tabledescr=>create

EXPORTING

p_line_type = gr_struc

RECEIVING

p_result = gr_tabtype.

  • Creating itab with table-ref ->

CREATE DATA lr_itab TYPE HANDLE gr_tabtype.

ASSIGN lr_itab->* TO <gr_xlstab>. "

      • READ FROM EXCEL

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

  • I_FIELD_SEPERATOR =

i_line_header = 'X'

i_tab_raw_data = lt_raw[] " WORK TABLE

i_filename = p_file

TABLES

i_tab_converted_data = <gr_xlstab> "ACTUAL DATA

EXCEPTIONS

conversion_failed = 1

OTHERS = 2.

      • DISPLAY TABLE (with the missing columns header ?)

TRY.

cl_salv_table=>factory(

EXPORTING

list_display = abap_true

IMPORTING

r_salv_table = lo_alv

CHANGING

t_table = <gr_xlstab> ).

CATCH cx_salv_msg .

ENDTRY.

3 REPLIES 3
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,564

it's not so surprising that sap cannot find the relationship between a dynamic field and the ddic (usually we use it for internal tables statically defined and fields based on ddic data elements). Or maybe a language problem? Otherwise, use ALV tools that allow to enter column names (REUSE_ALV_GRID_DISPLAY function module, CL_GUI_ALV_GRID, etc.)

Read only

DanReeves
Newcomer
0 Likes
1,564

Here is the solution that I used to add the column names from a passed dynamic table before outputting to the ALV.

Form outputALV using it_results type standard table.

DATA: gr_table TYPE REF TO CL_SALV_TABLE.

DATA: gr_funct TYPE REF TO CL_SALV_FUNCTIONS.

"Use the factory method to initialize the SALV object

Try.

cl_salv_table=>factory( IMPORTING r_salv_table = gr_table

CHANGING t_table = it_results ).

Catch cx_salv_msg.

EndTry.

"Loop through the table headings and set the column names

DATA: columns TYPE REF TO cl_salv_columns_table,

column TYPE REF TO cl_salv_column,

colNames TYPE SALV_T_COLUMN_REF,

colName like line of colNames,

txtMedium TYPE SCRTEXT_M.

Try.

columns = gr_table->get_columns( ).

colNames = columns->get( ).

Loop at colNames into colName.

column = columns->get_column( to_upper( colName-columnname ) ).

txtMedium = colName-columnname.

column->set_medium_text( txtMedium ).

ENDLOOP.

Catch cx_salv_not_found.

EndTry.

gr_table->display( ).

ENDFORM.

Read only

0 Likes
1,564

this solution is working