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

Former Member
0 Likes
934

Hi,

I am using tcode f-02 for GL Opening Balance and for uploading I used the BDC programming and everything is works fine.

But how should I handle the errors using BDCMSGCOLL.

THanks,

Pavan.

1 ACCEPTED SOLUTION
Read only

vinod_gunaware2
Active Contributor
0 Likes
888

Hi

Have look belwo code it will be useful.

  • Set the parameters for Call Transaction

CLEAR WA_CTU_PARAMS.

WA_CTU_PARAMS-DISMODE = 'N'.

WA_CTU_PARAMS-UPDMODE = 'S'.

WA_CTU_PARAMS-NOBINPT = 'X'.

WA_CTU_PARAMS-NOBIEND = 'X'.

WA_CTU_PARAMS-DEFSIZE = 'X'.

  • Call Transaction MM01

IF W_FLAG NE 'X'.

CALL TRANSACTION 'MM01' USING T_BDCDATA OPTIONS FROM WA_CTU_PARAMS

MESSAGES INTO T_BDCMSGCOLL.

COMMIT WORK AND WAIT.

DESCRIBE TABLE T_BDCMSGCOLL LINES N.

IF N <> 0.

LOOP AT T_BDCMSGCOLL INTO WA_BDCMSGCOLL.

CLEAR ERR_LOG.

W_MSGNO = WA_BDCMSGCOLL-MSGNR.

CALL FUNCTION 'WRITE_MESSAGE'

EXPORTING

MSGID = WA_BDCMSGCOLL-MSGID

MSGNO = W_MSGNO

MSGTY = WA_BDCMSGCOLL-MSGTYP

IMPORTING

MESSG = ERR_LOG.

  • Error that occurs during transactoon

IF ERR_LOG-MSGTY = 'E'.

MOVE-CORRESPONDING T_UPLOAD TO T_DOWNLOAD.

MOVE ERR_LOG-MSGTX TO T_DOWNLOAD-MSG.

APPEND T_DOWNLOAD.

ENDIF.

ENDLOOP.

ENDIF.

ENDIF.

regards

vinod

8 REPLIES 8
Read only

Former Member
0 Likes
888

Hi pavan,

1. BDCMSGCOLL

All the messages (whether error/warning / success)

will get collected in bdcmsgcoll.

2. Just display them to the users.

3. We cannot take any action based on these

errors thru abap code,

bcos these errors are subjective

and can be diagnosed only by the user.

regards,

amit m.

Read only

Former Member
0 Likes
888

Here is the syntax for CALL TRANSACTION:

CALL TRANSACTION... { {[MODE mode] [UPDATE upd]}

| [OPTIONS FROM opt] }

[MESSAGES INTO itab] ... .

You can declare an internal table of type BDCMSGCOLL in your program and use the MESSAGES INTO option to get all error/warning/success messages into the same. You can then loop at this itab and display the messages to the user.

Hope this helps.

Sudha

Read only

vinod_gunaware2
Active Contributor
0 Likes
889

Hi

Have look belwo code it will be useful.

  • Set the parameters for Call Transaction

CLEAR WA_CTU_PARAMS.

WA_CTU_PARAMS-DISMODE = 'N'.

WA_CTU_PARAMS-UPDMODE = 'S'.

WA_CTU_PARAMS-NOBINPT = 'X'.

WA_CTU_PARAMS-NOBIEND = 'X'.

WA_CTU_PARAMS-DEFSIZE = 'X'.

  • Call Transaction MM01

IF W_FLAG NE 'X'.

CALL TRANSACTION 'MM01' USING T_BDCDATA OPTIONS FROM WA_CTU_PARAMS

MESSAGES INTO T_BDCMSGCOLL.

COMMIT WORK AND WAIT.

DESCRIBE TABLE T_BDCMSGCOLL LINES N.

IF N <> 0.

LOOP AT T_BDCMSGCOLL INTO WA_BDCMSGCOLL.

CLEAR ERR_LOG.

W_MSGNO = WA_BDCMSGCOLL-MSGNR.

CALL FUNCTION 'WRITE_MESSAGE'

EXPORTING

MSGID = WA_BDCMSGCOLL-MSGID

MSGNO = W_MSGNO

MSGTY = WA_BDCMSGCOLL-MSGTYP

IMPORTING

MESSG = ERR_LOG.

  • Error that occurs during transactoon

IF ERR_LOG-MSGTY = 'E'.

MOVE-CORRESPONDING T_UPLOAD TO T_DOWNLOAD.

MOVE ERR_LOG-MSGTX TO T_DOWNLOAD-MSG.

APPEND T_DOWNLOAD.

ENDIF.

ENDLOOP.

ENDIF.

ENDIF.

regards

vinod

Read only

0 Likes
888

hi,

Look at the sample code

DATA: BEGIN OF IT_MREC,

TCODE LIKE BDCMSGCOLL-TCODE,

DYNAME LIKE BDCMSGCOLL-DYNAME,

DYNUMB LIKE BDCMSGCOLL-DYNUMB,

MSGTYP LIKE BDCMSGCOLL-MSGTYP,

