Пример работы с ALV на основе ФМ REUSE_ALV_GRID_DISPLAY

  1. *---------------------------------------------------------------------*
  2. *& Report ZBW_P_AG_VAMIXLS
  3. *&
  4. *---------------------------------------------------------------------*
  5. *&
  6. *&
  7. *---------------------------------------------------------------------*
  8. *---------------------------------------------------------------------*
  9. *&Created by: Artyom Grabarov
  10. *&Created on: 03.04.2014
  11. *&Version: 1.0
  12. *---------------------------------------------------------------------*
  13. *&Comments:
  14. *&Демо программа для модификации загруженной таблицы (ZBW_TABL_CORRTAB)
  15. *&соответствия реквизитов перевозки и статей доходов
  16. *&
  17. *---------------------------------------------------------------------*
  18. report zbw_p_ag_vamixls.
  19. include zbw_p_ag_vamixls_data.
  20. include zbw_p_ag_vamixls_scr.
  21. include zbw_p_ag_vamixls_sel.
  22.  
  23.  
  24. w_command = 'USER_COMMAND'.
  25. w_pfsta = 'SET_PF_STAT'.
  26.  
  27.  
  28.  
  29. * Example of build fieldcat
  30. line_fieldcat-fieldname = 'Z_REVENUES_GROUP'.
  31. line_fieldcat-tabname = 'ITAB'.
  32. line_fieldcat-seltext_m = 'Группа доходов'.
  33. line_fieldcat-edit = 'X'.
  34. * for F4 set reftable and refname
  35. line_fieldcat-ref_tabname = '/BI0/MPROFIT_CTR'.
  36. line_fieldcat-ref_fieldname = 'PROFIT_CTR'.
  37. append line_fieldcat to i_fieldcat.
  38. clear line_fieldcat.
  39.  
  40. line_fieldcat-fieldname = 'Z_INCOME_ITEM'.
  41. line_fieldcat-tabname = 'ITAB'.
  42. line_fieldcat-seltext_m = 'Статья доходов'.
  43. * for custom field length set outputlen
  44. line_fieldcat-outputlen = '60'.
  45. line_fieldcat-ref_tabname = 'ZBW_TABL_CORRTAB'.
  46. line_fieldcat-ref_fieldname = 'Z_INCOME_ITEM'.
  47. append line_fieldcat to i_fieldcat.
  48. clear line_fieldcat.
  49.  
  50. line_fieldcat-fieldname = 'Z_MZHS'.
  51. line_fieldcat-tabname = 'ITAB'.
  52. line_fieldcat-seltext_m = 'МЖС'.
  53. line_fieldcat-edit = 'X'.
  54. * for checkbox set checkbox
  55. line_fieldcat-checkbox = 'X'.
  56. line_fieldcat-outputlen = '5'.
  57. append line_fieldcat to i_fieldcat.
  58. clear line_fieldcat.
  59.  
  60. line_fieldcat-fieldname = 'Z_PV'.
  61. line_fieldcat-tabname = 'ITAB'.
  62. line_fieldcat-seltext_m = 'ПВ'.
  63. line_fieldcat-edit = 'X'.
  64. line_fieldcat-checkbox = 'X'.
  65. line_fieldcat-outputlen = '5'.
  66. append line_fieldcat to i_fieldcat.
  67. clear line_fieldcat.
  68.  
  69. line_fieldcat-fieldname = 'Z_PK'.
  70. line_fieldcat-tabname = 'ITAB'.
  71. line_fieldcat-seltext_m = 'ПК'.
  72. line_fieldcat-edit = 'X'.
  73. line_fieldcat-checkbox = 'X'.
  74. line_fieldcat-outputlen = '5'.
  75. append line_fieldcat to i_fieldcat.
  76. clear line_fieldcat.
  77.  
  78. line_fieldcat-fieldname = 'Z_LT'.
  79. line_fieldcat-tabname = 'ITAB'.
  80. line_fieldcat-seltext_m = 'ЛТ'.
  81. line_fieldcat-edit = 'X'.
  82. line_fieldcat-checkbox = 'X'.
  83. line_fieldcat-outputlen = '5'.
  84. append line_fieldcat to i_fieldcat.
  85. clear line_fieldcat.
  86.  
  87. line_fieldcat-fieldname = 'Z_GKR'.
  88. line_fieldcat-tabname = 'ITAB'.
  89. line_fieldcat-seltext_m = 'ГКР'.
  90. line_fieldcat-edit = 'X'.
  91. line_fieldcat-checkbox = 'X'.
  92. line_fieldcat-outputlen = '5'.
  93. append line_fieldcat to i_fieldcat.
  94. clear line_fieldcat.
  95.  
  96. line_fieldcat-fieldname = 'Z_PAYMENT_CODE'.
  97. line_fieldcat-tabname = 'ITAB'.
  98. line_fieldcat-seltext_m = 'Код платежа'.
  99. line_fieldcat-edit = 'X'.
  100. line_fieldcat-outputlen = '20'.
  101. append line_fieldcat to i_fieldcat.
  102. clear line_fieldcat.
  103.  
  104. line_fieldcat-fieldname = 'Z_PAYER_CODE'.
  105. line_fieldcat-tabname = 'ITAB'.
  106. line_fieldcat-seltext_m = 'Код платильщика'.
  107. line_fieldcat-edit = 'X'.
  108. line_fieldcat-outputlen = '20'.
  109. append line_fieldcat to i_fieldcat.
  110. clear line_fieldcat.
  111.  
  112. line_fieldcat-fieldname = 'Z_PLACE_AND_FORM'.
  113. line_fieldcat-tabname = 'ITAB'.
  114. line_fieldcat-seltext_m = 'Место и форма расчета'.
  115. line_fieldcat-edit = 'X'.
  116. line_fieldcat-outputlen = '20'.
  117. append line_fieldcat to i_fieldcat.
  118. clear line_fieldcat.
  119.  
  120. line_fieldcat-fieldname = 'Z_PLACE_AND_FORM'.
  121. line_fieldcat-tabname = 'ITAB'.
  122. line_fieldcat-seltext_m = 'Место и форма расчета'.
  123. line_fieldcat-edit = 'X'.
  124. line_fieldcat-outputlen = '20'.
  125. append line_fieldcat to i_fieldcat.
  126. clear line_fieldcat.
  127.  
  128. line_fieldcat-fieldname = 'Z_TYPE_OF_MSG'.
  129. line_fieldcat-tabname = 'ITAB'.
  130. line_fieldcat-seltext_m = 'Вид сообщения'.
  131. line_fieldcat-edit = 'X'.
  132. line_fieldcat-outputlen = '20'.
  133. append line_fieldcat to i_fieldcat.
  134. clear line_fieldcat.
  135.  
  136. line_fieldcat-fieldname = 'Z_PROPERTY_SIGN'.
  137. line_fieldcat-tabname = 'ITAB'.
  138. line_fieldcat-seltext_m = 'Признак собственности'.
  139. line_fieldcat-edit = 'X'.
  140. line_fieldcat-ref_tabname = '/BIC/MYRU_PRS'.
  141. line_fieldcat-ref_fieldname = '/BIC/YRU_PRS'.
  142. line_fieldcat-outputlen = '20'.
  143. append line_fieldcat to i_fieldcat.
  144. clear line_fieldcat.
  145.  
  146. line_fieldcat-fieldname = 'Z_SIGN_OF_IT'.
  147. line_fieldcat-tabname = 'ITAB'.
  148. line_fieldcat-seltext_m = 'Признак международной перевозки'.
  149. line_fieldcat-edit = 'X'.
  150. line_fieldcat-ref_tabname = '/BIC/MYRU_PRMP'.
  151. line_fieldcat-ref_fieldname = '/BIC/YRU_PRMP'.
  152. line_fieldcat-outputlen = '20'.
  153. append line_fieldcat to i_fieldcat.
  154. clear line_fieldcat.
  155.  
  156. line_fieldcat-fieldname = 'Z_SIGN_OF_V_OR_C'.
  157. line_fieldcat-tabname = 'ITAB'.
  158. line_fieldcat-seltext_m = 'Определитель вагон или контейнер'.
  159. line_fieldcat-edit = 'X'.
  160. line_fieldcat-ref_tabname = '/BIC/MYRU_OVK'.
  161. line_fieldcat-ref_fieldname = '/BIC/YRU_OVK'.
  162. line_fieldcat-outputlen = '20'.
  163. append line_fieldcat to i_fieldcat.
  164. clear line_fieldcat.
  165.  
  166. line_fieldcat-fieldname = 'Z_KIND_OF_WAGON'.
  167. line_fieldcat-tabname = 'ITAB'.
  168. line_fieldcat-seltext_m = 'род вагонов/тип(футовость) контейнеров'.
  169. line_fieldcat-edit = 'X'.
  170. line_fieldcat-outputlen = '40'.
  171. append line_fieldcat to i_fieldcat.
  172. clear line_fieldcat.
  173.  
  174. line_fieldcat-fieldname = 'Z_SHIPPING_CODE'.
  175. line_fieldcat-tabname = 'ITAB'.
  176. line_fieldcat-seltext_m = 'код груза ЕТСНГ'.
  177. line_fieldcat-edit = 'X'.
  178. line_fieldcat-outputlen = '60'.
  179. append line_fieldcat to i_fieldcat.
  180. clear line_fieldcat.
  181.  
  182. * for sorting
  183. wa_sort-spos = 1.
  184. wa_sort-fieldname = 'Z_REVENUES_GROUP'.
  185. wa_sort-tabname = 'ITAB'.
  186. wa_sort-up = 'X'.
  187. append wa_sort to it_sort.
  188. clear wa_sort.
  189.  
  190. * for combobox use this code
  191. *FIELD-SYMBOLS <fs_drop2> TYPE lvc_s_drop.
  192. *
  193. * DATA:
  194. * gt_dropdown1 TYPE lvc_t_drop.
  195. ** Listbox with flight statuses (handle '1').
  196. * APPEND INITIAL LINE TO gt_dropdown1 ASSIGNING <fs_drop2>.
  197. * <fs_drop2>-handle = '1'.
  198. * <fs_drop2>-value = '01 Scheduled'.
  199. *
  200. * APPEND INITIAL LINE TO gt_dropdown1 ASSIGNING <fs_drop2>.
  201. * <fs_drop2>-handle = '1'.
  202. * <fs_drop2>-value = '02 On-Time'.
  203. *
  204. * APPEND INITIAL LINE TO gt_dropdown1 ASSIGNING <fs_drop2>.
  205. * <fs_drop2>-handle = '1'.
  206. * <fs_drop2>-value = '03 Delayed'.
  207.  
  208.  
  209.  
  210. call function 'REUSE_ALV_GRID_DISPLAY'
  211. exporting
  212. it_fieldcat = i_fieldcat
  213. it_sort = it_sort
  214. i_callback_program = sy-repid
  215. i_callback_pf_status_set = w_pfsta
  216. i_callback_user_command = 'USER_COMMAND'
  217. it_events = events[]
  218. t_outtab = itab.
  219.  
  220.  
  221. if sy-subrc <> 0.
  222. message id sy-msgid type sy-msgty number sy-msgno
  223. with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  224.  
  225. include zbw_p_ag_vamixls_FORM.

