模拟会计凭证审批 OO ALV(屏幕跳转、定位行数据、审批按钮)

根据选定的单、多行会计凭证进行审批,双击单个会计凭证跳转会计订单明细。将审批的凭证记录在一张自定义表中

  1 *&---------------------------------------------------------------------*
  2 *& Report  ZFI_SP
  3 *&---------------------------------------------------------------------*
  4 *&参考FB03
  5 *&---------------------------------------------------------------------*
  6 REPORT  zfi_sp.
  7 TYPE-POOLS:slis,icon.
  8 TABLES:t001,bkpf,skat.
  9 DATA: ok_code LIKE sy-ucomm,
 10      save_ok LIKE ok_code.
 11 INCLUDE zfi_sp_alldata.   "会计编号的详细会计科目的数据类型
 12 
 13 DATA gt_fieldcat TYPE slis_t_fieldcat_alv.
 14 DATA gs_fieldcat TYPE slis_fieldcat_alv.  "表字段
 15 DATA gs_layout TYPE slis_layout_alv.  "布局
 16 DATA gt_events TYPE slis_t_event.
 17 DATA gs_event TYPE slis_alv_event.  "事件
 18 TYPES:BEGIN OF ty_type,
 19    sel TYPE c,          "选择按钮列
 20    bukrs TYPE bukrs,
 21    belnr TYPE belnr_d,  "会计凭证编号
 22    gjahr TYPE gjahr,
 23    blart TYPE blart,    "类型`
 24    bldat TYPE    bldat,    "凭证中的凭证日期
 25    budat TYPE budat,   "凭证中的过帐日期
 26    bktxt TYPE bktxt,    "文本
 27    sp TYPE c,
 28  END OF ty_type.
 29 DATA:gt_itab TYPE TABLE OF ty_type WITH HEADER LINE.
 30 DATA:wa_insert TYPE zfi_sp_table,
 31       wa_itab TYPE ty_type.
 32 
 33 DATA:fi_itab TYPE TABLE OF zfi_sp_table WITH HEADER LINE.
 34 
 35 DATA:fieldcat TYPE lvc_t_fcat,    "1001 屏幕数据定义
 36       grid TYPE REF TO cl_gui_alv_grid,
 37       g_container TYPE scrfname VALUE 'CONT1',
 38       g_custom_container TYPE REF TO cl_gui_custom_container.
 39 DATA: gt_fieldcat02 TYPE lvc_t_fcat,
 40       gs_variant02   TYPE disvariant,
 41       gs_layout02   TYPE lvc_s_layo.
 42 
 43 SELECTION-SCREEN BEGIN OF BLOCK blk_001 WITH FRAME TITLE blk_001 .
 44 SELECT-OPTIONS:t_bukrs FOR t001-bukrs OBLIGATORY.
 45 PARAMETERS:b_gjahr LIKE bkpf-gjahr DEFAULT sy-datum(4) OBLIGATORY.
 46 SELECT-OPTIONS:b_belnr FOR bkpf-belnr ,
 47 b_bldat FOR bkpf-bldat,
 48 b_budat FOR bkpf-budat,
 49 b_blart FOR bkpf-blart,
 50 s_txt50 FOR skat-txt50,
 51 b_usnam FOR bkpf-usnam.
 52 PARAMETERS:a_check AS CHECKBOX.
 53 **PARAMETERS:b_check AS CHECKBOX DEFAULT 'X'.
 54 SELECTION-SCREEN END OF BLOCK blk_001.
 55 
 56 AT SELECTION-SCREEN.
 57   "新增公司权限对象检查
 58   PERFORM frm_authority_check.
 59 
 60 START-OF-SELECTION.
 61   IF a_check = ''.
 62     IF b_blart = ''.
 63       SELECT bkpf~bukrs        "公司代码
 64        bkpf~belnr        "凭证编号
 65        bkpf~gjahr        "年度
 66        bkpf~blart        "凭证类型
 67        bkpf~budat        "过帐日期
 68        bkpf~bldat        "凭证日期
 69        bkpf~bktxt       "抬头文本
 70        z~sp              "审批标识
 71   INTO CORRESPONDING FIELDS OF TABLE gt_itab
 72   FROM  bkpf
 73   LEFT JOIN zfi_sp_table AS z ON z~belnr = bkpf~belnr AND z~belnr = bkpf~belnr AND z~bukrs = bkpf~bukrs
 74     WHERE bkpf~bukrs IN t_bukrs        "公司代码
 75      AND  bkpf~belnr IN b_belnr        "凭证编号
 76      AND  bkpf~gjahr = b_gjahr         "会计年度
 77      AND  bkpf~bldat IN b_bldat        "凭证日期
 78      AND  bkpf~budat IN b_budat        "过帐日期
 79      AND  bkpf~blart IN ('SA','AB','AA','RV','DZ','RE','KZ') "凭证类型
 80      AND  bkpf~usnam IN b_usnam.        "制作人
 81     ELSE.
 82       SELECT bkpf~bukrs        "公司代码
 83           bkpf~belnr        "凭证编号
 84           bkpf~gjahr        "年度
 85           bkpf~blart        "凭证类型
 86           bkpf~budat        "过帐日期
 87           bkpf~bldat        "凭证日期
 88           bkpf~bktxt       "抬头文本
 89           z~sp              "审批标识
 90       INTO CORRESPONDING FIELDS OF TABLE gt_itab
 91           FROM  bkpf
 92           LEFT JOIN zfi_sp_table AS z ON z~belnr = bkpf~belnr AND z~belnr = bkpf~belnr AND z~bukrs = bkpf~bukrs
 93           WHERE bkpf~bukrs IN t_bukrs        "公司代码
 94           AND  bkpf~belnr IN b_belnr        "凭证编号
 95           AND  bkpf~gjahr = b_gjahr         "会计年度
 96           AND  bkpf~bldat IN b_bldat        "凭证日期
 97           AND  bkpf~budat IN b_budat        "过帐日期
 98           AND  bkpf~blart IN b_blart        "凭证类型
 99           AND  bkpf~usnam IN b_usnam.        "制作人
