Application Development 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: 

Re:Reg BDC's

Former Member
0 Kudos

Hi,

Iam very confused with BDC's,very new to this topic, i need any one's guidance from scratch,when to go to SHDB for recording ,when to write BDC program , I need different BDC example codes with explanations and steps

I hope experts u can help me

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi,

Here enclosing the procedure on How to write BDC Programme using Session and Call transaction…

BDC Flow

Text file ---> Internal table ---> Database

File Functions

Upload --> Uploads from text file to internal table (displays the

popup to change the path)

Ws_upload ---> directly inputs from text file to internal table

download ---> downloads from internal table to text fine (populating

internal table with select statement)

Ws_download ---> directly downloads to the text file.

Modes of file types are: DAT, BIN and ASC

Structure of BDCDATA:

Program Name

Screen Number

Dynbegin (default 'X')

FNam

FVal

BDC is for transferring data from Non SAP system to SAP System.

This can be done in 3 methods:

1) Session Method

2) Call Transaction

3) Direct Input

In Session method, we can create a session and need to select the

session through SM35 transaction code. By clicking the process only

the transaction executes.

In Call transaction method, directly populate in database. There

are 3 modes ie., A, N and E (ie., All screens, no screens and error

screens)

Syntax: Call transction 'MM01' using bdcdata mode 'A/N/E'.

BASIC STEPS COMMON FOR SESSION AND CALL TRANSCATION METHODS

SESSION METHOD

1) Declaring internal table which you will be populating text file

information (ie., legacy data)

2) Creating internal table like BDCDATA.

3) Call upload function which we will be making some changes ie.,

file name, filetype (DAT, BIN, ASC) and tables.

4) Call function BDC_OPEN_GROUP. Remove comment for exporting,

client, key and user. The value for the user is sy-uname, key is

'X' and client is sy-mandt.

5) Loop at internal table

6) within the loop we will be having perform statements calling

subroutines (ie., screens)

7) Within the loop BDC_INSERT.

Changes in the function modules to remove comments for exporting,

tcode (transaction code) and table as BDCDATA.

Require to refresh BDCDATA.

8)Close the internal table loop using endloop

9)Call BDC_CLOSE_GROUP

10) Difine subroutines.

CALL TRANSACTION METHOD

1) Creating internal table from text information as input

2) Internal table for BDCDATA.

3) Call Upload function

4) Loop at internal table

5) refresh BDCDATA and write the subroutines

6) Syntax for Call transaction:

CALL TRANSACTION 'MM01' USING BDCDATA MODE 'A/N/E'.

7) Close the loop using endloop

😎 Define subroutines.

regards,

pavan

5 REPLIES 5

Former Member
0 Kudos

Hi,

Check this sample code...

report zsd_bict_customer

no standard page heading line-size 255.

selection screen

selection-screen begin of block b1 with frame.

parameters : p_fname type rlgrap-filename obligatory.

parameters ctumode like ctu_params-dismode obligatory default 'N'.

parameters e_group(12). "group name of error-session

selection-screen end of block b1.

types declaration

types: begin of ty_cust,

ktokd type rf02d-ktokd,

name1 type kna1-name1,

sortl type kna1-sortl,

ort01 type kna1-ort01,

land1 type kna1-land1,

pstlz type kna1-pstlz,

spras type kna1-spras,

end of ty_cust.

data declaration

data: wa_cust type ty_cust,

it_cust like table of wa_cust with header line.

data : session value '',

ctu value 'X',

group(12),

user(12),

cupdate value 'S',

keep,

holddate like sy-datum,

e_user(12),

e_keep value 'X',

e_hdate like sy-datum,

nodata,

smalllog.

*--Batchinputdata of single transaction

data:bdcdata like bdcdata occurs 0 with header line.

*--messages of call transaction

data:messtab like bdcmsgcoll occurs 0 with header line.

*--error session opened (' ' or 'X')

data:e_group_opened.

*--message texts

tables: t100.

initialization.

user = sy-uname.

e_user = sy-uname.

start-of-selection.

data:v_fname type string.

v_fname = p_fname.

call function 'GUI_UPLOAD'

exporting

filename = v_fname

filetype = 'ASC'

