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: 

BDC Error handling technique

Former Member
0 Kudos

Hi Guys

I got an input like the following...can you please explain this----

(((A good practice is to use call transaction but use BDC session for when there is an error in the record.

i.e call transaction..

if sy-subrc ne 0.

perform form_bdc_session.

endif.

This method is quicker, you can capture errors and deal with them in a BDC session later.)))

If the records are erronious..then why to take them to a BDC session..?!!!! Any ways ..when sy-subrc <> 0 we will display them on to the screen.

Please explain.

3 REPLIES 3

Former Member
0 Kudos

Hi,

When the Call Transaction for BDC fails better to call sessions method, so that the log will be clearly displayed in that using SM35 t code.

See the sample code for BDC:

REPORT ZMMBDC1_1 NO STANDARD PAGE HEADING MESSAGE-ID ZT.

  • internal table for selecting data from flat file

DATA : BEGIN OF IT_DATA OCCURS 0,

MBRSH, " Industry sector

MTART(4), " Material type

KZSEL, " Checkbox

MAKTX(40), " Material description

MEINS(3), " Base unit of measure

MATKL(9), " Material group

BISMT(18), " Old material number

END OF IT_DATA.

  • internal table for bdcdata

DATA : IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

  • internal table to handle messages

DATA : IT_MESSAGES LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

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

  • Variables & Flag declaration

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

  • variables declaration

DATA : V_MESG(50).

  • flag declaration

DATA : FG_BDC,

FG_FLAG1 TYPE I.

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

  • selection screen

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

SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.

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

  • parameter

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

PARAMETERS : P_FILE LIKE RLGRAP-FILENAME OBLIGATORY.

SELECTION-SCREEN END OF BLOCK BLK1.

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

  • initialization

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

INITIALIZATION.

  • peform to initialize parameter

PERFORM INIT_PARM.

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

  • start of selection

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

start-of-selection.

  • perform to upload it_data

PERFORM UP_LOAD_IT_DATA.

  • perform transfer data

PERFORM TRANSFER_DATA.

  • end of selection

END-OF-SELECTION.

&----


*& Form INIT_PARM

&----


  • Initializing parameter

----


FORM INIT_PARM.

P_FILE = 'C:\'.

ENDFORM. " INIT_PARM

&----


*& Form UP_LOAD_IT_DATA

&----


  • Transfering data from file to internal table

----


FORM UP_LOAD_IT_DATA.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

FILENAME = P_FILE

FILETYPE = 'ASC'

TABLES

DATA_TAB = IT_DATA

EXCEPTIONS

CONVERSION_ERROR = 1

FILE_OPEN_ERROR = 2

FILE_READ_ERROR = 3

INVALID_TABLE_WIDTH = 4

INVALID_TYPE = 5

NO_BATCH = 6

UNKNOWN_ERROR = 7

GUI_REFUSE_FILETRANSFER = 8

OTHERS = 9.

IF SY-SUBRC = 2 .

FG_FLAG1 = 1.

MESSAGE I001.

ENDIF.

ENDFORM. " UP_LOAD_IT_DATA

&----


*& Form TRANSFER_DATA

&----


  • Processing the data

----


FORM TRANSFER_DATA.

FG_BDC = 'N'.

LOOP AT IT_DATA.

  • perform to fill it_bdcdata.

PERFORM FILL_IT_BDCDATA.

CALL TRANSACTION 'MM01' USING IT_BDCDATA MODE 'N' UPDATE 'S'

MESSAGES INTO IT_MESSAGES.

IF SY-SUBRC <> 0.

FG_FLAG1 = 1.

  • if error occurs in transaction mode run bdc session for that data

PERFORM BDC_PROCESS.

ENDIF.

  • Handles error messages

PERFORM ERROR_MESSAGES.

CLEAR : IT_BDCDATA,IT_DATA,IT_MESSAGES.

REFRESH : IT_BDCDATA,IT_MESSAGES.

ENDLOOP.

IF FG_FLAG1 = 0.

MESSAGE I003.

ENDIF.

IF FG_BDC = 'O'.

  • close bdc if it is open

PERFORM CLOSE_BDC.

ENDIF.

ENDFORM. " TRANSFER_DATA

&----


*& Form FILL_IT_BDCDATA

&----


  • Filling Bdcdata structure with it_data

  • Some fields have been commented for future updations

----


FORM FILL_IT_BDCDATA.

PERFORM BDC_DYNPRO USING : 'SAPLMGMM' '0060'.

PERFORM BDC_FIELD USING : 'BDC_OKCODE' '/00',

: 'BDC_CURSOR' 'RMMG1_REF-MATNR',

: 'RMMG1-MBRSH' IT_DATA-MBRSH,

: 'RMMG1-MTART' IT_DATA-MTART.

PERFORM BDC_DYNPRO USING : 'SAPLMGMM' '0070'.

PERFORM BDC_FIELD USING : 'BDC_OKCODE' '=RESA'.

PERFORM BDC_DYNPRO USING : 'SAPLMGMM' '0070'.

PERFORM BDC_FIELD USING : 'BDC_OKCODE' '=ENTR',

: 'MSICHTAUSW-KZSEL(01)' IT_DATA-KZSEL.

PERFORM BDC_DYNPRO USING : 'SAPLMGMM' '4000'.

PERFORM BDC_FIELD USING : 'BDC_OKCODE' '=BU',

: 'BDC_SUBSCR' 'SAPLMGMM' & ' 2000TABFRA1',

: 'BDC_SUBSCR' 'SAPLMGD1' & ' 1002SUB1',

: 'BDC_CURSOR' 'MAKT-MAKTX',

