Sunteți pe pagina 1din 51

WEL COME TO K-LABS PVT LTD CHITRADURGA

1. INTRODUCTION TO BDC 2. CALL TRASNACTION METHOD. 3. COMMON ERRORS in BDC AND SOLUTIONS. 4. BDC SESSION METHOD.

DATA transfer methods are divided as OUTBOUND and INBOUND. OUTBOUND: Transfer the data from the source system (SAP) to target system (External and internal). I.e. data from the SAP to SAP, NON SAP.

SAP

SAP

NON SAP

INBOUND: Data Transfer from External into SAP. I.e. data from the SAP, NON SAP to SAP.

Note: BDC IS AN INBOUND Technique.

Methods of Batch Input


SAP provides two basic methods for transferring legacy data in to the R/3 System. 1. Classical Batch Input method. 2. Call Transaction Method. Classical Batch Input method In this method an ABAP/4 program reads the external data to the SAP System and stores in a batch input session. After creating the session, you can run the session to execute the SAP transaction in it. This method uses the function modules BDC_ OPEN, BDC_INSERT and BDC_CLOSE Batch Input Session can be process in 3 ways 1. In the foreground 2. In the background 3. During processing, with error display You should process batch input sessions in the foreground or using the error display if you want to test the data transfer. If you want to execute the data transfer or test its performance, you should process the sessions in the background. Points to note about Classical Batch Input method

Asynchronous processing Transfer data for multiple transactions. Synchronous database update. A batch input process log is generated for each session. Session cannot be generated in parallel.

Call Transaction Method. In this method ABAP/4 program uses CALL TRANSACTION USING statement to run an SAP transaction. Entire batch input process takes place online in the program

10

11

STEP BY STEP PROCEDURE TO CREATE BDC: STEP 1. TYPE SHDB in command Prompt as shown below

STEP2: Choose New Recording or Press F5 from key board.

12

STEP3: Enter Recording Name, T-code (ex; XD01).

13

STEP4. Select START RECORDING. Then Initial Screen Pop Up

14

15

Click on Continue Button

16

STEP5: SAVE FIRST then Go BACK Recording screen Appears open new NOTEPAD. Enter required data into note pad as shown below

17

STEP6: CLICK YES And GO BACK.

STEP7: Select your record name Choose CREATE Program (Shift+F5)

18

STEP8: Enter program name

STEP9: Enter source code (F5).

19

STEP10: Double click on include. After entering into source code. Select start new screen and insert field code and go BACK Paste it your main Source code.

20

STEP11: Writing ABAP report to do data transfer


Now Four Steps in ABAP Editor: 1. Create an internal table for above fields in the report after Include bdcrecx1. 2. Next call upload function after start-of-selection 3. Put Loop after perform open group 4. Now replace the constants in perform statement within loop by internal table name With field name. Make the values used in recording in . Then Save, Activate

21

SOURCE CODE:
report ZSD_BDC_P no standard page heading line-size 255. *include bdcrecx1. *parameters: dataset(132) lower case.

22

*** DO NOT CHANGE - the generated data section - DO NOT CHANGE * * * If it is nessesary to change the data section use the rules: * 1.) Each definition of a field exists of two lines * 2.) The first line shows exactly the comment * '* data element: ' followed with the data element * which describes the field. * If you don't have a data element use the * comment without a data element name * 3.) The second line shows the fieldname of the * structure, the fieldname must consist of * a fieldname and optional the character '_' and * three numbers and the field length in brackets * 4.) Each field must be type C. * *** Generated data section with specific formatting - DO NOT CHANGE * data: begin of record occurs 0, * data element: KUN16 KUNNR_001(016), * data element: KTOKD KTOKD_002(004), * data element: KUN16 KUNNR_003(016), * data element: ANRED ANRED_004(015), * data element: NAME1_GP * NAME1_005(035), * data element: SORTL * SORTL_006(010), * data element: STRAS_GP STRAS_007(035), * data element: PFACH * PFACH_008(010), * data element: ORT01_GP * ORT01_009(035), * data element: PSTLZ PSTLZ_010(010), * data element: LAND1_GP * LAND1_011(003), * data element: REGIO REGIO_012(003), * data element: SPRAS * SPRAS_013(002), * data element: TELF1 TELF1_014(016), end of record. *** End generated data section *** start-of-selection. data : BDCDATA type table of bdcdata with header line. ***perform open_dataset using dataset. ***perform open_group. *** ***do.

