当前位置: 代码迷 >> 报表 >> sap 会计凭证表格
  详细解决方案

sap 会计凭证表格

热度:172   发布时间:2016-05-05 07:42:08.0
sap 会计凭证报表
春节刚过,还没得心情来上班。就接到了新任务修改一下报表ZFI002财务凭证查询报表。当然对于老手来说这样的事情是小菜一碟了。也确实我是新手都2个小时搞定。所以清闲的很,用来记录以下过程。给需要的童鞋学习。任务主要是要新增加栏位:借方发生额,贷方发生额,文本,参照,用户名。并且用户名可以输入。不管它啦。先看看之前的是什么样子。呵呵~~

       输入(查询条件):公司代码:BKPF-BUKRS    凭证编号:BKPF-BELNR    会计年度:BKPF- GJAHR   凭证类型:BKPF- BLART    凭证日期:BKPF-BLDAT   过账日期:BKPF-BUDAT   用户名:BKPF-USNAM(新增加哦~)
   
     表有:T_BKPF,T_BSEG,T_LFA1,T_SKAT
   
     处理过程有:GET_BKPF()-->CHECK_BKPF()-->GET_BSEG()-->PROCESS_BSEG()-->EVENTS_BUILD()-->LAYOUT_BUILD()-->FIELDS_BUILD()-->DISPLAY_BUILD().


    是不是很啰嗦啊,其实就是那么简单嘛,分析要求:取数据-->处理数据-->alv显示  其实很多ABAP的报表都是这样的一个套路。好了,其他的也就不多说了,直接上Code.