100     ENDIF.
101 
102     DELETE gt_itab WHERE sp = 'X'.
103     PERFORM all_data.
104     PERFORM set_event.
105   ELSE.
106     SELECT * FROM zfi_sp_table INTO CORRESPONDING FIELDS OF TABLE fi_itab
107        WHERE bukrs IN t_bukrs        "公司代码
108          AND  belnr IN b_belnr        "凭证编号
109          AND  gjahr = b_gjahr         "会计年度
110          AND  zerdt IN b_bldat        "凭证日期
111          AND  blart IN b_blart        "凭证类型
112          AND  uname IN b_usnam.        "审核人
113   ENDIF.
114 
115   PERFORM set_layout.
116   PERFORM set_fieldname.
117   PERFORM result_alv.
118 *&---------------------------------------------------------------------*
119 *&      Form  alv_user_command
120 *&---------------------------------------------------------------------*
121 *  定义初始屏幕操作逻辑
122 *----------------------------------------------------------------------*
123 *      -->P_UCOMM    text
124 *      -->P_SELFIELD text
125 *----------------------------------------------------------------------*
126 FORM alv_user_command USING p_ucomm TYPE sy-ucomm p_selfield TYPE slis_selfield.
127   p_selfield-refresh = 'X'.     "控制grid产生新屏幕
128   CLEAR wa_insert.
129   CASE p_ucomm.
130     WHEN  '&IC1'.
131       READ TABLE gt_itab INDEX p_selfield-tabindex. "定位双击的行号
132       LOOP AT itab1 WHERE belnr = gt_itab-belnr.
133         APPEND itab1 TO itab2.
134       ENDLOOP.
135       IF itab2[] IS NOT INITIAL.
136         CALL SCREEN '1001'.
137       ENDIF.
138     WHEN 'SP'.                            "多个会计凭证一起审批
139       LOOP AT gt_itab WHERE sel = 'X'.
140         CLEAR wa_insert.
141         MOVE-CORRESPONDING gt_itab TO wa_insert.
142         wa_insert-zerdt = sy-datum.
143         wa_insert-uzeit = sy-uzeit.
144         wa_insert-uname = sy-uname.
145         wa_insert-sp = 'X'.
146         INSERT zfi_sp_table FROM wa_insert.
147         DELETE gt_itab.
148       ENDLOOP.
149       p_selfield-refresh = 'X'.   "审批完成刷新
150   ENDCASE.
151 ENDFORM.                    "MALV_USER_COMMAND
152 *&---------------------------------------------------------------------*
153 *&      Form  alvshow
154 *&---------------------------------------------------------------------*
155 *  显示双击选中会计编号的详细会计科目
156 *  CL_GUI_ALV_GRID->set_table_for_first_display
157 *----------------------------------------------------------------------*
158 FORM alvshow.
159   gs_layout02-no_rowmark = 'X'. "禁用行选择
160   gs_layout02-cwidth_opt = 'X'. "优化列宽度
161   gs_layout02-no_toolbar = 'X'. "隐藏工具栏
162 
163   gs_variant02-report = sy-repid.
164 
165   CREATE OBJECT g_custom_container
166     EXPORTING
167       container_name = g_container. "创建容器
168 
169   CREATE OBJECT grid
170     EXPORTING
171       i_parent = g_custom_container."创建ALV对象
172 
173   PERFORM f_grid_build_fieldcat  CHANGING gt_fieldcat02.
174   SORT itab2 BY hkont DESCENDING.
175 
176   CALL METHOD grid->set_table_for_first_display
177     EXPORTING
178       is_layout       = gs_layout02
179       is_variant      = gs_variant02
180     CHANGING
181       it_outtab       = itab2[]
182       it_fieldcatalog = gt_fieldcat02.
183   CLEAR:gt_fieldcat02,gs_layout02,gs_variant02.
184 ENDFORM.                    "alvshow
185 *&---------------------------------------------------------------------*
186 *&      Form  f_grid_build_fieldcat
187 *&---------------------------------------------------------------------*
188 *
189 *----------------------------------------------------------------------*
190 *      -->PT_FIELDCAT  text
191 *----------------------------------------------------------------------*
192 FORM f_grid_build_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.
193   DATA ls_fcat TYPE lvc_s_fcat.
194 
195   CLEAR ls_fcat.
196   ls_fcat-fieldname = 'BUKRS'.
197   ls_fcat-coltext =
198   ls_fcat-tooltip =
199   ls_fcat-seltext = '公司'.
200   ls_fcat-outputlen = 4.
201   APPEND ls_fcat TO pt_fieldcat.
202 
203   CLEAR ls_fcat.
204   ls_fcat-fieldname = 'BELNR'.
205   ls_fcat-coltext =
206 ls_fcat-tooltip =
207 ls_fcat-seltext = '凭证'.
208   ls_fcat-outputlen = 10.
209   APPEND ls_fcat TO pt_fieldcat.
210 
211   CLEAR ls_fcat.
212   ls_fcat-fieldname = 'HKONT'.
213   ls_fcat-coltext =
214   ls_fcat-tooltip =
215   ls_fcat-seltext = '科目'.
216   ls_fcat-outputlen = 10.
217   APPEND ls_fcat TO pt_fieldcat.
218 
219   CLEAR ls_fcat.
220   ls_fcat-fieldname = 'SHKZG'.
221   ls_fcat-coltext =
222 ls_fcat-tooltip =
223 ls_fcat-seltext = '借方/贷方标识'.
224   ls_fcat-outputlen = 1.
225   APPEND ls_fcat TO pt_fieldcat.
226 
227   CLEAR ls_fcat.
228   ls_fcat-fieldname = 'BUZEI'.
229   ls_fcat-coltext =
230 ls_fcat-tooltip =
231 ls_fcat-seltext = '会计凭证中的行项目数'.
232   ls_fcat-outputlen = 3.
233   APPEND ls_fcat TO pt_fieldcat.
234 
235   CLEAR ls_fcat.
236   ls_fcat-fieldname = 'DMBTR'.
237   ls_fcat-coltext =
238 ls_fcat-tooltip =
239 ls_fcat-seltext = '按本位币计的金额本'.
240   ls_fcat-outputlen = 13.
241   APPEND ls_fcat TO pt_fieldcat.
242 
243   CLEAR ls_fcat.
244   ls_fcat-fieldname = 'WRBTR'.
245   ls_fcat-coltext =
246 ls_fcat-tooltip =
247 ls_fcat-seltext = '凭证货币金额'.
248   ls_fcat-outputlen = 13.
249   APPEND ls_fcat TO pt_fieldcat.
250 
251   CLEAR ls_fcat.
252   ls_fcat-fieldname = 'SGTXT'.
253   ls_fcat-coltext =
254 ls_fcat-tooltip =
255 ls_fcat-seltext = '摘要'.
256   ls_fcat-outputlen = 50.
257   APPEND ls_fcat TO pt_fieldcat.
258 
259   CLEAR ls_fcat.
260   ls_fcat-fieldname = 'KUNNR'.
261   ls_fcat-coltext =
262 ls_fcat-tooltip =
263 ls_fcat-seltext = '客户编号'.
264   ls_fcat-outputlen = 10.
265   APPEND ls_fcat TO pt_fieldcat.
266 
267   CLEAR ls_fcat.
268   ls_fcat-fieldname = 'LIFNR'.
269   ls_fcat-coltext =
270   ls_fcat-tooltip =
271   ls_fcat-seltext = '供应商或债权人的帐号'.
272   ls_fcat-outputlen = 8.
273   APPEND ls_fcat TO pt_fieldcat.
274 
275   CLEAR ls_fcat.
276   ls_fcat-fieldname = 'TXT50'.
277   ls_fcat-coltext =
278   ls_fcat-tooltip =
279   ls_fcat-seltext = '科目名称'.
280   ls_fcat-outputlen = 50.
281   APPEND ls_fcat TO pt_fieldcat.
282 
283   CLEAR ls_fcat.
284   ls_fcat-fieldname = 'KOSTL'.
285   ls_fcat-coltext =
286   ls_fcat-tooltip =
287   ls_fcat-seltext = '成本中心'.
288   ls_fcat-outputlen = 10.
289   APPEND ls_fcat TO pt_fieldcat.
290 
291   CLEAR ls_fcat.
292   ls_fcat-fieldname = 'FKBER_LONG'.
293   ls_fcat-coltext =
294   ls_fcat-tooltip =
295   ls_fcat-seltext = '功能范围'.
296   ls_fcat-outputlen = 16.
297   APPEND ls_fcat TO pt_fieldcat.
298 
299   CLEAR ls_fcat.
300   ls_fcat-fieldname = 'KTEXT'.
301   ls_fcat-coltext =
302   ls_fcat-tooltip =
303   ls_fcat-seltext = '客户名称'.
304   ls_fcat-outputlen = 35.
305   APPEND ls_fcat TO pt_fieldcat.
306 
307   CLEAR ls_fcat.
308   ls_fcat-fieldname = 'NAME'.
309   ls_fcat-coltext =
310   ls_fcat-tooltip =
311   ls_fcat-seltext = '供应商名称'.
312   ls_fcat-outputlen = 35.
313   APPEND ls_fcat TO pt_fieldcat.
314 
315   CLEAR ls_fcat.
316   ls_fcat-fieldname = 'BLDAT'.
317   ls_fcat-coltext =
318   ls_fcat-tooltip =
319   ls_fcat-seltext = '凭证日期'.
320   ls_fcat-outputlen = 8.
321   APPEND ls_fcat TO pt_fieldcat.
322 
323   CLEAR ls_fcat.
324   ls_fcat-fieldname = 'BUDAT'.
325   ls_fcat-coltext =
326   ls_fcat-tooltip =
327   ls_fcat-seltext = '过账日期'.
328   ls_fcat-outputlen = 8.
329   APPEND ls_fcat TO pt_fieldcat.
330 
331   CLEAR ls_fcat.
332   ls_fcat-fieldname = 'BLART'.
333   ls_fcat-coltext =
334   ls_fcat-tooltip =
335   ls_fcat-seltext = '类型'.
336   ls_fcat-outputlen = 2.
337   APPEND ls_fcat TO pt_fieldcat.
338 
339   CLEAR ls_fcat.
340   ls_fcat-fieldname = 'HWAER'.
341   ls_fcat-coltext =
342   ls_fcat-tooltip =
343   ls_fcat-seltext = '本币'.
344   ls_fcat-outputlen = 5.
345   APPEND ls_fcat TO pt_fieldcat.
346 ENDFORM.                    "F_GRID_BUILD_FIELDCAT
347 *&---------------------------------------------------------------------*
348 *&      Form  alv_status_set
349 *&---------------------------------------------------------------------*
350 *       text
351 *----------------------------------------------------------------------*
352 *      -->PT_EXTAB   text
353 *----------------------------------------------------------------------*
354 FORM alv_status_set USING pt_extab TYPE slis_t_extab.
355   SET PF-STATUS 'COPY_GUI'." OF PROGRAM 'SAPLKKBL'.
356 ENDFORM.                    "ALV_STATUS_SET
357 *&---------------------------------------------------------------------*
358 *&      Form  set_layout
359 *&---------------------------------------------------------------------*
360 *       text
361 *----------------------------------------------------------------------*
362 FORM set_layout .
363   gs_layout-zebra = 'X'.
364   gs_layout-colwidth_optimize = 'X'.
365   gs_layout-cell_merge = 'X'.         "内容能够复制到剪贴板
366   IF a_check <> 'X'.  "显示已审批数据不用指定 不然点击按钮会报错
367     gs_layout-box_fieldname = 'SEL'.    "指定这个字段为【选择块】
368   ENDIF.
369 
370 ENDFORM.                    " SET_LAYOUT
371 *&---------------------------------------------------------------------*
372 *&      Form  set_fieldname
373 *&---------------------------------------------------------------------*
374 *       text
375 *----------------------------------------------------------------------*
376 FORM set_fieldname.
377   DEFINE setfieldcat.
378     clear: gs_fieldcat.
379     gs_fieldcat-col_pos = &1.
380     gs_fieldcat-fieldname = &2.
381     gs_fieldcat-seltext_m = &3.
382     gs_fieldcat-no_zero = 'X'.
383     append gs_fieldcat to gt_fieldcat.
384   END-OF-DEFINITION.
385 
386   setfieldcat 1 'BUKRS' '工厂'.
387   setfieldcat 2 'BELNR' '凭证编号'.
388   setfieldcat 3 'GJAHR' '年度'.
389   setfieldcat 4 'BLART' '类型'.
390   IF a_check = 'X'.
391     setfieldcat 5 'ZERDT' '审批日期'.
392     setfieldcat 6 'UZEIT' '审批时间'.
393     setfieldcat 7 'UNAME' '审批人'.
394     setfieldcat 8 'SP' '审批完成标识'.
395   ELSE.
396     setfieldcat 5 'BLDAT' '凭证日期'.
397     setfieldcat 6 'BUDAT' '过帐日期'.
398     setfieldcat 7 'BKTXT' '抬头文本'.
399 *  setfieldcat 8 'SP'    '审批标识'.
400   ENDIF.
401 ENDFORM.                    "set_fieldname
402 *&---------------------------------------------------------------------*
403 *&      Form  result_alv
404 *&---------------------------------------------------------------------*
405 *       text
406 *----------------------------------------------------------------------*
407 FORM result_alv .
408   IF a_check = ''.
409     CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
410       EXPORTING
411         i_callback_program      = sy-repid
412         is_layout               = gs_layout
413         it_fieldcat             = gt_fieldcat
414         it_events               = gt_events
415         i_callback_user_command = 'ALV_USER_COMMAND'  "按钮功能(这个功能也能在is_layout中定义)
416       TABLES
417         t_outtab                = gt_itab
418       EXCEPTIONS
419         program_error           = 1
420         OTHERS                  = 2.
421   ELSE.
422     CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
423       EXPORTING
424         i_callback_program = sy-repid
425         is_layout          = gs_layout
426         it_fieldcat        = gt_fieldcat
427       TABLES
428         t_outtab           = fi_itab
429       EXCEPTIONS
430         program_error      = 1
431         OTHERS             = 2.
432   ENDIF.
433   CLEAR a_check.
434 ENDFORM.                    " RESULT_ALV
435 
436 *&---------------------------------------------------------------------*
437 *&      Form  set_event
438 *&---------------------------------------------------------------------*
439 *       text
440 *----------------------------------------------------------------------*
441 FORM set_event .
442   CLEAR gs_event.
443   MOVE 'PF_STATUS_SET' TO gs_event-name."调用PF_STATUS_SET签名的Form,ALV工具栏显示前,可自定义工具条
444   MOVE 'ALV_STATUS_SET' TO gs_event-form. "工具栏设置
445   APPEND gs_event TO gt_events.
446 ENDFORM.                    " SET_EVENT
447 *&---------------------------------------------------------------------*
448 *&      Form  all_data
449 *&---------------------------------------------------------------------*
450 *       text
451 *----------------------------------------------------------------------*
452 FORM all_data.
453   SELECT SINGLE * FROM t001 WHERE bukrs = t_bukrs.
454   comtitle = t001-butxt.
455 
456   SELECT bukrs        "公司代码
457          belnr        "凭证编号
458          blart        "凭证类型
459          usnam        "用户名
460          ppnam        "凭证制作人
461          budat        "过帐日期
462          bldat        "凭证日期
463          waers
464          hwaer        "本位币
465          kursf        "汇率
466     INTO CORRESPONDING FIELDS OF  TABLE itab_bkpf
467     FROM  bkpf
468     WHERE bukrs IN t_bukrs        "公司代码
469      AND  belnr IN b_belnr        "凭证编号
470      AND  gjahr = b_gjahr         "会计年度
471      AND  bldat IN b_bldat        "凭证日期
472      AND  budat IN b_budat        "过帐日期
473      AND  blart IN b_blart        "凭证类型
474      AND  usnam IN b_usnam.       "制作人
475 
476   SORT itab_bkpf BY belnr ASCENDING .
477 
478   IF  sy-subrc <> 0.
479     MESSAGE '输入的凭证编号不存在!' TYPE 'E'.
480   ENDIF.
481 
482   LOOP AT itab_bkpf.
483     SELECT belnr        "凭证编号
484            hkont         "总分类帐帐目
485            shkzg         "借方/贷方标识
486            dmbtr         "按本位币计的金额
487            wrbtr         "凭证货币金额
488            sgtxt         "项目文本
489            kunnr         "客户编号1
490            lifnr         "供应商或债权人的帐号
491            zuonr         "分配编号
492            buzei         "会计凭证中的行项目数
493            kostl         "成本中心
494            fkber_long    "功能范围
495       APPENDING CORRESPONDING FIELDS OF  TABLE itab_bseg
496       FROM bseg
497       WHERE belnr = itab_bkpf-belnr AND gjahr = b_gjahr
498       AND bukrs IN t_bukrs .
499     "修改日元问题  by  hua.su.
500     IF  itab_bkpf-waers = 'JPY' .
501       LOOP AT itab_bseg WHERE belnr = itab_bkpf-belnr. 
502         itab_bseg-wrbtr = itab_bseg-wrbtr * 100.
503         MODIFY itab_bseg.
504         CLEAR itab_bseg.
505       ENDLOOP.
506     ENDIF.
507 
508     SELECT SINGLE butxt INTO itab_bkpf-butxt
509      FROM t001
510       WHERE bukrs = itab_bkpf-bukrs.
511 
512     SELECT SINGLE ltext
513     FROM t003t
514     INTO itab_bkpf-ltext
515     WHERE blart = itab_bkpf-blart AND t003t~spras = '1'.
516 
517     IF itab_bkpf-blart = 'KR' OR itab_bkpf-blart = 'KZ' OR
518 itab_bkpf-blart = 'DR' OR
519        itab_bkpf-blart = 'DZ' OR itab_bkpf-blart = 'SA'.
520 
521       SELECT SINGLE xblnr INTO itab_bkpf-xblnr   "参考凭证号
522         FROM bkpf
523         WHERE belnr = itab_bkpf-belnr.
524     ENDIF.
525 
526     SELECT SINGLE name_last name_first
527            INTO (itab_bkpf-name_last,itab_bkpf-name_first)
528       FROM user_addr
529       WHERE bname = itab_bkpf-usnam.
530     CONCATENATE itab_bkpf-name_last itab_bkpf-name_first INTO
531 itab_bkpf-name_last.
532 
533     SELECT SINGLE bseg~kunnr
534            INTO   itab_bkpf-kunnr
535            FROM bseg
536            WHERE bseg~belnr = itab_bkpf-belnr AND  kunnr <> ''.
537 
538     IF itab_bkpf-blart = 'RV'.
539       SELECT SINGLE kna1~name1
540           INTO itab_bkpf-sgtxt
541           FROM kna1
542           WHERE kunnr = itab_bkpf-kunnr.
543       CONCATENATE '销售-' itab_bkpf-sgtxt INTO itab_bkpf-sgtxt.
544     ENDIF.
545 
546     MODIFY itab_bkpf INDEX sy-tabix.
547   ENDLOOP.
548 
549   IF NOT itab_bseg[] IS INITIAL.
550     DATA temp_sgtxt LIKE bseg-sgtxt.
551     SORT itab_bseg DESCENDING BY belnr lifnr.
552     LOOP AT itab_bseg.
553       SELECT  SINGLE txt50
554       FROM skat
555       INTO itab_bseg-txt50
556       WHERE skat~saknr = itab_bseg-hkont.
557       SELECT SINGLE cskt~ktext
558           INTO itab_bseg-ktext
559           FROM cskt
560           WHERE cskt~kostl = itab_bseg-kostl AND cskt~spras = '1'.
561 
562       IF itab_bseg-lifnr <> ''.
563         CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
564           EXPORTING
565             input  = itab_bseg-lifnr
566           IMPORTING
567             output = itab_bseg-lifnr.
568         CONCATENATE itab_bseg-txt50 '-' itab_bseg-lifnr  INTO itab_bseg-txt50.
569       ENDIF.
570 
571       IF itab_bseg-kunnr <> ''.
572         CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
573           EXPORTING
574             input  = itab_bseg-kunnr
575           IMPORTING
576             output = itab_bseg-kunnr.
577         CONCATENATE itab_bseg-txt50 '-' itab_bseg-kunnr  INTO itab_bseg-txt50.
578       ENDIF.
579       IF itab_bseg-fkber_long = '1000'.
580         CONCATENATE    itab_bseg-txt50 '-' itab_bseg-ktext
581 '-' itab_bseg-kostl '-' '制造费用' INTO itab_bseg-txt50.
582       ELSEIF itab_bseg-fkber_long = '2000' .
583         CONCATENATE   itab_bseg-txt50 '-' itab_bseg-ktext
584 '-' itab_bseg-kostl '-' '管理费用' INTO itab_bseg-txt50.
585       ELSEIF itab_bseg-fkber_long = '3000'.
586         CONCATENATE  itab_bseg-txt50 '-' itab_bseg-ktext
587 '-' itab_bseg-kostl '-' '销售费用' INTO itab_bseg-txt50.
588       ELSEIF itab_bseg-fkber_long = '4000'.
589         CONCATENATE  itab_bseg-txt50 '-' itab_bseg-ktext
590 '-' itab_bseg-kostl '-' '研发费用' INTO itab_bseg-txt50.
591       ELSEIF itab_bseg-fkber_long = '5000'.
592         CONCATENATE  itab_bseg-txt50 '-' itab_bseg-ktext
593 '-' itab_bseg-kostl '-' '材料附加费' INTO itab_bseg-txt50.
594       ENDIF.
595 
596       MODIFY itab_bseg INDEX sy-tabix.
597     ENDLOOP.
598   ENDIF.
599 
600 *************读取供应商或客户描述*************
601   IF NOT itab_bseg[] IS INITIAL."确定为已过帐的凭证
602     SELECT  saknr
603             txt50
604       INTO  TABLE itab_skat
605       FROM skat
606        FOR ALL ENTRIES IN itab_bseg
607      WHERE saknr = itab_bseg-hkont
608        AND spras = sy-langu
609        AND ktopl = t001-ktopl.
610 *      READ TABLE ITAB_SKAT.
611     SELECT  kunnr name1
612       INTO  TABLE  itab_kna1
613       FROM kna1
614        FOR ALL ENTRIES IN itab_bseg
615      WHERE kunnr = itab_bseg-kunnr.
616 
617     SELECT  lifnr name1
618       INTO  TABLE  itab_lfa1
619       FROM lfa1
620        FOR ALL ENTRIES IN itab_bseg
621      WHERE lifnr = itab_bseg-lifnr.
622   ENDIF.
623 
624   SORT itab_bseg BY shkzg DESCENDING buzei ASCENDING belnr ASCENDING .
625   LOOP AT itab_bseg.
626     COLLECT itab_bseg INTO itab.
627   ENDLOOP.
628 
629   SORT itab BY belnr.
630   LOOP AT itab.                                             "FBY 2015
631     READ TABLE itab_bkpf WITH KEY belnr = itab-belnr.
632     IF sy-subrc = 0.
633       itab1-bukrs = itab_bkpf-bukrs.
634       itab1-belnr = itab_bkpf-belnr."会计凭证编号
635       itab1-hkont = itab-hkont.  "科目编码
636       itab1-shkzg = itab-shkzg.  "借方/贷方标识
637       itab1-buzei = itab-buzei.
638       itab1-dmbtr = itab-dmbtr.  "按本位币计的金额
639       itab1-wrbtr = itab-wrbtr.  "凭证货币金额
640       itab1-sgtxt = itab-sgtxt. "摘要
641       itab1-kunnr = itab-kunnr.                             "客户编号1
642       itab1-lifnr = itab-lifnr. "供应商或债权人的帐号
643       itab1-txt50 = itab-txt50. "科目名称
644       itab1-kostl = itab-kostl.  "成本中心
645       itab1-fkber_long = itab-fkber_long.  "功能范围
646       itab1-ktext = itab-ktext.  "成本中心描述
647       itab1-name1 = itab-name1.  "客户名称
648       itab1-name =  itab-name. "供应商名称
649       itab1-bldat = itab_bkpf-bldat. "凭证日期      "fby
650       itab1-budat = itab_bkpf-budat. "过账日期
651       itab1-blart = itab_bkpf-blart. "类型
652       itab1-hwaer = itab_bkpf-hwaer. "本币
653       APPEND itab1.
654       CLEAR  itab1.
655     ENDIF.
656   ENDLOOP.
657 ENDFORM.                    "FRM_GET_DATA
658 *&---------------------------------------------------------------------*
659 *&      Form  frm_authority_check
660 *&---------------------------------------------------------------------*
661 *       text
662 *----------------------------------------------------------------------*
663 FORM frm_authority_check .
664   DATA: BEGIN OF lt_werks OCCURS 0 ,
665             werks LIKE t001w-werks,
666           END OF  lt_werks .
667 
668   SELECT werks
669     INTO CORRESPONDING FIELDS OF TABLE lt_werks
670     FROM t001w
671     WHERE werks IN t_bukrs.
672 
673   LOOP AT lt_werks .
674     AUTHORITY-CHECK OBJECT 'ZWERKS'  ID 'WERKS' FIELD  lt_werks-werks .
675     IF sy-subrc <> 0.
676       MESSAGE  e001(00) WITH '你没有 ' lt_werks-werks '公司的操作权限!'.
677     ENDIF.
678   ENDLOOP .
679 ENDFORM.                    "frm_authority_check
680 
681 INCLUDE zfi_sp_pbo .
682 INCLUDE zfi_sp_pai .
View Code

 

