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

Error handling programs for BDC

Former Member
0 Likes
4,822

I want to know does we write error handling programs in BDC

If we write error handling programs what will be the requirements

Points will be rewarded.

Thanks,

Durga .

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,684

hai Prasad,

there is no special programs called error handling programs in BDC .

But When Ever we are writing BDC programs Some Records Will Not be Updated Due To Format Errors etc,

Then We have to Handle those errors So That All the records that came from Flat file should be enterd into SAP system.

Then In Session method these will automatically Logged.

Where as in CALL Transaction method We have to handle this .

The Following Program Shows how to hanldle Errors in BDC Program.

WE can handle the Errors in Call transaction method through BDCMSGCOLL Strcture and one Important function module is Format_message.

For Example :

DATA : BDCMSGCOLL TYPE TABLE OF BDCMSGCOLL WITH HEADER LINE,

BDCDATA TYPE TABLE OF BDCDATA WITH HEADER LINE.

CALL TRANSACTION 'MM01' USING BDCDATA MODE N UPDATE S MESSAGES INTO BDCMSGCOLL.

IF SY-SUBRC 0.

PERFORM ERR.

CLEAR I_MSG.

REFRESH I_MSG.

ENDIF.

&----


*& Form ERR

&----


text

--> p1 text

<-- p2 text form ERR .

DATA V_MSG(255) TYPE C.

READ TABLE I_MSG WITH KEY MSGTYP = 'E'.

IF SY-SUBRC = 0.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = I_MSG-MSGID

LANG = 'E'

NO = I_MSG-MSGNR

V1 = I_MSG-MSGV1

V2 = I_MSG-MSGV2

V3 = I_MSG-MSGV3

V4 = I_MSG-MSGV4

IMPORTING

MSG = V_MSG

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2

.

IF sy-subrc 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

WRITE V_MSG. " Error Message Displayed Here.

CLEAR V_MSG.

ENDIF.

endform. " ERR

IF found helpfull Do Reward.

Regards.

Eshwar.

6 REPLIES 6
Read only

Former Member
0 Likes
2,684

Check these threads.

Read only

Former Member
0 Likes
2,685

hai Prasad,

there is no special programs called error handling programs in BDC .

But When Ever we are writing BDC programs Some Records Will Not be Updated Due To Format Errors etc,

Then We have to Handle those errors So That All the records that came from Flat file should be enterd into SAP system.

Then In Session method these will automatically Logged.

Where as in CALL Transaction method We have to handle this .

The Following Program Shows how to hanldle Errors in BDC Program.

WE can handle the Errors in Call transaction method through BDCMSGCOLL Strcture and one Important function module is Format_message.

For Example :

DATA : BDCMSGCOLL TYPE TABLE OF BDCMSGCOLL WITH HEADER LINE,

BDCDATA TYPE TABLE OF BDCDATA WITH HEADER LINE.

CALL TRANSACTION 'MM01' USING BDCDATA MODE N UPDATE S MESSAGES INTO BDCMSGCOLL.

IF SY-SUBRC 0.

PERFORM ERR.

CLEAR I_MSG.

REFRESH I_MSG.

ENDIF.

&----


*& Form ERR

&----


text

--> p1 text

<-- p2 text form ERR .

DATA V_MSG(255) TYPE C.

READ TABLE I_MSG WITH KEY MSGTYP = 'E'.

IF SY-SUBRC = 0.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = I_MSG-MSGID

LANG = 'E'

NO = I_MSG-MSGNR

V1 = I_MSG-MSGV1

V2 = I_MSG-MSGV2

V3 = I_MSG-MSGV3

V4 = I_MSG-MSGV4

IMPORTING

MSG = V_MSG

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2

.

IF sy-subrc 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

WRITE V_MSG. " Error Message Displayed Here.

CLEAR V_MSG.

ENDIF.

endform. " ERR

IF found helpfull Do Reward.

Regards.

Eshwar.

Read only

Former Member
0 Likes
2,684

Hi

Hi

check this program ..in this i have used session method to display the error records.....this is for vendor data uploading...

REPORT zmm_bdcp_assignment3 NO STANDARD PAGE HEADING

LINE-SIZE 255.

-


STRUCTURE DECLARATION

-


TYPES : BEGIN OF st_vendor,

ktokk TYPE rf02k-ktokk, "account group

anred TYPE lfa1-anred, "title

name1 TYPE lfa1-name1, "vendor name

sortl TYPE lfa1-sortl, "search term

pstlz TYPE lfa1-pstlz, "postal code

