method IF_SWF_IFS_WORKITEM_EXIT~EVENT_RAISED.
DATA: lv_id TYPE sww_wiid,
lo_container TYPE REF TO if_swf_ifs_parameter_container,
lv_attach TYPE TABLE OF obj_record,
lv_folder_id TYPE soodk,
lv_str TYPE string,
lv_size TYPE so_obj_len,
ls_document_info TYPE sofolenti1,
ls_data TYPE sodocchgi1,
lv_objtype TYPE swo_objtyp,
lv_objkey TYPE swo_typeid,
lv_return TYPE swotreturn,
lv_sofm TYPE swo_objhnd,
lv_object TYPE obj_record,
lt_obj TYPE TABLE OF obj_record,
lt_solix TYPE solix_tab,
ls_trip TYPE sibflporb,
lv_tripno TYPE reinr,
lv_pernr TYPE pernr_d,
lv_form TYPE fpcontent,
lt_ret TYPE bapirettab,
lt_header TYPE TABLE OF solisti1,
ls_header TYPE solisti1.
* Ausführen der Logik beim Anlegen des Workitems
CHECK im_event_name = 'CREATED'.
* Holen der Workitem ID
CALL METHOD im_workitem_context->get_workitem_id
RECEIVING
re_workitem = lv_id.
* Holen des Workitem Container
CALL METHOD im_workitem_context->get_wi_container
RECEIVING
re_container = lo_container.
* Prüfen, ob schon ein Attachment vorhanden ist
TRY.
CALL METHOD lo_container->get
EXPORTING
name = '_ATTACH_OBJECTS'
IMPORTING
value = lv_attach.
CATCH: cx_swf_cnt_elem_not_found,
cx_swf_cnt_elem_type_conflict,
cx_swf_cnt_unit_type_conflict,
cx_swf_cnt_container.
ENDTRY.
* Holen der Reisedaten für die PDF-Generierung
IF lv_attach IS INITIAL.
TRY.
CALL METHOD lo_container->get
EXPORTING
name = 'TRIP'
IMPORTING
value = ls_trip.
lv_pernr = ls_trip-instid+0(8).
lv_tripno = ls_trip-instid+8.
CATCH: cx_swf_cnt_elem_not_found,
cx_swf_cnt_elem_type_conflict,
cx_swf_cnt_unit_type_conflict,
cx_swf_cnt_container.
EXIT.
ENDTRY.
* Holen des Speicherordner
CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
EXPORTING
owner = sy-uname
region = 'B'
IMPORTING
folder_id = lv_folder_id.
* Reiseantrag generieren
CALL FUNCTION 'PTRM_WEB_FORM_PDF_GET'
EXPORTING
i_employeenumber = lv_pernr " Personalnummer
i_tripnumber = lv_tripno " Reisenummer
i_periodnumber = '000' " Nummer der Reiseperiode
i_trip_component = 'R' " Kennzeichen Plan Antrag
i_trip_data_source = 'DB' " Quelle der Reise für Formular
i_language = sy-langu " Sprachenschlüssel
IMPORTING
e_pdf_form = lv_form " Formularprozessierung: Inhalt von XFT, XFD, PDF etc.
TABLES
et_return = lt_ret. " Tabelle mit BAPI Return Informationen
CALL METHOD cl_bcs_convert=>xstring_to_solix
EXPORTING
iv_xstring = lv_form
RECEIVING
et_solix = lt_solix.
* Dokumentdaten setzen
ls_data-doc_size = xstrlen( lv_form ).
ls_data-obj_name = lv_tripno.
ls_data-obj_descr = ls_data-obj_name.
* Wichtig: Headerdaten setzen, sonst wird das mit der Anzeige in der Fiori Inbox nichts
ls_header-line = 'Reiseantrag'.
APPEND ls_header TO lt_header.
ls_header-line = |&SO_FILENAME=Reiseantrag_| && |{ lv_pernr }| && |_| && |{ lv_tripno }| && |.PDF|.
APPEND ls_header TO lt_header.
APPEND '&SO_FORMAT=BIN' TO lt_header.
APPEND '&SO_CONTTYPE=application/pdf' TO lt_header.
* Dokument anlegen
CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
EXPORTING
folder_id = lv_folder_id
document_data = ls_data
document_type = 'BIN'
IMPORTING
document_info = ls_document_info
TABLES
object_header = lt_header
contents_hex = lt_solix
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.
* Objekttyp festlegen und verknüpfen
lv_objtype = 'SOFM'.
lv_objkey = ls_document_info-doc_id.
CALL FUNCTION 'SWO_CREATE'
EXPORTING
objtype = lv_objtype
objkey = lv_objkey
IMPORTING
object = lv_sofm
return = lv_return
EXCEPTIONS
no_remote_objects = 1
OTHERS = 2.
* Objekt zum Workitem Container hinzufügen
lv_object-header = 'OBJH'.
lv_object-type = 'SWO'.
lv_object-handle = lv_sofm.
APPEND lv_object TO lt_obj.
TRY.
CALL METHOD lo_container->set
EXPORTING
name = '_ATTACH_OBJECTS'
value = lt_obj[].
CATCH: cx_swf_cnt_cont_access_denied
cx_swf_cnt_elem_access_denied
cx_swf_cnt_elem_not_found
cx_swf_cnt_elem_type_conflict
cx_swf_cnt_unit_type_conflict
cx_swf_cnt_elem_def_invalid
cx_swf_cnt_container.
RAISE EXCEPTION TYPE cx_swf_ifs_workitem_exit_error.
ENDTRY.
* Objekt zusätzlich an die E-Mail hängen
TRY.
CALL METHOD lo_container->set
EXPORTING
name = 'ATTACHMENTS'
value = lt_obj[].
CATCH: cx_swf_cnt_cont_access_denied
cx_swf_cnt_elem_access_denied
cx_swf_cnt_elem_not_found
cx_swf_cnt_elem_type_conflict
cx_swf_cnt_unit_type_conflict
cx_swf_cnt_elem_def_invalid
cx_swf_cnt_container.
RAISE EXCEPTION TYPE cx_swf_ifs_workitem_exit_error.
ENDTRY.
* Commit
CALL METHOD im_workitem_context->do_commit_work.
ENDIF.
endmethod.