ZFI_SP_ALLDATA
*&---------------------------------------------------------------------*
*&  包括                ZFI_SP_ALLDATA
*&---------------------------------------------------------------------*
*--------------------------------------------------------------------------------------------------------------------------------*
DATA:comtitle     LIKE t001-butxt.
TYPES:BEGIN OF ty_itab1,
       bukrs LIKE bkpf-bukrs,
       belnr LIKE bseg-belnr, "会计凭证编号
       hkont LIKE bseg-hkont,  "科目编码
       shkzg LIKE bseg-shkzg,  "借方/贷方标识
       buzei LIKE bseg-buzei,
       dmbtr LIKE bseg-dmbtr,  "按本位币计的金额
       wrbtr LIKE bseg-wrbtr,  "凭证货币金额
       sgtxt LIKE bseg-sgtxt, "摘要
       kunnr LIKE bseg-kunnr,                               "客户编号1
       lifnr LIKE bseg-lifnr, "供应商或债权人的帐号
       txt50 LIKE skat-txt50,  "科目名称
       kostl LIKE bseg-kostl,  "成本中心
       fkber_long LIKE bseg-fkber_long,  "功能范围
       ktext LIKE cskt-ktext,  "成本中心描述
       name1 LIKE kna1-name1,  "客户名称
       name  LIKE lfa1-name1,  "供应商名称
       bldat LIKE bkpf-bldat, "凭证日期      "fby
       budat LIKE bkpf-budat, "过账日期
       blart LIKE bkpf-blart, "类型
       hwaer LIKE bkpf-hwaer, "本币
     END OF ty_itab1.
