cancel
Showing results for 
Search instead for 
Did you mean: 

error handling in bdc Fb01along with erros in Idoc.

Former Member
0 Kudos
50

Hi,

Can any one send me the sample code for the error handling in bdc Fb01along with erros in Idoc. Actually, mail should be sent

Thanks

Avi.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

This may help you.

<b>FORM send_mail USING receiver.

CLEAR: w_lines,tbl_packing_list,tbl_object_header,

tbl_contents_txt, tbl_receivers.

REFRESH:tbl_packing_list, tbl_object_header,

tbl_contents_txt,tbl_receivers.

SORT tbl_err.

DELETE ADJACENT DUPLICATES FROM tbl_err COMPARING ALL FIELDS.

IF NOT tbl_err[] IS INITIAL.

  • Preparing the email.

PERFORM prepare_email.

ELSE.

  • If sy-subrc NE 0.

MOVE sy-subrc TO w_code.

  • ENDIF.

EXIT.

ENDIF.

  • Get the content of header e-mail document data

PERFORM document_data.

  • Get details of the error file attached (like type of file and format)

PERFORM packing_list.

  • Get receiver mail id's

tbl_receivers-receiver = receiver.

tbl_receivers-rec_type = 'C'.

tbl_receivers-express = c_flag.

tbl_receivers-sap_body = c_flag.

APPEND tbl_receivers.

*

  • Call FM to send E-mails to receivers

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = st_document_data

put_in_outbox = 'X'

TABLES

packing_list = tbl_packing_list

object_header = tbl_object_header

contents_txt = tbl_contents_txt

receivers = tbl_receivers[]

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

*

ENDFORM. " send_mail

&----


*& Form prepare_email

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM prepare_email.

  • E-Mail body content

IF NOT w_lifnr IS INITIAL.

CONCATENATE text-015 w_docnum text-016

INTO tbl_contents_txt-line

SEPARATED BY space.

ENDIF.

APPEND tbl_contents_txt.

CLEAR tbl_contents_txt.

*

  • E-mail error file attachment header

CONCATENATE text-063 text-064

text-065 text-066 c_comma

INTO tbl_contents_txt-line

SEPARATED BY c_comma.

APPEND tbl_contents_txt.

CLEAR tbl_contents_txt.

*

  • E-mail error file attachment content

LOOP AT tbl_err.

CONCATENATE w_docnum tbl_err-v_segnum

tbl_err-msg tbl_err-type

INTO tbl_contents_txt-line

SEPARATED BY c_comma.

CONCATENATE c_linefeed tbl_contents_txt-line c_comma

INTO tbl_contents_txt-line.

APPEND tbl_contents_txt.

CLEAR tbl_contents_txt.

ENDLOOP.

ENDFORM. " prepare_email

&----


*& Form document_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM document_data.

CLEAR w_line.

IF NOT w_lifnr IS INITIAL.

CONCATENATE text-075 text-027 sy-datum sy-uzeit INTO w_line

SEPARATED BY c_uscore.

ENDIF.

st_document_data-obj_name = w_line.

st_document_data-obj_descr = w_line.

st_document_data-priority = 1.

st_document_data-obj_prio = 1.

ENDFORM. " document_data

&----


*& Form packing_list

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM packing_list.

CLEAR w_lines.

DESCRIBE TABLE tbl_err LINES w_lines.

READ TABLE tbl_contents_txt INDEX w_lines.

*

tbl_packing_list-head_start = 1.

tbl_packing_list-head_num = 1.

tbl_packing_list-body_start = 1.

tbl_packing_list-body_num = 1.

tbl_packing_list-doc_type = 'RAW'.

APPEND tbl_packing_list.

tbl_packing_list-head_start = 1.

tbl_packing_list-head_num = 0.

tbl_packing_list-body_start = 2.

tbl_packing_list-body_num = w_lines + 1.

tbl_packing_list-doc_type = 'CSV'.

tbl_packing_list-obj_descr = 'Error_Attachment'(060).

IF NOT w_lifnr IS INITIAL.

tbl_packing_list-obj_name = 'Idoc Number is'(072).

ENDIF.

tbl_packing_list-doc_size = 255 * ( w_lines + 1 ).

APPEND tbl_packing_list.

*

ENDFORM. " packing_list

</b>

Thanks

Manju.

Answers (0)