has_field_separator = 'X'

tables

data_tab = it_cust

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 sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

perform open_group.

loop at it_cust.

screen number 100

perform bdc_dynpro using 'SAPMF02D' '0100'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RF02D-KTOKD'

it_cust-ktokd. "Account group

screen number 110

perform bdc_dynpro using 'SAPMF02D' '0110'.

perform bdc_field using 'BDC_OKCODE'

'VW'.

perform bdc_field using 'KNA1-NAME1'

it_cust-name1. " Name

perform bdc_field using 'KNA1-SORTL'

it_cust-sortl. " Search term

perform bdc_field using 'KNA1-ORT01'

it_cust-ort01. " City

perform bdc_field using 'KNA1-LAND1'

it_cust-land1. " Land/Country

perform bdc_field using 'KNA1-PSTLZ'

it_cust-pstlz. " Postal code

perform bdc_field using 'KNA1-SPRAS'

it_cust-spras. " Language

screen number 120

perform bdc_dynpro using 'SAPMF02D' '0120'.

perform bdc_field using 'BDC_OKCODE'

'=VW'.

screen number 125

perform bdc_dynpro using 'SAPMF02D' '0125'.

perform bdc_field using 'BDC_OKCODE'

'=VW'.

screen number 360

perform bdc_dynpro using 'SAPMF02D' '0360'.

perform bdc_field using 'BDC_OKCODE'

'=VW'.

perform bdc_transaction using 'XD01'.

endloop.

perform close_group.

----


  • create batchinput session *

  • (not for call transaction using...) *

----


form open_group.

if session = 'X'.

skip.

write: /(20) 'Create group'(i01), group.

skip.

  • open batchinput group

call function 'BDC_OPEN_GROUP'

exporting

client = sy-mandt

group = group

user = user

keep = keep

holddate = holddate.

write: /(30) 'BDC_OPEN_GROUP'(i02),

(12) 'returncode:'(i05),

sy-subrc.

endif.

endform. "open_group

----


  • end batchinput session *

  • (call transaction using...: error session) *

----


form close_group.

if session = 'X'.

*close batchinput group

call function 'BDC_CLOSE_GROUP'.

write: /(30) 'BDC_CLOSE_GROUP'(i04),

(12) 'returncode:'(i05),

sy-subrc.

else.

if e_group_opened = 'X'.

call function 'BDC_CLOSE_GROUP'.

write: /.

write: /(30) 'Fehlermappe wurde erzeugt'(i06).

e_group_opened = ' '.

endif.

endif.

endform. "close_group

----


  • Start new transaction according to parameters *

----


form bdc_transaction using tcode.

data: l_mstring(480).

data: l_subrc like sy-subrc.

  • batch input session

if session = 'X'.

call function 'BDC_INSERT'

exporting

tcode = tcode

tables

dynprotab = bdcdata.

if smalllog <> 'X'.

write: / 'BDC_INSERT'(i03),

tcode,

'returncode:'(i05),

sy-subrc,

'RECORD:',

sy-index.

endif.

  • call transaction using

else.

refresh messtab.

call transaction tcode using bdcdata

mode ctumode

update cupdate

messages into messtab.

l_subrc = sy-subrc.

if smalllog <> 'X'.

write: / 'CALL_TRANSACTION',

tcode,

'returncode:'(i05),

l_subrc,

'RECORD:',

sy-index.

loop at messtab.

select single * from t100 where sprsl = messtab-msgspra

and arbgb = messtab-msgid

and msgnr = messtab-msgnr.

if sy-subrc = 0.

l_mstring = t100-text.

if l_mstring cs '&1'.

replace '&1' with messtab-msgv1 into l_mstring.

replace '&2' with messtab-msgv2 into l_mstring.

replace '&3' with messtab-msgv3 into l_mstring.

replace '&4' with messtab-msgv4 into l_mstring.

else.

replace '&' with messtab-msgv1 into l_mstring.

replace '&' with messtab-msgv2 into l_mstring.

replace '&' with messtab-msgv3 into l_mstring.

replace '&' with messtab-msgv4 into l_mstring.

endif.

condense l_mstring.

write: / messtab-msgtyp, l_mstring(250).

