1, Call Transaction
Call Transaction: 就是直接调用Tcode进行数据批量导入。
优点:方便快捷,程序处理方便,同步更新时能实时得到BDC处理结果。
缺点:系统不能自动保存BDC 日志,需自己建透明表来维护数据,或者仅仅是将日志显示出来。
call transaction方法将数据归集到BDCDATA 结构的内表中,然后导入到系统中,通过BDCMSGCOLL结构返回BDC导入操作的成功与否消息。
BDCDATA结构中比较关键的几个字段解释:
PROGRAM - BDC module pool
DYNPRO- BDC Screen number
DYNBEGIN- BDC screen start
FNAM- Field name
FVAL- BDC field value
2, SHDB/SM35录屏
以FB09更改payment block为例,
2.1 Tcode SHDB进行录屏,
2.2 输入Document Number,Company Code,Fiscal Year,Line item,然后回车进入下一屏幕,
输入Pmnt Block ‘A‘,然后保存
2.3 得到BDC录屏结果,可以按需要调整结果,并据此写BDC代码
3, 例子代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
REPORT ztest_bdc_transaction.
* update payment block by BDC
DATA:git_bdcdata TYPE STANDARD TABLE OF bdcdata,
gwa_bdcdata LIKE LINE OF git_bdcdata,
git_messtab TYPE STANDARD TABLE OF bdcmsgcoll,
gwa_messtab LIKE LINE OF git_messtab,
gwa_ctu TYPE ctu_params.
REFRESH:git_bdcdata,
git_messtab.
* input document number
PERFORM frm_bdc_dynpro USING ‘SAPMF05L‘ ‘0102‘.
PERFORM frm_bdc_field USING ‘RF05L-BELNR‘
‘016000000‘.
PERFORM frm_bdc_field USING ‘RF05L-BUKRS‘
‘3250‘.
PERFORM frm_bdc_field USING ‘RF05L-GJAHR‘
‘2015‘.
PERFORM frm_bdc_field USING ‘RF05L-BUZEI‘
‘1‘.
PERFORM frm_bdc_field USING ‘BDC_OKCODE‘
‘/00‘.
* set payment block
PERFORM frm_bdc_dynpro USING ‘SAPMF05L‘ ‘0302‘.
PERFORM frm_bdc_field USING ‘BSEG-ZLSPR‘
‘A‘.
* save
PERFORM frm_bdc_field USING ‘BDC_OKCODE‘
‘=AE‘.
gwa_ctu-defsize = ‘X‘.
gwa_ctu-dismode = ‘N‘.
gwa_ctu-updmode = ‘S‘.
CALL TRANSACTION ‘FB09‘ USING git_bdcdata
OPTIONS FROM gwa_ctu
MESSAGES INTO git_messtab.
LOOP AT git_messtab INTO gwa_messtab WHERE msgtyp = ‘E‘
OR msgtyp = ‘X‘
OR msgtyp = ‘A‘.
* error handling .....
ENDLOOP.
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM frm_bdc_dynpro USING i_program
i_dynpro.
CLEAR gwa_bdcdata.
gwa_bdcdata-program = i_program.
gwa_bdcdata-dynpro = i_dynpro.
gwa_bdcdata-dynbegin = abap_true.
APPEND gwa_bdcdata TO git_bdcdata.
ENDFORM. "FRM_BDC_DYNPRO
*&---------------------------------------------------------------------*
*& Form FRM_BDC_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_1131 text
* -->P_LWA_CO07_BDgco_mATNR text
*----------------------------------------------------------------------*
FORM frm_bdc_field USING i_fnam
i_fval.
CLEAR gwa_bdcdata.
gwa_bdcdata-fnam = i_fnam.
gwa_bdcdata-fval = i_fval.
"delete leading zero
SHIFT gwa_bdcdata-fval LEFT DELETING LEADING space.
APPEND gwa_bdcdata TO git_bdcdata.
ENDFORM. " FRM_BDC_FIELD
|
以上。