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 error handling

Former Member
0 Likes
1,213

Hi Guys, I have a doubt. I'm developing a BDC for KS01 cost center. Everything is working fine, what I want to do is to create a customized message if there is any error in the uploading, say for example I have ten records the 8th record has an error now I need to know which is the record containing error how to do tat??

Just give me an idea please. I have tried using bdcmsgcoll but not getting the right kind of output I'm expecting..All I want is how to determine the number of the record containing the error..Please help

Regards

Ajay

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,180

hi wat u can do is...inside

inside form bdc_transaction aftr call transaction u can get all messages ...like dis...

LOOP AT messtab INTO wa_messtab.

SELECT SINGLE *

FROM t100

WHERE sprsl = wa_messtab-msgspra

AND arbgb = wa_messtab-msgid

AND msgnr = wa_messtab-msgnr.

IF sy-subrc = 0.

l_mstring = t100-text.

IF l_mstring CS '&1'.

REPLACE '&1' WITH wa_messtab-msgv1 INTO l_mstring.

REPLACE '&2' WITH wa_messtab-msgv2 INTO l_mstring.

REPLACE '&3' WITH wa_messtab-msgv3 INTO l_mstring.

REPLACE '&4' WITH wa_messtab-msgv4 INTO l_mstring.

ELSE.

REPLACE '&' WITH wa_messtab-msgv1 INTO l_mstring.

REPLACE '&' WITH wa_messtab-msgv2 INTO l_mstring.

REPLACE '&' WITH wa_messtab-msgv3 INTO l_mstring.

REPLACE '&' WITH wa_messtab-msgv4 INTO l_mstring.

ENDIF.

CONDENSE l_mstring.

**Put all Non Sucess Messages to the internal table

IF wa_messtab-msgtyp EQ 'E' or wa_messtab-msgtyp EQ 'A'.

One way:

wa_outtab-keyfield1 = 'value.

wa_outtab-msgtyp = 'E'.

wa_outtab-mstring = l_mstring.

APPEND wa_outtab to it_outtab. "the error row appended to one internal table

Second way:

READ TABLE it_final into wa_final with key field = wa_value.

v_line = sy-index. "The error line in the table

ENDIF.

ENDIF.

ENDIF.

CLEAR: wa_messtab,

wa_outtab.

ENDLOOP.

9 REPLIES 9
Read only

Former Member
0 Likes
1,180

Hi,

After CALL TRANSACTION statement, you will be checking for the SY_SUBRC or the message table I_MSGTAB of type BDCMSGCOLL for the success or error of the record.

Use a variable to get count of the record when looping the final internal table.

Keep appending the count and the content of the record from final internal table to another internal table ITAB to know the record failed or successfully uploaded.

And finally move the ITAB content to another file and save it to know the records failed or successfully uploaded.

With Regards,

Dwaraka.S

Read only

Mohamed_Mukhtar
Active Contributor
0 Likes
1,180

Hi,

in loop ...endloop , you can do error handling.

set a flag for error records.

for example

LOOP AT it_records INTO wa_records.
 IF wa_records-move_type IS NOT INITIAL.
    DATA wa_bwart TYPE bwart.
    SELECT SINGLE bwart FROM t156 INTO wa_bwart
                                  WHERE bwart = wa_records-move_type.
    IF sy-dbcnt EQ 0.
      wa_error = wa_records.
      wa_error-text = 'In valid Movement Type'.
      wa_flag = 'X'.
    ELSE.
      wa_error = wa_records.
    ENDIF.
  ELSE.
    wa_error = wa_records.
    wa_error-text = 'Movement type cannot be blank'..
    wa_flag = 'X'.
  ENDIF.
" you can do validations for every field of a record.

if wa_flag is not intial.

" write code here to upadte datables

else.

append wa_error to it_error.
clear wa_flag"

ENDLOOP.

After the loop statements is processed completely.Error table contains error records.

Download these error records with GUI_DOWNLOAD.

Thanks & REgards

Read only

Former Member
0 Likes
1,180

Hi,

If you give any error records to the transaction, it'll give standard error message. now u can capture using BDCMSGCOLL,

but u want customized error message right?

For this find out any user exit or Badi before std error message getting triggered, and do all ur validations in the user exit to find out error records and raise ur customized error message.

or else do ur validations in the program itself to find error records and pass ony correct records to BDC.

Read only

Former Member
0 Likes
1,180

HI.

Refer this code.

Call this perform after call transaction

perform f_error_msg .

form f_error_msg .

data: v_err_msg(250).

loop at it_messtab.

**To find Message

call function 'FORMAT_MESSAGE'

