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

Former Member
0 Likes
933

how to upload data using call transaction ,Explain clearly.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
878

Hi,

For a BDC upload you need to write a program which created BDC sessions.

Steps:

1. Work out the transaction you would use to create the data manually.

2. Use transaction SHDB to record the creation of one material master data.

Click the New recording button or the Menu - Recording - Create

3. Save the recording, and then go back a screen and go to the overview.

4. Select the recording and click on Edit - Create Program. Give the program a Z name, and select transfer from recording.

5. Edit the program. You will see that all the data you entered is hard-coded into the program. You need to make the following changes:

5.1 After the start-of-selection, Call ws_upload to upload the file (the excel file needs to be saved as TAB separated).

5.2 After the open-group, Loop on the uploaded data. For each line, perform validation checks on the data, then modify the perform bdc_field commands to use the file data.

5.3. After perform bdc_transaction, add the endloop.

Execute the program. It will have options to create a batch session or to process directly.

These are all my finds . Might be it will be useful to you.

Direct call of transactions, session handling:

/nxxxx This terminates the current transaction, and starts transaction xxxx

/n This terminates the transaction. This generally corresponds to pressing F15 to go back.

/nend This termiantes all separate sessions and logs off (corresponds to System - Logoff).

/nex This terminates all separate sessions and logs off immediately (without any warning!).

/oxxxx This opens a new session and starts transaction xxxx in This session.

/o This lists existing sessions and allows deletion or opening of a new session.

