BDC-CALL TRASACTION Recording: it is a SAP provided option to record the screen and field details of an application (Ex:XD01,XK01, VA01,ME21N,VF01,…………) while it is executing(Running). This is used to write the code to automate the data upload into SAP SHDB is the T.code to work with recording Go to SHDB Click on New recording icon Provide the Recording name, Transaction code(Ex:XD01) for which recording is required Click on ‘Start recording ‘ Tab
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
BDC-CALL TRASACTION
Recording: it is a SAP provided option to record the screen and field details of an application (Ex:XD01,XK01, VA01,ME21N,VF01,…………) while it is executing(Running).
This is used to write the code to automate the data upload into SAP
SHDB is the T.code to work with recording
Go to SHDB
Click on New recording icon
Provide the Recording name, Transaction code(Ex:XD01) for which recording is required
Click on ‘Start recording ‘ Tab
Enter the data in fields required in first screen
Click on ENTER
Provide the data in required fields in second screen
Click on SAVE--------Enter-----Enter
Now click on SAVE to save the above recording if required
1) Call transaction MethodGo to se38
Click on Create and provide the description and type
Click on ENTER and click on Local Object Icon
Now write the program
REPORT zbdc_call_demo.
DATA:BEGIN OF wa_kna1, kunnr LIKE kna1-kunnr, ktokd LIKE kna1-ktokd, name1 LIKE kna1-name1, sortl LIKE kna1-sortl, ort01 LIKE kna1-ort01, pstlz LIKE kna1-pstlz, land1 LIKE kna1-land1, spras LIKE kna1-spras, END OF wa_kna1,
it_kna1 LIKE TABLE OF wa_kna1.
*To hold the screen and field details of a customerDATA:wa_bdcdata TYPE bdcdata, it_bdcdata LIKE TABLE OF wa_bdcdata.
*To read the data from text file to presentations layerCALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = 'C:\customer.txt'* FILETYPE = 'ASC' has_field_separator = 'X'* HEADER_LENGTH = 0* IMPORTING* FILELENGTH = FILELENGTH* HEADER = HEADER TABLES data_tab = it_kna1* EXCEPTIONS.
*To process the dataIF NOT it_kna1 IS INITIAL.
LOOP AT it_kna1 INTO wa_kna1.*To get the screen & field detaisl of each customer*First screen details wa_bdcdata-program = 'SAPMF02D'. wa_bdcdata-dynpro = '0100'. wa_bdcdata-dynbegin = 'X'. APPEND wa_bdcdata TO it_bdcdata. CLEAR wa_bdcdata.
wa_bdcdata-fnam = 'BDC_CURSOR'. wa_bdcdata-fval = 'RF02D-KTOKD'. APPEND wa_bdcdata TO it_bdcdata.
*to run the Application(XD01) CALL TRANSACTION 'XD01' USING it_bdcdata MODE 'A'. REFRESH it_bdcdata.
ENDLOOP.ELSE. MESSAGE 'No data found to upload' TYPE 'I'.ENDIF.
SAVE----CHECK-----ACTIVATE
To test the program
Create the text file(customer) data with the fields in wa_kna1 with Tab space and place in C drive
Example 2Go to SE38
Now create the program as below
report zbdc_call_demo.
*To hold the data received from local drivedata:begin of wa_cust, kunnr type kunnr, "customer number ktokd type ktokd, "accountgroup name1 type name1, "name sortl type sortl, "search term stras type stras, "STREET land1 type land1, "country spras type spras, "language end of wa_cust,
it_cust like table of wa_cust.
*To hold the screen and field details of the transaction data: wa_bdcdata type bdcdata, it_bdcdata like table of wa_bdcdata.
call transaction 'XD01' using it_bdcdata mode 'A'. "(A:All screens(foreground),N:no screens(Back ground),E:error screens) refresh it_bdcdata. endloop. else. message 'No data found from the file' type 'I'. endif.
Example 3Go to SE38
Now create the program as below
REPORT zbdc_call_demo2.TYPE-POOLS truxs.
*To hold the data received from local driveDATA:BEGIN OF wa_cust, kunnr TYPE kunnr, "customer number ktokd TYPE ktokd, "accountgroup name1 TYPE name1, "name sortl TYPE sortl, "search term stras TYPE stras, "STREET land1 TYPE land1, "country spras TYPE spras, "language END OF wa_cust, it_cust LIKE TABLE OF wa_cust.*To hold the screen and field details of the transactionDATA: wa_bdcdata TYPE bdcdata, it_bdcdata LIKE TABLE OF wa_bdcdata.DATA v_notepad TYPE truxs_t_text_data.PARAMETERS p_file TYPE rlgrap-filename.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.*To browse the file CALL FUNCTION 'F4_FILENAME' EXPORTING program_name = syst-cprog dynpro_number = syst-dynnr field_name = ' ' IMPORTING file_name = p_file. IF NOT p_file IS INITIAL.*To convert the data from excel sheet to int table CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP' EXPORTING* I_FIELD_SEPERATOR = I_FIELD_SEPERATOR* I_LINE_HEADER = I_LINE_HEADER i_tab_raw_data = v_notepad i_filename = p_file TABLES i_tab_converted_data = it_cust* EXCEPTIONS* CONVERSION_FAILED = 1* OTHERS = 2 . IF sy-subrc <> 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.
ELSE. MESSAGE 'File was not found' TYPE 'E'. ENDIF.
IF NOT it_cust IS INITIAL. DELETE it_cust INDEX 1.*to process the data LOOP AT it_cust INTO wa_cust.*to add the leading zerosCALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = wa_cust-ktokd IMPORTING OUTPUT = wa_cust-ktokd .
*To get the sceen and field details of the transaction* 1st screen details
CALL TRANSACTION 'XD01' USING it_bdcdata MODE 'N'.
REFRESH it_bdcdata. ENDLOOP. ELSE. MESSAGE 'No data found from the file' TYPE 'I'. ENDIF.*&---------------------------------------------------------------------**& Form fill_bdcdata*&---------------------------------------------------------------------** text To fill the bdcdata int table*----------------------------------------------------------------------** -->P_0135 text* -->P_0136 text* -->P_0137 text* -->P_0138 text* -->P_0139 text*----------------------------------------------------------------------*FORM fill_bdcdata USING value(p_prog) value(p_dynpro) value(p_dynbgn) value(p_fnam) value(p_fval).
1) Synchronous processing. The system performs a database commit immediately before and after the CALL TRANSACTION USING statement.
2) Updating the database can be either synchronous or asynchronous. The program specifies the update type.
3) Transfer data for a single transaction.4) Transfers data for a sequence of dialog screens.5) No batch input processing log is generated.6) Error handling is not possible
7) asynchronous processing8) can transfer small amount of data9) processing is faster.10) errors need to be handled explicitly11) data is updated automatically
SESSION METHOD
1) Data is not updated in the database table until the session is processed.
2) No sy-subrc is returned.
3) Error log is created for error records.
4) Updation is always synchronous.
5) Session method supports both small amount of data as well as large amount of data
6) Data processing is asynchronous and data updation is synchronous.
7) It processes multiple applications while performing validations.
8) In session method data will be updated in data base only after processing session only.
9) System provide by default logfile for handling error records.
10) It supports both foreground as well as background process
In session method, there are 3 function modules are used
1) BDC_OPEN_GROUP : this is used to open the session
2) BDC_INSERT: this is used to insert the data
3) BDC_CLOSE_GROUP: this is used to close the session
Steps to work with SESSION METHOD
1) Define the required work areas and int tables
2) Upload the data using GUI_UPLOAD or CONVERT_TEXT_XLS_TO_SAP or any other
3) open the session using BDC_OPEN_GROUP
4) Loop
5) prepare the bdcdata int table data
6) Insert the data using BDC_INSERT
7) ENDLOOP
8) Close the session using BDC_CLOSE_GROUP
9) Now go to SM35 to process the session(Fore ground, Display with errors or Back ground)
Example 1
Go to SE38
Now create the program as below
report zbdc_session_demo.
type-pools truxs.
*To hold the data received from local drive
data:begin of wa_cust,
kunnr type kunnr, "customer number
ktokd type ktokd, "accountgroup
name1 type name1, "name
sortl type sortl, "search term
stras type stras, "STREET
land1 type land1, "country
spras type spras, "language
end of wa_cust,
it_cust like table of wa_cust.
*To hold the screen and field details of the transaction
data: wa_bdcdata type bdcdata,
it_bdcdata like table of wa_bdcdata.
data v_notepad type truxs_t_text_data.
parameters p_file type rlgrap-filename.
at selection-screen on value-request for p_file.
*To browse the file
call function 'F4_FILENAME'
exporting
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
importing
file_name = p_file.
*start of selection
start-of-selection.
if not p_file is initial.
*To convert the data from excel sheet to int table
call function 'TEXT_CONVERT_XLS_TO_SAP'
exporting
* I_FIELD_SEPERATOR = I_FIELD_SEPERATOR
* I_LINE_HEADER = I_LINE_HEADER
i_tab_raw_data = v_notepad
i_filename = p_file
tables
i_tab_converted_data = it_cust
* EXCEPTIONS
* CONVERSION_FAILED = 1
* OTHERS = 2
.
else.
message 'File was not found' type 'E'.
endif.
*END OF SELECTION EVENT
end-of-selection.
*to open the session
call function 'BDC_OPEN_GROUP'
exporting
* CLIENT = SY-MANDT
* DEST = FILLER8
group = 'DEMO'
* HOLDDATE = FILLER8
keep = 'X'
user = sy-uname
* RECORD = FILLER1
prog = sy-cprog
* DCPFM = '%'
* DATFM = '%'
* IMPORTING
* QID = QID
* 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 not it_cust is initial.
delete it_cust index 1.
*to process the data
loop at it_cust into wa_cust.
*to add the leading zeros
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = wa_cust-ktokd
importing
output = wa_cust-ktokd
.
*To get the sceen and field details of the transaction
* 1st screen details
perform fill_bdcdata using 'SAPMF02D' '0100' 'X' '' ''.