FM实现F4帮助系列二:联动的搜索

函数:

DYNP_VALUES_READ(Read screen field values before PAI field transport)

F4IF_INT_TABLE_VALUE_REQUEST

效果图:

图片

误区:

P_CONNID帮助中直接如下:

  SELECT  …… 

    WHERE werks = p_werks.

如果用户填写p_werks 未回车而直接点p_matnr的帮助,p_werks此时还为空.

本例子代码:


图片


图片


文本

REPORT  zlm_test_043.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS: p_werks TYPE  werks_d,

            p_matnr TYPE  matnr.

SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_matnr.

  PERFORM frm_f4.

*&------------------------------------------------------------------- 

*&搜索帮助

*&------------------------------------------------------------------- 

FORM frm_f4.

  TYPES: BEGIN OF values,

         matnr TYPE matnr,

         maktx TYPE maktx,

       END OF values.

  DATA: progname         TYPE sy-repid,

        dynnum           TYPE sy-dynnr,

        dynpro_values    TYPE TABLE OF dynpread,

        field_value      LIKE LINE OF dynpro_values,

        values_tab       TYPE TABLE OF values.

  progname = sy-repid.

  dynnum   = sy-dynnr.

  CLEAR: field_value, dynpro_values.

  "指定需要取值的屏幕字段

  field_value-fieldname = 'P_WERKS'.      "

  APPEND field_value TO dynpro_values.

  "获取屏幕 P_WERKS 字段的值

  CALL FUNCTION 'DYNP_VALUES_READ'

    EXPORTING

      dyname             = progname

      dynumb             = dynnum

      translate_to_upper = 'X'

    TABLES

      dynpfields         = dynpro_values.

  "根据屏幕输入值进行进一步搜索

  READ TABLE dynpro_values INDEX 1 INTO field_value.

  SELECT  makt~matnr makt~maktx

    FROM  makt

    INNER JOIN marc ON  marc~matnr = makt~matnr

    INTO  CORRESPONDING FIELDS OF TABLE values_tab

    WHERE werks = field_value-fieldvalue.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'

    EXPORTING

      retfield     = 'MATNR'                    "需要回传的字段

      dynpprog     = progname

      dynpnr       = dynnum

      dynprofield  = 'MAKTX'                    "需要显示的字段

      window_title = '情选择物料 '

      value_org    = 'S'

    TABLES

      value_tab    = values_tab.

ENDFORM.                    "frm_f4


猜你喜欢

转载自blog.51cto.com/15057820/2628634

相关文章