SAP-ABAP 报工及费用分摊功能

&---------------------------------------------------------------------
*& Report ZCOPP001
&---------------------------------------------------------------------

REPORT zcopp001 MESSAGE-ID 00.

INCLUDE zcopp001_top.
INCLUDE zcopp001_sel.
INCLUDE zcopp001_frm.

START-OF-SELECTION.

AUTHORITY-CHECK OBJECT ‘F_BKPF_BUK’ ID ‘BUKRS’ FIELD p_bukrs
ID ‘ACTVT’ DUMMY.
IF sy-subrc <> 0.
MESSAGE e208 WITH ‘没有公司代码权限’.
ENDIF.

"取自建表数据
PERFORM frm_get_data.

**显示数据
PERFORM frm_alv_data.

END-OF-SELECTION.


&---------------------------------------------------------------------
*& 包含 ZCOPP001_TOP
&---------------------------------------------------------------------

------------------------------------------------------------

  • 数据声明 - 开始
    ------------------------------------------------------------

------------------------------------------------------------

  • DESC:INCLUDES文件 *
    ------------------------------------------------------------
    *INCLUDE .

------------------------------------------------------------

  • DESC: 表/ 结构 / 视图的声明 *
    ------------------------------------------------------------

TABLES: sscrfields, ztco002, ztco003.

------------------------------------------------------------

  • DESC: 定义所需要的 TYPES *
    ------------------------------------------------------------
    *TYPE-POOLS: slis.

TYPES: BEGIN OF ty_out.
INCLUDE TYPE ztco002.
TYPES:
butxt TYPE t001-butxt,
sltext TYPE cskt-ltext,
rltext TYPE cskt-ltext,
bkbez TYPE t025t-bkbez,
"cellcolor TYPE lvc_t_scol, "行颜色控制段
stat TYPE char4,
sel TYPE char1,
mess TYPE bapi_msg, "执行信息
END OF ty_out.
------------------------------------------------------------

  • DESC:定义所需要的内表 / 结构 *
    ------------------------------------------------------------
    DATA: gt_out TYPE TABLE OF ty_out,
    wa_out LIKE LINE OF gt_out,
    gt_ztco002 TYPE TABLE OF ztco002,
    wa_ztco002 LIKE LINE OF gt_ztco002,
    gt_ztco003 TYPE TABLE OF ztco003,
    wa_ztco003 LIKE LINE OF gt_ztco003.

DATA: gv_posnr TYPE buzei.

------------BAPI相关定义------------------
DATA :gw_documentheader TYPE bapiache09, "凭证头
gt_currencyamount TYPE TABLE OF bapiaccr09 WITH HEADER LINE, "金额行
gt_accountgl TYPE TABLE OF bapiacgl09 WITH HEADER LINE, "总账
gt_return TYPE TABLE OF bapiret2 WITH HEADER LINE, "扩充
gt_extension2 TYPE TABLE OF bapiparex WITH HEADER LINE, "返回 "
gw_zsfi_exten TYPE zsfi004, "扩充结构
gt_accountreceivable TYPE TABLE OF bapiacar09 WITH HEADER LINE, "应收
gt_accountpayable TYPE TABLE OF bapiacap09 WITH HEADER LINE, "应付
gt_criteria TYPE TABLE OF bapiackec9 WITH HEADER LINE.

**–ALV用
DATA: gt_events TYPE slis_t_event,

  •  gw_reprep   TYPE  slis_reprep_id,
    gw_layout   TYPE  lvc_s_layo,
    gw_settings TYPE  lvc_s_glay,
    wa_fieldcat TYPE  lvc_s_fcat,
    gt_fieldcat TYPE  lvc_t_fcat,
    gt_drop     TYPE  lvc_t_drop,
    wa_drop     TYPE  lvc_s_drop,
    wa_sort     TYPE  slis_sortinfo_alv,
    gt_sort     TYPE  slis_t_sortinfo_alv,
    gt_header   TYPE slis_t_listheader,
    wa_header   TYPE slis_listheader.
    

------------------------------------------------------------

  • DESC: 定义变/常量 *
    ------------------------------------------------------------
    DATA: gv_len TYPE i,
    gv_flag TYPE char1.

DATA: g_zgxc_hkont TYPE hkont,
g_lwcb_hkont TYPE hkont,
g_olda_hkont TYPE hkont,
g_medi_hkont TYPE hkont,
g_emij_hkont TYPE hkont,
g_mate_hkont TYPE hkont,
g_unem_hkont TYPE hkont,
g_gjj_hkont TYPE hkont,
g_fwf_hkont TYPE hkont.

CONSTANTS: c_zgxc_hkont TYPE hkont VALUE ‘6601000001’,
c_lwcb_hkont TYPE hkont VALUE ‘6601000002’,
c_olda_hkont TYPE hkont VALUE ‘6601000003’,
c_medi_hkont TYPE hkont VALUE ‘6601000004’,
c_emij_hkont TYPE hkont VALUE ‘6601000005’,
c_mate_hkont TYPE hkont VALUE ‘6601000006’,
c_unem_hkont TYPE hkont VALUE ‘6601000007’,
c_gjj_hkont TYPE hkont VALUE ‘6601000008’,
c_fwf_hkont TYPE hkont VALUE ‘6601000048’. " lucky 20220408

CONSTANTS: c_zgxc_hkont_zc TYPE hkont VALUE ‘5301010101’,
c_lwcb_hkont_zc TYPE hkont VALUE ‘5301010118’,
c_olda_hkont_zc TYPE hkont VALUE ‘5301010108’,
c_medi_hkont_zc TYPE hkont VALUE ‘5301010109’,
c_emij_hkont_zc TYPE hkont VALUE ‘5301010111’,
c_mate_hkont_zc TYPE hkont VALUE ‘5301010110’,
c_unem_hkont_zc TYPE hkont VALUE ‘5301010112’,
c_gjj_hkont_zc TYPE hkont VALUE ‘5301010113’,
c_fwf_hkont_zc TYPE hkont VALUE ‘5301010136’." lucky 20220408

CONSTANTS: c_zgxc_hkont_zx TYPE hkont VALUE ‘5301010201’,
c_lwcb_hkont_zx TYPE hkont VALUE ‘5301010218’,
c_olda_hkont_zx TYPE hkont VALUE ‘5301010208’,
c_medi_hkont_zx TYPE hkont VALUE ‘5301010209’,
c_emij_hkont_zx TYPE hkont VALUE ‘5301010211’,
c_mate_hkont_zx TYPE hkont VALUE ‘5301010210’,
c_unem_hkont_zx TYPE hkont VALUE ‘5301010212’,
c_gjj_hkont_zx TYPE hkont VALUE ‘5301010213’,
c_fwf_hkont_zx TYPE hkont VALUE ‘5301010236’." lucky 20220408

------------------------------------------------------------

  • DESC: 定义屏幕号变量 *
    ------------------------------------------------------------
    *DATA: "sub(3) TYPE c VALUE ‘100’, "初始屏幕的屏幕号变量
  •  subrc_main(3) TYPE c VALUE '100',   "显示平台初始屏幕下面的屏幕号变量
    
  •  sub_target(3) TYPE c VALUE '221'.    "下半屏幕下得屏幕号变量
    

------------------------------------------------------------

  • DESC: 定义表条目变量和表控制变量 *
    ------------------------------------------------------------
    *CONTROLS: triptab TYPE TABSTRIP.
    --------------------------------------------------------------------
  • DESC: 定义类 *
    --------------------------------------------------------------------
    ------------------------------------------------------------
  • 数据定义 - 结束 *
    ------------------------------------------------------------

&---------------------------------------------------------------------
*& 包含 ZCOPP001_SEL
&---------------------------------------------------------------------
------------------------------------------------------------

  • DESC: 定义选择屏幕 —开始 *
    ------------------------------------------------------------
    SELECTION-SCREEN: FUNCTION KEY 1. "激活
    SELECTION-SCREEN: FUNCTION KEY 2. "激活

SELECTION-SCREEN: BEGIN OF BLOCK blk0 WITH FRAME TITLE TEXT-001.
PARAMETERS: p_bukrs TYPE bukrs OBLIGATORY DEFAULT ‘1100’, " File location Input
p_gjahr TYPE gjahr OBLIGATORY,
p_monat TYPE monat OBLIGATORY.

SELECTION-SCREEN END OF BLOCK blk0.

------------------------------------------------------------

  • DESC: 定义选择屏幕 —结束 *
    ------------------------------------------------------------
    INITIALIZATION.
    DATA: lv_date TYPE sy-datum.
    CALL FUNCTION ‘FIMA_DATE_CREATE’
    EXPORTING
    i_date = sy-datum
    i_months = -1
    IMPORTING
    e_date = lv_date.
    p_gjahr = lv_date(4).
    p_monat = lv_date+4(2).

