Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BDC/Batch Input common mistakes

Former Member
0 Likes
2,270

I need some examples of BDC/Batch Input common mistakes, and how to avoid them. If you got any ideas for DOs and DON'Ts in BDC/Batch Input, please answer me, and I'll be sure to give you reward points.

Edited by: Brian Gonsales on Mar 13, 2008 7:21 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,510

BATCH DATA COMMUNICATION

BDC is used to transfer data from SAP to SAP system or from a non-SAP system to SAP system.It uses the normal Transaction codes to transfer the data. This method is used to transfer large amounts of data that is available in electronic form.

There are two types of methods offered by SAP for BDC:

*Session Method*

The first method uses a session to process the data. Data to be fed to the BDC program is read from a flat file and is stored in a batch-input session. Then the session is processed or executed to migrate the data to the SAP system. This can be done using the tcode SM35. This method uses the function module BDC_OPEN, BDC_INSERT and BDC_CLOSE to

generate the sessions

*Call Transaction Method:*

In the second method, BDC uses the ABAP statement CALL TRANSACTION USING statement to run a transaction. Here the entire set of input data is processed immediately without creating any session.

Advantage of Session Method:

The primary advantage of Session Method is that once a session has been created, it can be processed at any convenient time by the user. It can also be scheduled to executed in background and then the statust of the session viewed once it gets completed.

Tcodes:

1) SHDB - Transaction Recorder.

2) SM35 - Batch Input - Session Overview.

BDC – Steps

Pre-Requisites

- Should have a screen program (Module Pool)

- Data should be able to be saved through the above mentioned program

- You should have the data to be uploaded in a flat file in the system.

 Note :

• Can use excel sheet to enter the data and save it as tab- delimited file.

• Note down the table names that will be affected.

Steps:

- Transaction : SHDB ( or use SM35 and click on Recording)

- New Recording

- Give a name in which recording has to be saved (Needn’t necessarily start

with ‘Z’)

- Enter Transaction Code (Transaction to upload data)

- Click Start Recording

- Enter the details and save the data and exit.

- A screen with saved data and the ok codes, cursor position … will be

shown. Save it.

- Click back button

- Click Program button after selecting the recording you have done.

- Enter a program name (Like that which we give in SM38)

- Select Radio button - Transfer from recording and Enter.

- Give Title and click Source code.

- Save the program.

- Define a structure in types (After Include …)

- Define an internal table and a work area in data part

- Define a variable of type string to store external file path

- Parameter has to be given to enter file name(type ibipparms-path)

- Enter ‘AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILE’ where FILE is the parameter given.

- Call function F4_FILENAME (through Patterns) and give file_name as FILE.

- Assign the FILE to the variable we declared with String type.

- Call function GUI_UPLOAD (through Patterns) and give filename as the variable and give ‘X’ for has field separator and give internal table as data_tab

- In start of selection after open_group…

- Loop at internal table to work area

- Clear bdcdata

- Endloop before close_group.

- Change the hard coded data (which came from recording) to the data from internal table.

- Activate and Execute

- Click on Call Transaction

- Select processing mode

- Remove NoDataIndicator

- Select file from which data has to be uploaded

- Execute

- Check table to check whether data is uploaded correctly

Recording Program

In the Source code some modifications are to be done.The modified Program is given below.Replace the code with this one and change the path of the text file as required in the ‘GUI_UPLOAD’ function call.Also in the first line change the name of the program.

Note : Replace the code with this one completely

REPORT zbdc_06

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

  • 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, " Add OCCURS 0 here

  • data element: ZACCNO

serial_001(008),

  • data element: ZNAME_TEST

name_002(015),

  • data element: ZAGE_TEST

age_003(003),

  • data element: ZACCNO

serial_004(008),

  • data element: ZNAME_TEST

name_005(015),

  • data element: ZAGE_TEST

age_006(003),

END OF record.

      • End generated data section ***