[plain] view plaincopyprint?
01.*&---------------------------------* 
02.*& Report  ZFI002 
03.*&---------------------------------* 
04.* Author : RobertLee 
05.* Date   : 2008.05.02 
06.* Purpose: FI Doc Report using ALV For Finance 
07.* 
08.*&---------------------------------* 
09.* Change : Jasson.Lee 
10.* Date   : 2012.02.14 
11.* Purpose: FI Doc Report using ALV For Finance  Add col 
12.* 
13.*---------------------------------- 
14.REPORT  ZFI002. 
15. 
16.TABLES:   BKPF,BSEG,LFA1,SKAT. 
17.*-------------------------------- 
18.* Global Types 
19.* Essential Declaration for ALV Display 
20.*-------------------------------- 
21.TYPE-POOLS: slis. 
22.*-------------------------------- 
23.* Global Internal Tables 
24.*-------------------------------- 
25.DATA: 
26.  i_fieldcat_alv  TYPE slis_t_fieldcat_alv , 
27.  i_layout        TYPE slis_layout_alv, 
28.  i_fieldcat      TYPE slis_fieldcat_alv, 
29.  i_events        TYPE slis_t_event, 
30.  w_events  LIKE LINE OF i_events, 
31.  i_list_comments TYPE slis_t_listheader, 
32.  w_list_comments LIKE LINE OF i_list_comments, 
33.  w_repid LIKE sy-repid. 
34. 
35.DATA: BEGIN OF T_BKPF OCCURS 0, 
36.       BUKRS LIKE BKPF-BUKRS,  "CoCode 
37.       BELNR LIKE BKPF-BELNR,  "FI Doc 
38.       GJAHR LIKE BKPF-GJAHR,  "Fiscal Year 
39.       BLART LIKE BKPF-BLART,  "Doc Type 
40.       BLDAT LIKE BKPF-BLDAT,  "Doc Date 
41.       BUDAT LIKE BKPF-BUDAT,  "Posting Date 
42.       TCODE LIKE BKPF-TCODE,  "Transaction Code 
43.       AWKEY LIKE BKPF-AWKEY,  "Reference Doc 
44.       BSTAT LIKE BKPF-BSTAT,  "Document Status 
45.       BKTXT LIKE BKPF-BKTXT,  " txt 
46.       XBLNR LIKE BKPF-XBLNR,  " ref 
47.       USNAM LIKE BKPF-USNAM,  " user name 
48.      END OF T_BKPF. 
49. 
50.DATA: BEGIN OF T_BSEG OCCURS 0, 
51.       BUKRS LIKE BSEG-BUKRS,  "CoCode 
52.       BELNR LIKE BSEG-BELNR,  "FI Doc 
53.       GJAHR LIKE BSEG-GJAHR,  "Fiscal Year 
54.       BUZEI LIKE BSEG-BUZEI,  "Item 
55.       SHKZG LIKE BSEG-SHKZG,  "Credit or Debit 
56.       PSWSL LIKE BSEG-PSWSL,  "Cur 
57.       DMBTR like BSEG-DMBTR,  "Local Amount 
58.       PSWBT LIKE BSEG-PSWBT,  "Amount 
59.       SAKNR LIKE BSEG-SAKNR,  "G/L Account Number 
60.       HKONT LIKE BSEG-HKONT,  "General Ledger Account 
61.       LIFNR LIKE BSEG-LIFNR,  "Account Number of Vendor or Creditor 
62.       BSCHL LIKE BSEG-BSCHL,  "Posting Key 
63. 
64.       BLART LIKE BKPF-BLART,  "Doc Type 
65.       BLDAT LIKE BKPF-BLDAT,  "Doc Date 
66.       BUDAT LIKE BKPF-BUDAT,  "Posting Date 
67.       TCODE LIKE BKPF-TCODE,  "Transaction Code 
68.       AWKEY LIKE BKPF-AWKEY,  "Reference Doc 
69.       BSTAT LIKE BKPF-BSTAT,  "Document status 
70.       TXT20 LIKE SKAT-TXT20,  "G/L Acccount Name 
71.       NAME1 LIKE LFA1-NAME1,  "Vendor Name 
72.       PSWBT1 LIKE BSEG-PSWBT,  "Amount 
73.       PSWBT2 LIKE BSEG-PSWBT,  "Amount 
74.       BKTXT LIKE BKPF-BKTXT,  " txt 
75.       XBLNR LIKE BKPF-XBLNR,  " ref 
76.       USNAM LIKE BKPF-USNAM,  " user name 
77.      END OF T_BSEG. 
78. 
79.DATA: BEGIN OF T_LFA1 OCCURS 0, 
80.      LIFNR LIKE LFA1-LIFNR, 
81.      NAME1 LIKE LFA1-NAME1, 
82.     END OF T_LFA1. 
83.DATA: BEGIN OF T_SKAT OCCURS 0, 
84.      SAKNR LIKE SKAT-SAKNR, 
85.      TXT20 LIKE SKAT-TXT20, 
86.      END OF T_SKAT. 
87.DATA W_LEN TYPE I. 
88.*-------------------------------- 
89.* Selection Screen 
90.*-------------------------------- 
91.SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. 
92.SELECT-OPTIONS: 
93.  S_BUKRS FOR BKPF-BUKRS Default 5000,    "CoCode 
94.  S_BELNR FOR BKPF-BELNR,                 "FI Doc 
95.  S_GJAHR FOR BKPF-GJAHR Default 2008,    "Fiscal Year 
96.  S_BLART FOR BKPF-BLART,                 "Doc Type 
97.  S_BLDAT FOR BKPF-BLDAT,                 "Doc Date 
98.  S_BUDAT FOR BKPF-BUDAT,                 "Posting Date 
99.  S_USNAM FOR BKPF-USNAM. 
100.SELECTION-SCREEN END OF BLOCK b1. 
101. 
102.*-------------------------------- 
103.* Initialization 
104.*-------------------------------- 
105.INITIALIZATION. 
106. 
107.*-------------------------------- 
108.* At Selection Screen PBO 
109.*-------------------------------- 
110.AT SELECTION-SCREEN OUTPUT. 
111. 
112.*-------------------------------- 
113.* Start of Selection 
114.*-------------------------------- 
115.START-OF-SELECTION. 
116.  PERFORM GET_BKPF. 
117.  PERFORM CHECK_BKPF. 
118.  PERFORM GET_BSEG. 
119.  PERFORM Process_BSEG. 
120.  PERFORM Events_build. 
121.  PERFORM Layout_build. 
122.  PERFORM Fields_bulid. 
123.  PERFORM Display_data. 
124. 
125.END-OF-SELECTION. 
126.*-------------------------------- 
127.* Top of Page 
128.*-------------------------------- 
129.TOP-OF-PAGE. 
130. 
131.*-------------------------------- 
132.* At User Command 
133.*-------------------------------- 
134.AT USER-COMMAND. 
135.*-------------------------------- 
136.* At Line Selection 
137.*-------------------------------- 
138.AT LINE-SELECTION. 
139. 
140.*&---------------------------------* 
141.*&      Form  display_data 
142.*&---------------------------------* 
143.FORM display_data. 
144. 
145.  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' 
146.   EXPORTING 
147.     i_callback_user_command           = 'USER_COMMAND'           "用户触发事件 
148.*    i_callback_pf_status_set          = 'PF_STATUS_SET'(001)     "调用用户事件和按钮事件 
149.     i_callback_program                = w_repid                  "当前程序 
150.     is_layout                         = i_layout                 "子函数layout_build填充的格式定义 
151.     it_fieldcat                       = i_fieldcat_alv[]         "子函数fields填充的各列 
152.     it_events                         = i_events[] 
153.     i_save                            = 'A'                      "保存变式 
154.    TABLES 
155.      t_outtab                          = T_BSEG. 
156. 
157.ENDFORM.                    "display_data 
158.*---------------------------------* 
159.*       FORM user_command                                             * 
160.*---------------------------------* 
161.FORM USER_COMMAND  USING i_ucomm LIKE sy-ucomm 
162.                           selfield TYPE slis_selfield. 
163.  CASE i_ucomm. 
164.    WHEN '&IC1'. 
165.      CASE selfield-sel_tab_field. 
166.        WHEN '1-BELNR'. 
167.          SET PARAMETER ID 'BLN' FIELD selfield-value. 
168.          SET PARAMETER ID 'BUK' FIELD T_BSEG-BUKRS. 
169.          SET PARAMETER ID 'GJR' FIELD T_BSEG-GJAHR. 
170.          CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN. 
171.      ENDCASE. 
172.    WHEN OTHERS. 
173.  ENDCASE. 
174. 
175.ENDFORM.                    "callback_ucomm 
176. 
177.*&---------------------------------* 
178.*&      Form  GET_BKPF 
179.*&---------------------------------* 
180.*       text 
181.*----------------------------------* 
182.*  -->  p1        text 
183.*  <--  p2        text 
184.*----------------------------------* 
185.FORM GET_BKPF . 
186.*Get Data From BKPF 
187.  SELECT BUKRS BELNR GJAHR BLART BLDAT BUDAT TCODE AWKEY BSTAT BKTXT XBLNR USNAM 
188.  INTO TABLE T_BKPF 
189.  FROM BKPF 
190.  WHERE BUKRS IN S_BUKRS AND BELNR IN S_BELNR AND BLDAT IN S_BLDAT 
191.        and GJAHR in S_GJAHR and BLART in S_BLART AND BUDAT IN S_BUDAT AND USNAM IN S_USNAM . 
192.ENDFORM.                    " GET_BKPF 
193.*&---------------------------------* 
194.*&      Form  CHECK_BKPF 
195.*&---------------------------------* 
196.*       text 
197.*----------------------------------* 
198.*  -->  p1        text 
199.*  <--  p2        text 
200.*----------------------------------* 
201.FORM CHECK_BKPF . 
202.  IF T_BKPF[] IS INITIAL. 
203.    MESSAGE I000(ZMsg) with '没找到对应的数据,请更改查询条件'. 
204.    LEAVE LIST-PROCESSING. 
205.  ENDIF. 
206. 
207.ENDFORM.                    " CHECK_BKPF 
208.*&---------------------------------* 
209.*&      Form  GET_BSEG 
210.*&---------------------------------* 
211.FORM GET_BSEG. 
212.*Get Data From BSEG 
213.  SELECT BUKRS BELNR GJAHR BUZEI SHKZG PSWSL DMBTR PSWBT SAKNR HKONT LIFNR BSCHL 
214.  INTO CORRESPONDING FIELDS OF TABLE T_BSEG 
215.  FROM BSEG 
216.  FOR ALL ENTRIES IN T_BKPF 
217.  WHERE BUKRS = T_BKPF-BUKRS AND BELNR = T_BKPF-BELNR AND GJAHR = T_BKPF-GJAHR. 
218.*Get G/L Account name from skat 
219.  SELECT SAKNR TXT20 
220.  INTO TABLE T_SKAT 
221.  FROM SKAT 
222.  WHERE SPRAS = SY-LANGU AND KTOPL = 'INT'. 
223.*Get  Vendor Info from LFA1 
224.  SELECT LIFNR NAME1 
225.  INTO TABLE T_LFA1 
226.  FROM LFA1 
227.  FOR ALL ENTRIES IN T_BSEG 
228.  WHERE LIFNR = T_BSEG-LIFNR. 
229.ENDFORM.                    "GET_BSEG 
230.*&---------------------------------* 
231.*&      Form  events_build 
232.*&---------------------------------* 
233.FORM events_build. 
234. 
235.  CALL FUNCTION 'REUSE_ALV_EVENTS_GET' 
236.    EXPORTING 
237.      i_list_type = 0 
238.    IMPORTING 
239.      et_events   = i_events. 
240. 
241.*  READ TABLE i_events  WITH KEY name = 'TOP_OF_PAGE'  INTO w_events. 
242.*  IF sy-subrc = 0. 
243.*    MOVE 'ALV_TOP_OF_PAGE' TO w_events-form. 
244.*    MODIFY i_events FROM w_events INDEX sy-tabix. 
245.*  ENDIF. 
246.* 
247.*  READ TABLE i_events  WITH KEY name = 'END_OF_LIST'  INTO w_events. 
248.*  IF sy-subrc = 0. 
249.*    MOVE 'ALV_END_OF_LIST' TO w_events-form. 
250.*    MODIFY i_events FROM w_events INDEX sy-tabix. 
251.*  ENDIF. 
252. 
253.  READ TABLE i_events WITH KEY name = 'USER_COMMAND'   INTO w_events. 
254.  IF sy-subrc = 0. 
255.    MOVE 'USER_COMMAND' TO w_events-form. 
256.    MODIFY i_events FROM w_events INDEX sy-tabix. 
257.  ENDIF. 
258. 
259.ENDFORM.                    "events_build 
260. 
261.*&---------------------------------* 
262.*&      Form  layout_build 
263.*&---------------------------------* 
264.FORM layout_build. 
265.*  i_layout-detail_popup        = 'X'.    "弹出详细信息窗口 
266.*  i-layout-no_vline            = 'X'.    "设置列间隔线 
267.  i_layout-info_fieldname       = 'COLOR'.  "颜色值 
268.  i_layout-colwidth_optimize    = 'X'.    "优化列宽选项 
269.  i_layout-detail_initial_lines = 'X'. 
270.  i_layout-detail_titlebar      = '凭证查询报表'. 
271.  i_layout-no_colhead           =' '. 
272.  w_repid = sy-repid. 
273. 
274.ENDFORM.                    "layout_build 
275. 
276. 
277.*&---------------------------------* 
278.*&      Form  Fields_Bulid 
279.*&---------------------------------* 
280.*       text 
281.*----------------------------------* 
282.*  -->  p1        text 
283.*  <--  p2        text 
284.*----------------------------------* 
285.FORM fields_bulid . 
286.  DATA tmp_pos TYPE i. 
287.  REFRESH i_fieldcat_alv. 
288.  CLEAR i_fieldcat. 
289. 
290.  tmp_pos = 1. 
291.  i_fieldcat-col_pos = tmp_pos. 
292.  i_fieldcat-fieldname = 'BLART'. 
293.  i_fieldcat-seltext_l = '凭证类型'. 
294.  i_fieldcat-key = 'X'. 
295.  APPEND i_fieldcat TO i_fieldcat_alv. 
296.  CLEAR i_fieldcat. 
297. 
298.  tmp_pos = tmp_pos + 1. 
299.  i_fieldcat-col_pos = tmp_pos. 
300.  i_fieldcat-fieldname = 'BUKRS'. 
301.  i_fieldcat-seltext_l = '公司代码'. 
302.  i_fieldcat-outputlen  = '15'. 
303.  i_fieldcat-no_zero = 'X'. 
304.  i_fieldcat-key = 'X'. 
305.  APPEND i_fieldcat TO i_fieldcat_alv. 
306.  CLEAR i_fieldcat. 
307. 
308.  tmp_pos = tmp_pos + 1. 
309.  i_fieldcat-col_pos = tmp_pos. 
310.  i_fieldcat-fieldname = 'BELNR'. 
311.  i_fieldcat-seltext_l = '会计凭证号'. 
312.  i_fieldcat-outputlen  = '10'. 
313.  APPEND i_fieldcat TO i_fieldcat_alv. 
314.  CLEAR i_fieldcat. 
315. 
316.  tmp_pos = tmp_pos + 1. 
317.  i_fieldcat-col_pos = tmp_pos. 
318.  i_fieldcat-fieldname = 'BLDAT'. 
319.  i_fieldcat-seltext_l = '凭证日期'. 
320.  APPEND i_fieldcat TO i_fieldcat_alv. 
321.  CLEAR i_fieldcat. 
322. 
323.  tmp_pos = tmp_pos + 1. 
324.  i_fieldcat-col_pos = tmp_pos. 
325.  i_fieldcat-fieldname = 'BUDAT'. 
326.  i_fieldcat-seltext_l = '过账日期'. 
327.  APPEND i_fieldcat TO i_fieldcat_alv. 
328.  CLEAR i_fieldcat. 
329. 
330.  tmp_pos = tmp_pos + 1. 
331.  i_fieldcat-col_pos = tmp_pos. 
332.  i_fieldcat-fieldname = 'GJAHR'. 
333.  i_fieldcat-seltext_l = '年度'. 
334.  APPEND i_fieldcat TO i_fieldcat_alv. 
335.  CLEAR i_fieldcat. 
336. 
337.  tmp_pos = tmp_pos + 1. 
338.  i_fieldcat-col_pos = tmp_pos. 
339.  i_fieldcat-fieldname = 'BUZEI'. 
340.  i_fieldcat-seltext_l = '项目'. 
341.  APPEND i_fieldcat TO i_fieldcat_alv. 
342.  CLEAR i_fieldcat. 
343. 
344. 
345.  tmp_pos = tmp_pos + 1. 
346.  i_fieldcat-col_pos = tmp_pos. 
347.  i_fieldcat-fieldname = 'BSCHL'. 
348.  i_fieldcat-seltext_l = 'PK'. 
349.  APPEND i_fieldcat TO i_fieldcat_alv. 
350.  CLEAR i_fieldcat. 
351. 
352.  tmp_pos = tmp_pos + 1. 
353.  i_fieldcat-col_pos = tmp_pos. 
354.  i_fieldcat-fieldname = 'SHKZG'. 
355.  i_fieldcat-seltext_l = '借方/贷方'. 
356.  i_fieldcat-no_out = 'X'. 
357.  APPEND i_fieldcat TO i_fieldcat_alv. 
358.  CLEAR i_fieldcat. 
359. 
360.  tmp_pos = tmp_pos + 1. 
361.  i_fieldcat-col_pos = tmp_pos. 
362.  i_fieldcat-fieldname = 'HKONT'. 
363.  i_fieldcat-seltext_l = '科目'. 
364.  i_fieldcat-No_Zero = 'X'. 
365.  APPEND i_fieldcat TO i_fieldcat_alv. 
366.  CLEAR i_fieldcat. 
367. 
368.  tmp_pos = tmp_pos + 1. 
369.  i_fieldcat-col_pos = tmp_pos. 
370.  i_fieldcat-fieldname = 'SAKNR'. 
371.  i_fieldcat-seltext_l = '总帐科目'. 
372.  i_fieldcat-No_Zero = 'X'. 
373.  i_fieldcat-no_out = 'X'. 
374.  APPEND i_fieldcat TO i_fieldcat_alv. 
375.  CLEAR i_fieldcat. 
376. 
377.  tmp_pos = tmp_pos + 1. 
378.  i_fieldcat-col_pos = tmp_pos. 
379.  i_fieldcat-fieldname = 'TXT20'. 
380.  i_fieldcat-seltext_l = '科目名'. 
381.  APPEND i_fieldcat TO i_fieldcat_alv. 
382.  CLEAR i_fieldcat. 
383. 
384.  tmp_pos = tmp_pos + 1. 
385.  i_fieldcat-col_pos = tmp_pos. 
386.  i_fieldcat-fieldname = 'LIFNR'. 
387.  i_fieldcat-seltext_l = 'Vendor'. 
388.  i_fieldcat-no_out = 'X'. 
389.  APPEND i_fieldcat TO i_fieldcat_alv. 
390.  CLEAR i_fieldcat. 
391. 
392.  tmp_pos = tmp_pos + 1. 
393.  i_fieldcat-col_pos = tmp_pos. 
394.  i_fieldcat-fieldname = 'NAME1'. 
395.  i_fieldcat-seltext_l = '厂商名'. 
396.  i_fieldcat-no_out = 'X'. 
397.  APPEND i_fieldcat TO i_fieldcat_alv. 
398.  CLEAR i_fieldcat. 
399. 
400.  tmp_pos = tmp_pos + 1. 
401.  i_fieldcat-col_pos = tmp_pos. 
402.  i_fieldcat-fieldname = 'PSWSL'. 
403.  i_fieldcat-seltext_l = '币别'. 
404.  APPEND i_fieldcat TO i_fieldcat_alv. 
405.  CLEAR i_fieldcat. 
406. 
407.  tmp_pos = tmp_pos + 1. 
408.  i_fieldcat-col_pos = tmp_pos. 
409.  i_fieldcat-fieldname = 'PSWBT'. 
410.  i_fieldcat-seltext_l = '金额'. 
411.  APPEND i_fieldcat TO i_fieldcat_alv. 
412.  CLEAR i_fieldcat. 
413. 
414.  tmp_pos = tmp_pos + 1. 
415.  i_fieldcat-col_pos = tmp_pos. 
416.  i_fieldcat-fieldname = 'DMBTR'. 
417.  i_fieldcat-seltext_l = '本币金额'. 
418.  APPEND i_fieldcat TO i_fieldcat_alv. 
419.  CLEAR i_fieldcat. 
420. 
421.  tmp_pos = tmp_pos + 1. 
422.  i_fieldcat-col_pos = tmp_pos. 
423.  i_fieldcat-fieldname = 'AWKEY'. 
424.  i_fieldcat-seltext_l = '原始凭证'. 
425.  APPEND i_fieldcat TO i_fieldcat_alv. 
426.  CLEAR i_fieldcat. 
427. 
428.  tmp_pos = tmp_pos + 1. 
429.  i_fieldcat-col_pos = tmp_pos. 
430.  i_fieldcat-fieldname = 'TCODE'. 
431.  i_fieldcat-seltext_l = '原始凭证交易码'. 
432.  APPEND i_fieldcat TO i_fieldcat_alv. 
433.  CLEAR i_fieldcat. 
434. 
435.  tmp_pos = tmp_pos + 1. 
436.  i_fieldcat-col_pos = tmp_pos. 
437.  i_fieldcat-fieldname = 'BSTAT'. 
438.  i_fieldcat-seltext_l = '凭证状态'. 
439.  i_fieldcat-no_Out = 'X'. 
440.  APPEND i_fieldcat TO i_fieldcat_alv. 
441.  CLEAR i_fieldcat. 
442. 
443.  tmp_pos = tmp_pos + 1. 
444.  i_fieldcat-col_pos = tmp_pos. 
445.  i_fieldcat-fieldname = 'PSWBT1'. 
446.  i_fieldcat-seltext_l = '借方发生额'. 
447.  APPEND i_fieldcat TO i_fieldcat_alv. 
448.  CLEAR i_fieldcat. 
449. 
450.  tmp_pos = tmp_pos + 1. 
451.  i_fieldcat-col_pos = tmp_pos. 
452.  i_fieldcat-fieldname = 'PSWBT2'. 
453.  i_fieldcat-seltext_l = '贷方发生额'. 
454.  APPEND i_fieldcat TO i_fieldcat_alv. 
455.  CLEAR i_fieldcat. 
456. 
457.  tmp_pos = tmp_pos + 1. 
458.  i_fieldcat-col_pos = tmp_pos. 
459.  i_fieldcat-fieldname = 'BKTXT'. 
460.  i_fieldcat-seltext_l = '文本'. 
461.  APPEND i_fieldcat TO i_fieldcat_alv. 
462.  CLEAR i_fieldcat. 
463. 
464.  tmp_pos = tmp_pos + 1. 
465.  i_fieldcat-col_pos = tmp_pos. 
466.  i_fieldcat-fieldname = 'XBLNR'. 
467.  i_fieldcat-seltext_l = '参照'. 
468.  APPEND i_fieldcat TO i_fieldcat_alv. 
469.  CLEAR i_fieldcat. 
470. 
471.  tmp_pos = tmp_pos + 1. 
472.  i_fieldcat-col_pos = tmp_pos. 
473.  i_fieldcat-fieldname = 'USNAM'. 
474.  i_fieldcat-seltext_l = '用户名'. 
475.  APPEND i_fieldcat TO i_fieldcat_alv. 
476.  CLEAR i_fieldcat. 
477. 
478. 
479.ENDFORM.                    " Fields_Bulid 
480.*&---------------------------------* 
481.*&      Form  Process_BSEG 
482.*&---------------------------------* 
483.*       text 
484.*----------------------------------* 
485.*  -->  p1        text 
486.*  <--  p2        text 
487.*----------------------------------* 
488.FORM process_BSEG . 
489.  DATA l_loop LIKE sy-tabix. 
490.  DATA L_LEN TYPE I. 
491.  SORT T_BSEG BY BUKRS GJAHR BELNR. 
492.  SORT T_BKPF BY BUKRS GJAHR BELNR. 
493.  LOOP AT T_BSEG. 
494.    L_LOOP = SY-TABIX. 
495.    IF T_BSEG-SHKZG = 'H'. 
496.      T_BSEG-DMBTR = T_BSEG-DMBTR * ( -1 ). 
497.      T_BSEG-PSWBT = T_BSEG-PSWBT * ( -1 ). 
498.      T_BSEG-PSWBT2 = T_BSEG-PSWBT * ( -1 ). 
499.    ENDIF. 
500.    IF T_BSEG-SHKZG = 'S'. 
501.      T_BSEG-PSWBT1 = T_BSEG-PSWBT . 
502.    ENDIF. 
503.* Get G/L Account Name 
504.    READ TABLE T_SKAT WITH KEY SAKNR = T_BSEG-HKONT BINARY SEARCH. 
505.    IF SY-SUBRC = 0. 
506.      T_BSEG-TXT20 = T_SKAT-TXT20. 
507.    ENDIF. 
508.* Get Vendor Name 
509.    IF T_BSEG-SAKNR <> '' AND T_BSEG-LIFNR <> ''. 
510.      T_BSEG-HKONT = T_BSEG-LIFNR. 
511.      READ TABLE T_LFA1 WITH KEY LIFNR = T_BSEG-LIFNR BINARY SEARCH. 
512.      IF SY-SUBRC = 0. 
513.        T_BSEG-NAME1 = T_LFA1-NAME1. 
514.        T_BSEG-TXT20 = T_LFA1-NAME1. 
515.      ENDIF. 
516.    ENDIF. 
517.*Move Doc Header to Item 
518.    READ TABLE T_BKPF WITH KEY BUKRS = T_BSEG-BUKRS GJAHR = T_BSEG-GJAHR 
519.                               BELNR = T_BSEG-BELNR BINARY SEARCH. 
520.    IF SY-SUBRC = 0. 
521.      T_BSEG-BLART = T_BKPF-BLART . 
522.      T_BSEG-BLDAT = T_BKPF-BLDAT . 
523.      T_BSEG-BUDAT = T_BKPF-BUDAT . 
524.      T_BSEG-TCODE = T_BKPF-TCODE . 
525.      T_BSEG-AWKEY = T_BKPF-AWKEY . 
526.      T_BSEG-BKTXT = T_BKPF-BKTXT . 
527.      T_BSEG-XBLNR = T_BKPF-XBLNR . 
528.      T_BSEG-USNAM = T_BKPF-USNAM . 
529.    ENDIF. 
530.    IF T_BSEG-AWKEY <>' '. 
531.      W_LEN = STRLEN( T_BSEG-AWKEY ) . 
532.      IF W_LEN = 10 OR W_LEN = 14 OR W_LEN = 18. 
533.        T_BSEG-AWKEY = T_BSEG-AWKEY(10). 
534.      ENDIF. 
535.    ENDIF. 
536. 
537.    MODIFY T_BSEG. 
538.    SY-TABIX = L_LOOP. 
539.  ENDLOOP. 
540.ENDFORM.                    " Process_BSEG 
*&---------------------------------*
*& Report  ZFI002
*&---------------------------------*
* Author : RobertLee
* Date   : 2008.05.02
* Purpose: FI Doc Report using ALV For Finance
*
*&---------------------------------*
* Change : Jasson.Lee
* Date   : 2012.02.14
* Purpose: FI Doc Report using ALV For Finance  Add col
*
*----------------------------------
REPORT  ZFI002.

