ABAP F4使用总结!!

PARAMETERS: p_werks LIKE t001l-werks ,
            p_lgort LIKE t001l-lgort .
SELECTION-SCREEN SKIP.
PARAMETERS: p_kunnr LIKE kna1-kunnr  .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_lgort.
  PERFORM get_lgort CHANGING p_lgort.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_kunnr.
  PERFORM kunnr_f4help CHANGING p_kunnr.
*&---------------------------------------------------------------------*
*&      Form  get_event_for_user
*&---------------------------------------------------------------------*
FORM get_lgort  CHANGING l_lgort LIKE p_lgort.
  DATA: wa_shlp TYPE shlp_descr,
        wa_selopt TYPE ddshselopt,
        it_return_values TYPE STANDARD TABLE OF ddshretval,
        wa_return_values TYPE ddshretval,
        it_dynpfields TYPE STANDARD TABLE OF dynpread,
        wa_dynpfields TYPE dynpread.

  wa_dynpfields-fieldname = 'P_WERKS'.
  APPEND wa_dynpfields TO it_dynpfields.

**取屏幕字段的已有值
  CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      dyname     = sy-repid
      dynumb     = sy-dynnr
    TABLES
      dynpfields = it_dynpfields.

**根据表名和字段名确定使用哪个搜索帮助
  CALL FUNCTION 'F4IF_DETERMINE_SEARCHHELP'
    EXPORTING
      tabname   = 'T001L'
      fieldname = 'LGORT'
    IMPORTING
      shlp      = wa_shlp.

  READ TABLE it_dynpfields WITH KEY fieldname = 'P_WERKS' INTO wa_dynpfields.
  IF NOT wa_dynpfields-fieldvalue IS INITIAL.
    wa_selopt-sign      = 'I'.
    wa_selopt-option    = 'CP'.
    wa_selopt-low       = wa_dynpfields-fieldvalue.
    wa_selopt-shlpfield = 'WERKS'.
    wa_selopt-shlpname  = wa_shlp-shlpname.
    APPEND wa_selopt TO wa_shlp-selopt.
  ENDIF.

**根据条件打开指定的搜索帮助
  CALL FUNCTION 'F4IF_START_VALUE_REQUEST'
    EXPORTING
      shlp          = wa_shlp
    TABLES
      return_values = it_return_values.

  READ TABLE it_return_values WITH KEY fieldname = 'LGORT' INTO wa_return_values.
  IF sy-subrc IS INITIAL.
    l_lgort = wa_return_values-fieldval.
    READ TABLE it_return_values WITH KEY fieldname = 'WERKS' INTO wa_return_values.
    IF sy-subrc IS INITIAL AND wa_return_values-fieldval NE wa_dynpfields-fieldvalue.
      REFRESH it_dynpfields.
      wa_dynpfields-fieldvalue = wa_return_values-fieldval.
      APPEND wa_dynpfields TO it_dynpfields.
**更新屏幕字段
      CALL FUNCTION 'DYNP_VALUES_UPDATE'
        EXPORTING
          dyname     = sy-repid
          dynumb     = sy-dynnr
        TABLES
          dynpfields = it_dynpfields.
    ENDIF.
  ENDIF.
ENDFORM.                    " get_event_for_user

*&---------------------------------------------------------------------*
*&      Form  kunnr_f4help
*&---------------------------------------------------------------------*
FORM kunnr_f4help CHANGING l_kunnr .
  DATA: wa_shlp         TYPE shlp_descr,
        wa_shlp_desct   TYPE shlp_desct ,
        fcode           LIKE sy-ucomm ,
        wa_interface    LIKE LINE OF wa_shlp-interface,
        wa_fielddescr   LIKE LINE OF wa_shlp-fielddescr,
        wa_fieldprop    LIKE LINE OF wa_shlp-fieldprop,
        wa_selopt       LIKE LINE OF wa_shlp-selopt,
        wa_retval       TYPE ddshretval,
        it_retval       TYPE STANDARD TABLE OF ddshretval.
  DATA: subrc LIKE sy-subrc .

**根据搜索帮助取得wa_shlp
  CALL FUNCTION 'F4IF_GET_SHLP_DESCR' EXPORTING
      shlpname = 'VMVAA'  "search help VMVAA
      shlptype = 'SH'
    IMPORTING
      shlp     = wa_shlp.

*定义 VKORG 为只读字段
  LOOP AT wa_shlp-interface INTO wa_interface WHERE shlpfield = 'VKORG'.
    wa_interface-value = '3020'.
    wa_interface-dispfield = 'X'.
    MODIFY wa_shlp-interface FROM wa_interface INDEX syst-tabix.
  ENDLOOP.
  LOOP AT wa_shlp-fieldprop INTO wa_fieldprop WHERE fieldname = 'VKORG'.
    wa_fieldprop-shlpinput = 'X'.
    wa_fieldprop-shlpseldis = 'X'.
    MODIFY wa_shlp-fieldprop FROM wa_fieldprop INDEX syst-tabix.
  ENDLOOP.
*定义输出字段
  READ TABLE wa_shlp-interface INTO wa_interface WITH KEY shlpfield = 'VBELN'.
  IF sy-subrc = 0.
    wa_interface-valfield = 'X'.
*    l_shlp_interface-value = tree_id.
    MODIFY wa_shlp-interface FROM wa_interface INDEX sy-tabix.
  ELSE.
    MESSAGE e017(bmen) RAISING internal_error.
  ENDIF.
* 选择界面初始值
  wa_selopt-shlpname  = wa_shlp-shlpname.
  wa_selopt-shlpfield = 'KUNNR'.
  wa_selopt-sign      = 'I'.
  wa_selopt-option    = 'EQ'.
  wa_selopt-low       = '4000'.
  APPEND wa_selopt TO wa_shlp-selopt.

  APPEND wa_shlp TO wa_shlp_desct.
  APPEND wa_shlp TO wa_shlp_desct.
  CLEAR wa_shlp.

  CALL FUNCTION 'F4IF_CHOOSE_SEARCHHELP'
    EXPORTING
      shlp_tab = wa_shlp_desct
    IMPORTING
      shlp     = wa_shlp
      fcode    = fcode.
  CALL FUNCTION 'F4IF_START_VALUE_REQUEST'
    EXPORTING
      shlp          = wa_shlp
    IMPORTING
      rc            = subrc
    TABLES
      return_values = it_retval.
  LOOP AT it_retval INTO wa_retval.
    p_kunnr = wa_retval-fieldval.
  ENDLOOP.
ENDFORM.                    " CALL_F4HELP

posted @ 2019-03-30 22:55  木子水皮  阅读(1293)  评论(0编辑  收藏  举报