ABAP-how to define a drop-down list in the alv_grid Function

Source: Internet
Author: User

Recently, I have heard from netizens and users that I want you to add a list to the ALV grid function. In fact, sap has already considered your needs and your needs can be fulfilled. I will dedicate the code for your reference and learning.

The Code is as follows:

Report.
**************************************** ********************************
* Daten definition *
**************************************** ********************************
Type-pools: slis.

Types:
Begin of t_data,
Matnr type Makt-matnr,
Maktx type Makt-maktx,
Spras type Makt-spras,
End of t_data,
Begin of t_alv,
Matnr type Makt-matnr,
Maktx type Makt-maktx,
Spras type Makt-spras,
Dd_handle type int4,
End of t_alv.
Data:
Gt_fieldcatalog type lvc_t_fcat,
Gw_fieldcatalog type lvc_s_fcat,
* Define data in the storage drop-down list
Gt_ddval type lvc_t_drop,
Gw_ddval type lvc_s_drop,

Gt_events type slis_t_event,
Gw_events type slis_alv_event,
Gt_data type table of t_data,
Gw_data type t_data,
Gt_alv type table of t_alv,
Gw_alv type t_alv,
G_repid type sy-repid value sy-repid.
**************************************** ********************************
* Selection screen *
**************************************** ********************************
Select-options: s_matnr for gw_data-matnr.

**************************************** ********************************
* Start-of-selection *
**************************************** ********************************
Start-of-selection.
Select matnr maktx spras
Into Table gt_data up to 50 rows
From Makt
Where matnr in s_matnr
And spras = 'en '.

Loop at gt_data into gw_data.
Move-corresponding gw_data to gw_alv.
Append gw_alv to gt_alv.
Endloop.

Perform creat_fieldcat.
Perform creat_dropdown_values.
Perform creat_event_exits.
Call function 'reuse _ alv_grid_display_lvc'
Exporting
I _callback_program = g_repid
It_fieldcat_lvc = gt_fieldcatalog
It_events = gt_events
Tables
T_outtab = gt_alv.
*---------------------------------------------------------------------*
* Set the format of the output field
*---------------------------------------------------------------------*
Form creat_fieldcat.
Clear gw_fieldcatalog.
Gw_fieldcatalog-fieldname = 'matnr '.
Gw_fieldcatalog-ref_field = 'matnr '.
Gw_fieldcatalog-ref_table = 'makt '.
Append gw_fieldcatalog to gt_fieldcatalog.

Clear gw_fieldcatalog.
Gw_fieldcatalog-fieldname = 'maktx '.
Gw_fieldcatalog-ref_field = 'maktx '.
Gw_fieldcatalog-ref_table = 'makt '.
Append gw_fieldcatalog to gt_fieldcatalog.

Clear gw_fieldcatalog.
Gw_fieldcatalog-fieldname = 'spras '.
Gw_fieldcatalog-OUTPUTLEN = '7 '.
Gw_fieldcatalog-dd_outlen = '7 '.
Gw_fieldcatalog-intlen = '2 '.
Gw_fieldcatalog-inttype = 'C '.
Gw_fieldcatalog-coltext = 'language '.
Gw_fieldcatalog-tooltip = 'language '.
Gw_fieldcatalog-seltext = 'language '.
Gw_fieldcatalog-drdn_field = 'dd _ handle '.
Gw_fieldcatalog-EDIT = 'x '.
Append gw_fieldcatalog to gt_fieldcatalog.
Endform. "creat_fieldcat
*---------------------------------------------------------------------*
* Generate different drop-down lists based on all the languages of the materials.
*---------------------------------------------------------------------*
Form creat_dropdown_values.
Data: l_spras type Makt-spras,
Rochelle count type I.
Loop at gt_alv into gw_alv.
Add 1 to l_count.
Select spras
Into l_spras
From Makt
Where matnr = gw_alv-matnr.
Clear gw_ddval.
Gw_ddval-handle = l_count.
Gw_ddval-value = l_spras.
Append gw_ddval to gt_ddval.
Endselect.

Clear gw_ddval.
Gw_ddval-handle = l_count.
Gw_ddval-value = ''.
Append gw_ddval to gt_ddval.
* Set the corresponding
Gw_alv-dd_handle = l_count.
Modify gt_alv from gw_alv.
Endloop.
Endform. "creat_dropdown_values
*---------------------------------------------------------------------*
* Form creat_event_exits
*---------------------------------------------------------------------*
Form creat_event_exits.
Gw_events-name = 'caller _ exit '.
Gw_events-form = 'caller _ exit '.
Append gw_events to gt_events.
Endform. "creat_event_exits
*---------------------------------------------------------------------*
* Set the drop-down list so that the grid and internal tables can be linked.
*---------------------------------------------------------------------*
Form caller_exit using ls_data type slis_data_caller_exit.
Data: l_ref_alv type ref to cl_gui_alv_grid.
Call function 'get _ globals_from_slvc_fullscr'
Importing
E_grid = l_ref_alv.
Call method l_ref_alv-> set_drop_down_table
Exporting
It_drop_down = gt_ddval.
Endform. "caller_exit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.