二维码

[fmalv] 使用'REUSE_ALV_LIST_DISPLAY'建立互交式alv list

Twilight发表于 2014-07-17 14:59yny038 最后回复于 2015-04-19 10:39 [复制链接] 5543 1

该程序是通过the basic ALV list 显示 Purchase Order的头部明细,然后双击任一行,在第二个alv list 界面显示Purchase Order行项目明细

选择屏幕:       
Purchasing Document 1.png
输入采购订单号,点击执行
Purchasing Document 2.png
双击记录的任一行,跳转到第二个alv list
Purchasing Document 3.png

程序代码:
  1. ***********************************************************************
  2. * type-pools declaration
  3. ***********************************************************************
  4. TYPE-POOLS:slis.

  5. ***********************************************************************
  6. * data declarations
  7. ***********************************************************************
  8. DATA:
  9. w_ebeln TYPE ekko-ebeln,
  10. w_prog TYPE sy-repid,
  11. t_fieldcat TYPE slis_t_fieldcat_alv,
  12. fs_fieldcat LIKE LINE OF t_fieldcat,
  13. t_eventcat TYPE slis_t_event,
  14. w_eventcat LIKE LINE OF t_eventcat.

  15. ***********************************************************************
  16. * select-options declaration
  17. ***********************************************************************
  18. SELECT-OPTIONS:s_ebeln FOR w_ebeln.

  19. ***********************************************************************
  20. * internal table and field-string declarations
  21. ***********************************************************************
  22. DATA:
  23. t_ekko LIKE STANDARD TABLE OF ekko,
  24. fs_ekko LIKE LINE OF t_ekko.

  25. DATA:t_ekpo LIKE STANDARD TABLE OF ekpo,
  26. fs_ekpo LIKE LINE OF t_ekpo.

  27. ***********************************************************************
  28. *start-of-selection
  29. ***********************************************************************
  30. START-OF-SELECTION.
  31.   SELECT *
  32.   FROM ekko
  33.   INTO TABLE t_ekko
  34.   WHERE ebeln IN s_ebeln.

  35.   w_prog = sy-repid.

  36.   CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
  37.     EXPORTING
  38.       i_callback_program      = w_prog
  39.       i_callback_user_command = 'PICK'
  40.       i_structure_name        = 'EKKO'
  41.     TABLES
  42.       t_outtab                = t_ekko
  43.     EXCEPTIONS
  44.       program_error           = 1
  45.       OTHERS                  = 2.
  46.   IF sy-subrc <> 0.
  47. *message id sy-msgid type sy-msgty number sy-msgno
  48. *with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  49.   ENDIF.

  50. *&--------------------------------------------------------------------*
  51. *& form pick
  52. *&--------------------------------------------------------------------*
  53. *-->ucomm text
  54. *-->selfield text
  55. *---------------------------------------------------------------------*
  56. FORM pick USING command LIKE sy-ucomm
  57.                 selfield TYPE slis_selfield.
  58.   READ TABLE t_ekko INTO fs_ekko INDEX selfield-tabindex.  "internal output table index

  59.   CASE command.
  60.     WHEN '&IC1'.
  61.       SELECT *
  62.       FROM ekpo
  63.       INTO TABLE t_ekpo
  64.       WHERE ebeln EQ fs_ekko-ebeln.

  65.       w_prog = sy-repid.

  66.       CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'"根据内表或结构返回FIELDCAT字段结构信息
  67.         EXPORTING
  68.           i_structure_name       = 'EKPO'
  69.         CHANGING
  70.           ct_fieldcat            = t_fieldcat
  71.         EXCEPTIONS
  72.           inconsistent_interface = 1
  73.           program_error          = 2
  74.           OTHERS                 = 3.
  75.       IF sy-subrc <> 0.
  76. * message id sy-msgid type sy-msgty number sy-msgno
  77. * with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  78.       ENDIF.

  79.       DELETE t_fieldcat WHERE fieldname EQ 'EBELN'.
  80.       DELETE t_fieldcat WHERE fieldname EQ 'BUKRS'.
  81.       DELETE t_fieldcat WHERE fieldname EQ 'LGORT'.
  82.       DELETE t_fieldcat WHERE fieldname EQ 'WERKS'.

  83.       PERFORM t_eventcat."alv表头

  84.       CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
  85.         EXPORTING
  86.           i_callback_program = w_prog
  87.           it_fieldcat        = t_fieldcat
  88.           it_events          = t_eventcat
  89.         TABLES
  90.           t_outtab           = t_ekpo
  91.         EXCEPTIONS
  92.           program_error      = 1
  93.           OTHERS             = 2.
  94.       IF sy-subrc <> 0.
  95. * message id sy-msgid type sy-msgty number sy-msgno
  96. * with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  97.       ENDIF.

  98.   ENDCASE. " CASE COMMAND
  99. ENDFORM. " FORM PICK

  100. *&---------------------------------------------------------------------*
  101. *&      Form  T_EVENTCAT
  102. *&---------------------------------------------------------------------*
  103. *       text
  104. *----------------------------------------------------------------------*
  105. FORM t_eventcat.
  106.   w_eventcat-name = 'TOP_OF_PAGE'.
  107.   w_eventcat-form = 'TOP'.
  108.   APPEND w_eventcat TO t_eventcat.
  109. ENDFORM.                    "T_EVENTCAT

  110. *&---------------------------------------------------------------------*
  111. *&      Form  TOP
  112. *&---------------------------------------------------------------------*
  113. *       text
  114. *----------------------------------------------------------------------*
  115. FORM top.
  116.   READ TABLE t_ekpo INTO fs_ekpo INDEX 1.
  117.   WRITE:/ 'Purchase Document Number'(001),30 fs_ekpo-ebeln,
  118.   / 'Company Code'(002), 30 fs_ekpo-bukrs,
  119.   / 'Plant'(003), 30 fs_ekpo-werks,
  120.   / 'Storage Location'(004),30 fs_ekpo-lgort.
  121. ENDFORM.                    "TOP
复制代码
回复

使用道具 举报

yny038
学习了    楼主辛苦了{:soso_e183:}
回复 支持 反对

使用道具 举报

快速回帖

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

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