BAPI:GL_ACCT_MASTER_SAVE
FORM frm_execute_fs00 USING uv_test TYPE c
CHANGING cs_out TYPE ty_s_out.
"GL_ACCT_MASTER_SAVE 创建总账科目
"前台事务代码:FS00
"函数功能描述
"创建、修改、删除总账科目,且可测试运行
DATA: ls_account_coa TYPE glaccount_coa,
ls_account_coa_keyy TYPE glaccount_coa_key,
ls_account_coa_data TYPE glaccount_coa_data,
ls_account_coa_info TYPE glaccount_coa_info,
lt_account_names TYPE glaccount_name_table,
ls_account_names TYPE glaccount_name,
ls_account_names_keyy TYPE glaccount_name_key,
ls_account_names_data TYPE glaccount_name_data,
lt_account_ccodes TYPE glaccount_ccode_table,
ls_account_ccodes TYPE glaccount_ccode,
ls_account_ccodes_keyy TYPE glaccount_ccode_key,
ls_account_ccodes_data TYPE glaccount_ccode_data,
ls_account_ccodes_info TYPE glaccount_ccode_info,
lt_account_careas TYPE glaccount_carea_table,
ls_account_careas TYPE glaccount_carea,
ls_glaccount_carea_key TYPE glaccount_carea_key,
ls_glaccount_carea_data TYPE glaccount_carea_data,
ls_glaccount_carea_info TYPE glaccount_carea_info,
ls_glaccount_carea_fromto TYPE glaccount_carea_fromto,
lt_return TYPE TABLE OF bapiret2 WITH HEADER LINE.
DATA: lv_msgtx TYPE bapi_msg,
lv_mtype TYPE bapi_mtype,
lv_no_save_at_warning TYPE xfeld.
"清空变量
REFRESH: lt_account_names,
lt_account_ccodes,
lt_account_careas,
lt_return.
CLEAR: ls_account_coa,
ls_account_names,
ls_account_names_keyy,
ls_account_names_data,
ls_account_ccodes,
ls_account_ccodes_keyy,
ls_account_ccodes_data,
ls_account_ccodes_info,
ls_account_careas,
ls_glaccount_carea_key,
ls_glaccount_carea_data,
ls_glaccount_carea_info,
ls_glaccount_carea_fromto,
lv_msgtx,
lv_mtype,
lv_no_save_at_warning.
--------------------------------------------------------------------
IF gv_action NE gc_action_d.
ls_account_coa_keyy-ktopl = gc_ktopl_th. "帐目表
ls_account_coa_keyy-saknr = cs_out-saknr. "总账科目
ls_account_coa_data-glaccount_type = cs_out-glaccount. "科目类型
ls_account_coa_data-ktoks = cs_out-ktoks. "总帐科目组
ls_account_coa_data-gvtyp = ‘X’. "损益报表科目类型
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
EXPORTING
input = cs_out-BILKT "组科目号
IMPORTING
OUTPUT = ls_account_coa_data-BILKT
.
ls_account_coa_info-erdat = sy-datum. "记录创建日期
ls_account_coa_info-ernam = sy-uname. "创建对象的人员名称
ls_account_coa_info-sakan = cs_out-saknr. "总账科目
ls_account_coa-action = gv_action. "数据记录活动:I/插入;U/修改;D/删除
ls_account_coa-keyy = ls_account_coa_keyy.
ls_account_coa-data = ls_account_coa_data.
ls_account_coa-info = ls_account_coa_info.
ENDIF.
--------------------------------------------------------------------
IF gv_action NE gc_action_d.
ls_account_names_keyy-ktopl = gc_ktopl_th. "帐目表
ls_account_names_keyy-saknr = cs_out-saknr. "总账科目
ls_account_names_keyy-spras = sy-langu. "语言代码
ls_account_names_data-txt20 = cs_out-txt20. "总帐科目名称
ls_account_names_data-txt50 = cs_out-txt50. "总账科目长文本
ls_account_names-action = gv_action. "数据记录活动:I/插入;U/修改;D/删除
ls_account_names-keyy = ls_account_names_keyy.
ls_account_names-data = ls_account_names_data.
APPEND ls_account_names TO lt_account_names.
ENDIF.
--------------------------------------------------------------------
ls_account_ccodes_keyy-bukrs = cs_out-bukrs. "公司代码
ls_account_ccodes_keyy-saknr = cs_out-saknr. "总账科目
ls_account_ccodes_data-waers = cs_out-waers. "货币
ls_account_ccodes_data-fstag = cs_out-fstag. "字段状态组
ls_account_ccodes_data-xsalh = cs_out-xsalh. "仅以本位币记帐
ls_account_ccodes_data-mwskz = cs_out-mwskz. "税务类型
ls_account_ccodes_data-xmwno = cs_out-xmwno. "允许不含税过账
ls_account_ccodes_data-mitkz = cs_out-mitkz. "统驭科目类型
ls_account_ccodes_data-xopvw = cs_out-xopvw. "未清项管理
ls_account_ccodes_data-zuawa = cs_out-zuawa. "排序码
ls_account_ccodes_data-xintb = cs_out-xintb. "只能自动过帐
ls_account_ccodes_data-xmitk = cs_out-xmitk. "统驭科目是否准备就绪可以输入
ls_account_ccodes_data-xgkon = cs_out-xgkon. "与现金流有关
ls_account_ccodes_info-erdat = sy-datum. "记录创建日期
ls_account_ccodes_info-ernam = sy-uname. "创建对象的人员名称
ls_account_ccodes-action = gv_action. "数据记录活动:I/插入;U/修改;D/删除
IF gv_action EQ gc_action_d.
ls_account_ccodes_data-xloeb = abap_true. "标识: 是否标记待删除科目?
ls_account_ccodes-action = gc_action_u. "会计科目标记删除,需要设置action为修改U
ENDIF.
ls_account_ccodes-keyy = ls_account_ccodes_keyy.
ls_account_ccodes-data = ls_account_ccodes_data.
ls_account_ccodes-info = ls_account_ccodes_info.
APPEND ls_account_ccodes TO lt_account_ccodes.
--------------------------------------------------------------------
IF NOT cs_out-katyp IS INITIAL AND gv_action NE gc_action_d.
ls_glaccount_carea_key-kokrs = gc_kokrs_th.
ls_glaccount_carea_key-saknr = cs_out-saknr. "总账科目
IF gv_action NE gc_action_d.
ls_glaccount_carea_data-katyp = cs_out-katyp. "成本要素类型
ls_glaccount_carea_info-ersda = sy-datum. "创建日期
ls_glaccount_carea_info-usnam = sy-uname. "输入者
ls_glaccount_carea_fromto-datab = '20210101'. "开始生效日期
ls_glaccount_carea_fromto-datbi = gc_datbi. "有效截至日期
ENDIF.
ls_account_careas-action = gv_action.
ls_account_careas-keyy = ls_glaccount_carea_key.
ls_account_careas-data = ls_glaccount_carea_data.
ls_account_careas-info = ls_glaccount_carea_info.
ls_account_careas-fromto = ls_glaccount_carea_fromto.
APPEND ls_account_careas TO lt_account_careas.
ENDIF.
CASE uv_test.
WHEN abap_true.
lv_no_save_at_warning = abap_true.
WHEN OTHERS.
ENDCASE.
CALL FUNCTION ‘GL_ACCT_MASTER_SAVE’
EXPORTING
testmode = uv_test
no_save_at_warning = lv_no_save_at_warning
TABLES
account_names = lt_account_names
account_ccodes = lt_account_ccodes
account_careas = lt_account_careas
return = lt_return
CHANGING
account_coa = ls_account_coa.
LOOP AT lt_return INTO DATA(ls_return) WHERE type CA ‘EAX’.
IF ls_return-id EQ 'FH' AND ls_return-number EQ '511'.
"数据包含错误, 您不能保存
CLEAR ls_return.
CONTINUE.
ENDIF.
MESSAGE ID ls_return-id
TYPE ls_return-type
NUMBER ls_return-number
WITH ls_return-message_v1
ls_return-message_v2
ls_return-message_v3
ls_return-message_v4
INTO DATA(lv_msgtx_single).
lv_msgtx_single = ls_return-type
&& '-'
&& ls_return-id
&& '-'
&& ls_return-number
&& '-'
&& lv_msgtx_single.
IF lv_msgtx IS INITIAL.
lv_msgtx = lv_msgtx_single.
ELSE.
lv_msgtx = lv_msgtx && '|' && lv_msgtx_single.
ENDIF.
CLEAR: ls_return,
lv_msgtx_single.
ENDLOOP.
IF sy-subrc = 0.
PERFORM frm_bapi_rollback.
lv_mtype = 'E'.
ELSE.
IF uv_test EQ abap_false.
PERFORM frm_bapi_commit USING abap_true.
ELSE.
cs_out-z_sel = abap_true.
ENDIF.
IF uv_test EQ abap_true.
"测试运行
READ TABLE lt_return INTO ls_return
WITH KEY type = 'S'
id = 'FH'
number = '510'.
IF sy-subrc EQ 0.
lv_mtype = 'W'.
lv_msgtx = ls_return-message.
CLEAR ls_return.
ELSE.
lv_mtype = 'W'.
LOOP AT lt_return INTO ls_return.
IF lv_msgtx IS INITIAL.
lv_msgtx = ls_return-message.
ELSE.
lv_msgtx = lv_msgtx && '|' && ls_return-message.
ENDIF.
CLEAR ls_return.
ENDLOOP.
ENDIF.
ELSE.
"正式运行
READ TABLE lt_return INTO ls_return
WITH KEY type = 'S'
id = 'FH'
number = '512'.
IF sy-subrc EQ 0.
lv_mtype = 'S'.
lv_msgtx = ls_return-message.
CLEAR ls_return.
ELSE.
lv_mtype = 'S'.
LOOP AT lt_return INTO ls_return.
IF lv_msgtx IS INITIAL.
lv_msgtx = ls_return-message.
ELSE.
lv_msgtx = lv_msgtx && '|' && ls_return-message.
ENDIF.
CLEAR ls_return.
ENDLOOP.
ENDIF.
DO 500 TIMES.
SELECT bukrs,
saknr,
xloeb
INTO TABLE @DATA(lt_skb1)
FROM skb1
WHERE bukrs EQ @cs_out-bukrs
AND saknr EQ @cs_out-saknr.
IF sy-subrc EQ 0.
DATA(lv_flg_get) = abap_true.
EXIT.
ELSE.
WAIT UP TO '0.001' SECONDS.
ENDIF.
ENDDO.
IF lv_flg_get EQ abap_false.
"后台表查找不到科目,则报错
lv_mtype = 'E'.
lv_msgtx = TEXT-017.
ELSEIF gv_action EQ gc_action_d.
READ TABLE lt_skb1 INTO DATA(ls_skb1) INDEX 1.
IF sy-subrc EQ 0.
IF ls_skb1-xloeb EQ abap_false.
lv_mtype = 'E'.
lv_msgtx = TEXT-018.
ENDIF.
CLEAR ls_skb1.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
cs_out-mtype = lv_mtype.
cs_out-msgtx = lv_msgtx.
ENDFORM.