https://wiki.scn.sap.com/wiki/display/ABAP/Sample+codes+for+BDC+methods+-+CTU+and+BI+session
Pages
Data Transfers - BAPI, BDC, ALE, LSMW, DX-WB
Batch Input - BDC
Skip to end of banner
Go to start of banner
Sample codes for BDC methods - CTU and BI session
Skip to end of metadata
Created by Former Member, last modified by Former Member on Sep 26, 2013
Go to start of metadata
Demo program for both BI session and CTU
Sample Code for Call Transaction Using (CTU) method
Sample Code for Batch Input Session method
Demo program for both BI session and CTU
It is based on Flight Data Application - Demo Example for Integration Technologies. So it works on all SAP systems, whatever they are ECC, SRM, CRM, etc.
You need to call SAPBC_DATA_GENERATOR program to generate initial data.
This program creates a flight record on any existing flight (date is the maximum of existing records + 1 day).
Sample Code for Call Transaction Using (CTU) method
TYPES: BEGIN OF t_employee,pernr TYPE p0002-pernr, "Employee Number
midnm TYPE p0002-midnm, "mid name
rufnm TYPE p0002-rufnm, "nick name
begda(10) TYPE c,
endda(10) TYPE c,
END OF t_employee.
DATA: it_employee TYPE STANDARD TABLE OF t_employee,wa_employee TYPE t_employee,
it_bdcdata TYPE bdcdata OCCURS 0 WITH HEADER LINE ,
i_file_path TYPE localfile,
file_name TYPE string,
I_SESSIONNAME(12) TYPE c.
SELECTION-SCREEN BEGIN OF BLOCK bk1 WITH FRAME TITLE title1.
SELECTION-SCREEN COMMENT 1(10) txt_01.PARAMETERS p_fname TYPE rlgrap-filename OBLIGATORY.
PARAMETERS p_sess LIKE APQI-GROUPID .
SELECTION-SCREEN END OF BLOCK bk1.AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
CLEAR i_file_path.
PERFORM select_input_file_name.
MOVE i_file_path TO p_fname.
file_name = p_fname.
START-OF-SELECTION.
PERFORM BDC_CALL_TRANSACTION_METHOD
CALL FUNCTION 'GUI_UPLOAD'EXPORTING
filename = file_name
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = it_employee.
FORM BDC_CALL_TRANSACTION.
LOOP AT it_employee INTO wa_employee.PERFORM bdc_dynpro USING 'SAPMP50A' '1000'.
PERFORM bdc_field USING 'RP50G-PERNR'
wa_employee-pernr.
PERFORM bdc_field USING 'RP50G-TIMR6'
'X'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RP50G-CHOIC'.
PERFORM bdc_field USING 'RP50G-CHOIC'
'0002'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=MOD'.
PERFORM bdc_dynpro USING 'MP000200' '2044'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=UPD'.
PERFORM bdc_field USING 'BDC_CURSOR'
'P0002-RUFNM'.
PERFORM bdc_field USING 'P0002-BEGDA'
wa_employee-begda.
PERFORM bdc_field USING 'P0002-ENDDA'
wa_employee-endda.
PERFORM bdc_field USING 'P0002-MIDNM'
wa_employee-midnm.
PERFORM bdc_field USING 'P0002-RUFNM'
wa_employee-rufnm.
CALL TRANSACTION 'PA30' USING it_bdcdataMODE 'A'
UPDATE 's'.
REFRESH it_bdcdata.
ENDLOOP.
ENDFORM.*&---------------------------------------------------------------------*
*& Form select_input_file_name
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM select_input_file_name.
CALL FUNCTION 'F4_FILENAME'EXPORTING
program_name = sy-repid
dynpro_number = sy-dynnr
field_name = 'PATH'
IMPORTING
file_name = i_file_path.
ENDFORM. "select_input_file_name*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PROG text
* -->SCR text
*----------------------------------------------------------------------*
FORM bdc_dynpro USING prog scr.CLEAR it_bdcdata.
it_bdcdata-program = prog.
it_bdcdata-dynpro = scr.
it_bdcdata-dynbegin = 'X'.
APPEND it_bdcdata.
ENDFORM. "BDC_DYNPRO*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FNAM text
* -->FVAL text
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.CLEAR it_bdcdata.
it_bdcdata-fnam = fnam.
it_bdcdata-fval = fval.
APPEND it_bdcdata.
ENDFORM. "BDC_FIELDSample Code for Batch Input Session method
Copy the previous program, and call the following routine BDC_BATCH_INPUT_SESSION instead of calling BDC_CALL_TRANSACTION_METHOD.
FORM BDC_BATCH_INPUT_SESSION.CALL FUNCTION 'BDC_OPEN_GROUP'EXPORTING
CLIENT = SY-MANDT
GROUP = I_SESSIONNAME
USER = SY-UNAME
KEEP = 'X'
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.
• BDC Insert
LOOP AT it_employee INTO wa_employee.PERFORM bdc_dynpro USING 'SAPMP50A' '1000'.
PERFORM bdc_field USING 'RP50G-PERNR'
wa_employee-pernr.
PERFORM bdc_field USING 'RP50G-TIMR6'
'X'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RP50G-CHOIC'.
PERFORM bdc_field USING 'RP50G-CHOIC'
'0002'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=MOD'.
PERFORM bdc_dynpro USING 'MP000200' '2044'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=UPD'.
PERFORM bdc_field USING 'BDC_CURSOR'
'P0002-RUFNM'.
PERFORM bdc_field USING 'P0002-BEGDA'
wa_employee-begda.
PERFORM bdc_field USING 'P0002-ENDDA'
wa_employee-endda.
PERFORM bdc_field USING 'P0002-MIDNM'
wa_employee-midnm.
PERFORM bdc_field USING 'P0002-RUFNM'
wa_employee-rufnm.
CALL FUNCTION 'BDC_INSERT'EXPORTING
TCODE = 'PA30'
TABLES
DYNPROTAB = it_bdcdata
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7.
clear it_bdcdata.
ENDLOOP.* Closing Batch Input
CALL FUNCTION 'BDC_CLOSE_GROUP'.ENDFORM.Muhammad Muzammil Khan
February 19, 2020 7 minute read
BDC – Batch Data Communication in SAP ABAP
111063,006
BDC – Batch Data Communication in SAP ABAP
BDC means Batch Data Communication, not Batch Data Conversion. Moreover, it was renamed Batch Input at least 20 years ago (the term BDC is still widely used though).
In this blog, I am gonna discussed the SAP DATA Migration tools mainly BDC- Batch Data Communication to export data from non-SAP environment to SAP ERP.
I will create BDC (Upload) Program for cheques with Payment doc.i-e; the BDC Program for transaction code FCH5 – Create Check.
I will discussed and write ABAP Code for BDC creation using two methods.
1- Online/Real time Data Upload.
2- Session/Batch Data Upload (using t-code SM35)
Pros and Cons.
1- Online/Real time Data Upload.
The Error Handling is Explicit: means you have to write ABAP code to collect errors generated for each records at the time of Program Execute for analysis using Message table T001.
2- Session Method Data Upload (using t-code SM35)
The Error Handling is Implicit: means you don’t have to collect the error messages for records to analyze, as it was already get created when Batch (created ) is execute from SM35. And you can analyze the errors for Batch over there.
1- Online/Real time Data Upload.
Below are the ABAP coding steps for BDC creation using Online/Real time Data Upload.,
1- Declare Structure/Internal Table/Work Area for File Format.
2- Call Function module ‘GUI_Upload’
3- Assign Internal Table ‘IT_FILE‘ in Function Module, to collect file data in it.
...