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

Former Member
0 Likes
389

Hi Friends,

how can we send the error record from the error log file ( in session method) to the client.

2 REPLIES 2
Read only

Former Member
0 Likes
358

Hi,

i had the same requirement as tht of urs. hope the following code helps u.

here im trying to run a BDC program to update the material std price.

first i will run the call transaction method .if that fails i will run the session method and hold the failed execution in a session and jst notify the user abt the same in a mail.hope this is part of ur requirement

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

PERFORM call_transaction_mr21.

ENDLOOP.

  • Perform bdc close group

IF gv_bdc_open_flag = gc_x.

PERFORM bdc_close_group.

ENDIF.

  • Send the log mail

PERFORM send_log_mail.

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

  • Local Data Declaration

CONSTANTS:lc_e TYPE c VALUE 'E',

lc_mr21(4) TYPE c VALUE 'MR21',

lc_mode(1) TYPE c VALUE 'N',

lc_update(1) TYPE c VALUE 'U'.

REFRESH: gt_bdc_msg.

  • Call MR21 Transaction

CALL TRANSACTION lc_mr21

USING gt_bdc_tab

MODE lc_mode

UPDATE lc_update

MESSAGES INTO gt_bdc_msg.

  • If the Call Transaction Fails

IF sy-subrc NE 0.

IF gv_bdc_open_flag IS INITIAL.

PERFORM bdc_open_group.

gv_bdc_open_flag = gc_x.

ENDIF.

PERFORM bdc_insert_group.

DELETE gt_bdc_msg WHERE msgtyp NE lc_e.

  • If the message table is having error mesasges

IF gt_bdc_msg IS NOT INITIAL.

gs_error-matnr = gs_cbht-matnr.

APPEND gs_error TO gt_error.

CLEAR gs_error.

ENDIF.

REFRESH:gt_bdc_msg,

gt_bdc_tab.

ELSE.

gs_success-matnr = gs_cbht-matnr.

APPEND gs_success TO gt_success.

CLEAR gs_success.

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

FORM bdc_insert_group .

CALL FUNCTION 'BDC_INSERT'

EXPORTING

tcode = 'MR21'

TABLES

dynprotab = gt_bdc_tab

EXCEPTIONS

internal_error = 1

not_open = 2

queue_error = 3

tcode_invalid = 4

printing_invalid = 5

posting_invalid = 6

OTHERS = 7.

IF sy-subrc <> 0.

WRITE 😕 text-014. "Error in BDC_INSERT

EXIT.

ENDIF.

ENDFORM. " BDC_INSERT_GROUP

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

  • Creating the document to be sent with success message.

IF gt_error IS INITIAL.

gs_doc_chng-obj_name = 'Standard Price'(010).

gs_doc_chng-obj_descr = 'Material Standard Price update Successful'(011)

.

gs_objtxt = 'Materials updated Sucessfully with new Standard Price'(012)

.

APPEND gs_objtxt TO gt_objtxt.

LOOP AT gt_success INTO gs_success.

gs_objtxt = gs_success.

APPEND gs_objtxt TO gt_objtxt.

ENDLOOP.

ELSE.

  • Creating the document to be sent with error message.

gs_doc_chng-obj_name = 'Error Price'(002).

gs_doc_chng-obj_descr = 'Material Standard Price Updation Errors'(003)

.

gs_objtxt = 'The following Material Numbers failed to update'(004).

APPEND gs_objtxt TO gt_objtxt.

LOOP AT gt_error INTO gs_error.

gs_objtxt = gs_error.

APPEND gs_objtxt TO gt_objtxt.

ENDLOOP.

IF gt_success IS NOT INITIAL.

gs_objtxt = 'Materials updated Sucessfully with New Standard Price'(012)

.

APPEND gs_objtxt TO gt_objtxt.

LOOP AT gt_success INTO gs_success.

gs_objtxt = gs_success.

APPEND gs_objtxt TO gt_objtxt.

ENDLOOP.

ENDIF.

ENDIF.

DESCRIBE TABLE gt_objtxt LINES gv_tab_lines.

READ TABLE gt_objtxt INTO gs_objtxt INDEX gv_tab_lines.

gs_doc_chng-doc_size = ( gv_tab_lines - 1 ) * 255 + STRLEN( gs_objtxt )

.

  • Creating the entry for the compressed document

CLEAR gs_objpack-transf_bin.

gs_objpack-head_start = 1.

gs_objpack-head_num = 0.

gs_objpack-body_start = 1.

gs_objpack-body_num = gv_tab_lines.

gs_objpack-doc_type = 'RAW'.

APPEND gs_objpack TO gt_objpack.

  • Entering names in the distribution list

IF p_plist IS NOT INITIAL.

gs_reclist-receiver = p_plist.

gs_reclist-rec_type = gc_c.

APPEND gs_reclist TO gt_reclist.

CLEAR gs_reclist.

ENDIF.

  • Populating the reciever list

gs_reclist-receiver = p_plist.

gs_reclist-rec_type = gc_u.

APPEND gs_reclist TO gt_reclist.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = gs_doc_chng

put_in_outbox = gc_x

commit_work = gc_x

TABLES

packing_list = gt_objpack

object_header = gt_objhead

contents_bin = gt_objbin