START-OF-SELECTION.

PERFORM read_legacy. " Create subroutine for

*perform open_dataset using dataset. "Comment Here

PERFORM open_group.

*do.

*read dataset dataset into record.

*if sy-subrc <> 0. exit. endif.

LOOP AT record. "Add LOOP AT RECORD

PERFORM bdc_dynpro USING 'SAPMZBDC_05' '9000'.

PERFORM bdc_field USING 'BDC_CURSOR'

'ZBDC_05-AGE'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=SAVE'.

PERFORM bdc_field USING 'ZBDC_05-SERIAL'

record-serial_001.

PERFORM bdc_field USING 'ZBDC_05-NAME'

record-name_002.

PERFORM bdc_field USING 'ZBDC_05-AGE'

record-age_003.

PERFORM bdc_dynpro USING 'SAPMZBDC_05' '9000'.

PERFORM bdc_field USING 'BDC_CURSOR'

'ZBDC_05-SERIAL'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BACK'.

PERFORM bdc_field USING 'ZBDC_05-SERIAL'

record-serial_004.

PERFORM bdc_field USING 'ZBDC_05-NAME'

record-name_005.

PERFORM bdc_field USING 'ZBDC_05-AGE'

record-age_006.

PERFORM bdc_transaction USING 'ZBDC_05'.

ENDLOOP. " Add ENDLOOP here

*enddo. "Comment here

PERFORM close_group.

*perform close_dataset using dataset. "Comment here

&----


*& Form read_legacy

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM read_legacy .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = 'c:\bdc\bdc.txt'

  • FILETYPE = 'ASC'

has_field_separator = '#'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • 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.

MESSAGE ID sy-msgid TYPE 'A' NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " read_legacy

Reward if useful.

Regards,

Neenu Jose

2 REPLIES 2
Read only

Former Member
0 Likes
1,511

BATCH DATA COMMUNICATION

BDC is used to transfer data from SAP to SAP system or from a non-SAP system to SAP system.It uses the normal Transaction codes to transfer the data. This method is used to transfer large amounts of data that is available in electronic form.

There are two types of methods offered by SAP for BDC:

*Session Method*

The first method uses a session to process the data. Data to be fed to the BDC program is read from a flat file and is stored in a batch-input session. Then the session is processed or executed to migrate the data to the SAP system. This can be done using the tcode SM35. This method uses the function module BDC_OPEN, BDC_INSERT and BDC_CLOSE to

generate the sessions

*Call Transaction Method:*

In the second method, BDC uses the ABAP statement CALL TRANSACTION USING statement to run a transaction. Here the entire set of input data is processed immediately without creating any session.

Advantage of Session Method:

The primary advantage of Session Method is that once a session has been created, it can be processed at any convenient time by the user. It can also be scheduled to executed in background and then the statust of the session viewed once it gets completed.

Tcodes:

1) SHDB - Transaction Recorder.

2) SM35 - Batch Input - Session Overview.

BDC – Steps

Pre-Requisites

- Should have a screen program (Module Pool)

- Data should be able to be saved through the above mentioned program

- You should have the data to be uploaded in a flat file in the system.

&#61607; Note :

• Can use excel sheet to enter the data and save it as tab- delimited file.

• Note down the table names that will be affected.

Steps:

- Transaction : SHDB ( or use SM35 and click on Recording)

- New Recording

- Give a name in which recording has to be saved (Needn’t necessarily start

with ‘Z’)

- Enter Transaction Code (Transaction to upload data)

- Click Start Recording

- Enter the details and save the data and exit.

- A screen with saved data and the ok codes, cursor position … will be

shown. Save it.

- Click back button

- Click Program button after selecting the recording you have done.

- Enter a program name (Like that which we give in SM38)

- Select Radio button - Transfer from recording and Enter.

- Give Title and click Source code.

- Save the program.

- Define a structure in types (After Include …)