DATA:itab1 TYPE TABLE OF ty_itab1 WITH HEADER LINE,
     itab2 TYPE TABLE OF ty_itab1 WITH HEADER LINE.


DATA:BEGIN OF itab_bkpf OCCURS 0,
       bukrs LIKE bkpf-bukrs,
       butxt LIKE t001-butxt,
       belnr LIKE bseg-belnr,"会计凭证编号
       blart LIKE bkpf-blart,
       bktxt LIKE bkpf-bktxt,
       usnam LIKE bkpf-usnam,"过帐人
       ppnam LIKE bkpf-ppnam,"预制人
       budat LIKE bkpf-budat,
       bldat LIKE bkpf-bldat,
       xblnr LIKE bkpf-xblnr,"参照
       waers LIKE bkpf-waers,"币别码
       hwaer LIKE bkpf-hwaer,"本位币 by snowchen 10/05/25
       ltext  LIKE t003t-ltext, "凭证类型描述
       name_first  LIKE user_addr-name_first,        "
       name_last   LIKE user_addr-name_last,         "
       sgtxt LIKE bseg-sgtxt, "摘要
       kunnr LIKE bseg-kunnr, "客户代码
       kursf LIKE bkpf-kursf, "汇率
     END OF itab_bkpf.
DATA:BEGIN OF itab_bseg OCCURS 0,

  belnr LIKE bseg-belnr, "会计凭证编号
  hkont LIKE bseg-hkont,  "科目编码
  shkzg LIKE bseg-shkzg,  "借方/贷方标识
  buzei LIKE bseg-buzei,
  dmbtr LIKE bseg-dmbtr,  "按本位币计的金额
  wrbtr LIKE bseg-wrbtr,  "凭证货币金额
  sgtxt LIKE bseg-sgtxt, "摘要
  kunnr LIKE bseg-kunnr,                                    "客户编号1
  lifnr LIKE bseg-lifnr, "供应商或债权人的帐号
  txt50 LIKE skat-txt50,  "科目名称
  kostl LIKE bseg-kostl,  "成本中心
  fkber_long LIKE bseg-fkber_long,  "功能范围
  ktext LIKE cskt-ktext,  "成本中心描述
  name1 LIKE kna1-name1,  "客户名称
  name  LIKE lfa1-name1,  "供应商名称
