cancel
Showing results for 
Search instead for 
Did you mean: 

Adding a column dynamically to the alv : dump

abhishek_gupta2
Participant
0 Kudos

Hello ALL ,

I have a ALV with fixed fields . These fields are also part of context .

Now I have to add new fields to the table as columns and also populate the values dynamically .

To add new columns  , I add below code .

loop at fields into field

    CALL METHOD lv_value->if_salv_wd_column_settings~create_column

      EXPORTING

        id       = field

        position = lv_lines

      RECEIVING

        value    = lr_column.

    lo_column_header = lr_column->create_header( ) .

    lo_column_header->set_text( field ) .

* Create an attribute in the context

*     navigate from <CONTEXT> to <POSITIONS> via lead selection

    lo_nd_positions = wd_context->get_child_node( name = wd_this->wdctx_positions ).

    CALL METHOD lo_nd_positions->get_node_info

      RECEIVING

        node_info = lr_child_node_info.

    ls_context_attribute_info-name = field

    ls_context_attribute_info-type_name = 'CHAR30'.

    ls_context_attribute_info-is_static = abap_false.

    CALL METHOD lr_child_node_info->add_attribute

      EXPORTING

        attribute_info = ls_context_attribute_info.

* Create a cell editor with reference to column id .

    CREATE OBJECT lr_input

      EXPORTING

        value_fieldname = field.

    CALL METHOD lr_column->set_cell_editor

      EXPORTING

        value = lr_input.

endloop.

The issue is i am getting a dump as application says , not able to find the attribute field. I already added the attribute field to the context by using add atributte and based on this refrence , I am creating the input field . so now I have the field in the table and also the reference to this field  in the context and binding also exists .

whats the reason for dump .kindly advice .

Thanks..

Accepted Solutions (1)

Accepted Solutions (1)

veerababu_alladi
Explorer
0 Kudos

Hi Abhishek,

you are adding field dynamically.so you need to create field catalog first.then call it in ALV.

field catalog format.

data :

               fieldcatalog type                     slis_t_fieldcat_alv with header line,

               gd_repid     like                     sy-repid,

               gd_layout    type                     slis_layout_alv,

   fieldcatalog-fieldname   = 'GRP_ID'.

   fieldcatalog-seltext_m   = 'Group ID'.

   fieldcatalog-col_pos     0.

   append fieldcatalog to fieldcatalog.

   clear  fieldcatalog.

   fieldcatalog-fieldname   = 'TYPE_ID'.

   fieldcatalog-seltext_m   = 'Type ID'.

   fieldcatalog-col_pos     1.

   append fieldcatalog to fieldcatalog.

   clear  fieldcatalog.

   fieldcatalog-fieldname   = 'PGM_ID'.

   fieldcatalog-seltext_m   = 'Program ID'.

   fieldcatalog-col_pos     = 2.

   fieldcatalog-outputlen   = 18.

   fieldcatalog-emphasize   = 'X'.

   fieldcatalog-key         = 'X'.

   fieldcatalog-do_sum      = 'X'.

   fieldcatalog-no_zero     = 'X'.

   append fieldcatalog to fieldcatalog.

   clear  fieldcatalog.

   fieldcatalog-fieldname   = 'BEGDA'.

   fieldcatalog-seltext_m   = 'Start Date'.

   fieldcatalog-col_pos     = 3.

   append fieldcatalog to fieldcatalog.

   clear  fieldcatalog.

   fieldcatalog-fieldname   = 'ENDDA'.

   fieldcatalog-seltext_m   = 'End date'.

   fieldcatalog-col_pos     = 4.

   append fieldcatalog to fieldcatalog.

   clear  fieldcatalog.


gd_layout-no_input          = 'X'.

gd_layout-colwidth_optimize = 'X'.


call function 'REUSE_ALV_GRID_DISPLAY'

     exporting

       i_callback_program = gd_repid

       is_layout          = gd_layout

       it_fieldcat        = fieldcatalog[]

       i_save             = 'X'

     tables

       t_outtab           = lt_alv

     exceptions

       program_error      = 1

       others             = 2.

   if sy-subrc <> 0.

     message id sy-msgid type sy-msgty number sy-msgno

             with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

   endif.



Thanks,

Veerababu.

Former Member
0 Kudos

Hello Veerababu.

Thanks for respond. Our requirement is , We had already ALV table displaying in the portal.The context node is binded to Data node of ALV. Now we want to add new column to the existing ALV, as i can not add new attribute to the standard context node, i want add the new column dynamically and display it as new column in the existing ALV table,This we want to do dynamically Could you please help on it if you have any solution .

Thanks

Bharat

abhishek_gupta2
Participant
0 Kudos

Hello Bharat ,

I know the problem faced by you . At the moment there is no way to affect the data binding which is external mapping in nature .

So I would suggest you to create the dynamic node , create the columns dynamically , then take the reference of the columns and populate the relevant data and then push the data to alv table which is also dyanmic.

There are standard functions like filter and settings which also needs to be activated for the alv. If any buttons required , handle them dynamically .

I am clsoing the thread.

Thanks & Regards,

Abhishek.

Answers (1)

Answers (1)

abhishek_gupta2
Participant
0 Kudos

Note that this ALV is case of external mapping and when I am updating the context with the new attribute , I have to take addtional care during this external mapping .

But not sure what needs to done .

0 Kudos

Hi Abhishek,

Can you check the Dictionary Structure property of context node?

That should be empty for adding columns.

Thanks

Ananda

Former Member
0 Kudos

Hello Abhishek.

Hope you are doing good.

Has your issue resolved? If yes please let me know steps you have corrected for your code.

I have similar requirement need your assistance.