else.

write: / messtab.

endif.

endloop.

skip.

endif.

    • Erzeugen fehlermappe ************************************************

if l_subrc <> 0 and e_group <> space.

if e_group_opened = ' '.

call function 'BDC_OPEN_GROUP'

exporting

client = sy-mandt

group = e_group

user = e_user

keep = e_keep

holddate = e_hdate.

e_group_opened = 'X'.

endif.

call function 'BDC_INSERT'

exporting

tcode = tcode

tables

dynprotab = bdcdata.

endif.

endif.

refresh bdcdata.

endform. "bdc_transaction

----


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

if fval <> nodata.

clear bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

append bdcdata.

endif.

endform. "bdc_field

Regards,

Swathi

Former Member
0 Kudos

hi,

Here enclosing the procedure on How to write BDC Programme using Session and Call transaction…

BDC Flow

Text file ---> Internal table ---> Database

File Functions

Upload --> Uploads from text file to internal table (displays the

popup to change the path)

Ws_upload ---> directly inputs from text file to internal table

download ---> downloads from internal table to text fine (populating

internal table with select statement)

Ws_download ---> directly downloads to the text file.

Modes of file types are: DAT, BIN and ASC

Structure of BDCDATA:

Program Name

Screen Number

Dynbegin (default 'X')

FNam

FVal

BDC is for transferring data from Non SAP system to SAP System.

This can be done in 3 methods:

1) Session Method

2) Call Transaction

3) Direct Input

In Session method, we can create a session and need to select the

session through SM35 transaction code. By clicking the process only

the transaction executes.

In Call transaction method, directly populate in database. There

are 3 modes ie., A, N and E (ie., All screens, no screens and error

screens)

Syntax: Call transction 'MM01' using bdcdata mode 'A/N/E'.

BASIC STEPS COMMON FOR SESSION AND CALL TRANSCATION METHODS

SESSION METHOD

1) Declaring internal table which you will be populating text file

information (ie., legacy data)

2) Creating internal table like BDCDATA.

3) Call upload function which we will be making some changes ie.,

file name, filetype (DAT, BIN, ASC) and tables.

4) Call function BDC_OPEN_GROUP. Remove comment for exporting,

client, key and user. The value for the user is sy-uname, key is

'X' and client is sy-mandt.

5) Loop at internal table

6) within the loop we will be having perform statements calling

subroutines (ie., screens)

7) Within the loop BDC_INSERT.

Changes in the function modules to remove comments for exporting,

tcode (transaction code) and table as BDCDATA.

Require to refresh BDCDATA.

8)Close the internal table loop using endloop

9)Call BDC_CLOSE_GROUP

10) Difine subroutines.

CALL TRANSACTION METHOD

1) Creating internal table from text information as input

2) Internal table for BDCDATA.

3) Call Upload function

4) Loop at internal table

5) refresh BDCDATA and write the subroutines

6) Syntax for Call transaction:

CALL TRANSACTION 'MM01' USING BDCDATA MODE 'A/N/E'.

7) Close the loop using endloop

😎 Define subroutines.

regards,

pavan

Former Member
0 Kudos

Hi

the BDC program should be in this format

Transaction Recorder (SHDB)

How to Upload Presentation Server Flat file to SAP R/3 system???

How to upload application server file to R/3 system?

Definition

Example - Call Transaction Method

Transaction Recorder (SHDB)

Before you work with the Batch Input methods, you should know the purpose of the tool

Transaction Recorder.

Use:

You can use the transaction recorder to record a series of transactions and their screens.

Features:

You can use the recording to create

Data transfer programs that use batch input or CALL TRANSACTION

Batch input sessions

Test data

Function modules.

Note: It doesn’t record F1, F4 and Scrollbar movements

Upload Flat file from Presentation Server to SAP R/3

CALL FUNCTION ‘GUI_UPLOAD'

EXPORTING

CODEPAGE = ‘IBM'

FILENAME = P_UFILE

FILETYPE = 'DAT'

TABLES

DATA_TAB = INT_TAB

EXCEPTIONS

CONVERSION_ERROR = 1

FILE_OPEN_ERROR = 2

