Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Setting ALV Column width

Hi experts,

I'm trying to set fixed width in my ALV report.

I using set_width to set the fixed width.

But I could not get the fixed width.

data salv_column type ref to cl_salv_wd_column.

salv_column->set_width( '4' ).

When I try this i'm getting like belwo.

if my Header text is 'Test Column', and width = 4.

I could able to see the header text fully (Test column).

But I should see only Test and in the 2nd row it should show Column

Any idea of doing it???

Thankx...

Former Member replied

Hi,

You need to change Table setting Layout. Please check this code:

* create an instance of ALV component
DATA: LR_IF_CONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE,
LR_CMP_USAGE TYPE REF TO IF_WD_COMPONENT_USAGE,
LR_CMDL TYPE REF TO CL_SALV_WD_CONFIG_TABLE,
LR_TABLE_SETTING TYPE REF TO IF_SALV_WD_TABLE_SETTINGS.
LR_CMP_USAGE = WD_THIS->WD_CPUSE_ALV( ).

IF LR_CMP_USAGE->HAS_ACTIVE_COMPONENT( ) IS INITIAL.
  LR_CMP_USAGE->CREATE_COMPONENT( ).
ENDIF.

** get reference to the ALV model
LR_IF_CONTROLLER = WD_THIS->WD_CPIFC_ALV( ).
LR_CMDL = LR_IF_CONTROLLER->GET_MODEL( ).
LR_TABLE_SETTING ?= LR_CMDL.

** Set column width
DATA LR_COL TYPE REF TO CL_SALV_WD_COLUMN.

LR_COL = LR_CMDL->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'PERNR' ).
LR_COL->SET_WIDTH( '70' ) .
LR_COL = LR_CMDL->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'ENAME' ).
LR_COL->SET_WIDTH( '100' ) .

LR_TABLE_SETTING->SET_FIXED_TABLE_LAYOUT( ABAP_TRUE ).

LR_TABLE_SETTING->SET_FIXED_TABLE_LAYOUT( ABAP_TRUE ).

Regards,

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question