2020.01.10 [ABAP] essay on the drop-down box ALV

ALV drop-down box

As shown in the drop-down box made ALV drop-down box to select 1 to 5, with the view of how the embodiments below

 

 

 

1. Add to a field GT_DATA using the drop-down box:

TYPES:BEGIN OF ty_data,
        checkbox TYPE c,
        matnr    TYPE mara-matnr,
        mtart    TYPE mara-mtart,
        matkl    TYPE mara-matkl,
        maktx    TYPE makt-maktx,
        context  TYPE char10,"用于下拉框
      END OF ty_data.

DATA gt_data TYPE TABLE OF ty_data WITH EMPTY KEY.

2. Set fieldcat property:

Set field to enter context provided fieldcat-drdn_hndl = '1'.

(The following is a drop down box corresponding to the group, may be 23,456 to mark ????? group drop-down box, in order to achieve a plurality of drop-down box)

FORM frm_set_fieldcat.
  DATA lv_pos TYPE i.
  DATA ls_fieldcat LIKE LINE OF gt_fieldcat.
  DEFINE %%append_fieldcat.
    lv_pos = lv_pos + 1.
    ls_fieldcat-col_pos = lv_pos.
    ls_fieldcat-fieldname = &1."字段名
    ls_fieldcat-coltext = &2."文本
*  ls_fieldcat-no_zero = &3."去掉前导零
    ls_fieldcat-ref_table = &3.
    ls_fieldcat-ref_field = &4.
  APPEND ls_fieldcat TO gt_fieldcat.
  CLEAR ls_fieldcat.
  END-OF-DEFINITION.

  %%append_fieldcat:
  'CHECKBOX' '选择' '' '',
  'MATNR' '' 'MARA' 'MATNR',
  'MTART' '' 'MARA' 'MTART',   ' MAKTX '' power '' MAKTX '
  'MATKL' 'Mara' MATKL ',

  'CONTEXT' 'drop-down input. 1' '' ''.

  The READ TABLE gt_fieldcat Assigning the FIELD-SYMBOL (<FS1>) = the WITH KEY fieldName 'the CONTEXT'.
  The IF SY-SUBRC the EQ of 0. The
    <FS1> -edit = 'X-'.
    <fs1> -drdn_hndl = '1' . " packet identification
  ENDIF.

 

3. Set the drop-down box contents

Below, set_drop_down_table () method is called before the required set_table_for_first_display () method, or drop-down box does not pull down values.

Handle = 1 is the packet to the drop-down box

    "ALV 下拉框
    DATA:ls_drop_down TYPE lvc_s_drop,
         lt_drop_down TYPE lvc_t_drop.
    "句柄HANDLE 为I类型,相同数字为同一组下拉框
    DO 5 TIMES.
      CLEAR ls_drop_down.
      ls_drop_down-handle = '1'.“对应分组标识
      ls_drop_down-value = sy-index.
      APPEND ls_drop_down TO lt_drop_down.
    ENDDO.

  "ALV 下拉框
    cr_grid->set_drop_down_table(
  it_drop_down = lt_drop_down
  ).

 CALL METHOD cr_grid->set_table_for_first_display
      EXPORTING
        is_variant           = ls_disvariant
        i_default            = 'X'
        i_save               = 'U'
        is_layout            = ls_layout
        it_toolbar_excluding = lt_exclude
      CHANGING
        it_outtab            = ct_data
        it_fieldcatalog      = ct_fieldcat.

 

4.有多个下拉框分组的时候效果:

 

 

 

 

这样应该理解了handle = 1 / 2 时分组的概念了。

 

Guess you like

Origin www.cnblogs.com/jxzhu/p/12174168.html