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

Factory ALV Method

Former Member
0 Likes
2,344

Hi,

I am not able to set 2nd column heading, code as shown below, If any missing guide me.

TYPES:
BEGIN OF IT,
MATNR
TYPE MARA-MATNR,
MTART
TYPE MARA-MTART,
END OF IT.

DATA :
ALV
TYPE REF TO CL_SALV_TABLE,
ITAB
TYPE TABLE OF IT,
FNC
TYPE REF TO CL_SALV_FUNCTIONS,
DSP
TYPE REF TO CL_SALV_DISPLAY_SETTINGS,
CLM
TYPE REF TO CL_SALV_COLUMN_TABLE,
CLS
TYPE REF TO CL_SALV_COLUMNS_TABLE.


SELECT MATNR MTART INTO TABLE ITAB FROM MARA UP TO 20 ROWS.

CL_SALV_TABLE=>FACTORY(
IMPORTING R_SALV_TABLE = ALV
CHANGING T_TABLE = ITAB ).

FNC = ALV->GET_FUNCTIONS( ).
FNC->SET_ALL( ABAP_TRUE ).

DSP = ALV->GET_DISPLAY_SETTINGS( ).
DSP->SET_LIST_HEADER(
'This is demo' ).

CLS = ALV->GET_COLUMNS( ).
CLM ?= CLS->GET_COLUMN(
'MATNR' ).
CLM->SET_LONG_TEXT(
'This is col1' ).


CLM ?= CLS->GET_COLUMN( 'MTART' ).
CLM->SET_LONG_TEXT( 'This is col2 ' ).


ALV->DISPLAY( ).




Output :



Thanks,

Avirat


1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,047

Thanks..

Issue Resolved !!

7 REPLIES 7
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
2,047

Do like this

 

CLM ?= CLS->GET_COLUMN(

'MTART' ).
CLM->SET_LONG_TEXT(
'This is col2 ' ).
CLM->SET_MEDIUM_TEXT(
'This is col2 ' ).
data:lv_text type SCRTEXT_S.
lv_text =
'This is col2 '.
CLM->SET_SHORT_TEXT( lv_text ).
ALV->DISPLAY( ).

Read only

0 Likes
2,047

so it is necessary to declare

all 3.

long,medium,short

text. ?

for each single column.

Read only

0 Likes
2,047

May be your alv display would be showing medium text. Drag it if you see your's declaration in long text. And you have not declared midium text for your ALV display so it's keeping the standard one.

Read only

0 Likes
2,047

It depends what exactly you want as output. Since you can adjust the wirdth of the columns that is why we short/medium/long text. You can only keep short text if you want short name to be this

Nabheet

Read only

Private_Member_15166
Active Contributor
0 Likes
2,047

Hi,

Try like this.

  DATA : lr_column  TYPE REF TO cl_salv_column_table,

         lr_columns TYPE REF TO cl_salv_columns_table.

  lr_columns = alv->get_columns( ).

  TRY.

      lr_column ?= lr_columns->get_column( 'MTART' ).

      lr_column->set_short_text( 'Colmn 2' ).

      lr_column->set_medium_text( 'This is col2' ).

      lr_column->set_long_text( 'This is col2').

    CATCH cx_salv_not_found.

  ENDTRY.

Read only

Former Member
0 Likes
2,048

Thanks..

Issue Resolved !!

Read only

Former Member
0 Likes
2,047

HI Avirat,

The second column is not getting displayed when we use only set_long_text(  ) ,may be because of

length of the mtart field.

Please find the below code.Here i used set_medium_text ( ) and set_short_text( ) methods along with  set_long_text(  ), it is working fine .

TYPES:
BEGIN OF it,
matnr TYPE mara-matnr,
mtart TYPE mara-mtart,
END OF it.

DATA :
alv  TYPE REF TO cl_salv_table,
itab TYPE TABLE OF it,
fnc  TYPE REF TO cl_salv_functions,
dsp  TYPE REF TO cl_salv_display_settings,
clm  TYPE REF TO cl_salv_column_table,
cls  TYPE REF TO cl_salv_columns_table,
l_scrtext_s TYPE scrtext_s.


SELECT matnr mtart INTO TABLE itab FROM mara UP TO 20 ROWS.

cl_salv_table=>factory( IMPORTING r_salv_table = alv
CHANGING t_table = itab ).

fnc = alv->get_functions( ).
fnc->set_all( abap_true ).

dsp = alv->get_display_settings( ).
dsp->set_list_header( 'This is demo' ).

cls = alv->get_columns( ).

l_scrtext_s = 'COL 1'.

clm ?= cls->get_column( 'MATNR' ).
clm->set_long_text'This is col1 ' ).

CLEAR l_scrtext_s.

l_scrtext_s = 'COL 2'.
clm ?= cls->get_column( 'MTART' ).
clm->set_long_text( 'This is col2' ).
clm->set_medium_text( 'This is col2' ).
clm->set_short_text( value = l_scrtext_s  ).

alv->display( ).



Output:

When we extend the column 2.

Regards,

Manasa Veena P.