TABLES:   BKPF,BSEG,LFA1,SKAT.
*--------------------------------
* Global Types
* Essential Declaration for ALV Display
*--------------------------------
TYPE-POOLS: slis.
*--------------------------------
* Global Internal Tables
*--------------------------------
DATA:
  i_fieldcat_alv  TYPE slis_t_fieldcat_alv ,
  i_layout        TYPE slis_layout_alv,
  i_fieldcat      TYPE slis_fieldcat_alv,
  i_events        TYPE slis_t_event,
  w_events  LIKE LINE OF i_events,
  i_list_comments TYPE slis_t_listheader,
  w_list_comments LIKE LINE OF i_list_comments,
  w_repid LIKE sy-repid.

DATA: BEGIN OF T_BKPF OCCURS 0,
       BUKRS LIKE BKPF-BUKRS,  "CoCode
       BELNR LIKE BKPF-BELNR,  "FI Doc
       GJAHR LIKE BKPF-GJAHR,  "Fiscal Year
       BLART LIKE BKPF-BLART,  "Doc Type
       BLDAT LIKE BKPF-BLDAT,  "Doc Date
       BUDAT LIKE BKPF-BUDAT,  "Posting Date
       TCODE LIKE BKPF-TCODE,  "Transaction Code
       AWKEY LIKE BKPF-AWKEY,  "Reference Doc
       BSTAT LIKE BKPF-BSTAT,  "Document Status
       BKTXT LIKE BKPF-BKTXT,  " txt
       XBLNR LIKE BKPF-XBLNR,  " ref
       USNAM LIKE BKPF-USNAM,  " user name
      END OF T_BKPF.