: 'MAKT-MAKTX' IT_DATA-MAKTX,

: 'BDC_SUBSCR' 'SAPLMGD1' & ' 2001SUB2',

: 'MARA-MEINS' IT_DATA-MEINS,

: 'MARA-MATKL' IT_DATA-MATKL,

: 'MARA-BISMT' IT_DATA-BISMT,

: 'BDC_OKCODE' '=BU'.

*perform bdc_field using 'MARA-EXTWG' ''.

*perform bdc_field using 'MARA-LABOR' ''.

*perform bdc_field using 'MARA-KOSCH' ''.

*perform bdc_field using 'MARA-MSTAE' ''.

*perform bdc_field using 'MARA-MSTDE' ''.

*perform bdc_field using 'BDC_SUBSCR' 'SAPLMGD1' & ' 2561SUB3'.

*perform bdc_field using 'MARA-BEGRU' ''.

*perform bdc_field using 'BDC_SUBSCR' 'SAPLMGD1' & ' 2007SUB4'.

*perform bdc_field using 'MARA-NTGEW' ''.

*perform bdc_field using 'MARA-BRGEW' ''.

*perform bdc_field using 'MARA-GEWEI' ''.

*perform bdc_field using 'MARA-VOLUM' ''.

*perform bdc_field using 'MARA-VOLEH' ''.

*PERFORM BDC_FIELD USING 'MARA-GROES' ''.

*perform bdc_field using 'MARA-EAN11' ''.

*perform bdc_field using 'MARA-NUMTP' ''.

*PERFORM BDC_FIELD USING 'BDC_SUBSCR' 'SAPLMGD1' & ' 2005SUB5'.

*perform bdc_field using 'BDC_SUBSCR' 'SAPLMGD1' & ' 2011SUB6'.

*perform bdc_field using 'MARA-MAGRV' ''.

ENDFORM. " FILL_IT_BDCDATA

&----


*& Form BDC_DYNPRO

&----


  • Filling the it_bdcdata table with program name & screen number

----


FORM BDC_DYNPRO USING PROGRAM LIKE BDCDATA-PROGRAM

DYNPRO LIKE BDCDATA-DYNPRO.

IT_BDCDATA-PROGRAM = PROGRAM.

IT_BDCDATA-DYNPRO = DYNPRO.

IT_BDCDATA-DYNBEGIN = 'X'.

APPEND IT_BDCDATA.

CLEAR IT_BDCDATA.

ENDFORM. " BDC_DYNPRO

&----


*& Form BDC_FIELD

&----


  • Filling it_bdcdata with field name and field value

----


FORM BDC_FIELD USING FNAM LIKE BDCDATA-FNAM

FVAL.

IT_BDCDATA-FNAM = FNAM.

IT_BDCDATA-FVAL = FVAL.

APPEND IT_BDCDATA.

CLEAR IT_BDCDATA.

ENDFORM. " BDC_FIELD

&----


*& Form ERROR_MESSAGES

&----


  • Displaying error messages

----


FORM ERROR_MESSAGES.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = SY-MSGID

LANG = '-D'

IMPORTING

MSG = V_MESG

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2.

LOOP AT IT_MESSAGES WHERE MSGTYP = 'E'.

WRITE : / 'Message :'(I06) ,V_MESG.

CLEAR IT_MESSAGES.

ENDLOOP.

ENDFORM. " ERROR_MESSAGES

&----


*& Form BDC_PROCESS

&----


  • Open bdc session if call transaction fails

----


FORM BDC_PROCESS.

IF FG_BDC = 'N'.

  • open bdc session

PERFORM OPEN_BDC.

FG_BDC = 'O'.

ENDIF.

IF FG_BDC = 'O'.

  • insert data into bdc session

PERFORM INSERT_BDC.

ENDIF.

ENDFORM. " BDC_PROCESS

&----


*& Form OPEN_BDC

&----


  • Calling function module to open bdc session

----


FORM OPEN_BDC.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

GROUP = 'SMM1'

KEEP = 'X'

USER = SY-UNAME

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.

ENDFORM. " OPEN_BDC

&----


*& Form INSERT_BDC

&----


  • Insert it_bdcdata into bdc by calling function module bdc_insert

----


FORM INSERT_BDC.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'MM01'

TABLES

DYNPROTAB = IT_BDCDATA

EXCEPTIONS

INTERNAL_ERROR = 1

NOT_OPEN = 2

QUEUE_ERROR = 3

TCODE_INVALID = 4

PRINTING_INVALID = 5

POSTING_INVALID = 6

OTHERS = 7.

ENDFORM. " INSERT_BDC

&----


*& Form CLOSE_BDC

&----


  • Closing bdc session

----


FORM CLOSE_BDC.

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

NOT_OPEN = 1

QUEUE_ERROR = 2

OTHERS = 3.

ENDFORM. " CLOSE_BDC

Regards,

Anji

Message was edited by:

Anji Reddy Vangala

Former Member
0 Kudos

Hi ram,

u can use bdc session if there is huge amount of data. u can capture the errors in the log explicitly....u can use call transaction for small amounts of data...also error records can be found using fm fomat_message..which displays the erorrs...

session quicker in the sense ..explicitly the log is created automatically for u...

the following link is self-explanatory and gives u a clear picture..

http://www.itcserver.com/blog/2006/06/30/batch-input-vs-call-transaction/

hope this helps u a bit,

all the best,

regards,

sampath

  • mark helpful answers

Message was edited by:

sampath pilla

Former Member
0 Kudos

hi,

by collecting erroneous records in a BDC session , we can modify the erroneous records present in session and reexecute the error records