Вы находитесь на странице: 1из 3

method CREATE_ATTACHMENT.

* *--------------------------------------------------------------------*
* Initial Build
* *--------------------------------------------------------------------*
* * Class name : ZCL_P2P_UTILITY *
* * Created on : 28/09/2017 *
* * Author : Abhishek Singh(Abhishek) *
* * Requested by : Stephen Harrison *
* * Development specId : P003 *
* * Transport request : DE1K909325 *
* * Functional design : D003d_19 FSD_P2P_P003 Create Requisitions *
* * Technical design : *
* * Description : This method is used to create a GOS *
* attachment. *
*----------------------------------------------------------------------*
* Modification Information *
*----------------------------------------------------------------------*
* Change date : *
* Author : *
* Transport Number : *
* Change Request : *
* Defect Number : *
* Description : *
*----------------------------------------------------------------------*
DATA: l_folder_id TYPE so_obj_id,
l_document_data TYPE sodocchgi1,
l_document_type TYPE so_obj_tp,
l_document_info TYPE sofolenti1,
l_object_content_hex TYPE TABLE OF solix,
l_line_content_hex TYPE solix,
l_only_name TYPE string,
l_extension TYPE hap_attachment_type,
l_msgno TYPE char3,
l_data_read TYPE i,
l_appraisal_id TYPE borident,
l_attachment_id TYPE borident,
ls_doc_bor_key TYPE hap_s_doc_bor_key,
conv_class TYPE REF TO cl_abap_conv_in_ce,
off_class TYPE REF TO cl_abap_view_offlen.

DATA: lv_rcode TYPE sy-subrc. "VXJ2001940

DATA: lt_object_header TYPE STANDARD TABLE OF solisti1,


ls_object_header TYPE solisti1.

* CLEAR: es_return,
* es_attachment.
*

CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'


EXPORTING
region = 'B'
IMPORTING
folder_id = l_folder_id "#EC *
EXCEPTIONS
communication_failure = 1
owner_not_exist = 2
system_failure = 3
x_error = 4
OTHERS = 5.

IF sy-subrc <> 0.
l_msgno = sy-msgno.
CALL FUNCTION 'HRHAP_MESSAGE_FILL'
EXPORTING
msgno = l_msgno
IMPORTING
s_return = e_return.
RETURN.
ENDIF.

CALL FUNCTION 'HRHAP_DOC_ATTACHMENT_FILESPLIT'


EXPORTING
filename = i_filename
IMPORTING
name = l_only_name
extension = l_extension.

l_document_data-obj_descr = l_only_name.
l_document_data-obj_name = 'MITTEILUNG'.

l_document_type = l_extension.

* -> VXJ2001940
* check, if file extension is allowed
CALL FUNCTION 'SO_TSOPE_CHECK'
EXPORTING
file_ext = l_document_type
query = 'CREA'
IMPORTING
rcode = lv_rcode
EXCEPTIONS
x_error = 1
OTHERS = 2.

IF sy-subrc <> 0 OR
lv_rcode <> 0.
IF 1 = 0. MESSAGE e322(so). ENDIF. "Documents of this type are not allowed in
your system
e_return-type = 'E'.
e_return-log_no = 'SO'.
e_return-message = 'Not allowed'.
RETURN.
ENDIF.
* <- VXJ2001940

conv_class = cl_abap_conv_in_ce=>create(
replacement = ' '
ignore_cerr = abap_true
input = i_content ) .

* Removed special handling for ASCII files. We should also treat .txt in binary
mode.
* A Unicode encoded .txt file breaks in ASCII mode.

off_class = cl_abap_view_offlen=>create_legacy_view( l_line_content_hex ).


l_data_read = 1.
WHILE l_data_read > 0.
CLEAR l_line_content_hex.
CALL METHOD conv_class->read
EXPORTING
n = -1
view = off_class
IMPORTING
data = l_line_content_hex
len = l_data_read.
IF l_data_read > 0.
APPEND l_line_content_hex TO l_object_content_hex.
ENDIF.
ENDWHILE.
l_document_data-doc_size = XSTRLEN( i_content ).
CONCATENATE '&SO_FILENAME = ' i_filename INTO ls_object_header-line SEPARATED BY
space.
APPEND ls_object_header TO lt_object_header.

CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'


EXPORTING
folder_id = l_folder_id
document_data = l_document_data
document_type = l_document_type
IMPORTING
document_info = l_document_info
TABLES
* object_content = l_object_content
contents_hex = l_object_content_hex
object_header = lt_object_header
EXCEPTIONS
folder_not_exist = 1
document_type_not_exist = 2
operation_no_authorization = 3
parameter_error = 4
x_error = 5
enqueue_error = 6
OTHERS = 7.
IF sy-subrc <> 0.
l_msgno = sy-msgno.
CALL FUNCTION 'HRHAP_MESSAGE_FILL'
EXPORTING
msgno = l_msgno
IMPORTING
s_return = e_return.
RETURN.
ENDIF.

e_ID = l_document_info-doc_id(34).
endmethod.

Вам также может понравиться