|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622 。
您需要 登录 才可以下载或查看,没有帐号?注册
x
注册ERP100已经好久了,但是一直没有发帖,积分比较少,所以打算给论坛做点贡献,赚点积分挤入老会员行列。发现论坛的教学程序比较少,正好最近有空写点范例程序。我打算把ABAP涉及的项目中常用的应用程序都做一个DEMO供初学者参考(ALV, BDC, DIALOG PROG, REPORT PROG, SAP SCRIPT, SMARTFORMS, ETC…), 内容顺序跟培训课程不大一样,但这些都是独立模块,互相的关联没有太多限制,所以也没有关系。今天我将具体给出一个BDC的实践例子,抛砖引玉,有不足之处希望大家多多指教!同时希望erp100的其他同仁们也能够借此机会跟大家分享一些你们觉得有价值的ABAP程序。
BDC 分为传统输入方法(CLASSICAL BATCH INPUT METHOD)和调用事务方法(CALL TRANSACTION METHOD)。
由于程序的长度不是非常长,所以我就不分帖描述了,在SAP R/3 4.6C IDES 测试通过,程序细节如下:
传统方法在此使用已比较少,调用事务方法比较多一点。所以这里,我就给出一个调用事务方式。功能描述我将在代码里面描述
REPORT Z_ABAPDEMOprojload
NO STANDARD PAGE HEADING LINE-SIZE 255.
*
*INCLUDE Z_ABAPDEMOprojload_top.
*&---------------------------------------------------------------------*
*& Include Z_ABAPDEMOPROJLOAD_TOP *
*&---------------------------------------------------------------------*
TABLES Z_ABAPDEMOproj.
DATA : BEGIN OF i_proj OCCURS 0,
project LIKE Z_ABAPDEMOproj-project,
proj_desc LIKE Z_ABAPDEMOproj-proj_desc,
stdat(10) TYPE c,
enddat(10) TYPE c,
customer LIKE Z_ABAPDEMOproj-customer,
location LIKE Z_ABAPDEMOproj-location,
END OF i_proj.
DATA i_bdctab LIKE bdcdata OCCURS 0 WITH HEADER LINE.
DATA messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
*INCLUDE Z_ABAPDEMOprojload_form.
*&---------------------------------------------------------------------*
*& Include Z_ABAPDEMOPROJLOAD_FORM *
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form insert
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM insert .
*这里面的代码不是手动输入的,是通过一个录屏程序生成的,录屏程序的TR-CODE是SM35,在此你还需要
*指定一个transaction。
* perform open_group.
LOOP AT i_proj.
CLEAR i_bdctab[].
PERFORM bdc_dynpro USING 'Z_ABAPDEMO_D9_DIALOG' '0100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'Z_ABAPDEMOPROJ-PROJECT'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'Z_ABAPDEMOPROJ-PROJECT'
i_proj-project.
PERFORM bdc_dynpro USING 'Z_ABAPDEMO_D9_DIALOG' '0200'.
PERFORM bdc_field USING 'BDC_CURSOR'
'Z_ABAPDEMOPROJ-LOCATION'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=SAVE'.
PERFORM bdc_field USING 'Z_ABAPDEMOPROJ-PROJ_DESC'
i_proj-proj_desc.
PERFORM bdc_field USING 'Z_ABAPDEMOPROJ-STDAT'
i_proj-stdat.
PERFORM bdc_field USING 'Z_ABAPDEMOPROJ-ENDDAT'
i_proj-enddat.
PERFORM bdc_field USING 'Z_ABAPDEMOPROJ-CUSTOMER'
i_proj-customer.
PERFORM bdc_field USING 'Z_ABAPDEMOPROJ-LOCATION'
i_proj-location.
PERFORM bdc_dynpro USING 'SAPLSPO1' '0500'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=OPT1'.
PERFORM bdc_dynpro USING 'Z_ABAPDEMO_D9_DIALOG' '0200'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/EEXIT'.
PERFORM bdc_field USING 'BDC_CURSOR'
'LPROJID'.
PERFORM transaction USING 'Z_ABAPDEMOPROJ1'.
ENDLOOP.
* perform close_group.
ENDFORM. " insert
*&---------------------------------------------------------------------*
*& Form process
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM process .
ENDFORM. " process
*&---------------------------------------------------------------------*
*& Form upload
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM upload .
*上传文本文件,这是一个以TAB分隔的表内容文件,它的字段以我后面的数据库表字段的顺序排列
*这里使用的是GUI_UPLOAD,还可以是WS_UPLOAD,大同小异
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\Documents and Settings\xincheng24\Desktop\PROJ.TXT'
filetype = 'ASC'
has_field_separator = '#'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
data_tab = i_proj
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. " upload
*&--------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->PROGRAM text
* -->DYNPRO text
*---------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
*该子程序也是由录屏程序生成的
CLEAR i_bdctab.
i_bdctab-program = program.
i_bdctab-dynpro = dynpro.
i_bdctab-dynbegin = 'X'.
APPEND i_bdctab.
ENDFORM. "BDC_DYNPRO
*&--------------------------------------------------------------------*
*& Form bdc_field
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->FNAM text
* -->FVAL text
*---------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
*该子程序同样由录屏程序生成
CLEAR i_bdctab.
i_bdctab-fnam = fnam.
i_bdctab-fval = fval.
APPEND i_bdctab.
ENDFORM. "DBC_FIELD
*&--------------------------------------------------------------------*
*& Form transaction
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->FNAM text
* -->FVAL text
*---------------------------------------------------------------------*
FORM transaction USING tcode.
*这就是调用事务类型的体现,需要主意的就是模式MODE和UPDATE。AS的组合就是显示所有log
*同步更新
REFRESH messtab.
CALL TRANSACTION tcode USING i_bdctab
MODE 'A'
UPDATE 'S'
MESSAGES INTO messtab.
ENDFORM. "TRANSACTION
*Main program
START-OF-SELECTION.
*upload the data from text file to internal table
PERFORM upload.
*process the data type. mainly used to convert date type
PERFORM process.
*insert the data from internal table to database table
PERFORM insert.
[ 本帖最后由 zhuxincheng 于 2007-7-27 10:06 编辑 ] |
-
-
BDC.doc
49 KB, 下载次数: 72, 下载积分: 努力值 -5 点
|