Include ZBW_P_AG_VAMIXLS_DATA

  1. *&---------------------------------------------------------------------*
  2. *& Include ZBW_P_AG_VAMIXLS_DATA
  3. *&---------------------------------------------------------------------*
  4. tables : zbw_tabl_corrtab.
  5. type-pools : slis.
  6.  
  7. data: itab_wa type zbw_tabl_corrtab,
  8. itab type zbw_tabl_corrtab occurs 0.
  9.  
  10. data : i_fieldcat type slis_t_fieldcat_alv,
  11. i_fieldcat1 type slis_t_fieldcat_alv,
  12. w_fieldcat like line of i_fieldcat,
  13. line_fieldcat type slis_fieldcat_alv,
  14. line_fieldcat1 type slis_fieldcat_alv,
  15. report_id like sy-repid.
  16.  
  17. data : w_command type slis_formname,
  18. w_pfsta type slis_formname.
  19. data : events type slis_t_event with header line.
  20. data: temp_txt_string1 type string,
  21. temp_txt_string2 type string,
  22. temp_txt_string3 type string,
  23. temp_txt_string4 type string,
  24. numc_rev_grp type n length 10.
  25.  
  26. begin of rev_numc,
  27. sign(1),
  28. option(2),
  29. low type n length 10,
  30. high type n length 10,
  31. end of rev_numc.
  32.  
  33. data rev_numc_t type rev_numc occurs 0 with header line.
  34.  
  35. data : it_sort type slis_t_sortinfo_alv,
  36. wa_sort type slis_sortinfo_alv.

