NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

"Constant Declaration
CONSTANTS: c_a TYPE char1 VALUE 'A',
c_r TYPE char1 VALUE 'R',
c_s TYPE char1 VALUE 'S',
c_approved TYPE char20 VALUE 'APPROVED',
c_rejected TYPE char20 VALUE 'REJECTED',
c_write TYPE c VALUE 'W',
c_kind TYPE rsparams-kind VALUE 'P',
c_sign TYPE rsparams-sign VALUE 'I',
c_option TYPE rsparams-low VALUE 'EQ',
c_t5 TYPE rantyp VALUE '5',
c_me TYPE char1 VALUE 'E',
c_ms TYPE char1 VALUE 'S',
c_01(2) VALUE '01',
c_02(2) VALUE '02',
c_col(1) VALUE ';'.

"declared variables & constant {
DATA: gv_ecode TYPE RANGE OF zsgtsfdt_ecode,
gv_selmat1 TYPE rsparams-selname,
gv_selmat2 TYPE rsparams-selname,
gv_selmat3 TYPE rsparams-selname,
gv_ecmprg TYPE sy-repid,
gv_slset TYPE sy-slset.
CONSTANTS : c_ecode TYPE rvari_vnam VALUE 'ZSGSLC_LC_ECODE',
c_selnam_bukrs TYPE rvari_vnam VALUE 'ZSGSLC_SELNAME_BUKRS',
c_selnam_rfha TYPE rvari_vnam VALUE 'ZSGSLC_SELNAME_RFHA',
c_selnam_date TYPE rvari_vnam VALUE 'ZSGSLC_SELNAME_DATE',
c_ecmprg TYPE rvari_vnam VALUE 'ZSGSLC_ECMPRG',
c_ecmprg_variant TYPE rvari_vnam VALUE 'ZSGSLC_ECMPRG_VARIANT'.


* Declare for Inbound E-Mail processing
DATA: lo_document TYPE REF TO if_document_bcs,
l_mail_attr TYPE bcss_dbpa,
l_mail_content TYPE bcss_dbpc,
lo_reply TYPE REF TO cl_send_request_bcs,
sender TYPE REF TO if_sender_bcs,
sender_addr TYPE string,
lv_email TYPE comm_id_long,
lv_semail TYPE comm_id_long,
send_request TYPE REF TO cl_bcs,
ltext TYPE bcsy_text,
body_text TYPE so_text255,
document TYPE REF TO cl_document_bcs,
ex_sender TYPE REF TO cl_sapuser_bcs,
recipient TYPE REF TO if_recipient_bcs,
bcs_exception TYPE REF TO cx_bcs,
sent_to_all TYPE os_boolean,
lv_action TYPE char01,
lv_wid TYPE char50,
lv_action_text TYPE char12,
lv_subject1 TYPE so_obj_des,
lv_ecode TYPE char4,
lv_flow TYPE sbewart.
DATA: lt_vari TYPE STANDARD TABLE OF rsparams,
ls_vari TYPE rsparams,
ls_varid TYPE varid.

"Bapi declaration.
DATA: lv_companycode TYPE bapi2042-company_code,
lv_financialtransaction TYPE bapi2042-transaction,
lv_flowkey TYPE bapi_ftr_mainflow_detail-flow_key,
lt_error TYPE TABLE OF bapiret2.

DATA: rt_bukrs TYPE RANGE OF bukrs,
rt_rfha TYPE RANGE OF tb_rfha.

DATA: lv_ex_stat TYPE c,
lv_ex_msg TYPE bapi_msg,
lv_ex_doc TYPE belnr_d,
lt_ex_post TYPE zsgslctr_icl_pst.

* Internal table
TYPES: BEGIN OF ty_mail_id,
send TYPE adr6-smtp_addr,
END OF ty_mail_id.

DATA: lt_nid TYPE TABLE OF ty_mail_id.


"Get email code for LC payment from the PARAM
SELECT sign,
opti AS option,
low
FROM tvarvc
INTO TABLE @gv_ecode
WHERE name = @c_ecode. "}

"Get selname from the PARAM {
SELECT SINGLE low
FROM tvarvc
INTO @gv_selmat1
WHERE name = @c_selnam_bukrs.

SELECT SINGLE low
FROM tvarvc
INTO @gv_selmat2
WHERE name = @c_selnam_rfha.

SELECT SINGLE low
FROM tvarvc
INTO @gv_selmat3
WHERE name = @c_selnam_date.