exporting

id = it_messtab-msgid

lang = it_messtab-msgspra

no = it_messtab-msgnr

v1 = it_messtab-msgv1

v2 = it_messtab-msgv2

v3 = it_messtab-msgv3

v4 = it_messtab-msgv4

importing

msg = v_err_msg

exceptions

not_found = 1

others = 2

.

if sy-subrc = 0.

write: v_err_msg.

endif.

endloop.

clear:it_messtab.

endform. " f_error_msg

REgards,

Jay

Read only

Former Member
0 Likes
1,181

hi wat u can do is...inside

inside form bdc_transaction aftr call transaction u can get all messages ...like dis...

LOOP AT messtab INTO wa_messtab.

SELECT SINGLE *

FROM t100

WHERE sprsl = wa_messtab-msgspra

AND arbgb = wa_messtab-msgid

AND msgnr = wa_messtab-msgnr.

IF sy-subrc = 0.

l_mstring = t100-text.

IF l_mstring CS '&1'.

REPLACE '&1' WITH wa_messtab-msgv1 INTO l_mstring.

REPLACE '&2' WITH wa_messtab-msgv2 INTO l_mstring.

REPLACE '&3' WITH wa_messtab-msgv3 INTO l_mstring.

REPLACE '&4' WITH wa_messtab-msgv4 INTO l_mstring.

ELSE.

REPLACE '&' WITH wa_messtab-msgv1 INTO l_mstring.

REPLACE '&' WITH wa_messtab-msgv2 INTO l_mstring.

REPLACE '&' WITH wa_messtab-msgv3 INTO l_mstring.

REPLACE '&' WITH wa_messtab-msgv4 INTO l_mstring.

ENDIF.

CONDENSE l_mstring.

**Put all Non Sucess Messages to the internal table

IF wa_messtab-msgtyp EQ 'E' or wa_messtab-msgtyp EQ 'A'.

One way:

wa_outtab-keyfield1 = 'value.

wa_outtab-msgtyp = 'E'.

wa_outtab-mstring = l_mstring.

APPEND wa_outtab to it_outtab. "the error row appended to one internal table

Second way:

READ TABLE it_final into wa_final with key field = wa_value.

v_line = sy-index. "The error line in the table

ENDIF.

ENDIF.

ENDIF.

CLEAR: wa_messtab,

wa_outtab.

ENDLOOP.

Read only

0 Likes
1,180

Guys thanks all of u..Really helped a lot..

but what i did was, I had put a counter CNT type i and uploaded the data into an internal table..like dis

DATA : BEGIN OF IT_ER OCCURS 0,

MSG(250),

CT TYPE I,

END OF IT_ER.

DATA : CNT TYPE I.

"After the call transaction..

CNT = CNT + 1.

IF SY-SUBRC IS INITIAL.

IT_ER-MSG = 'THE RECORD', CNT 'CREATED'.

ELSE.

IT_ER-MSG = 'THE RECORD', CNT 'NOT CREATED'.

APPEND IT_ER.

CLEAR IT_ER.

ENDIF.

But for this getting a syntax error..Pls help..

Error was comma without preceding colon after it_er-msg?

What is the right syntax for this?

Read only

0 Likes
1,180

hi,

Instead of IT_ER-MSG = 'THE RECORD', CNT 'CREATED'.

Use Concatenate 'THE RECORD', CNT 'CREATED' INTO IT_ER-MSG SEPERATED BY Space.

CNT = CNT + 1.
IF SY-SUBRC IS INITIAL.
Concatenate 'THE RECORD' CNT 'CREATED' INTO IT_ER-MSG SEPERATED BY Space.
ELSE.
Concatenate 'THE RECORD' CNT 'NOT CREATED' INTO IT_ER-MSG SEPERATED BY Space.
APPEND IT_ER.
CLEAR IT_ER.
ENDIF.

Read only

0 Likes
1,180

hi...

data:v_cnt(10) type c.

CNT = CNT + 1.

v_cnt = cnt.

IF SY-SUBRC IS INITIAL.

Concatenate 'THE RECORD' v_cnt 'CREATED' INTO IT_ER-MSG SEPERATED BY Space.

ELSE.

Concatenate 'THE RECORD' v_cnt 'NOT CREATED' INTO IT_ER-MSG SEPERATED BY Space.

APPEND IT_ER.

CLEAR IT_ER.

ENDIF.

Read only

0 Likes
1,180

Dear TT thanks a lot for your responses..Actually I'm familiar with concatenate but wanted to know if any other solution apart from Concatenate is there?? But your replies helped a lot man..thanks a heap..

Regards

Ajay