**

**

23

perform GET_DATA. perform UPLOAD. *read dataset dataset into record. *if sy-subrc <> 0. exit. endif. form mapping. perform bdc_dynpro perform bdc_field perform bdc_field perform bdc_field perform bdc_field perform bdc_dynpro perform bdc_field perform bdc_dynpro perform bdc_field perform bdc_field perform bdc_field *perform bdc_field * *perform bdc_field * perform bdc_field *perform bdc_field * *perform bdc_field * perform bdc_field *perform bdc_field * perform bdc_field *perform bdc_field * perform bdc_field using 'SAPMF02D' '0100'. '0100'. using 'BDC_CURSOR' 'RF02D-KUNNR'. 'RF02D-KUNNR'. using 'BDC_OKCODE' '/00'. '/00'. using 'RF02D-KUNNR' record-KUNNR_001. using 'RF02D-KTOKD' record-KTOKD_002. using 'SAPMF02D' '7100'. '7100'. using 'RF02D-KUNNR' record-KUNNR_003. using 'SAPMF02D' '0110'. '0110'. using 'BDC_CURSOR' 'KNA1-TELF1'. 'KNA1-TELF1'. using 'BDC_OKCODE' 'UPDA'. 'UPDA'. using 'KNA1-ANRED' record-ANRED_004. using 'KNA1-NAME1' record-NAME1_005. using 'KNA1-SORTL' record-SORTL_006. using 'KNA1-STRAS' record-STRAS_007. using 'KNA1-PFACH' record-PFACH_008. using 'KNA1-ORT01' record-ORT01_009. using 'KNA1-PSTLZ' record-PSTLZ_010. using 'KNA1-LAND1' record-LAND1_011. using 'KNA1-REGIO' record-REGIO_012. using 'KNA1-SPRAS' record-SPRAS_013. using 'KNA1-TELF1' record-TELF1_014.

endform. *perform bdc_transaction using 'XD01'. *********enddo. ********* *********perform close_group. form get_data. CALL FUNCTION 'GUI_UPLOAD' EXPORTING

24

FILENAME ='C:\Documents and Settings\USER\Des ktop\bdc.txt' FILETYPE = 'ASC' HAS_FIELD_SEPARATOR = '#' * HEADER_LENGTH = 0 * READ_BY_LINE = 'X' * DAT_MODE = ' ' * CODEPAGE = ' ' * IGNORE_CERR = ABAP_TRUE * REPLACEMENT = '#' * CHECK_BOM = ' ' * VIRUS_SCAN_PROFILE = * NO_AUTH_CHECK = ' ' * IMPORTING * FILELENGTH = * HEADER = TABLES DATA_TAB = record * 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. * Implement suitable error handling here ENDIF.

*CALL FUNCTION 'UPLOAD' * EXPORTING ** CODEPAGE * FILENAME * FILETYPE ** ITEM ** FILEMASK_MASK ** FILEMASK_TEXT ** FILETYPE_NO_CHANGE ** FILEMASK_ALL ** FILETYPE_NO_SHOW ** LINE_EXIT ** USER_FORM ** USER_PROG

= ' ' = '' = 'DAT' = ' ' = ' ' = ' ' = ' ' = ' ' = ' ' = ' ' = ' ' = ' '

25

** SILENT = 'S' ** IMPORTING ** FILESIZE = ** CANCEL = ** ACT_FILENAME = ** ACT_FILETYPE = * TABLES * DATA_TAB = Record ** EXCEPTIONS ** CONVERSION_ERROR = 1 ** INVALID_TABLE_WIDTH = 2 ** INVALID_TYPE = 3 ** NO_BATCH = 4 ** UNKNOWN_ERROR = 5 ** GUI_REFUSE_FILETRANSFER = 6 ** OTHERS = 7 * . *IF SY-SUBRC <> 0. ** Implement suitable error handling here *ENDIF. **perform close_dataset using dataset. endform. FORM BDC_DYNPRO USING PROGRAM DYNPRO. CLEAR BDCDATA. BDCDATA-PROGRAM = PROGRAM. BDCDATA-DYNPRO = DYNPRO. BDCDATA-DYNBEGIN = 'X'. 'X'. APPEND BDCDATA. ENDFORM. *---------------------------------------------------------------------* * Insert field * *---------------------------------------------------------------------* FORM BDC_FIELD USING FNAM FVAL. IF FVAL <> SPACE. "NODATA. CLEAR BDCDATA. BDCDATA-FNAM = FNAM. BDCDATA-FVAL = FVAL. APPEND BDCDATA. ENDIF. ENDFORM. *&--------------------------------------------------------------------* *& Form UPLOAD *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * --> p1 text * <-- p2 text *---------------------------------------------------------------------* FORM UPLOAD.

