ITPUB论坛-中国专业的IT技术社区

 找回密码
 注册
查看: 3916|回复: 0

[ABAP] 参考sap标准文档,alv grid 不成功,附上源码

[复制链接]
认证徽章
论坛徽章:
0
发表于 2017-12-21 12:57 | 显示全部楼层 |阅读模式
小弟,刚学abap不久,学到面对对象的alv,就是无法实现效果,找了网上各种教程,就是不成功,无奈所以上来,希望得到指点。恳请大家指正。程序ZSTALV_002结构大致如下:
ALV002.png
ZSTALV_002程序,数据来源demo中的sflight ,全部代码如下:
  1. REPORT ZSTALV_002.
  2. *Step 1# Add a custom control on the screen which will be related to the custom container.
  3. * Let’s give it the name ‘CC_ALV’.
  4. *Step 2 # Declare global variables to be used for ALV Grid.
  5. *-- Global data definitions for ALV
  6. *--- ALV Grid instance reference
  7. DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid .
  8. *--- Name of the custom control added on the screen
  9. DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV'.
  10. *--- Custom container instance reference
  11. DATA gr_ccontainer TYPE REF TO cl_gui_custom_container .
  12. *--- Field catalog table
  13. DATA gt_fieldcat TYPE lvc_t_fcat .
  14. *--- Layout structure
  15. DATA gs_layout TYPE lvc_s_layo .

  16. *Code Part 1 – Global data definitions for ALV
  17. *Step 3 # Declare your internal table which is supposed to hold the list data. Let’s name it “gt_list”.
  18. *Here is an example declaration.
  19. *--- Internal table holding list data
  20. DATA BEGIN OF gt_list OCCURS 0 .
  21. INCLUDE STRUCTURE SFLIGHT .
  22. *--In further sections, some additional fields will added here
  23. *--for some functionality
  24. DATA END OF gt_list .

  25. START-OF-SELECTION.
  26. SELECT * FROM sflight INTO TABLE gt_list.

  27. CALL SCREEN 100.

  28. *Code Part 2 – Declaration of the internal table that will hold the list data
  29. *We will use the data of table SFLIGHT as our list data.

  30. INCLUDE ZSTALV_002_OPD.

  31. FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat .
  32. DATA ls_fcat type lvc_s_fcat .
  33. ls_fcat-fieldname = 'CARRID' .
  34. ls_fcat-inttype = 'C' .
  35. ls_fcat-outputlen = '3' .
  36. ls_fcat-coltext = 'Carrier ID' .
  37. ls_fcat-seltext = 'Carrier ID' .
  38. APPEND ls_fcat to pt_fieldcat .
  39. CLEAR ls_fcat .
  40. ls_fcat-fieldname = 'CONNID' .
  41. ls_fcat-ref_table = 'SFLIGHT' .
  42. ls_fcat-ref_table = 'CONNID' .
  43. ls_fcat-outputlen = '3' .
  44. ls_fcat-coltext = 'Connection ID' .
  45. ls_fcat-seltext = 'Connection ID' .
  46. APPEND ls_fcat to pt_fieldcat .
  47. ENDFORM .

  48. FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo.
  49. ps_layout-zebra = 'X' .
  50. ps_layout-grid_title = 'Flights' .
  51. ps_layout-smalltitle = 'X' .
  52. ENDFORM. " prepare_layout

  53. FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions .
  54. DATA ls_exclude TYPE ui_func.
  55. ls_exclude = cl_gui_alv_grid=>mc_fc_maximum .
  56. APPEND ls_exclude TO pt_exclude.
  57. ls_exclude = cl_gui_alv_grid=>mc_fc_minimum .
  58. APPEND ls_exclude TO pt_exclude.
  59. ls_exclude = cl_gui_alv_grid=>mc_fc_subtot .
  60. APPEND ls_exclude TO pt_exclude.
  61. ls_exclude = cl_gui_alv_grid=>mc_fc_sum .
  62. APPEND ls_exclude TO pt_exclude.
  63. ls_exclude = cl_gui_alv_grid=>mc_fc_average .
  64. APPEND ls_exclude TO pt_exclude.
  65. ls_exclude = cl_gui_alv_grid=>mc_mb_sum .
  66. APPEND ls_exclude TO pt_exclude.
  67. ls_exclude = cl_gui_alv_grid=>mc_mb_subtot .
  68. ENDFORM .


  69. FORM prepare_sort_table CHANGING pt_sort TYPE lvc_t_sort .
  70. DATA ls_sort TYPE lvc_s_sort .
  71. ls_sort-spos = '1' .
  72. ls_sort-fieldname = 'CARRID' .
  73. ls_sort-up = 'X' . "A to Z
  74. ls_sort-down = space .
  75. APPEND ls_sort TO pt_sort .
  76. ls_sort-spos = '2' .
  77. ls_sort-fieldname = 'SEATSOCC' .
  78. ls_sort-up = space .
  79. ls_sort-down = 'X' . "Z to A
  80. APPEND ls_sort TO pt_sort .
  81. ENDFORM. " prepare_sort_table

  82. FORM prepare_filter_table CHANGING pt_filt TYPE lvc_t_filt .
  83. DATA ls_filt TYPE lvc_s_filt .
  84. ls_filt-fieldname = 'FLDATE' .
  85. ls_filt-sign = 'E' .
  86. ls_filt-option = 'BT' .
  87. ls_filt-low = '20030101' .
  88. ls_filt-high = '20031231' .
  89. APPEND ls_filt TO pt_filt .
  90. ENDFORM. " prepare_filter_table