DATA: BEGIN OF T_BSEG OCCURS 0,
       BUKRS LIKE BSEG-BUKRS,  "CoCode
       BELNR LIKE BSEG-BELNR,  "FI Doc
       GJAHR LIKE BSEG-GJAHR,  "Fiscal Year
       BUZEI LIKE BSEG-BUZEI,  "Item
       SHKZG LIKE BSEG-SHKZG,  "Credit or Debit
       PSWSL LIKE BSEG-PSWSL,  "Cur
       DMBTR like BSEG-DMBTR,  "Local Amount
       PSWBT LIKE BSEG-PSWBT,  "Amount
       SAKNR LIKE BSEG-SAKNR,  "G/L Account Number
       HKONT LIKE BSEG-HKONT,  "General Ledger Account
       LIFNR LIKE BSEG-LIFNR,  "Account Number of Vendor or Creditor
       BSCHL LIKE BSEG-BSCHL,  "Posting Key

       BLART LIKE BKPF-BLART,  "Doc Type
       BLDAT LIKE BKPF-BLDAT,  "Doc Date
       BUDAT LIKE BKPF-BUDAT,  "Posting Date
       TCODE LIKE BKPF-TCODE,  "Transaction Code
       AWKEY LIKE BKPF-AWKEY,  "Reference Doc
       BSTAT LIKE BKPF-BSTAT,  "Document status
       TXT20 LIKE SKAT-TXT20,  "G/L Acccount Name
       NAME1 LIKE LFA1-NAME1,  "Vendor Name
       PSWBT1 LIKE BSEG-PSWBT,  "Amount
       PSWBT2 LIKE BSEG-PSWBT,  "Amount
       BKTXT LIKE BKPF-BKTXT,  " txt
       XBLNR LIKE BKPF-XBLNR,  " ref
       USNAM LIKE BKPF-USNAM,  " user name
      END OF T_BSEG.