26

loop at record. refresh bdcdata. perform mapping. call transaction 'XD01' using bdcdata update 'S' mode 'A'. 'A'. endloop. ENDFORM. " UPLOAD

Input:

Output:

27

ERROR HANDLING IN CALL TRASACTION METHOD:

28

2.

29

Solution:

30

3.

31

32

7.

Solution;

10.

33

Solution:

12,

34

Solutions.

FORM UPLOAD . loop at record. refresh bdcdata. perform mapping. call transaction 'XD01' using bdcdata update 'S' mode 'A'. 'A'. endloop. ENDFORM.

35

Difference between CALL TRANSACTION and SESSION Method


Call Transaction method Classical or session method

In this method, the ABAP/4 program uses the call transaction <T-code > using <bdc_tab> mode <mode> update <update > method.

In this method, ABAP/4 program read the external data that is to be entered to the SAP system and stores the data in the batch input session. When the prgm has finished creating the session, we can run the session thro the TC SM35. This method involves FM like BDC_OPEN,BDC_INSERT,BDC_CLOSE

In Call Transaction, the transactions are triggered at the time of processing itself and so the ABAP program must do the error handling.

Synchronous Processing

Whereas in Batch Input Sessions, the ABAP program creates a session with all the transactional data, and this session can be viewed, scheduled and processed (using Transaction SM35) at a later time. The latter technique has a built-in error processing mechanism too. Asynchronous Processing

We can update the database both synchronously and asynchronously. We can specify the mode in the program.

Synchronous Database update. During processing, no transaction is started until the previous transaction has been written to the database.

No batch input processing log

Detailed Log will be generated for all the sessions

While execution it starts from the first.

While executing it wont start from the first. It will start from the place where it ends with error.

36

Faster than session method

Not as fast as call transaction method

BDC Session - Automatic Execution from Report


When to Use: Upload programs where you use BDC session method to create Sessions, which should later be executed using transaction SM35. Requirements before you start: You need to know the BDC Session name, which is usually an input parameter or is generated by the report programs. Steps to execute BDC Session from the program: Step 1: Get BDC Queue ID CALL FUNCTION 'BDC_OBJECT_SELECT' EXPORTING name = session name session_creator = sy-uname datatype = 'BDC' client = sy-mandt qstate ='' date_from = sy-datum date_to = sy-datum TABLES apqitab = itab_apqi EXCEPTIONS OTHERS = 1. Queue ID (QID) = itab_apqi-qid Step 2: Get Session Info Get Session info for the queue ID from table APQI. SELECT SINGLE * FROM apqi INTO session WHERE qid = QID (from Step 1). Step3: Lock BDC Queue CALL FUNCTION 'ENQUEUE_BDC_QID' EXPORTING datatyp = session-datatyp groupid = session-groupid qid = session-qid EXCEPTIONS foreign_lock = 1 system_failure = 99. 37

Step4: OPEN JOB DATA: jobname LIKE tbtco-jobname, jobnumb LIKE rsjobinfo-jobnumb, Jobname = wa_session-groupid. CALL FUNCTION 'JOB_OPEN' EXPORTING jobgroup = 'BATCH-INPUT' jobname = jobname sdlstrtdt = sy-datum sdlstrttm = sy-uzeit IMPORTING jobcount = jobnumb EXCEPTIONS cant_create_job = 1 invalid_job_data = 2 jobname_missing = 3 OTHERS = 99. Step5: Execute the Queue Execute the QUEUE using Submit to Report RSBDCBTC. SUBMIT rsbdcbtc TO SAP-SPOOL DESTINATION space IMMEDIATELY space KEEP IN SPOOL space WITHOUT SPOOL DYNPRO USER session-userid VIA JOB jobname NUMBER jobnumb WITH queue_id EQ wa_session-qid WITH mappe EQ jobname WITH modus EQ 'N' WITH logall EQ 'X' " Extended Log AND RETURN. If Sy-subrc = 0 Step6: Close Job CALL FUNCTION 'JOB_CLOSE' EXPORTING jobcount = jobnumb jobname = jobname strtimmed = 'X' targetsystem = '' " Target Host EXCEPTIONS