land1 TYPE lfa1-land1, "country

banks TYPE lfbk-banks,

bankl TYPE lfbk-bankl, "bank key

bankn TYPE lfbk-bankn, "account number

END OF st_vendor.

TYPES : BEGIN OF st_success,

lifnr TYPE lfa1-lifnr, "vendor number

name TYPE lfa1-name1, "vendor name

END OF st_success.

TYPES: BEGIN OF st_error,

linno TYPE i, "line number

message TYPE string, "error message

END OF st_error.

-


INTERNAL TABLE DECLARATIONS

WORK AREA DECLARATIONS

-


DATA : it_vendor TYPE STANDARD TABLE OF st_vendor,

wa_vendor TYPE st_vendor,

it_success TYPE STANDARD TABLE OF st_success,

wa_success TYPE st_success,

it_error TYPE STANDARD TABLE OF st_error,

wa_error TYPE st_error,

it_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE,

it_message LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

-


DATA DECLARATION

-


DATA : v_file TYPE string,

v_tcode(4) VALUE 'XK01',

v_index LIKE sy-tabix,

v_totalrec TYPE i,

v_errrec TYPE i,

v_succrec TYPE i.

-


SELECTION SCREEN

-


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS: p_file TYPE rlgrap-filename.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-010.

PARAMETERS p_mode LIKE ctu_params-dismode DEFAULT 'N' .

"A: show all dynpros

"E: show dynpro on error only

"N: do not display dynpro

PARAMETERS p_update LIKE ctu_params-updmode DEFAULT 'S'.

"S: synchronously

"A: asynchronously

SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-011.

PARAMETERS : p_group(12) DEFAULT '8907'. "group name for error session

SELECTION-SCREEN END OF BLOCK b3.

-


AT SELECTION SCREEN ON VALUE-REQUEST

-


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

field_name = ' '

IMPORTING

file_name = p_file.

-


START-OF-SELECTION

-


START-OF-SELECTION.

v_file = p_file.

*gui upload

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = v_file

filetype = 'ASC'

has_field_separator = 'X'

TABLES

data_tab = it_vendor

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.

*loadind data into it_bdcdata

LOOP AT it_vendor INTO wa_vendor.

v_index = sy-tabix.

PERFORM load_bdcdata.

-


CALL TRANSACTION

-


CALL TRANSACTION v_tcode USING it_bdcdata

MODE p_mode

UPDATE p_update

MESSAGES INTO it_message.

*reading success

IF sy-subrc = 0.

READ TABLE it_message WITH KEY msgtyp = 'S'.

IF sy-subrc = 0.

wa_success-lifnr = it_message-msgv1.

wa_success-name = wa_vendor-name1.

APPEND wa_success TO it_success.

ENDIF.

ELSE.

*reading errors

READ TABLE it_message WITH KEY msgtyp = 'E'.

IF sy-subrc = 0.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = sy-msgid

no = it_message-msgnr

v1 = it_message-msgv1

v2 = it_message-msgv2

v3 = it_message-msgv3

v4 = it_message-msgv4

IMPORTING

msg = wa_error-message.

wa_error-linno = v_index.

APPEND wa_error TO it_error.

CLEAR wa_error.

ENDIF.

*session opening

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

client = sy-mandt

group = p_group

holddate = sy-datum

keep = 'X'

user = sy-uname.

*inserting into session

CALL FUNCTION 'BDC_INSERT'

EXPORTING

tcode = 'XK01'

TABLES

dynprotab = it_bdcdata.

*closing session

CALL FUNCTION 'BDC_CLOSE_GROUP'.

ENDIF.

CLEAR: it_bdcdata, it_message.

REFRESH: it_bdcdata, it_message.

ENDLOOP.

-


SUMMARY DISPLAY

-


DESCRIBE TABLE it_vendor LINES v_totalrec.

DESCRIBE TABLE it_error LINES v_errrec.

v_succrec = v_totalrec - v_errrec .

WRITE : /1 text-004 COLOR 1.

WRITE : /2 'Total Records Processed :', 25 v_totalrec,

/2 'Error Records :', 25 v_errrec,

/2 'Successful Records :', 25 v_succrec.

SKIP 2.

WRITE : /1 text-005 COLOR 1.

LOOP AT it_error INTO wa_error.

WRITE:/2 wa_error-linno,

wa_error-message.

ENDLOOP.

SKIP 2.

WRITE : /1 text-009 COLOR 1.

ULINE AT : /2(46).