sscrfields-functxt_01 = icon_tools && ‘工时工费导入程序’.
sscrfields-functxt_02 = icon_history && ‘历史凭证’.

AT SELECTION-SCREEN.
CASE sscrfields-ucomm.
WHEN ‘FC01’."工时工费导入程序
SUBMIT zcocp001 WITH p_gjahr = p_gjahr
WITH p_monat = p_monat
VIA SELECTION-SCREEN AND RETURN.
WHEN ‘FC02’."历史凭证
SUBMIT zcorp002 WITH p_bukrs = p_bukrs
WITH p_gjahr = p_gjahr
VIA SELECTION-SCREEN AND RETURN.
ENDCASE.


&---------------------------------------------------------------------
*& 包含 ZCOPP001_FRM
&---------------------------------------------------------------------
&---------------------------------------------------------------------
*& Form frm_alv_data
&---------------------------------------------------------------------
*& text
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM frm_alv_data .
REFRESH: gt_fieldcat.
CLEAR: gw_layout,gw_settings.
gw_layout-cwidth_opt = ‘X’.
gw_layout-zebra = ‘X’.

  • gw_layout-box_fname = ‘SEL’.

  • gw_layout-stylefname = ‘EDITMARK’.

  • gw_settings-edt_cll_cb = ‘X’.

PERFORM frm_fill_dieldcat.

CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC’
EXPORTING

  • I_INTERFACE_CHECK        = ' '
    
  • I_BYPASSING_BUFFER       =
    
  • I_BUFFER_ACTIVE          =
    i_callback_program       = sy-repid
    i_callback_pf_status_set = 'SET_PF_STATUS'
    i_callback_user_command  = 'USER_COMMAND'
    
  • I_CALLBACK_TOP_OF_PAGE   = ' '
    
  • I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
    
  • I_CALLBACK_HTML_END_OF_LIST       = ' '
    
  • I_STRUCTURE_NAME         =
    
  • I_BACKGROUND_ID          = ' '
    
  • i_grid_title             = gv_title
    
  • i_grid_settings          = gw_settings
    is_layout_lvc            = gw_layout
    it_fieldcat_lvc          = gt_fieldcat
    
  • it_excluding             = gt_excluding
    
  • IT_SPECIAL_GROUPS_LVC    =
    
  • IT_SORT_LVC              =
    
  • IT_FILTER_LVC            =
    
  • IT_HYPERLINK             =
    
  • IS_SEL_HIDE              =
    i_default                = 'X'
    i_save                   = 'A'
    
  • IS_VARIANT               =
    
  • IT_EVENTS                =
    
  • IT_EVENT_EXIT            =
    
  • IS_PRINT_LVC             =
    
  • IS_REPREP_ID_LVC         =
    
  • I_SCREEN_START_COLUMN    = 0
    
  • I_SCREEN_START_LINE      = 0
    
  • I_SCREEN_END_COLUMN      = 0
    
  • I_SCREEN_END_LINE        = 0
    
  • I_HTML_HEIGHT_TOP        =
    
  • I_HTML_HEIGHT_END        =
    
  • IT_ALV_GRAPHICS          =
    
  • IT_EXCEPT_QINFO_LVC      =
    
  • IR_SALV_FULLSCREEN_ADAPTER        =
    
  • IMPORTING
  • E_EXIT_CAUSED_BY_CALLER  =
    
  • ES_EXIT_CAUSED_BY_USER   =
    
    TABLES
    t_outtab = gt_out
    EXCEPTIONS
    program_error = 1
    OTHERS = 2.
    IF sy-subrc <> 0.
  • Implement suitable error handling here
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

ENDFORM.
FORM set_pf_status USING rt_extab TYPE slis_t_extab.

REFRESH: rt_extab.
SET PF-STATUS ‘STANDARD’ EXCLUDING rt_extab.

ENDFORM.
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
DATA: lv_subrc TYPE sy-subrc.

CASE r_ucomm.
WHEN ‘ZPOST’.
CLEAR: lv_subrc.
PERFORM frm_check_document CHANGING lv_subrc.
IF lv_subrc = 0.
PERFORM frm_post_document.
ENDIF.

WHEN 'ZREVERSE'.
  PERFORM frm_reverse_document.

WHEN OTHERS.

ENDCASE.

rs_selfield-refresh = ‘X’.
rs_selfield-row_stable = ‘X’.
rs_selfield-col_stable = ‘X’.
ENDFORM.
&---------------------------------------------------------------------
*& Form frm_fill_dieldcat
&---------------------------------------------------------------------
*& text
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM frm_fill_dieldcat .
DEFINE def_fcat.
CLEAR: wa_fieldcat.
wa_fieldcat-fieldname = &1.
wa_fieldcat-coltext = &2.
wa_fieldcat-ref_field = &3.
wa_fieldcat-ref_table = &4.

  • wa_fieldcat-edit = &5.
  • wa_fieldcat-checkbox = &6.
  • wa_fieldcat-no_zero = &7.
    APPEND wa_fieldcat TO gt_fieldcat.
    END-OF-DEFINITION.

def_fcat ‘STAT’ ‘消息状态’ ‘’ ‘’.
def_fcat ‘MESS’ ‘消息’ ‘’ ‘’.
def_fcat ‘DYPC’ ‘导入批次’ ‘’ ‘’.
def_fcat ‘BUKRS’ ‘公司代码’ ‘BUKRS’ ‘ZTCO002’.
def_fcat ‘BUTXT’ ‘公司代码描述’ ‘BUTXT’ ‘T001’.
def_fcat ‘CJAHR’ ‘年度’ ‘CJAHR’ ‘ZTCO002’.
def_fcat ‘MONAT’ ‘期间’ ‘MONAT’ ‘ZTCO002’.

  • def_fcat ‘PARTNER’ ‘员工号’ ‘PARTNER’ ‘ZTCO002’.
  • def_fcat ‘NAME’ ‘姓名’ ‘’ ‘ZTCO002’.
    def_fcat ‘SKOSTL’ ‘发出成本中心’ ‘SKOSTL’ ‘ZTCO002’.
    def_fcat ‘SLTEXT’ ‘发出成本中心描述’ ‘LTEXT’ ‘CSKT’.
    def_fcat ‘ZGZFL’ ‘工作分类’ ‘’ ‘ZTCO002’.
    def_fcat ‘BKLAS’ ‘系列’ ‘BKLAS’ ‘ZTCO002’.
    def_fcat ‘BKBEZ’ ‘系列名称’ ‘BKBEZ’ ‘T025T’.
    def_fcat ‘RKOSTL’ ‘接收成本中心’ ‘RKOSTL’ ‘ZTCO002’.
    def_fcat ‘RLTEXT’ ‘接收成本中心描述’ ‘LTEXT’ ‘CSKT’.
    def_fcat ‘ZPRONO’ ‘项目号’ ‘ZPRONO’ ‘ZTCO002’.
    def_fcat ‘AUFNR’ ‘内部订单’ ‘AUFNR’ ‘ZTCO002’.
    def_fcat ‘ZGS’ ‘工时’ ‘ZGS’ ‘ZTCO002’.
    def_fcat ‘ZZGXC’ ‘职工薪酬’ ‘ZZGXC’ ‘ZTCO002’.
    def_fcat ‘ZLWCB’ ‘劳务成本’ ‘ZLWCB’ ‘ZTCO002’.
    def_fcat ‘ZOLDA’ ‘社保-养老’ ‘ZOLDA’ ‘ZTCO002’.
    def_fcat ‘ZMEDI’ ‘社保-医疗’ ‘ZMEDI’ ‘ZTCO002’.
    def_fcat ‘ZEMIJ’ ‘社保-工伤’ ‘ZEMIJ’ ‘ZTCO002’.
    def_fcat ‘ZMATE’ ‘社保-生育’ ‘ZMATE’ ‘ZTCO002’.
    def_fcat ‘ZUNEM’ ‘社保-失业’ ‘ZUNEM’ ‘ZTCO002’.
    def_fcat ‘ZGJJ’ ‘公积金’ ‘ZGJJ’ ‘ZTCO002’.
    def_fcat ‘ZFWF’ ‘技术服务费’ ‘ZFWF’ ‘ZTCO002’. "lucky 20220408
    def_fcat ‘ZHJ’ ‘合计’ ‘ZHJ’ ‘ZTCO002’.
    def_fcat ‘RBUKRS’ ‘会计凭证公司代码’ ‘RBUKRS’ ‘ZTCO002’.
    def_fcat ‘GJAHR’ ‘会计凭证年度’ ‘GJAHR’ ‘ZTCO002’.
    def_fcat ‘BELNR’ ‘会计凭证’ ‘BELNR’ ‘ZTCO002’.
    ENDFORM.
    &---------------------------------------------------------------------
    *& Form frm_get_data
    &---------------------------------------------------------------------
    *& text
    &---------------------------------------------------------------------
    *& --> p1 text
    *& <-- p2 text
    &---------------------------------------------------------------------
    FORM frm_get_data .
    REFRESH: gt_out.

