如何创建实用call transaction方法的BDC程序

 我来答
福喜900
2014-11-28 · TA获得超过6.1万个赞
知道大有可为答主
回答量:1.1万
采纳率:0%
帮助的人:1亿
展开全部
程序创建步骤:
1 对相应功能进行录屏:
shdb ------>xk01---------> 生成程序(zxk01)和文件(zxk01.txt).
2.新建一个程序(zbdcxk01)
(1)声明BDCDASTA:
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
data NODATA value '/' .
TABLES: T100.
parameters p_file like rlgrap-filename .
at selection-screen on value-request for p_file.
perform file_find .
(2) 创建file_find子程序
FORM file_find .
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
STATIC = 'X'
CHANGING
FILE_NAME = p_file .
ENDFORM. " file_find
(3)声明目标文件的类型,从程序(zxk01)中拷贝以下代码.
*** Generated data section with specific formatting - DO NOT CHANGE ***
data: begin of record occurs 0,
* data element: LIF16
LIFNR_001(016),
* data element: KTOKK
KTOKK_002(004),
* data element: NAME1_GP
NAME1_003(035),
* data element: SORTL
SORTL_004(010),
* data element: LAND1_GP
LAND1_005(003),
* data element: SPRAS
SPRAS_006(002),
end of record.
(4) 声明目标文件的结构体:
data wa_record like record.
(5)声明源文件的类型,根据业务需求,和数据格式自己做.
data: begin of it_record occurs 0,
* data element: LIF16
LIFNR_001(016),
* data element: NAME1_GP
NAME1_003(035),
* data element: SORTL
SORTL_004(010),
end of it_record.
(6)声明源文件的结构体:
data wa_it_record like it_record.
(7) 在start-of-selection .下面调用uploadfile 程序.
start-of-selection .
perform uploadfile .
(8) 创建uploadfile 子程序.
data filename type string .
filename = p_file .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = filename
* FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = it_record
* EXCEPTIONS
* FILE_OPEN_ERROR = 1
* FILE_READ_ERROR = 2
* NO_BATCH = 3
* GUI_REFUSE_FILETRANSFER = 4
* INVALID_TYPE = 5
* NO_AUTHORITY = 6
* UNKNOWN_ERROR = 7
* BAD_DATA_FORMAT = 8
* HEADER_NOT_ALLOWED = 9
* SEPARATOR_NOT_ALLOWED = 10
* HEADER_TOO_LONG = 11
* UNKNOWN_DP_ERROR = 12
* ACCESS_DENIED = 13
* DP_OUT_OF_MEMORY = 14
* DISK_FULL = 15
* DP_TIMEOUT = 16
* OTHERS = 17
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " uploadfile
(9)将源文件数据传给目标文件内表,自己写以下代码, record-LIFNR_001 等格式来源于程序(zxk01).
loop at it_record into wa_it_record .
record-LIFNR_001 = wa_it_record-lifnr_001 .
record-KTOKK_002 = '0001'.
record-NAME1_003 = wa_it_record-name1_003 .
record-SORTL_004 = wa_it_record-SORTL_004.
record-LAND1_005 = 'CN'.
record-SPRAS_006 = 'EN'.
append record .
endloop .
(10) 模拟功能实现步骤,这部分代码可以从程序(zxk01)中拷贝,但是要注意将 record-LIFNR_001改为 wa_record-LIFNR_001.其他类似项也一样 要加wa_,代码如下所示.
loop at record into wa_record .
perform bdc_dynpro using 'SAPMF02K' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-LIFNR'
wa_record-LIFNR_001.
perform bdc_field using 'RF02K-KTOKK'
wa_record-KTOKK_002.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-SPRAS'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFA1-NAME1'
wa_record-NAME1_003.
perform bdc_field using 'LFA1-SORTL'
wa_record-SORTL_004.
perform bdc_field using 'LFA1-LAND1'
wa_record-LAND1_005.
perform bdc_field using 'LFA1-SPRAS'
wa_record-SPRAS_006.
perform bdc_dynpro using 'SAPMF02K' '0120'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-KUNNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPMF02K' '0130'.
perform bdc_field using 'BDC_CURSOR'
'LFBK-BANKS(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
(11) 创建 bdc_dynpro子程序,可以在程序(zxk01)中拷贝
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM. " BDC_DYNPRO
(12) 创建bdc_field 程序,可以在程序(zxk01)中拷贝
FORM BDC_FIELD USING P_FNAM P_FVAL.
IF P_FVAL <> NODATA.
CLEAR BDCDATA.
BDCDATA-FNAM = P_FNAM.
BDCDATA-FVAL = P_FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM. " BDC_FIELD
(13) 调用CALL TANSACTION方法 将'XK01' 换成相应的事物码即可.
call transaction 'XK01' USING BDCDATA MODE 'N'
UPDATE 'S' MESSAGES INTO messtab.
clear bdcdata.
refresh bdcdata.
DATA: L_MSTRING(480).
DATA: L_SUBRC LIKE SY-SUBRC.
LOOP AT MESSTAB.
SELECT SINGLE * FROM T100 WHERE SPRSL = MESSTAB-MSGSPRA
AND ARBGB = MESSTAB-MSGID
AND MSGNR = MESSTAB-MSGNR.
IF SY-SUBRC = 0.
L_MSTRING = T100-TEXT.
IF L_MSTRING CS '&1'.
REPLACE '&1' WITH MESSTAB-MSGV1 INTO L_MSTRING.
REPLACE '&2' WITH MESSTAB-MSGV2 INTO L_MSTRING.
REPLACE '&3' WITH MESSTAB-MSGV3 INTO L_MSTRING.
REPLACE '&4' WITH MESSTAB-MSGV4 INTO L_MSTRING.
ELSE.
REPLACE '&' WITH MESSTAB-MSGV1 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV2 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV3 INTO L_MSTRING.
REPLACE '&' WITH MESSTAB-MSGV4 INTO L_MSTRING.
ENDIF.
CONDENSE L_MSTRING.
WRITE: / MESSTAB-MSGTYP, L_MSTRING(250).
ELSE.
WRITE: / MESSTAB.
ENDIF.
ENDLOOP.
endloop .
(14)整个过程已经结束,检查激活该程序,运行并从中选择需要上传的文件例如:zver001.txt,然后回车就可以完成了.
注意事项:
在该程序的书写过程中在以下几处设置断点可以检查出程序中的错误.
(1)bdcdata
看里面是否有数据
(2) append record .
看里面是否有数据
(3) loop at it_record into wa_it_record .
看里面是否有数据
(4)bdcdata,record和it_record都有数据那么就看
perform bdc_field using 'RF02K-LIFNR'
wa_record-LIFNR_001.
是 wa_record-LIFNR_001还是 record-LIFNR_001.
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式