WRITE :/2 sy-vline ,(10) 'VENDOR NUM' , 15 sy-vline , 17 'VENDOR NAME' , 47 sy-vline.

ULINE AT : /2(46).

LOOP AT it_success INTO wa_success.

WRITE:/2 sy-vline , wa_success-lifnr, 15 sy-vline , 17 wa_success-name , 47 sy-vline.

ENDLOOP.

ULINE AT : /2(46).

&----


*& Form append_bdcdata

&----


FORM append_bdcdata USING p_flag p_fname p_fval.

CLEAR it_bdcdata.

IF p_flag = 'X'.

it_bdcdata-program = p_fname.

it_bdcdata-dynpro = p_fval.

it_bdcdata-dynbegin = 'X'.

APPEND it_bdcdata.

ELSEIF NOT p_fval IS INITIAL.

it_bdcdata-fnam = p_fname.

it_bdcdata-fval = p_fval.

APPEND it_bdcdata.

ENDIF.

ENDFORM. "append_bdcdata

&----


*& Form load_bdcdata

&----


FORM load_bdcdata .

PERFORM append_bdcdata USING : 'X' 'SAPMF02K' '0100',

' ' 'BDC_OKCODE' '/00',

' ' 'RF02K-KTOKK' wa_vendor-ktokk,

'X' 'SAPMF02K' '0110',

' ' 'BDC_OKCODE' '/00',

' ' 'LFA1-ANRED' wa_vendor-anred,

' ' 'LFA1-NAME1' wa_vendor-name1,

' ' 'LFA1-SORTL' wa_vendor-sortl,

' ' 'LFA1-PSTLZ' wa_vendor-pstlz,

' ' 'LFA1-LAND1' wa_vendor-land1,

'X' 'SAPMF02K' '0120',

' ' 'BDC_OKCODE' '/00',

'X' 'SAPMF02K' '0130',

' ' 'BDC_OKCODE' '=ENTR',

' ' 'LFBK-BANKS(01)' wa_vendor-banks,

' ' 'LFBK-BANKL(01)' wa_vendor-bankl,

' ' 'LFBK-BANKN(01)' wa_vendor-bankn,

'X' 'SAPMF02K' '0130',

' ' 'BDC_OKCODE' '=ENTR',

'X' 'SAPLSPO1' '0300',

' ' 'BDC_OKCODE' '=YES'.

ENDFORM. " load_bdcdata

Read only

Former Member
0 Likes
2,684

Hi Prasad,

It's not like we will write a separate program to handle the errors in BDC.

When you writing an BDC program with Call Transaction Method you need handle all the errors manually i.e u need to create a structure with refrence to BDCMSGCAL and while writing the code for Call Transaction Syntax you need to mention the messages into the TAble which is created with refernce to BDCMSGCAL.

Reward Point If useful.

Regards,

Suma

Read only

manubhutani
Active Contributor
0 Likes
2,684

HI

In call transaction method u handle errors by passing the error and success message in an internal table

like this

DATA : T_BDCMSGCOLL LIKE STANDARD TABLE OF BDCMSGCOLL WITH HEADER LINE.

CLEAR w_ctu_params.

w_ctu_params-dismode = 'N'.

w_ctu_params-updmode = 'S'.

w_ctu_params-cattmode = ' '.

w_ctu_params-defsize = ' '.

w_ctu_params-racommit = ' '.

w_ctu_params-nobinpt = 'X'.

w_ctu_params-nobiend = ' '.

CALL TRANSACTION tcode USING t_bdcdata

*mode 'N' update 'S'

OPTIONS FROM w_ctu_params

MESSAGES INTO t_bdcmsgcoll.

then you can use this func module to format the messages

LOOP AT t_bdcmsgcoll.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = t_bdcmsgcoll-msgid

lang = sy-langu

no = t_bdcmsgcoll-msgnr

v1 = t_bdcmsgcoll-msgv1

v2 = t_bdcmsgcoll-msgv2

v3 = t_bdcmsgcoll-msgv3

v4 = t_bdcmsgcoll-msgv4

IMPORTING

msg = err_msg

EXCEPTIONS

not_found = 1

OTHERS = 2.

IF sy-subrc = 0.

MOVE err_msg TO w_return-message.

APPEND w_return TO return.

ENDIF.

ENDLOOP.

as messages are in the form of nos.. this FM converts those numbers into useful messages

In the session method,

you can see the log there in the transaction sm35..

p-lease reward points..

Read only

0 Likes
2,684

Hi Durga,

Can u tell me about the ctu_param.

Regards,

Gopi.vardhan