SELECT * FROM ztco002
INTO CORRESPONDING FIELDS OF TABLE gt_out
WHERE bukrs = p_bukrs
AND cjahr = p_gjahr
AND monat = p_monat.

CHECK gt_out[] IS NOT INITIAL.

SELECT bukrs, butxt
FROM t001
INTO TABLE @DATA(lt_t001).

  • SELECT partner, name_last

  • INTO TABLE @DATA(lt_partner)

  • FROM but000

  • WHERE type = ‘1’

  •  AND bu_group = 'Z006'.
    

    SELECT kostl, ltext
    FROM cskt
    INTO TABLE @DATA(lt_cskt)
    WHERE spras = ‘1’
    AND kokrs = ‘8000’
    AND datbi >= @sy-datum.

    SELECT bklas, bkbez
    FROM t025t
    INTO TABLE @DATA(lt_t025t)
    WHERE spras = ‘1’.

    SORT lt_t001 BY bukrs.

  • SORT lt_partner BY partner.
    SORT lt_cskt BY kostl.
    SORT lt_t025t BY bklas.

"取描述
LOOP AT gt_out INTO wa_out.

  • READ TABLE lt_partner INTO DATA(ls_partner) WITH KEY partner = wa_out-partner BINARY SEARCH.
  • IF sy-subrc = 0.
  •  wa_out-name = ls_partner-name_last.
    
  • ENDIF.
READ TABLE lt_cskt INTO DATA(ls_cskt) WITH KEY kostl = wa_out-skostl BINARY SEARCH.
IF sy-subrc = 0.
  wa_out-sltext = ls_cskt-ltext.
ENDIF.

READ TABLE lt_cskt INTO ls_cskt WITH KEY kostl = wa_out-rkostl BINARY SEARCH.
IF sy-subrc = 0.
  wa_out-rltext = ls_cskt-ltext.
ENDIF.

READ TABLE lt_t025t INTO DATA(ls_t025t) WITH KEY bklas = wa_out-bklas BINARY SEARCH.
IF sy-subrc = 0.
  wa_out-bkbez = ls_t025t-bkbez.
ENDIF.

READ TABLE lt_t001 INTO DATA(ls_t001) WITH KEY bukrs = wa_out-bukrs BINARY SEARCH.
IF sy-subrc = 0.
  wa_out-butxt = ls_t001-butxt.
ENDIF.

MODIFY gt_out FROM wa_out.

ENDLOOP.

ENDFORM.
&---------------------------------------------------------------------
*& Form frm_post_document
&---------------------------------------------------------------------
*& 生产会计凭证
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM frm_post_document .

DATA: l_dmbtr TYPE dmbtr,
l_sgtxt TYPE sgtxt,
l_objnr TYPE j_objnr,
l_field TYPE char30,
l_errflg TYPE char1,
l_date TYPE sy-datum,
l_waers TYPE t001-waers,
l_lines TYPE i,
l_tabix TYPE sy-tabix.
DATA: lt_out TYPE TABLE OF ty_out, "用于校验COSP成本中心实际发生额
lt_out2 TYPE TABLE OF ty_out, "用于生成凭证
ls_out TYPE ty_out.
FIELD-SYMBOLS: .

RANGES: "r_aufnr FOR coas-aufnr,
r_auart FOR coas-auart.

  •      r_objnr FOR cosp-objnr.
    

    r_auart[] = VALUE #(
    ( sign = ‘I’ option = ‘EQ’ low = ‘1101’ )
    ( sign = ‘I’ option = ‘EQ’ low = ‘1201’ )
    ( sign = ‘I’ option = ‘EQ’ low = ‘1301’ )
    ( sign = ‘I’ option = ‘EQ’ low = ‘1401’ )
    ( sign = ‘I’ option = ‘EQ’ low = ‘1501’ )
    ( sign = ‘I’ option = ‘EQ’ low = ‘1601’ )
    ( sign = ‘I’ option = ‘EQ’ low = ‘1701’ )
    ( sign = ‘I’ option = ‘EQ’ low = ‘1711’ )
    ).

    REFRESH: lt_out.
    LOOP AT gt_out INTO wa_out where belnr is INITIAL.
    CLEAR: ls_out.
    ls_out-dypc = wa_out-dypc.
    ls_out-cjahr = wa_out-cjahr.
    ls_out-monat = wa_out-monat.
    ls_out-bukrs = wa_out-bukrs.
    ls_out-skostl = wa_out-skostl.
    ls_out-zzgxc = wa_out-zzgxc.
    ls_out-zlwcb = wa_out-zlwcb.
    ls_out-zolda = wa_out-zolda.
    ls_out-zmedi = wa_out-zmedi.
    ls_out-zemij = wa_out-zemij.
    ls_out-zmate = wa_out-zmate.
    ls_out-zunem = wa_out-zunem.
    ls_out-zgjj = wa_out-zgjj.
    ls_out-zfwf = wa_out-zfwf. "lucky 20220408
    COLLECT ls_out INTO lt_out.

    ls_out-rkostl = wa_out-rkostl.
    ls_out-aufnr = wa_out-aufnr.
    ls_out-auart = wa_out-auart.
    ls_out-zprono = wa_out-zprono.
    ls_out-rbukrs = wa_out-rbukrs.
    ls_out-gjahr = wa_out-gjahr.
    ls_out-belnr = wa_out-belnr.
    COLLECT ls_out INTO lt_out2.

  • IF wa_out-belnr IS NOT INITIAL.

  •  l_errflg = 'X'.
    
  •  MESSAGE '请先冲销旧凭证' TYPE 'W'.
    
  •  EXIT.
    
  • ENDIF.
    ENDLOOP.

CHECK l_errflg = ‘’."无错误才创建凭证

"2022/03/10客户要求取消校验逻辑

  • "4、金额按科目分,总额小于等于成本中心对应的科目当月发生额;
  • "5、校验的表是COSP,比如:KS+8000+成本中心=对象号(COSP-OBJNR),COSP-GJAHR=分摊年度,COSP-WRTTP=‘ 04’,
  • "VERSN=‘0’KSTAR=对应科目,如:6601000001,然后取WTG001~WTG016,16个对应16个期间,进行汇总;
  • LOOP AT lt_out INTO ls_out.
  • l_objnr = ‘KS8000’ && ls_out-skostl.
  • SELECT kstar, SUM( wtg001 ) AS wtg001, SUM( wtg002 ) AS wtg002, SUM( wtg003 ) AS wtg003, SUM( wtg004 ) AS wtg004,
  •      SUM( wtg005 ) AS wtg005, SUM( wtg006 ) AS wtg006, SUM( wtg007 ) AS wtg007, SUM( wtg008 ) AS wtg008,
    
  •      SUM( wtg009 ) AS wtg009, SUM( wtg010 ) AS wtg010, SUM( wtg011 ) AS wtg011, SUM( wtg012 + wtg013 + wtg014 + wtg015 + wtg016 ) AS wtg012
    
  •  FROM cosp
    
  •  INTO TABLE @DATA(lt_cosp)
    
  •  WHERE objnr = @l_objnr
    
  •    AND gjahr = @p_gjahr
    
  •    AND wrttp = '04'
    
  •    AND versn = '000'
    
  •    AND kstar IN ( @c_zgxc_hkont, @c_lwcb_hkont, @c_olda_hkont, @c_medi_hkont, @c_emij_hkont, @c_mate_hkont, @c_unem_hkont, @c_gjj_hkont )
    
  •  GROUP BY kstar.
    
  • LOOP AT lt_cosp INTO DATA(ls_cosp).
  •  l_field = 'WTG0' && p_monat.
    
  •  ASSIGN COMPONENT l_field OF STRUCTURE ls_cosp TO .
    
  •  CASE ls_cosp-kstar.
    
  •    WHEN c_zgxc_hkont.
    
  •      IF ls_out-zzgxc > .
    
  •        wa_out-stat = icon_red_light.
    
  •        wa_out-mess = wa_out-mess && '职工薪酬总额大于成本中心对应科目当月发生额;'.
    
  •        l_errflg = 'X'.
    
  •      ENDIF.
    
  •    WHEN c_lwcb_hkont.
    
  •      IF ls_out-zlwcb > .
    
  •        wa_out-stat = icon_red_light.
    
  •        wa_out-mess = wa_out-mess && '劳务成本总额大于成本中心对应科目当月发生额;'.
    
  •        l_errflg = 'X'.
    
  •      ENDIF.
    
  •    WHEN c_olda_hkont.
    
  •      IF ls_out-zolda > .
    
  •        wa_out-stat = icon_red_light.
    
  •        wa_out-mess = wa_out-mess && '社保-养老总额大于成本中心对应科目当月发生额;'.
    
  •        l_errflg = 'X'.
    
  •      ENDIF.
    
  •    WHEN c_medi_hkont.
    
  •      IF ls_out-zmedi > .
    
  •        wa_out-stat = icon_red_light.
    
  •        wa_out-mess = wa_out-mess && '社保-医疗总额大于成本中心对应科目当月发生额;'.
    
  •        l_errflg = 'X'.
    
  •      ENDIF.
    
  •    WHEN c_emij_hkont.
    
  •      IF ls_out-zemij > .
    
  •        wa_out-stat = icon_red_light.
    
  •        wa_out-mess = wa_out-mess && '社保-工伤总额大于成本中心对应科目当月发生额;'.
    
  •        l_errflg = 'X'.
    
  •      ENDIF.
    
  •    WHEN c_mate_hkont.
    
  •      IF ls_out-zmate > .
    
  •        wa_out-stat = icon_red_light.
    
  •        wa_out-mess = wa_out-mess && '社保-生育总额大于成本中心对应科目当月发生额;'.
    
  •        l_errflg = 'X'.
    
  •      ENDIF.
    
  •    WHEN c_unem_hkont.
    
  •      IF ls_out-zunem > .
    
  •        wa_out-stat = icon_red_light.
    
  •        wa_out-mess = wa_out-mess && '社保-失业总额大于成本中心对应科目当月发生额;'.
    
  •        l_errflg = 'X'.
    
  •      ENDIF.
    
  •    WHEN c_gjj_hkont.
    
  •      IF ls_out-zgjj > .
    
  •        wa_out-stat = icon_red_light.
    
  •        wa_out-mess = wa_out-mess && '公积金总额大于成本中心对应科目当月发生额;'.
    
  •        l_errflg = 'X'.
    
  •      ENDIF.
    
  •  ENDCASE.
    
  •  UNASSIGN .
    
  • ENDLOOP.
  • REFRESH:lt_cosp.
  • MODIFY gt_out FROM wa_out TRANSPORTING stat mess WHERE skostl = ls_out-skostl.
  • ENDLOOP.