MSGSPRA LIKE BDCMSGCOLL-MSGSPRA,

MSGID LIKE BDCMSGCOLL-MSGID,

MSGNR LIKE BDCMSGCOLL-MSGNR,

MSGV1 LIKE BDCMSGCOLL-MSGV1,

MSGV2 LIKE BDCMSGCOLL-MSGV2,

MSGV3 LIKE BDCMSGCOLL-MSGV3,

MSGV4 LIKE BDCMSGCOLL-MSGV4,

ENV LIKE BDCMSGCOLL-ENV,

FLDNAME LIKE BDCMSGCOLL-FLDNAME,

END OF IT_MREC.

DATA: IT_MTAB LIKE BDCMSGCOLL OCCURS 0 "Ò¯¾°¼Þ—p

WITH HEADER LINE.

REFRESH: IT_MTAB.

CALL TRANSACTION WK_TRANSCD

USING BDCDATA

MODE WK_NODISP

UPDATE WK_UMODE

MESSAGES INTO IT_MTAB.

WK_SUBRC = SY-SUBRC.

IF WK_SUBRC = 0.

PERFORM ENQUEUE_ZAT43.

DELETE FROM ZAT43 WHERE BUKRS = PR_BUKRS

AND SEQNO = ITAB_REC-SEQNO.

CASE SY-SUBRC.

WHEN 0.

COMMIT WORK.

WHEN 4.

WHEN OTHERS.

MESSAGE A004 WITH 'ZAT43' SY-SUBRC.

ENDCASE.

PERFORM DEQUEUE_ZAT43.

ELSE.

WK_RCD = SY-SUBRC.

MESSAGE S053(ZY) WITH IT_MSGF0 WK_RCD.

LOOP AT IT_MTAB.


MOVE IT_MTAB TO IT_MREC.
IT_MSGF1-MSG11_TCODE = IT_MREC-TCODE.
IT_MSGF1-MSG12_DYNAME = IT_MREC-DYNAME.
IT_MSGF2-MSG21_DYNUMB = IT_MREC-DYNUMB.
IT_MSGF2-MSG22_MSGTYP = IT_MREC-MSGTYP.
IT_MSGF3-MSG31_FLDNAME = IT_MREC-FLDNAME.

MESSAGE S054(ZY) WITH IT_MSGF1 IT_MSGF2 IT_MSGF3.

MESSAGE ID IT_MREC-MSGID
TYPE 'S'
NUMBER IT_MREC-MSGNR
WITH IT_MREC-MSGV1
IT_MREC-MSGV2
IT_MREC-MSGV3
IT_MREC-MSGV4.

ENDLOOP

Hope it helps,

Regards,

Santosh P

Read only

Former Member
0 Likes
888

Hi,

While doing call transaction, if an error occurs in updation, we declare bdcmsgcoll and store our messages in it and to retreive error message from it use function module 'FORMAT_MESSAGE' and capture the messages.

Here is a sample of the program code for that:

LOOP AT it_messtab.

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

IMPORTING

msg = g_msg

EXCEPTIONS

OTHERS = 0.

IF it_messtab-msgtyp = 'S'.

it_sucess-sucess_rec = g_msg.

it_sucess-lifnr = it_header-lifnr." Based on your field

it_sucess-tabix = v_lines.

APPEND it_sucess.

ELSEIF it_messtab-msgtyp = 'E'.

it_error-error_rec = g_msg.

it_error-lifnr = it_header-lifnr.

it_error-tabix = v_lines.

APPEND it_error.

ELSE.

it_info-info_rec = g_msg.

it_info-lifnr = it_header-lifnr.

it_info-tabix = v_lines.

APPEND it_info.

ENDIF.

ENDLOOP.

Regards,

Anjali

Read only

hymavathi_oruganti
Active Contributor
0 Likes
888

hi,

1. declare an internal table like BDCMSGCOLL.

let it be T_BDCMSGCOLL.

2. now,

CALL TRANSACTION tcode USING itab MESSAGESD T_BDCMSGCOLL

<b>NOTE: BDCMSGCOLL is an internal table which has, MSGNO, ID etc But it doesnot return <b>MESSAGE TEXT</b></b>

so, to get the message text,

we can call any of the following fn modules, whic take message id, no etc and return message text

"FORMAT_MESSAGE", "WRITE_MESSAGE", "BAPI_GET_MESSAGE_DETAIL" etc.

3.another easiest method is,

<b>READ TABLE T100 WITH KEY ID = MSGID.

WRITE T100-MSGTXT.</b>

Read only

Former Member
0 Likes
888

Hi all,

Thanks for your response.

I coded like this, if there is any issues please correct me :

IF SY-SUBRC NE 0.

LOOP AT messtab WHERE msgtyp = 'E'.

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.

write : / w_textout.

ENDLOOP.

ENDIF.

In the above code messtab is the internal table for BDCMSGCOLL.

Please let me know.

Thanks,

Pavan.

Message was edited by: Pavan Panduru

Read only

0 Likes
888

Hi again,

1. Ya its perfectly right !

regards,

amit m.