其实BDC与LSMW类似,不过好处是BDC在开发的加工下,可能更方便些;
LTMC是S4提供的最新的迁移控制台,但是限制有些多。
在S4里面,字段是有些变化的。
表1:SKA1
总账科目主记录
科目表层数据,多了两列,分别是总账科目类型和总账科目子类型
表2:SKAT
在SAP系统中,每一个总账科目(G/L Account)都有两个层次,首先必须在chart of accounts level维护共有的信息,然后再在company code level维护公司代码独有的信息。
公司代码所用的科目表叫operating chart of accounts(运营科目表)。一般在项目实施完了之后,会用批处理工具把所有的会计科目导入到SAP系统中。
①FS00–集中维护会计科目,同一个科目必须在科目表层和公司代码层下都做维护。
②FSP0–在科目表层维护会计科目;
③FSS0–在公司代码层维护会计科目;
备注:查询以1开头的科目:用“1*”搜索;
总账科目类型 X:资产负债表科目;N:营业外收支;P:初级成本或收入;S:次级成本
如果科目货币设为本位币以外的其他货币,则该科目只能用该货币过账;
如果科目货币设为本位币,则该科目可用任何货币过账。
比如:如果本位币是CNY,有一个“现金-USD”科目,则能限制“现金-USD”科目只能输入USD。
比如:如果本位币是CNY,有一个“现金-CNY”科目,则不能限制“现金-CNY”科目只能输入CNY。
本项勾上后,科目余额将不能以其他货币显示,只能以本位币显示。
SAP系统中有一个特殊科目GR/IR,必须设为only balances in local currency,否则在过账时,系统会提示编号为F5672的错误。
对于一般纳税人来说:
采购–进项税;
销售–销项税;
如:销售商品(17%的税率)
(商品出库) 借:主营业务成本 100元 贷:库存商品 100元
(开发票) 借:应收账款 117元 贷:主营业务收入 100元
应交税金-应交增值税-销项税 17元
(收款) 借:银行存款 117 贷:应收账款 117元
也就是说:对于会计科目“主营业务收入”,一般在这里设为“仅允许销项税”。
本项勾上之后,就表示此会计科目含不含税都可以过账。
举例:公司卖给客户(三菱公司)300万元的商品,需要销售(SD)那边来记账(开发票),但是,销售人员在记账时不会像财务人员那样记:
GL:
销售人员只会记:
SD:
在实际的SAP系统中,销售那边一记账,系统就会自动在财务这边生成一笔凭证,为什么自动生成呢?
就是因为,我们把科目“应收账款”设为了客户“三菱公司”的统驭科目。设为统驭科目的会计科目就不能在手工记账了,只能通过其他的模块(如:AR、AP、SD、MM)自动记账。而这里的这个字段,是让我们选择这个科目属于什么类型的统驭科目的(是属于客户?属于供应商?属于资产?……)。
设置一个统驭科目的步骤:
1.新建一个科目(如:应收账款或应付账款),并指定它的“统驭科目类型”为“客户或供应商或资产……”
2.在创建客户或供应商主数据时,在其“统驭科目”字段中选择刚才新建的那个会计科目;这样,以后对这个客户或供应商进行记账的话,从AP、AP、SD或MM那边记“客户或供应商”的同时,也会自动在GL中记一笔,并记在“应收账款或应付账款”上。
成本要素类别 1是初级
后台设置路径:财务会计—财务会计全局设置—凭证—行项目—控制—定义字段状态变式(T-code:OBC4),它用来控制在做凭证时(记账界面、录入凭证的界面),该科目的辅助核算项目哪些是必输的,哪些是隐藏的,哪些是可选的;
勾上之后,此会计科目就只能自动记账,不能在GL模块中进行手工记账,即只能通过其他模块传递过来自动生成记账凭证(如:AR、AP、MM、SD);
以建成本要素5001050010生产成本-技术成本-工资为例
录制内容如下:
形成源代码如下:
定义部分:
data: begin of record,
* data element: SAKNR
SAKNR_001(010), "总账科目
* data element: BUKRS
BUKRS_002(004), "公司代码
* data element: GLACCOUNT_TYPE
GLACCOUNT_TYPE_003(001),"总账科目类型 X:资产负债表科目;N:营业外收支;P:初级成本或收入;S:次级成本
* data element: GLACCOUNT_TYPE
GLACCOUNT_TYPE_004(001),"总账科目类型 X:资产负债表科目;N:营业外收支;P:初级成本或收入;S:次级成本
* data element: KTOKS
KTOKS_005(004)," 科目组:ABST:非资产统御类科目;FIN:货币资金类;ERR:损益类MAT:物料管理类SAKO:一般总账类ANL:资产统驭类
* data element: GLACCOUNT_TYPE
GLACCOUNT_TYPE_006(001),"总账科目类型 X:资产负债表科目;N:营业外收支;P:初级成本或收入;S:次级成本
* data element: KTOKS
KTOKS_007(004)," 科目组:ABST:非资产统御类科目;FIN:货币资金类;ERR:损益类MAT:物料管理类SAKO:一般总账类ANL:资产统驭类
* data element: TXT20_SKAT
TXT20_ML_008(020), "科目短文本
* data element: TXT50_SKAT
TXT50_ML_009(050), "科目长文本
* data element: WAERS_SKB1
WAERS_010(005),"科目货币
* data element: XSALH
XSALH_011(001),"限本位币记余额 选择X
* data element: SMWSK
MWSKZ_012(002)," 税务类型
* data element: XMWNO
XMWNO_013(001)," 允许含/不含税过帐
* data element: MITKZ
MITKZ_014(001),"统驭科目的科目类型
* data element: DZUAWA
ZUAWA_015(003)," 排序码
* data element: KATYP
KATYP_016(002),"
* data element: FSTAG
FSTAG_017(004)," 成本要素类别 1是初级
* data element: XINTB
XINTB_018(001),"字段状态组
XINTB(1),"只能自动过账
end of record.
循环调用部分:
do.
read dataset dataset into record.
if sy-subrc <> 0. exit. endif.
perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
perform bdc_field using 'BDC_OKCODE'
'=ACC_CRE'.
perform bdc_field using 'BDC_CURSOR'
'GLACCOUNT_SCREEN_KEY-SAKNR'.
perform bdc_field using 'GLACCOUNT_SCREEN_KEY-SAKNR'
record-SAKNR_001.
perform bdc_field using 'GLACCOUNT_SCREEN_KEY-BUKRS'
record-BUKRS_002.
perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
perform bdc_field using 'BDC_OKCODE'
'=GLACC_TYPE'.
perform bdc_field using 'BDC_CURSOR'
'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'.
perform bdc_field using 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'
record-GLACCOUNT_TYPE_003.
perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
perform bdc_field using 'BDC_OKCODE'
'=2102_GROUP'.
perform bdc_field using 'BDC_CURSOR'
'GLACCOUNT_SCREEN_COA-KTOKS'.
perform bdc_field using 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'
record-GLACCOUNT_TYPE_004.
perform bdc_field using 'GLACCOUNT_SCREEN_COA-KTOKS'
record-KTOKS_005.
perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
perform bdc_field using 'BDC_OKCODE'
'=TAB02'.
perform bdc_field using 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'
record-GLACCOUNT_TYPE_006.
perform bdc_field using 'GLACCOUNT_SCREEN_COA-KTOKS'
record-KTOKS_007.
perform bdc_field using 'BDC_CURSOR'
'GLACCOUNT_SCREEN_COA-TXT50_ML'.
perform bdc_field using 'GLACCOUNT_SCREEN_COA-TXT20_ML'
record-TXT20_ML_008.
perform bdc_field using 'GLACCOUNT_SCREEN_COA-TXT50_ML'
record-TXT50_ML_009.
perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
perform bdc_field using 'BDC_OKCODE'
'=TAB03'.
perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-WAERS'
record-WAERS_010.
perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-XSALH'
record-XSALH_011.
perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-MWSKZ'
record-MWSKZ_012.
perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-XMWNO'
record-XMWNO_013.
perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-MITKZ'
record-MITKZ_014.
perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-ZUAWA'
record-ZUAWA_015.
perform bdc_field using 'BDC_CURSOR'
'GLACCOUNT_SCREEN_CAREA-KATYP'.
perform bdc_field using 'GLACCOUNT_SCREEN_CAREA-KATYP'
record-KATYP_016.
perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
perform bdc_field using 'BDC_OKCODE'
'=SAVE'.
perform bdc_field using 'BDC_CURSOR'
'GLACCOUNT_SCREEN_CCODE-XINTB'.
perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-FSTAG'
record-FSTAG_017.
perform bdc_field using 'GLACCOUNT_SCREEN_CCODE-XINTB'
record-XINTB_018.
perform bdc_transaction using 'FS00'.
enddo.
*&---------------------------------------------------------------------*
*& Report ZLGZBDCFS00IMP
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zlgzbdcfs00imp NO STANDARD PAGE HEADING LINE-SIZE 255.
* For ALV display
TYPE-POOLS: slis.
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gs_layout TYPE slis_layout_alv.
* 处理Tab分割符
TABLES:
ska1, skb1, skat.
* 定义全局日志信息,用来存储正常日志+错误日志
DATA: BEGIN OF gt_log OCCURS 0,
saknr(010), " G/L account number
type(1), " messange type
txt100(100), " message text
END OF gt_log.
*1 第一步,定义对象
TYPE-POOLS: truxs.
TYPES: BEGIN OF ty_datas,
saknr(010), "总账科目
bukrs(004), "公司代码
glaccount_type(001),"总账科目类型 X:资产负债表科目;N:营业外收支;P:初级成本或收入;S:次级成本
ktoks(004)," 科目组:ABST:非资产统御类科目;FIN:货币资金类;ERR:损益类MAT:物料管理类SAKO:一般总账类ANL:资产统驭类
txt20_ml(020), "科目短文本
txt50_ml(050), "科目长文本
waers(005),"科目货币
xsalh(001),"限本位币记余额 选择X
mwskz(002)," 税务类型
xmwno(001)," 允许含/不含税过帐
mitkz(001),"统驭科目的科目类型
zuawa(003)," 排序码
katyp(002),"成本要素类别 1是初级
fstag(004)," 字段状态组
xintb(001),"只能自动过账
END OF ty_datas.
"定义EXCEL的数据存储对象
DATA: gt_data TYPE TABLE OF ty_datas,
record TYPE ty_datas.
"BDC的数据对象
DATA: gt_bdcdata TYPE TABLE OF bdcdata WITH HEADER LINE.
"BDC的数据对象
DATA: bdcdata TYPE TABLE OF bdcdata WITH HEADER LINE.
*2 第二步,定义文件选择参数,并选择文件
*----------------------------------------------------------------------*
* 定义默认框架、选择文件、选择后 *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK lgz1 WITH FRAME TITLE text01.
* Parameter for file name
PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY DEFAULT 'E:\测试科目导入.xlsx'.
SELECTION-SCREEN END OF BLOCK lgz1.
SELECTION-SCREEN BEGIN OF BLOCK lgz2 WITH FRAME TITLE text02.
* Parameters for update mode
PARAMETERS: mode_a RADIOBUTTON GROUP rad TYPE c, " 前台更新
mode_n RADIOBUTTON GROUP rad TYPE c, " 后台更新
moed_e RADIOBUTTON GROUP rad TYPE c. " 仅显示错误模式
SELECTION-SCREEN END OF BLOCK lgz2.
INITIALIZATION.
text01 = '选择导入文件'.
text02 = '选择更新模式'.
"选择调用文件
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM frm_get_filename.
*3 第三步,获取文件数据
START-OF-SELECTION.
PERFORM frm_get_data.
PERFORM check_data.
END-OF-SELECTION.
*4 第四步,调用BDC录入数据
* " 调用方法一 By Transaction
IF gt_log[] IS INITIAL.
PERFORM frm_exec_transaction.
PERFORM alv_show.
ELSE.
PERFORM alv_show.
ENDIF.
" 调用方法二 By Session(把多个Transaction放到一个Session一起执行)
"PERFORM FRM_EXEC_SESSION.
**------------------------------------------FROM------------------------------------------**
"2.1调用文件的标准程序form
FORM frm_get_filename .
"调用文件的标准程序
DATA: lv_rc TYPE i.
DATA: lt_file_table TYPE filetable.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = '打开文件'
CHANGING
file_table = lt_file_table
rc = lv_rc.
IF sy-subrc = 0.
READ TABLE lt_file_table INTO DATA(wa_file_table) INDEX 1.
p_file = wa_file_table-filename.
ENDIF.
ENDFORM.
"3.1 获取文件数据
FORM frm_get_data .
DATA: lt_raw TYPE truxs_t_text_data.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = lt_raw
i_filename = p_file
TABLES
i_tab_converted_data = gt_data
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
*&--------------------------------------------------------------------*
*& 3.2 检查数据form
*---------------------------------------------------------------------*
FORM check_data.
DATA: l_ktopl LIKE ska1-ktopl. " 定义变量,去公司代码表查询公司代码是否存在
DATA: l_saknr LIKE skb1-saknr. " 定义变量,去科目表查询科目是否存在
DATA: message TYPE string. "定义消息,统一写错误日志
* 删除科目ID为空的
DELETE gt_data WHERE saknr = space.
LOOP AT gt_data INTO record.
* 科目如果位数不足,可补前导0
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = record-saknr
IMPORTING
output = record-saknr
EXCEPTIONS
OTHERS = 1.
* 检查公司代码是否为空
IF record-bukrs = space .
CONCATENATE record-saknr '公司代码未维护.' INTO message.
PERFORM write_log_err USING record-saknr message.
ENDIF.
* 去公司代码表检查公司代码是否存在
CLEAR l_ktopl.
SELECT SINGLE ktopl INTO l_ktopl
FROM t001
WHERE bukrs = record-bukrs.
* 判断公司代码是否维护
IF l_ktopl = space .
CONCATENATE record-saknr '公司代码不存在.' INTO message.
PERFORM write_log_err USING record-saknr message.
ENDIF.
* 去科目表检查公司代码和科目是否都存在
CLEAR l_saknr.
SELECT SINGLE saknr INTO l_saknr
FROM skb1
WHERE bukrs = record-bukrs AND saknr = record-saknr.
* 判断科目是否存在
IF l_saknr > '0' .
CONCATENATE record-saknr '科目已存在,不能再导入.' INTO message.
PERFORM write_log_err USING record-saknr message.
ENDIF.
* 判断短文本是否维护
IF record-txt20_ml = space .
CONCATENATE record-saknr '短文本未维护.' INTO message.
PERFORM write_log_err USING record-saknr message.
ENDIF.
* 判断长文本是否维护
IF record-txt50_ml = space .
CONCATENATE record-saknr '长文本未维护.' INTO message.
PERFORM write_log_err USING record-saknr message.
ENDIF.
* 判断币种是否维护
IF record-waers = space .
CONCATENATE record-saknr '币别未维护.' INTO message.
PERFORM write_log_err USING record-saknr message.
ENDIF.
* 判断字段状态组是否维护
IF record-fstag EQ space .
CONCATENATE record-saknr '字段状态组未维护.' INTO message.
PERFORM write_log_err USING record-saknr message.
ENDIF.
ENDLOOP.
ENDFORM. "check_data
"4.1 调用的FORM每读入一行,就执行一次
FORM frm_exec_transaction.
"定义消息的展示方式
DATA: lt_message TYPE TABLE OF bdcmsgcoll WITH HEADER LINE.
DATA: lv_message TYPE string.
DATA: l_mode.
* Determine Mode
IF mode_a = 'X'. " Display All
l_mode = 'A'.
ELSEIF mode_n = 'X'. " Display Nothing
l_mode = 'N'.
ELSE.
l_mode = 'E'. " Display errors
ENDIF.
"循环文件内表
LOOP AT gt_data INTO record.
"以下要根据不同的类别选择,调用不同的录屏程序。原因是业务上如果选择P的话,才能有初级成本要素的选项。如果科目组是ANST,那么税务类型和是否含税过账这2个字段不可选择。
"这就是为什么这么反感BDC的原因,BDC的程序不太通用,一旦业务设置有变动,那么程序要进行适应性调整,还是BAPI香啊,不管前台输入限制。
IF record-glaccount_type = 'P' .
PERFORM frm_convert_data USING record.
ELSEIF record-ktoks = 'ANST' .
PERFORM frm_convert_data_3 USING record.
ELSE .
PERFORM frm_convert_data_2 USING record.
ENDIF.
CALL TRANSACTION 'FS00' USING gt_bdcdata[]
* OPTIONS FROM GS_OPTIONS "结构传参,参照结构:CTU_PARAMS
MESSAGES INTO lt_message "返回消息,参照结构:BDCMSGCOLL
UPDATE 'S' "更新模式:S 同步 A 异步
MODE l_mode. "显示模式:A 前台 N 后台 E 仅显示错误
IF sy-subrc = 0.
IF lt_message[] IS INITIAL.
CLEAR gt_log.
gt_log-saknr = record-saknr.
CONCATENATE record-saknr '科目导入成功.' INTO gt_log-txt100.
gt_log-type = 'S'.
APPEND gt_log.
ELSE.
" print all error messages using gt_bdcmsgcoll.
LOOP AT lt_message WHERE msgtyp = 'E'.
CLEAR lv_message.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = lt_message-msgid
msgnr = lt_message-msgnr
msgv1 = lt_message-msgv1
msgv2 = lt_message-msgv2
msgv3 = lt_message-msgv3
msgv4 = lt_message-msgv4
IMPORTING
message_text_output = lv_message .
PERFORM write_log_err USING record-saknr lv_message.
CLEAR lt_message.
ENDLOOP.
ENDIF.
ELSE.
CLEAR gt_log.
gt_log-saknr = record-saknr.
CONCATENATE record-saknr 'BDC执行失败.' INTO gt_log-txt100.
gt_log-type = 'E'.
APPEND gt_log.
ENDIF.
ENDLOOP.
ENDFORM.
* 4.1.1 这个调用的是填充数据到gt_bdcdata的程序,可以原封不动的拷贝执行录屏时的代码,有些重复的可以注释掉
FORM frm_convert_data USING p_record.
* BDC_SUBSCR的项没有意义,可不填
CLEAR: gt_bdcdata,gt_bdcdata[].
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ACC_CRE'.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_KEY-SAKNR'.
"总账科目
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_KEY-SAKNR'
record-saknr.
"公司代码
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_KEY-BUKRS'
record-bukrs.
"PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
"PERFORM bdc_field USING 'BDC_OKCODE'
" '=GLACC_TYPE'.
"PERFORM bdc_field USING 'BDC_CURSOR'
" 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'.
"PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'
" record-glaccount_type.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=2102_GROUP'.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_COA-KTOKS'.
"总账科目类型 X:资产负债表科目;N:营业外收支;P:初级成本或收入;S:次级成本
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'
record-glaccount_type.
" 科目组:ABST:非资产统御类科目;FIN:货币资金类;ERR:损益类MAT:物料管理类SAKO:一般总账类ANL:资产统驭类
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-KTOKS'
record-ktoks.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=TAB02'.
"PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'
" record-glaccount_type.
"PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-KTOKS'
" record-ktoks.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_COA-TXT50_ML'.
"科目短文本
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-TXT20_ML'
record-txt20_ml.
"科目长文本
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-TXT50_ML'
record-txt50_ml.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=TAB03'.
"科目货币
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-WAERS'
record-waers.
"限本位币记余额 选择X
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-XSALH'
record-xsalh.
" 税务类型
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-MWSKZ'
record-mwskz.
" 允许含/不含税过帐
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-XMWNO'
record-xmwno.
"统驭科目的科目类型
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-MITKZ'
record-mitkz.
" 排序码
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-ZUAWA'
record-zuawa.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_CAREA-KATYP'.
" 成本要素类别 1是初级
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CAREA-KATYP'
record-katyp.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=SAVE'.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_CCODE-XINTB'.
"字段状态组
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-FSTAG'
record-fstag.
"只能自动过账
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-XINTB'
record-xintb.
ENDFORM.
* 4.1.2 如果不是成本要素,那么初级成本要素字段是没法显示的
FORM frm_convert_data_2 USING p_record.
* BDC_SUBSCR的项没有意义,可不填
CLEAR: gt_bdcdata,gt_bdcdata[].
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ACC_CRE'.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_KEY-SAKNR'.
"总账科目
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_KEY-SAKNR'
record-saknr.
"公司代码
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_KEY-BUKRS'
record-bukrs.
"PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
"PERFORM bdc_field USING 'BDC_OKCODE'
" '=GLACC_TYPE'.
"PERFORM bdc_field USING 'BDC_CURSOR'
" 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'.
"PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'
" record-glaccount_type.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=2102_GROUP'.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_COA-KTOKS'.
"总账科目类型 X:资产负债表科目;N:营业外收支;P:初级成本或收入;S:次级成本
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'
record-glaccount_type.
" 科目组:ABST:非资产统御类科目;FIN:货币资金类;ERR:损益类MAT:物料管理类SAKO:一般总账类ANL:资产统驭类
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-KTOKS'
record-ktoks.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=TAB02'.
"PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'
" record-glaccount_type.
"PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-KTOKS'
" record-ktoks.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_COA-TXT50_ML'.
"科目短文本
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-TXT20_ML'
record-txt20_ml.
"科目长文本
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-TXT50_ML'
record-txt50_ml.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=TAB03'.
"科目货币
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-WAERS'
record-waers.
"限本位币记余额 选择X
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-XSALH'
record-xsalh.
" 税务类型
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-MWSKZ'
record-mwskz.
" 允许含/不含税过帐
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-XMWNO'
record-xmwno.
"统驭科目的科目类型
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-MITKZ'
record-mitkz.
" 排序码
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-ZUAWA'
record-zuawa.
"PERFORM bdc_field USING 'BDC_CURSOR'
" 'GLACCOUNT_SCREEN_CAREA-KATYP'.
" 成本要素类别 1是初级
"PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CAREA-KATYP'
" record-katyp.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=SAVE'.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_CCODE-XINTB'.
"字段状态组
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-FSTAG'
record-fstag.
"只能自动过账
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-XINTB'
record-xintb.
ENDFORM.
* 4.1.3 如果选择了资产负债类科目,XMWNO_013(001)和mwskz," 这2个字段不允许选择
FORM frm_convert_data_3 USING p_record.
* BDC_SUBSCR的项没有意义,可不填
CLEAR: gt_bdcdata,gt_bdcdata[].
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ACC_CRE'.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_KEY-SAKNR'.
"总账科目
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_KEY-SAKNR'
record-saknr.
"公司代码
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_KEY-BUKRS'
record-bukrs.
"PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
"PERFORM bdc_field USING 'BDC_OKCODE'
" '=GLACC_TYPE'.
"PERFORM bdc_field USING 'BDC_CURSOR'
" 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'.
"PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'
" record-glaccount_type.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=2102_GROUP'.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_COA-KTOKS'.
"总账科目类型 X:资产负债表科目;N:营业外收支;P:初级成本或收入;S:次级成本
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'
record-glaccount_type.
" 科目组:ABST:非资产统御类科目;FIN:货币资金类;ERR:损益类MAT:物料管理类SAKO:一般总账类ANL:资产统驭类
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-KTOKS'
record-ktoks.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=TAB02'.
"PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'
" record-glaccount_type.
"PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-KTOKS'
" record-ktoks.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_COA-TXT50_ML'.
"科目短文本
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-TXT20_ML'
record-txt20_ml.
"科目长文本
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-TXT50_ML'
record-txt50_ml.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=TAB03'.
"科目货币
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-WAERS'
record-waers.
"限本位币记余额 选择X
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-XSALH'
record-xsalh.
"" 税务类型
"PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-MWSKZ'
" record-mwskz.
"" 允许含/不含税过帐
"PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-XMWNO'
" record-xmwno.
"统驭科目的科目类型
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-MITKZ'
record-mitkz.
" 排序码
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-ZUAWA'
record-zuawa.
"PERFORM bdc_field USING 'BDC_CURSOR'
" 'GLACCOUNT_SCREEN_CAREA-KATYP'.
*" 成本要素类别 1是初级
*PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CAREA-KATYP'
* record-katyp.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=SAVE'.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_CCODE-XINTB'.
"字段状态组
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-FSTAG'
record-fstag.
"只能自动过账
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-XINTB'
record-xintb.
ENDFORM.
*----------------------------------------------------------------------*
* 4.1.1.1屏幕填充form,参考录屏的源码程序 *
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
CLEAR gt_bdcdata.
gt_bdcdata-program = program.
gt_bdcdata-dynpro = dynpro.
gt_bdcdata-dynbegin = 'X'.
APPEND gt_bdcdata.
ENDFORM.
*----------------------------------------------------------------------*
* 4.1.1.2字段填充form,参考录屏的源码程序 *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
CLEAR gt_bdcdata.
gt_bdcdata-fnam = fnam.
gt_bdcdata-fval = fval.
APPEND gt_bdcdata.
ENDFORM.
*写错误日志form
FORM write_log_err USING saknr message.
CLEAR gt_log.
gt_log-saknr = saknr.
gt_log-type = 'E'.
gt_log-txt100 = message.
APPEND gt_log.
ENDFORM. "write_Log_err
*&---------------------------------------------------------------------*
*& Form fieldcat_init
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FIELD_NAME text
* -->FIELD_TEXT text
* -->FIELD_LENGTH text
*----------------------------------------------------------------------*
FORM fieldcat_init USING field_name
field_text
field_length TYPE i.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = field_name.
ls_fieldcat-seltext_l = field_text.
ls_fieldcat-seltext_m = field_text.
ls_fieldcat-seltext_s = field_text.
ls_fieldcat-outputlen = field_length.
APPEND ls_fieldcat TO gt_fieldcat.
ENDFORM. "Fieldcat_init
*&--------------------------------------------------------------------*
*& Form ALV_SHOW
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM alv_show.
* Populate fieldcatalog
PERFORM fieldcat_init USING : 'SAKNR' '总帐科目' 10 .
PERFORM fieldcat_init USING : 'TYPE' '类型' 4 .
PERFORM fieldcat_init USING : 'TXT100' '描述' 100.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = gs_layout
it_fieldcat = gt_fieldcat[]
TABLES
t_outtab = gt_log
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. "output
遇到的最大问题,就是前台界面因为配置的不同,会显示不同的字段必输等
例如只有成本要素类别的科目,才能有成本要素字段聚焦、成本要素字段录入等内容,所以要根据业务实际配置情况,做动态更新。
可以根据不同类型录屏多次,或者直接拷贝修改录屏的内容。
PS:其实录屏的内容非常简单,也就几类常用的,多接触了自然就熟悉了。
比如:
PERFORM bdc_dynpro USING ‘SAPLGL_ACCOUNT_MASTER_MAINTAIN’ ‘2001’. 就是选择屏幕
PERFORM bdc_field USING ‘BDC_OKCODE’ ‘=ACC_CRE’. 就是鼠标选择或者回车选择
PERFORM bdc_field USING ‘BDC_CURSOR’ ‘GLACCOUNT_SCREEN_KEY-SAKNR’. 就是聚焦字段
PERFORM bdc_field USING ‘GLACCOUNT_SCREEN_KEY-SAKNR’ record-saknr. 就是写字段等。
内容很简单的,就是用起来麻烦些,搞不好因为一些配置,就看不到该屏幕或者该字段了。
跟fiori端口是一致的
https://mysap.goodsap.cn:44300/sap/bc/webdynpro/sap/dmc_wda?WDCONFIGURATIONID=DMC_WDA_APP&sap-client=100&sap-language=ZH
一般数据
公司代码数据
科目名称
激活后开始传输,验证画面如下:
显示已完成
查看导入科目
人家SAP业务玩的肯定比咱们溜,比用BDC舒服多了。至于每个字段代表的含义,要是能跟后台字段对应上最好了(主要是英文不好)
可以用英文环境登录se11查看相关表,就大约知道什么意思了
用多了就熟悉了。
但是有些限制,比如多个公司共用1个账目表,那么导入第二个公司时,会提示账目表已存在(不过如果共用账目表,直接复制科目就可以了)
当然,如果作为一个开发男,我还是喜欢BAPI>BDC>LTMC,毕竟LTMC是“通用的”。相比较来说,我是宁愿花个1天搞个导入,也比用别人的导入,研究没法改代码的好些。。。还是想有一些个性化或者说灵动性