CHECK l_errflg = ‘’."无错误才创建凭证

CLEAR: gv_posnr.
REFRESH : gt_accountgl,gt_accountreceivable,gt_accountpayable,gt_currencyamount,gt_return,gt_extension2,gt_criteria.
CLEAR : gw_documentheader.

DESCRIBE TABLE lt_out2 LINES l_lines.

SELECT SINGLE waers FROM t001 INTO l_waers WHERE bukrs = p_bukrs.
LOOP AT lt_out2 INTO wa_out.
l_tabix = sy-tabix.

wa_out-belnr = '$1'.
MODIFY lt_out2 FROM wa_out.

IF wa_out-aufnr IS NOT INITIAL.
  l_sgtxt = |{ p_gjahr }年{ p_monat }月份从{ wa_out-skostl }成本中心人工转入内部订单|.
  "科目进行更换,具体如下表:内部订单类型1101,1201,1301,1401,1501,1601,1701,1711,都计入自筹对应的科目,即5301010*,不计入专项科目;
  "其他内部订单类型,都计入6601*对应的科目;
  IF wa_out-auart IN r_auart[].
    g_zgxc_hkont = c_zgxc_hkont_zc.
    g_lwcb_hkont = c_lwcb_hkont_zc.
    g_gjj_hkont = c_gjj_hkont_zc.
    g_olda_hkont = c_olda_hkont_zc.
    g_medi_hkont = c_medi_hkont_zc.
    g_emij_hkont = c_emij_hkont_zc.
    g_mate_hkont = c_mate_hkont_zc.
    g_unem_hkont = c_unem_hkont_zc.
    g_fwf_hkont = c_fwf_hkont_zc.
  ELSE.
    g_zgxc_hkont = c_zgxc_hkont.
    g_lwcb_hkont = c_lwcb_hkont.
    g_gjj_hkont = c_gjj_hkont.
    g_olda_hkont = c_olda_hkont.
    g_medi_hkont = c_medi_hkont.
    g_emij_hkont = c_emij_hkont.
    g_mate_hkont = c_mate_hkont.
    g_unem_hkont = c_unem_hkont.
    g_fwf_hkont = c_fwf_hkont.
  ENDIF.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  l_sgtxt = |{ p_gjahr }年{ p_monat }月份从{ wa_out-skostl }成本中心人工转入{ wa_out-rkostl }成本中心|.

  g_zgxc_hkont = c_zgxc_hkont.
  g_lwcb_hkont = c_lwcb_hkont.
  g_gjj_hkont = c_gjj_hkont.
  g_olda_hkont = c_olda_hkont.
  g_medi_hkont = c_medi_hkont.
  g_emij_hkont = c_emij_hkont.
  g_mate_hkont = c_mate_hkont.
  g_unem_hkont = c_unem_hkont.
  g_fwf_hkont = c_fwf_hkont.
ENDIF.

"总账
"职工薪酬
l_dmbtr = wa_out-zzgxc * -1.
IF wa_out-aufnr IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_zgxc_hkont  ''  wa_out-zprono l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zzgxc g_zgxc_hkont  wa_out-aufnr  wa_out-zprono  l_sgtxt l_waers ''.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_zgxc_hkont  ''  '' l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zzgxc g_zgxc_hkont  ''   ''  l_sgtxt l_waers wa_out-rkostl.
ENDIF.

"劳务成本
l_dmbtr = wa_out-zlwcb * -1.
IF wa_out-aufnr IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_lwcb_hkont  ''  wa_out-zprono l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zlwcb g_lwcb_hkont  wa_out-aufnr  wa_out-zprono  l_sgtxt l_waers ''.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_lwcb_hkont  ''  '' l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zlwcb g_lwcb_hkont  ''   ''  l_sgtxt l_waers wa_out-rkostl.
ENDIF.

"公积金
l_dmbtr = wa_out-zgjj * -1.
IF wa_out-aufnr IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_gjj_hkont  ''  wa_out-zprono l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zgjj g_gjj_hkont  wa_out-aufnr  wa_out-zprono  l_sgtxt l_waers ''.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_gjj_hkont  ''  '' l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zgjj g_gjj_hkont  ''   ''  l_sgtxt l_waers wa_out-rkostl.
ENDIF.

"社保-养老
l_dmbtr = wa_out-zolda * -1.
IF wa_out-aufnr IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_olda_hkont  ''  wa_out-zprono l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zolda g_olda_hkont  wa_out-aufnr  wa_out-zprono  l_sgtxt l_waers ''.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_olda_hkont  ''  '' l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zolda g_olda_hkont  ''   ''  l_sgtxt l_waers wa_out-rkostl.
ENDIF.

"社保-医疗
l_dmbtr = wa_out-zmedi * -1.
IF wa_out-aufnr IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_medi_hkont  ''  wa_out-zprono l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zmedi g_medi_hkont  wa_out-aufnr  wa_out-zprono  l_sgtxt l_waers ''.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_medi_hkont  ''  '' l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zmedi g_medi_hkont  ''   ''  l_sgtxt l_waers wa_out-rkostl.
ENDIF.

"社保-工伤
l_dmbtr = wa_out-zemij * -1.
IF wa_out-aufnr IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_emij_hkont  ''  wa_out-zprono l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zemij g_emij_hkont  wa_out-aufnr  wa_out-zprono  l_sgtxt l_waers ''.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_emij_hkont  ''  '' l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zemij g_emij_hkont  ''   ''  l_sgtxt l_waers wa_out-rkostl.
ENDIF.

"社保-生育
l_dmbtr = wa_out-zmate * -1.
IF wa_out-aufnr IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_mate_hkont  ''  wa_out-zprono l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zmate g_mate_hkont  wa_out-aufnr  wa_out-zprono  l_sgtxt l_waers ''.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_mate_hkont  ''  '' l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zmate g_mate_hkont  ''   ''  l_sgtxt l_waers wa_out-rkostl.
ENDIF.

"社保-失业
l_dmbtr = wa_out-zunem * -1.
IF wa_out-aufnr IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_unem_hkont  ''  wa_out-zprono l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zunem g_unem_hkont  wa_out-aufnr  wa_out-zprono  l_sgtxt l_waers ''.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_unem_hkont  ''  '' l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zunem g_unem_hkont  ''   ''  l_sgtxt l_waers wa_out-rkostl.
ENDIF.

"技术服务费   lucky 20220408
l_dmbtr = wa_out-zfwf * -1.
IF wa_out-aufnr IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_fwf_hkont  ''  wa_out-zprono l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zfwf g_fwf_hkont  wa_out-aufnr  wa_out-zprono  l_sgtxt l_waers ''.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_fwf_hkont  ''  '' l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zfwf g_fwf_hkont  ''   ''  l_sgtxt l_waers wa_out-rkostl.
ENDIF.