- Define an internal table and a work area in data part

- Define a variable of type string to store external file path

- Parameter has to be given to enter file name(type ibipparms-path)

- Enter ‘AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILE’ where FILE is the parameter given.

- Call function F4_FILENAME (through Patterns) and give file_name as FILE.

- Assign the FILE to the variable we declared with String type.

- Call function GUI_UPLOAD (through Patterns) and give filename as the variable and give ‘X’ for has field separator and give internal table as data_tab

- In start of selection after open_group…

- Loop at internal table to work area

- Clear bdcdata

- Endloop before close_group.

- Change the hard coded data (which came from recording) to the data from internal table.

- Activate and Execute

- Click on Call Transaction

- Select processing mode

- Remove NoDataIndicator

- Select file from which data has to be uploaded

- Execute

- Check table to check whether data is uploaded correctly

Recording Program

In the Source code some modifications are to be done.The modified Program is given below.Replace the code with this one and change the path of the text file as required in the ‘GUI_UPLOAD’ function call.Also in the first line change the name of the program.

Note : Replace the code with this one completely

REPORT zbdc_06

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

  • 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, " Add OCCURS 0 here

  • data element: ZACCNO

serial_001(008),

  • data element: ZNAME_TEST

name_002(015),

  • data element: ZAGE_TEST

age_003(003),

  • data element: ZACCNO

serial_004(008),

  • data element: ZNAME_TEST

name_005(015),

  • data element: ZAGE_TEST

age_006(003),

END OF record.

      • End generated data section ***

START-OF-SELECTION.

PERFORM read_legacy. " Create subroutine for

*perform open_dataset using dataset. "Comment Here

PERFORM open_group.

*do.

*read dataset dataset into record.

*if sy-subrc <> 0. exit. endif.

LOOP AT record. "Add LOOP AT RECORD

PERFORM bdc_dynpro USING 'SAPMZBDC_05' '9000'.

PERFORM bdc_field USING 'BDC_CURSOR'

'ZBDC_05-AGE'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=SAVE'.

PERFORM bdc_field USING 'ZBDC_05-SERIAL'

record-serial_001.

PERFORM bdc_field USING 'ZBDC_05-NAME'

record-name_002.

PERFORM bdc_field USING 'ZBDC_05-AGE'

record-age_003.

PERFORM bdc_dynpro USING 'SAPMZBDC_05' '9000'.

PERFORM bdc_field USING 'BDC_CURSOR'

'ZBDC_05-SERIAL'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BACK'.

PERFORM bdc_field USING 'ZBDC_05-SERIAL'

record-serial_004.

PERFORM bdc_field USING 'ZBDC_05-NAME'

record-name_005.

PERFORM bdc_field USING 'ZBDC_05-AGE'

record-age_006.

PERFORM bdc_transaction USING 'ZBDC_05'.

ENDLOOP. " Add ENDLOOP here

*enddo. "Comment here

PERFORM close_group.

*perform close_dataset using dataset. "Comment here

&----


*& Form read_legacy

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM read_legacy .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = 'c:\bdc\bdc.txt'

  • FILETYPE = 'ASC'

has_field_separator = '#'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • 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.

MESSAGE ID sy-msgid TYPE 'A' NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " read_legacy

Reward if useful.

Regards,

Neenu Jose

Read only

Former Member
0 Likes
1,510

Hi,

1) While recording the transaction you should be very careful. If you record it wrongly you will end up in a big problem.

2) You should see that you loop through the internal table and populate the BDCDATA table properly. Otherwise you may not able to upload the proper data.

Here at the end of each literation you should clear the contents of bdcdata internal table.

3) You should use the read dataset instructions when the data is there on the application server or UNIX directory and you should use the GUI_UPLOAD function module when the data is there on the presentation server.

4) IF the data is present on the presentation server you cannot create the background job for it.

I hope it is helpful.

Thanks,

Prasanna