Anda di halaman 1dari 24

BDC with Session Method

Scenario: Uploading customer master records to SAP system by BDC session method.
Session Method:
Session method is always synchronous.
Message is handled automatically by the session log.
Mostly used for huge amount of data upload.
Multiple Trasactions can be processed by a single session method.
Step1. The recording of XD01 (Customer Master Creation ) from SHDB transaction is given below.

[http://3.bp.blogspot.com/-rPp67zDhQp4/UsjVyVqpMII/AAAAAAAAGmo/t_Mx73tL_mM/s1600/25.jpg]

Step2. Go to SE38 and create a report program for bdc session method.

[http://2.bp.blogspot.com/mKGi3gWWxyg/UskT1SDyFII/AAAAAAAAGqg/W_qBY5FJIUE/s1600/26.JPG]

Step3. Provide the below code & activate the program.


______________ __________________________________________________________________
*&---------------------------------------------------------------------*
*& Report ZBDC_SESSION_METH_CUST_MASTER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zbdc_session_meth_cust_master.
TYPES : BEGIN OF ty_cust,
comp_code TYPE bukrs,
sales_org TYPE vkorg,
dist_chnl TYPE vtweg,
divi TYPE spart,
acc_grp TYPE ktokd,
title TYPE anred,
land TYPE land1,
region TYPE regio,
lang TYPE spras,
ord_prob TYPE awahr,
curr TYPE waers,
del_prio TYPE lprio,
shipp_cond TYPE vsbed,
delv_plant TYPE vwerk,
END OF ty_cust.
DATA : lt_excel TYPE TABLE OF alsmex_tabline,
ls_excel TYPE alsmex_tabline,
lt_cust TYPE TABLE OF ty_cust,
ls_cust TYPE ty_cust,
lt_bdc TYPE TABLE OF bdcdata,
ls_bdc TYPE bdcdata,
session_name TYPE apqi-groupid.
PARAMETERS : path TYPE rlgrap-filename OBLIGATORY DEFAULT 'C:\Users\ratn\Desktop\bdc with call
transaction\LEAGCY CUST RECORD'.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR path .
CALL FUNCTION 'F4_FILENAME'
EXPORTING

program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'PATH'
IMPORTING
file_name = path.
START-OF-SELECTION.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename
= path
i_begin_col
=1
i_begin_row
=2
i_end_col
= 50
i_end_row
= 50
TABLES
intern
= lt_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole
=2
OTHERS
= 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
LOOP AT lt_excel INTO ls_excel.
CASE ls_excel-col.
WHEN '001'.
ls_cust-comp_code = ls_excel-value.
WHEN '002'.
ls_cust-sales_org = ls_excel-value.
WHEN '003'.
ls_cust-dist_chnl = ls_excel-value.
WHEN '004'.
ls_cust-divi = ls_excel-value.
WHEN '005'.
ls_cust-acc_grp = ls_excel-value.
WHEN '006'.
ls_cust-title = ls_excel-value.
WHEN '007'.
ls_cust-land = ls_excel-value.
WHEN '008'.
ls_cust-region = ls_excel-value.
WHEN '009'.
ls_cust-lang = ls_excel-value.
WHEN '010'.
ls_cust-ord_prob = ls_excel-value.
WHEN '011'.
ls_cust-curr = ls_excel-value.
WHEN '012'.
ls_cust-del_prio = ls_excel-value.

WHEN '013'.
ls_cust-shipp_cond = ls_excel-value.
WHEN '014'.
ls_cust-delv_plant = ls_excel-value.
WHEN OTHERS.
ENDCASE.
AT END OF row.
APPEND ls_cust TO lt_cust.
CLEAR : ls_cust, ls_excel.
ENDAT.
ENDLOOP.
PERFORM bdc_open_group.
PERFORM bdc_create_group.
PERFORM bdc_close_group.

*&---------------------------------------------------------------------*
*&
Form BDC_OPEN_GROUP
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM bdc_open_group .
CONCATENATE sy-datum sy-uzeit INTO session_name .
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client
= sy-mandt
* DEST
= FILLER8
group
= session_name
* HOLDDATE
= FILLER8
keep
= 'x'
user
= sy-uname
* RECORD
= FILLER1
prog
= sy-cprog
* DCPFM
= '%'
* DATFM
= '%'
* IMPORTING
* 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 sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
" BDC_OPEN_GROUP
*&---------------------------------------------------------------------*
*&
Form BDC_CREATE_GROUP
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM bdc_create_group .
IF lt_cust IS NOT INITIAL.
LOOP AT lt_cust INTO ls_cust.
PERFORM : call_screen USING 'SAPMF02D' '0100' 'X'.
PERFORM : fill_screen USING 'BDC_CURSOR' 'RF02D-KTOKD'.
PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.
PERFORM : fill_screen USING 'RF02D-BUKRS' ls_cust-comp_code.
PERFORM : fill_screen USING 'RF02D-VKORG' ls_cust-sales_org.
PERFORM : fill_screen USING 'RF02D-VTWEG' ls_cust-dist_chnl.
PERFORM : fill_screen USING 'RF02D-SPART' ls_cust-divi.
PERFORM : fill_screen USING 'RF02D-KTOKD' ls_cust-acc_grp.
PERFORM : call_screen USING 'SAPMF02D' '0110' 'X'.
PERFORM : fill_screen USING 'BDC_CURSOR' 'KNA1-SPRAS'.
PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.
PERFORM : fill_screen USING 'KNA1-ANRED' ls_cust-title.
PERFORM : fill_screen USING 'KNA1-LAND1' ls_cust-land.
PERFORM : fill_screen USING 'KNA1-REGIO' ls_cust-region.
PERFORM : fill_screen USING 'KNA1-SPRAS' ls_cust-lang.
PERFORM : call_screen USING 'SAPMF02D' '0120' 'X'.
PERFORM : fill_screen USING 'BDC_CURSOR' 'KNA1-LIFNR'.
PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.
PERFORM : call_screen USING 'SAPMF02D' '0125' 'X'.
PERFORM : fill_screen USING 'BDC_CURSOR' 'KNA1-NIELS'.
PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.
PERFORM : call_screen USING 'SAPMF02D' '0130' 'X'.
PERFORM : fill_screen USING 'BDC_CURSOR' 'KNBK-BANKS(01)'.
PERFORM : fill_screen USING 'BDC_OKCODE' '=ENTR'.
PERFORM : call_screen USING 'SAPMF02D' '0340' 'X'.
PERFORM : fill_screen USING 'BDC_CURSOR' 'KNVA-ABLAD(01)'.

PERFORM : fill_screen USING 'BDC_OKCODE' '=ENTR'.


PERFORM : call_screen USING 'SAPMF02D' '0370' 'X'.
PERFORM : fill_screen USING 'BDC_CURSOR' 'KNEX-LNDEX(01)'.
PERFORM : fill_screen USING 'BDC_OKCODE' '=ENTR'.
PERFORM : fill_screen USING 'KNA1-CIVVE' 'X'.
PERFORM : call_screen USING 'SAPMF02D' '0360' 'X'.
PERFORM : fill_screen USING 'BDC_CURSOR' 'KNVK-NAMEV(01)'.
PERFORM : fill_screen USING 'BDC_OKCODE' '=ENTR'.
PERFORM : call_screen USING 'SAPMF02D' '0210' 'X'.
PERFORM : fill_screen USING 'BDC_CURSOR' 'KNB1-AKONT'.
PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.
PERFORM : call_screen USING 'SAPMF02D' '0215' 'X'.
PERFORM : fill_screen USING 'BDC_CURSOR' 'KNB1-ZTERM'.
PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.
PERFORM : call_screen USING 'SAPMF02D' '0220' 'X'.
PERFORM : fill_screen USING 'BDC_CURSOR' 'KNB5-MAHNA'.
PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.
PERFORM : call_screen USING 'SAPMF02D' '0230' 'X'.
PERFORM : fill_screen USING 'BDC_CURSOR' 'KNB1-VRSNR'.
PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.
PERFORM : call_screen USING 'SAPMF02D' '0310' 'X'.
PERFORM : fill_screen USING 'BDC_CURSOR' 'KNVV-BZIRK'.
PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.
PERFORM : fill_screen USING 'KNVV-AWAHR' ls_cust-ord_prob.
PERFORM : fill_screen USING 'KNVV-WAERS' ls_cust-curr.

PERFORM : call_screen USING 'SAPMF02D' '0315' 'X'.


PERFORM : fill_screen USING 'BDC_CURSOR' 'KNVV-VWERK'.
PERFORM : fill_screen USING 'BDC_OKCODE' '/00'.
PERFORM : fill_screen USING 'KNVV-LPRIO' ls_cust-del_prio.
PERFORM : fill_screen USING 'KNVV-KZAZU' 'X'.
PERFORM : fill_screen USING 'KNVV-VSBED' ls_cust-shipp_cond.
PERFORM : fill_screen USING 'KNVV-VWERK' ls_cust-delv_plant.
PERFORM : fill_screen USING 'KNVV-ANTLF' '9'.
PERFORM : call_screen USING 'SAPMF02D' '0320' 'X'.
PERFORM : fill_screen USING 'BDC_CURSOR' 'KNVV-PERFK'.
PERFORM : fill_screen USING 'BDC_OKCODE' '=ENTS'.
PERFORM : call_screen USING 'SAPMF02D' '1350' 'X'.
PERFORM : fill_screen USING 'BDC_CURSOR' 'KNVI-TAXKD(01)'.
PERFORM : fill_screen USING 'BDC_OKCODE' '=ENTR'.

PERFORM : call_screen USING 'SAPMF02D' '0324' 'X'.


PERFORM : fill_screen USING 'BDC_CURSOR' '*TPART-VTEXT(01)'.
PERFORM : fill_screen USING 'BDC_OKCODE' '=ENTR'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode
= 'XD01'
*
POST_LOCAL
= NOVBLOCAL
*
PRINTING
= NOPRINT
*
SIMUBATCH
=''
*
CTUPARAMS
=''
TABLES
dynprotab
= lt_bdc
EXCEPTIONS
internal_error = 1
not_open
=2
queue_error
=3
tcode_invalid = 4
printing_invalid = 5
posting_invalid = 6
OTHERS
= 7.
IF sy-subrc <> 0.
ENDIF.
ENDLOOP.
WRITE:/ 'Please check tcode- SM35 for the session: ', session_name.
ELSE.
MESSAGE 'No record to Upload' TYPE 'I'.
ENDIF.
ENDFORM.
" BDC_CREATE_GROUP
*&---------------------------------------------------------------------*
*&
Form BDC_CLOSE_GROUP
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM bdc_close_group .
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
not_open = 1
queue_error = 2
OTHERS
= 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
" BDC_CLOSE_GROUP
*&---------------------------------------------------------------------*
*&
Form CALL_SCREEN
*&---------------------------------------------------------------------*

*
text
*----------------------------------------------------------------------*
*
-->P_0273 text
*
-->P_0274 text
*
-->P_0275 text
*----------------------------------------------------------------------*
FORM call_screen USING pgm
dyn
dyn_bgn.
ls_bdc-program = pgm.
ls_bdc-dynpro = dyn.
ls_bdc-dynbegin = dyn_bgn.
APPEND ls_bdc TO lt_bdc.
CLEAR ls_bdc.
ENDFORM.
" CALL_SCREEN
*&---------------------------------------------------------------------*
*&
Form FILL_SCREEN
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_0625 text
*
-->P_0626 text
*----------------------------------------------------------------------*
FORM fill_screen USING nam
val.
ls_bdc-fnam = nam.
ls_bdc-fval = val.
APPEND ls_bdc TO lt_bdc.
CLEAR ls_bdc.
ENDFORM.
" FILL_SCREEN

_________________________________________________________________________________
Step 3.1. The excel file format should be as follows.

[http://2.bp.blogspot.com/-10KVwAyrN9M/UskUft12ZRI/AAAAAAAAGqo/PGifOs6fd_M/s1600/28.JPG]

Step4. Run the report and select the excel file and execute it.

[http://3.bp.blogspot.com/--vSNfjt19HU/UsjWZgrg6yI/AAAAAAAAGmw/Y9MJEvYZn6M/s1600/1.JPG]

Step5. The output of teh report is as follows.

[http://1.bp.blogspot.com/-cwBlEYQ2pCo/UsjWgoU1HrI/AAAAAAAAGoE/0Bl0MX8hxIg/s1600/2.JPG]

Step6. Go to SM35 tcode.

[http://2.bp.blogspot.com/-S-3YyJPZeAU/UsjWmeLJAKI/AAAAAAAAGo8/8aoqYU3zV7U/s1600/3.JPG]

Step7. Select the Session and clcik on the process button.

[http://3.bp.blogspot.com/-rXC7tyMrPzA/UsjWm62H41I/AAAAAAAAGpI/yVnS08idDb8/s1600/4.JPG]

Step8. Select the radio button as per necessary and click on Process button.

[http://4.bp.blogspot.com/-rRR0TCMO1dA/UsjWnxPRhyI/AAAAAAAAGpU/Pg76SUQ0mYs/s1600/5.JPG]

Step9. Hit Enter key from key board to continue.

[http://3.bp.blogspot.com/-JgngGbM-WkM/UsjWnhn-UTI/AAAAAAAAGpQ/t6d1_xAOgQ0/s1600/6.JPG]

Step10. Hit Enter key from key board to continue.

[http://2.bp.blogspot.com/-n5P1O7BK95k/UsjWovBJAyI/AAAAAAAAGpg/C_-HeezJNPE/s1600/7.JPG]

Step11.Hit Enter key from key board to continue.

No comments yet

Add a comment
[http://4.bp.blogspot.com/-SW0i2cZ3UM8/UsjWpf5JnKI/AAAAAAAAGpo/ateB6LT4VAk/s1600/8.JPG]

Step12.Hit Enter key from key board to continue.

[http://4.bp.blogspot.com/-T0DNVjlQVhQ/UsjWpk66HfI/AAAAAAAAGps/pHze1DL67CE/s1600/9.JPG]

Step13.Hit Enter key from key board to continue.

[http://3.bp.blogspot.com/-a0XoIsnJ8BE/UsjWbJELKZI/AAAAAAAAGm4/byJju1_e6OY/s1600/10.JPG]

Step14.Hit Enter key from key board to continue.

[http://3.bp.blogspot.com/-nx0gGAG5R5c/UsjWb06S9vI/AAAAAAAAGnA/v3gy9ldoZnI/s1600/11.JPG]

Step15. Hit Enter key from key board to continue.

[http://3.bp.blogspot.com/-Pgn9OhrsQrM/UsjWcJ2yqaI/AAAAAAAAGnM/gsfrtb8E2Kc/s1600/12.JPG]

Step16. Hit Enter key from key board to continue.

[http://4.bp.blogspot.com/-hiTIDdceGeM/UsjWcU7s2yI/AAAAAAAAGnI/ZLCiGB5seCI/s1600/13.JPG]

Step17. Hit Enter key from key board to continue.

[http://2.bp.blogspot.com/-VNM9QQcsBaQ/UsjWdLIC9rI/AAAAAAAAGnU/mjMeQLNY0QE/s1600/14.JPG]

Step18. Hit Enter key from key board to continue.

[http://4.bp.blogspot.com/-sXoiWKj3qCM/UsjWdqnFtsI/AAAAAAAAGng/yU0c_fav6Wg/s1600/15.JPG]

Step19. Hit Enter key from key board to continue.

[http://3.bp.blogspot.com/-LH4sDbqe-e4/UsjWeNtVOCI/AAAAAAAAGnk/r1WfEVkwtc8/s1600/16.JPG]

Step20. Hit Enter key from key board to continue.

[http://4.bp.blogspot.com/-GAgxyS2nXo8/UsjWe0aPLhI/AAAAAAAAGnw/45qyQm8A_wo/s1600/17.JPG]

Step21. Hit Enter key from key board to continue.

[http://3.bp.blogspot.com/-K39-hhRhtcY/UsjWgSKbyaI/AAAAAAAAGn4/GLO6v_pGp4E/s1600/18.JPG]

Step22.Hit Enter key from key board to continue.

[http://1.bp.blogspot.com/-9KLqzafHyGA/UsjWgbPK64I/AAAAAAAAGn8/Cx4PqhVTCqU/s1600/19.JPG]

Step23.Hit Enter key from key board to continue.

[http://1.bp.blogspot.com/-vkDZJIOwYsA/UsjWha624fI/AAAAAAAAGoM/wFAiVHE_aGQ/s1600/20.JPG]

Step24.Hit Enter key from key board to continue.

[http://4.bp.blogspot.com/-RomaA0ushDw/UsjWhyvWAKI/AAAAAAAAGoU/kv0sodV__ac/s1600/21.JPG]

Step25.Hit Enter key from key board to continue.

[http://1.bp.blogspot.com/-whXG_8zPTDQ/UsjWiRIwEUI/AAAAAAAAGog/UqEHgOQEWo4/s1600/22.JPG]

Step26.Hit Enter key from key board to continue. After processing all the reocrd the below screen will apprear. Now
to see the message log select the line and click on Analysis button.

[http://1.bp.blogspot.com/-WUekin9qJ-c/UsjWjlc9CfI/AAAAAAAAGoo/09JYNJAQWWc/s1600/23.JPG]

Step27. The The transaction XD01 is called thrice as our excel contained 3 records of customer master.

[http://3.bp.blogspot.com/-9E-TcVe0Vsc/UsjWjyHTWdI/AAAAAAAAGos/WRyUh_-CLAU/s1600/24.JPG]

Step28. Click on the third tab and it displays what are the customer numbers are created.
________________________________________________________________________________

[http://4.bp.blogspot.com/-lYml0LOUWnI/UsjWmK7UHuI/AAAAAAAAGo4/eTZQsIThmWY/s1600/25.JPG]

Posted 5th January 2014 by S Prasad


View comments