contents_txt = gt_objtxt

receivers = gt_reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

CASE sy-subrc.

WHEN 0.

WRITE: 'eMail sent successfully'(005).

WHEN OTHERS.

WRITE: / 'eMail could not be sent'(008).

ENDCASE.

Read only

Former Member
0 Likes
358

Hai Balaji

Go through the following Code for your requirement

report Z_CALLTRANS_VENDOR_01

no standard page heading line-size 255.

      • Generated data section with specific formatting - DO NOT CHANGE ***

data: begin of it_lfa1 occurs 0,

KTOKK like lfa1-ktokk,

NAME1 like lfa1-name1,

SORTL like lfa1-sortl,

LAND1 like lfa1-land1,

end of it_lfa1.

      • End generated data section ***

data : it_bdc like bdcdata occurs 0 with header line.

*DATA: IT_MESSAGES TYPE TABLE OF BDCMSGCOLL WITH HEADER LINE.

*DATA: LV_MESSAGE(255).

data : it_messages like bdcmsgcoll occurs 0 with header line.

data : V_message(255).

data : V_flag.

data : V_datum1 type sy-datum.

data : begin of it_mesg occurs 0,

message(100),

end of it_mesg.

*V_datum1 = sy-datum-1.

parameters : P_Sess like APQI-GROUPID.

start-of-selection.

perform Get_data.

*perform open_group.

loop at it_lfa1.

perform bdc_dynpro using 'SAPMF02K' '0100'.

perform bdc_field using 'BDC_CURSOR'

'RF02K-KTOKK'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RF02K-KTOKK'

it_lfa1-KTOKK.

perform bdc_dynpro using 'SAPMF02K' '0110'.

perform bdc_field using 'BDC_CURSOR'

'LFA1-LAND1'.

perform bdc_field using 'BDC_OKCODE'

'=UPDA'.

perform bdc_field using 'LFA1-NAME1'

it_lfa1-name1.

perform bdc_field using 'LFA1-SORTL'

it_lfa1-sortl.

perform bdc_field using 'LFA1-LAND1'

it_lfa1-land1.

call transaction 'XK01' using it_bdc

mode 'N'

update 'S'

messages into it_messages.

if sy-subrc <> 0.

if V_flag <> 'X'.

perform open_group.

V_flag = 'X'.

endif.

perform bdc_transaction. "using 'XK01'.

endif.

perform format_messages.

refresh : it_bdc,it_messages.

.

endloop.

if V_flag = 'X'.

perform close_group.

endif.

&----


*& Form Get_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM Get_data .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'C:\srinu_vendor.txt'

FILETYPE = 'DAT'

TABLES

DATA_TAB = it_lfa1

EXCEPTIONS

CONVERSION_ERROR = 1

INVALID_TABLE_WIDTH = 2

INVALID_TYPE = 3

NO_BATCH = 4

UNKNOWN_ERROR = 5

GUI_REFUSE_FILETRANSFER = 6

OTHERS = 7

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

ENDFORM. " Get_data

&----


*& Form bdc_dynpro

&----


  • text

----


  • -->P_0061 text

  • -->P_0062 text

----


FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR it_BDC.

it_BDC-PROGRAM = PROGRAM.

it_BDC-DYNPRO = DYNPRO.

it_BDC-DYNBEGIN = 'X'.

APPEND it_BDC.

ENDFORM.

----


  • Insert field *

----


FORM BDC_FIELD USING FNAM FVAL.

CLEAR it_BDC.

it_BDC-FNAM = FNAM.

it_BDC-FVAL = FVAL.

APPEND it_BDC.

ENDFORM.

&----


*& Form format_messages

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM format_messages .

loop at it_messages.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = it_messages-MSGID

LANG = 'EN'

NO = it_messages-MSGNR

V1 = it_messages-MSGV1

V2 = it_messages-MSGV2

V3 = it_messages-MSGV3

V4 = it_messages-MSGV4

IMPORTING

MSG = V_message

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_message.

clear : V_message.

endloop.

ENDFORM. " format_messages

&----


*& Form open_group

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM open_group .

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

GROUP = P_Sess

  • HOLDDATE = V_datum1

KEEP = 'X'

USER = SY-UNAME

.

IF SY-SUBRC = 0.

write : / 'Session Creating wit Name : ',P_Sess.

ENDIF.

ENDFORM. " open_group

&----


*& Form close_group

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM close_group .

CALL FUNCTION 'BDC_CLOSE_GROUP'.

ENDFORM. " close_group

&----


*& Form bdc_transaction

&----


  • text

----


  • -->P_0132 text

----


FORM bdc_transaction. "USING VALUE(P_0132).

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'XK01'

  • POST_LOCAL = NOVBLOCAL

  • PRINTING = NOPRINT

  • SIMUBATCH = ' '

  • CTUPARAMS = ' '

TABLES

DYNPROTAB = it_bdc

  • EXCEPTIONS

  • INTERNAL_ERROR = 1

  • NOT_OPEN = 2

  • QUEUE_ERROR = 3

  • TCODE_INVALID = 4

  • PRINTING_INVALID = 5

  • POSTING_INVALID = 6

  • OTHERS = 7

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

ENDFORM. " bdc_transaction

Regards

Sreeni