FILE_READ_ERROR = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

OTHERS = 10 .

IF SY-SUBRC NE 0.

MESSAGE E999(FR) WITH 'ERROR IN FILE UPLOAD'.

ENDIF.

Upload file from application server to SAP R/3

Open the the application server file

OPEN DATASET <dsn> FOR INPUT <mode>

Read the data from application server file

READ DATASET <dsn> INTO <wa>

And then close the application server file

CLOSE DATASET <dsn>

Definition- Declaring BDC Table

DATA: BDC_TAB LIKE STANDARD TABLE OF

BDCDATA INITIAL SIZE 6

WITH HEADER LINE .

The internal table used to collect the transaction’s information must be declared “LIKE BDCDATA”.

Filling BDC Table – Method #1

FORM FILL_BDC_TAB.

REFRESH BDC_TAB.

CLEAR BDC_TAB.

BDC_TAB-PROGRAM = ‘SAPMF02K’.

BDC_TAB-DYNPRO = ‘01016’.

BDC_TAB-DYNBEGIN = ‘X’.

APPEND BDC_TAB.

CLEAR BDC_TAB.

BDC_TAB-FNAM = ‘RF02K-LIFNR’.

BDC_TAB-FVAL = ‘TEST1’.

APPEND BDC_TAB.

CLEAR BDC_TAB.

BDC_TAB-FNAM = ‘RF02K-D0010’.

BDC_TAB-FVAL = ‘X’.

APPEND BDC_TAB.

CLEAR BDC_TAB.

BDC_TAB-PROGRAM = ‘SAPMF02K’.

BDC_TAB-DYNPRO = ‘0110’.

BDC_TAB-DYNBEGIN = ‘X’.

APPEND BDC_TAB.

CLEAR BDC_TAB.

BDC_TAB-FNAM = ‘LFA1-STRAS’.

BDC_TAB-FVAL = ‘123 Main St.’.

APPEND BDC_TAB.

CLEAR BDC_TAB.

BDC_TAB-FNAM = ‘BDC_OKCODE’.

BDC_TAB-FVAL = ‘/11’.

APPEND BDC_TAB.

ENDFORM.

Filling BDC Table – Method #2

FORM FILL_BDC_TAB.

REFRESH BDC_TAB.

PERFORM POPULATE_BDC_TAB

USING:

‘1’ ‘SAPMF02K’ ‘0106’,

‘ ‘ ‘RF02K-LIFNR’ ‘TEST1’,

‘ ‘ ‘RF02K-D0010’ ‘X’,

‘1’ ‘SAPMF02K’ ‘0110’,

‘ ‘ ‘LFA1-STRAS’, ‘123 Main St.’,

‘ ‘ ‘BDC_OKCODE’, ‘/11’.

ENDFORM.

FORM POPULATE_BDC_TAB USING FLAG VAR1 VAR2.

CLEAR BDC_TAB.

IF FLAG = ‘1’.

BDC_TAB-PROGRAM = VAR1.

BDC_TAB-DYNPRO = VAR2..

BDC_TAB-DYNBEGIN = ‘X’.

ELSE.

BDC_TAB-FNAM = VAR1.

BDC_TAB-FVAL = VAR2.

ENDIF.

APPEND BDC_TAB.

ENDFORM.

This two subroutine method to fill the BDC table is preferable because the “POPULATE_BDC_TABLE” subroutine is reusable throughout all batch input programs.

Example #1 - Change Vendor (Call Transaction Method)

Example #1- Declaration Section

REPORT Y180DM10.

DATA: BDC_TAB LIKE STANDARD TABLE OF

BDCDATA INITIAL SIZE 6 WITH HEADER LINE.

INFILE(20) VALUE ‘/tmp/bc180_file4’.

DATA: BEGIN OF INREC.

VENDNUM LIKE LFA1-LIFNR.

STREET LIKE LFA1-STRAS.

END OF INREC.

PARAMETERS: DISPMODE DEFAULT ‘A’,

UPDAMODE DEFAULT ‘S’.

START-OF-SELECTION.

OPEN DATASET INFILE

FOR INPUT IN TEXT MODE.

DO.

READ DATASET INFILE INTO INREC.

