二维码

[fmalv] ABAP动态调用ALV Function

Twilight发表于 2015-09-18 10:59Twilight 最后回复于 2015-09-18 10:59 [复制链接] 1956 0

ABAP实现动态调用ALV Function:Grid ALV、List ALV

程序代码:
  1. *&---------------------------------------------------------------------*
  2. *&* write by Sariel
  3. *&---------------------------------------------------------------------*

  4. TYPE-POOLS: abap,slis.

  5. TABLES: mara.

  6. DATA: v_fname TYPE string.
  7. DATA: it_parm TYPE abap_func_parmbind_tab,
  8.       it_excp TYPE abap_func_excpbind_tab,
  9.       he_parm TYPE abap_func_parmbind,
  10.       he_excp TYPE abap_func_excpbind.
  11. DATA: it_mara TYPE STANDARD TABLE OF mara.
  12. DATA: it_fcat TYPE slis_t_fieldcat_alv.

  13. PARAMETER: r1 RADIOBUTTON GROUP rb DEFAULT 'X',
  14.            r2 RADIOBUTTON GROUP rb.

  15. START-OF-SELECTION.
  16.   PERFORM set_func_name.
  17.   PERFORM get_data_mara.
  18.   PERFORM set_parm_name.
  19.   PERFORM set_para_exep.
  20.   PERFORM exe_func_dynm.

  21. *&---------------------------------------------------------------------*
  22. *&      Form  SET_FUNC_NAME
  23. *&---------------------------------------------------------------------*
  24. FORM set_func_name .
  25.   IF r1 = abap_true.
  26.     v_fname = 'REUSE_ALV_GRID_DISPLAY'.
  27.   ELSE.
  28.     v_fname = 'REUSE_ALV_LIST_DISPLAY'.
  29.   ENDIF.
  30. ENDFORM.                    " SET_FUNC_NAME

  31. *&---------------------------------------------------------------------*
  32. *&      Form  get_data_MARA
  33. *&---------------------------------------------------------------------*
  34. FORM get_data_mara .
  35.   SELECT *
  36.     INTO TABLE it_mara
  37.     FROM mara
  38.       UP TO 100 ROWS.
  39.   he_parm-name = 'T_OUTTAB'.
  40.   he_parm-kind = abap_func_tables.
  41.   GET REFERENCE OF it_mara INTO he_parm-value.
  42.   INSERT he_parm INTO TABLE it_parm.
  43. ENDFORM.                    " get_data_MARA

  44. *&---------------------------------------------------------------------*
  45. *&      Form  SET_PARM_NAME
  46. *&---------------------------------------------------------------------*
  47. FORM set_parm_name .
  48.   CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
  49.     EXPORTING
  50.       i_structure_name       = 'MARA'
  51.     CHANGING
  52.       ct_fieldcat            = it_fcat
  53.     EXCEPTIONS
  54.       inconsistent_interface = 1
  55.       program_error          = 2
  56.       OTHERS                 = 3.
  57.   IF sy-subrc <> 0.
  58.     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  59.           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  60.   ENDIF.
  61.   he_parm-name = 'IT_FIELDCAT'.
  62.   he_parm-kind = abap_func_exporting.
  63.   GET REFERENCE OF it_fcat INTO he_parm-value.
  64.   INSERT he_parm INTO TABLE it_parm.
  65. ENDFORM.                    " SET_PARM_NAME

  66. *&---------------------------------------------------------------------*
  67. *&      Form  SET_PARA_EXEP
  68. *&---------------------------------------------------------------------*
  69. FORM set_para_exep .
  70.   he_excp-name = 'PROGRAM_ERROR'.
  71.   he_excp-value = 1.
  72.   INSERT he_excp INTO TABLE it_excp.
  73. ENDFORM.                    " SET_PARA_EXEP

  74. *&---------------------------------------------------------------------*
  75. *&      Form  EXE_FUNC_DYNM
  76. *&---------------------------------------------------------------------*
  77. FORM exe_func_dynm .
  78.   CALL FUNCTION v_fname
  79.     PARAMETER-TABLE
  80.     it_parm
  81.     EXCEPTION-TABLE
  82.     it_excp.
  83. ENDFORM.                    " EXE_FUNC_DYNM
复制代码


测试结果:
动态alv.jpg
回复

使用道具 举报

快速回帖

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

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