二维码

ABAP选择屏幕的实时关联F4帮助的实现案例

Twilight发表于 2014-10-14 19:26Twilight 最后回复于 2014-10-14 19:26 [复制链接] 7836 0

在 AT SELECTION-SCREEN 事件中更新 PARAMETER 或 SELECT-OPTIONS 的数值时,当前界面不会立即更新,要按 Enter之后才会更新最新值。
主要用到 'DYNP_VALUES_UPDATE'和 'DYNP_VALUES_READ'两个函数。

程序代码:
  1. TYPE-POOLS: slis.
  2. *----------------------------------------------------------------------*
  3. *        T A B L E S
  4. *----------------------------------------------------------------------*

  5. *----------------------------------------------------------------------*
  6. *        T Y P E S
  7. *----------------------------------------------------------------------*
  8. * Main internal table for process
  9. TYPES: BEGIN OF ty_bwart,
  10.   zeile TYPE mseg-zeile,
  11.   bwart TYPE mseg-bwart,
  12.   sobkz TYPE mseg-sobkz,
  13.   rmtxt TYPE string,
  14. END OF ty_bwart.

  15. *----------------------------------------------------------------------*
  16. *        I N T E R N A L   T A B L E
  17. *----------------------------------------------------------------------*
  18. DATA: t_bwart         TYPE ty_bwart  OCCURS 0 WITH HEADER LINE.

  19. *----------------------------------------------------------------------*
  20. *        W O R K I N G   A R E A S                                     *
  21. *----------------------------------------------------------------------*

  22. DATA: w_bwart           TYPE ty_bwart.

  23. *----------------------------------------------------------------------*
  24. *        S E L E C T I O N  -  S C R E E N
  25. *----------------------------------------------------------------------*

  26. SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE c_title.
  27. PARAMETER: p_bwart LIKE mseg-bwart OBLIGATORY, "MOV Type
  28.            p_sobkz LIKE mseg-sobkz.            "Special Stock
  29. SELECTION-SCREEN SKIP 1.
  30. SELECTION-SCREEN END OF BLOCK b1.

  31. *----------------------------------------------------------------------*
  32. *        L O A D - O F - P R O G R A M
  33. *----------------------------------------------------------------------*
  34. LOAD-OF-PROGRAM.

  35. *----------------------------------------------------------------------*
  36. *        I N I T I A L I Z A T I O N
  37. *----------------------------------------------------------------------*
  38. INITIALIZATION.

  39.   c_title = 'DYNP_VALUES_UPDATE Demo'.

  40.   t_bwart-bwart = '322'.
  41.   t_bwart-sobkz = ''.
  42.   t_bwart-rmtxt = 'Unrest. Use > QI (WH stock)'.
  43.   APPEND t_bwart.

  44.   t_bwart-bwart = '344'.
  45.   t_bwart-sobkz = 'K'.
  46.   t_bwart-rmtxt = 'Unrest. Use > Blocked (Consignment)'.
  47.   APPEND t_bwart.

  48.   t_bwart-bwart = '321'.
  49.   t_bwart-sobkz = ''.
  50.   t_bwart-rmtxt = 'QI > to Unrest. Use (WH stock)'.
  51.   APPEND t_bwart.

  52.   t_bwart-bwart = '350'.
  53.   t_bwart-sobkz = 'E'.
  54.   t_bwart-rmtxt = 'QI > Blocked (SO stock)'.
  55.   APPEND t_bwart.

  56.   t_bwart-bwart = '350'.
  57.   t_bwart-sobkz = 'K'.
  58.   t_bwart-rmtxt = 'QI > Blocked (Consignment)'.
  59.   APPEND t_bwart.
  60. *----------------------------------------------------------------------*
  61. *        A T   S E L E C T I O N  -  S C R E E N
  62. *----------------------------------------------------------------------*
  63. AT SELECTION-SCREEN. "ON VALUE-REQUEST FOR P_LAYOUT.

  64. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_bwart.
  65.   DATA l_selfield TYPE slis_selfield.
  66.   DATA: wa_fcat TYPE slis_fieldcat_ALV,
  67.         fcat TYPE slis_t_fieldcat_alv.

  68.   "Field Cat. for Error Message Display
  69.   CLEAR wa_fcat.
  70.   wa_fcat-row_pos   = '1'.
  71.   wa_fcat-col_pos   = '1'.
  72.   wa_fcat-fieldname = 'BWART'.
  73.   wa_fcat-tabname   = 'T_BWART'.
  74.   wa_fcat-seltext_m = 'Movement'.
  75.   wa_fcat-outputlen = 5.
  76.   APPEND wa_fcat TO fcat.

  77.   CLEAR wa_fcat.
  78.   wa_fcat-row_pos   = '1'.
  79.   wa_fcat-col_pos   = '2'.
  80.   wa_fcat-fieldname = 'SOBKZ'.
  81.   wa_fcat-tabname   = 'T_BWART'.
  82.   wa_fcat-seltext_m = 'Spec.Stk.'.
  83.   wa_fcat-outputlen = 5.
  84.   APPEND wa_fcat TO fcat.

  85.   CLEAR wa_fcat.
  86.   wa_fcat-row_pos   = '1'.
  87.   wa_fcat-col_pos   = '3'.
  88.   wa_fcat-fieldname = 'RMTXT'.
  89.   wa_fcat-tabname   = 'T_BWART'.
  90.   wa_fcat-seltext_m = 'Description'.
  91.   wa_fcat-outputlen = 50.
  92.   APPEND wa_fcat TO fcat.

  93.   CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
  94.           EXPORTING
  95.             i_selection          = 'X'
  96.             i_zebra              = 'X'
  97.             it_fieldcat          = fcat
  98.             i_tabname            = 'T_BWART'
  99. *              I_CHECKBOX_FIELDNAME = 'CHECKBOX'
  100.           IMPORTING
  101.             es_selfield          = l_selfield
  102.           TABLES
  103.             t_outtab             = t_bwart.

  104.   IF l_selfield-tabindex GT 0.
  105.     CLEAR w_bwart.
  106.     READ TABLE t_bwart INDEX l_selfield-tabindex INTO w_bwart.
  107.     IF w_bwart-bwart IS NOT INITIAL.

  108.       DATA: ltab_fields LIKE dynpread OCCURS 0 WITH HEADER LINE.

  109.       DATA: lc_dyname LIKE sy-repid.
  110.       DATA: lc_dynumb LIKE sy-dynnr.

  111.       lc_dyname = sy-repid.
  112.       lc_dynumb = sy-dynnr.

  113.       ltab_fields-fieldname  = 'P_BWART'.
  114.       ltab_fields-fieldvalue = w_bwart-bwart.
  115.       APPEND ltab_fields.
  116.       ltab_fields-fieldname  = 'P_SOBKZ'.
  117.       ltab_fields-fieldvalue = w_bwart-sobkz.
  118.       APPEND ltab_fields.

  119.       CALL FUNCTION 'DYNP_VALUES_UPDATE'
  120.         EXPORTING
  121.           dyname     = lc_dyname
  122.           dynumb     = lc_dynumb
  123.         TABLES
  124.           dynpfields = ltab_fields
  125.         EXCEPTIONS
  126.           OTHERS     = 8.
  127.     ENDIF.
  128.   ENDIF.