"生成会计凭证
IF gv_posnr >=  '980' OR l_tabix = l_lines."每行alv8个科目工12行,留足行项目,避免中间超过999
  l_date = p_gjahr && p_monat && '01'.
  CALL FUNCTION 'FIMA_DATE_CREATE'
    EXPORTING
      i_date                  = l_date
      i_set_last_day_of_month = 'X'
    IMPORTING
      e_date                  = l_date.

  "抬头数据
  CLEAR gw_documentheader.
  gw_documentheader-comp_code = wa_out-bukrs.   "公司代码

  gw_documentheader-doc_date = sy-datum.    "凭证日期

  gw_documentheader-pstng_date = l_date.  "过账日期

  gw_documentheader-doc_type = 'Z7'.    "凭证类型

  gw_documentheader-header_txt = |{ p_gjahr }年{ p_monat }月份的人工费用|.  "凭证抬头文本

  gw_documentheader-fisc_year = p_gjahr.  "会计年度

  gw_documentheader-fis_period = p_monat.  "期间

  gw_documentheader-username = sy-uname.


  CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
    EXPORTING
      documentheader    = gw_documentheader
  •     CUSTOMERCPD       =
    
  •     CONTRACTHEADER    =
    
  •    IMPORTING
    
  •     OBJ_TYPE          =
    
  •     OBJ_KEY           = LV_OBJKEY
    
  •     OBJ_SYS           =
      TABLES
        accountgl         = gt_accountgl[]
        accountreceivable = gt_accountreceivable[]
        accountpayable    = gt_accountpayable[]
    
  •     ACCOUNTTAX        =
        currencyamount    = gt_currencyamount[]
    
  •     criteria          = gt_criteria[]
    
  •     VALUEFIELD        =
    
  •     EXTENSION1        =
        return            = gt_return[]
    
  •     PAYMENTCARD       =
    
  •     CONTRACTITEM      =
        extension2        = gt_extension2[]
    
  •     REALESTATE        =
    
  •     ACCOUNTWT         =
      .
    LOOP AT gt_return WHERE type = 'E' OR type = 'A'.
    ENDLOOP.
    IF sy-subrc = 0.
      CLEAR: wa_out-belnr.
      wa_out-stat  = icon_red_light.
      READ TABLE gt_return INDEX 2.
      IF sy-subrc = 0.
        wa_out-mess  = gt_return-message.
      ELSE.
        wa_out-mess = '会计凭证创建失败'.
      ENDIF.
      LOOP AT lt_out2 INTO ls_out WHERE belnr = '$1'.
        ls_out-stat = wa_out-stat.
        ls_out-mess = wa_out-mess.
        ls_out-belnr = wa_out-belnr.
        MODIFY lt_out2 FROM ls_out.
        MODIFY gt_out FROM wa_out TRANSPORTING stat mess belnr
          WHERE skostl = ls_out-skostl
            AND rkostl = ls_out-rkostl
            AND aufnr = ls_out-aufnr
            AND zprono = ls_out-zprono
            and dypc = ls_out-dypc.
      ENDLOOP.
    
      l_errflg = 'X'.
    
      EXIT.
    ELSE.
    
      READ TABLE gt_return INDEX 1.
      wa_out-rbukrs = gt_return-message_v2+10(4). "公司代码
      wa_out-belnr = gt_return-message_v2+0(10) .                         "凭证编号
      wa_out-gjahr = gt_return-message_v2+14(4).
      wa_out-stat  = icon_green_light.
    
      LOOP AT lt_out2 INTO ls_out WHERE belnr = '$1'.
        ls_out-stat = wa_out-stat.
        ls_out-belnr = wa_out-belnr.
        ls_out-gjahr = wa_out-gjahr.
        ls_out-rbukrs = wa_out-rbukrs.
        MODIFY lt_out2 FROM ls_out.
    
        MODIFY gt_out FROM wa_out TRANSPORTING rbukrs belnr gjahr stat
          WHERE skostl = ls_out-skostl
            AND rkostl = ls_out-rkostl
            AND aufnr = ls_out-aufnr
            AND zprono = ls_out-zprono
            and dypc = ls_out-dypc.
    
      ENDLOOP.
    
    ENDIF.
    
    REFRESH : gt_accountgl,gt_accountreceivable,gt_accountpayable,gt_currencyamount,gt_return,gt_extension2,gt_criteria.
    CLEAR : gw_documentheader.
    CLEAR: gv_posnr.
    

    ENDIF.

    ENDLOOP.

    IF l_errflg = ‘’.
    REFRESH: gt_ztco002.
    MOVE-CORRESPONDING gt_out[] TO gt_ztco002[].
    IF gt_ztco002[] IS NOT INITIAL.
    MODIFY ztco002 FROM TABLE gt_ztco002.
    ENDIF.

    CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
    EXPORTING
    wait = ‘X’.
    ELSE.
    MODIFY gt_out FROM wa_out TRANSPORTING belnr WHERE belnr IS NOT INITIAL.

    CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’.

    ENDIF.
    ENDFORM.
    &---------------------------------------------------------------------
    *& Form frm_hkont_item
    &---------------------------------------------------------------------
    *& text
    &---------------------------------------------------------------------
    *& --> GS_OUTTAB_800_10
    *& --> P_
    *& --> GS_OUTTAB_AUFNR
    *& --> P_
    *& --> GS_OUTTAB_WAERK
    *& --> GS_OUTTAB_MATNR
    &---------------------------------------------------------------------
    FORM frm_hkont_item USING pv_kmze pv_hkont pv_aufnr pv_zprono pv_sgtxt pv_waerk pv_kostl.
    ADD 1 TO gv_posnr.
    "金额
    gt_currencyamount-itemno_acc = gv_posnr. "项目编号

    gt_currencyamount-currency = pv_waerk."‘GBP’. " 货币码

    gt_currencyamount-amt_doccur = pv_kmze . "货币金额

    APPEND gt_currencyamount.
    CLEAR gt_currencyamount.

    "总账
    gt_accountgl-itemno_acc = gv_posnr. "项目编号

    gt_accountgl-gl_account = pv_hkont . "总账科目

    gt_accountgl-orderid = pv_aufnr . "内部订单

    gt_accountgl-costcenter = pv_kostl . "成本中心

    gt_accountgl-item_text = pv_sgtxt. "文本

    APPEND gt_accountgl.
    CLEAR gt_accountgl.

    "扩展项

    gw_zsfi_exten-posnr = gv_posnr. "项目编号
    gw_zsfi_exten-zzxmbm = pv_zprono. "项目号
    IF pv_kmze < 0."总账科目金额为负,过账码为50;总账科目金额为正,过账码为40
    gw_zsfi_exten-bschl = ‘50’. "记账码
    ELSE.
    gw_zsfi_exten-bschl = ‘40’. "记账码
    ENDIF.

    gt_extension2-structure = ‘ZSFI004’.

    gt_extension2-valuepart1 = gw_zsfi_exten.

    APPEND gt_extension2.
    CLEAR : gt_extension2,gw_zsfi_exten.
    ENDFORM.
    &---------------------------------------------------------------------
    *& Form frm_reverse_document
    &---------------------------------------------------------------------
    *& text
    &---------------------------------------------------------------------
    *& --> p1 text
    *& <-- p2 text
    &---------------------------------------------------------------------
    FORM frm_reverse_document .
    DATA: lt_belnr TYPE TABLE OF ty_out,
    ls_reversal LIKE bapiacrev,
    lv_bus_act LIKE bapiache09-bus_act,
    lv_obj_key LIKE bapiacrev-obj_key,
    lt_return TYPE TABLE OF bapiret2,
    ls_return TYPE bapiret2.

    MOVE-CORRESPONDING gt_out TO lt_belnr.

    SORT lt_belnr BY rbukrs gjahr belnr.
    DELETE ADJACENT DUPLICATES FROM lt_belnr COMPARING rbukrs gjahr belnr.

    LOOP AT lt_belnr INTO DATA(ls_belnr) WHERE belnr IS NOT INITIAL.
    SELECT SINGLE * FROM bkpf INTO @DATA(ls_bkpf)
    WHERE bukrs = @ls_belnr-rbukrs
    AND belnr = @ls_belnr-belnr
    AND gjahr = @ls_belnr-gjahr
    AND xreversal = ‘’.
    IF sy-subrc <> 0.
    CLEAR: wa_out-rbukrs, wa_out-belnr, wa_out-gjahr.
    wa_out-stat = icon_red_light.
    wa_out-mess = ‘会计凭证不存在或已冲销’.

    UPDATE ztco002 SET rbukrs = wa_out-rbukrs
                       belnr = wa_out-belnr
                       gjahr = wa_out-gjahr
                       WHERE rbukrs = ls_belnr-rbukrs
                         AND belnr = ls_belnr-belnr
                         AND gjahr = ls_belnr-gjahr.
    COMMIT WORK AND WAIT.
    
    MODIFY gt_out FROM wa_out TRANSPORTING stat mess rbukrs belnr gjahr
      WHERE rbukrs = ls_belnr-rbukrs
        AND belnr = ls_belnr-belnr
        AND gjahr = ls_belnr-gjahr.
    CONTINUE.
    

    ENDIF.

    CLEAR: ls_reversal, lv_bus_act, lv_obj_key.
    REFRESH: lt_return.

  • bapi 参数赋值
    ls_reversal-obj_type = ls_bkpf-awtyp.

  • lS_reversal-obj_key = lS_bkpf-awkey.
    ls_reversal-obj_key_r = ls_bkpf-awkey.
    ls_reversal-pstng_date = ls_bkpf-budat.
    ls_reversal-fis_period = ls_bkpf-monat.
    ls_reversal-comp_code = ls_bkpf-bukrs.

  • ls_reversal-ac_doc_no = ls_bkpf-belnr.
    ls_reversal-reason_rev = ‘03’.
    lv_bus_act = ls_bkpf-glvor.

  • 取得系统 LOGICAL SYSTEM
    CALL FUNCTION ‘OWN_LOGICAL_SYSTEM_GET’
    IMPORTING
    own_logical_system = ls_reversal-obj_sys.

  • 调用 BAPI 函数,冲销会计凭证
    CALL FUNCTION ‘BAPI_ACC_DOCUMENT_REV_POST’
    EXPORTING
    reversal = ls_reversal
    bus_act = lv_bus_act
    IMPORTING

  •   OBJ_TYPE =
      obj_key  = lv_obj_key
    
  •   OBJ_SYS  =
    TABLES
      return   = lt_return.
    

    IF lv_obj_key IS NOT INITIAL AND lv_obj_key NE ‘$’.
    CLEAR: wa_ztco003.
    wa_ztco003-rbukrs = ls_belnr-rbukrs.
    wa_ztco003-belnr = ls_belnr-belnr.
    wa_ztco003-gjahr = ls_belnr-gjahr.
    wa_ztco003-r_belnr = lv_obj_key(10).
    wa_ztco003-r_rbukrs = lv_obj_key+10(4).
    wa_ztco003-r_gjahr = lv_obj_key+14(4).
    INSERT ztco003 FROM wa_ztco003.

    CLEAR: wa_out-rbukrs, wa_out-belnr, wa_out-gjahr.
    UPDATE ztco002 SET rbukrs = wa_out-rbukrs
                       belnr = wa_out-belnr
                       gjahr = wa_out-gjahr
                       WHERE rbukrs = ls_belnr-rbukrs
                         AND belnr = ls_belnr-belnr
                         AND gjahr = ls_belnr-gjahr.
    
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.
    
    wa_out-stat = icon_green_light.
    wa_out-mess = '冲销成功'.
    
    MODIFY gt_out FROM wa_out TRANSPORTING stat mess rbukrs belnr gjahr
      WHERE rbukrs = ls_belnr-rbukrs
        AND belnr = ls_belnr-belnr
        AND gjahr = ls_belnr-gjahr.
    

    ELSE.
    CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’.

    wa_out-stat = icon_red_light.
    LOOP AT lt_return INTO ls_return.
      wa_out-mess = wa_out-mess && ls_return-message && ';'.
    ENDLOOP.
    MODIFY gt_out FROM wa_out TRANSPORTING stat mess
      WHERE rbukrs = ls_belnr-rbukrs
        AND belnr = ls_belnr-belnr
        AND gjahr = ls_belnr-gjahr.
    

    ENDIF.

    ENDLOOP.
    ENDFORM.
    &---------------------------------------------------------------------
    *& Form frm_check_document
    &---------------------------------------------------------------------
    *& text
    &---------------------------------------------------------------------
    *& <-- LV_SUBRC
    &---------------------------------------------------------------------
    FORM frm_check_document CHANGING pv_subrc.
    DATA: l_dmbtr TYPE dmbtr,
    l_sgtxt TYPE sgtxt,
    l_objnr TYPE j_objnr,
    l_field TYPE char30,
    l_errflg TYPE char1,
    l_date TYPE sy-datum,
    l_waers TYPE t001-waers,
    l_lines TYPE i,
    l_tabix TYPE sy-tabix.
    DATA: lt_out TYPE TABLE OF ty_out, "用于校验COSP成本中心实际发生额
    lt_out2 TYPE TABLE OF ty_out, "用于生成凭证
    ls_out TYPE ty_out.
    FIELD-SYMBOLS: .
    RANGES: "r_aufnr FOR coas-aufnr,
    r_auart FOR coas-auart.

  •      r_objnr FOR cosp-objnr.
    

    pv_subrc = 4.

    r_auart[] = VALUE #(
    ( sign = ‘I’ option = ‘EQ’ low = ‘1101’ )
    ( sign = ‘I’ option = ‘EQ’ low = ‘1201’ )
    ( sign = ‘I’ option = ‘EQ’ low = ‘1301’ )
    ( sign = ‘I’ option = ‘EQ’ low = ‘1401’ )
    ( sign = ‘I’ option = ‘EQ’ low = ‘1501’ )
    ( sign = ‘I’ option = ‘EQ’ low = ‘1601’ )
    ( sign = ‘I’ option = ‘EQ’ low = ‘1701’ )
    ( sign = ‘I’ option = ‘EQ’ low = ‘1711’ )
    ).

    REFRESH: lt_out.
    LOOP AT gt_out INTO wa_out where belnr is INITIAL.
    CLEAR: ls_out.
    ls_out-cjahr = wa_out-cjahr.
    ls_out-monat = wa_out-monat.
    ls_out-bukrs = wa_out-bukrs.
    ls_out-skostl = wa_out-skostl.
    ls_out-zzgxc = wa_out-zzgxc.
    ls_out-zlwcb = wa_out-zlwcb.
    ls_out-zolda = wa_out-zolda.
    ls_out-zmedi = wa_out-zmedi.
    ls_out-zemij = wa_out-zemij.
    ls_out-zmate = wa_out-zmate.
    ls_out-zunem = wa_out-zunem.
    ls_out-zgjj = wa_out-zgjj.
    ls_out-zfwf = wa_out-zfwf.
    COLLECT ls_out INTO lt_out.

    ls_out-rkostl = wa_out-rkostl.
    ls_out-aufnr = wa_out-aufnr.
    ls_out-auart = wa_out-auart.
    ls_out-zprono = wa_out-zprono.
    ls_out-rbukrs = wa_out-rbukrs.
    ls_out-gjahr = wa_out-gjahr.
    ls_out-belnr = wa_out-belnr.
    COLLECT ls_out INTO lt_out2.

  • IF wa_out-aufnr IS NOT INITIAL AND wa_out-auart IN r_auart[].

  •  CLEAR: r_aufnr.
    
  •  r_aufnr(3) = 'IEQ'.
    
  •  r_aufnr-low = wa_out-aufnr.
    
  •  COLLECT r_aufnr.
    
  •  CLEAR: r_objnr.
    
  •  r_objnr(3) = 'IEQ'.
    
  •  r_objnr-low = 'OR' && wa_out-aufnr.
    
  •  COLLECT r_objnr.
    
  • ENDIF.

  • IF wa_out-belnr IS NOT INITIAL.

  •  l_errflg = 'X'.
    
  •  MESSAGE '请先冲销旧凭证' TYPE 'W'.
    
  •  EXIT.
    
  • ENDIF.
    ENDLOOP.

  • CHECK l_errflg = ‘’."无错误才创建凭证

  • REFRESH: gt_ztco007.

  • SELECT * FROM ztco007 INTO TABLE gt_ztco007

  • FOR ALL ENTRIES IN lt_out2

  • WHERE aufnr = lt_out2-aufnr

  •  AND ( zyear < p_gjahr OR ( zyear = p_gjahr AND zmon <= p_monat ) ).
    
  • SORT gt_ztco007 BY aufnr.

  • IF r_aufnr[] IS NOT INITIAL.

  • SELECT a~aufnr, SUM( 0 - a~hsl ) AS hsl

  •  FROM acdoca AS a
    
  •  JOIN coas AS b ON a~aufnr = b~aufnr
    
  •  INTO TABLE @DATA(lt_lk)
    
  •  WHERE a~rbukrs = @p_bukrs
    
  •    AND ( a~gjahr < @p_gjahr OR ( a~gjahr = @p_gjahr AND a~poper <= @p_monat ) )
    
  •    AND a~aufnr IN @r_aufnr
    
  •    AND a~racct EQ '2401000000'
    
  •    AND a~gkont NE '6302010000'
    
  •    AND a~zzzjly IN ( '02', '03', '04', '05', '06' )
    
  •  GROUP BY a~aufnr.
    
  • SORT lt_lk BY aufnr.

  • ENDIF.

  • IF r_objnr[] IS NOT INITIAL.

  • SELECT objnr, SUM( wtg001 ) AS wtg001, SUM( wtg002 ) AS wtg002, SUM( wtg003 ) AS wtg003, SUM( wtg004 ) AS wtg004,

  •        SUM( wtg005 ) AS wtg005, SUM( wtg006 ) AS wtg006, SUM( wtg007 ) AS wtg007, SUM( wtg008 ) AS wtg008,
    
  •        SUM( wtg009 ) AS wtg009, SUM( wtg010 ) AS wtg010, SUM( wtg011 ) AS wtg011, SUM( wtg012 + wtg013 + wtg014 + wtg015 + wtg016 ) AS wtg012
    
  •    FROM cosp
    
  •    INTO TABLE @DATA(lt_yylk)
    
  •    WHERE objnr = @r_objnr
    
  •      AND gjahr <= @p_gjahr
    
  •      AND wrttp = '04'
    
  •      AND versn = '000'
    
  •    GROUP BY objnr.
    
  • SORT lt_yylk BY objnr.

  • ENDIF.

  • LOOP AT lt_lk INTO DATA(ls_lk).

  • CLEAR: l_objnr.

  • l_objnr = ‘OR’ && ls_lk-aufnr.

  • READ TABLE lt_yylk INTO DATA(ls_yylk) WITH KEY objnr = l_objnr BINARY SEARCH.

  • IF sy-subrc = 0.

  •  DO p_monat TIMES VARYING lv_value FROM ls_yylk-wtg001 NEXT ls_yylk-wtg002.
    
  •    ls_lk-hsl = ls_lk-hsl - lv_value.
    
  •  ENDDO.
    
  •  MODIFY lt_lk FROM ls_lk.
    
  • ENDIF.

  • ENDLOOP.

  • DELETE lt_lk WHERE hsl <= 0.
    "2022/03/10客户要求取消校验逻辑

  • "4、金额按科目分,总额小于等于成本中心对应的科目当月发生额;

  • "5、校验的表是COSP,比如:KS+8000+成本中心=对象号(COSP-OBJNR),COSP-GJAHR=分摊年度,COSP-WRTTP=‘ 04’,

  • "VERSN=‘0’KSTAR=对应科目,如:6601000001,然后取WTG001~WTG016,16个对应16个期间,进行汇总;

  • LOOP AT lt_out INTO ls_out.

  • l_objnr = ‘KS8000’ && ls_out-skostl.

  • SELECT kstar, SUM( wtg001 ) AS wtg001, SUM( wtg002 ) AS wtg002, SUM( wtg003 ) AS wtg003, SUM( wtg004 ) AS wtg004,

  •      SUM( wtg005 ) AS wtg005, SUM( wtg006 ) AS wtg006, SUM( wtg007 ) AS wtg007, SUM( wtg008 ) AS wtg008,
    
  •      SUM( wtg009 ) AS wtg009, SUM( wtg010 ) AS wtg010, SUM( wtg011 ) AS wtg011, SUM( wtg012 + wtg013 + wtg014 + wtg015 + wtg016 ) AS wtg012
    
  •  FROM cosp
    
  •  INTO TABLE @DATA(lt_cosp)
    
  •  WHERE objnr = @l_objnr
    
  •    AND gjahr = @p_gjahr
    
  •    AND wrttp = '04'
    
  •    AND versn = '000'
    
  •    AND kstar IN ( @c_zgxc_hkont, @c_lwcb_hkont, @c_olda_hkont, @c_medi_hkont, @c_emij_hkont, @c_mate_hkont, @c_unem_hkont, @c_gjj_hkont )
    
  •  GROUP BY kstar.
    
  • LOOP AT lt_cosp INTO DATA(ls_cosp).

  •  l_field = 'WTG0' && p_monat.
    
  •  ASSIGN COMPONENT l_field OF STRUCTURE ls_cosp TO .
    
  •  CASE ls_cosp-kstar.
    
  •    WHEN c_zgxc_hkont.
    
  •      IF ls_out-zzgxc > .
    
  •        wa_out-stat = icon_red_light.
    
  •        wa_out-mess = wa_out-mess && '职工薪酬总额大于成本中心对应科目当月发生额;'.
    
  •        l_errflg = 'X'.
    
  •      ENDIF.
    
  •    WHEN c_lwcb_hkont.
    
  •      IF ls_out-zlwcb > .
    
  •        wa_out-stat = icon_red_light.
    
  •        wa_out-mess = wa_out-mess && '劳务成本总额大于成本中心对应科目当月发生额;'.
    
  •        l_errflg = 'X'.
    
  •      ENDIF.
    
  •    WHEN c_olda_hkont.
    
  •      IF ls_out-zolda > .
    
  •        wa_out-stat = icon_red_light.
    
  •        wa_out-mess = wa_out-mess && '社保-养老总额大于成本中心对应科目当月发生额;'.
    
  •        l_errflg = 'X'.
    
  •      ENDIF.
    
  •    WHEN c_medi_hkont.
    
  •      IF ls_out-zmedi > .
    
  •        wa_out-stat = icon_red_light.
    
  •        wa_out-mess = wa_out-mess && '社保-医疗总额大于成本中心对应科目当月发生额;'.
    
  •        l_errflg = 'X'.
    
  •      ENDIF.
    
  •    WHEN c_emij_hkont.
    
  •      IF ls_out-zemij > .
    
  •        wa_out-stat = icon_red_light.
    
  •        wa_out-mess = wa_out-mess && '社保-工伤总额大于成本中心对应科目当月发生额;'.
    
  •        l_errflg = 'X'.
    
  •      ENDIF.
    
  •    WHEN c_mate_hkont.
    
  •      IF ls_out-zmate > .
    
  •        wa_out-stat = icon_red_light.
    
  •        wa_out-mess = wa_out-mess && '社保-生育总额大于成本中心对应科目当月发生额;'.
    
  •        l_errflg = 'X'.
    
  •      ENDIF.
    
  •    WHEN c_unem_hkont.
    
  •      IF ls_out-zunem > .
    
  •        wa_out-stat = icon_red_light.
    
  •        wa_out-mess = wa_out-mess && '社保-失业总额大于成本中心对应科目当月发生额;'.
    
  •        l_errflg = 'X'.
    
  •      ENDIF.
    
  •    WHEN c_gjj_hkont.
    
  •      IF ls_out-zgjj > .
    
  •        wa_out-stat = icon_red_light.
    
  •        wa_out-mess = wa_out-mess && '公积金总额大于成本中心对应科目当月发生额;'.
    
  •        l_errflg = 'X'.
    
  •      ENDIF.
    
  •  ENDCASE.
    
  •  UNASSIGN .
    
  • ENDLOOP.

  • REFRESH:lt_cosp.

  • MODIFY gt_out FROM wa_out TRANSPORTING stat mess WHERE skostl = ls_out-skostl.

  • ENDLOOP.