SELECT SINGLE low
FROM tvarvc
INTO @gv_ecmprg
WHERE name = @c_ecmprg.

SELECT SINGLE low
FROM tvarvc
INTO @gv_slset
WHERE name = @c_ecmprg_variant.


* Now read the subject and process the work item
* Read the action
lv_action = iv_subject+0(1).
lv_ecode = iv_subject+1(4).
lv_subject1 = iv_subject.
* Read the work item ID
lv_wid = iv_subject+1(15).

* First check the status of the ECM Invoice is reject or approved
SELECT a~zbukrs,
a~zrfha,
a~zsfhazba,
a~zpdate,
a~zflow_key,
a~zemail,
a~zapp_rej,
a~zemail_time,
a~zemail_refid,
a~zeml_init,
b~sgsart,
c~dis_flowtype,
d~zslc_deal_id
FROM zsgslctr_emlpr AS a
INNER JOIN vtbfha AS b
ON b~bukrs = a~zbukrs AND b~rfha = a~zrfha
INNER JOIN zsgslctr_slc_ftr AS d
ON d~zbukrs = b~bukrs AND d~zrfha = b~rfha
* INNER JOIN atfta AS c "#EC CI_BUFFJOIN
LEFT OUTER JOIN atfta AS c
ON c~sfhazba = a~zsfhazba AND c~ssign = a~ssign AND c~rantyp = @c_t5
WHERE zemail_refid = @lv_wid
INTO TABLE @DATA(lt_ecm).

* If data not found, indicates an invalid e-mail sent to offline ID
IF sy-subrc NE 0.
lv_wid = TEXT-002.
ENDIF.

DATA(ls_ecm) = lt_ecm[ 1 ].

"Initiator ID
lv_email = ls_ecm-zeml_init.

* Email ID selection
SELECT SINGLE zcat,
zecode,
znid
FROM zsgtsftr_emlbd
INTO @DATA(ls_emlbd)
WHERE zcat EQ @c_01 "'01'
AND zecode EQ @lv_ecode.

* Preparing TO-CC List
CLEAR lt_nid .
SPLIT ls_emlbd-znid AT c_col INTO TABLE lt_nid .


* Approver Name.
DATA lv_seml TYPE ad_smtpadr.
lv_seml = iv_sender_addr.
TRANSLATE lv_seml TO LOWER CASE.
SELECT SINGLE a~bname "a~name_text
FROM v_usr_name AS a
INNER JOIN usr21 AS b
ON b~bname = a~bname
INNER JOIN adr6 AS c
ON c~addrnumber = b~addrnumber AND c~persnumber = b~persnumber
WHERE c~smtp_addr = @lv_seml
INTO @DATA(lv_suname).
CLEAR lv_seml.

* Check the status, if COMPLETED, send the notification
IF ls_ecm-zapp_rej = c_a.
TRY.
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document -------------------------------
* Build the e-mail Body
CLEAR: body_text.
CONCATENATE 'Email Reference ID : '
lv_wid
'is in status "APPROVED"' INTO body_text SEPARATED BY space.
APPEND body_text TO ltext.
CLEAR: body_text.
CONCATENATE 'This has already been processed '
'and cannot be processed again.' INTO body_text SEPARATED BY space.
APPEND body_text TO ltext.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = ltext
i_length = '510'
i_subject = lv_subject1 ).
* Add document to send request
CALL METHOD send_request->set_document( document ).
* --------- set sender -------------------------------------------
* note: this is necessary only if you want to set the sender
* different from actual user (SY-UNAME). Otherwise sender is
* set automatically with actual user.
sender = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
* --------- Add recipient (e-mail address) -----------------------
* Create recipient - passing the receipient e-mail ID
recipient = cl_cam_address_bcs=>create_internet_address( lv_email ).
* Add recipient with its respective attributes to send request
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
* ---------- Send document ---------------------------------------
send_request->set_send_immediately( 'X' ).
CALL METHOD send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).
COMMIT WORK.
CATCH cx_bcs INTO bcs_exception.
ENDTRY.
ELSEIF ls_ecm-zapp_rej = c_s.
* First process the Work Item Based on the action
IF lv_action = c_a.
* Set the ACTION Text
lv_action_text = c_approved.
* If APPROVED

"Updating flow table with approved status
UPDATE zsgslctr_emlpr SET zemail = abap_true
zapp_rej = c_a
* zemail_time = sy-uzeit
zar_id = iv_sender_addr
zar_date = sy-datum
zar_time = sy-uzeit
zchanged_by = sy-uname
zchanged_date = sy-datum
zchanged_time = sy-uzeit
WHERE zemail_refid = lv_wid.
COMMIT WORK AND WAIT.


