BDC示例文档
1.使用SHDB录屏。
点New Recodring,出现如下屏幕:
http://s2/mw690/4b38c310ge186ac68d551&690
点确定键,出现以下界面
http://s5/mw690/4b38c310ge186aeb48be4&690
点继续按钮。
点继续按钮,进入MM02进入修改。
http://s11/mw690/4b38c310ge186b05c41ca&690
http://s1/mw690/4b38c310g7cf3dead3330&690
http://s3/mw690/4b38c310ge186b3088a62&690
然后点“保存”,保存这次修改。
现在SAP回到了SHDB,
先点“保存”,保存Recording :Z_XJ_MM02_01,
然后点”返回”,返回SHDB的第一屏。
选中“Z_XJ_MM02_01”,然后点击“Program”,由SAP自动生成一个程序。
http://s6/mw690/4b38c310ge186b61e11e5&690
输入程序属性信息如下:
代码如下:
report z_xj_mm02_01
no standard page heading line-size 255.
include bdcrecx1.
parameters: dataset(132) lower case.
*** DO NOT
CHANGE - the generated data section - DO NOT
CHANGE
***
*
* If it is
nessesary to change the data section use the rules:
* 1.) Each
definition of a field exists of two lines
* 2.) The first
line shows exactly the comment
*
'* data element: ' followed with the data element
*
which describes the field.
*
If you don't have a data element use the
*
comment without a data element name
* 3.) The
second line shows the fieldname of the
*
structure, the fieldname must consist of
*
a fieldname and optional the character '_' and
*
three numbers and the field length in brackets
* 4.) Each
field must be type C.
*
*** Generated data section with specific formatting
- DO NOT CHANGE ***
data: begin of record,
* data element: MATNR
matnr_001(018),
"第1个是物料号,长度为18个字符
* data element: XFELD
kzsel_01_002(001), "第2个是选择视图,这里是选择视图01-基本视图1
* data element: XFELD
kzsel_11_003(001), "第3个是选择视图,这里是选择视图11-MRP视图1
* data element: WERKS_D
werks_004(004),
"第4个是工厂,这里固定为1001.
* data element: MAKTX
maktx_005(040),
"第5个是物料描述
* data element: MEINS
meins_006(003),
"第6个是单位,长度为3个字符
* data element: MATKL
matkl_007(009),
"第7个是物料组,长度为9个字符
* data element: GEWEI
gewei_008(003),
"第8个是重量单位,长度为3
* data element: GROES
groes_009(032),
"第9个是大小/量纲,长度为32
* data element: DISMM
dismm_010(002),
"第10个是MRP类型,
* data element: DISPO
dispo_011(003),
"第11个是MRP 控制者
* data element: DISLS
disls_012(002),
"第12个是批量大小
end of record.
*** End generated data section ***
data: it_record
like table of
record.
*data: filename type localfile ,
data: filetype(10) type c.
data:filename
type string.
start-of-selection.
perform
get_data.
* perform open_dataset using
dataset.
perform open_group.
* do.
"放弃使用do,而采用loop循环
loop
at it_record
into record.
* read
dataset dataset into record. "取消dataset,使用内表
if sy-subrc
<> 0. exit. endif.
perform
bdc_dynpro
using 'SAPLMGMM' '0060'.
perform
bdc_field
using 'BDC_CURSOR'
'RMMG1-MATNR'.
perform
bdc_field
using 'BDC_OKCODE'
'=ENTR'.
perform
bdc_field
using 'RMMG1-MATNR'
record-matnr_001.
perform
bdc_dynpro
using 'SAPLMGMM' '0070'.
perform
bdc_field
using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(11)'.
perform
bdc_field
using 'BDC_OKCODE'
'=ENTR'.
perform
bdc_field
using 'MSICHTAUSW-KZSEL(01)'
record-kzsel_01_002.
perform
bdc_field
using 'MSICHTAUSW-KZSEL(11)'
record-kzsel_11_003.
perform
bdc_dynpro
using 'SAPLMGMM' '0080'.
perform
bdc_field
using 'BDC_CURSOR'
'RMMG1-WERKS'.
perform
bdc_field
using 'BDC_OKCODE'
'=ENTR'.
perform
bdc_field
using 'RMMG1-WERKS'
record-werks_004.
perform
bdc_dynpro
using 'SAPLMGMM' '4004'.
perform
bdc_field
using 'BDC_OKCODE'
'/00'.
perform
bdc_field
using 'MAKT-MAKTX'
record-maktx_005.
perform
bdc_field
using 'BDC_CURSOR'
'MARA-BISMT'.
perform
bdc_field
using 'MARA-MEINS'
record-meins_006.
perform
bdc_field
using 'MARA-MATKL'
record-matkl_007.
perform
bdc_field
using 'MARA-GEWEI'
record-gewei_008.
perform
bdc_field
using 'MARA-GROES'
record-groes_009.
perform
bdc_dynpro
using 'SAPLMGMM' '4000'.
perform
bdc_field
using 'BDC_OKCODE'
'=BU'.
perform
bdc_field
using 'BDC_CURSOR'
'MAKT-MAKTX'.
perform
bdc_field
using 'MARC-DISMM'
record-dismm_010.
perform
bdc_field
using 'MARC-DISPO'
record-dispo_011.
perform
bdc_field
using 'MARC-DISLS'
record-disls_012.
perform
bdc_transaction using 'MM02'.
* enddo.
endloop.
perform close_group.
* perform close_dataset using
dataset.
*&---------------------------------------------------------------------*
*&
Form get_data
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
form get_data.
call function
'WS_FILENAME_GET'
exporting
def_filename
= 'Z_XJ_MM02_01上传文档.txt'
def_path
= 'D:\'
mask
= ',*.*,*.*. '
mode
= 'O'
title
= '请打开Z_XJ_MM02_01上传文档.txt'
importing
filename
= filename
exceptions
inv_winsys
= 1
no_batch
= 2
selection_cancel = 3
selection_error = 4
others
= 5.
if sy-subrc <> 0.
exit.
endif.
***---上传文件方法1:上传函数WS_UPLOAD
* call function 'WS_UPLOAD'
*
exporting
*
filename = filename
*
filetype = 'DAT'
* tables
*
data_tab = it_record.
***---上传文件方法2:上传函数GUI_UPLOAD
* call function 'GUI_UPLOAD'
*
exporting
*
filename
=
filename
"'D:\Z_XJ_MM02_01上传文档.txt'
*
filetype
= 'DAT'
*
codepage
= '8400'
**
HAS_FIELD_SEPARATOR
= ' '
**
HEADER_LENGTH
= 0
**
READ_BY_LINE
= 'X'
**
DAT_MODE
= ' '
**
CODEPAGE
= ' '
**
IGNORE_CERR
= ABAP_TRUE
**
REPLACEMENT
= '#'
**
CHECK_BOM
= ' '
**
VIRUS_SCAN_PROFILE
=
**
NO_AUTH_CHECK
= ' '
** 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.
** Implement suitable error handling here
* endif.
*
*
***---上传文件方法3:上传函数cl_gui_frontend_services=>GUI_UPLOAD
call method
cl_gui_frontend_services=>gui_upload
exporting
filename
= filename
filetype
= 'DAT'
codepage
= '8400'
changing
data_tab
= it_record
exceptions
file_open_error
= 1
file_read_error
= 2
no_batch
= 3
gui_refuse_filetransfer = 4
no_authority
= 6
unknown_error
= 7
bad_data_format
= 8
unknown_dp_error
= 12
access_denied
= 13
others
= 17.
endform.
"get_data
调用BDC 不管是写ABAP 还是通过SAP 生成的BDC
程序,上传数据时都会有两种方式选择:
1: Generate session 首先生成一个会话,像其它大方式的上传数据一样,
在之后通过SM35 执行此会话进行真正的数
据上传
2: Call transaction 并不需要生成会话,当执行BDC 程序时就直接上传数据
执行结果:
http://s11/mw690/4b38c310ge186b8374eaa&690
http://s16/mw690/4b38c310ge186b85cc6af&690
注意事项:
1、录“操作”的时候,不要有“多余”的操作,如果有,就重新录。
2、尽量用鼠标去点击按钮,而不要只是敲“Enter”
加载中,请稍候......