复制代码
屏幕设计:
中间有一个cc_alv的框。
有一个测试展示的文本显示文本“displey”
SCREEN.png
屏幕设计逻辑流:
逻辑流.png
点击display_alv函数,进入include页面:

opd.png
display_alv全部代码如下:
  1. FORM DISPLAY_ALV .
  2. IF gr_alvgrid IS INITIAL .
  3. *----Creating custom container instance
  4. CREATE OBJECT gr_ccontainer
  5. EXPORTING
  6. container_name = gc_custom_control_name
  7. EXCEPTIONS
  8. cntl_error = 1
  9. cntl_system_error = 2
  10. create_error = 3
  11. lifetime_error = 4
  12. lifetime_dynpro_dynpro_link = 5
  13. others = 6 .
  14. IF sy-subrc <> 0.
  15. *--Exception handling
  16. ENDIF.
  17. *----Creating ALV Grid instance
  18. CREATE OBJECT gr_alvgrid
  19. EXPORTING
  20. i_parent = gr_ccontainer
  21. EXCEPTIONS
  22. error_cntl_create = 1
  23. error_cntl_init = 2
  24. error_cntl_link = 3
  25. error_dp_create = 4
  26. others = 5 .
  27. IF sy-subrc <> 0.
  28. *--Exception handling
  29. ENDIF.
  30. *----Preparing field catalog.
  31. PERFORM prepare_field_catalog CHANGING gt_fieldcat .
  32. *----Preparing layout structure
  33. PERFORM prepare_layout CHANGING gs_layout .
  34. *----Here will be additional preparations
  35. *--e.g. initial sorting criteria, initial filtering criteria, excluding
  36. *--functions
  37. CALL METHOD gr_alvgrid->set_table_for_first_display
  38. EXPORTING
  39. * I_BUFFER_ACTIVE =
  40. * I_CONSISTENCY_CHECK =
  41. * I_STRUCTURE_NAME =
  42. * IS_VARIANT =
  43. * I_SAVE =
  44. * I_DEFAULT = 'X'
  45. is_layout = gs_layout
  46. * IS_PRINT =
  47. * IT_SPECIAL_GROUPS =
  48. * IT_TOOLBAR_EXCLUDING =
  49. * IT_HYPERLINK =
  50. CHANGING
  51. it_outtab = gt_list[]
  52. it_fieldcatalog = gt_fieldcat
  53. * IT_SORT =
  54. * IT_FILTER =
  55. EXCEPTIONS
  56. invalid_parameter_combination = 1
  57. program_error = 2
  58. too_many_lines = 3
  59. OTHERS = 4 .
  60. IF sy-subrc <> 0.
  61. *--Exception handling
  62. ENDIF.
  63. ELSE .
  64. CALL METHOD gr_alvgrid->refresh_table_display
  65. * EXPORTING
  66. * IS_STABLE =
  67. * I_SOFT_REFRESH =
  68. EXCEPTIONS
  69. finished = 1
  70. OTHERS = 2 .
  71. IF sy-subrc <> 0.
  72. *--Exception handling
  73. ENDIF.
  74. ENDIF .
  75. ENDFORM.                    " DISPLAY_ALV
复制代码
屏幕状态设计:
屏幕状态.png
屏幕状态测试结果,三个按钮式出现的。
屏幕状态测试.png

然后点击ZSTALV_002中的测试,没有问题,点击激活,没有问题,再点击运行,数据没有出现。
ceshi.png
哎,折腾了几天了,看了这种书,各种文档,就是不知道面对对象的alv怎么搞出来。function alv 由于比较简单,已经弄出来的。
请大神们帮忙看看哪里有问题。是不是代码结构不对啊。


您需要登录后才可以回帖 登录 | 注册

本版积分规则

TOP技术积分榜 社区积分榜 徽章 电子杂志 团队 统计 虎吧 老博客 知识索引树 读书频道 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档 | IT博客
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛 | SAP ERP系统
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 网站律师 隐私政策 知识产权声明
京ICP备16024965号 北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表