END OF itab_bseg.
DATA: itab LIKE TABLE OF itab_bseg  WITH HEADER LINE.

DATA: BEGIN OF itab_skat OCCURS 10  ,
saknr LIKE skat-saknr,   "会计科目
txt50 LIKE skat-txt50,    "科目描述
END OF itab_skat.


DATA: BEGIN OF itab_kna1 OCCURS 0 ,
      kunnr LIKE kna1-kunnr,"客户编码
      name1 LIKE kna1-name1,"客户名称
END OF itab_kna1.

DATA: BEGIN OF itab_lfa1 OCCURS 0 ,
      lifnr LIKE lfa1-lifnr,"供应商编码
      name1 LIKE lfa1-name1,"供应商名称

END OF itab_lfa1.

DATA: BEGIN OF itab_sgtxt OCCURS 0 ,
      sgtxt LIKE bseg-sgtxt,
  END OF itab_sgtxt.
*--------------------------------------------------------------------------------------------------、

 

PBO

*&---------------------------------------------------------------------*
*&  Include           ZFI_SP_PBO
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  STATUS_1001  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_1001 OUTPUT.
  SET PF-STATUS 'T001'.
  PERFORM alvshow.   "展示双击选中会计编号的详细会计科目
*  SET TITLEBAR '凭证科目'.
ENDMODULE.                 " STATUS_1001  OUTPUT

 

 

