Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
5352119c
Advisor
Advisor
0 Kudos
2,600

Background


In eDocument Cockpit, there are many standard actions and corresponding process status, basically, you can enhance them with some enhancement points that delivered by sap to Implement some of the requirements you want.

The purpose of this blog is to give you some insights about extensibility, maybe you can extend actions via function module for eDocument process, in a way, that is full of possibilities.

Solution









IMG Menu IMG >Cross-Application Components >General Application Functions   >eDocument >General Settings >Extend Actions for eDocument Processes via Function Module

Configuration View (SM30:EDOACTPROCBFCUSV)

In this customizing activity, you can extend an action for a given process status by configuring a function module. The function module is executed immediately after the action in a separate session, using TRFC (Transactional Remote Function Call). You can monitor the execution results in the BGRFC Monitor (SBGRFCMON) transaction.

Before you start customizing your system, define the inbound destination in the BGRFC Configuration (SBGRFCCONF) transaction.


define BGRFC


If you are unfamiliar with the BGRFC, please refer to https://support.sap.com/en/alm/sap-focused-run/expert-portal/integration-cloud-monitoring/bgrfc.html



A real case


This business is for Thailand eTax, if the eDocument submit failed, will send an error notification to processer via E-mail.

How-to


step1: Obviously, you need to config the eDoc Process as 'THETAX' eDoc Action as 'SUBMIT' and Process Status as 'ERR_RD', for the function module, use the same import parameters as in the sample function module EDOC_ACTION_BF_SAMPLE, the the inbound destination is mandatory


configuration for Thailand eTax


step2: Adding code in the function Module ZEDOC_ACT_ERROR_NOTIFICATION to achieve the function, below is an example implementation
FUNCTION zedoc_act_error_notification.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(IV_EDOC_GUID) TYPE EDOC_GUID
*" VALUE(IS_PROCESS_ATTR) TYPE EDOC_ATTR_MANAGED_BY_PROCMGR
*" EXCEPTIONS
*" AUTHORIZATION_ERROR
*" UNKNOWN_ERROR
*"----------------------------------------------------------------------
DATA:lt_main_text TYPE soli_tab.
DATA:ls_main_text LIKE LINE OF lt_main_text.
DATA lv_ext_number TYPE balhdr-extnumber .
DATA lt_messages TYPE STANDARD TABLE OF balm .
DATA: lv_msg TYPE string,
lo_edo_db TYPE REF TO if_edocument_db,
ls_edoc TYPE edocument.

DATA:lv_subject TYPE so_obj_des.
DATA:lv_subject_long TYPE string.

DATA:lv_sender TYPE adr6-smtp_addr.
DATA lt_recipients_to TYPE bcsy_smtpa .
DATA ls_recipients_to TYPE ad_smtpadr .

CHECK iv_edoc_guid IS NOT INITIAL .

CREATE OBJECT lo_edo_db TYPE cl_edocument_db.
ls_edoc = lo_edo_db->select_edocument( iv_edoc_guid = iv_edoc_guid ).

CLEAR lv_ext_number.
lv_ext_number = iv_edoc_guid .
"get error messages
CALL FUNCTION 'APPL_LOG_READ_DB'
EXPORTING
object = 'EDOCUMENT'
subobject = '*'
external_number = lv_ext_number
TABLES
messages = lt_messages.

SORT lt_messages BY mandant time_stmp DESCENDING .
DELETE ADJACENT DUPLICATES FROM lt_messages COMPARING mandant.
CLEAR lv_msg .
LOOP AT lt_messages INTO DATA(ls_message).
lv_msg = lv_msg && ls_message-msgv1 && ls_message-msgv2 && ls_message-msgv3 && ls_message-msgv4 .
CLEAR ls_message .
ENDLOOP.
"set main text
CLEAR ls_main_text.
ls_main_text-line = 'Document Source key: ' && ls_edoc-source_key.
APPEND ls_main_text TO lt_main_text.
CLEAR ls_main_text.

ls_main_text-line = 'Error messages:' .
APPEND ls_main_text TO lt_main_text.
CLEAR ls_main_text.

ls_main_text-line = lv_msg.
APPEND ls_main_text TO lt_main_text.

"send Email

lv_subject = 'Error notification test'.
lv_sender = 'your email address'.

ls_recipients_to = 'your email address'.
APPEND lS_recipients_to TO lt_recipients_to .
TRY.
CALL METHOD cl_edoc_util=>send_email
EXPORTING
iv_email_type = 'RAW'
iv_subject = lv_subject
it_content_text = lt_main_text
* it_content_hex =
* iv_content_length =
* iv_language = SY-LANGU
* iv_vsi_profile =
iv_sender = lv_sender
it_recipients_to = lt_recipients_to
* it_recipients_cc =
* iv_sensitivity =
* iv_importance =
* it_email_header =
* it_attachments =
iv_send_immediately = 'X'.
CATCH cx_edocument.

ENDTRY.


ENDFUNCTION.

step3: Test in the system, the notification was sent to the E-mail successfully.


Example Notification


 

Just as above implementation, you can choose an eDocument process and a process status to implement your specific demands. You can trigger additional actions within the framework or outside the framework.
Labels in this area