DATA: BEGIN OF T_LFA1 OCCURS 0,
      LIFNR LIKE LFA1-LIFNR,
      NAME1 LIKE LFA1-NAME1,
     END OF T_LFA1.
DATA: BEGIN OF T_SKAT OCCURS 0,
      SAKNR LIKE SKAT-SAKNR,
      TXT20 LIKE SKAT-TXT20,
      END OF T_SKAT.
DATA W_LEN TYPE I.
*--------------------------------
* Selection Screen
*--------------------------------
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:
  S_BUKRS FOR BKPF-BUKRS Default 5000,    "CoCode
  S_BELNR FOR BKPF-BELNR,                 "FI Doc
  S_GJAHR FOR BKPF-GJAHR Default 2008,    "Fiscal Year
  S_BLART FOR BKPF-BLART,                 "Doc Type
  S_BLDAT FOR BKPF-BLDAT,                 "Doc Date
  S_BUDAT FOR BKPF-BUDAT,                 "Posting Date
  S_USNAM FOR BKPF-USNAM.
SELECTION-SCREEN END OF BLOCK b1.

*--------------------------------
* Initialization
*--------------------------------
INITIALIZATION.

*--------------------------------
* At Selection Screen PBO
*--------------------------------
AT SELECTION-SCREEN OUTPUT.

