Session Method:
1. Asynchronous Processing.
2. Synchronous database updates.
3. Transfer of data for multiple
transactions. Using FM bdc_insert.
4. As compared to call transaction, this is
slow.
5. Best suited for bulk transfer.
6. Automatic error handling.
7. Error logs are created.
8. The value of sy-subrc is never returned.
Because records are stored temporary in session and after the records are
updated to the database.
9. You can store the sessions and it can be used for later processing.
10.
it can handle small amount of data as well as large amount of data.
11. Function modules :
F4_FILENAME ( Open the legacy
file [.txt or .xls]) .
TEXT_CONVERT_XSL_TO_SAP (
Convert the .xls file to sap format) : Using for only .xls files.
GUI_UPLOAD : Using for only .txt files.
BDC_OPEN_GROUP : To create a
new session.(No session 1).
BDC_INSERT : To add a
transaction to a batch input session.
BDC_CLOSE_GROUP : To close the
session.
1) The first step in the program is to do the recording. Recording is the process in which we record the steps by means of codes. So after doing recording a file will be generated. We use this file or I should say codes in our program. Then the question arises that why we need to do the recording and get the file?? The answer is that bdc is done when we have to upload a large no of data in sap like 1000’s or more , and creating these many entries one by one manually is not possible .so in bdc what we do is we create one entry manually and record the process . this recording is used in the program in a loop to make rest of the entries.just the values will be different each time.
So for creating a recording the do following steps-
A) Go to transaction “ SHDB”. you will get following screen
B) click on “ NEW RECORDING” u will get this window. Fill the name of recording in the first , I have given name “DEMO1”. In the 2nd field i.e transaction code give the name of the transaction which is to be performed, I have given “MM01” which is for creating materials. Then click “START RECORDING”.
C) I will show the recording of MM01 .
I have selected the following. then press enter to move to 2nd screen.
Select “BASIC DATA 1”. Click ok.
Next screen will be like this.
Fill in following fields.
Press enter. The recording will be generated. now Click on “ SAVE” and then on “BACK” buttons at the top.
d) Now select the recording and click on “PROGRAM”.
e) Now give the name of a program(new one). And click on OK.
Give description of program and click on “ SOURCE CODE” at the bottom.
f) The Following code will get copied in the program.
2) Now we have to do the coding part. The first thing that is to be done is that at the top one include will be there naming “BDCRECX1” this is standard include. we will not use this perform so we will get the useful things from this perform and will delete this perform. we will also delete the parameter “ DATASET” as we will not use it. So We have to go inside the include and scroll to bottom . There bottom two performs we have to copy and paste in the main program. Then delete the include. in one perform there will be “ NO DATA” delete it and give ‘ ‘. As highlighted.
4) We have to declare data type for the bdc .Like this
5) Now we will declare the internal tables and work areas .
Here the 1st one will be used for a function module which will allow us to select the excel file from presentation server(desktop).
2nd and 3rd are for storing the data.
6) This structure will be used in the function module which will bring data from excel sheet to internal table.
7) Creating selection screen. Here no need to remember the parameter type just go inside the function “F4_FILENAME” and see the export parameter type it is “IBIPPARMS-PATH” so we are using it.
8) Calling function to give option to select excel file from desktop.
9) Calling function to bring data from excel sheet to internal table.
10) Use the function module " BDC_OPEN_GROUP ". In the field "GROUP" give any name which will be the name of the session.
11) Logic for loop and use of recording
12) Replace the hard-coding starting from “RECORD” to field of work area. like this
13) Use function module "BDC_INSERT"
14) Call function module " BDC_CLOSE_GROUP"
15)
Now prepare the excel sheet. I will use this
excel file
16)
Run program .Then go to "SM35" for Session Overview. Line select your
Program and press the Button "PROCESS".
We will get the 3
options for Processing
1. Foreground
- Step by step processing will be done by you.
2. Background
– All the Processing will be done in Background.
3. Display
Error – If there is any error, it will be displayed in log otherwise it is
similar to background mode.
Select the mode from
radio button and press ‘Process’ button
Following information
message will be displayed if processing is successfully completed.we can press "SESSION OVERVIEW" for details of the session.
In case of any Error
we can go to the log and check the error message from
the "LOG" button as shown below.
we will get the following screen.
17) we can go to "MM03" and check the material created.
18) Full program code-
TYPES : BEGIN OF ty_excel,
mbrsh TYPE mbrsh,
mtart TYPE mtart,
maktx TYPE maktx,
matkl TYPE matkl,
meins TYPE meins,
END OF ty_excel.
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA:
gv_name TYPE rlgrap-filename,
git_upl TYPE STANDARD TABLE OF ty_excel,
gwa_upl TYPE ty_excel.
TYPES: FS_STRUCT(4096) TYPE C OCCURS 0.
DATA: G_DAT TYPE FS_STRUCT .
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_file TYPE ibipparms-path.
SELECTION-SCREEN END OF BLOCK b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
* FIELD_NAME = ' '
IMPORTING
file_name = p_file.
gv_name = p_file.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
* I_LINE_HEADER =
I_TAB_RAW_DATA = G_DAT
I_FILENAME = p_file
TABLES
I_TAB_CONVERTED_DATA = gIT_upl
* 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.
start-of-selection.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = 'AKS'
KEEP = 'X'
USER = SY-UNAME
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.
START-OF-SELECTION.
LOOP AT gIT_upl INTO gWA_upl.
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RMMG1-MBRSH'
gwa_upl-mbrsh."record-MBRSH_001.
perform bdc_field using 'RMMG1-MTART'
gwa_upl-mtart."record-MTART_002.
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
'X'."record-KZSEL_01_003.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
gwa_upl-maktx."record-MAKTX_004.
perform bdc_field using 'BDC_CURSOR'
'MARA-MATKL'.
perform bdc_field using 'MARA-MEINS'
gwa_upl-meins."record-MEINS_005.
perform bdc_field using 'MARA-MATKL'
gwa_upl-matkl."record-MATKL_006.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'MM01'
* POST_LOCAL = NOVBLOCAL
* PRINTING = NOPRINT
* SIMUBATCH = ' '
* CTUPARAMS = ' '
TABLES
DYNPROTAB = BDCDATA
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7
.
REFRESH BDCDATA.
ENDLOOP.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA .
ENDFORM. "BDC_DYNPRO
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA .
ENDFORM. "BDC_FIELD
mbrsh TYPE mbrsh,
mtart TYPE mtart,
maktx TYPE maktx,
matkl TYPE matkl,
meins TYPE meins,
END OF ty_excel.
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA:
gv_name TYPE rlgrap-filename,
git_upl TYPE STANDARD TABLE OF ty_excel,
gwa_upl TYPE ty_excel.
TYPES: FS_STRUCT(4096) TYPE C OCCURS 0.
DATA: G_DAT TYPE FS_STRUCT .
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_file TYPE ibipparms-path.
SELECTION-SCREEN END OF BLOCK b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
* FIELD_NAME = ' '
IMPORTING
file_name = p_file.
gv_name = p_file.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
* I_LINE_HEADER =
I_TAB_RAW_DATA = G_DAT
I_FILENAME = p_file
TABLES
I_TAB_CONVERTED_DATA = gIT_upl
* 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.
start-of-selection.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = 'AKS'
KEEP = 'X'
USER = SY-UNAME
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.
START-OF-SELECTION.
LOOP AT gIT_upl INTO gWA_upl.
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RMMG1-MBRSH'
gwa_upl-mbrsh."record-MBRSH_001.
perform bdc_field using 'RMMG1-MTART'
gwa_upl-mtart."record-MTART_002.
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
'X'."record-KZSEL_01_003.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
gwa_upl-maktx."record-MAKTX_004.
perform bdc_field using 'BDC_CURSOR'
'MARA-MATKL'.
perform bdc_field using 'MARA-MEINS'
gwa_upl-meins."record-MEINS_005.
perform bdc_field using 'MARA-MATKL'
gwa_upl-matkl."record-MATKL_006.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'MM01'
* POST_LOCAL = NOVBLOCAL
* PRINTING = NOPRINT
* SIMUBATCH = ' '
* CTUPARAMS = ' '
TABLES
DYNPROTAB = BDCDATA
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7
.
REFRESH BDCDATA.
ENDLOOP.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA .
ENDFORM. "BDC_DYNPRO
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA .
ENDFORM. "BDC_FIELD
Nice
ReplyDeleteSir ... Apne BDC ke bare me jankari achchhi Di hai
ReplyDelete1XBET - Slingo Games
ReplyDeleteSlots Games · Game 카지노 Provider · 1XBET Hacksaw Casino 퍼스트카지노
First Casino Review | Is it legit and safe?
ReplyDeleteFirst Casino is rated 4.3 188bet out of 5 by our members and 45% of them said: "liked it". LCB 퍼스트카지노 has set up an 100% deposit match with First 제왕카지노 Casino Rating: 4.1 · Review by CasinoWow