CHECK l_errflg = ‘’."无错误才创建凭证

CLEAR: gv_posnr.
REFRESH : gt_accountgl,gt_accountreceivable,gt_accountpayable,gt_currencyamount,gt_return,gt_extension2,gt_criteria.
CLEAR : gw_documentheader.

DESCRIBE TABLE lt_out2 LINES l_lines.

SELECT SINGLE waers FROM t001 INTO l_waers WHERE bukrs = p_bukrs.
LOOP AT lt_out2 INTO wa_out.
l_tabix = sy-tabix.

wa_out-belnr = '$1'.
MODIFY lt_out2 FROM wa_out.
IF wa_out-aufnr IS NOT INITIAL.
  l_sgtxt = |{ p_gjahr }年{ p_monat }月份从{ wa_out-skostl }成本中心人工转入内部订单|.
  "科目进行更换,具体如下表:内部订单类型1101,1201,1301,1401,1501,1601,1701,1711,都计入自筹对应的科目,即5301010*,不计入专项科目;
  "其他内部订单类型,都计入6601*对应的科目;
  IF wa_out-auart IN r_auart[].
    g_zgxc_hkont = c_zgxc_hkont_zc.
    g_lwcb_hkont = c_lwcb_hkont_zc.
    g_gjj_hkont = c_gjj_hkont_zc.
    g_olda_hkont = c_olda_hkont_zc.
    g_medi_hkont = c_medi_hkont_zc.
    g_emij_hkont = c_emij_hkont_zc.
    g_mate_hkont = c_mate_hkont_zc.
    g_unem_hkont = c_unem_hkont_zc.
    g_fwf_hkont = c_fwf_hkont_zc.
  ELSE.
    g_zgxc_hkont = c_zgxc_hkont.
    g_lwcb_hkont = c_lwcb_hkont.
    g_gjj_hkont = c_gjj_hkont.
    g_olda_hkont = c_olda_hkont.
    g_medi_hkont = c_medi_hkont.
    g_emij_hkont = c_emij_hkont.
    g_mate_hkont = c_mate_hkont.
    g_unem_hkont = c_unem_hkont.
    g_fwf_hkont = c_fwf_hkont.
  ENDIF.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  l_sgtxt = |{ p_gjahr }年{ p_monat }月份从{ wa_out-skostl }成本中心人工转入{ wa_out-rkostl }成本中心|.

  g_zgxc_hkont = c_zgxc_hkont.
  g_lwcb_hkont = c_lwcb_hkont.
  g_gjj_hkont = c_gjj_hkont.
  g_olda_hkont = c_olda_hkont.
  g_medi_hkont = c_medi_hkont.
  g_emij_hkont = c_emij_hkont.
  g_mate_hkont = c_mate_hkont.
  g_unem_hkont = c_unem_hkont.
  g_fwf_hkont = c_fwf_hkont.