IF SY-SUBRC < > 0. EXIT. ENDIF.

PERFORM FILL_BDC_TAB.

CALL TRANSACTION ‘FK02’

USING BDC_TAB

MODE DISPMODE

UPDATE UPDAMODE.

IF SY-SUBRC < > 0.

WRITE: /‘ERROR’.

ENDIF.

ENDDO.

CLOSE DATASET INFILE.

synchronous updating

DO.

………

PERFORM FILL_BDC_TAB.

CALL TRANSACTION ‘FK02’

USING BDC_TAB

MODE ‘N’

UPDATE ‘S’.

IF SY-SUBRC < > 0.

WRITE: /‘ERROR’.

ENDIF.

ENDDO.

With synchronous updating, we can check SY-SUBRC to determine the success of the transaction and the actual update to the database.

asynchronous updating

DO.

………

PERFORM FILL_BDC_TAB.

CALL TRANSACTION ‘FK02’

USING BDC_TAB

MODE ‘N’

UPDATE ‘A’.

IF SY-SUBRC < > 0.

WRITE: /‘ERROR’.

ENDIF.

ENDDO.

With asynchronous updating, we can check SY-SUBRC to determine the success of the transaction only, not the actual update to the database.

Error Handling

Write an error report.

Send the record(s) in error to an error file.

Create a batch input session with the record(s) in error.

To store error messages ( CALL TRANSACTION )

data: begin of Tab_Mess occurs 0.

include structure bdcmsgcoll.

data : end of Tab_Mess,

CALL TRANSACTION ‘FK02’ USING BDC_TAB MODE ‘N’ UPDATE ‘S’

MESSAGES INTO TAB_MESS.

IF SY-SUBRC NE 0.

WRITE: / Tab_MESS-TCODE, Tab_MESS-DYNUMB, Tab_MESS-MSGTYP ,

Tab_MESS-MSGID.

ENDIF.

i am giving you example for Change Vendor you practice for ur tcode

For our example, we will use the “Change Vendor” transaction (“FK02”) to add a street address to an already existing vendor.

Step #1

Use “System&#61664;Status” menu path to determine online program name (SAPMF02K), screen number (0110)

Step #2

Use “F1” key and “Technical Info” pushbutton in each screen field to be filled to determine the field name.

Step #3

Determine how to proceed in the transaction

(save the record by clicking on the ‘Save’ pushbutton or pressing the ‘F11’ key).

BDC Table Contents

After researching the transaction we can determine the contents of the BDC table.

PROGRAM DYNPRO DYNBEGIN FNAM FVAL

SAMPF02K 0106 X

RF02K-LIFNR TEST1

RF02K-D0110 X

SAMPF02K 0110 X

LFA1-STRAS 123 Main St.

BDC_OKCODE /11

Batch Input Methods

“CALL TRANSACTION USING”

STATEMENT

Call transaction - for data transfer

Processing batch input data with CALL TRANSACTION USING is the faster of the two recommended data transfer methods. In this method, legacy data is processed inline in your data transfer program.

Syntax:

CALL TRANSACTION <tcode>

USING <bdc_tab>

MODE <mode>

UPDATE <update>

A Display all

E Display errors only

N No display

S Synchronous

A Asynchronous

L Local update

The process flow of CALL TRANSACTION

A program that uses CALL TRANSACTION USING to process legacy data should execute thefollowing steps:

Prepare a BDCDATA structure for the transaction that you wish to run.

Prepare a internal table to store error messages Tab_Mess like structure of BDCMSGCOLL.

With a CALL TRANSACTION USING statement, call the transaction and prepare the BDCDATA structure. For example:

CALL TRANSACTION ‘MM01' USING BDCDATA MODE 'A' UPDATE 'S'. MESSAGES INTO TAB_MESS.

IF SY-SUBRC <> 0.

<Error_handling>.

ENDIF.

Overview of Batch Input Session

The first batch input method is to create a batch input session. It is the processing of this batch input session that updates the database, not the execution of the batch input program.

Reward if usefull

http://www.sap-img.com/abap/learning-bdc-programming.htm

http://aspalliance.com/1130_Batch_Data_Communication_BDC_in_SAP_R3