Skip to Content

How to have dynamic column in wda alv

Mar 22, 2017 at 12:38 PM


avatar image
Former Member

I want to have dynamic number of wda alv column based on my input filed.

Like I have date in my input filed, if I give 3 months in my input i need 3 columns in my alv,

if i give 4 months as my input i need 4 columns in my alv.

Please do help.


10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

harish vyas Mar 23, 2017 at 10:50 AM

Hi Kashiap,

Columns in ALV will be based ATTRIBUTEs in node i.e. each attribute of a node is linked to individual column in ALV table.

Now there can be multiple scenarios:

1. Columns in the ALV which you want to show are linked to some standard backend table/structure.

2. Columns in ALV are just for enduser perspective and are not mapped with any backend table/structure, data entered in ALV will be used further for some calculations are then dumped into DB table or else where.

  • Create a node in CONTEXT of COMPONENTCONTROLLER and Drag/drop the same node into the DATA node of the Interface Controller (which I assume you might have already done).
  • In WDDOINIT method write the code to create dynamic ATTRIBUTES.

In below example I have kept name of node as 'ND_TABLE'.

LIST_OF_ALL_FIELDS_OF_TBL_STR represents list of fields in any table/structure.

WA_OF_ALL_FIELDS_OF_TBL_STR represents workarea for above table/structure.

LV_COUNT is user input i.e. number of columns it want.

DATA lo_nd_nd_table TYPE REF TO if_wd_context_node.

DATA lo_nd_nd_table_info TYPE REF TO if_wd_context_node_info.

DATA lv_attribute TYPE wdr_context_attribute_info.

lo_nd_nd_table = wd_context->get_child_node( name = wd_this->wdctx_nd_table ).

lo_nd_nd_table_info = lo_nd_nd_table->get_node_info( ).


lv_attribute-name = WA_OF_ALL_FIELDS_OF_TBL_STR-NAME

lv_attribute-type_name = WA_OF_ALL_FIELDS_OF_TBL_STR-TYPE_NAME.

CALL METHOD lo_nd_nd_table_info->add_attribute( EXPORTING attribute_info = lv_attribute ).

IF sy-tabix EQ LV_COUNT.



In case there is no linkage of any table or Structure to our ALV table, then instead of using LOOP statement, we can simply use DO statement, as shown below.

DATA lv_index TYPE c VALUE 1.


CONCATENATE 'ATT' lv_index INTO lv_attribute-name SEPARATED BY '_'.
lv_attribute-type_name = 'CHAR30'.
CALL METHOD lo_nd_nd_table_info->add_attribute( EXPORTING attribute_info = lv_attribute ).

lv_index = lv_index + 1.


Do let me know if this approach works for you.



10 |10000 characters needed characters left characters exceeded