
* set sender
lo_sender = cl_sapuser_bcs=>create( 'KEGSAPSUP' ).
METHOD if_inbound_exit_bcs~process_inbound .
DATA: sender TYPE REF TO if_sender_bcs.
DATA: sender_addr TYPE string.
DATA: lo_reply TYPE REF TO cl_send_request_bcs .
DATA: li_document TYPE REF TO if_document_bcs,
l_subject TYPE so_obj_des,
ls_text TYPE soli,
lt_text TYPE soli_tab.
TRY.
**** init
CLEAR e_retcode.
CLEAR es_t100msg.
**** Get a pointer to the reply email object
lo_reply = io_sreq->reply( ).
**** Check to make sure this is from an approved Sender
sender = io_sreq->get_sender( ).
sender_addr = sender->address_string( ).
TRANSLATE sender_addr TO UPPER CASE.
**** Only reply if this message came from within out mail system
IF sender_addr CS '@SITECO.DE' OR
sender_addr CS '@SITECO.NET'.
**** Process Attachment
DATA: l_parts TYPE int4,
anhang_nr TYPE string,
attribute TYPE bcss_dbpa,
lt_attachments TYPE TABLE OF int4,
ls_attachments LIKE LINE OF lt_attachments,
ls_content TYPE bcss_dbpc,
lv_request_guid_c TYPE crmt_object_guid32,
ls_file_info TYPE crmt_icss_file_info,
lt_file_content_binary TYPE TABLE OF sdokcntbin,
l_sender_subject TYPE char50,
lt_cont_hex TYPE solix_tab,
ls_cont_hex LIKE LINE OF lt_cont_hex,
lv_objkey TYPE swo_typeid,
size TYPE string.
**** Data Types for Binary Conversion
DATA: v_struct TYPE sdokcntbin,
v_cur_pos TYPE i,
v_line TYPE sdok_sdatx,
v_temp TYPE xstring,
v_length TYPE i.
**** get document
li_document = io_sreq->get_document( ).
**** get subject
l_sender_subject = li_document->get_subject( ).
**** Get Opportunity GUID from Subject
DATA: iv_opportunity_id TYPE crmt_object_id,
lt_opportunity TYPE TABLE OF crmt_icm_opportunity_descrpt,
ls_opportunity LIKE LINE OF lt_opportunity,
opp_guid TYPE string.
iv_opportunity_id = l_sender_subject.
CALL FUNCTION 'CRM_ICM_OPPORTUNITY_SEARCH'
EXPORTING
iv_opportunity_id = iv_opportunity_id
* IV_OPPORTUNITY_DESCRIPTION =
* IV_OPPORTUNITY_GUID =
TABLES
et_opportunity = lt_opportunity
EXCEPTIONS
no_authorization = 1
error_occured = 2
OTHERS = 3.
**** Only if we get a valid GUID we process the Attachments
READ TABLE lt_opportunity INDEX 1 INTO ls_opportunity.
IF sy-subrc <> 0
OR ls_opportunity-guid = '00000000000000000000000000000000'.
CONCATENATE
'No Opportunity with number:'
iv_opportunity_id 'was found'
INTO ls_text SEPARATED BY space.
APPEND ls_text TO lt_text.
l_subject = ls_text.
ELSE.
**** Assign Opportunity GUID for display and FM input
opp_guid = ls_opportunity-guid.
lv_request_guid_c = ls_opportunity-guid.
**** Insert Opportunity GUID and Description into the reply text
CONCATENATE 'Opportunity GUID:' opp_guid
'Description:' ls_opportunity-description
INTO ls_text
SEPARATED BY space.
APPEND ls_text TO lt_text.
**** get no. of body parts
l_parts = li_document->get_body_part_count( ).
**** Read which body part contains the file we are looking for (PDF or TIF)
DO l_parts TIMES.
attribute = li_document->get_body_part_attributes( sy-index ).
TRANSLATE attribute-subject TO UPPER CASE.
IF attribute-subject CS '.PDF'
OR attribute-subject CS '.TIF'.
MOVE sy-index TO ls_attachments.
APPEND ls_attachments TO lt_attachments.
ENDIF.
ENDDO.
LOOP AT lt_attachments INTO ls_attachments.
**** Read the actual content
ls_content = li_document->get_body_part_content( ls_attachments ).
attribute = li_document->get_body_part_attributes( ls_attachments ).
anhang_nr = ls_attachments.
ls_file_info-filename = attribute-filename.
v_cur_pos = 0.
**** Fill v_temp
CLEAR v_temp.
LOOP AT ls_content-cont_hex INTO ls_cont_hex.
CONCATENATE v_temp ls_cont_hex-line INTO v_temp IN BYTE MODE.
ENDLOOP.
**** Detect Lenth of File
ls_file_info-length = xstrlen( v_temp ).
**** Fill Table for Attachment
CLEAR lt_file_content_binary.
WHILE NOT v_temp IS INITIAL.
v_line = v_temp.
v_struct-line = v_line.
INSERT v_struct INTO TABLE lt_file_content_binary.
SHIFT v_temp LEFT BY 1022 PLACES IN BYTE MODE.
ENDWHILE.
**** Attach Document to Opportunity
CALL FUNCTION 'CRM_ICSS_UPLOAD_SR_ATTACHMENT'
EXPORTING
iv_request_guid_c = lv_request_guid_c
icss_file_info = ls_file_info
IMPORTING
ev_objkey = lv_objkey
TABLES
file_content_binary = lt_file_content_binary.
**** Return Objectkey and other File information
size = ls_file_info-length.
CONCATENATE 'Attachment No.' anhang_nr
'Filename:' attribute-filename
'Size:' size
INTO ls_text
SEPARATED BY space.
APPEND ls_text TO lt_text.
ENDLOOP.
**** send reply
CONCATENATE
'Attachment was added to Opportunity' iv_opportunity_id
INTO l_subject
SEPARATED BY space.
ENDIF.
me->send_reply( io_reply = lo_reply
ip_subject = l_subject
it_content = lt_text ).
ENDIF.
* ----------------------------------------------------------------------------
* error handling
* ----------------------------------------------------------------------------
* system error
CATCH cx_os_object_not_found cx_alert_recipient_unknown
cx_document_bcs cx_send_req_bcs cx_address_bcs.
TRY.
**** send reply
l_subject = 'Message could not be processed'.
**** build content for reply
ls_text = 'An internal system error occured!! Please send the message again.'.
APPEND ls_text TO lt_text.
ls_text = 'If this error occurs again please call your system administrator.'.
APPEND ls_text TO lt_text.
me->send_reply( io_reply = lo_reply
ip_subject = l_subject
it_content = lt_text ).
* e_retcode = 4.
CATCH cx_document_bcs cx_address_bcs cx_send_req_bcs.
* e_retcode = 4.
ENDTRY.
ENDTRY.
**** exit has done its work
e_retcode = if_inbound_exit_bcs=>gc_terminate.
ENDMETHOD.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
1 | |
1 | |
1 | |
1 | |
1 |