Include ZBW_P_AG_VAMIXLS_SCR

  1. *&---------------------------------------------------------------------*
  2. *& Include ZBW_P_AG_VAMIXLS_SCR
  3. *&---------------------------------------------------------------------*
  4. select-options: rev_grup for zbw_tabl_corrtab-z_revenues_group.

Include ZBW_P_AG_VAMIXLS_SEL

  1. *&---------------------------------------------------------------------*
  2. *& Include ZBW_P_AG_VAMIXLS_SEL
  3. *&---------------------------------------------------------------------*
  4. * delete leading space
  5. loop at rev_grup.
  6. shift rev_grup-low left deleting leading '0'.
  7. shift rev_grup-high left deleting leading '0'.
  8. modify rev_grup.
  9.  
  10. from zbw_tabl_corrtab into table itab
  11. where z_revenues_group in rev_grup
  12. .

Include ZBW_P_AG_VAMIXLS_FORM

  1. *&---------------------------------------------------------------------*
  2. *& Include ZBW_P_AG_VAMIXLS_FORM
  3. *&---------------------------------------------------------------------*
  4. ***************PF STATUS************************
  5. * set PF Status
  6. form set_pf_stat using rt_extab type slis_t_extab.
  7. set pf-status 'ZSTANDARD'. " you must create PF status at first
  8. endform. "SET_PF_STAT
  9. ****************************************************
  10.  
  11. ***********INTERACTIVE DISPLAY********************
  12. * Screen Logic on user comm
  13. form user_command using r_ucomm like sy-ucomm
  14. rs_selfield type slis_selfield.
  15.  
  16. data p_ref1 type ref to cl_gui_alv_grid.
  17.  
  18. call function 'GET_GLOBALS_FROM_SLVC_FULLSCR'
  19. importing
  20. e_grid = p_ref1.
  21. call method p_ref1->check_changed_data.
  22.  
  23. case r_ucomm.
  24. ********FORM SAVE************
  25. when 'SAVE'.
  26.  
  27. loop at itab into itab_wa.
  28. shift itab_wa-z_revenues_group left deleting leading '0'.
  29. modify itab from itab_wa.
  30. delete itab WHERE z_revenues_group eq '' or z_revenues_group = 0 or z_revenues_group = '0000' or z_revenues_group IS INITIAL.
  31. modify zbw_tabl_corrtab from table itab .
  32. if sy-subrc eq 0.
  33. message 'Записи сохранены' type 'S'.
  34. when 'NEW'.
  35. clear itab_wa.
  36. append itab_wa to itab.
  37.  
  38. call function 'REUSE_ALV_GRID_DISPLAY'
  39. exporting
  40. it_fieldcat = i_fieldcat
  41. it_sort = it_sort
  42. i_callback_program = sy-repid
  43. i_callback_pf_status_set = w_pfsta
  44. i_callback_user_command = 'USER_COMMAND'
  45. it_events = events[]
  46. t_outtab = itab.
  47.  
  48. when 'ENTER'.
  49. PERFORM refresh_alv.
  50. when 'DEL'.
  51. clear itab_wa.
  52. read table itab index rs_selfield-tabindex into itab_wa.
  53. delete from zbw_tabl_corrtab where z_revenues_group eq itab_wa-z_revenues_group.
  54. delete itab index rs_selfield-tabindex.
  55. call function 'REUSE_ALV_GRID_DISPLAY'
  56. exporting
  57. it_fieldcat = i_fieldcat
  58. it_sort = it_sort
  59. i_callback_program = sy-repid
  60. i_callback_pf_status_set = w_pfsta
  61. i_callback_user_command = 'USER_COMMAND'
  62. it_events = events[]
  63. t_outtab = itab.
  64. when 'BACK'.
  65. leave to screen 0.
  66. when 'EXIT'.
  67. leave program.
  68. when 'REFRESH'.
  69. PERFORM refresh_alv.
  70. WHEN 'COPYS'.
  71. clear itab_wa.
  72. read table itab index rs_selfield-tabindex into itab_wa.
  73. itab_wa-z_revenues_group = ''.
  74. itab_wa-z_income_item = ''.
  75. append itab_wa to itab.
  76. call function 'REUSE_ALV_GRID_DISPLAY'
  77. exporting
  78. it_fieldcat = i_fieldcat
  79. it_sort = it_sort
  80. i_callback_program = sy-repid
  81. i_callback_pf_status_set = w_pfsta
  82. i_callback_user_command = 'USER_COMMAND'
  83. it_events = events[]
  84. t_outtab = itab.
  85. endform. "user_command
  86.  
  87. FORM refresh_alv.
  88. loop at itab into itab_wa where z_income_item eq ''.
  89. numc_rev_grp = itab_wa-z_revenues_group.
  90. select single /bic/text_an1 /bic/text_an2 /bic/text_an3 /bic/text_an4 from /bi0/mprofit_ctr bypassing buffer into
  91. (temp_txt_string1, temp_txt_string2, temp_txt_string3, temp_txt_string4)
  92. where profit_ctr = numc_rev_grp and dateto >= sy-datum and objvers eq 'A' and co_area eq '1'.
  93. concatenate temp_txt_string1 temp_txt_string2 temp_txt_string3 temp_txt_string4 into itab_wa-z_income_item.
  94. modify itab from itab_wa.
  95.  
  96. call function 'REUSE_ALV_GRID_DISPLAY'
  97. exporting
  98. it_fieldcat = i_fieldcat
  99. it_sort = it_sort
  100. i_callback_program = sy-repid
  101. i_callback_pf_status_set = w_pfsta
  102. i_callback_user_command = 'USER_COMMAND'
  103. it_events = events[]
  104. t_outtab = itab.

Комментарии