*--------------------------------
* Start of Selection
*--------------------------------
START-OF-SELECTION.
  PERFORM GET_BKPF.
  PERFORM CHECK_BKPF.
  PERFORM GET_BSEG.
  PERFORM Process_BSEG.
  PERFORM Events_build.
  PERFORM Layout_build.
  PERFORM Fields_bulid.
  PERFORM Display_data.

END-OF-SELECTION.
*--------------------------------
* Top of Page
*--------------------------------
TOP-OF-PAGE.

*--------------------------------
* At User Command
*--------------------------------
AT USER-COMMAND.
*--------------------------------
* At Line Selection
*--------------------------------
AT LINE-SELECTION.

*&---------------------------------*
*&      Form  display_data
*&---------------------------------*
FORM display_data.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
     i_callback_user_command           = 'USER_COMMAND'           "用户触发事件
*    i_callback_pf_status_set          = 'PF_STATUS_SET'(001)     "调用用户事件和按钮事件
     i_callback_program                = w_repid                  "当前程序
     is_layout                         = i_layout                 "子函数layout_build填充的格式定义
     it_fieldcat                       = i_fieldcat_alv[]         "子函数fields填充的各列
     it_events                         = i_events[]
     i_save                            = 'A'                      "保存变式
    TABLES
      t_outtab                          = T_BSEG.