38

cant_start_immediate =1 invalid_startdate =2 jobname_missing =3 job_close_failed =4 job_nosteps =5 job_notex =6 lock_failed =7 OTHERS = 99. IF sy-subrc = 0 Step 7: Update Session info UPDATE apqi SET qstate = 'S' WHERE destsys = wa_session-destsys AND destapp = wa_session-destapp AND datatyp = wa_session-datatyp AND groupid = wa_session-groupid AND progid = wa_session-progid AND formid = wa_session-formid AND qattrib = wa_session-qattrib AND qid = wa_session-qid. COMMIT WORK.

Step 8: Delete Job If Job Not closed (Sy-subrc <> 0 for step 5 or 6), delete Job. CALL FUNCTION 'BP_JOB_DELETE' EXPORTING jobname = jobname jobcount = jobnumb forcedmode = 'X' EXCEPTIONS OTHERS = 99. Step 9: Unlock BDC queue CALL FUNCTION 'DEQUEUE_BDC_QID' EXPORTING datatyp = wa_session-datatyp groupid = wa_session-groupid qid = wa_session-qid.

39

BDC SESSION METHOD STEPS: 1.T CODE SHDB. 2.

3.

5.

40

7.

41

9 10.SOURCE CODE FOR BDC SESSION METHOD.

REPORT ZBDCREC1 NO STANDARD PAGE HEADING LINE-SIZE 255. * *include bdcrecx1. * *parameters: dataset(132) lower case. *** DO NOT CHANGE - the generated data section - DO NOT CHANGE * * * If it is nessesary to change the data section use the rules: * 1.) Each definition of a field exists of two lines * 2.) The first line shows exactly the comment * '* data element: ' followed with the data element * which describes the field. * If you don't have a data element use the * comment without a data element name * 3.) The second line shows the fieldname of the * structure, the fieldname must consist of

**

42

* a fieldname and optional the character '_' and * three numbers and the field length in brackets * 4.) Each field must be type C. * *** Generated data section with specific formatting - DO NOT CHANGE * DATA: BEGIN OF RECORD OCCURS 0, * data element: LIF16 LIFNR_001(016), * data element: KTOKK KTOKK_002(004), * data element: ANRED ANRED_003(015), * data element: NAME1_GP NAME1_004(035), * data element: SORTL SORTL_005(010), * data element: LAND1_GP LAND1_006(003), * data element: REGIO REGIO_007(003), * data element: SPRAS SPRAS_008(002), END OF RECORD. *** End generated data section *** DATA: BDCDATA TYPE TABLE OF BDCDATA WITH HEADER LINE. START-OF-SELECTION. PERFORM UPLOAD. PERFORM OPEN_GROUP. * * DO. * * READ DATASET DATASET INTO RECORD. * IF SY-SUBRC <> 0. EXIT. ENDIF. LOOP AT RECORD. REFRESH BDCDATA. PERFORM BDC_DYNPRO PERFORM BDC_FIELD PERFORM BDC_FIELD PERFORM BDC_FIELD PERFORM BDC_FIELD USING 'SAPMF02K' '0100'. USING 'BDC_CURSOR' 'RF02K-KTOKK'. USING 'BDC_OKCODE' '/00'. USING 'RF02K-LIFNR' RECORD-LIFNR_001. USING 'RF02K-KTOKK'

**

43

* *

RECORD-KTOKK_002. USING 'SAPMF02K' '0110'. USING 'BDC_CURSOR' 'LFA1-SPRAS'. PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'. PERFORM BDC_FIELD USING 'LFA1-ANRED' RECORD-ANRED_003. PERFORM BDC_FIELD USING 'LFA1-NAME1' RECORD-NAME1_004. PERFORM BDC_FIELD USING 'LFA1-SORTL' RECORD-SORTL_005. PERFORM BDC_FIELD USING 'LFA1-LAND1' RECORD-LAND1_006. PERFORM BDC_FIELD USING 'LFA1-REGIO' RECORD-REGIO_007. PERFORM BDC_FIELD USING 'LFA1-SPRAS' RECORD-SPRAS_008. PERFORM BDC_DYNPRO USING 'SAPMF02K' '0120'. PERFORM BDC_FIELD USING 'BDC_CURSOR' 'LFA1-KUNNR'. PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'. PERFORM BDC_DYNPRO USING 'SAPMF02K' '0130'. PERFORM BDC_FIELD USING 'BDC_CURSOR' 'LFBK-BANKS(01)'. PERFORM BDC_FIELD USING 'BDC_OKCODE' '=ENTR'. PERFORM BDC_DYNPRO USING 'SAPMF02K' '0380'. PERFORM BDC_FIELD USING 'BDC_CURSOR' 'KNVK-NAMEV(01)'. PERFORM BDC_FIELD USING 'BDC_OKCODE' '=ENTR'. PERFORM BDC_TRANSACTION USING 'XK01'. PERFORM BDC_DYNPRO PERFORM BDC_FIELD ENDDO.