/i This terminates the current session (corresponds to System End

/i1, /i2,... This terminates the session with the number given.

.xyzw Fast path: 'xyzw' refers to the underlined letters in the menus. This type of navigation is uncommon and is provided more for emergencies (such as a defective mouse).

Batch

The following commands can be entered in correction mode ('Process in foreground' or 'Display errors only') when processing a batch input session:

/n This terminates the current batch input transaction and characterizes it as

/bdel This deletes the current batch input transaction.

/bend This terminates batch input processing and sets the session to Failed

/bda This switches from Display errors only to Process in foreground

/bde This switches from Process in foreground to Display errors only

ABAP/4

/h This switches into debugging mode.

/hs This switches into debugging mode and activates the debugging of system functions.

Also check out the links. This is very useful.

http://www.sapdevelopment.co.uk/bdc/bdc_call.htm

Regards,

Kate

7 REPLIES 7
Read only

Former Member
0 Likes
879

Hi,

For a BDC upload you need to write a program which created BDC sessions.

Steps:

1. Work out the transaction you would use to create the data manually.

2. Use transaction SHDB to record the creation of one material master data.

Click the New recording button or the Menu - Recording - Create

3. Save the recording, and then go back a screen and go to the overview.

4. Select the recording and click on Edit - Create Program. Give the program a Z name, and select transfer from recording.

5. Edit the program. You will see that all the data you entered is hard-coded into the program. You need to make the following changes:

5.1 After the start-of-selection, Call ws_upload to upload the file (the excel file needs to be saved as TAB separated).

5.2 After the open-group, Loop on the uploaded data. For each line, perform validation checks on the data, then modify the perform bdc_field commands to use the file data.

5.3. After perform bdc_transaction, add the endloop.

Execute the program. It will have options to create a batch session or to process directly.

These are all my finds . Might be it will be useful to you.

Direct call of transactions, session handling:

/nxxxx This terminates the current transaction, and starts transaction xxxx

/n This terminates the transaction. This generally corresponds to pressing F15 to go back.

/nend This termiantes all separate sessions and logs off (corresponds to System - Logoff).

/nex This terminates all separate sessions and logs off immediately (without any warning!).

/oxxxx This opens a new session and starts transaction xxxx in This session.

/o This lists existing sessions and allows deletion or opening of a new session.

/i This terminates the current session (corresponds to System End

/i1, /i2,... This terminates the session with the number given.

.xyzw Fast path: 'xyzw' refers to the underlined letters in the menus. This type of navigation is uncommon and is provided more for emergencies (such as a defective mouse).

Batch

The following commands can be entered in correction mode ('Process in foreground' or 'Display errors only') when processing a batch input session:

/n This terminates the current batch input transaction and characterizes it as

/bdel This deletes the current batch input transaction.

/bend This terminates batch input processing and sets the session to Failed

/bda This switches from Display errors only to Process in foreground

/bde This switches from Process in foreground to Display errors only

ABAP/4

/h This switches into debugging mode.

/hs This switches into debugging mode and activates the debugging of system functions.

Also check out the links. This is very useful.

http://www.sapdevelopment.co.uk/bdc/bdc_call.htm

Regards,

Kate

Read only

Former Member
0 Likes
878

hi,

CALL TRANSACTION is used especially for integration actions between two SAP systems or between different modules. Users sometimes wish to do something like that click a button or an item then SAP would inserts or changes data automatically. Here CALL TRANSACTION should be considered.

Use the CALL TRANSACTION USING statement:

Summary: With CALL TRANSACTION USING, the system processes the data more quickly than with batch input sessions. Unlike batch input sessions, CALL TRANSACTION USING does not automatically support interactive correction or logging functions.

Your program prepares the data and then calls the corresponding transaction that is then processed immediately.

The most important features of CALL TRANSACTION USING are:

Synchronous processing

Transfer of data from an individual transaction each time the statement CALL TRANSACTION USING is called

You can update the database both synchronously and asynchronously

The program specifies the update type

Separate LUW (logical units of work) for the transaction

The system executes a database commit immediately before and after the CALL TRANSACTION USING statement

No batch input processing log

A technique similar to SESSION method, while batch input is a two-step procedure, Call Transaction does both steps online, one after the other. In this method, you call a transaction from your program by

Call transaction <tcode> using <BDCTAB>

Mode <A/N/E>

Update <S/A>

Messages into <MSGTAB>.

Parameter – 1 is transaction code.

Parameter – 2 is name of BDCTAB table.

Parameter – 3 here you are specifying mode in which you execute transaction

A is all screen mode. All the screen of transaction are displayed.

N is no screen mode. No screen is displayed when you execute the transaction.

E is error screen. Only those screens are displayed wherein you have error record.

Parameter – 4 here you are specifying update type by which database table is updated.

S is for Synchronous update in which if you change data of one table then all the related Tables gets updated. And sy-subrc is returned i.e., sy-subrc is returned for once and all.

A is for Asynchronous update. When you change data of one table, the sy-subrc is returned. And then updating of other affected tables takes place. So if system fails to update other tables, still sy-subrc returned is 0 (i.e., when first table gets updated).

Parameter – 5 when you update database table, operation is either successful or unsuccessful or operation is successful with some warning. These messages are stored in internal table, which you specify along with MESSAGE statement. This internal table should be declared like BDCMSGCOLL, a structure available in ABAP/4. It contains the following fields:

1. Tcode: Transaction code

2. Dyname: Batch point module name

3. Dynumb: Batch input Dyn number

4. Msgtyp: Batch input message type (A/E/W/I/S)

5. Msgspra: Batch input Lang, id of message

6. Msgid: Message id

7. MsgvN: Message variables (N = 1 - 4)

For each entry, which is updated in database, table message is available in BDCMSGCOLL. As BDCMSGCOLL is structure, you need to declare a internal table which can contain multiple records (unlike structure).

Steps for CALL TRANSACTION method

1. Internal table for the data (structure similar to your local file)

2. BDCTAB like BDCDATA

3. UPLOAD or WS_UPLOAD function to upload the data from local file to itab. (Considering file is local file)

4. Loop at itab.

Populate BDCTAB table.

Call transaction <tcode> using <BDCTAB>

Mode <A/N/E>

Update <S/A>.

Refresh BDCTAB.

Endloop.

(To populate BDCTAB, You need to transfer each and every field)

Steps for uploading data using CALL TRANSACTION

1. Internal table for the data (structure similar to your local file)

2. BDCTAB like BDCDATA

3. Internal table BDCMSG like BDCMSGCOLL

4. Internal table similar to Ist internal table

(Third and fourth steps are for error handling)

5. UPLOAD or WS_UPLOAD function to upload the data from the local file to itab. (Considering file is local file)

6. Loop at itab.

Populate BDCTAB table.

Call transaction <tr.code> using <Bdctab>

Mode <A/N/E>

Update <S/A>

Messages <BDCMSG>.

Perform check.

Refresh BDCTAB.

Endloop.

7 Form check.

IF sy-subrc <> 0. (Call transaction returns the sy-subrc if updating is not successful).

Call function Format_message.

(This function is called to store the message given by system and to display it along with record)

Append itab2.

Display the record and message.

In this example I uploaded the data using CT and handlled the errrors,I opened session for error records.

*CALL TRANSACTION

REPORT ztest_report

NO STANDARD PAGE HEADING

LINE-SIZE 255

MESSAGE-ID ZRASH.

*--Internal Table for Data Uploading.

DATA : BEGIN OF IT_FFCUST OCCURS 0,

KUNNR(10),

BUKRS(4),

KTOKD(4),

ANRED(15),

NAME1(35),

SORTL(10),

STRAS(35),

ORT01(35),

PSTLZ(10),

LAND1(3),

SPRAS(2),

AKONT(10),

END OF IT_FFCUST.

*--Internal Table to Store Error Records.

DATA : BEGIN OF IT_ERRCUST OCCURS 0,

KUNNR(10),

EMSG(255),

END OF IT_ERRCUST.

*--Internal Table to Store Successful Records.

DATA : BEGIN OF IT_SUCCUST OCCURS 0,

KUNNR(10),

SMSG(255),

END OF IT_SUCCUST.

*--Internal Table for Storing the BDC data.

DATA : IT_CUSTBDC LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

*--Internal Table for storing the messages.

DATA : IT_CUSTMSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

DATA : V_FLAG1(1) VALUE ' ',

"Flag used for opening session.

V_TLINES LIKE SY-TABIX,

"For storing total records processed.

V_ELINES LIKE SY-TABIX,

"For storing the no of error records.

V_SLINES LIKE SY-TABIX.

"For storing the no of success records.

SELECTION-SCREEN BEGIN OF BLOCK B1.

PARAMETERS : V_FNAME LIKE RLGRAP-FILENAME,

V_SESNAM LIKE RLGRAP-FILENAME.

SELECTION-SCREEN END OF BLOCK B1.

START-OF-SELECTION.

*-- Form to upload flatfile data into the internal table.

PERFORM FORM_UPLOADFF.

TOP-OF-PAGE.

WRITE:/ 'Details of the error and success records for the transaction'.

ULINE.

SKIP.

END-OF-SELECTION.

*-- Form to Generate a BDC from the Uploaded Internal table

PERFORM FORM_BDCGENERATE.

*--To write the totals and the session name.

PERFORM FORM_WRITEOP.

FORM FORM_UPLOADFF .

*--Variable to change the type of the parameter file name.

DATA : LV_FILE TYPE STRING.

LV_FILE = V_FNAME.

*--Function to upload the flat file to the internal table.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = LV_FILE

  • FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = IT_FFCUST

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.

*--Deleting the headings from the internal table.

DELETE IT_FFCUST INDEX 1.

*--Getting the total number of records uploaded.

DESCRIBE TABLE IT_FFCUST LINES V_TLINES.

ENDIF.

ENDFORM. " form_uploadff

FORM FORM_BDCGENERATE .

*--Generating the BDC table for the fields of the internal table.

LOOP AT IT_FFCUST.

PERFORM POPULATEBDC USING :

'X' 'SAPMF02D' '0105',

' ' 'BDC_OKCODE' '/00' ,

' ' 'RF02D-KUNNR' IT_FFCUST-KUNNR,

' ' 'RF02D-BUKRS' IT_FFCUST-BUKRS,

' ' 'RF02D-KTOKD' IT_FFCUST-KTOKD,

'X' 'SAPMF02D' '0110' ,

' ' 'BDC_OKCODE' '/00',

' ' 'KNA1-ANRED' IT_FFCUST-ANRED,

' ' 'KNA1-NAME1' IT_FFCUST-NAME1,

' ' 'KNA1-SORTL' IT_FFCUST-SORTL,

' ' 'KNA1-STRAS' IT_FFCUST-STRAS,

' ' 'KNA1-ORT01' IT_FFCUST-ORT01,

' ' 'KNA1-PSTLZ' IT_FFCUST-PSTLZ,

' ' 'KNA1-LAND1' IT_FFCUST-LAND1,

' ' 'KNA1-SPRAS' IT_FFCUST-SPRAS,

'X' 'SAPMFO2D' '0120',

' ' 'BDC_OKCODE' '/00',

'X' 'SAPMF02D' '0125',

' ' 'BDC_OKCODE' '/00',

'X' 'SAPMF02D' '0130',

' ' 'BDC_OKCODE' '=ENTR',

'X' 'SAPMF02D' '0340',

' ' 'BDC_OKCODE' '=ENTR',

'X' 'SAPMF02D' '0360',

' ' 'BDC_OKCODE' '=ENTR',

'X' 'SAPMF02D' '0210',

' ' 'KNB1-AKONT' IT_FFCUST-AKONT,

' ' 'BDC_OKCODE' '/00',

'X' 'SAPMF02D' '0215',

' ' 'BDC_OKCODE' '/00',

'X' 'SAPMF02D' '0220',

' ' 'BDC_OKCODE' '/00',

'X' 'SAPMF02D' '0230',

' ' 'BDC_OKCODE' '=UPDA'.

*--Calling the transaction 'fd01'.

CALL TRANSACTION 'FD01' USING IT_CUSTBDC MODE 'N' UPDATE 'S'

MESSAGES INTO IT_CUSTMSG.

IF SY-SUBRC <> 0.

*--Populating the error records internal table.

IT_ERRCUST-KUNNR = IT_FFCUST-KUNNR.

APPEND IT_ERRCUST.

CLEAR IT_ERRCUST.

*--Opening a session if there is an error record.

IF V_FLAG1 = ' '.

PERFORM FORM_OPENSESSION.

V_FLAG1 = 'X'.

ENDIF.

*--Inserting the error records into already open session.

IF V_FLAG1 = 'X'.

PERFORM FORM_INSERT.

ENDIF.

*--Populating the Success records internal table.

ELSE.

IT_SUCCUST-KUNNR = IT_FFCUST-KUNNR.

APPEND IT_SUCCUST.

CLEAR IT_SUCCUST.

ENDIF.

*--Displaying the messages.

IF NOT IT_CUSTMSG[] IS INITIAL.

PERFORM FORM_FORMATMSG.

ENDIF.

*--Clearing the message and bdc tables.

CLEAR : IT_CUSTBDC[],IT_CUSTMSG[].

ENDLOOP.

*--Getting the total no of error records.

DESCRIBE TABLE IT_ERRCUST LINES V_ELINES.

*--Getting the total no of successful records.

DESCRIBE TABLE IT_SUCCUST LINES V_SLINES.

*--Closing the session only if it is open.

IF V_FLAG1 = 'X'.

PERFORM FORM_CLOSESESS.

ENDIF.

ENDFORM. " Form_bdcgenerate

FORM POPULATEBDC USING VALUE(P_0178)

VALUE(P_0179)

VALUE(P_0180).

IF P_0178 = 'X'.

IT_CUSTBDC-PROGRAM = P_0179.

IT_CUSTBDC-DYNPRO = P_0180.

IT_CUSTBDC-DYNBEGIN = 'X'.

ELSE.

IT_CUSTBDC-FNAM = P_0179.

IT_CUSTBDC-FVAL = P_0180.

ENDIF.

APPEND IT_CUSTBDC.

CLEAR IT_CUSTBDC.

ENDFORM. " populatebdc

FORM FORM_OPENSESSION .

*--Variable to convert the given session name into reqd type.

DATA : LV_SESNAM(12).

LV_SESNAM = V_SESNAM.

*--Opening a session.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

GROUP = LV_SESNAM

HOLDDATE = '20040805'

KEEP = 'X'

USER = SY-UNAME

PROG = SY-CPROG

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

WRITE 😕 'Session not open'.

ENDIF.

ENDFORM. " FORM_OPENSESSION

FORM FORM_INSERT .

*--Inserting the record into session.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'FD01'

  • POST_LOCAL = NOVBLOCAL

  • PRINTING = NOPRINT

  • SIMUBATCH = ' '

  • CTUPARAMS = ' '

TABLES

DYNPROTAB = IT_CUSTBDC

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.

WRITE 😕 'Unable to insert the record'.

ENDIF.

ENDFORM. " FORM_INSERT

FORM FORM_CLOSESESS .

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

NOT_OPEN = 1

QUEUE_ERROR = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

ENDIF.

ENDFORM. " FORM_CLOSESESS

FORM FORM_FORMATMSG .

*--Var to store the formatted msg.

DATA : LV_MSG(255).

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = SY-MSGID

LANG = SY-LANGU

NO = SY-MSGNO

V1 = SY-MSGV1

V2 = SY-MSGV2

V3 = SY-MSGV3

V4 = SY-MSGV4

IMPORTING

MSG = LV_MSG

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2.

IF SY-SUBRC = 0.

WRITE 😕 LV_MSG.

ENDIF.

ULINE.

ENDFORM. " FORM_FORMATMSG

FORM FORM_WRITEOP .

WRITE 😕 'Total Records Uploaded :',V_TLINES,

/ 'No of Error Records :',V_ELINES,

/ 'No of Success Records :',V_SLINES,

/ 'Name of the Session :',V_SESNAM.

ULINE.

ENDFORM. " form_writeop

Read only

Former Member
0 Likes
878

HI

Refer this code.

REPORT ZSYSTEM LINE-SIZE 255.

TABLES: T100.

  • Batch-input data

DATA: BEGIN OF G_BDCDATA OCCURS 100.

INCLUDE STRUCTURE BDCDATA.

DATA: END OF G_BDCDATA.

DATA: G_MESSAGE(200).

PERFORM FILL_BDCDATA.

CALL TRANSACTION 'FI01' USING G_BDCDATA MODE 'N'.

  • of course it is nicer with a message itab, but this example

  • should also demostrate the use of system variables.

SELECT SINGLE * FROM T100 WHERE

SPRSL = 'E'

AND ARBGB = SY-MSGID

AND MSGNR = SY-MSGNO.

G_MESSAGE = T100-TEXT.

PERFORM REPLACE_PARAMETERS USING SY-MSGV1

SY-MSGV2

SY-MSGV3

SY-MSGV4

CHANGING G_MESSAGE.

WRITE: / 'System variables:'.

SKIP.

WRITE: / ' Sy-msgty:', SY-MSGTY.

WRITE: / ' Sy-msgid:', SY-MSGID.

WRITE: / ' Sy-msgno:', SY-MSGNO.

WRITE: / ' Sy-msgv1:', SY-MSGV1.

WRITE: / ' Sy-msgv2:', SY-MSGV2.

WRITE: / ' Sy-msgv3:', SY-MSGV3.

WRITE: / ' Sy-msgv4:', SY-MSGV4.

SKIP.

WRITE: / 'The transaction was called with a wrong country code.'.

WRITE: / 'The error message should be either that or that you have'.

WRITE: / ' no authorisation to execute the transaction'.

SKIP.

WRITE: / 'Message:'.

SKIP.

WRITE: / SY-MSGTY, G_MESSAGE.

----


  • Build up the BDC-table *

----


FORM FILL_BDCDATA.

REFRESH G_BDCDATA.

PERFORM BDC_DYNPRO USING 'SAPMF02B' '0100'.

PERFORM BDC_FIELD USING 'BNKA-BANKS' 'ZZZ'.

PERFORM BDC_FIELD USING 'BDC_OKCODE' 'QQQQQ'.

ENDFORM.

----


  • FORM BDC_DYNPRO *

----


  • Batchinput: Start new Dynpro *

----


FORM BDC_DYNPRO USING P_PROGRAM P_DYNPRO.

CLEAR G_BDCDATA.

G_BDCDATA-PROGRAM = P_PROGRAM.

G_BDCDATA-DYNPRO = P_DYNPRO.

G_BDCDATA-DYNBEGIN = 'X'.

APPEND G_BDCDATA.

ENDFORM. " BDC_DYNPRO

----


  • FORM BDC_FIELD *

----


  • Batchinput: Feld hinzufugen *

----


FORM BDC_FIELD USING P_FNAM P_FVAL.

CLEAR G_BDCDATA.

G_BDCDATA-FNAM = P_FNAM.

G_BDCDATA-FVAL = P_FVAL.

APPEND G_BDCDATA.

ENDFORM. " BDC_FIELD

----


  • FORM REPLACE_PARAMETERS *

----


  • ........ *

----


  • --> P_PAR_1 *

  • --> P_PAR_2 *

  • --> P_PAR_3 *

  • --> P_PAR_4 *

  • --> P_MESSAGE *

----


FORM REPLACE_PARAMETERS USING P_PAR_1

P_PAR_2

P_PAR_3

P_PAR_4

CHANGING P_MESSAGE.

  • erst mal pruefen, ob numerierte Parameter verwendet wurden

DO.

REPLACE '&1' WITH P_PAR_1 INTO P_MESSAGE.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ENDDO.

DO.

REPLACE '&2' WITH P_PAR_2 INTO P_MESSAGE.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ENDDO.

DO.

REPLACE '&3' WITH P_PAR_3 INTO P_MESSAGE.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ENDDO.

DO.

REPLACE '&4' WITH P_PAR_4 INTO P_MESSAGE.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ENDDO.

  • falls keine numerierten Parameter vorh., ersetzen wie gehabt

REPLACE '&' WITH P_PAR_1 INTO P_MESSAGE.

CONDENSE P_MESSAGE.

IF SY-SUBRC EQ 0.

REPLACE '&' WITH P_PAR_2 INTO P_MESSAGE.

CONDENSE P_MESSAGE.

IF SY-SUBRC EQ 0.

REPLACE '&' WITH P_PAR_3 INTO P_MESSAGE.

CONDENSE P_MESSAGE.

IF SY-SUBRC EQ 0.

REPLACE '&' WITH P_PAR_4 INTO P_MESSAGE.

CONDENSE P_MESSAGE.

ENDIF.

ENDIF.

ENDIF.

ENDFORM. "replace_parameters

Reward all helpfull answers.

Regards.

Jay

Read only

Former Member
0 Likes
878

Hi Lakshman,

You can upload data using Call Transaction method using the following way

Process Mode:A,

Update Mode:S,

Keep Session:Yes.

Then execute.

Read only

Former Member
0 Likes
878

hi

good

BDC using Call transaction involves calling an SAP transaction in back ground from within the ABAP

program. The process involves building an Internal BDC table containing the screen information needed to

execute the required transaction and then passing this to the Call transaction command (See code example).

The full procedure for creating a BDC program is as follows:

STEP 1

Create recording using SM35(or SHDB).

STEP 2

Use recording as a basis to populate the Internal BDC table. See

'FORM bdc_update' within the code example

=========

*Code used to create BDC

&----


*& Report ZBDC_EXAMPLE *

*& *

&----


*& Example BDC program, which updates net price of item 00010 of a *

*& particular Purchase order(EBELN). *

*& *

&----


REPORT ZBDC_EXAMPLE NO STANDARD PAGE HEADING

LINE-SIZE 132.

*----


  • Data declaration

TABLES: ekko, ekpo.

TYPES: BEGIN OF t_ekko,

ebeln TYPE ekko-ebeln,

waers TYPE ekko-waers,

netpr TYPE ekpo-netpr,

err_msg(73) TYPE c,

END OF t_ekko.

DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,

wa_ekko TYPE t_ekko,

it_error TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,

wa_error TYPE t_ekko,

it_success TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,

wa_success TYPE t_ekko.

DATA: w_textout LIKE t100-text.

DATA: gd_update TYPE i,

gd_lines TYPE i.

*Used to store BDC data

DATA: BEGIN OF bdc_tab OCCURS 0.

INCLUDE STRUCTURE bdcdata.

DATA: END OF bdc_tab.

*Used to stores error information from CALL TRANSACTION Function Module

DATA: BEGIN OF messtab OCCURS 0.

INCLUDE STRUCTURE bdcmsgcoll.

DATA: END OF messtab.

*----


*Screen declaration

SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME

TITLE text-001. "Purchase order Num

SELECT-OPTIONS: so_ebeln FOR ekko-ebeln OBLIGATORY.

SELECTION-SCREEN END OF BLOCK block1.

SELECTION-SCREEN BEGIN OF BLOCK block2 WITH FRAME

TITLE text-002. "New NETPR value

PARAMETERS: p_newpr(14) TYPE c obligatory. "LIKE ekpo-netpr.

SELECTION-SCREEN END OF BLOCK block2.

************************************************************************

*START-OF-SELECTION

START-OF-SELECTION.

  • Retrieve data from Purchase order table(EKKO)

SELECT ekkoebeln ekkowaers ekpo~netpr

INTO TABLE it_ekko

FROM ekko AS ekko INNER JOIN ekpo AS ekpo

ON ekpoebeln EQ ekkoebeln

WHERE ekko~ebeln IN so_ebeln AND

ekpo~ebelp EQ '10'.

************************************************************************

*END-OF-SELECTION

END-OF-SELECTION.

  • Check data has been retrieved ready for processing

DESCRIBE TABLE it_ekko LINES gd_lines.

IF gd_lines LE 0.

  • Display message if no data has been retrieved

MESSAGE i003(zp) WITH 'No Records Found'(001).

LEAVE TO SCREEN 0.

ELSE.

  • Update Customer master data (instalment text)

LOOP AT it_ekko INTO wa_ekko.

PERFORM bdc_update.

ENDLOOP.

  • Display message confirming number of records updated

IF gd_update GT 1.

MESSAGE i003(zp) WITH gd_update 'Records updated'(002).

ELSE.

MESSAGE i003(zp) WITH gd_update 'Record updated'(003).

ENDIF.

  • Display Success Report

  • **********************

  • Check Success table

DESCRIBE TABLE it_success LINES gd_lines.

IF gd_lines GT 0.

  • Display result report column headings

PERFORM display_column_headings.

  • Display result report

PERFORM display_report.

ENDIF.

  • Display Error Report

  • ********************

  • Check errors table

DESCRIBE TABLE it_error LINES gd_lines.

  • If errors exist then display errors report

IF gd_lines GT 0.

  • Display errors report

PERFORM display_error_headings.

PERFORM display_error_report.

ENDIF.

ENDIF.

&----


*& Form DISPLAY_COLUMN_HEADINGS

&----


  • Display column headings

----


FORM display_column_headings.

WRITE:2 ' Success Report '(014) COLOR COL_POSITIVE.

SKIP.

WRITE:2 'The following records updated successfully:'(013).

WRITE:/ sy-uline(42).

FORMAT COLOR COL_HEADING.

WRITE:/ sy-vline,

(10) 'Purchase Order'(004), sy-vline,

(11) 'Old Netpr'(005), sy-vline,

(11) 'New Netpr'(006), sy-vline.

WRITE:/ sy-uline(42).

ENDFORM. " DISPLAY_COLUMN_HEADINGS

&----


*& Form BDC_UPDATE

&----


  • Populate BDC table and call transaction ME22

----


FORM bdc_update.

PERFORM dynpro USING:

'X' 'SAPMM06E' '0105',

' ' 'BDC_CURSOR' 'RM06E-BSTNR',

' ' 'RM06E-BSTNR' wa_ekko-ebeln,

' ' 'BDC_OKCODE' '/00', "OK code

'X' 'SAPMM06E' '0120',

' ' 'BDC_CURSOR' 'EKPO-NETPR(01)',

' ' 'EKPO-NETPR(01)' p_newpr,

' ' 'BDC_OKCODE' '=BU'. "OK code

  • Call transaction to update customer instalment text

CALL TRANSACTION 'ME22' USING bdc_tab MODE 'N' UPDATE 'S'

MESSAGES INTO messtab.

  • Check if update was succesful

IF sy-subrc EQ 0.

ADD 1 TO gd_update.

APPEND wa_ekko TO it_success.

ELSE.

  • Retrieve error messages displayed during BDC update

LOOP AT messtab WHERE msgtyp = 'E'.

  • Builds actual message based on info returned from Call transaction

CALL FUNCTION 'MESSAGE_TEXT_BUILD'

EXPORTING

msgid = messtab-msgid

msgnr = messtab-msgnr

msgv1 = messtab-msgv1

msgv2 = messtab-msgv2

msgv3 = messtab-msgv3

msgv4 = messtab-msgv4

IMPORTING

message_text_output = w_textout.

ENDLOOP.

  • Build error table ready for output

wa_error = wa_ekko.

wa_error-err_msg = w_textout.

APPEND wa_error TO it_error.

CLEAR: wa_error.

ENDIF.

  • Clear bdc date table

CLEAR: bdc_tab.

REFRESH: bdc_tab.

ENDFORM. " BDC_UPDATE

----


  • FORM DYNPRO *

----


  • stores values to bdc table *

----


  • --> DYNBEGIN *

  • --> NAME *

  • --> VALUE *

----


FORM dynpro USING dynbegin name value.

IF dynbegin = 'X'.

CLEAR bdc_tab.

MOVE: name TO bdc_tab-program,

value TO bdc_tab-dynpro,

'X' TO bdc_tab-dynbegin.

APPEND bdc_tab.

ELSE.

CLEAR bdc_tab.

MOVE: name TO bdc_tab-fnam,

value TO bdc_tab-fval.

APPEND bdc_tab.

ENDIF.

ENDFORM. " DYNPRO

&----


*& Form DISPLAY_REPORT

&----


  • Display Report

----


FORM display_report.

FORMAT COLOR COL_NORMAL.

  • Loop at data table

LOOP AT it_success INTO wa_success.

WRITE:/ sy-vline,

(10) wa_success-ebeln, sy-vline,

(11) wa_success-netpr CURRENCY wa_success-waers, sy-vline,

(11) p_newpr, sy-vline.

CLEAR: wa_success.

ENDLOOP.

WRITE:/ sy-uline(42).

REFRESH: it_success.

FORMAT COLOR COL_BACKGROUND.

ENDFORM. " DISPLAY_REPORT

&----


*& Form DISPLAY_ERROR_REPORT

&----


  • Display error report data

----


FORM display_error_report.

LOOP AT it_error INTO wa_error.

WRITE:/ sy-vline,

(10) wa_error-ebeln, sy-vline,

(11) wa_error-netpr CURRENCY wa_error-waers, sy-vline,

(73) wa_error-err_msg, sy-vline.

ENDLOOP.

WRITE:/ sy-uline(104).

REFRESH: it_error.

ENDFORM. " DISPLAY_ERROR_REPORT

&----


*& Form DISPLAY_ERROR_HEADINGS

&----


  • Display error report headings

----


FORM display_error_headings.

SKIP.

WRITE:2 ' Error Report '(007) COLOR COL_NEGATIVE.

SKIP.

WRITE:2 'The following records failed during update:'(008).

WRITE:/ sy-uline(104).

FORMAT COLOR COL_HEADING.

WRITE:/ sy-vline,

(10) 'Purchase Order'(009), sy-vline,

(11) 'Netpr'(010), sy-vline,

(73) 'Error Message'(012), sy-vline.

WRITE:/ sy-uline(104).

FORMAT COLOR COL_NORMAL.

ENDFORM. " DISPLAY_ERROR_HEADINGS

thaks

mrutyun^

Read only

Former Member
0 Likes
878

Hi,

check out the links. This is very useful.

http://www.sapdevelopment.co.uk/bdc/bdc_call.htm

Regards

Read only

Former Member
0 Likes
878

answered