ENDIF.

"总账
"职工薪酬
l_dmbtr = wa_out-zzgxc * -1.
IF wa_out-aufnr IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_zgxc_hkont  ''  wa_out-zprono l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zzgxc g_zgxc_hkont  wa_out-aufnr  wa_out-zprono  l_sgtxt l_waers ''.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_zgxc_hkont  ''  '' l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zzgxc g_zgxc_hkont  ''   ''  l_sgtxt l_waers wa_out-rkostl.
ENDIF.

"劳务成本
l_dmbtr = wa_out-zlwcb * -1.
IF wa_out-aufnr IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_lwcb_hkont  ''  wa_out-zprono l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zlwcb g_lwcb_hkont  wa_out-aufnr  wa_out-zprono  l_sgtxt l_waers ''.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_lwcb_hkont  ''  '' l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zlwcb g_lwcb_hkont  ''   ''  l_sgtxt l_waers wa_out-rkostl.
ENDIF.

"公积金
l_dmbtr = wa_out-zgjj * -1.
IF wa_out-aufnr IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_gjj_hkont  ''  wa_out-zprono l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zgjj g_gjj_hkont  wa_out-aufnr  wa_out-zprono  l_sgtxt l_waers ''.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_gjj_hkont  ''  '' l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zgjj g_gjj_hkont  ''   ''  l_sgtxt l_waers wa_out-rkostl.
ENDIF.

