BDC程式示例
1,呼叫事物方法
2,傳統方法
3,湊合著看吧~!
[@more@]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 Settingsxincheng24DesktopPROJ.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.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
傳統方法:
*&---------------------------------------------------------------------*
*& *
*& Report Zsapdemo_BDC_SESSION *
*& *
*& This program Obtain a list report for Customer Debt including each *
*& note created for the documents. *
*&---------------------------------------------------------------------*
*& Change Log: *
*& *
*&---------------------------------------------------------------------*
*& Init.| Who | Date | Text |*
*&---------------------------------------------------------------------*
REPORT zsapdemo_bdc_session
NO STANDARD PAGE HEADING
LINE-COUNT 150(5)
LINE-SIZE 135 .
*----------------------------------------------------------------------*
* Constants
*----------------------------------------------------------------------*
DATA: g_repid TYPE sy-repid,
strfilelocn TYPE string.
*----------------------------------------------------------------------*
* DB-Tables
*----------------------------------------------------------------------*
TABLES: zshilpa_1.
*----------------------------------------------------------------------*
* Variables/Internal Tables
*----------------------------------------------------------------------*
DATA: it_tab TYPE zshilpa_1 OCCURS 0 WITH HEADER LINE,
it_bdctab TYPE bdcdata OCCURS 0 WITH HEADER LINE,
it_messtab TYPE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
*----------------------------------------------------------------------*
* Select options / parameters *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: sfileloc LIKE rlgrap-filename
DEFAULT 'C:Documents and Settingsxincheng24Desktopzshilpa_1.txt'
OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
*----------------------------------------------------------------------*
* Initialization *
*----------------------------------------------------------------------*
INITIALIZATION.
*-- Initialize Values
PERFORM initialize_values.
*----------------------------------------------------------------------*
* Selection screen checks *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR sfileloc.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = g_repid
IMPORTING
file_name = sfileloc.
*----------------------------------------------------------------------*
* *** MAIN PROCESSING *** *
*----------------------------------------------------------------------*
START-OF-SELECTION.
strfilelocn = sfileloc.
PERFORM upload_data.
END-OF-SELECTION.
PERFORM bdc_session.
CHECK sy-subrc IS INITIAL.
MESSAGE s002(zsapdemo_msg_class).
*&---------------------------------------------------------------------*
*& Form initialize_values
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* p2 text
*----------------------------------------------------------------------*
FORM initialize_values .
*-- Get the Program Name
g_repid = sy-repid.
ENDFORM. " initialize_values
*&---------------------------------------------------------------------*
*& Form upload_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* p2 text
*----------------------------------------------------------------------*
FORM upload_data .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = strfilelocn
filetype = 'ASC'
has_field_separator = '#'
TABLES
data_tab = it_tab
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_data
*&---------------------------------------------------------------------*
*& Form fill_bdcdata
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0129 text
* -->P_0130 text
* -->P_0131 text
* -->P_0132 text
* -->P_0133 text
*----------------------------------------------------------------------*
FORM fill_bdcdata USING value(bdc_program)
value(bdc_dynpro)
value(bdc_dynbegin)
value(bdc_fnam)
value(bdc_fval).
it_bdctab-program = bdc_program.
it_bdctab-dynpro = bdc_dynpro.
it_bdctab-dynbegin = bdc_dynbegin.
it_bdctab-fnam = bdc_fnam.
it_bdctab-fval = bdc_fval.
APPEND it_bdctab.
CLEAR it_bdctab.
ENDFORM. " fill_bdcdata
*&---------------------------------------------------------------------*
*& Form bdc_session
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* p2 text
*----------------------------------------------------------------------*
FORM bdc_session .
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = 'Zsapdemo_BDC'
user = 'FIUSER'
prog = sy-cprog
EXCEPTIONS
client_invalid = 1
destination_invalid = 2
group_invalid = 3
group_is_locked = 4
holddate_invalid = 5
internal_error = 6
queue_error = 7
running = 8
system_lock_error = 9
user_invalid = 10
OTHERS = 11.
IF sy-subrc <> 0.
WRITE: / 'Error Occured while Opening BDC Group.'.
ENDIF.
LOOP AT it_tab.
PERFORM fill_bdcdata USING :
'SAPMSVMA' '0100' 'X' ' ' ' ',
' ' ' ' ' ' 'BDC_CURSOR' 'VIEWNAME',
' ' ' ' ' ' 'BDC_OKCODE' '=UPD',
' ' ' ' ' ' 'VIEWNAME' 'ZSHILPA_1',
' ' ' ' ' ' 'VIMDYNFLDS-LTD_DTA_NO' 'X',
'SAPLZSHILPA_1' '0001' 'X' ' ' ' ',
' ' ' ' ' ' 'BDC_CURSOR' 'ZSHILPA_1-ZMAT_NO(01)',
' ' ' ' ' ' 'BDC_OKCODE' '=NEWL',
'SAPLZSHILPA_1' '0002' 'X' ' ' ' ',
' ' ' ' ' ' 'BDC_CURSOR' 'ZSHILPA_1-ZMAN',
' ' ' ' ' ' 'BDC_OKCODE' '=SAVE',
' ' ' ' ' ' 'ZSHILPA_1-NAME' it_tab-name,
' ' ' ' ' ' 'ZSHILPA_1-ZMAT_NO' it_tab-zmat_no,
' ' ' ' ' ' 'ZSHILPA_1-ZMAN' it_tab-zman,
'SAPLZSHILPA_1' '0002' 'X' ' ' ' ',
' ' ' ' ' ' 'BDC_CURSOR' 'ZSHILPA_1-ZMAT_NO',
' ' ' ' ' ' 'BDC_OKCODE' '=SAVE',
' ' ' ' ' ' 'ZSHILPA_1-ZMAT_NO' 'it_tab-zmat_no',
' ' ' ' ' ' 'ZSHILPA_1-ZMAN' 'it_tab-zman',
'SAPLZSHILPA_1' '0002' 'X' ' ' ' ',
' ' ' ' ' ' 'BDC_CURSOR' 'ZSHILPA_1-ZMAT_NO',
' ' ' ' ' ' 'BDC_OKCODE' '=UEBE',
' ' ' ' ' ' 'ZSHILPA_1-ZMAT_NO' '2',
' ' ' ' ' ' 'ZSHILPA_1-ZMAN' '2',
'SAPLZSHILPA_1' '0001' 'X' ' ' ' ',
' ' ' ' ' ' 'BDC_CURSOR' ' ZSHILPA_1-ZMAT_NO(01)',
' ' ' ' ' ' 'BDC_OKCODE' '=BACK',
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8356764/viewspace-969062/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- BDC SESSIONSession
- BDC技術
- (轉)BDC技術
- 匯入物料主檔基本資料的BDC程式C程式
- BDC OK CODE 的含義,錄屏操作中BDC_OKCODE
- 常用的BDC OkCode
- SAP ABAP/4學習---BDC批次輸入寫成內表程式
- ABAP程式示例
- RabbitMQ 程式碼示例MQ
- ABAP程式示例4
- ABAP程式示例3
- lisp 程式碼示例Lisp
- 排序程式碼示例排序
- 函式模組:TB_POPUP_FOR_BDC_CONTROL函式
- BDC錄屏該程式後 最後按儲存按鈕卻無法執行
- Java NIO 程式碼示例Java
- ALVALV程式示例
- java SPI 程式碼示例Java
- 從解讀 BDC 自動生成的程式碼談起,講解 SAPGUI 的程式組成部分試讀版GUI
- 視窗程式框架示例程式碼框架
- Kafka 1.0.0 d程式碼示例Kafka
- 靜態代理程式碼示例
- xargs 的示例程式碼.
- java 管道流程式碼示例Java
- 螢幕控制示例程式
- Java NIO程式設計示例Java程式設計
- QRust(四)示例程式Rust
- MapReduce 程式設計模型 & WordCount 示例程式設計模型
- Windows守護程式簡單示例Windows
- 微信小程式圖片使用示例微信小程式
- 【Java】經典示例程式碼Java
- 多執行緒程式碼示例執行緒
- 工廠模式示例程式碼模式
- 原型模式示例程式碼原型模式
- FileSystemObject(FSO) 示例程式碼 (轉)Object
- RSA加密解密示例程式碼加密解密
- js程式碼與html程式碼分離示例JSHTML
- sitemap 檔案填充示例程式碼