"Dynamically Variant Change -
CLEAR ls_vari.
ls_vari-selname = gv_selmat1. "c_selmat1. "Company code
ls_vari-kind = c_kind.
ls_vari-option = c_option.
ls_vari-sign = c_sign.
ls_vari-low = ls_ecm-zbukrs.
APPEND ls_vari TO lt_vari.

CLEAR ls_vari.
ls_vari-selname = gv_selmat2. "c_selmat2. "Transaction code
ls_vari-kind = c_kind.
ls_vari-option = c_option.
ls_vari-sign = c_sign.
ls_vari-low = ls_ecm-zrfha.
APPEND ls_vari TO lt_vari.

CLEAR ls_vari.
ls_vari-selname = gv_selmat3. "c_selmat3. "Key Date
ls_vari-kind = c_kind.
ls_vari-option = c_option.
ls_vari-sign = c_sign.
ls_vari-low = ls_ecm-zpdate.
APPEND ls_vari TO lt_vari.

"Re-populating the variant description.
ls_varid-mandt = sy-mandt.
ls_varid-aename = sy-uname.
ls_varid-aedat = sy-datum.
ls_varid-aetime = sy-uzeit.

"Creating a new variant with the new values.
CALL FUNCTION 'RS_CHANGE_CREATED_VARIANT'
EXPORTING
curr_report = gv_ecmprg "c_ecmprg "Program Name
curr_variant = gv_slset "c_slset "Variant Name
vari_desc = ls_varid "Variant Description
TABLES
vari_contents = lt_vari "Variant Contents
EXCEPTIONS
illegal_report_or_variant = 1
illegal_variantname = 2
not_authorized = 3
not_executed = 4
report_not_existent = 5
report_not_supplied = 6
variant_doesnt_exist = 7
variant_locked = 8
selections_no_match = 9
OTHERS = 10.

IF sy-subrc EQ 0.
COMMIT WORK AND WAIT.
* Variant has been populated with new data successfully.
ENDIF.

"Raising Event for TBB1 Posting
CALL FUNCTION 'BP_EVENT_RAISE'
EXPORTING
eventid = 'SAP_FS_TRM'
* EVENTPARM = ' '
* TARGET_INSTANCE = ' '
* TARGET_MODE = ' '
* EXCEPTIONS
* BAD_EVENTID = 1
* EVENTID_DOES_NOT_EXIST = 2
* EVENTID_MISSING = 3
* RAISE_FAILED = 4
* OTHERS = 5
.
IF sy-subrc = 0.
* WRITE:/ 'Event Triggered'.
* Implement suitable error handling here
ENDIF.
ENDIF.

IF lv_action = c_r.
* Set the ACTION Text
lv_action_text = c_rejected.
* If REJECTED

"Updating flow table with approved status
UPDATE zsgslctr_emlpr SET zemail = space
zapp_rej = space "'R'
* zemail_time = sy-uzeit
zar_id = iv_sender_addr
zar_date = sy-datum
zar_time = sy-uzeit
zchanged_by = sy-uname
zchanged_date = sy-datum
zchanged_time = sy-uzeit
WHERE zemail_refid = lv_wid.
COMMIT WORK AND WAIT. .


IF lv_wid+0(4) IN gv_ecode.
lv_flow = ls_ecm-zsfhazba.
ENDIF.

IF lv_flow IS NOT INITIAL.
"Paymenet Details deletion
me->zsgslcif_email~dlt_pymnt(
EXPORTING iv_bukrs = ls_ecm-zbukrs
iv_rfha = ls_ecm-zrfha
iv_date = ls_ecm-zpdate
iv_flowtype = lv_flow ).
ENDIF.

ENDIF.
* After the action now send the e-mail
TRY.
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document -------------------------------
* Build the e-mail Body
CLEAR: body_text.
CONCATENATE 'Invoice Reference ID : '
lv_wid
'has been'
lv_action_text INTO body_text SEPARATED BY space.
APPEND body_text TO ltext.
CLEAR: body_text.

"Error Message
IF lv_ex_stat = c_me.
APPEND space TO ltext.
CLEAR: body_text.
CONCATENATE TEXT-e03 lv_ex_msg INTO body_text SEPARATED BY space .
APPEND body_text TO ltext.
APPEND space TO ltext.
ENDIF.

