Sie sind auf Seite 1von 36

Business Transaction Events

(see also TheSAPConsultan for duplicate invoice check process 00001110)


This activity describes how you can connect additional components (such as in the form of function modules developed yourself or a product from an external software provider) to the standard R/3 System. There are two types of interface available in the General Ledger Accounting (FI-GL), Accounts Receivable and Accounts Payable (FI-AR/FI-AP), and Sales and Distribution (SD) components for this: 1. Publish & Subscribe interfaces (also called "informing interfaces" in the following) These should inform you about particular events (such as a document being entered) in the SAP standard application and make the data generated as a result available to the external software. The external software does not return any data to the standard R/3 System. (I'm confused. MIT is using two business transaction events for the SD to FI interface. Both of these events are Publish & Subscribe interfaces. They both return data to the SAP standard application! They both change the FI document before it is posted. What I've figured out is that if there is an export to memory and an import from memory before and after the function call, then we can't modify the data. We can check this in the calling function module - OUTBOUND_CALL_00503110_E or OPEN_FI_PERFORM_00001020_E, etc) Examples of such events in the R/3 System are: * Master record was created, changed, or blocked * Document was entered, parked, changed, or reversed * Items were cleared or reset Additional processing can be caused in the additional component on the basis of these events and data: * Starting a workflow * Generating or changing additional data * Requesting correspondence FI Clearing (F-32) calls (gathered via SE30): Function OPEN_FI_PERFORM_00001020_E (can't modify data) 00001020 POST DOCUMENT: Prior to final checks

EVENT This Event is reached prior to completing the document. The checks that are carried out at this point include checking, prior to posting, that the document balances to zero, and calculations for tax offsetting. This Event is accessed once per standard posting process and is similar to validation at document level (Event 0003). A document number has not yet been assigned when this Event is reached. INTERFACE All document line items created and the document header data are transferred (both as tables).