"社保-养老
l_dmbtr = wa_out-zolda * -1.
IF wa_out-aufnr IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_olda_hkont  ''  wa_out-zprono l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zolda g_olda_hkont  wa_out-aufnr  wa_out-zprono  l_sgtxt l_waers ''.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_olda_hkont  ''  '' l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zolda g_olda_hkont  ''   ''  l_sgtxt l_waers wa_out-rkostl.
ENDIF.

"社保-医疗
l_dmbtr = wa_out-zmedi * -1.
IF wa_out-aufnr IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_medi_hkont  ''  wa_out-zprono l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zmedi g_medi_hkont  wa_out-aufnr  wa_out-zprono  l_sgtxt l_waers ''.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_medi_hkont  ''  '' l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zmedi g_medi_hkont  ''   ''  l_sgtxt l_waers wa_out-rkostl.
ENDIF.

"社保-工伤
l_dmbtr = wa_out-zemij * -1.
IF wa_out-aufnr IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_emij_hkont  ''  wa_out-zprono l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zemij g_emij_hkont  wa_out-aufnr  wa_out-zprono  l_sgtxt l_waers ''.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_emij_hkont  ''  '' l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zemij g_emij_hkont  ''   ''  l_sgtxt l_waers wa_out-rkostl.
ENDIF.

"社保-生育
l_dmbtr = wa_out-zmate * -1.
IF wa_out-aufnr IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_mate_hkont  ''  wa_out-zprono l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zmate g_mate_hkont  wa_out-aufnr  wa_out-zprono  l_sgtxt l_waers ''.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_mate_hkont  ''  '' l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zmate g_mate_hkont  ''   ''  l_sgtxt l_waers wa_out-rkostl.
ENDIF.

"社保-失业
l_dmbtr = wa_out-zunem * -1.
IF wa_out-aufnr IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_unem_hkont  ''  wa_out-zprono l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zunem g_unem_hkont  wa_out-aufnr  wa_out-zprono  l_sgtxt l_waers ''.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_unem_hkont  ''  '' l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zunem g_unem_hkont  ''   ''  l_sgtxt l_waers wa_out-rkostl.
ENDIF.

"社保-失业
l_dmbtr = wa_out-zfwf * -1.
IF wa_out-aufnr IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_fwf_hkont  ''  wa_out-zprono l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zfwf g_fwf_hkont  wa_out-aufnr  wa_out-zprono  l_sgtxt l_waers ''.
ELSEIF wa_out-rkostl IS NOT INITIAL.
  PERFORM frm_hkont_item USING l_dmbtr c_fwf_hkont  ''  '' l_sgtxt l_waers wa_out-skostl.
  PERFORM frm_hkont_item USING wa_out-zfwf g_fwf_hkont  ''   ''  l_sgtxt l_waers wa_out-rkostl.
ENDIF.

"生成会计凭证
IF gv_posnr >=  '980' OR l_tabix = l_lines."每行alv8个科目工12行,留足行项目,避免中间超过999
  l_date = p_gjahr && p_monat && '01'.
  CALL FUNCTION 'FIMA_DATE_CREATE'
    EXPORTING
      i_date                  = l_date
      i_set_last_day_of_month = 'X'
    IMPORTING
      e_date                  = l_date.

  "抬头数据
  CLEAR gw_documentheader.
  gw_documentheader-comp_code = wa_out-bukrs.   "公司代码

  gw_documentheader-doc_date = sy-datum.    "凭证日期

  gw_documentheader-pstng_date = l_date.  "过账日期

  gw_documentheader-doc_type = 'Z7'.    "凭证类型

  gw_documentheader-header_txt = |{ p_gjahr }年{ p_monat }月份的人工费用|.  "凭证抬头文本

  gw_documentheader-fisc_year = p_gjahr.  "会计年度

  gw_documentheader-fis_period = p_monat.  "期间

  gw_documentheader-username = sy-uname.


  CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
    EXPORTING
      documentheader    = gw_documentheader
  •     CUSTOMERCPD       =
    
  •     CONTRACTHEADER    =
    
  •    IMPORTING
    
  •     OBJ_TYPE          =
    
  •     OBJ_KEY           = LV_OBJKEY
    
  •     OBJ_SYS           =
      TABLES
        accountgl         = gt_accountgl[]
        accountreceivable = gt_accountreceivable[]
        accountpayable    = gt_accountpayable[]
    
  •     ACCOUNTTAX        =
        currencyamount    = gt_currencyamount[]
    
  •     criteria          = gt_criteria[]
    
  •     VALUEFIELD        =
    
  •     EXTENSION1        =
        return            = gt_return[]
    
  •     PAYMENTCARD       =
    
  •     CONTRACTITEM      =
        extension2        = gt_extension2[]
    
  •     REALESTATE        =
    
  •     ACCOUNTWT         =
      .
    LOOP AT gt_return WHERE type = 'E' OR type = 'A'.
    ENDLOOP.
    IF sy-subrc = 0.
      CLEAR: wa_out-belnr.
      wa_out-stat  = icon_red_light.
      READ TABLE gt_return INDEX 2.
      IF sy-subrc = 0.
        wa_out-mess  = gt_return-message.
      ELSE.
        wa_out-mess = '会计凭证创建失败'.
      ENDIF.
      LOOP AT lt_out2 INTO ls_out WHERE belnr = '$1'.
        ls_out-stat = wa_out-stat.
        ls_out-mess = wa_out-mess.
        ls_out-belnr = wa_out-belnr.
        MODIFY lt_out2 FROM ls_out.
        MODIFY gt_out FROM wa_out TRANSPORTING stat mess belnr
          WHERE skostl = ls_out-skostl
            AND rkostl = ls_out-rkostl
            AND aufnr = ls_out-aufnr
            AND zprono = ls_out-zprono and dypc = ls_out-dypc.
      ENDLOOP.
    
      l_errflg = 'X'.
    
      EXIT.
    ELSE.
    
      wa_out-belnr = '' .                         "凭证编号
      MODIFY lt_out2 FROM wa_out TRANSPORTING belnr WHERE belnr = '$1'.
    
    ENDIF.
    
    REFRESH : gt_accountgl,gt_accountreceivable,gt_accountpayable,gt_currencyamount,gt_return,gt_extension2,gt_criteria.
    CLEAR : gw_documentheader.
    CLEAR: gv_posnr.
    

    ENDIF.

    ENDLOOP.

    IF l_errflg = ‘’.
    pv_subrc = 0.
    ELSE.
    pv_subrc = 4.
    ENDIF.

ENDFORM.

你可能感兴趣的:(SAP-ABAP,sap)