APPEND space TO ltext.
APPEND LINES OF it_body TO ltext.
APPEND space TO ltext.
APPEND space TO ltext.


document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = ltext
i_length = '510'
i_subject = lv_subject1 ).
* Add document to send request
CALL METHOD send_request->set_document( document ).
* --------- set sender -------------------------------------------
* note: this is necessary only if you want to set the sender
* different from actual user (SY-UNAME). Otherwise sender is
* set automatically with actual user.

IF NOT lv_suname IS INITIAL.
* sender = cl_cam_address_bcs=>create_internet_address(
* i_address_string = lv_seml ).
sender = cl_sapuser_bcs=>create( lv_suname ).
ELSE.
sender = cl_sapuser_bcs=>create( sy-uname ).
ENDIF.

CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
* --------- Add recipient (e-mail address) -----------------------
IF lv_action = c_a.
* Set Email Receiver(s) (CC)
LOOP AT lt_nid ASSIGNING FIELD-SYMBOL(<fs_nid>).
TRY. recipient = cl_cam_address_bcs=>create_internet_address( <fs_nid>-send ). CATCH cx_address_bcs. ENDTRY.
TRY. send_request->add_recipient( EXPORTING i_recipient = recipient i_express = 'X' i_copy = 'X' ). CATCH cx_send_req_bcs . ENDTRY.
ENDLOOP.
ENDIF.
* Create recipient - for Sender ID
IF lv_ex_stat = c_me.
lv_semail = iv_sender_addr.
TRY. recipient = cl_cam_address_bcs=>create_internet_address( lv_semail ). CATCH cx_address_bcs. ENDTRY.
TRY. send_request->add_recipient( EXPORTING i_recipient = recipient i_express = 'X' ). CATCH cx_send_req_bcs . ENDTRY.
ENDIF.
* Create recipient - passing the receipient e-mail ID
recipient = cl_cam_address_bcs=>create_internet_address( lv_email ).
* Add recipient with its respective attributes to send request
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
* ---------- Send document ---------------------------------------
send_request->set_send_immediately( 'X' ).
CALL METHOD send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).
COMMIT WORK.
CATCH cx_bcs INTO bcs_exception.
ENDTRY.
ELSE.
* This means the work item is in ERROR or some exception status, NOTIFY!!!!!
* Here you can reply back to the user if they send invalid e-mails to ECCOFFLINE other then clicking on the Processing Links
TRY.
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document -------------------------------
* Build the e-mail Body based on the Work Item ID
IF lv_wid = TEXT-002.
* Build E-Mail for Invalid WID
CLEAR: body_text.
CONCATENATE 'This system e-mail is meant only for OFFLINE WORKFLOW Processing.'
'Please do not send any e-mails to this ID other then via Workflow Processing Offline Links.' INTO body_text SEPARATED BY space.
APPEND body_text TO ltext.
CLEAR: body_text.
CONCATENATE 'This is a system generated auto e-mail '
'Please do not reply to this ID.' INTO body_text SEPARATED BY space.
APPEND body_text TO ltext.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = ltext
i_length = '510'
i_subject = lv_subject1 ).
ELSE.
* Build E-Mail body for Valid WID gone in exception status
CLEAR: body_text.
CONCATENATE 'ECM Reference ID '
lv_wid
'might not have processed as desired.' INTO body_text SEPARATED BY space.
APPEND body_text TO ltext.
CLEAR: body_text.
CONCATENATE 'Please forward this e-mail to the '
'System / Workflow Administrator to help you and analyze / solve it.' INTO body_text SEPARATED BY space.
APPEND body_text TO ltext.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = ltext
i_length = '510'
i_subject = lv_subject1 ).
ENDIF.
* Add document to send request
CALL METHOD send_request->set_document( document ).
* --------- set sender -------------------------------------------
* note: this is necessary only if you want to set the sender
* different from actual user (SY-UNAME). Otherwise sender is
* set automatically with actual user.
sender = cl_sapuser_bcs=>create( sy-uname ).
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
* --------- Add recipient (e-mail address) -----------------------
* Create recipient - passing the receipient e-mail ID
recipient = cl_cam_address_bcs=>create_internet_address( lv_email ).
* Add recipient with its respective attributes to send request
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
* ---------- Send document ---------------------------------------
send_request->set_send_immediately( 'X' ).
CALL METHOD send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).
COMMIT WORK.
CATCH cx_bcs INTO bcs_exception.
ENDTRY.
ENDIF.
* End the IF for checking valid E-Mail
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.