Parameter T_BSEG T_BKPF Function OPEN_FI_PERFORM_00001025_E (can't modify data) 00001025 POST DOCUMENT: Final checks completed

EVENT This Event lies following all checks on the whole document, but prior to number assignment. Following this Event, no further error messages may be sent. The document is complete at this point, and no further changes can be made to it prior to posting. INTERFACE All current data, all document data relevant for the posting, and various control parameters are transferred to the additional component. At this point you can still implement your own checks on the current document data. Parameter I_BKDF T_AUSZ1 T_AUSZ2 T_AUSZ3 T_BKP1 T_BKPF T_BSEC T_BSED T_BSEG T_BSET T_BSEU Function OPEN_FI_PERFORM_00001030_E (can't modify data) Function OPEN_FI_PERFORM_00001140_E (can't modify data) 2. Process interfaces (also referred to as "process" in the following) Process interfaces are used to submit business processes to a different control which cannot be realized with the standard system, that is process interfaces replace standard processes. Here you can structure determination of individual field contents or of specific reactions to process flows individually. It is possible to connect different external developments to the standard R/3 System. The additional developments are generally carried out using the ABAP/4 Development Workbench. This way you can, for example, influence the control of payment transactions. Selection of payment method, house bank and partner bank can be made using the payment data (currency, amount, and payee) according to a selection logic which you have defined. FI Clearing (F-32) calls: Function Function Function Function OPEN_FI_PERFORM_00001120_P OPEN_FI_PERFORM_00001130_P OPEN_FI_PERFORM_00001150_P OPEN_FI_PERFORM_00001170_P

Standard Settings Sample modules are delivered in the standard R/3 System which you can copy into your name range and fill them with statements there.

Activities 1. Enter a product using "Settings -> Customer's products". Actually, in 4.6C, from transaction FIBF (IMG -> Financial Accounting -> Financial Accounting Global Settings -> Business Transaction Events): Settings -> Products -> ...of a customer

There are generally a large number of function modules belonging to a product which can be called by different program events from within the standard R/3 System. A product can also be an external software component. If the product is in an external system, enter an RFC destination here. If the product is in the same system, you do not have to enter anything. Important: Do not forget to activate the product after making the following settings. 2. Establish the interfaces with which the R/3 System provides you. To do this, choose Environment -> Info system (P/S) or Environment -> Info system (Processes).

Execute the program. You should enter "A" as the attribute type. You see the respective interfaces with which the R/3 System provides you. Note the key of the interface which you require. You can also select: * By particular SAP application components

* By particular events by entering intervals * Which interfaces are used in activated products * Which interfaces are used within a particular country version or within a particular industry * Which interfaces are used within a particular customer product

3. Enter the function module which you have developed yourself. To do this, choose either Goto -> Edit modules within the info system or Settings -> P/S modules or Process modules -> Customer's in the "SAP Business Framework" menu. Make the following entries: * Key for the interface * The product that you want to use * Function module which belongs to this product. You can also enter several function modules for a product. Caution: The function module must be within your name range, that is must begin with the letter Z. You leave the Ctr and Appl. fields blank unless you want a particular country version or a particular SAP industry-specific component to be enhanced or replaced instead of the

standard process flow. 4. Fill the source text of your function module and activate it. To do this, go again via Environment -> Info system (P/S) or Environment -> Info system (Processes) into the information system and execute the program. Then proceed as follows: * Click twice on the interface you have chosen. If you want, you can look at the interface at this point by choosing Goto -> Interface. Then choose the Back function again afterwards. * Place the cursor on the relevant line and choose Goto -> Function library. You see the sample function module delivered by SAP. * Copy the sample module delivered by SAP and call it the same as the function module entered in step 3. * Fill the source text of the empty function module. * Activate the function module. * Activate the product as described in step 1. 5. Run the R/3 program affected and test whether calling your function module works. Further Notes The other menu paths are only used for information about additional components delivered by SAP or about software already installed by external software providers.

SAP Business Transaction Events


Im extremely sorry that I couldnt write on my blog for some time because of the assignments that I had to finish for my clients! Today I got some free time and decided to talk about SAP business transaction events! SAP business transaction events are one type of customer enhancements provided by SAP! On this post Ill talk about how we can change the logic for duplicate vendor invoice check using SAP business transaction events! We can access the business transaction events using FIBF

Next we have to find the process interface for duplicate invoice check! To do that, follow the following steps. Select the menu as stated below

Execute the info system as stated below

All the processes will be shown below

Select the process 1110 and click on Sample function module as stated below

Copy the sample functional module SAMPLE_PROCESS_00001110 and create ZSAMPLE_PROCESS_00001110. Put the customized logic in the functional module ZSAMPLE_PROCESS_00001110 and activate it!

Now go back to FIBF and execute the menu as shown below

Define a new product and activate it

Now go back to FIBF and execute the menu as shown below

Assign the function module ZSAMPLE_PROCESS_00001110 to the process 1110and the product that was defined in the earlier step.

Bingo!!!!!! Now every time when a vendor invoice is being posted the invoice check will be carried out using the custom logic built into the function module ZSAMPLE_PROCESS_00001110. But make sure that the double invoice check tick has been put on the relevant vendor masters! I hope this post about the SAP business transaction events will help your business! Thank you very much for reading my blog! Please feel free to send me your comments!

Creation of Events via Business Transaction Events


Use
G/L accounting and accounts receivable/payable accounting provide publish and subscribe interfaces, which inform other application components or external interested parties (partners, customers) that particular events (such as document entered) have taken place in financial accounting. The data this creates can be used by the interested parties for their own subsequent processing. But no data can be returned to G/L accounting or accounts receivable/payable accounting. SAP Business Workflow uses this interface to create events of object types defined in the Business Object Repository from its events. These events can be used as triggering events of a workflow, for example.

Features
When a Business Transaction Event occurs the system calls a function module which creates the BOR event. To do this, this function module "converts" the data from the Business Transaction Event into the format suitable for the event and creates the appropriate event for the Business Transaction Event. The function module hence has a parameter interface and implementation which are appropriate for the Business Transaction Event. For every Business Transaction Event that can be linked to an event, SAP provides a suitable function module with appropriate interface and implementation. The following relationships are currently possible: Business Transaction Event Event

00001030

POST DOCUMENT: Update standard data

BKPF

Accounting document

CREATED

Document created

00001040

REVERSE CLEARING: After standard update

BKPF

Accounting document

CLEARINGREVERSED

Clearing reversed

00001050

POST DOCUMENT: FI/CO interface

BKPF

Accounting document

CREATED

Document created

00001110

CHANGE DOCUMENT: Save standard data

BKPF

Accounting document

CHANGED

Document changed

00001320

CUSTOMER MASTER DATA: Save

BUS3007

Customer account

CREATED

Account opened

00001420

VENDOR MASTER DATA: Save

BUS3008

Vendor account

CREATED

Account opened

00001520

CREDIT MANAGEMENT: Save

BUS1010

Customer credit account

CREATED

Account opened

Activities
The Business Transaction Events and the events are already defined. You may create the linkage between them. You can use a wizard for event creation.

Finally, you must set the status of the event whose creation you have just configured to released. To do this, call the Business Object Builder and change the release status of the event for the relevant object type.

REPORT zsmartformpdf_sendemail NO STANDARD PAGE HEADING LINE-SIZE 132 LINE-COUNT 65 MESSAGE-ID zchk. *----------------------------------------------------------------------* TABLES *----------------------------------------------------------------------TABLES : aufk,t352t,t003o,toa_dara,arc_params,nast. *----------------------------------------------------------------------* DATA: INTERNAL TABLES *----------------------------------------------------------------------DATA : it_aufk TYPE STANDARD TABLE OF aufk. DATA: it_lines TYPE STANDARD TABLE OF tline WITH HEADER LINE. DATA: BEGIN OF it_header OCCURS 0. " define a local table header INCLUDE STRUCTURE thead. " using SAPSCRIPT structure DATA: END OF it_header. DATA : wa_aufk LIKE LINE OF it_aufk. DATA : wa_lines LIKE LINE OF it_lines, v_bin_filesize TYPE i, it_docs TYPE STANDARD TABLE OF docs, it_lines1 TYPE STANDARD TABLE OF tline, v_name1 TYPE string, v_path TYPE string, v_fullpath TYPE string, v_filter TYPE string, v_uact TYPE i, v_guiobj TYPE REF TO cl_gui_frontend_services, v_filename TYPE string, v_fm_name TYPE rs38l_fnam. DATA : mstr_print_parms LIKE pri_params, mc_valid(1) TYPE c, mi_bytecount TYPE i, mi_length TYPE i, mi_rqident LIKE tsp01-rqident. DATA : p_linsz LIKE sy-linsz VALUE 132, " Line size p_paart LIKE sy-paart VALUE 'X_65_132'. " Paper Format DATA : var TYPE i VALUE 0 . DATA : p_repid LIKE sy-repid . DATA : it_tsp01 TYPE STANDARD TABLE OF tsp01 WITH HEADER LINE . DATA : it_pdf LIKE tline OCCURS 0 WITH HEADER LINE . * Spool to PDF conversions DATA: gd_spool_nr LIKE tsp01-rqident, gd_destination LIKE rlgrap-filename, gd_bytecount LIKE tst01-dsize, gd_buffer TYPE string. *DATA DECLARATION DATA: gd_recsize TYPE i.

* Spool IDs TYPES: BEGIN OF t_tbtcp. INCLUDE STRUCTURE tbtcp. TYPES: END OF t_tbtcp. DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0, wa_tbtcp TYPE t_tbtcp. * Job Runtime Parameters DATA: gd_eventid LIKE tbtcm-eventid, gd_eventparm LIKE tbtcm-eventparm, gd_external_program_active LIKE tbtcm-xpgactive, gd_jobcount LIKE tbtcm-jobcount, gd_jobname LIKE tbtcm-jobname, gd_stepcount LIKE tbtcm-stepcount, gd_error TYPE sy-subrc, gd_reciever TYPE sy-subrc. DATA: w_recsize TYPE i. DATA: gd_subject LIKE sodocchgi1-obj_descr, it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE, it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE, gd_sender_type LIKE soextreci1-adr_typ, gd_attachment_desc TYPE so_obj_nam, gd_attachment_name TYPE so_obj_des. *----------------------------------------------------------------------* DATA: VARIABLES *----------------------------------------------------------------------DATA: fm_sform TYPE rs38l_fnam, v_name TYPE thead-tdname. CONSTANTS: c_id(4) TYPE c VALUE 'KOPF', c_langu(1) TYPE c VALUE 'E', c_object(10) TYPE c VALUE 'AUFK'. *--Data Declaration for Printing Layout DATA: ls_itcpo TYPE itcpo. DATA: lf_repid TYPE sy-repid. DATA: lf_device TYPE tddevice. DATA: cf_retcode TYPE sy-subrc. DATA: ls_recipient TYPE swotobjid. DATA: ls_sender TYPE swotobjid. DATA: ls_control_param TYPE ssfctrlop. DATA: ls_composer_param TYPE ssfcompop. DATA: ls_addr_key LIKE addr_key. DATA: w_screen(1) TYPE c. DATA: xscreen(1) TYPE c. DATA: da_mess LIKE vbfs OCCURS 0 WITH HEADER LINE. DATA: ws_fname TYPE rs38l_fnam, ws_ctrlp TYPE ssfctrlop, ws_optns TYPE ssfcompop, w_padest LIKE tsp03l-padest. DATA: da_message_printed(1) TYPE c, da_preview_processed(1) TYPE c,

repeat(1) TYPE c, da_subrc LIKE sy-subrc. DATA: w_otfdata TYPE ssfcrescl. DATA: BEGIN OF it_itcoo OCCURS 0. INCLUDE STRUCTURE it coo. DATA: END OF it_itcoo. DATA: w_otf TYPE it coo. IMPORT var FROM MEMORY ID 'JIT1' . FREE MEMORY ID 'JIT1'. IF var = 0. *&---------------------------------------------------------------------* *& Form GET_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM get_data . SELECT aufnr auart zzplat objnr adrnra werks ktext zzplat saknr zzmainftln zzserviceloc zzcounty zzpremise zzpipe ktext adrnra erdat zzcross_street1 zzcross_street2 zzcurkcockftln INTO CORRESPONDING FIELDS OF TABLE it_aufk FROM aufk WHERE aufk~aufnr = s_aufnr. IF it_aufk IS INITIAL. MESSAGE i004. LEAVE TO LIST-PROCESSING. ENDIF. READ TABLE it_aufk INDEX 1 INTO wa_aufk. CONCATENATE sy-mandt wa_aufk-aufnr INTO v_name. *& read long text CALL FUNCTION 'READ_TEXT' EXPORTING id = c_id

language = c_langu name = v_name object = c_object IMPORTING header = it_header TABLES lines = it_lines EXCEPTIONS id =1 language =2 name =3 not_found =4 object =5 reference_check =6 wrong_access_to_archive = 7 OTHERS = 8. ENDFORM. " GET_DATA *&---------------------------------------------------------------------* *& Form CALL_FORM *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM call_form . DATA lv_msgtype TYPE sy-msgty. IMPORT it_aufk it_lines it_header FROM MEMORY ID 'JIT1' . IF var = 0. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname = 'ZPM_OPERATION' IMPORTING fm_name = fm_sform EXCEPTIONS no_form =1 no_function_module = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. CHECK NOT fm_sform IS INITIAL. CLEAR w_otfdata. ls_control_param-getotf = 'X'. CALL FUNCTION fm_sform TABLES it_aufk = it_aufk it_lines = it_lines it_header = it_header EXCEPTIONS formatting_error = 1 internal_error = 2

send_error =3 user_canceled = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. *-- Setup the Print Parmaters CALL FUNCTION 'GET_PRINT_PARAMETERS' EXPORTING authority = space copies = '1' cover_page = space data_set = space department = space destination = space expiration = '1' immediately = space new_list_id = 'X' no_dialog = 'X' user = sy-uname IMPORTING out_parameters = mstr_print_parms valid = mc_valid EXCEPTIONS archive_info_not_found = 1 invalid_print_params = 2 invalid_archive_params = 3 OTHERS = 4. *-- Make sure that a printer destination has been set up *-- If this is not done the PDF function module ABENDS IF mstr_print_parms-pdest = space. mstr_print_parms-pdest = 'LP01'. ENDIF. *-- Explicitly set line width, and output format so that *-- the PDF conversion comes out OK mstr_print_parms-linsz = p_linsz. mstr_print_parms-paart = p_paart. * for Submit the report to create the abapspool. var = var + 1. FREE MEMORY ID 'JIT1'. EXPORT it_aufk it_lines it_header var TO MEMORY ID 'JIT1' . SUBMIT (p_repid) TO SAP-SPOOL SPOOL PARAMETERS mstr_print_parms WITHOUT SPOOL DYNPRO AND RETURN. *selecting the spool request using the above consructed varibale SELECT * FROM tsp01 INTO TABLE it_tsp01 WHERE rq2name = sy-uname . IF sy-subrc = 0.

*sorting the internal table SORT it_tsp01 BY rqcretime DESCENDING . *reading the first spool request READ TABLE it_tsp01 INDEX 1. REFRESH it_pdf[]. CLEAR it_pdf. *converting the spool request into pdf CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF' EXPORTING src_spoolid = it_tsp01-rqident no_dialog ='' TABLES pdf = it_pdf EXCEPTIONS err_no_otf_spooljob =1 err_no_spooljob =2 err_no_permission =3 err_conv_not_possible = 4 err_bad_dstdevice =5 user_cancelled =6 err_spoolerror =7 err_temseerror =8 err_btcjob_open_failed = 9 err_btcjob_submit_failed = 10 err_btcjob_close_failed = 11. CHECK sy-subrc = 0. * Transfer the 132-long strings to 255-long strings LOOP AT it_pdf. TRANSLATE it_pdf USING ' ~'. CONCATENATE gd_buffer it_pdf INTO gd_buffer. ENDLOOP. TRANSLATE gd_buffer USING '~ '. DO. it_mess_att = gd_buffer. APPEND it_mess_att. SHIFT gd_buffer LEFT BY 255 PLACES. IF gd_buffer IS INITIAL. EXIT. ENDIF. ENDDO. *RECIPIENT DATA : p_email1 TYPE somlreci1-receiver VALUE 'jnarang@spartconsulting.com'. DESCRIBE TABLE it_mess_att LINES gd_recsize. CHECK gd_recsize > 0. *& Subroutine to send the email to the RECIPIENT. PERFORM send_email USING p_email1. ENDIF. ENDIF. ENDFORM. " CALL_FORM

*&---------------------------------------------------------------------* *& Form VALIDATE_AUFNR_INPUTS *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM validate_aufnr_inputs . SELECT SINGLE * FROM aufk WHERE aufnr = s_aufnr. *& Error Message for Order Number IF sy-subrc <> 0. MESSAGE e018 WITH s_aufnr . ENDIF. ENDFORM. " VALIDATE_AUFNR_INPUTS *&---------------------------------------------------------------------* *& Form POPUP *&---------------------------------------------------------------------* FORM popup . DATA : answer TYPE char1. CLEAR answer. CALL FUNCTION 'POPUP_TO_CONFIRM' EXPORTING titlebar = 'CONFIRMATION' text_question = 'Do You Want To Print' text_button_1 = 'YES' icon_button_1 = 'ICON_CHECKED' text_button_2 = 'CANCEL' icon_button_2 = 'ICON_CANCEL' default_button = '1' display_cancel_button = ' ' start_column = 25 start_row =6 IMPORTING answer = answer EXCEPTIONS text_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. IF answer = '2'. LEAVE SCREEN . ENDIF . ENDFORM. " POPUP *&---------------------------------------------------------------------* *& Form F_SEND_PDF_BY_EMAIL *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_TB_PDF255 text * -->P_LTB_BODY text

* -->P_LTB_RECIPIENTS text * -->P_LW_SUBJECT text * -->P_LW_FILENAME text *----------------------------------------------------------------------* FORM f_send_pdf_by_email TABLES p_tb_pdf STRUCTURE tline p_ltb_body STRUCTURE solisti1 p_ltb_recipients STRUCTURE somlreci1 USING p_lw_subject TYPE so_obj_des p_lw_filename TYPE char100. *Variables y tablas internas. DATA: BEGIN OF ltb_objbin OCCURS 0. INCLUDE STRUCTURE solisti1. DATA: END OF ltb_objbin. DATA: lwa_doc_chng LIKE sodocchgi1, lw_tab_lines LIKE sy-tabix, ltb_objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE, ltb_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE. *MAIN PROCESSING SECTION-----------------------------------------CLEAR: ltb_objbin, ltb_objtxt, ltb_objpack, lwa_doc_chng. REFRESH: ltb_objbin, ltb_objtxt, ltb_objpack. *Control Data lwa_doc_chng-obj_name = 'URGENT'. lwa_doc_chng-sensitivty = 'P'. lwa_doc_chng-no_change = 'X'. lwa_doc_chng-priority = '1'. lwa_doc_chng-obj_prio = '1'. lwa_doc_chng-obj_langu = sy-langu. lwa_doc_chng-no_change = 'X'. *Email Subject lwa_doc_chng-obj_descr = p_lw_subject. *Email Body LOOP AT p_ltb_body. ltb_objtxt-line = p_ltb_body-line. APPEND ltb_objtxt. ENDLOOP. CLEAR ltb_objtxt. DESCRIBE TABLE ltb_objtxt LINES lw_tab_lines. IF lw_tab_lines GT 0. READ TABLE ltb_objtxt INDEX lw_tab_lines. lwa_doc_chng-doc_size = ( lw_tab_lines - 1 ) * 255 + STRLEN( ltb_objtxt ). CLEAR ltb_objpack-transf_bin. ltb_objpack-body_start = 1. ltb_objpack-body_num = lw_tab_lines. ltb_objpack-doc_type = 'RAW'. APPEND ltb_objpack. ENDIF. LOOP AT p_tb_pdf.

ltb_objbin-line = p_tb_pdf-tdline. APPEND ltb_objbin. ENDLOOP. ltb_objpack-transf_bin = 'X'. ltb_objpack-body_start = 1. DESCRIBE TABLE ltb_objbin LINES lw_tab_lines. ltb_objpack-body_num = lw_tab_lines. ltb_objpack-doc_type = 'PDF'. ltb_objpack-obj_descr = p_lw_filename. ltb_objpack-obj_name = p_lw_filename. ltb_objpack-doc_size = lw_tab_lines * 255. APPEND ltb_objpack. *Call the function to send the PDF file by email CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING document_data = lwa_doc_chng put_in_outbox = 'X' TABLES packing_list = ltb_objpack contents_bin = ltb_objbin contents_txt = ltb_objtxt receivers = p_ltb_recipients 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. CASE sy-subrc. WHEN 0. WHEN 1. RAISE too_many_receivers. WHEN 2. RAISE document_not_sent . WHEN 3. RAISE document_type_not_exist. WHEN 4. RAISE operation_no_authorization. WHEN 5. RAISE parameter_error. WHEN 7. RAISE enqueue_error . WHEN OTHERS. RAISE x_error. ENDCASE. COMMIT WORK. ENDFORM. " F_SEND_PDF_BY_EMAIL *&---------------------------------------------------------------------* *& Form SEND_EMAIL *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_P_EMAIL1 text *----------------------------------------------------------------------* FORM send_email USING p_email.

CHECK NOT ( p_email IS INITIAL ). REFRESH it_mess_bod. * Default subject matter gd_subject = 'Subject'. gd_attachment_desc = 'Attachnament'. * CONCATENATE 'attach_name' ' ' INTO gd_attachment_name. it_mess_bod = 'Hi There,'. APPEND it_mess_bod. it_mess_bod = 'Please Find the attached Smart Form for Operation Ticket Control'. APPEND it_mess_bod. DATA : p_sender TYPE somlreci1-receiver VALUE 'P3D@nwnatural.com'. * If no sender specified - default blank IF p_sender EQ space. gd_sender_type = space. ELSE. gd_sender_type = 'INT'. ENDIF. * Send file by email as .xls speadsheet PERFORM send_file_as_email_attachment TABLES it_mess_bod it_mess_att USING p_email 'Example .pdf document attached' 'PDF' gd_attachment_name gd_attachment_desc p_sender gd_sender_type CHANGING gd_error gd_reciever. ENDFORM. " SEND_EMAIL *&---------------------------------------------------------------------* *& Form SEND_FILE_AS_EMAIL_ATTACHMENT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_IT_MESS_BOD text * -->P_IT_MESS_ATT text * -->P_P_EMAIL text * -->P_1395 text * -->P_1396 text * -->P_GD_ATTACHMENT_NAME text * -->P_GD_ATTACHMENT_DESC text * -->P_P_SENDER text * -->P_GD_SENDER_TYPE text * <--P_GD_ERROR text * <--P_GD_RECIEVER text *----------------------------------------------------------------------* FORM send_file_as_email_attachment TABLES it_message it_attach

USING p_email p_mtitle p_format p_filename p_attdescription p_sender_address p_sender_addres_type CHANGING perror p_reciever. DATA:ld_error TYPE sy-subrc, ld_reciever TYPE sy-subrc, ld_mtitle LIKE sodocchgi1-obj_descr, ld_email LIKE somlreci1-receiver, ld_format TYPE so_obj_tp , ld_attdescription TYPE so_obj_nam , ld_attfilename TYPE so_obj_des , ld_sender_address LIKE soextreci1-receiver, ld_sender_address_type LIKE soextreci1-adr_typ, ld_receiver LIKE sy-subrc. DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE, t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE, t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE, t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE, t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE, w_cnt TYPE i, w_sent_all(1) TYPE c, w_doc_data LIKE sodocchgi1. ld_email = p_email. ld_mtitle = p_mtitle. ld_format = p_format. ld_attdescription = p_attdescription. ld_attfilename = p_filename. ld_sender_address = p_sender_address. ld_sender_address_type = p_sender_addres_type. * Fill the document data. w_doc_data-doc_size = 1. * Populate the subject/generic message attributes w_doc_data-obj_langu = sy-langu. w_doc_data-obj_name = 'SAPRPT'. w_doc_data-obj_descr = ld_mtitle . w_doc_data-sensitivty = 'F'. * Fill the document data and get size of attachment CLEAR w_doc_data. READ TABLE it_attach INDEX w_cnt. w_doc_data-doc_size = ( w_cnt - 1 ) * 255 + STRLEN( it_attach ). w_doc_data-obj_langu = sy-langu. w_doc_data-obj_name = 'SAPRPT'. w_doc_data-obj_descr = ld_mtitle. w_doc_data-sensitivty = 'F'.

CLEAR t_attachment. REFRESH t_attachment. t_attachment[] = it_attach[]. * Describe the body of the message CLEAR t_packing_list. REFRESH t_packing_list. t_packing_list-transf_bin = space. t_packing_list-head_start = 1. t_packing_list-head_num = 0. t_packing_list-body_start = 1. DESCRIBE TABLE it_message LINES t_packing_list-body_num. t_packing_list-doc_type = 'RAW'. APPEND t_packing_list. * Create attachment notification t_packing_list-transf_bin = 'X'. t_packing_list-head_start = 1. t_packing_list-head_num = 1. t_packing_list-body_start = 1. DESCRIBE TABLE t_attachment LINES t_packing_list-body_num. t_packing_list-doc_type = ld_format. t_packing_list-obj_descr = ld_attdescription. t_packing_list-obj_name = ld_attfilename. t_packing_list-doc_size = t_packing_list-body_num * 255. APPEND t_packing_list. * Add the recipients email address CLEAR t_receivers. REFRESH t_receivers. t_receivers-receiver = ld_email. t_receivers-rec_type = 'U'. t_receivers-com_type = 'INT'. t_receivers-notif_del = 'X'. t_receivers-notif_ndel = 'X'. APPEND t_receivers. CALL FUNCTION 'SO_DOCUMENT_SEND_API1' EXPORTING document_data = w_doc_data put_in_outbox = 'X' sender_address = ld_sender_address sender_address_type = ld_sender_address_type commit_work = 'X' IMPORTING sent_to_all = w_sent_all TABLES packing_list = t_packing_list contents_bin = t_attachment contents_txt = it_message receivers = t_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. * Populate zerror return code ld_error = sy-subrc. * Populate zreceiver return code LOOP AT t_receivers. ld_receiver = t_receivers-retrn_code. ENDLOOP. ENDFORM. " SEND_FILE_AS_EMAIL_ATTACHMENT

Sending HTML Email from SAP CRM/ERP Pavan Bayyapu Business Card Company: SAP Labs LLC Posted on Aug. 30, 2005 04:07 PM in Business Solutions, SAP NetWeaver Platform, Emerging Technologies, Enterprise Data Warehousing/Business Warehouse, ABAP

Subscribe Print Permalink Share

<html> <body> This blog explains how to make use of Netweaver technologies smartforms and SAPConnect to prepare the content and send email. Smartforms Smart Forms provides graphical tool to prepare the content. Thus, a user who is familiar with the tool but has only rudimentary programming knowledge can configure forms with data from an SAP system for the relevant business processes. A function module gets generated when the smartform is activated. The logic of the form is mapped entirely in the Smart Form. To print a form, you call it from within an application program, in which you retrieve the application data to be merged into the form. As data retrieval and form logic are separated, you must only adapt the Smart Form if changes to the form logic are necessary. The application program passes the data via a function module interface to the Smart Form. For more information on smartforms refer to Reference section.

SAPConnect SAPconnect provides a standard interface for external communication, which supports sending with telecommunication services, such as FAX, text message (pager/SMS), Internet mail, and X.400, as well as sending to printers and between different SAP systems. It enables external communication components to be connected to the SAP system. In this article we only deal with email functionality of SAPConnect. Fusing both technologies together Smartform can be configured to send an email or fax or print when the content is retrieved via the generated function module. However the sent email will be in the form of PDF document. Email notification in html format is achieved with the following steps: 1. 2. 3. 4. 5. Create the smartform with relevant content. Activate the smartform to generate the function module. Use the generated function module to retrieve the content in html format. Transform the content (eg: html tags) as needed. Use the SAPConnect to send the email.

Creation of smartform Create or modify a smartform using the transaction smartforms. You can have html content like links for images as shown below.

Activate the form to generate the function module. Code to fetch the smartform content in html format Following code will get the smartform generated function module. Using the generated function module, it fetches the content in HTML format. From address can be SAP user id or an internal email address. Email address maintained SU01 transaction of the SAP user will appear in the from part of the email.

*&--------------------------------------------------------------------* *& Form SEND_SMARTFORM_HTML_EMAIL

*&--------------------------------------------------------------------* * RETREIVES CONTENT FROM SMARTFORM AND SENDS EMAIL TO THE RECEIVERS

*---------------------------------------------------------------------* * * * * -->ET_RETURN -->RECEIVERS -->FORM_NAME ERROR OR INFORMATIONAL MESSAGES EMAIL RECEPIENTS FORM NAME

-->MAIL_SUBJECT EMAIL SUBJECT

*---------------------------------------------------------------------* FORM SEND_SMARTFORM_HTML_EMAIL TABLES ET_RETURN TYPE BAPIRET2_TAB RECEIVERS USING IV_SMARTFORM TYPE TDSFNAME STRUCTURE SOMLRECI1 "receivers

SEND_PARTNER TYPE BU_PARTNER "from address MAIL_SUBJECT TYPE SO_OBJ_DES.

DATA: CONTROL_PARAMETERS TYPE SSFCTRLOP, OUTPUT_OPTIONS TYPE SSFCOMPOP, DOCUMENT_OUTPUT_INFO TYPE SSFCRESPD, JOB_OUTPUT_INFO TYPE SSFCRESCL, JOB_OUTPUT_OPTIONS TYPE SSFCRESOP, XSFPARAM_LINE P_HTML P_GRAPHICS TYPE SSFXSFP, TYPE TRFRESULT, TYPE TSF_XSF_GR, " generated function module name

FORM_NAME TYPE RS38L_FNAM. DATA: WA_RETURN TYPE BAPIRET2.

CONSTANTS: C_GR_DIR TYPE TDTEXT VALUE 'MYGRAPHICS/'. *SET SMARTFORM OUTPUT OPTIONS OUTPUT_OPTIONS-XSFCMODE = 'X'. OUTPUT_OPTIONS-XSF = 'X'. OUTPUT_OPTIONS-XSFOUTMODE = 'A'. OUTPUT_OPTIONS-XSFFORMAT = 'X'. CLEAR OUTPUT_OPTIONS-XSFOUTDEV. XSFPARAM_LINE-NAME = 'GRAPHICS'.

"#EC NOTEXT

"#EC NOTEXT "#EC NOTEXT "#EC NOTEXT "#EC NOTEXT

"#EC NOTEXT "#EC NOTEXT

XSFPARAM_LINE-VALUE = 'EXTRACT'.

APPEND XSFPARAM_LINE TO OUTPUT_OPTIONS-XSFPARS. XSFPARAM_LINE-NAME = 'GRAPHICS-DIRECTORY'. "#EC NOTEXT

XSFPARAM_LINE-VALUE = C_GR_DIR. APPEND XSFPARAM_LINE TO OUTPUT_OPTIONS-XSFPARS. XSFPARAM_LINE-NAME = 'CONTENT-ID'. "#EC NOTEXT "#EC NOTEXT

XSFPARAM_LINE-VALUE = 'ENABLE'. APPEND XSFPARAM_LINE TO OUTPUT_OPTIONS-XSFPARS. * SILENT MODE ON OUTPUT_OPTIONS-TDIMMED = SPACE. OUTPUT_OPTIONS-TDNEWID = SPACE. CONTROL_PARAMETERS-NO_DIALOG = 'X'. * Get the generated function name of the smartform CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING FORMNAME IMPORTING FM_NAME EXCEPTIONS NO_FORM = 1 = FORM_NAME = IV_SMARTFORM "#EC NOTEXT

"#EC NOTEXT

NO_FUNCTION_MODULE = 2 OTHERS IF SY-SUBRC <> 0. * Error receiving the generated function module CLEAR WA_RETURN. MESSAGE E005 WITH IV_SMARTFORM INTO WA_RETURN-MESSAGE. WA_RETURN-TYPE = 'E'. "#EC NOTEXT INSERT WA_RETURN INTO TABLE ET_RETURN. EXIT. ENDIF. * Get the smartform content = 3.

CALL FUNCTION FORM_NAME EXPORTING CONTROL_PARAMETERS OUTPUT_OPTIONS = CONTROL_PARAMETERS = OUTPUT_OPTIONS

*pass other application specific parameters (eg order number, items ). IMPORTING DOCUMENT_OUTPUT_INFO = DOCUMENT_OUTPUT_INFO JOB_OUTPUT_INFO JOB_OUTPUT_OPTIONS EXCEPTIONS FORMATTING_ERROR =1 INTERNAL_ERROR =2 SEND_ERROR =3 USER_CANCELED IF SY-SUBRC <> 0. * FAILED TO GET CONTENT FROM SMARTFORM CLEAR WA_RETURN. MESSAGE E012 WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE ET_RETURN. EXIT. ENDIF. P_HTML = JOB_OUTPUT_INFO-XMLOUTPUT-TRFRESULT. WITH FORM_NAME SY-SUBRC INTO = 4. = JOB_OUTPUT_INFO = JOB_OUTPUT_OPTIONS

P_GRAPHICS[] = JOB_OUTPUT_INFO-XMLOUTPUT-XSFGR[]. * send the extracted content all the recipients PERFORM SEND_HTML_EMAIL TABLES

ET_RETURN RECEIVERS USING P_HTML P_GRAPHICS[] SEND_PARTNER MAIL_SUBJECT. ENDFORM. "SEND_SMARTFORM_HTML_EMAIL

Code to send the email Following code will transform the html content into displayable format and send email to all the recipients. Note: This form also handles the images (static) defined in the smartform, as well as the images defined with html IMG tag (eg: URL link to image on the network).

*&--------------------------------------------------------------------* *& Form SEND_HTML_EMAIL

*&--------------------------------------------------------------------* * Send the email provided the content and other details

*---------------------------------------------------------------------* * * * * * -->P_RETURN Error messages

-->P_RECEIVERS emailr recipients -->P_HTML html text

-->P_GRAPHICS html graphics if any -->P_SUBJECT subject of the email

*---------------------------------------------------------------------* FORM SEND_HTML_EMAIL TABLES P_RETURN TYPE BAPIRET2_TAB P_RECEIVERS STRUCTURE SOMLRECI1

USING P_HTML P_GRAPHICS

TYPE TRFRESULT TYPE TSF_XSF_GR

SEND_PARTNER TYPE BU_PARTNER P_SUBJECT DATA: L_GRAPHIC TYPE SSF_XSF_GR. CONSTANTS: C_GR_DIR TYPE TDTEXT VALUE 'MYGRAPHICS/'. DATA: HTML_DATA TYPE TRFRESULT, GRAPHICS TYPE TSF_XSF_GR, "#EC NOTEXT TYPE SO_OBJ_DES.

LV_SENT_TO_ALL TYPE BOOLEAN, LV_SEND_ADDRESS LI_SENDER TYPE ADR6-SMTP_ADDR, TYPE REF TO IF_SENDER_BCS,

RECEIVER TYPE SOMLRECI1. DATA: LO_BCS LO_DOC_BCS LO_MIME_HELPER LO_RECIPIENT DATA: L_FILENAME LT_SOLI LT_SOLIX LS_SOLI LS_SOLIX DATA: L_HTML_RAW HTML_XSTR HTML_STR HTML_LEN L_OFFSET L_LENGTH L_DIFF L_CONTENT_ID TYPE REF TO CL_BCS, TYPE REF TO CL_DOCUMENT_BCS, TYPE REF TO CL_GBT_MULTIRELATED_SERVICE, TYPE REF TO IF_RECIPIENT_BCS. TYPE STRING, TYPE SOLI_TAB, TYPE SOLIX_TAB, TYPE SOLI, TYPE SOLIX. LIKE LINE OF HTML_DATA-CONTENT, TYPE XSTRING, TYPE STRING, TYPE I, TYPE I, TYPE I, TYPE I, TYPE STRING,

L_CONTENT_TYPE TYPE W3CONTTYPE,

L_OBJ_LEN GR_XSTR L_GR_RAW L_USERNAME

TYPE SO_OBJ_LEN, TYPE XSTRING, TYPE BAPICONTEN, TYPE UNAME,

L_MAIL_ADDRESS TYPE AD_SMTPADR, WA_RETURN TYPE BAPIRET2. DATA: LV_SEND_REQ_BCS LV_ADDRESS_BCS LV_GBT_MIME LV_BCOM_MIME LV_DOCUMENT_BCS TYPE REF TO CX_SEND_REQ_BCS, TYPE REF TO CX_ADDRESS_BCS, TYPE REF TO CX_GBT_MIME, TYPE REF TO CX_BCOM_MIME, TYPE REF TO CX_DOCUMENT_BCS.

CLEAR HTML_XSTR. LOOP AT P_HTML-CONTENT INTO L_HTML_RAW. CONCATENATE HTML_XSTR L_HTML_RAW INTO HTML_XSTR IN BYTE MODE. ENDLOOP. HTML_XSTR = HTML_XSTR(P_HTML-LENGTH). CALL FUNCTION 'SCP_TRANSLATE_CHARS' EXPORTING INBUFF INCODE * OUTCODE CSUBST = HTML_XSTR = '4110' = '0000' = 'X' " UTF-8 "#EC NOTEXT " ACTUAL CODEPAGE "#EC NOTEXT "#EC NOTEXT "#EC NOTEXT

SUBSTC_SPACE = 'X' IMPORTING OUTBUFF OUTUSED EXCEPTIONS OTHERS = HTML_STR = HTML_LEN = 1.

* CHANGE ENCODING UTF-8 TO LATIN1 REPLACE ALL OCCURRENCES OF 'UTF-8' IN HTML_STR WITH 'iso-8859-1' IGNORING CASE. *HACK THE HTML CODE GENERATED BY SARTFORM TO MAKE THE "#EC NOTEXT

*EXTERNAL IMAGES APPEAR AS <IMG> TAG IN HTML REPLACE ALL OCCURRENCES OF '<IMG' IN HTML_STR WITH '<IMG' IGNORING CASE. "#EC NOTEXT

REPLACE ALL OCCURRENCES OF '/>' IN HTML_STR WITH '/>' IGNORING CASE. REPLACE ALL OCCURRENCES OF '</A>' IN HTML_STR WITH '' IGNORING CASE. "#EC NOTEXT "#EC NOTEXT

REPLACE ALL OCCURRENCES OF '<' IN HTML_STR WITH '<' IGNORING CASE. "#EC NOTEXT

REPLACE ALL OCCURRENCES OF '>' IN HTML_STR WITH '>' IGNORING CASE. "#EC NOTEXT

HTML_LEN = STRLEN( HTML_STR ). L_OFFSET = 0. L_LENGTH = 255. WHILE L_OFFSET < HTML_LEN. L_DIFF = HTML_LEN - L_OFFSET. IF L_DIFF > L_LENGTH. LS_SOLI-LINE = HTML_STR+L_OFFSET(L_LENGTH). ELSE. LS_SOLI-LINE = HTML_STR+L_OFFSET(L_DIFF). ENDIF. APPEND LS_SOLI TO LT_SOLI. ADD L_LENGTH TO L_OFFSET. ENDWHILE. CREATE OBJECT LO_MIME_HELPER. CALL METHOD LO_MIME_HELPER->SET_MAIN_HTML EXPORTING CONTENT = LT_SOLI

FILENAME

= 'SAPWEBFORM.HTM'

"#EC NOTEXT "#EC NOTEXT

DESCRIPTION = 'SAP WEB FORM'. LOOP AT P_GRAPHICS INTO L_GRAPHIC. CLEAR GR_XSTR. LOOP AT L_GRAPHIC-CONTENT INTO L_GR_RAW.

CONCATENATE GR_XSTR L_GR_RAW-LINE INTO GR_XSTR IN BYTE MODE. ENDLOOP. GR_XSTR = GR_XSTR(L_GRAPHIC-LENGTH). L_OFFSET = 0. L_LENGTH = 255. CLEAR LT_SOLIX[]. WHILE L_OFFSET < L_GRAPHIC-LENGTH. L_DIFF = L_GRAPHIC-LENGTH - L_OFFSET. IF L_DIFF > L_LENGTH. LS_SOLIX-LINE = GR_XSTR+L_OFFSET(L_LENGTH). ELSE. LS_SOLIX-LINE = GR_XSTR+L_OFFSET(L_DIFF). ENDIF. APPEND LS_SOLIX TO LT_SOLIX. ADD L_LENGTH TO L_OFFSET. ENDWHILE. CONCATENATE C_GR_DIR L_GRAPHIC-GRAPHICS '.BMP' INTO L_FILENAME. CONCATENATE C_GR_DIR L_GRAPHIC-GRAPHICS '.BMP' INTO L_CONTENT_ID. L_CONTENT_TYPE = L_GRAPHIC-HTTPTYPE. L_OBJ_LEN = L_GRAPHIC-LENGTH. "#EC NOTEXT "#EC NOTEXT

*Add images to the email CALL METHOD LO_MIME_HELPER->ADD_BINARY_PART EXPORTING

CONTENT FILENAME EXTENSION DESCRIPTION

= LT_SOLIX = L_FILENAME = 'BMP' = 'GRAPHIC IN BMP FORMAT' "#EC NOTEXT "#EC NOTEXT

CONTENT_TYPE = L_CONTENT_TYPE LENGTH CONTENT_ID ENDLOOP. TRY. LO_DOC_BCS = CL_DOCUMENT_BCS=>CREATE_FROM_MULTIRELATED( I_SUBJECT = P_SUBJECT = L_OBJ_LEN = L_CONTENT_ID.

I_MULTIREL_SERVICE = LO_MIME_HELPER ). CATCH CX_DOCUMENT_BCS INTO LV_DOCUMENT_BCS. * ERROR HANDLING CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT

MOVE LV_DOCUMENT_BCS->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE P_RETURN. EXIT. CATCH CX_BCOM_MIME INTO LV_BCOM_MIME. CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT

MOVE LV_BCOM_MIME->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE P_RETURN. EXIT. CATCH CX_GBT_MIME INTO LV_GBT_MIME. CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT

MOVE LV_GBT_MIME->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE P_RETURN.

EXIT. ENDTRY. * REUSE THE CONTENT PREPARED FOR ALL RECEIVERS LOOP AT P_RECEIVERS INTO RECEIVER.

L_MAIL_ADDRESS = RECEIVER-RECEIVER. * CREATE SEND_REQUEST TRY. LO_BCS = CL_BCS=>CREATE_PERSISTENT( ). LO_BCS->SET_DOCUMENT( I_DOCUMENT = LO_DOC_BCS ). CATCH CX_SEND_REQ_BCS INTO LV_SEND_REQ_BCS. CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT

MOVE LV_SEND_REQ_BCS->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE P_RETURN. EXIT. ENDTRY. * CREATE SENDER CLASS CL_CAM_ADDRESS_BCS DEFINITION LOAD. TRY. IF L_USERNAME NS '@'. L_USERNAME = SEND_PARTNER . TRANSLATE L_USERNAME TO UPPER CASE. "#EC TRANSLANG "#EC NOTEXT

LI_SENDER ?= CL_SAPUSER_BCS=>CREATE( L_USERNAME ). ELSE. DATA: L_FROM_MAIL_ADDRESS TYPE AD_SMTPADR. L_FROM_MAIL_ADDRESS = L_USERNAME. LI_SENDER ?= CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( I_ADDRESS_STRING = L_FROM_MAIL_ADDRESS ).

ENDIF. CALL METHOD LO_BCS->SET_SENDER EXPORTING I_SENDER = LI_SENDER. CATCH CX_ADDRESS_BCS INTO LV_ADDRESS_BCS. * ERROR HANDLING CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT

MOVE LV_ADDRESS_BCS->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE P_RETURN. EXIT. CATCH CX_SEND_REQ_BCS INTO LV_SEND_REQ_BCS. * FAILED TO ADD A SENDER CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT

MOVE LV_SEND_REQ_BCS->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE P_RETURN. EXIT. EXIT. ENDTRY. * CREATE RECIPIENT

TRY. LO_RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( I_ADDRESS_STRING = L_MAIL_ADDRESS ). CATCH CX_ADDRESS_BCS INTO LV_ADDRESS_BCS. * ERROR HANDLING CONTINUE. ENDTRY. TRY.

LO_BCS->ADD_RECIPIENT( I_RECIPIENT = LO_RECIPIENT ). CATCH CX_SEND_REQ_BCS INTO LV_SEND_REQ_BCS. * FAILED TO ADD A RECIPIENT CONTINUE. ENDTRY. * SEND TRY. * RECEIPTS ONLY FOR ERRORS CALL METHOD LO_BCS->SEND_REQUEST->SET_REQUESTED_STATUS EXPORTING I_REQUESTED_STATUS = 'N'. LV_SENT_TO_ALL = LO_BCS->SEND( ). CATCH CX_SEND_REQ_BCS INTO LV_SEND_REQ_BCS. CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT "#EC NOTEXT

MOVE LV_SEND_REQ_BCS->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE P_RETURN. * ERROR HANDLING EXIT. ENDTRY. ENDLOOP. COMMIT WORK. * set the success information CLEAR WA_RETURN. MESSAGE i013 INTO WA_RETURN-MESSAGE. "Email sent successfully " END LOOP AT P_RECEIVERS

INSERT WA_RETURN INTO TABLE P_RETURN. ENDFORM. "SEND_HTML_EMAIL

Adjust the look and feel of the email content Make proper use of the smartstyles (transaction smartstyles) in the smartform to improve the look and feel of the email. Here is how a sample email looks. You can also use static images in the smartform. These images will come as multipart format. You can also make use of URL links in the smartforms to provide the link from email to the webapplication like webshop

Das könnte Ihnen auch gefallen