1、BDC的过程
2、BDC执行方式
3、详细步骤
1)code:SHDB
2)新建记录
填写客户信息
如果在页面中没有遇到要填写的信息,就点击下一制表页
信息录完之后点击保存,没有录完就继续下一页
创建程序
到达如下界面
回到SHDB,进入创建好的BDC记录,将录入的字段整理成表格
新建程序:
创建内表、复制BDC的源代码,修改
*&———————————————————————*
*& Report ZSAP_BDC
*&
*&———————————————————————*
*&
*&
*&———————————————————————*
REPORT zsap_bdc.
*—–批导入—–*
“结构,从BDC中复制的结构
TYPES:BEGIN OF ty_customer,
* data element: KUN16
kunnr_001(016),”客户编号
* data element: KTOKD
ktokd_005(004),”账户组
* data element: VKORG
vkorg_002(004),”销售组织
* data element: VTWEG
vtweg_003(002),”分销渠道
* data element: SPART
spart_004(002),”产品组
* data element: ANRED
anred_006(015),”标题
* data element: NAME1_GP
name1_007(035),”姓
* data element: STRAS_GP
stras_008(035),”街道
* data element: PSTLZ
pstlz_010(010),”邮政编码
* data element: ORT01_GP
ort01_009(035),”城市
* data element: LAND1_GP
land1_012(003),”国家
* data element: ORT02_GP
ort02_011(035),”地区
* data element: BZIRK
bzirk_016(006),”销售地区
* data element: AWAHR
awahr_017(003),”销售部门
* data element: LPRIO
lprio_021(002),”交货优先权
* data element: PERFK
perfk_024(002),”出票日期
END OF ty_customer.
“从BDC复制的变量
*———————————————————————-*
* data definition
*———————————————————————-*
* Batchinputdata of single transaction
DATA:bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
* messages of call transaction
DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
DATA: ctumode LIKE ctu_params-dismode.
DATA: cupdate LIKE ctu_params-updmode.
“根据结构创建内表
DATA lt_customer TYPE TABLE OF ty_customer WITH HEADER LINE.
“用于接收上载的文件名称的临时变量
DATA:lv_filename TYPE string.
“上传文件的选择屏幕元素
PARAMETERS:p_file LIKE rlgrap-filename OBLIGATORY.
“文件搜索帮助
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
“执行方法
CALL FUNCTION ‘F4_FILENAME’
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ‘ ‘
IMPORTING
file_name = p_file.
START-OF-SELECTION.
“文件上载,并把数据存在内表
lv_filename = p_file.
CALL FUNCTION ‘GUI_UPLOAD’
EXPORTING
filename = lv_filename
filetype = ‘ASC’
has_field_separator = ‘X’
* HEADER_LENGTH = 0
read_by_line = ‘X’
dat_mode = ‘ ‘
codepage = ‘ ‘
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = ‘#’
* CHECK_BOM = ‘ ‘
* VIRUS_SCAN_PROFILE =
no_auth_check = ‘X’
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
data_tab = lt_customer[]
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.
* Implement suitable error handling here
ENDIF.
CHECK lt_customer[] IS NOT INITIAL.
LOOP AT lt_customer.
“从bdc复制的子例程调用语句,更改内表对应的字段,把不需要传的字段注释掉或者设置成空值
PERFORM bdc_dynpro USING ‘SAPMF02D’ ‘0100’.
PERFORM bdc_field USING ‘BDC_OKCODE’
‘/00’.
PERFORM bdc_field USING ‘RF02D-KUNNR’
lt_customer-kunnr_001.”内表对应的字段
PERFORM bdc_field USING ‘RF02D-VKORG’
lt_customer-vkorg_002.
PERFORM bdc_field USING ‘RF02D-VTWEG’
lt_customer-vtweg_003.
PERFORM bdc_field USING ‘RF02D-SPART’
lt_customer-spart_004.
PERFORM bdc_field USING ‘RF02D-KTOKD’
lt_customer-ktokd_005.
PERFORM bdc_dynpro USING ‘SAPMF02D’ ‘0110’.
PERFORM bdc_field USING ‘BDC_CURSOR’
‘KNA1-ORT02’.
PERFORM bdc_field USING ‘BDC_OKCODE’
‘=VW’.
PERFORM bdc_field USING ‘KNA1-ANRED’
lt_customer-anred_006.
PERFORM bdc_field USING ‘KNA1-NAME1’
lt_customer-name1_007.
PERFORM bdc_field USING ‘KNA1-STRAS’
lt_customer-stras_008.
PERFORM bdc_field USING ‘KNA1-ORT01’
lt_customer-ort01_009.
PERFORM bdc_field USING ‘KNA1-PSTLZ’
lt_customer-pstlz_010.
PERFORM bdc_field USING ‘KNA1-ORT02’
lt_customer-ort02_011.
PERFORM bdc_field USING ‘KNA1-LAND1’
lt_customer-land1_012.
PERFORM bdc_field USING ‘KNA1-SPRAS’
‘ZH’.”必传
PERFORM bdc_dynpro USING ‘SAPMF02D’ ‘0120’.
PERFORM bdc_field USING ‘BDC_CURSOR’
‘KNA1-LIFNR’.
PERFORM bdc_field USING ‘BDC_OKCODE’
‘=VW’.
*perform bdc_field using ‘KNA1-STKZN’
* ”.
PERFORM bdc_dynpro USING ‘SAPMF02D’ ‘0125’.
PERFORM bdc_field USING ‘BDC_CURSOR’
‘KNA1-NIELS’.
PERFORM bdc_field USING ‘BDC_OKCODE’
‘=VW’.
PERFORM bdc_dynpro USING ‘SAPMF02D’ ‘0130’.
PERFORM bdc_field USING ‘BDC_CURSOR’
‘KNBK-BANKS(01)’.
PERFORM bdc_field USING ‘BDC_OKCODE’
‘=VW’.
PERFORM bdc_dynpro USING ‘SAPMF02D’ ‘0340’.
PERFORM bdc_field USING ‘BDC_CURSOR’
‘RF02D-KUNNR’.
PERFORM bdc_field USING ‘BDC_OKCODE’
‘=VW’.
PERFORM bdc_dynpro USING ‘SAPMF02D’ ‘0370’.
PERFORM bdc_field USING ‘BDC_CURSOR’
‘RF02D-KUNNR’.
PERFORM bdc_field USING ‘BDC_OKCODE’
‘=VW’.
*perform bdc_field using ‘KNA1-CIVVE’
* ”.
PERFORM bdc_dynpro USING ‘SAPMF02D’ ‘0310’.
PERFORM bdc_field USING ‘BDC_CURSOR’
‘KNVV-VKBUR’.
PERFORM bdc_field USING ‘BDC_OKCODE’
‘=VW’.
PERFORM bdc_field USING ‘KNVV-BZIRK’
lt_customer-bzirk_016.
PERFORM bdc_field USING ‘KNVV-AWAHR’
lt_customer-awahr_017.
*perform bdc_field using ‘KNVV-VKBUR’
* ”.
*perform bdc_field using ‘KNVV-WAERS’
* ”.
*perform bdc_field using ‘KNVV-KALKS’
* ”.
PERFORM bdc_dynpro USING ‘SAPMF02D’ ‘0315’.
PERFORM bdc_field USING ‘BDC_CURSOR’
‘KNVV-LPRIO’.
PERFORM bdc_field USING ‘BDC_OKCODE’
‘=VW’.
PERFORM bdc_field USING ‘KNVV-LPRIO’
lt_customer-lprio_021.
*perform bdc_field using ‘KNVV-KZAZU’
* ”.
*perform bdc_field using ‘KNVV-ANTLF’
* ”.
PERFORM bdc_dynpro USING ‘SAPMF02D’ ‘0320’.
PERFORM bdc_field USING ‘BDC_CURSOR’
‘KNVV-PERFK’.
PERFORM bdc_field USING ‘BDC_OKCODE’
‘=UPDA’.
PERFORM bdc_field USING ‘KNVV-PERFK’
lt_customer-perfk_024.
PERFORM bdc_transaction USING ‘XD01’.
ENDLOOP.
“从BDC复制的子例程
*&———————————————————————*
*& Form BDC_DYNPRO
*&———————————————————————*
* text
*———————————————————————-*
* –>PROGRAM text
* –>DYNPRO text
*———————————————————————-*
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = ‘X’.
APPEND bdcdata.
ENDFORM. “BDC_DYNPRO
*———————————————————————-*
* Insert field *
*———————————————————————-*
FORM bdc_field USING fnam fval.
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
APPEND bdcdata.
ENDFORM. “BDC_FIELD
*&———————————————————————*
*& Form BDC_TRANSACTION
*&———————————————————————*
* text
*———————————————————————-*
* –>TCODE text
*———————————————————————-*
FORM bdc_transaction USING tcode.
REFRESH messtab.
CALL TRANSACTION tcode USING bdcdata
MODE ‘A'”显示所有屏幕
UPDATE ‘S'”同步
MESSAGES INTO messtab.
ENDFORM. “BDC_TRANSACTION
执行BDC注意事项
准备数据然后删除表头另存成Unicode txt格式
文件上载方式(此方式只适合上传txt,不适合上载Excel)
或者用
;
另外说一下下载