复制代码

程序执行效果:
DYNP_VALUES_UPDATE 1.png
p_bwart,F4选择数值之后,p_sobkz里的值会自动更新进去,不用回车
DYNP_VALUES_UPDATE 2.png
ltab_fields内表值:
DYNP_VALUES_UPDATE 3.png
PS: DYNP_VALUES_UPDATE函数常用在search help的search help exit里

选择屏幕字段栏位实时更新函数:
  1. CALL FUNCTION 'DYNP_VALUES_UPDATE'
  2.         EXPORTING
  3.           dyname               = sy-repid
  4.           dynumb               = sy-dynnr
  5.         TABLES
  6.           dynpfields           = dyn_fields
  7.         EXCEPTIONS
  8.           invalid_abapworkarea = 1
  9.           invalid_dynprofield  = 2
  10.           invalid_dynproname   = 3
  11.           invalid_dynpronummer = 4
  12.           invalid_request      = 5
  13.           no_fielddescription  = 6
  14.           undefind_error       = 7
  15.           OTHERS               = 8.
复制代码

选择屏幕字段栏位读取函数:
  1. CALL FUNCTION 'DYNP_VALUES_READ'
  2.     EXPORTING
  3.        dyname                = sy-repid
  4.        dynumb                = sy-dynnr
  5.     TABLES
  6.        dynpfields            = lt_dynpread
  7.     EXCEPTIONS
  8.        invalid_abapworkarea = 1
  9.        invalid_dynprofield   = 2
  10.        invalid_dynproname    = 3
  11.        invalid_dynpronummer = 4
  12.        invalid_request       = 5
  13.        no_fielddescription   = 6
  14.        invalid_parameter     = 7
  15.        undefind_error        = 8
  16.        double_conversion     = 9
  17.        stepl_not_found       = 10
  18.       OTHERS                = 11.
复制代码
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表