PERFORM INSERT. ENDLOOP. PERFORM CLOSE_GROUP. * PERFORM CLOSE_DATASET USING DATASET. *&--------------------------------------------------------------------* *& Form BDC_DYNPRO *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * -->PROGRAM text * -->DYNPRO text *---------------------------------------------------------------------* FORM BDC_DYNPRO USING PROGRAM DYNPRO.

44

CLEAR BDCDATA. BDCDATA-PROGRAM = PROGRAM. BDCDATA-DYNPRO = DYNPRO. BDCDATA-DYNBEGIN = 'X'. APPEND BDCDATA. ENDFORM. "BDC_DYNPRO *---------------------------------------------------------------------* * Insert field * *---------------------------------------------------------------------* FORM BDC_FIELD USING FNAM FVAL. IF FVAL <> SPACE. CLEAR BDCDATA. BDCDATA-FNAM = FNAM. BDCDATA-FVAL = FVAL. APPEND BDCDATA. ENDIF. ENDFORM. "BDC_FIELD *&--------------------------------------------------------------------* *& Form OPEN_GROUP *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * --> p1 text * <-- p2 text *---------------------------------------------------------------------* FORM OPEN_GROUP . CALL FUNCTION 'BDC_OPEN_GROUP' EXPORTING CLIENT = SY-MANDT * DEST = FILLER8 GROUP = 'GROUP_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

45

* * * *

RUNNING = 8 SYSTEM_LOCK_ERROR = 9 USER_INVALID = 10 OTHERS = 11 . IF SY-SUBRC <> 0. * Implement suitable error handling here ENDIF. ENDFORM. " OPEN_GROUP *&--------------------------------------------------------------------* *& Form UPLOAD *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * --> p1 text * <-- p2 text *---------------------------------------------------------------------* FORM UPLOAD . CALL FUNCTION 'GUI_UPLOAD' EXPORTING FILENAME = 'C:\Documents and Settings\Knowledg e\Desktop\XK01.TXT' FILETYPE = 'DAT' * HAS_FIELD_SEPARATOR = ' ' * HEADER_LENGTH = 0 * READ_BY_LINE = 'X' * DAT_MODE = ' ' * CODEPAGE = ' ' * IGNORE_CERR = ABAP_TRUE * REPLACEMENT = '#' * CHECK_BOM = ' ' * VIRUS_SCAN_PROFILE = * NO_AUTH_CHECK = ' ' * IMPORTING * FILELENGTH = * HEADER = TABLES DATA_TAB = RECORD * 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

46

* * * * *

ACCESS_DENIED = DP_OUT_OF_MEMORY = DISK_FULL = DP_TIMEOUT = OTHERS = . IF SY-SUBRC <> 0. * Implement suitable error handling ENDIF.

13 14 15 16 17 here

ENDFORM. " UPLOAD *&--------------------------------------------------------------------* *& Form INSERT *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * --> p1 text * <-- p2 text *---------------------------------------------------------------------* FORM INSERT . CALL FUNCTION 'BDC_INSERT' EXPORTING TCODE = 'XK01' * 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 . IF SY-SUBRC <> 0. * Implement suitable error handling here ENDIF. ENDFORM. " INSERT *&--------------------------------------------------------------------* *& Form CLOSE_GROUP *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * --> p1 text

47

* <-- p2 text *---------------------------------------------------------------------* FORM 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. " CLOSE_GROUP

11.T CODE SM35 Batch Input Session Overview

12.

48

T CODE SM36 13.

Enter continue

Enter continue.

49

Click Enter 3 Times which Results in Following Screen.

15. T CODE SM37 Simple Job Selection

50

16.

51

S-ar putea să vă placă și