ENDFORM.                    "display_data
*---------------------------------*
*       FORM user_command                                             *
*---------------------------------*
FORM USER_COMMAND  USING i_ucomm LIKE sy-ucomm
                           selfield TYPE slis_selfield.
  CASE i_ucomm.
    WHEN '&IC1'.
      CASE selfield-sel_tab_field.
        WHEN '1-BELNR'.
          SET PARAMETER ID 'BLN' FIELD selfield-value.
          SET PARAMETER ID 'BUK' FIELD T_BSEG-BUKRS.
          SET PARAMETER ID 'GJR' FIELD T_BSEG-GJAHR.
          CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
      ENDCASE.
    WHEN OTHERS.
  ENDCASE.

ENDFORM.                    "callback_ucomm

*&---------------------------------*
*&      Form  GET_BKPF
*&---------------------------------*
*       text
*----------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------*
FORM GET_BKPF .
*Get Data From BKPF
  SELECT BUKRS BELNR GJAHR BLART BLDAT BUDAT TCODE AWKEY BSTAT BKTXT XBLNR USNAM
  INTO TABLE T_BKPF
  FROM BKPF
  WHERE BUKRS IN S_BUKRS AND BELNR IN S_BELNR AND BLDAT IN S_BLDAT
        and GJAHR in S_GJAHR and BLART in S_BLART AND BUDAT IN S_BUDAT AND USNAM IN S_USNAM .
ENDFORM.                    " GET_BKPF
*&---------------------------------*
*&      Form  CHECK_BKPF
*&---------------------------------*
*       text
*----------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------*
FORM CHECK_BKPF .
  IF T_BKPF[] IS INITIAL.
    MESSAGE I000(ZMsg) with '没找到对应的数据,请更改查询条件'.
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " CHECK_BKPF
*&---------------------------------*
*&      Form  GET_BSEG
*&---------------------------------*
FORM GET_BSEG.
*Get Data From BSEG
  SELECT BUKRS BELNR GJAHR BUZEI SHKZG PSWSL DMBTR PSWBT SAKNR HKONT LIFNR BSCHL
  INTO CORRESPONDING FIELDS OF TABLE T_BSEG
  FROM BSEG
  FOR ALL ENTRIES IN T_BKPF
  WHERE BUKRS = T_BKPF-BUKRS AND BELNR = T_BKPF-BELNR AND GJAHR = T_BKPF-GJAHR.
*Get G/L Account name from skat
  SELECT SAKNR TXT20
  INTO TABLE T_SKAT
  FROM SKAT
  WHERE SPRAS = SY-LANGU AND KTOPL = 'INT'.
*Get  Vendor Info from LFA1
  SELECT LIFNR NAME1
  INTO TABLE T_LFA1
  FROM LFA1
  FOR ALL ENTRIES IN T_BSEG
  WHERE LIFNR = T_BSEG-LIFNR.
ENDFORM.                    "GET_BSEG
*&---------------------------------*
*&      Form  events_build
*&---------------------------------*
FORM events_build.

  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type = 0
    IMPORTING
      et_events   = i_events.

*  READ TABLE i_events  WITH KEY name = 'TOP_OF_PAGE'  INTO w_events.
*  IF sy-subrc = 0.
*    MOVE 'ALV_TOP_OF_PAGE' TO w_events-form.
*    MODIFY i_events FROM w_events INDEX sy-tabix.
*  ENDIF.
*
*  READ TABLE i_events  WITH KEY name = 'END_OF_LIST'  INTO w_events.
*  IF sy-subrc = 0.
*    MOVE 'ALV_END_OF_LIST' TO w_events-form.
*    MODIFY i_events FROM w_events INDEX sy-tabix.
*  ENDIF.

  READ TABLE i_events WITH KEY name = 'USER_COMMAND'   INTO w_events.
  IF sy-subrc = 0.
    MOVE 'USER_COMMAND' TO w_events-form.
    MODIFY i_events FROM w_events INDEX sy-tabix.
  ENDIF.

ENDFORM.                    "events_build

*&---------------------------------*
*&      Form  layout_build
*&---------------------------------*
FORM layout_build.
*  i_layout-detail_popup        = 'X'.    "弹出详细信息窗口
*  i-layout-no_vline            = 'X'.    "设置列间隔线
  i_layout-info_fieldname       = 'COLOR'.  "颜色值
  i_layout-colwidth_optimize    = 'X'.    "优化列宽选项
  i_layout-detail_initial_lines = 'X'.
  i_layout-detail_titlebar      = '凭证查询报表'.
  i_layout-no_colhead           =' '.
  w_repid = sy-repid.

ENDFORM.                    "layout_build


