Application Development 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: 

Drop down in alv grid and catching line selection

Former Member
0 Kudos

hi

i am displaying output in a grid to a screen with below method where it_datab has severla lfields and below is displaying output in alv frid format

i have a requierment to have a input field( ie one of the field of a record to be available for input and as dropdown with 3 values and user will selecte on value and then I will be updating the same  to data base with the value inpout in the particular record

for eg

field1 field 2 feield 3 field4

ab     ni        test   (here user will input values as Acc or AP or DP ) and then i will udpate thi record accordingly in the data base with the field 4 as inputted

pplease suggest a sample code to dod the same and correspoinding update in database on line selection and also sample code to have drop down for field 4 in the grid record.

    CALL METHOD grid1->set_table_for_first_display
      EXPORTING
        i_structure_name     = 'STRUCTIRE'
        is_layout            = gs_layout
        CHANGING
        it_outtab            = lt_dtab.

regards

Nishant

6 REPLIES 6

nabheetscn
Active Contributor
0 Kudos

Check this sample program BCALV_EDIT_06 it has an editable dropdown. Add a save buton in PF status. In user command save the data

Former Member
0 Kudos

This message was moderated.

sivaganesh_krishnan
Contributor
0 Kudos

hi nishant,

goto se80-> enter package as "SLIS" -> you will find many ALV program .

check the below link , you will find alv with drop down list..

Dropdowns in ALV - Code Gallery - SCN Wiki

former_member184569
Active Contributor
0 Kudos

Hi Nishant,

Follow these steps.

1. In your main program, write the

call screen 100.

Double click on 100 and it will go to screen painter.

2. Create a custom container - CONT, and name the okcode as say ok_code.

3. In the PBO, add the following.

MODULE pbo OUTPUT.
   set pf-status 'ZGUI'.
   set titlebar 'TIT100'.
     PERFORM alv_output.

ENDMODULE. 


FORM alv_output .

*Create object for container

  CREATE OBJECT g_custom_container

         EXPORTING container_name = 'CONT'.

*create object for grid

  CREATE OBJECT g_grid

         EXPORTING i_parent = g_custom_container.

* Build fieldcatalog

  PERFORM build_fieldcat.

*Build layout

  PERFORM build_layout.

* Initialize the values in drop down table.

  PERFORM dropdown_table.

* Get the data in output table.

  PERFORM get_data.

*Display ALV output

  CALL METHOD g_grid->set_table_for_first_display

    EXPORTING

      is_layout       = gs_layout

    CHANGING

      it_fieldcatalog = gt_fieldcat

      it_outtab       = gt_outtab.



CALL METHOD g_grid->set_ready_for_input
    EXPORTING
     I_READY_FOR_INPUT = 1.

ENDFORM.                               "ALV_OUTPUT



* In the field catalog, set handle for drop down.

FORM build_fieldcat.


*first create field catalog like usual.

  Perform create_fieldcat.

* Assign drop down to the dropdown field

LOOP AT gt_fieldcat INTO ls_fcat.

    CASE ls_fcat-fieldname.

      WHEN 'DDOWN_FLD'.

        ls_fcat-drdn_hndl = '1'.

        ls_fcat-edit = 'X'.

        ls_fcat-outputlen = 15.

        MODIFY gt_fieldcat FROM ls_fcat.

   ENDCASE.

ENDFORM.

* Initialize all values in the drop down table.

FORM dropdown_table.

*Declarations for drop down lists in ALV.

  DATA: lt_dropdown TYPE lvc_t_drop,

        ls_dropdown TYPE lvc_s_drop.


  ls_dropdown-handle = '1'.

  ls_dropdown-value = 'ACC'.

  APPEND ls_dropdown TO lt_dropdown.


  ls_dropdown-handle = '1'.

  ls_dropdown-value = 'AP'.

  APPEND ls_dropdown TO lt_dropdown.


  ls_dropdown-handle = '1'.

  ls_dropdown-value = 'DP.

  APPEND ls_dropdown TO lt_dropdown.


*Display the dropdown in ALV

  CALL METHOD g_grid->set_drop_down_table

    EXPORTING

      it_drop_down = lt_dropdown.

ENDFORM.   

4. In the PAI Module, save the value to the database like any other field


MODULE pai INPUT.

Case ok_code.

When ‘SAVE’.

* Save the values to database

perform save_database .

CALL METHOD g_grid->refresh_table_display.

endcase.

ENDMODULE.    


FORM save_database .

* Getting the selected rows index

CALL METHOD g_grid->GET_SELECTED_ROWS

        IMPORTING ET_INDEX_ROWS = i_selected_rows.

* Through the index capturing the values of selected rows

    LOOP AT i_selected_rows INTO w_selected_rows.

    READ TABLE itab INTO wa INDEX w_selected_rows-index.

        IF sy-subrc EQ 0.

          MOVE-CORRESPONDING wa TO w_modified.

          APPEND w_modified TO i_modified.

        ENDIF.

    ENDLOOP.

    MODIFY ztable FROM TABLE i_modified.

endform.

sandroramos
Active Participant
0 Kudos

Hi Nishant,

Take a look at BCALV_EDIT_06 program using SE38/SE80.

Regards,

Sandro Ramos

Former Member
0 Kudos

this is resolved