PAI

*&---------------------------------------------------------------------*
*&  Include           ZFI_SP_PAI
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_1001  INPUT
*&---------------------------------------------------------------------*
*  单个记录已审批的的会计凭证
*----------------------------------------------------------------------*
MODULE user_command_1001 INPUT.
  save_ok = ok_code.
  CLEAR ok_code.
  CASE save_ok.
    WHEN 'SP'.
      MOVE-CORRESPONDING gt_itab TO wa_insert.
      wa_insert-zerdt = sy-datum.
      wa_insert-uzeit = sy-uzeit.
      wa_insert-uname = sy-uname.
      wa_insert-sp = 'X'.
      INSERT zfi_sp_table FROM wa_insert.

      MOVE-CORRESPONDING gt_itab TO wa_itab.
      DELETE TABLE gt_itab FROM wa_itab.
      CLEAR:wa_itab,gt_itab.
      CLEAR:itab2[],itab2.
      LEAVE TO SCREEN 0.
    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
      CLEAR:itab2[],itab2,wa_itab,gt_itab.
      LEAVE TO SCREEN 0.
  ENDCASE.

ENDMODULE.                 " USER_COMMAND_1001  INPUT

 

posted @ 2020-09-14 13:45  肆意点  阅读(425)  评论(0编辑  收藏  举报