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

Send Notification (BDC Batch Input Session)

Former Member
0 Likes
1,230

Hi All,

I have a requirement in which I am updating two transactions using BDC(Batch Input) sessions. After BDC_CLOSE_GROUP, I am using SUBMIT RSBDCSUB for processing these sessions from report itself.

Once the processing is done,I need to send a notification via e mail with the count loaded, count rejected and load time. Do we have some function modules to achieve this? Please help me out.

Thanks in advance

Aparna Venugopal

5 REPLIES 5
Read only

Former Member
0 Likes
865

Hi Aparna,

You can use the fuction module SO_DOCUMENT_SEND_API1 to send notification after your code for SUBMIT. To find the number of records uploaded successfully you can have the variable counter and from messtab of BDC you can come to know about number of error records.

eg. Total records = No of records from flat file. You can use describe command for internal table for this.

Error records = No of records from messtab tab returned by BDC

Successful = Tolal - Error.

And send the information in mail.

Read only

Former Member
0 Likes
865

hi

Could you please elaborate on the point "messtab from BDC".I am using Batch Input Method and not Call Transaction method.In that case how will I get the messtab from BDC.

Your inputs will be really valuable as this is very urgent

Thanks in advance

Aparna Venugopal

Read only

Former Member
0 Likes
865

Hi,

Use the following the example to count the error, success records and format the the error message into an internal table. Merge the entire information into an internal table and create an attachment using the FM

SO_DOCUMENT_SEND_API1 to send the notification.

  • Success Record Structure

TYPES: BEGIN OF ty_success,

legven(16) TYPE c,

sapven(100) TYPE c,

END OF ty_success.

  • Error Record Structure

TYPES: BEGIN OF ty_error,

errmsg1 TYPE string,

errmsg2 TYPE string,

END OF ty_error.

data:

i_success TYPE STANDARD TABLE OF ty_success, "Success Records Internal Table

i_error TYPE STANDARD TABLE OF ty_error, "Error Records Internal Table

w_success TYPE ty_success, "Success Records Work Area

w_error TYPE ty_error, "Error Records Work Area

Loop at it_data.

CALL TRANSACTION 'XK01' USING i_bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO i_bdcmsgcoll.

PERFORM populate_status_msg.

FORM populate_status_msg.

SORT i_bdcmsgcoll BY msgtyp msgv1 DESCENDING.

READ TABLE i_bdcmsgcoll

INTO w_bdcmsgcoll

WITH KEY msgtyp = 'E'.

IF sy-subrc EQ 0.

*Counter to count the error records.

E = E + 1.

*Function Module for Formatting the Messages

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = w_bdcmsgcoll-msgid

lang = '-D'

no = w_bdcmsgcoll-msgnr

v1 = w_bdcmsgcoll-msgv1

v2 = w_bdcmsgcoll-msgv2

v3 = w_bdcmsgcoll-msgv3

v4 = w_bdcmsgcoll-msgv4

IMPORTING

msg = v_msgstr

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.

  • Moving Error Records to Error Internal Table

w_error-errmsg1 = w_xk01.

w_error-errmsg2 = v_msgstr.

APPEND w_error TO i_error.

CLEAR w_error.

ENDIF.

READ TABLE i_bdcmsgcoll

INTO w_bdcmsgcoll

WITH KEY msgtyp = 'S'.

IF sy-subrc = 0.

*Counter to count the success records.

S = S + 1.

  • Function Module for Formatting the Messages

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = w_bdcmsgcoll-msgid

lang = '-D'

no = w_bdcmsgcoll-msgnr

v1 = w_bdcmsgcoll-msgv1

v2 = w_bdcmsgcoll-msgv2

v3 = w_bdcmsgcoll-msgv3

v4 = w_bdcmsgcoll-msgv4

IMPORTING

msg = v_msgstr

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.

  • Moving Success Records to Success Internal Table

w_success-legven = w_xk01-lifnr.

w_success-sapven = w_bdcmsgcoll-msgv1.

APPEND w_success TO i_success.

CLEAR w_success.

ENDIF.

REFRESH i_bdcmsgcoll.

ENDFORM. "DOWNLOAD_STAT_MSG

Reward if useful.

Chandrasekhar K

Read only

Former Member
0 Likes
865

Hi,

I am using Batch Input Session and not Call Transaction method.I want to get the messtab in case of Batch Input Method.

Thanks in advance

Aparna Venugopal

Read only

0 Likes
865

Hi,

U can get the details about the processed or failed records from the table APQI. U can obtain this information from this table using GROUPID (Session name), TRANSCNT (Total number of Records) and TRANSCNTE (Transactions with errors) fields.

for example:

data: tot_rec like apqi-transcnt,

err_rec like apqi-transcnte,

suc_rec type number. "no. of successfully processed records

select TRANSCNT TRANSCNTE from APQI into (tot_rec, err_rec) where GROUPID = session_name.

suc_rec = tot_rec - err_rec.

Now format the document to be sent with the error messages according to ur requirements and call the FM SO_NEW_DOCUMENT_SEND_API to send the email.

I think this is enough for u according to ur requirements. Apart from this u can have a look at the following example also.

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

Reward points accordingly.

Chandrasekhar K