*&---------------------------------*
*&      Form  Fields_Bulid
*&---------------------------------*
*       text
*----------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------*
FORM fields_bulid .
  DATA tmp_pos TYPE i.
  REFRESH i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'BLART'.
  i_fieldcat-seltext_l = '凭证类型'.
  i_fieldcat-key = 'X'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'BUKRS'.
  i_fieldcat-seltext_l = '公司代码'.
  i_fieldcat-outputlen  = '15'.
  i_fieldcat-no_zero = 'X'.
  i_fieldcat-key = 'X'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'BELNR'.
  i_fieldcat-seltext_l = '会计凭证号'.
  i_fieldcat-outputlen  = '10'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'BLDAT'.
  i_fieldcat-seltext_l = '凭证日期'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'BUDAT'.
  i_fieldcat-seltext_l = '过账日期'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'GJAHR'.
  i_fieldcat-seltext_l = '年度'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'BUZEI'.
  i_fieldcat-seltext_l = '项目'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.


  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'BSCHL'.
  i_fieldcat-seltext_l = 'PK'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'SHKZG'.
  i_fieldcat-seltext_l = '借方/贷方'.
  i_fieldcat-no_out = 'X'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'HKONT'.
  i_fieldcat-seltext_l = '科目'.
  i_fieldcat-No_Zero = 'X'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'SAKNR'.
  i_fieldcat-seltext_l = '总帐科目'.
  i_fieldcat-No_Zero = 'X'.
  i_fieldcat-no_out = 'X'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'TXT20'.
  i_fieldcat-seltext_l = '科目名'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'LIFNR'.
  i_fieldcat-seltext_l = 'Vendor'.
  i_fieldcat-no_out = 'X'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'NAME1'.
  i_fieldcat-seltext_l = '厂商名'.
  i_fieldcat-no_out = 'X'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'PSWSL'.
  i_fieldcat-seltext_l = '币别'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'PSWBT'.
  i_fieldcat-seltext_l = '金额'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'DMBTR'.
  i_fieldcat-seltext_l = '本币金额'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'AWKEY'.
  i_fieldcat-seltext_l = '原始凭证'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'TCODE'.
  i_fieldcat-seltext_l = '原始凭证交易码'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'BSTAT'.
  i_fieldcat-seltext_l = '凭证状态'.
  i_fieldcat-no_Out = 'X'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'PSWBT1'.
  i_fieldcat-seltext_l = '借方发生额'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'PSWBT2'.
  i_fieldcat-seltext_l = '贷方发生额'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'BKTXT'.
  i_fieldcat-seltext_l = '文本'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'XBLNR'.
  i_fieldcat-seltext_l = '参照'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.

  tmp_pos = tmp_pos + 1.
  i_fieldcat-col_pos = tmp_pos.
  i_fieldcat-fieldname = 'USNAM'.
  i_fieldcat-seltext_l = '用户名'.
  APPEND i_fieldcat TO i_fieldcat_alv.
  CLEAR i_fieldcat.


ENDFORM.                    " Fields_Bulid
*&---------------------------------*
*&      Form  Process_BSEG
*&---------------------------------*
*       text
*----------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------*
FORM process_BSEG .
  DATA l_loop LIKE sy-tabix.
  DATA L_LEN TYPE I.
  SORT T_BSEG BY BUKRS GJAHR BELNR.
  SORT T_BKPF BY BUKRS GJAHR BELNR.
  LOOP AT T_BSEG.
    L_LOOP = SY-TABIX.
    IF T_BSEG-SHKZG = 'H'.
      T_BSEG-DMBTR = T_BSEG-DMBTR * ( -1 ).
      T_BSEG-PSWBT = T_BSEG-PSWBT * ( -1 ).
      T_BSEG-PSWBT2 = T_BSEG-PSWBT * ( -1 ).
    ENDIF.
    IF T_BSEG-SHKZG = 'S'.
      T_BSEG-PSWBT1 = T_BSEG-PSWBT .
    ENDIF.
* Get G/L Account Name
    READ TABLE T_SKAT WITH KEY SAKNR = T_BSEG-HKONT BINARY SEARCH.
    IF SY-SUBRC = 0.
      T_BSEG-TXT20 = T_SKAT-TXT20.
    ENDIF.
* Get Vendor Name
    IF T_BSEG-SAKNR <> '' AND T_BSEG-LIFNR <> ''.
      T_BSEG-HKONT = T_BSEG-LIFNR.
      READ TABLE T_LFA1 WITH KEY LIFNR = T_BSEG-LIFNR BINARY SEARCH.
      IF SY-SUBRC = 0.
        T_BSEG-NAME1 = T_LFA1-NAME1.
        T_BSEG-TXT20 = T_LFA1-NAME1.
      ENDIF.
    ENDIF.
*Move Doc Header to Item
    READ TABLE T_BKPF WITH KEY BUKRS = T_BSEG-BUKRS GJAHR = T_BSEG-GJAHR
                               BELNR = T_BSEG-BELNR BINARY SEARCH.
    IF SY-SUBRC = 0.
      T_BSEG-BLART = T_BKPF-BLART .
      T_BSEG-BLDAT = T_BKPF-BLDAT .
      T_BSEG-BUDAT = T_BKPF-BUDAT .
      T_BSEG-TCODE = T_BKPF-TCODE .
      T_BSEG-AWKEY = T_BKPF-AWKEY .
      T_BSEG-BKTXT = T_BKPF-BKTXT .
      T_BSEG-XBLNR = T_BKPF-XBLNR .
      T_BSEG-USNAM = T_BKPF-USNAM .
    ENDIF.
    IF T_BSEG-AWKEY <>' '.
      W_LEN = STRLEN( T_BSEG-AWKEY ) .
      IF W_LEN = 10 OR W_LEN = 14 OR W_LEN = 18.
        T_BSEG-AWKEY = T_BSEG-AWKEY(10).
      ENDIF.
    ENDIF.

    MODIFY T_BSEG.
    SY-TABIX = L_LOOP.
  ENDLOOP.
ENDFORM.                    " Process_BSEG

  相关解决方案