├── Changeset_End ├── Debugging ├── README.md ├── CacheRuntime ├── Delete ├── Stream ├── Archivelink │ ├── readme │ └── ZCL_CONTENT_REPOSITORY ├── Define for Streams ├── GOS │ ├── Get_List_of_Attachments_Simplified │ ├── Create │ ├── GET_STREAM │ └── Get_List_of_Attachments ├── Getstream from AL11 ├── ABAP App Server │ ├── download │ └── Upload ├── GetStream from SmartForm ├── CreateStream └── GetStream ├── Update ├── Warning_Save_In_Response_Header ├── FunctionImport ├── Changset_Begin ├── Read ├── NoCacheRuntime ├── Handling Custom HTTP Headers ├── .github └── FUNDING.yml ├── Define for Annotations ├── MPC_EXT └── Extending DEFINE ├── DeepInsert ├── Create ├── RaisingExceptions ├── ALVReport_To_Query ├── QueryFromALVReport ├── Redefine_get_entityset ├── Data input check ├── Expand ├── FioriElements └── CDS_DropDownValueHelp ├── Changeset_Process └── Query /Changeset_End: -------------------------------------------------------------------------------- 1 | COMMIT WORK AND WAIT. "If 'AND WAIT' is not added, then the immediate fetch of the values may not have the updated values. 2 | -------------------------------------------------------------------------------- /Debugging: -------------------------------------------------------------------------------- 1 | -> Hub layer sends calls to the backend from class /IWFND/CL_MGW_REQUEST_MANAGER->CALL_BACKEND. 2 | If the backend debugger does not trigger, do a F5 into the RFC call inside this class. 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SAP Gateway Templates 2 | Code Patterns/Sample code for SAP Gateway 3 | 4 | No License, No Attribution, No Apache, No MIT required. Use it as you like. :) and let me know if it helped. kammaje@outlook.com 5 | -------------------------------------------------------------------------------- /CacheRuntime: -------------------------------------------------------------------------------- 1 | DATA: ls_header type ihttpnvp. 2 | ls_header-name = 'Cache-Control'. 3 | ls_header-value = 'max-age=3600'. 4 | set_header( ls_header ). 5 | 6 | "Keep in mind that if the query is called by a $batch, then browser will not be able to honor these http headers. 7 | -------------------------------------------------------------------------------- /Delete: -------------------------------------------------------------------------------- 1 | DATA: ls_entity TYPE 2 | 3 | " Get Converted keys 4 | io_tech_request->get_converted_keys( IMPORTING es_key_values = ls_entity ). 5 | 6 | "key should be checked 7 | CHECK ls_entity-key1 IS NOT INITIAL AND ls_entity-key2 IS NOT INITIAL. 8 | -------------------------------------------------------------------------------- /Stream/Archivelink/readme: -------------------------------------------------------------------------------- 1 | Class ZCL_CONTENT_REPOSITORY will fetch BOTH GOS and ARCHIVELINK attachments. Most of this content is from SAP provided class for PR Fiori app. 2 | 3 | Method GET_DOCUMENTS_FOR_OBJECT provides a list of attachments for a Business Object 4 | Method ENHANCE_ATTACHMENT_CONTENT provides content of the attachment. 5 | 6 | -------------------------------------------------------------------------------- /Update: -------------------------------------------------------------------------------- 1 | 2 | DATA: ls_request_input_data TYPE zcl_zsqrmbwa_mpc_ext=>ts_finding, 3 | lv_finding_id TYPE zwm_finding. 4 | 5 | " Get Converted keys 6 | io_tech_request_context->get_converted_keys( IMPORTING es_key_values = ls_request_input_data ). 7 | lv_finding_id = ls_request_input_data-findingid. 8 | 9 | "Get Request Data 10 | io_data_provider->read_entry_data( IMPORTING es_data = ls_request_input_data ). 11 | -------------------------------------------------------------------------------- /Warning_Save_In_Response_Header: -------------------------------------------------------------------------------- 1 | 2 | " Below code will get the message in Reposne header 3 | " In the DPC_EXT Class. 4 | 5 | lo_container = me->mo_context->get_message_container( ). 6 | lo_container->add_message( 7 | iv_msg_type = 'S' 8 | iv_msg_id = 'BL' 9 | iv_msg_number = 308 10 | iv_msg_v1 = 'Success' 11 | iv_is_leading_message = abap_true 12 | iv_add_to_response_header = abap_true 13 | ). 14 | -------------------------------------------------------------------------------- /FunctionImport: -------------------------------------------------------------------------------- 1 | 2 | DATA: ls_parameter TYPE /iwbep/s_mgw_name_value_pair. 3 | DATA: lt_parameters TYPE /iwbep/t_mgw_name_value_pair. 4 | 5 | lt_parameters = io_tech_request_context->get_parameters( ). 6 | 7 | CASE io_tech_request_context->get_function_import_name( ). 8 | 9 | WHEN ''. 10 | 11 | WHEN OTHERS. 12 | 13 | ENDCASE. 14 | 15 | copy_data_to_ref( 16 | EXPORTING 17 | is_data = ls_summary 18 | CHANGING 19 | cr_data = er_data 20 | ). 21 | -------------------------------------------------------------------------------- /Changset_Begin: -------------------------------------------------------------------------------- 1 | METHOD /iwbep/if_mgw_appl_srv_runtime~changeset_begin. 2 | 3 | DATA: ls_operation_info TYPE /iwbep/s_mgw_operation_info. 4 | CONSTANTS: lc_entitysets TYPE string VALUE 'Operations,Components,WorkOrderSet'. 5 | 6 | LOOP AT it_operation_info INTO ls_operation_info. 7 | FIND FIRST OCCURRENCE OF ls_operation_info-entity_set IN lc_entitysets. 8 | IF sy-subrc EQ 0. 9 | * Defer Mode only for selected operations 10 | cv_defer_mode = abap_true. 11 | ENDIF. 12 | ENDLOOP. 13 | 14 | ENDMETHOD. 15 | -------------------------------------------------------------------------------- /Read: -------------------------------------------------------------------------------- 1 | DATA: lt_keys TYPE /iwbep/t_mgw_tech_pairs, 2 | ls_key TYPE LINE OF /iwbep/t_mgw_tech_pairs. 3 | 4 | "Keys to be read 5 | lt_keys = io_tech_request_context->get_keys( ). 6 | READ TABLE lt_keys INTO ls_key WITH KEY name = 'DOCUMENTNO'. 7 | IF sy-subrc EQ 0. 8 | lv_doc_number = ls_key-value. 9 | ENDIF. 10 | 11 | "Keys with COnversion routine applied 12 | DATA: ls_finding TYPE . 13 | io_tech_request_context->get_converted_keys( IMPORTING es_key_values = ls_finding ). 14 | -------------------------------------------------------------------------------- /NoCacheRuntime: -------------------------------------------------------------------------------- 1 | 2 | 3 | DATA: ls_response_header TYPE ihttpnvp. 4 | 5 | "now prevent caching for all responses. Below response headers prevent caching 6 | ls_response_header-name = 'Cache-Control'. 7 | ls_response_header-value = 'no-cache, no-store'. 8 | set_header( ls_response_header ). 9 | ls_response_header-name = 'Pragma'. 10 | ls_response_header-value = 'no-cache'. 11 | set_header( ls_response_header ). 12 | ls_response_header-name = 'Expires'. 13 | ls_response_header-value = '0'. 14 | set_header( ls_response_header ). 15 | 16 | "Using Headers 17 | chs_response_context-do_not_cache_on_client = abap_true. 18 | -------------------------------------------------------------------------------- /Stream/Define for Streams: -------------------------------------------------------------------------------- 1 | DATA: 2 | lo_annotation TYPE REF TO /iwbep/if_mgw_odata_annotation, "#EC NEEDED 3 | lo_entity_type TYPE REF TO /iwbep/if_mgw_odata_entity_typ, "#EC NEEDED 4 | lo_property TYPE REF TO /iwbep/if_mgw_odata_property. "#EC NEEDED 5 | 6 | " Get the complete metadata first. 7 | super->define( ). 8 | 9 | " Adding extra metadata now 10 | lo_entity_type = model->get_entity_type( iv_entity_name = 'EmpDetail'). "Your entity name 11 | 12 | lo_property = lo_entity_type->get_property( iv_property_name = 'MimeTyep' ). "Property in your entity which provides mimetype 13 | lo_property->set_as_content_type( ). 14 | -------------------------------------------------------------------------------- /Handling Custom HTTP Headers: -------------------------------------------------------------------------------- 1 | DATA : lo_facade TYPE REF TO /iwbep/if_mgw_dp_int_facade, 2 | lt_client_headers TYPE tihttpnvp, 3 | ls_client_header TYPE LINE OF tihttpnvp. 4 | 5 | " Read request header 6 | lo_facade ?= /iwbep/if_mgw_conv_srv_runtime~get_dp_facade( ). 7 | lt_client_headers = lo_facade->get_request_header( ). 8 | READ TABLE lt_client_headers INTO ls_client_header WITH KEY name = 'If-None-Match'. 9 | IF sy-subrc EQ 0. 10 | lv_header_value = ls_client_header-value. 11 | ENDIF. 12 | 13 | " Update Response Header 14 | ls_client_header-name = 'Custom_header_name'. 15 | ls_client_header-value = abap_true. 16 | set_header( ls_client_header ). 17 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: kkammaje # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /Define for Annotations: -------------------------------------------------------------------------------- 1 | DATA: 2 | lo_annotation TYPE REF TO /iwbep/if_mgw_odata_annotation, "#EC NEEDED 3 | lo_entity_type TYPE REF TO /iwbep/if_mgw_odata_entity_typ, "#EC NEEDED 4 | lo_property TYPE REF TO /iwbep/if_mgw_odata_property. "#EC NEEDED 5 | 6 | super->define( ). "Ensure you call the parent metadata 7 | lo_entity_type = model->get_entity_type( iv_entity_name = 'EmpDetail'). "Your Entity Name 8 | lo_property = lo_entity_type->get_property( iv_property_name = 'DateOfHire'). "Property inside your Entity 9 | lo_annotation = lo_property-/iwbep/if_mgw_odata_annotatabl~create_annotation( /iwbep/if_mgw_med_odata_types=>gc_sap_namespace ). "SAP's annotations 10 | lo_annotation->add( iv_key = 'display-format' iv_value = 'Date' ). "Specific annotation you want to add. 11 | -------------------------------------------------------------------------------- /MPC_EXT/Extending DEFINE: -------------------------------------------------------------------------------- 1 | " Extendinf DEFINE and adding SAP Annotations 2 | METHOD define. 3 | 4 | DATA: lo_entity_type TYPE REF TO /iwbep/if_mgw_odata_entity_typ, 5 | lo_property TYPE REF TO /iwbep/cl_mgw_odata_property, 6 | lo_annotation TYPE REF TO /iwbep/if_mgw_odata_annotation. 7 | 8 | super->define( ). "Ensure you call the parent metadata 9 | 10 | lo_entity_type = model->get_entity_type( iv_entity_name = 'SESItem'). "Your Entity Name 11 | lo_property ?= lo_entity_type->get_property( iv_property_name = 'Date'). "Property inside your Entity 12 | 13 | CALL METHOD lo_property->/iwbep/if_mgw_odata_annotatabl~create_annotation 14 | EXPORTING 15 | iv_annotation_namespace = /iwbep/if_mgw_med_odata_types=>gc_sap_namespace 16 | RECEIVING 17 | ro_annotation = lo_annotation. 18 | 19 | lo_annotation->add( iv_key = 'display-format' iv_value = 'Date' ). "Specific annotation you want to add. 20 | 21 | ENDMETHOD. 22 | -------------------------------------------------------------------------------- /DeepInsert: -------------------------------------------------------------------------------- 1 | METHOD /iwbep/if_mgw_appl_srv_runtime~create_deep_entity. 2 | 3 | * Type declaration for header and navigation items 4 | TYPES: BEGIN OF lty_s_workorder. 5 | INCLUDE TYPE zcl_zworkorder_mpc=>ts_workorderdetail. 6 | TYPES: components TYPE STANDARD TABLE OF zcl_zworkorder_mpc=>ts_component WITH DEFAULT KEY, 7 | operations TYPE STANDARD TABLE OF zcl_zworkorder_mpc=>ts_operation WITH DEFAULT KEY. 8 | TYPES: END OF lty_s_workorder. 9 | 10 | DATA: ls_workorder TYPE lty_s_workorder. 11 | 12 | * Validate whether the current request including the inline SOItem data matches 13 | * Upon match, access data from IO_DATA_PROVIDER 14 | IF io_expand->compare_to_tech_names('SALESAREAS') = /iwbep/if_mgw_odata_expand=>gcs_compare_result-match_equals. 15 | io_data_provider->read_entry_data( IMPORTING es_data = ls_workorder ). 16 | ENDIF. 17 | 18 | * Send back 19 | copy_data_to_ref( 20 | EXPORTING 21 | is_data = ls_payload 22 | CHANGING 23 | cr_data = er_deep_entity ). 24 | 25 | ENDMETHOD. 26 | -------------------------------------------------------------------------------- /Create: -------------------------------------------------------------------------------- 1 | 2 | * Get Source Keys. If query is through Navigation 3 | DATA: lt_parent_keys TYPE /iwbep/t_mgw_tech_pairs, 4 | ls_parent_key TYPE /iwbep/s_mgw_tech_pair. 5 | 6 | "Get Parent entity name 7 | IF io_tech_request_context->get_source_entity_type_name( ) = 'Inspection'. 8 | "get parent keys 9 | lt_parent_keys = io_tech_request_context->get_source_keys( ). 10 | READ TABLE lt_parent_keys INTO ls_parent_key WITH KEY name = 'INSPECTIONID'. 11 | IF sy-subrc EQ 0. 12 | er_entity-inspectionid = ls_parent_key-value. 13 | ENDIF. 14 | 15 | "Get Converted Parent Keys 16 | IF io_tech_request_context->get_source_entity_type_name( ) = 'Inspection'. 17 | "get parent keys 18 | io_tech_request_context->get_converted_source_keys( IMPORTING es_key_values = ). 19 | er_entity-inspectionid = -inspectionid. 20 | ENDIF. 21 | ENDIF. 22 | 23 | * Read request data 24 | DATA: ls_request_input_data TYPE . 25 | io_data_provider->read_entry_data( IMPORTING es_data = ls_request_input_data ). 26 | -------------------------------------------------------------------------------- /RaisingExceptions: -------------------------------------------------------------------------------- 1 | ---------------------- * Option 1: Using Message Container--------------------------------- 2 | 3 | DATA lo_message_container TYPE REF TO /iwbep/if_message_container. 4 | " get message container object 5 | lo_message_container = mo_context->get_message_container( ). 6 | 7 | *Option 1.1 - Add message from BAPI (BAPIRET2) 8 | CALL METHOD lo_message_container->add_messages_from_bapi 9 | EXPORTING 10 | it_bapi_messages = lt_return "This has to be of type BAPIRET2 11 | iv_determine_leading_msg = /iwbep/if_message_container=>gcs_leading_msg_search_option-first. 12 | 13 | *Option 1.2 14 | *Raise Exception 15 | RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception 16 | EXPORTING 17 | message_container = lo_message_container. 18 | 19 | ---------------------- *Option 2: Direct Use. Without /iwbep/if_message_container--------------------------------- 20 | 21 | MESSAGE e000(Zmessage_class) INTO DATA(lv_message) WITH sy-uname. 22 | 23 | RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception 24 | EXPORTING 25 | textid = /iwbep/cx_mgw_busi_exception=>business_error_unlimited 26 | message_unlimited = lv_message. 27 | -------------------------------------------------------------------------------- /Stream/GOS/Get_List_of_Attachments_Simplified: -------------------------------------------------------------------------------- 1 | DATA: lo_gos_api TYPE REF TO cl_gos_api, 2 | ls_appl_object TYPE gos_s_obj, 3 | lt_attachment_list TYPE gos_t_atta, 4 | lt_role_filter TYPE gos_t_rol, 5 | ls_attachment TYPE gos_s_atta, 6 | ls_finding_atta TYPE zcl_zsqrmbwa_mpc_ext=>ts_attachment. 7 | 8 | ls_appl_object-typeid = 'CL_XYZ'. "Class or BO Name 9 | ls_appl_object-catid = 'BC'. "BO for SW01 BO 10 | 11 | "Instantiate GOS 12 | ls_appl_object-instid = iv_finding_id. 13 | TRY. 14 | lo_gos_api = cl_gos_api=>create_instance( ls_appl_object ). 15 | APPEND cl_gos_api=>c_attachment TO lt_role_filter. 16 | lt_attachment_list = lo_gos_api->get_atta_list( lt_role_filter ). 17 | CATCH cx_gos_api. 18 | * error handling 19 | ENDTRY. 20 | 21 | LOOP AT lt_attachment_list INTO ls_attachment. 22 | ls_finding_atta-findingid = iv_finding_id. 23 | ls_finding_atta-id = ls_attachment-atta_id. 24 | ls_finding_atta-filename = ls_attachment-filename. 25 | ls_finding_atta-filedescription = ls_attachment-descr. 26 | ls_finding_atta-createdby = ls_attachment-cr_user. 27 | ls_finding_atta-createdbyname = ls_attachment-cr_name. 28 | ls_finding_atta-filesize = ls_attachment-filesize. 29 | ls_finding_atta-mime_type = ls_attachment-tech_type. 30 | ls_finding_atta-createdat = | { ls_attachment-cr_date }{ ls_attachment-cr_time } |. 31 | APPEND ls_finding_atta TO et_attachment_list. 32 | ENDLOOP. 33 | -------------------------------------------------------------------------------- /Stream/Getstream from AL11: -------------------------------------------------------------------------------- 1 | DATA: l_attachmentguid TYPE zdeemt_att_guid, 2 | lv_buffer TYPE xstring, 3 | ls_stream TYPE ty_s_media_resource, 4 | ls_lheader TYPE ihttpnvp. 5 | 6 | 7 | READ TABLE it_key_tab INTO DATA(ls_key) WITH KEY name = 'AttachmentId'. 8 | IF sy-subrc = 0. 9 | l_attachmentguid = ls_key-value . 10 | ENDIF. 11 | 12 | //Your logic to prepare the AL11 URL into variable lv_file_path 13 | 14 | OPEN DATASET lv_file_path FOR INPUT IN BINARY MODE. 15 | 16 | IF sy-subrc = 0. 17 | DO . 18 | READ DATASET lv_file_path INTO lv_buffer. 19 | IF sy-subrc = 0. 20 | CONCATENATE es_stream-value lv_buffer INTO es_stream-value IN BYTE MODE. 21 | ELSE. 22 | EXIT. 23 | ENDIF. 24 | ENDDO. 25 | ELSE. 26 | 27 | " Failed to open the file for reading 28 | MESSAGE e079(z_message) INTO DATA(lv_message). 29 | RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception 30 | EXPORTING 31 | textid = /iwbep/cx_mgw_busi_exception=>business_error_unlimited 32 | message_unlimited = lv_message. 33 | ENDIF. 34 | 35 | CLOSE DATASET lv_file_with_key. 36 | 37 | //Your logic to prepare the filename into variable lv_filename 38 | 39 | ls_lheader-name = 'Content-Disposition'. 40 | ls_lheader-value = 'outline; filename="' && lv_filename && '";'. 41 | 42 | set_header( is_header = ls_lheader ). 43 | copy_data_to_ref( EXPORTING is_data = ls_stream 44 | CHANGING cr_data = er_stream ). 45 | -------------------------------------------------------------------------------- /ALVReport_To_Query: -------------------------------------------------------------------------------- 1 | METHOD quotarecords_get_entityset. 2 | 3 | FIELD-SYMBOLS TYPE ANY TABLE. 4 | DATA: ls_report_output TYPE ty_vacation_report_line, 5 | ls_output TYPE zcl_zvacation_report_mpc=>ts_quotarecord, 6 | lt_entityset TYPE zcl_zvacation_report_mpc=>tt_quotarecord. 7 | 8 | cl_salv_bs_runtime_info=>set( EXPORTING display = abap_false 9 | metadata = abap_false 10 | data = abap_true ). 11 | 12 | SUBMIT zhr_vacation_report AND RETURN. 13 | TRY. 14 | cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data = lr_pay_data ). 15 | ASSIGN lr_pay_data->* TO . 16 | CATCH cx_salv_bs_sc_runtime_info. 17 | 18 | ENDTRY. 19 | 20 | cl_salv_bs_runtime_info=>clear_all( ). 21 | 22 | FIELD-SYMBOLS: 23 | TYPE table. 24 | ASSIGN lr_pay_data->* TO . 25 | 26 | CHECK IS NOT INITIAL. 27 | 28 | LOOP AT INTO ls_report_output. 29 | ls_output-personnelnumber = ls_report_output-pernr. 30 | ls_output-quota = ls_report_output-ktart. 31 | ls_output-quotaname = ls_report_output-kttext. 32 | ls_output-name = ls_report_output-cname. 33 | ls_output-entitlement = ls_report_output-entitle. 34 | ls_output-used = ls_report_output-deduct. 35 | ls_output-compensated = ls_report_output-reduced2. 36 | ls_output-remaining = ls_report_output-rest. 37 | ls_output-unit = ls_report_output-untext. 38 | APPEND ls_output TO et_entityset. 39 | ENDLOOP. 40 | 41 | ENDMETHOD. 42 | -------------------------------------------------------------------------------- /QueryFromALVReport: -------------------------------------------------------------------------------- 1 | METHOD quotarecords_get_entityset. 2 | 3 | FIELD-SYMBOLS TYPE ANY TABLE. 4 | DATA: lr_pay_data TYPE REF TO data, 5 | ls_report_output TYPE ty_vacation_report_line, 6 | ls_output TYPE zcl_zvacation_report_mpc=>ts_quotarecord. 7 | 8 | cl_salv_bs_runtime_info=>set( EXPORTING display = abap_false 9 | metadata = abap_false 10 | data = abap_true ). 11 | 12 | SUBMIT zhr_vacation_report AND RETURN. 13 | "<<<<<<>>>>> is name of the ALV report returning program 14 | 15 | TRY. 16 | cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data = lr_pay_data ). 17 | ASSIGN lr_pay_data->* TO . 18 | CATCH cx_salv_bs_sc_runtime_info. 19 | 20 | ENDTRY. 21 | 22 | cl_salv_bs_runtime_info=>clear_all( ). 23 | 24 | FIELD-SYMBOLS: 25 | TYPE table. 26 | ASSIGN lr_pay_data->* TO . 27 | 28 | LOOP AT INTO ls_report_output. 29 | ls_output-personnelnumber = ls_report_output-pernr. 30 | ls_output-quota = ls_report_output-ktart. 31 | ls_output-quotaname = ls_report_output-kttext. 32 | ls_output-name = ls_report_output-cname. 33 | ls_output-entitlement = ls_report_output-entitle. 34 | ls_output-used = ls_report_output-reduced. 35 | ls_output-compensated = ls_report_output-reduced2. 36 | ls_output-remaining = ls_report_output-rest. 37 | ls_output-unit = ls_report_output-untext. 38 | APPEND ls_output TO et_entityset. 39 | ENDLOOP. 40 | 41 | ENDMETHOD. 42 | -------------------------------------------------------------------------------- /Redefine_get_entityset: -------------------------------------------------------------------------------- 1 | METHOD /iwbep/if_mgw_appl_srv_runtime~get_entityset. 2 | DATA: lv_entityset TYPE /iwbep/mgw_tech_name, 3 | lt_entityset TYPE zcl_pr_ap_extension_mpc=>tt_openorder. 4 | 5 | "Get Entityset Name 6 | lv_entityset = io_tech_request_context->get_entity_set_name( ). 7 | 8 | CASE lv_entityset. 9 | WHEN 'OpenOrders'. 10 | 11 | "Get Open Orders 12 | CALL METHOD me->get_entityset_open_orders 13 | EXPORTING 14 | io_tech_request_context = io_tech_request_context 15 | IMPORTING 16 | es_response_context = es_response_context 17 | et_entityset = lt_entityset. 18 | 19 | * Send specific entity data to the caller interface 20 | copy_data_to_ref( 21 | EXPORTING 22 | is_data = lt_entityset 23 | CHANGING 24 | cr_data = er_entityset 25 | ). 26 | 27 | WHEN OTHERS. 28 | CALL METHOD super->/iwbep/if_mgw_appl_srv_runtime~get_entityset 29 | EXPORTING 30 | iv_entity_name = iv_entity_name 31 | iv_entity_set_name = iv_entity_set_name 32 | iv_source_name = iv_source_name 33 | it_filter_select_options = it_filter_select_options 34 | it_order = it_order 35 | is_paging = is_paging 36 | it_navigation_path = it_navigation_path 37 | it_key_tab = it_key_tab 38 | iv_filter_string = iv_filter_string 39 | iv_search_string = iv_search_string 40 | io_tech_request_context = io_tech_request_context 41 | IMPORTING 42 | er_entityset = er_entityset 43 | es_response_context = es_response_context. 44 | ENDCASE. 45 | ENDMETHOD. 46 | -------------------------------------------------------------------------------- /Data input check: -------------------------------------------------------------------------------- 1 | # This method checks the input (structure or table) 2 | 3 | # Method Interface 4 | IM_DATA TYPE ANY 5 | IV_TYPE TYPE TABNAME Table Name 6 | /IWBEP/CX_MGW_BUSI_EXCEPTION Business Exception 7 | 8 | # Code 9 | METHOD validate_inbuilt_checks. 10 | 11 | DATA: lt_failure TYPE STANDARD TABLE OF ddfkeyrc, 12 | lt_error TYPE tb_fw_error, 13 | lv_all_messages TYPE string. 14 | FIELD-SYMBOLS: TYPE ANY TABLE, 15 | TYPE any. 16 | 17 | DESCRIBE FIELD im_data TYPE DATA(lv_typ). 18 | IF lv_typ EQ 'h'. 19 | ASSIGN im_data TO . 20 | LOOP AT ASSIGNING . 21 | "Validate forign key checks 22 | CALL FUNCTION 'DDUT_INPUT_CHECK' 23 | EXPORTING 24 | tabname = iv_type 25 | fieldname = '*' 26 | value_list = 27 | TABLES 28 | failure_tab = lt_failure. 29 | ENDLOOP. 30 | ELSE. 31 | "Validate forign key checks 32 | CALL FUNCTION 'DDUT_INPUT_CHECK' 33 | EXPORTING 34 | tabname = iv_type 35 | fieldname = '*' 36 | value_list = im_data 37 | TABLES 38 | failure_tab = lt_failure. 39 | ENDIF. 40 | 41 | IF lines( lt_failure ) GT 0. 42 | LOOP AT lt_failure ASSIGNING FIELD-SYMBOL(). 43 | DATA(lv_msgno) = -msgnr. 44 | MESSAGE ID -arbgb TYPE 'E' NUMBER lv_msgno 45 | INTO DATA(lv_message) 46 | WITH -msgv1 -msgv2 47 | -msgv3 -msgv4. 48 | lv_all_messages = |{ lv_all_messages } - { lv_message }|. 49 | ENDLOOP. 50 | MESSAGE e022(zmm_wup_messages) INTO lv_message. 51 | lv_all_messages = |{ lv_all_messages } { lv_message }|. 52 | ENDIF. 53 | 54 | IF lv_all_messages IS NOT INITIAL. 55 | RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception 56 | EXPORTING 57 | textid = /iwbep/cx_mgw_busi_exception=>business_error_unlimited 58 | message_unlimited = lv_all_messages. 59 | ENDIF. 60 | 61 | ENDMETHOD. 62 | -------------------------------------------------------------------------------- /Expand: -------------------------------------------------------------------------------- 1 | 2 | *===================data declarations for the expand strucutre=================================================== 3 | TYPES: BEGIN OF lty_s_workorder. 4 | INCLUDE TYPE zcl_zworkorder_mpc=>ts_workorderdetail. 5 | TYPES: components TYPE STANDARD TABLE OF zcl_zworkorder_mpc=>ts_component WITH DEFAULT KEY, 6 | operations TYPE STANDARD TABLE OF zcl_zworkorder_mpc=>ts_operation WITH DEFAULT KEY, 7 | damagecodegroups TYPE STANDARD TABLE OF zcl_zworkorder_mpc=>ts_damagecodegroup WITH DEFAULT KEY, 8 | notificationunits TYPE STANDARD TABLE OF zcl_zworkorder_mpc=>ts_unit WITH DEFAULT KEY. 9 | TYPES: END OF lty_s_workorder. 10 | 11 | *=======Getting key for GET_EXPANDED_ENTITY====================================================================== 12 | DATA: lt_keys TYPE /iwbep/t_mgw_tech_pairs, 13 | ls_key TYPE /iwbep/s_mgw_tech_pair, 14 | lv_entity_name TYPE /iwbep/mgw_tech_name. 15 | 16 | * Get entityset name 17 | lv_entity_name = io_tech_request_context->get_entity_type_name( ). 18 | lt_keys = io_tech_request_context->get_keys( ). 19 | READ TABLE lt_keys INTO ls_key WITH KEY name = 'ORDERNUMBER'. 20 | CHECK sy-subrc EQ 0. 21 | 22 | *============Send Data back====================================================================================== 23 | copy_data_to_ref( 24 | EXPORTING 25 | is_data = laborentries_get_entity 26 | CHANGING 27 | cr_data = er_entity 28 | ). 29 | 30 | *============"Tell the framework that all required fecthing is done and not to do generic expand. =============== 31 | DATA: lo_request TYPE REF TO /iwbep/cl_mgw_request. 32 | lo_request ?= io_tech_request_context. 33 | DATA(lv_expand) = lo_request->/iwbep/if_mgw_req_entityset~get_expand( ). 34 | TRANSLATE lv_expand TO UPPER CASE. 35 | SPLIT lv_expand AT ',' INTO TABLE et_expanded_tech_clauses. 36 | 37 | //Note: For the above code to work, "ABAP Field Name"of the Navigation properties have to be same (Uppercase) 38 | //as the navigation property name (in SEGW). 39 | *================================================================================================================= 40 | -------------------------------------------------------------------------------- /Stream/GOS/Create: -------------------------------------------------------------------------------- 1 | DATA: lv_entity_name TYPE /iwbep/mgw_tech_name, 2 | ls_attachemnt TYPE zcl_zsqrmbwa_mpc_ext=>ts_attachment, 3 | ls_key_tab TYPE zcl_zsqrmbwa_mpc_ext=>ts_attachment. 4 | 5 | lv_entity_name = io_tech_request_context->get_entity_type_name( ). 6 | io_tech_request_context->get_converted_source_keys( IMPORTING es_key_values = ls_key_tab ). 7 | 8 | DATA: lo_gos_api TYPE REF TO cl_gos_api, 9 | lt_role_filter TYPE gos_t_rol, 10 | ls_attcont TYPE gos_s_attcont, 11 | lv_commit TYPE flag, 12 | ls_appl_object TYPE gos_s_obj, 13 | lx_gos_exception TYPE REF TO cx_gos_api. 14 | 15 | FIELD-SYMBOLS: TYPE zcl_zsqrmbwa_dpc_ext=>ty_deep_finding. 16 | 17 | * Get file name and extension 18 | CALL METHOD cl_bcs_utilities=>split_name 19 | EXPORTING 20 | iv_name = iv_slug "iv_slug should have complete file name with extension. Ex:samplefile.docx 21 | iv_delimiter = '.' 22 | IMPORTING 23 | ev_extension = ls_attcont-tech_type. 24 | 25 | ls_appl_object-typeid = 'CL_ABC'. "Class Name or BO Name 26 | ls_appl_object-catid = 'BC'. "BC for Class, BO for SW01 BOs 27 | ls_appl_object-instid = ls_key_tab-finding_id. 28 | 29 | "Instantiate GOS 30 | ls_appl_object-instid = iv_finding_id. 31 | ls_attcont-atta_cat = cl_gos_api=>c_msg. 32 | ls_attcont-content_x = is_media_resource-value. 33 | ls_attcont-filename = iv_slug. 34 | ls_attcont-filesize = xstrlen( iv_data ). "Very important. Without this XLSX and DOCX will have issues when downloaded 35 | 36 | TRY. 37 | lo_gos_api = cl_gos_api=>create_instance( ls_appl_object ). 38 | lo_gos_api->insert_al_item( 39 | EXPORTING 40 | is_attcont = ls_attcont 41 | iv_roltype = cl_gos_api=>c_attachment 42 | RECEIVING 43 | rv_commit = lv_commit 44 | ). 45 | 46 | CATCH cx_gos_api INTO lx_gos_exception. 47 | * error handling 48 | data: lv_error TYPE string. 49 | lv_error = lx_gos_exception->get_text( ). 50 | lv_error = lx_gos_exception->get_longtext( ). 51 | ENDTRY. 52 | 53 | IF lv_commit eq abap_true. 54 | COMMIT WORK. 55 | ENDIF. 56 | 57 | copy_data_to_ref( 58 | EXPORTING 59 | is_data = ls_attachemnt 60 | CHANGING 61 | cr_data = er_entity ). 62 | -------------------------------------------------------------------------------- /Stream/ABAP App Server/download: -------------------------------------------------------------------------------- 1 | METHOD read_attachment. 2 | *"---------------------------------------------------------------------- 3 | * Ticket# Name Date Description 4 | * INC0683404 guptani 06/16/21 Get Attachment Details 5 | *"---------------------------------------------------------------------- 6 | DATA: l_dir TYPE btch0000-text80, 7 | lv_buffer TYPE xstring. 8 | 9 | SELECT SINGLE file_name , file_key 10 | FROM zemt_attachments 11 | INTO ( @DATA(lv_filename) , @DATA(lv_filekey) ) 12 | WHERE attachment_guid = @iv_attid 13 | AND esc_sup_id = @mv_esc_supply_id. 14 | 15 | es_lheader-name = 'Content-Disposition'. 16 | es_lheader-value = 'outline; filename="' && lv_filename && '";'. 17 | 18 | SELECT SINGLE * FROM 19 | tvarvc INTO @DATA(ls_param) 20 | WHERE name = 'ZEMT_FILE_LOC'. 21 | 22 | SELECT SINGLE dirname 23 | FROM user_dir 24 | INTO l_dir 25 | WHERE aliass = ls_param-low. 26 | 27 | SPLIT lv_filename AT '.' INTO DATA(l_name) DATA(l_mimetype). 28 | DATA(lv_folder_name_no_zeros) = |{ mv_esc_supply_id ALPHA = OUT }|. 29 | CONDENSE lv_folder_name_no_zeros. 30 | DATA(p_file) = |{ l_dir }/{ lv_folder_name_no_zeros }/{ lv_filename }|. 31 | 32 | DATA: lv_name TYPE string, 33 | lv_file_key TYPE string, 34 | lv_file_with_key TYPE string. 35 | 36 | lv_name = p_file. 37 | lv_file_key = lv_filekey. 38 | 39 | get_filename_with_filekey( 40 | EXPORTING 41 | iv_file_name = lv_name 42 | iv_file_key = lv_file_key 43 | RECEIVING 44 | rv_file_name_with_key = lv_file_with_key 45 | ). 46 | 47 | OPEN DATASET lv_file_with_key FOR INPUT IN BINARY MODE . 48 | 49 | IF sy-subrc = 0. 50 | DO . 51 | READ DATASET lv_file_with_key INTO lv_buffer. 52 | IF sy-subrc = 0. 53 | CONCATENATE es_stream-value lv_buffer INTO es_stream-value IN BYTE MODE. 54 | ELSE. 55 | EXIT. 56 | ENDIF. 57 | ENDDO. 58 | ELSE. 59 | " Failed to open the file for reading 60 | MESSAGE e079(zemt_supp_message) INTO DATA(lv_message). 61 | RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception 62 | EXPORTING 63 | textid = /iwbep/cx_mgw_busi_exception=>business_error_unlimited 64 | message_unlimited = lv_message. 65 | ENDIF. 66 | 67 | CLOSE DATASET lv_file_with_key. 68 | 69 | ENDMETHOD. 70 | -------------------------------------------------------------------------------- /Stream/GOS/GET_STREAM: -------------------------------------------------------------------------------- 1 | DATA: lv_entity_name TYPE /iwbep/mgw_tech_name, 2 | ls_key_tab TYPE /iwbep/s_mgw_tech_pair, 3 | lt_key_tab TYPE /iwbep/t_mgw_tech_pairs, 4 | ls_header TYPE ihttpnvp, 5 | lv_finding_id TYPE zwm_finding, 6 | ls_stream TYPE /iwbep/if_mgw_core_srv_runtime=>ty_s_media_resource, 7 | lv_atta_key TYPE gos_atta_id, 8 | lv_file_name TYPE bitm_filename. 9 | 10 | lv_entity_name = io_tech_request_context->get_entity_type_name( ). 11 | lt_key_tab = io_tech_request_context->get_keys( ). 12 | READ TABLE lt_key_tab INTO ls_key_tab WITH KEY name = 'FINDINGID'. 13 | IF sy-subrc EQ 0. 14 | lv_finding_id = ls_key_tab-value. 15 | ENDIF. 16 | READ TABLE lt_key_tab INTO ls_key_tab WITH KEY name = 'ID'. 17 | IF sy-subrc EQ 0. 18 | lv_atta_key = ls_key_tab-value. 19 | ENDIF. 20 | 21 | DATA: lo_gos_api TYPE REF TO cl_gos_api, 22 | ls_appl_object TYPE gos_s_obj, 23 | ls_atta_key TYPE gos_s_attkey, 24 | ls_content TYPE gos_s_attcont. 25 | 26 | ls_atta_key-atta_id = lv_atta_key. 27 | ls_atta_key-atta_cat = 'MSG'. 28 | 29 | ls_appl_object-typeid = 'CL_SQRMBWA'. 30 | ls_appl_object-catid = 'BC'. 31 | 32 | "Instantiate GOS 33 | ls_appl_object-instid = lv_finding_id. 34 | TRY. 35 | lo_gos_api = cl_gos_api=>create_instance( ls_appl_object ). 36 | 37 | "Get Attachment Content 38 | CALL METHOD lo_gos_api->get_al_item 39 | EXPORTING 40 | is_atta_key = ls_atta_key 41 | RECEIVING 42 | rs_attcont = ls_content. 43 | 44 | "Attachment Content 45 | ls_stream-value = ls_content-content_x. 46 | 47 | "Calculate mime-type 48 | DATA: lv_mime_type TYPE w3conttype. 49 | CALL FUNCTION 'SDOK_MIMETYPE_GET' 50 | EXPORTING 51 | extension = ls_content-tech_type 52 | IMPORTING 53 | mimetype = lv_mime_type. 54 | 55 | ls_stream-mime_type = lv_mime_type. 56 | lv_file_name = ls_content-filename. 57 | 58 | CATCH cx_gos_api. 59 | * error handling 60 | ENDTRY. 61 | 62 | copy_data_to_ref( EXPORTING is_data = ls_stream 63 | CHANGING cr_data = er_stream ). 64 | 65 | * +++++++++++++++++++++++++++++++++++ 66 | " Download or Preview the pdf ? 67 | *+++++++++++++++++++++++++++++++++++ 68 | ls_header-name = 'Content-Disposition'. 69 | ls_header-value = |outline; filename="{ lv_file_name }";'|. "download 70 | set_header( is_header = ls_header ). 71 | -------------------------------------------------------------------------------- /FioriElements/CDS_DropDownValueHelp: -------------------------------------------------------------------------------- 1 | **************************Start : Main CDS View************************************* 2 | @AbapCatalog.sqlViewName: 'ZWM_VFINDINGS_C' 3 | @AbapCatalog.compiler.compareFilter: true 4 | @AccessControl.authorizationCheck: #CHECK 5 | @EndUserText.label: 'Findings View' 6 | @Search.searchable: true 7 | @OData.publish: true 8 | define view ZWM_FINDINGS_C as select from zwm_findings 9 | association [0..1] to ZWM_SCORE_VH as _scoreVH on $projection.ScoreId = _scoreVH.id 10 | { 11 | .... 12 | .... 13 | @Consumption.valueHelp: '_scoreVH' 14 | score as ScoreId, 15 | _scoreVH 16 | } 17 | 18 | **************************End : Main CDS View************************************* 19 | 20 | **************************Start: Value Help CDS View*************************************** 21 | @AbapCatalog.sqlViewName: 'ZWM_VSCORE_VH' 22 | @AbapCatalog.compiler.compareFilter: true 23 | @AccessControl.authorizationCheck: #CHECK 24 | @EndUserText.label: 'Value Help for Score' 25 | define view ZWM_SCORE_VH as select from zwm_valuehelps { 26 | @EndUserText.label: 'Id' 27 | key object_key as id, 28 | @EndUserText.label: 'Score' 29 | text as Text 30 | } where dropdown_id = '02' 31 | **************************End: Value Help CDS View*************************************** 32 | 33 | METHOD define. "Generated Class Name is ZCL_ 34 | 35 | super->define( ). 36 | 37 | "Set the Property as having 'Fixed Values' (This will provide Dropdown Option) 38 | DATA(lo_txt_property) = model->get_entity_type( 'ZWM_FINDINGS_CType' )->get_property( 'ScoreId' ). 39 | lo_txt_property->set_value_list( /iwbep/if_mgw_odata_property=>gcs_value_list_type_property-fixed_values ). 40 | 41 | "Within the ValueHelp Entity, inform that property 'Text' is the rext of key 'Id'. (Within the Dropdown, this will show both ID and Text) 42 | lo_txt_property = model->get_entity_type( 'ZWM_SCORE_VHType' )->get_property( 'Id' ). 43 | DATA(lo_text_anno) = lo_txt_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( 'sap' ). 44 | lo_text_anno->add( iv_key = 'text' iv_value = 'Text'). 45 | 46 | "Show Calendar as value help 47 | lo_txt_property = model->get_entity_type( 'ZWM_FINDINGS_CType' )->get_property( 'InspectionDate' ). 48 | lo_text_anno = lo_txt_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( 'sap' ). 49 | lo_text_anno->add( iv_key = 'display-format' iv_value = 'Date'). 50 | 51 | "Show Date Range in Value Help 52 | lo_txt_property = model->get_entity_type( 'ZWM_FINDINGS_CType' )->get_property( 'InspectionDate' ). 53 | lo_text_anno = lo_txt_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( 'sap' ). 54 | lo_text_anno->add( iv_key = 'filter-restriction' iv_value = 'interval'). 55 | 56 | ENDMETHOD. "Remember that this class gets overwritten everytime you activate the CDS view 57 | -------------------------------------------------------------------------------- /Stream/GOS/Get_List_of_Attachments: -------------------------------------------------------------------------------- 1 | METHOD get_header_gos_attachments. 2 | 3 | DATA: ls_doc_data TYPE sofolenti1, 4 | ls_docid TYPE sofolenti1-doc_id, 5 | ls_attachment TYPE gbapps_attachments, 6 | lt_links TYPE obl_t_link, 7 | ls_filter TYPE sofilteri1, 8 | ls_links TYPE obl_s_link, 9 | ls_lporb TYPE sibflporb. 10 | 11 | DATA: lv_date TYPE string. 12 | ls_lporb-instid = iv_doc_number. 13 | ls_lporb-catid = 'BO'. 14 | 15 | CASE iv_doc_type. 16 | WHEN if_gbapp_apv_constants=>cc_application_type_po. 17 | ls_lporb-typeid = 'BUS2012'. 18 | WHEN if_gbapp_apv_constants=>cc_application_type_pr. 19 | ls_lporb-typeid = 'BUS2105'. 20 | WHEN OTHERS. 21 | EXIT. 22 | ENDCASE. 23 | 24 | TRY . 25 | CALL METHOD cl_binary_relation=>read_links_of_binrel 26 | EXPORTING 27 | is_object = ls_lporb 28 | ip_relation = 'ATTA' 29 | ip_role = 'GOSAPPLOBJ' 30 | IMPORTING 31 | et_links = lt_links. 32 | 33 | CATCH cx_obl_parameter_error . "#EC NO_HANDLER 34 | CATCH cx_obl_internal_error . "#EC NO_HANDLER 35 | CATCH cx_obl_model_error . "#EC NO_HANDLER 36 | ENDTRY. 37 | 38 | ls_filter-send_info = 'X'. 39 | ls_filter-no_content = 'X'. 40 | 41 | LOOP AT lt_links INTO ls_links. 42 | 43 | CLEAR : ls_docid, ls_doc_data, ls_attachment. 44 | 45 | ls_docid = ls_links-instid_b. 46 | 47 | CALL FUNCTION 'SO_DOCUMENT_READ_API1' 48 | EXPORTING 49 | document_id = ls_docid 50 | filter = ls_filter 51 | IMPORTING 52 | document_data = ls_doc_data 53 | EXCEPTIONS 54 | document_id_not_exist = 1 55 | operation_no_authorization = 2 56 | x_error = 3 57 | OTHERS = 4. 58 | IF sy-subrc EQ 0. 59 | 60 | ls_attachment-object_id = iv_doc_number. 61 | ls_attachment-attach_guid = ls_docid. 62 | ls_attachment-description = ls_doc_data-obj_descr. 63 | 64 | SET LOCALE LANGUAGE sy-langu. 65 | ls_attachment-file_name = ls_doc_data-obj_descr. 66 | * CONCATENATE ls_attachment-file_name '.' ls_doc_data-obj_type INTO ls_attachment-file_name. 67 | ls_attachment-created_by_id = ls_doc_data-creat_name. 68 | ls_attachment-created_by_name = ls_doc_data-creat_fnam. 69 | CONCATENATE ls_doc_data-creat_date ls_doc_data-creat_time INTO lv_date. 70 | ls_attachment-created_at = lv_date. 71 | ls_attachment-is_gos_attachment = abap_true. 72 | ls_attachment-file_size = ls_doc_data-doc_size. 73 | SHIFT ls_attachment-file_size LEFT DELETING LEADING '0'. 74 | 75 | * compute mimetype 76 | DATA: lv_file_name TYPE skwf_filnm. 77 | lv_file_name = ls_attachment-file_name. 78 | CALL FUNCTION 'SKWF_MIMETYPE_OF_FILE_GET' 79 | EXPORTING 80 | filename = lv_file_name 81 | IMPORTING 82 | mimetype = ls_attachment-mime_type. 83 | 84 | APPEND ls_attachment TO et_attachments. 85 | ENDIF. 86 | ENDLOOP. 87 | 88 | ENDMETHOD. 89 | -------------------------------------------------------------------------------- /Stream/GetStream from SmartForm: -------------------------------------------------------------------------------- 1 | DATA: lt_keys TYPE /iwbep/t_mgw_tech_pairs, 2 | ls_stream TYPE ty_s_media_resource, 3 | ls_key TYPE /iwbep/s_mgw_tech_pair. 4 | 5 | * Get keys for the document 6 | lt_keys = io_tech_request_context->get_keys( ). 7 | READ TABLE lt_keys WITH KEY name = 'ORDERID' INTO ls_key. 8 | IF sy-subrc EQ 0. 9 | lv_customer = ls_key-value. 10 | ENDIF. 11 | 12 | * Get device type from language 13 | CALL FUNCTION 'SSF_GET_DEVICE_TYPE' 14 | EXPORTING 15 | i_language = sy-langu 16 | * i_application = 'SAPDEFAULT' 17 | IMPORTING 18 | e_devtype = lv_devtype 19 | EXCEPTIONS 20 | no_language = 1 21 | language_not_installed = 2 22 | no_devtype_found = 3 23 | system_error = 4 24 | OTHERS = 5. 25 | 26 | * Get Smartform's FM Name 27 | CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' 28 | EXPORTING 29 | formname = 'ZSMART_FORM_NAME' "Smartform name 30 | * formname = formname 31 | IMPORTING 32 | fm_name = lv_fm_name 33 | EXCEPTIONS 34 | no_form = 1 35 | no_function_module = 2 36 | OTHERS = 3. 37 | 38 | * Set device type in output options 39 | ls_output_options-tdprinter = lv_devtype. 40 | * Set relevant output options 41 | ls_output_options-tdnewid = 'X'. "Print parameters, 42 | ls_output_options-tddelete = space. "Print parameters 43 | 44 | * set control parameters to get the output text format (OTF) from Smart Forms 45 | ls_control_parameters-langu = sy-langu. 46 | TRANSLATE ls_control_parameters-langu TO UPPER CASE. 47 | ls_control_parameters-no_dialog = 'X'. 48 | ls_control_parameters-getotf = 'X'. 49 | ls_control_parameters-preview = space. "No preview 50 | 51 | * Call Smartform generated FM 52 | CALL FUNCTION lv_fm_name 53 | EXPORTING 54 | control_parameters = ls_control_parameters 55 | output_options = ls_output_options 56 | user_settings = space 57 | customer = ls_customer 58 | bookings = lt_bookings 59 | connections = lt_connections 60 | IMPORTING 61 | job_output_info = ls_output_data 62 | EXCEPTIONS 63 | formatting_error = 1 64 | internal_error = 2 65 | send_error = 3 66 | user_canceled = 4 67 | OTHERS = 5. 68 | 69 | APPEND LINES OF ls_output_data-otfdata[] TO lt_tstotf[]. 70 | 71 | * Convert OTF to PDF 72 | CALL FUNCTION 'CONVERT_OTF' 73 | EXPORTING 74 | format = 'PDF' 75 | IMPORTING 76 | bin_filesize = lv_pdf_len 77 | bin_file = lv_pdf_xstring " binary file 78 | TABLES 79 | otf = lt_tstotf 80 | lines = lt_lines 81 | EXCEPTIONS 82 | err_max_linewidth = 1 83 | err_format = 2 84 | err_conv_not_possible = 3 85 | err_bad_otf = 4 86 | OTHERS = 5. 87 | IF sy-subrc = 0. 88 | ls_stream-value = lv_pdf_xstring. 89 | ENDIF. 90 | "Mime type 91 | ls_stream-mime_type = 'application/pdf'. 92 | 93 | copy_data_to_ref( EXPORTING is_data = ls_stream 94 | CHANGING cr_data = er_stream ). 95 | 96 | 97 | +++++++++++++++++++++++++++++++++++ 98 | " Download or Preview the pdf ? 99 | +++++++++++++++++++++++++++++++++++ 100 | DATA ls_lheader TYPE ihttpnvp. 101 | ls_lheader–name = ‘Content-Disposition’. 102 | ls_lheader–value = ‘outline; filename=”Mobile.pdf”;’. //Download 103 | ls_lheader–value = ‘inline; filename=”Mobile.pdf”;’. //Preview 104 | set_header( is_header = ls_lheader ). 105 | -------------------------------------------------------------------------------- /Changeset_Process: -------------------------------------------------------------------------------- 1 | METHOD /iwbep/if_mgw_appl_srv_runtime~changeset_process. 2 | 3 | DATA: ls_changeset_request TYPE /iwbep/if_mgw_appl_types=>ty_s_changeset_request, 4 | ls_changeset_response TYPE /iwbep/if_mgw_appl_types=>ty_s_changeset_response, 5 | lo_request_context_d TYPE REF TO /iwbep/if_mgw_req_entity_d, 6 | lo_request_context_merge TYPE REF TO /iwbep/if_mgw_req_entity_p, 7 | lt_components TYPE /iwbep/if_mgw_appl_types=>ty_t_components, 8 | ls_component TYPE /iwbep/if_mgw_appl_types=>ty_s_component, 9 | lt_group_request TYPE /iwbep/if_mgw_appl_types=>ty_t_changeset_request, 10 | lv_entity_name TYPE /iwbep/mgw_tech_name, 11 | lo_request_context TYPE REF TO /iwbep/if_mgw_req_entity_c, 12 | lt_keys TYPE /iwbep/t_mgw_tech_pairs, 13 | ls_key TYPE /iwbep/s_mgw_tech_pair. 14 | 15 | * List of operations 16 | LOOP AT it_changeset_request INTO ls_changeset_request. 17 | 18 | " Operation Number in current changeset 19 | ls_changeset_response-operation_no = ls_changeset_request-operation_no. 20 | 21 | "Read Entity Name 22 | lo_request_context ?= ls_changeset_request-request_context. 23 | lv_entity_name = lo_request_context->get_entity_type_name( ). 24 | 25 | CASE lv_entity_name. 26 | WHEN 'EntityOne'. 27 | 28 | IF ls_changeset_request-operation_type = 'CD' "Create Deep 29 | OR ls_changeset_request-operation_type = 'CE' "Create 30 | OR ls_changeset_request-operation_type = 'PE' "MERGE 31 | "Read changeset data (for POST/PUT) 32 | ls_changeset_request-entry_provider->read_entry_data( IMPORTING es_data = ls_requirement ). 33 | ENDIF. 34 | 35 | "Read keys for (DELETE/PUT) 36 | IF ls_changeset_request-operation_type = 'DE' "Delete Items. 37 | OR ls_changeset_request-operation_type = 'PE'. "MERGE 38 | lo_request_context_d ?= ls_changeset_request-request_context. 39 | lt_keys = lo_request_context_d->get_keys( ). 40 | READ TABLE lt_keys INTO ls_key WITH KEY name = 'ORDERNUMBER'. 41 | IF sy-subrc EQ 0. 42 | "ls_operation-ordernumber = ls_key-value. 43 | ENDIF. 44 | ENDIF. 45 | 46 | IF ls_changeset_request-operation_type = 'PE' "MERGE 47 | "Read Components for MERGE 48 | lo_request_context_merge ?= ls_changeset_request-request_context. 49 | lt_components = lo_request_context_merge->get_components( ). 50 | 51 | READ TABLE lt_components WITH KEY property = 'DRAFT' TRANSPORTING NO FIELDS. 52 | IF sy-subrc EQ 0. 53 | "Field was updated. Do the needful. 54 | ENDIF. 55 | ENDIF. 56 | 57 | "CD Create Deep Entity 58 | "CE Create Entity 59 | "CM Create Steram 60 | "DE Delete Entity 61 | "DM Delete Stream 62 | "EA Execute Action 63 | "XE Expand Entity 64 | "XS Expand Entity Set 65 | "GE Get Entity 66 | "GS Get Entity Set 67 | "GD Get Entity Set Delta 68 | "GM Get Steram 69 | "PE Patch Entity 70 | "UE Update Entity 71 | "UM Update Stream 72 | "HB Changeset Begin 73 | "HE Changeset End 74 | "HP Changeset Process 75 | "IC Get Is Conditional Implemented 76 | 77 | 78 | " Set response data 79 | copy_data_to_ref( 80 | EXPORTING 81 | is_data = ls_requirement 82 | CHANGING 83 | cr_data = ls_changeset_response-entity_data ). 84 | 85 | INSERT ls_changeset_response INTO TABLE ct_changeset_response. 86 | 87 | "Collect data here to be used after ENDLOOP. 88 | 89 | CLEAR: ls_changeset_response. 90 | WHEN OTHERS. 91 | ENDCASE. 92 | ENDLOOP. 93 | 94 | ENDMETHOD. 95 | -------------------------------------------------------------------------------- /Query: -------------------------------------------------------------------------------- 1 | 2 | *Get Filters 3 | DATA: lt_filter_select_options TYPE /iwbep/t_mgw_select_option, 4 | ls_filter TYPE /iwbep/s_mgw_select_option, 5 | ls_select_option TYPE /iwbep/s_cod_select_option. 6 | 7 | lt_filter_select_options = io_tech_request_context->get_filter( )->get_filter_select_options( ). 8 | "Replace 'PLANT' with suitable property name (all capitals) 9 | READ TABLE lt_filter_select_options INTO ls_filter WITH KEY property = 'PLANT'. 10 | IF sy-subrc EQ 0. 11 | READ TABLE ls_filter-select_options INTO ls_select_option INDEX 1. 12 | lv_plant = ls_select_option-low. 13 | ENDIF. 14 | 15 | * Get $Select 16 | DATA: lt_select_table TYPE string_table, 17 | lv_property_selected type string. 18 | lt_select_table = io_tech_request_context->get_select( ). 19 | 20 | LOOP AT lt_select_table INTO DATA(lv_select). 21 | IF lv_property_selected IS INITIAL. 22 | lv_property_selected = lv_select. 23 | ELSE. 24 | lv_property_selected = |{ lv_property_selected }, { lv_select }|. 25 | ENDIF. 26 | ENDLOOP. 27 | 28 | IF lv_property_selected IS INITIAL. 29 | lv_property_selected = '*'. 30 | ENDIF. 31 | 32 | *Get Open SQL WHERE Clause from $filter 33 | DATA: lv_osql_where_clause TYPE string. 34 | lv_osql_where_clause = io_tech_request_context->get_osql_where_clause( ). 35 | 36 | *Get Source Keys. If query is through Navigation 37 | DATA: lt_parent_keys TYPE /iwbep/t_mgw_tech_pairs, 38 | ls_parent_key TYPE /iwbep/s_mgw_tech_pair. 39 | "Get Parent entity name 40 | IF io_tech_request_context->get_source_entity_type_name( ) = 'Material'. 41 | "get parent keys 42 | lt_parent_keys = io_tech_request_context->get_source_keys( ). 43 | READ TABLE lt_parent_keys INTO ls_parent_key WITH KEY name = 'MATERIALNUMBER'. 44 | IF sy-subrc EQ 0. 45 | lv_material_number = ls_parent_key-value. 46 | ENDIF. 47 | ENDIF. 48 | 49 | *Get Converted Source Keys 50 | DATA: ls_ls_ TYPE zcl_zsqrmbwa_mpc=>ts_. 51 | io_tech_request_context->get_converted_source_keys( IMPORTING es_key_values = ls_ ). 52 | 53 | *Get Open search string 54 | DATA: lv_search_string TYPE string, 55 | ltr_vendor_name TYPE RANGE OF name1_gp, 56 | lsr_vendor_name LIKE LINE OF ltr_vendor_name. 57 | lv_search_string = io_tech_request_context->get_search_string( ). 58 | "Create a range table to be used in a SELECT statement. Replace 'Vendor' above 59 | IF lv_search_string IS NOT INITIAL. 60 | CONCATENATE '*' lv_search_string '*' INTO lsr_vendor_name-low. 61 | lsr_vendor_name-option = 'CP'. 62 | lsr_vendor_name-sign = 'I'. 63 | APPEND lsr_vendor_name TO ltr_vendor_name. 64 | ENDIF. 65 | 66 | *Top&Skip 67 | DATA: lv_top TYPE i, 68 | lv_skip TYPE i, 69 | lv_total TYPE i, 70 | lv_start_from TYPE i. 71 | 72 | lv_top = io_tech_request_context->get_top( ). 73 | IF lv_top EQ 0. 74 | lv_top = 100. "If $top was not sent, send maximum 100 rows 75 | ENDIF. 76 | lv_skip = io_tech_request_context->get_skip( ). 77 | lv_total = lv_top + lv_skip. 78 | lv_start_from = lv_skip + 1. 79 | "Remove rows to be skipped 80 | IF lv_skip GT 0. 81 | DELETE lt_customers FROM 1 TO lv_skip. 82 | ENDIF. 83 | 84 | " Your SQL Statement goes here 85 | SELECT (lv_property_selected) 86 | FROM 87 | UP TO @lv_total ROWS 88 | INTO CORRESPONDING FIELDS OF TABLE @et_entityset 89 | WHERE (lv_osql_where_clause). 90 | 91 | *Orderby 92 | DATA: lt_order TYPE /iwbep/t_mgw_tech_order, 93 | ls_order LIKE LINE OF lt_order, 94 | lt_otab TYPE abap_sortorder_tab, 95 | ls_otab TYPE abap_sortorder. 96 | 97 | lt_order = io_tech_request_context->get_orderby( ). 98 | IF lt_order IS NOT INITIAL. 99 | LOOP AT lt_order INTO ls_order. 100 | ls_otab-name = ls_order-property. 101 | IF ls_order-order = 'desc'. 102 | ls_otab-descending = abap_true. 103 | ELSE. 104 | ls_otab-descending = abap_false. 105 | ENDIF. 106 | APPEND ls_otab TO lt_otab. 107 | ENDLOOP. 108 | SORT et_entityset BY (lt_otab). 109 | ENDIF. 110 | 111 | * Inline count 112 | IF io_tech_request_context->has_inlinecount( ) = abap_true. 113 | SELECT COUNT(*) FROM WHERE (lv_where_clause). 114 | es_response_context-inlinecount = sy-dbcnt. 115 | ELSE. 116 | CLEAR es_response_context-inlinecount. 117 | ENDIF. 118 | -------------------------------------------------------------------------------- /Stream/CreateStream: -------------------------------------------------------------------------------- 1 | METHOD /iwbep/if_mgw_appl_srv_runtime~create_stream. 2 | 3 | DATA: ls_fol_id TYPE soodk, 4 | ls_obj_data TYPE sood1, 5 | ls_attachemnt TYPE =>ts_attachment, "Of the Atatchemnt entity type 6 | lt_file_solix TYPE TABLE OF solix, 7 | ls_obj_data_api TYPE sodocchgi1, 8 | ls_doc_info TYPE sofolenti1, 9 | ls_content TYPE soli, 10 | lt_header TYPE STANDARD TABLE OF soli, 11 | lv_filename TYPE string. "file name and ext 12 | 13 | DATA: lv_entity_name TYPE /iwbep/mgw_tech_name, 14 | ls_attachemnt TYPE =>ts_attachment, 15 | ls_key_tab TYPE =>ts_attachment. 16 | 17 | lv_entity_name = io_tech_request_context->get_entity_type_name( ). 18 | // Business document key 19 | io_tech_request_context->get_converted_source_keys( IMPORTING es_key_values = ls_key_tab ). 20 | 21 | " The temporary location of the document to be uploaded 22 | CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET' 23 | EXPORTING 24 | region = 'B' " No authorization for Q : doucble check this 25 | IMPORTING 26 | folder_id = ls_fol_id 27 | EXCEPTIONS 28 | OTHERS = 1. 29 | 30 | IF sy-subrc NE 0. 31 | "Raise exception 32 | RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception 33 | EXPORTING 34 | textid = /iwbep/cx_mgw_busi_exception=>business_error_unlimited 35 | message_unlimited = 'File upload failed'. 36 | ENDIF. 37 | 38 | " Convert into solix/Binary table 39 | lt_file_solix = cl_bcs_convert=>xstring_to_solix( iv_xstring = is_media_resource-value ). 40 | 41 | ls_obj_data_api-obj_name = 'INFORMATION'. "par défaut 42 | ls_obj_data_api-obj_langu = sy-langu. 43 | 44 | * Get file name and extension 45 | CALL METHOD cl_bcs_utilities=>split_name 46 | EXPORTING 47 | iv_name = iv_slug "iv_slug should have complete file name with extension. Ex:samplefile.docx 48 | iv_delimiter = '.' 49 | IMPORTING 50 | ev_extension = ls_obj_data-file_ext. 51 | 52 | "File name in input as File description 53 | ls_obj_data_api-obj_descr = iv_slug. 54 | 55 | * Object header 56 | CLEAR ls_content. 57 | CONCATENATE '&SO_FILENAME=' iv_slug INTO ls_content. 58 | APPEND ls_content TO lt_header. 59 | 60 | "Very important step. This length will be used when the stream is read to cut till this length 61 | ls_obj_data_api-doc_size = xstrlen( is_media_resource-value ). 62 | 63 | "Creating file 64 | CALL FUNCTION 'SO_DOCUMENT_INSERT_API1' 65 | EXPORTING 66 | folder_id = ls_fol_id 67 | document_data = ls_obj_data_api 68 | document_type = ls_obj_data-file_ext 69 | IMPORTING 70 | document_info = ls_doc_info 71 | TABLES 72 | contents_hex = lt_file_solix 73 | object_header = lt_header 74 | EXCEPTIONS 75 | folder_not_exist = 1 76 | document_type_not_exist = 2 77 | operation_no_authorization = 3 78 | parameter_error = 4 79 | x_error = 5 80 | enqueue_error = 6 81 | OTHERS = 7. 82 | 83 | IF sy-subrc EQ 0. 84 | "File will be uploaded and this document ID is given back to the UI. 85 | "Right now the document is not associated with the Business object (ex: sales Order). 86 | "This method is getting called when a file is uploded, but the business object is yet to be created. 87 | "UI will send this ID along with Business object creation call, so that they can be associated. 88 | "If the business object is already present, (say updating a sales order), then this document ID will be 89 | "associated with the Bsuiness object right away. 90 | 91 | "Associate the uploaded file to the PR 92 | ls_object-objkey = ls_key_tab-doc_number. 93 | ls_object-objtype = 'BUS2105'. "Purchase Requisition 94 | 95 | ls_document-objtype = 'MESSAGE'. 96 | ls_document-objkey = ls_doc_info-doc_id. 97 | 98 | CALL FUNCTION 'BINARY_RELATION_CREATE_COMMIT' 99 | EXPORTING 100 | obj_rolea = ls_object 101 | obj_roleb = ls_document 102 | relationtype = 'ATTA' 103 | EXCEPTIONS ##FM_SUBRC_OK 104 | no_model = 1 105 | internal_error = 2 106 | unknown = 3 107 | OTHERS = 4. 108 | 109 | es_attachment-prnumber = ls_key_tab-doc_number. 110 | es_attachment-id = ls_doc_info-doc_id. 111 | es_attachment-createdby = ls_doc_info-creat_name. 112 | es_attachment-createdbyname = ls_doc_info-creat_fnam. 113 | es_attachment-filename = iv_slug. 114 | 115 | CONVERT DATE ls_doc_info-creat_date TIME ls_doc_info-creat_time 116 | INTO TIME STAMP es_attachment-createdat TIME ZONE sy-zonlo. 117 | 118 | es_attachment-mime_type = is_media_resource-mime_type. 119 | es_attachment-filesize = ls_doc_info-doc_size. 120 | es_attachment-filedescription = ls_doc_info-obj_descr. 121 | 122 | copy_data_to_ref( 123 | EXPORTING 124 | is_data = es_attachment 125 | CHANGING 126 | cr_data = er_entity ). 127 | 128 | ELSE. 129 | "Raise exception 130 | RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception 131 | EXPORTING 132 | textid = /iwbep/cx_mgw_busi_exception=>business_error_unlimited 133 | message_unlimited = 'File upload failed'. 134 | 135 | ENDIF. 136 | 137 | ENDMETHOD. 138 | -------------------------------------------------------------------------------- /Stream/GetStream: -------------------------------------------------------------------------------- 1 | TYPES: 2 | BEGIN OF ty_s_media_resource. 3 | INCLUDE TYPE /iwbep/if_mgw_core_srv_runtime=>ty_s_media_resource. 4 | TYPES: 5 | END OF ty_s_media_resource . 6 | 7 | DATA: lv_entity_name TYPE /iwbep/mgw_tech_name, 8 | ls_key_tab TYPE /iwbep/s_mgw_tech_pair, 9 | lt_key_tab TYPE /iwbep/t_mgw_tech_pairs, 10 | ls_stream TYPE ty_s_media_resource, 11 | ls_obj_hd TYPE sood2, 12 | lt_objhead TYPE STANDARD TABLE OF soli, 13 | ls_objhead TYPE soli, 14 | ls_header TYPE ihttpnvp. 15 | 16 | lv_entity_name = io_tech_request_context->get_entity_type_name( ). 17 | lt_key_tab = io_tech_request_context->get_keys( ). 18 | 19 | *----------------------------- 20 | Reading GOS attachemnt details 21 | *----------------------------- 22 | 23 | * buseinss object key 24 | DATA: gs_lpor TYPE sibflporb. 25 | * 26 | gs_lpor-instid = p_matnr. <> 27 | gs_lpor-typeid = 'BUS1001006'. <> 28 | gs_lpor-catid = 'BO'. 29 | * 30 | * attachment type selection 31 | DATA: lt_relat TYPE obl_t_relt, 32 | la_relat LIKE LINE OF lt_relat. 33 | * 34 | la_relat-sign = 'I'. 35 | la_relat-option = 'EQ'. 36 | la_relat-low = 'NOTE'. "For notes 'ATTA' for attachemnts 37 | APPEND la_relat TO lt_relat. 38 | * 39 | * Read the links 40 | DATA: t_links TYPE obl_t_link, 41 | la_links LIKE LINE OF t_links. 42 | * 43 | DATA: lo_root TYPE REF TO cx_root. 44 | * 45 | TRY. 46 | CALL METHOD cl_binary_relation=>read_links 47 | EXPORTING 48 | is_object = gs_lpor 49 | it_relation_options = lt_relat 50 | IMPORTING 51 | et_links = t_links. 52 | CATCH cx_root INTO lo_root. 53 | ENDTRY. 54 | 55 | *--------- 56 | * Read NOTE contents 57 | *--------- 58 | DATA l_folder_id TYPE soodk. 59 | DATA l_object_id TYPE soodk. 60 | DATA document_id TYPE sofmk. 61 | * 62 | * Get document id 63 | READ TABLE t_links INTO la_links INDEX 1. 64 | * 65 | document_id = la_links-instid_b. 66 | * 67 | * Set folder 68 | l_folder_id-objtp = document_id-foltp. 69 | l_folder_id-objyr = document_id-folyr. 70 | l_folder_id-objno = document_id-folno. 71 | * 72 | * Set Object 73 | l_object_id-objtp = document_id-doctp. 74 | l_object_id-objyr = document_id-docyr. 75 | l_object_id-objno = document_id-docno. 76 | * 77 | * Read the document content 78 | DATA document_content TYPE STANDARD TABLE OF soli. 79 | * 80 | CALL FUNCTION 'SO_OBJECT_READ' 81 | EXPORTING 82 | folder_id = l_folder_id 83 | object_id = l_object_id 84 | IMPORTING 85 | object_hd_display = ls_obj_hd 86 | TABLES 87 | objcont = document_content 88 | objhead = lt_objhead 89 | EXCEPTIONS 90 | active_user_not_exist = 1 91 | communication_failure = 2 92 | component_not_available = 3 93 | folder_not_exist = 4 94 | folder_no_authorization = 5 95 | object_not_exist = 6 96 | object_no_authorization = 7 97 | operation_no_authorization = 8 98 | owner_not_exist = 9 99 | parameter_error = 10 100 | substitute_not_active = 11 101 | substitute_not_defined = 12 102 | system_failure = 13 103 | x_error = 14 104 | OTHERS = 15. 105 | IF sy-subrc NE 0. 106 | MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 107 | WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 108 | ENDIF. 109 | 110 | ----------------------------------------------------------------- 111 | * build ev_mime_type and ev_file_name 112 | * ----------------------------------------------------------------- 113 | LOOP AT lt_objhead INTO ls_objhead 114 | WHERE table_line CP '&SO_FILENAME=*'. 115 | SPLIT ls_objhead AT '.' INTO TABLE lt_split. 116 | IF sy-subrc IS INITIAL.. 117 | lv_lines = lines( lt_split ). 118 | IF lv_lines <> 0. 119 | READ TABLE lt_split INTO ls_extension INDEX lv_lines. 120 | lv_extension = ls_extension. 121 | IF lv_extension <> ls_obj_hd-file_ext. 122 | SELECT SINGLE type INTO lv_mime_type FROM sdokmime_c 123 | WHERE extension = lv_extension. 124 | IF sy-subrc <> 0. 125 | SELECT SINGLE type INTO lv_mime_type FROM sdokmime 126 | WHERE extension = lv_extension. 127 | ENDIF. 128 | ENDIF. 129 | ENDIF. 130 | ENDIF. 131 | CLEAR: lt_split. 132 | SPLIT ls_objhead AT '=' INTO TABLE lt_split. 133 | lv_lines = lines( lt_split ). 134 | IF lv_lines <> 0. 135 | READ TABLE lt_split INTO ls_filename INDEX lv_lines. 136 | lv_file_name = ls_filename. 137 | ENDIF. 138 | EXIT. 139 | ENDLOOP. 140 | 141 | IF lv_file_name IS INITIAL. 142 | CONCATENATE ls_obj_hd-objdes ls_obj_hd-file_ext INTO lv_file_name SEPARATED BY '.'. 143 | ENDIF. 144 | 145 | * common processing, calculate mime-type 146 | CALL FUNCTION 'SDOK_MIMETYPE_GET' 147 | EXPORTING 148 | extension = ls_doc_data-obj_type 149 | IMPORTING 150 | mimetype = lv_mime_type. 151 | 152 | 153 | ls_stream-mime_type = lv_mime_type. 154 | ls_stream-value = lv_stream. 155 | 156 | copy_data_to_ref( EXPORTING is_data = ls_stream 157 | CHANGING cr_data = er_stream ). 158 | 159 | +++++++++++++++++++++++++++++++++++ 160 | " Download or Preview the pdf ? 161 | +++++++++++++++++++++++++++++++++++ 162 | DATA ls_lheader TYPE ihttpnvp. 163 | ls_lheader–name = ‘Content-Disposition’. 164 | ls_lheader–value = ‘outline; filename=”Mobile.pdf”;’. //Download 165 | ls_lheader–value = ‘inline; filename=”Mobile.pdf”;’. //Preview 166 | set_header( is_header = ls_lheader ). 167 | -------------------------------------------------------------------------------- /Stream/ABAP App Server/Upload: -------------------------------------------------------------------------------- 1 | METHOD add_attachment. 2 | *"---------------------------------------------------------------------- 3 | * Ticket# Name Date Description 4 | * INC0683404 guptani 06/16/21 Add Attachments to Esc Supply 5 | *"---------------------------------------------------------------------- 6 | TYPES : BEGIN OF ty_binary, 7 | line TYPE so_text255, 8 | END OF ty_binary. 9 | 10 | DATA: l_dir TYPE btch0000-text80, 11 | ls_attachments TYPE zemt_attachments, 12 | p_file(128), 13 | lv_binary_size TYPE i, 14 | lv_doc_size TYPE i, 15 | lt_binary_content TYPE STANDARD TABLE OF ty_binary, 16 | wl_binary_content TYPE ty_binary, 17 | lv_filename TYPE string, 18 | lv_internal TYPE string, 19 | lv_categoryid TYPE string, 20 | gv_add_par TYPE sxpgcolist-parameters, 21 | ls_return TYPE bapiret2. 22 | 23 | "Update escalations only when it is not cancelled or closed 24 | esc_update_not_allowed( ). 25 | 26 | "Inserting Metadata 27 | TRY. 28 | DATA(lv_attach_id) = NEW cl_system_uuid( )->if_system_uuid~create_uuid_c32( ). 29 | CATCH cx_uuid_error INTO DATA(lx_exception). 30 | ENDTRY. 31 | ls_attach-attachmentid = ls_attachments-attachment_guid = lv_attach_id. 32 | ls_attach-supplyid = ls_attachments-esc_sup_id = mv_esc_supply_id. 33 | ls_attachments-createdby = sy-uname. 34 | 35 | ls_attachments-createdtimestamp = mv_timestamp. 36 | 37 | ls_attachments-mandt = sy-mandt. 38 | 39 | "Inserting Metadata for EMT 40 | IF iv_sup_portal_username IS NOT SUPPLIED AND iv_sup_con_name IS NOT SUPPLIED. 41 | SPLIT iv_slug AT '|' INTO lv_filename lv_internal lv_categoryid. 42 | ls_attach-filename = ls_attachments-file_name = lv_filename. 43 | ls_attach-internal = ls_attachments-internal = lv_internal. 44 | ls_attach-categoryid = ls_attachments-category = lv_categoryid. 45 | ls_attach-uploadedbyid = ls_attachments-createdby = sy-uname. 46 | ls_attachments-supplier_authored = ' '. 47 | ls_attachments-file_key = mv_timestamp. 48 | SELECT SINGLE username FROM zcv_emt_req INTO ls_attach-uploadedby WHERE userid = sy-uname. 49 | 50 | ls_attach-uploadedon = ls_attachments-createdtimestamp . 51 | "Inserting Metadata for Supplier 52 | ELSE. 53 | ls_attachments-file_name = iv_slug. 54 | ls_attachments-supplier_name = iv_sup_con_name. 55 | ls_attachments-supplier_technical_id = iv_sup_portal_username. 56 | ls_attachments-file_key = iv_file_key. 57 | ls_attachments-supplier_authored = abap_true. 58 | ls_attachments-category = iv_category. 59 | ENDIF. 60 | "Handling internal flag for supplier portal and emt tool 61 | ls_attachments-internal = lv_internal. 62 | 63 | "External comments by LAM are allowed only if the escalation was ever sent to Supplier earlier 64 | IF lv_internal = ''. 65 | check_ext_com_att_allowed( ). 66 | ENDIF. 67 | 68 | IF is_media_resource-value IS NOT INITIAL. 69 | 70 | CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' 71 | EXPORTING 72 | buffer = is_media_resource-value 73 | IMPORTING 74 | output_length = lv_binary_size 75 | TABLES 76 | binary_tab = lt_binary_content. 77 | 78 | lv_doc_size = lv_binary_size. 79 | ls_attachments-file_size = lv_binary_size. 80 | 81 | ENDIF. 82 | 83 | " Add to attachment metadata table 84 | INSERT zemt_attachments FROM ls_attachments. 85 | IF sy-subrc IS NOT INITIAL. 86 | MESSAGE e005(zemt_supp_message) INTO ls_return-message. 87 | ls_return-type = 'E'. 88 | ls_return-field = '03'. 89 | APPEND ls_return TO et_return. 90 | EXIT. 91 | ELSE. 92 | ev_attach_key = lv_attach_id. 93 | ENDIF. 94 | 95 | "Uploading File for EMT 96 | IF iv_sup_portal_username IS NOT SUPPLIED AND iv_sup_con_name IS NOT SUPPLIED. 97 | SELECT SINGLE * FROM 98 | tvarvc INTO @DATA(ls_param) 99 | WHERE name = 'ZEMT_FILE_LOC'. 100 | IF sy-subrc IS NOT INITIAL. 101 | MESSAGE e008(zemt_supp_message) INTO ls_return-message. 102 | ls_return-type = 'E'. 103 | APPEND ls_return TO et_return. 104 | EXIT. 105 | ENDIF. 106 | SELECT SINGLE dirname 107 | FROM user_dir 108 | INTO l_dir 109 | WHERE aliass = ls_param-low. 110 | IF sy-subrc IS NOT INITIAL. 111 | MESSAGE e009(zemt_supp_message) INTO ls_return-message. 112 | ls_return-type = 'E'. 113 | APPEND ls_return TO et_return. 114 | EXIT. 115 | ENDIF. 116 | 117 | "No leading zeroes in folder name 118 | DATA(lv_folder_name_no_zeros) = |{ mv_esc_supply_id ALPHA = OUT }|. 119 | gv_add_par = |{ l_dir }/{ lv_folder_name_no_zeros }|. 120 | 121 | CALL FUNCTION 'SXPG_COMMAND_EXECUTE' 122 | EXPORTING 123 | commandname = 'ZMKDIR' 124 | additional_parameters = gv_add_par 125 | EXCEPTIONS 126 | no_permission = 1 127 | command_not_found = 2 128 | parameters_too_long = 3 129 | security_risk = 4 130 | wrong_check_call_interface = 5 131 | program_start_error = 6 132 | program_termination_error = 7 133 | x_error = 8 134 | parameter_expected = 9 135 | too_many_parameters = 10 136 | illegal_command = 11 137 | wrong_asynchronous_parameters = 12 138 | cant_enq_tbtco_entry = 13 139 | jobcount_generation_error = 14 140 | OTHERS = 15. 141 | IF sy-subrc <> 0. 142 | MESSAGE e047(zemt_supp_message) INTO ls_return-message. 143 | ls_return-type = 'E'. 144 | APPEND ls_return TO et_return. 145 | EXIT. 146 | ELSE. 147 | CONCATENATE gv_add_par lv_filename INTO p_file SEPARATED BY '/'. 148 | "Add file key 149 | DATA: lv_name TYPE string, 150 | lv_file_with_key TYPE string, 151 | lv_file_key TYPE string, 152 | lv_length TYPE i VALUE 510, 153 | lv_table_length TYPE i, 154 | lv_last_line_length TYPE i. 155 | 156 | lv_name = p_file. 157 | lv_file_key = ls_attachments-file_key. 158 | 159 | get_filename_with_filekey( 160 | EXPORTING 161 | iv_file_name = lv_name 162 | iv_file_key = lv_file_key 163 | RECEIVING 164 | rv_file_name_with_key = lv_file_with_key 165 | ). 166 | 167 | OPEN DATASET lv_file_with_key FOR OUTPUT IN BINARY MODE. 168 | 169 | lv_table_length = lines( lt_binary_content ). 170 | lv_last_line_length = lv_binary_size - ( ( lv_table_length - 1 ) * 510 ). 171 | 172 | IF sy-subrc = 0. 173 | LOOP AT lt_binary_content INTO wl_binary_content. 174 | IF sy-tabix = lv_table_length. 175 | lv_length = lv_last_line_length. 176 | ENDIF. 177 | TRANSFER wl_binary_content TO lv_file_with_key LENGTH lv_length. 178 | CLEAR wl_binary_content. 179 | ENDLOOP. 180 | ELSE. 181 | MESSAGE e011(zemt_supp_message) INTO ls_return-message. 182 | ls_return-type = 'E'. 183 | APPEND ls_return TO et_return. 184 | EXIT. 185 | ENDIF. 186 | CLOSE DATASET lv_file_with_key. 187 | ENDIF. 188 | ENDIF. 189 | 190 | "Supplier attachments needs notifications 191 | IF ls_attachments-supplier_authored = 'X'. 192 | zcl_emt_trigger_notifications=>esc_ext_attachment( 193 | EXPORTING 194 | iv_esc = mv_esc_supply_id ). 195 | ENDIF. 196 | 197 | ENDMETHOD. 198 | -------------------------------------------------------------------------------- /Stream/Archivelink/ZCL_CONTENT_REPOSITORY: -------------------------------------------------------------------------------- 1 | *----------------------------------------------------------------------* 2 | * CLASS ZCL_CONTENT_REPOSITORY DEFINITION 3 | *----------------------------------------------------------------------* 4 | * 5 | *----------------------------------------------------------------------* 6 | CLASS ZCL_CONTENT_REPOSITORY DEFINITION 7 | PUBLIC 8 | CREATE PUBLIC . 9 | 10 | PUBLIC SECTION. 11 | 12 | TYPES: 13 | BEGIN OF ts_document, 14 | object_id TYPE saeobjid, 15 | business_object TYPE saeanwdid, 16 | file_type TYPE saeobjart, 17 | arc_doc_id TYPE toa01-arc_doc_id, 18 | filename TYPE toaat-filename, 19 | description TYPE toaat-descr, 20 | binlength TYPE sapb-length, 21 | * contents type TSFIXML, 22 | contents TYPE STANDARD TABLE OF tbl1024 WITH DEFAULT KEY, " From ARCHIVOBJECT_GET_BYTES, BINARCHIVOBJECT 23 | END OF ts_document . 24 | TYPES: 25 | tt_documents TYPE STANDARD TABLE OF ts_document WITH DEFAULT KEY . 26 | TYPES: 27 | tt_metadata TYPE STANDARD TABLE OF toaom WITH DEFAULT KEY . 28 | TYPES: 29 | tt_document_types TYPE RANGE OF saeobjart. 30 | 31 | METHODS get_documents_for_object 32 | IMPORTING 33 | !iv_object_id TYPE saeobjid 34 | !iv_sap_object TYPE saeanwdid 35 | !it_document_types TYPE tt_document_types OPTIONAL 36 | RETURNING 37 | value(rt_documents) TYPE tt_documents . 38 | METHODS enhance_attachment_content 39 | IMPORTING 40 | !iv_attach_key TYPE so_entryid 41 | CHANGING 42 | !cv_mime_type TYPE w3conttype 43 | !cv_stream TYPE xstring 44 | !cv_file_name TYPE sdok_filnm . 45 | PROTECTED SECTION. 46 | private section. 47 | 48 | methods CHECK_FOR_HTML_PAGE 49 | changing 50 | !CS_DOCUMENT type TS_DOCUMENT . 51 | methods GET_ATTACHMENTS 52 | importing 53 | !IV_OBJECT_ID type SAEOBJID 54 | !IS_METADATA type TOAOM 55 | returning 56 | value(RT_DOCUMENTS) type TT_DOCUMENTS . 57 | methods GET_DOCUMENT_FILE_INFO 58 | importing 59 | !IV_ARCHIVE_DOC_ID type TOAAT-ARC_DOC_ID 60 | exporting 61 | !EV_FILENAME type TOAAT-FILENAME 62 | !EV_DESCRIPTION type TOAAT-DESCR . 63 | methods GET_METADATA_FOR_SAP_OBJECT 64 | importing 65 | !IV_SAP_OBJECT type SAEANWDID 66 | !IT_DOCUMENT_TYPES type TT_DOCUMENT_TYPES optional 67 | returning 68 | value(RT_METADATA) type TT_METADATA . 69 | methods GET_DETAIL 70 | importing 71 | !IV_OBJECT_ID type SAEOBJID 72 | !IS_METADATA type TOAOM 73 | !IS_CONNECTION type TOAV0 74 | returning 75 | value(RS_DOCUMENT) type TS_DOCUMENT . 76 | ENDCLASS. 77 | 78 | 79 | 80 | CLASS ZCL_CONTENT_REPOSITORY IMPLEMENTATION. 81 | 82 | 83 | * ---------------------------------------------------------------------------------------+ 84 | * | Instance Private Method ZCL_CONTENT_REPOSITORY->CHECK_FOR_HTML_PAGE 85 | * +-------------------------------------------------------------------------------------------------+ 86 | * | [<-->] CS_DOCUMENT TYPE TS_DOCUMENT 87 | * +-------------------------------------------------------------------------------------- 88 | METHOD check_for_html_page. 89 | 90 | TYPES: 91 | BEGIN OF ts_1024, 92 | line TYPE text1024, 93 | END OF ts_1024, 94 | 95 | tt_1024 TYPE STANDARD TABLE OF ts_1024. 96 | 97 | DATA: 98 | lv_file_type TYPE ZCL_CONTENT_REPOSITORY=>ts_document-file_type, 99 | lt_text TYPE tt_1024, 100 | ls_text LIKE LINE OF lt_text, 101 | ls_content LIKE LINE OF cs_document-contents. 102 | 103 | *-- If you are getting the same length for all documents retrieved, 104 | *-- or if the document returned is HTML, but the extension stored is not, 105 | *-- it is probably a web page with additional information. When this 106 | *-- happened to me, it was because the ICC Connector to FileNet was setup 107 | *-- to use the Content Repository viewer instead of the SAP internal viewer. 108 | *-- 109 | *-- This was done becauce the SAP internal viewer did not limit access to the 110 | *-- documents that could be viewed. If you can view the PO, then you can view 111 | *-- the attachments. 112 | *-- 113 | *-- As long as the ICC config is set up this way, it is not possible to donwload 114 | *-- or view attachments via the Fiori Approvals App. The reason for this is that 115 | *-- FileNet is not available outside of the local network. 116 | 117 | *-- To check for this condition, convert the document to text, and 118 | *-- see if it is an HTML document. This is only to be done for 119 | *-- documents that do not have an HTM or HTML extenstion. Otherwise 120 | *-- valid HTML documents will look like false positives. The downside 121 | *-- is that if the error happens with an actual HTML document, the 122 | *-- issue will not be caught 123 | 124 | lv_file_type = cs_document-file_type. 125 | 126 | TRANSLATE lv_file_type TO UPPER CASE. 127 | 128 | CHECK lv_file_type NE 'HTM' 129 | AND lv_file_type NE 'HTML'. 130 | 131 | READ TABLE cs_document-contents INTO ls_content INDEX 1. 132 | 133 | CHECK ls_content-line(15) = `3C21444F43545950452068746D6C3E`. " in RAW format 134 | 135 | *-- Convert file contents to text 136 | cl_rsz_www_db_interface=>convert_raw_to_char( 137 | EXPORTING 138 | i_t_in = cs_document-contents 139 | IMPORTING 140 | e_t_out = lt_text 141 | ). 142 | 143 | *-- Change the document type and extension so it can be loaded as an HTML doc 144 | *-- Add some explanation 145 | ls_text-line = `The original document was not returned from FileNet. This usually happens when ICC connector to FileNet` && cl_abap_char_utilities=>cr_lf && 146 | `has been configured to use the Content Navigator, and not the internal SAP Viewer.` && cl_abap_char_utilities=>cr_lf && 147 | cl_abap_char_utilities=>cr_lf && 148 | `The original document is below:` && cl_abap_char_utilities=>cr_lf && 149 | cl_abap_char_utilities=>cr_lf. 150 | 151 | INSERT ls_text INTO lt_text INDEX 1. 152 | 153 | * INSERT `The original document was not returned from FileNet. This usually happens when ICC connector to FileNet` INTO lt_text INDEX 1. 154 | * INSERT `has been configured to use the Content Navigator, and not the internal SAP Viewer.` INTO lt_text INDEX 2. 155 | * INSERT `` INTO lt_text INDEX 3. 156 | * INSERT `The original document is below:` INTO lt_text INDEX 4. 157 | * INSERT `` INTO lt_text INDEX 5. 158 | 159 | cl_rsz_www_db_interface=>convert_char_to_raw( 160 | EXPORTING 161 | i_t_in = lt_text 162 | IMPORTING 163 | e_t_out = cs_document-contents 164 | ). 165 | 166 | cs_document-description = `Error reading from FileNet: ` && cs_document-description. 167 | cs_document-file_type = 'Text'. 168 | cs_document-filename = cs_document-filename && `.txt`. 169 | 170 | ENDMETHOD. 171 | 172 | 173 | * ---------------------------------------------------------------------------------------+ 174 | * | Instance Public Method ZCL_CONTENT_REPOSITORY->ENHANCE_ATTACHMENT_CONTENT 175 | * +-------------------------------------------------------------------------------------------------+ 176 | * | [--->] IV_ATTACH_KEY TYPE SO_ENTRYID 177 | * | [<-->] CV_MIME_TYPE TYPE W3CONTTYPE 178 | * | [<-->] CV_STREAM TYPE XSTRING 179 | * | [<-->] CV_FILE_NAME TYPE SDOK_FILNM 180 | * +-------------------------------------------------------------------------------------- 181 | METHOD enhance_attachment_content. 182 | 183 | DATA: 184 | lv_arc_doc_id TYPE toav0-arc_doc_id, 185 | lv_doc_type TYPE saeobjart, 186 | ls_document TYPE ts_document, 187 | lv_content TYPE LINE OF ts_document-contents, 188 | lv_input_length TYPE i, 189 | lv_string TYPE string, 190 | lv_xstring TYPE xstring, 191 | ls_metadata TYPE toaom, 192 | lt_connections TYPE STANDARD TABLE OF toav0, 193 | ls_connection LIKE LINE OF lt_connections. 194 | 195 | *-- Get the connection for the requested document 196 | lv_arc_doc_id = iv_attach_key. 197 | 198 | CALL FUNCTION 'ARCHIV_GET_CONNECTIONS' 199 | EXPORTING 200 | arc_doc_id = lv_arc_doc_id 201 | TABLES 202 | connections = lt_connections 203 | EXCEPTIONS 204 | nothing_found = 1 205 | OTHERS = 2. 206 | 207 | READ TABLE lt_connections INTO ls_connection 208 | WITH KEY arc_doc_id = lv_arc_doc_id. 209 | 210 | IF sy-subrc = 0. 211 | 212 | CLEAR: 213 | cv_mime_type, 214 | cv_stream, 215 | cv_file_name. 216 | 217 | 218 | *-- Pass empty LS_METADATA. The only value from the is the Business Object 219 | *-- which we don't have anyway 220 | ls_document = me->get_detail( 221 | iv_object_id = space 222 | is_metadata = ls_metadata 223 | is_connection = ls_connection 224 | ). 225 | 226 | cv_file_name = ls_document-filename. 227 | 228 | lv_input_length = ls_document-binlength. 229 | 230 | CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' 231 | EXPORTING 232 | input_length = lv_input_length 233 | IMPORTING 234 | buffer = cv_stream 235 | TABLES 236 | binary_tab = ls_document-contents 237 | EXCEPTIONS 238 | failed = 1 239 | OTHERS = 2. 240 | 241 | CALL FUNCTION 'SDOK_MIMETYPE_GET' 242 | EXPORTING 243 | extension = ls_document-file_type 244 | IMPORTING 245 | mimetype = cv_mime_type. 246 | 247 | ENDIF. 248 | 249 | ENDMETHOD. 250 | 251 | 252 | * ---------------------------------------------------------------------------------------+ 253 | * | Instance Private Method ZCL_CONTENT_REPOSITORY->GET_ATTACHMENTS 254 | * +-------------------------------------------------------------------------------------------------+ 255 | * | [--->] IV_OBJECT_ID TYPE SAEOBJID 256 | * | [--->] IS_METADATA TYPE TOAOM 257 | * | [<-()] RT_DOCUMENTS TYPE TT_DOCUMENTS 258 | * +-------------------------------------------------------------------------------------- 259 | METHOD get_attachments. 260 | 261 | DATA: 262 | ls_document LIKE LINE OF rt_documents, 263 | lt_connections TYPE STANDARD TABLE OF toav0, 264 | ls_connection LIKE LINE OF lt_connections. 265 | 266 | *-- Get all of the connections to the attachments 267 | CALL FUNCTION 'ARCHIV_GET_CONNECTIONS' 268 | EXPORTING 269 | objecttype = is_metadata-sap_object 270 | object_id = iv_object_id 271 | archiv_id = is_metadata-archiv_id 272 | documenttype = is_metadata-ar_object 273 | TABLES 274 | connections = lt_connections 275 | EXCEPTIONS 276 | nothing_found = 1 277 | OTHERS = 2. 278 | 279 | *-- For each attachment, get the contents from the Content Repository 280 | LOOP AT lt_connections INTO ls_connection. 281 | 282 | ls_document = get_detail( 283 | is_connection = ls_connection 284 | is_metadata = is_metadata 285 | iv_object_id = iv_object_id 286 | ). 287 | 288 | IF ls_document IS NOT INITIAL. 289 | APPEND ls_document TO rt_documents. 290 | ENDIF. 291 | 292 | ENDLOOP. 293 | 294 | 295 | ENDMETHOD. "get_attachments 296 | 297 | 298 | * ---------------------------------------------------------------------------------------+ 299 | * | Instance Private Method ZCL_CONTENT_REPOSITORY->GET_DETAIL 300 | * +-------------------------------------------------------------------------------------------------+ 301 | * | [--->] IV_OBJECT_ID TYPE SAEOBJID 302 | * | [--->] IS_METADATA TYPE TOAOM 303 | * | [--->] IS_CONNECTION TYPE TOAV0 304 | * | [<-()] RS_DOCUMENT TYPE TS_DOCUMENT 305 | * +-------------------------------------------------------------------------------------- 306 | METHOD GET_DETAIL. 307 | 308 | data: 309 | lt_archiveobject type STANDARD TABLE OF DOCS WITH DEFAULT KEY, 310 | lv_length TYPE sapb-length VALUE '0', 311 | lv_offset TYPE sapb-offset VALUE '0'. 312 | 313 | CLEAR rs_document. 314 | 315 | rs_document-business_object = is_metadata-sap_object. 316 | rs_document-file_type = is_connection-reserve. 317 | rs_document-object_id = iv_object_id. 318 | rs_document-arc_doc_id = is_connection-arc_doc_id. 319 | 320 | *-- NOTE: If you are getting the same length for all documents retrieved, 321 | *-- it is probably a web page with additional information. When this 322 | *-- happened to me, it was because the ICC Connector to FileNet was setup 323 | *-- to use the Content Repository viewer instead of the SAP internal viewer. 324 | *-- 325 | *-- This was done becauce the SAP internal viewer did not limit access to the 326 | *-- documents that could be viewed. If you can view the PO, then you can view 327 | *-- the attachments. 328 | *-- 329 | *-- As long as the ICC config is set up this way, it is not possible to donwload 330 | *-- or view attachments via the Fiori Approvals App. The reason for this is that 331 | *-- FileNet is not available outside of the local network. 332 | *-- 333 | *-- You can see what is being passed back by setting mode = 'T', and using a text table for ARVHIVOBJECT table 334 | *-- 335 | CALL FUNCTION 'ARCHIVOBJECT_GET_BYTES' 336 | EXPORTING 337 | archiv_id = is_connection-archiv_id 338 | archiv_doc_id = is_connection-arc_doc_id 339 | document_type = is_connection-reserve(20) 340 | length = lv_length 341 | offset = lv_offset 342 | * MODE = ' ' 343 | * SIGNATURE = 'X' 344 | * SHIFT_FLAG = ' ' 345 | * COMPID = 'data' 346 | IMPORTING 347 | binlength = rs_document-binlength 348 | * LENGTH = LENGTH 349 | * OFFSET = OFFSET 350 | TABLES 351 | binarchivobject = rs_document-contents 352 | ARCHIVOBJECT = lt_archiveobject 353 | EXCEPTIONS 354 | error_archiv = 1 355 | error_communicationtable = 2 356 | error_kernel = 3 357 | OTHERS = 4. 358 | 359 | IF sy-subrc = 0. 360 | 361 | get_document_file_info( EXPORTING 362 | iv_archive_doc_id = is_connection-arc_doc_id 363 | IMPORTING 364 | ev_filename = rs_document-filename 365 | ev_description = rs_document-description 366 | ). 367 | 368 | *-- If the attachment does not have a filename and description, it is not an ICC file, 369 | *-- so it is not needed in this list. 370 | IF rs_document-filename IS INITIAL. 371 | 372 | CLEAR rs_document. 373 | 374 | ENDIF. 375 | 376 | *-- Check to see if the document is really an HTML web page from FileNet. When SSO 377 | *-- is not set up (and possibly other conditions), FileNet redirects the user to a 378 | *-- web page to log in. The method called above will then return the web page contents 379 | *-- when it cannot return the actual file 380 | check_for_html_page( CHANGING cs_document = rs_document ). 381 | 382 | ELSE. 383 | 384 | CLEAR rs_document. 385 | 386 | ENDIF. 387 | 388 | ENDMETHOD. 389 | 390 | 391 | * ---------------------------------------------------------------------------------------+ 392 | * | Instance Public Method ZCL_CONTENT_REPOSITORY->GET_DOCUMENTS_FOR_OBJECT 393 | * +-------------------------------------------------------------------------------------------------+ 394 | * | [--->] IV_OBJECT_ID TYPE SAEOBJID 395 | * | [--->] IV_SAP_OBJECT TYPE SAEANWDID 396 | * | [--->] IT_DOCUMENT_TYPES TYPE TT_DOCUMENT_TYPES(optional) 397 | * | [<-()] RT_DOCUMENTS TYPE TT_DOCUMENTS 398 | * +-------------------------------------------------------------------------------------- 399 | METHOD get_documents_for_object. 400 | 401 | DATA: 402 | lt_documents TYPE tt_documents, 403 | lt_metadata TYPE tt_metadata, 404 | ls_metadata LIKE LINE OF lt_metadata. 405 | 406 | lt_metadata = get_metadata_for_sap_object( 407 | iv_sap_object = iv_sap_object 408 | it_document_types = it_document_types 409 | ). 410 | 411 | *-- For each possible entry, get the documents associated with the Business document (PO, etc) 412 | LOOP AT lt_metadata INTO ls_metadata. 413 | 414 | *-- Use the defined Link Table 415 | lt_documents = get_attachments( 416 | iv_object_id = iv_object_id 417 | is_metadata = ls_metadata 418 | ). 419 | 420 | APPEND LINES OF lt_documents TO rt_documents. 421 | 422 | ENDLOOP. 423 | 424 | ENDMETHOD. "get_documents_for_object 425 | 426 | 427 | * ---------------------------------------------------------------------------------------+ 428 | * | Instance Private Method ZCL_CONTENT_REPOSITORY->GET_DOCUMENT_FILE_INFO 429 | * +-------------------------------------------------------------------------------------------------+ 430 | * | [--->] IV_ARCHIVE_DOC_ID TYPE TOAAT-ARC_DOC_ID 431 | * | [<---] EV_FILENAME TYPE TOAAT-FILENAME 432 | * | [<---] EV_DESCRIPTION TYPE TOAAT-DESCR 433 | * +-------------------------------------------------------------------------------------- 434 | METHOD get_document_file_info. 435 | 436 | CLEAR: 437 | ev_filename, 438 | ev_description. 439 | 440 | SELECT SINGLE filename descr 441 | INTO (ev_filename, ev_description) 442 | FROM toaat 443 | WHERE arc_doc_id = iv_archive_doc_id. 444 | 445 | ENDMETHOD. "get_document_file_info 446 | 447 | 448 | * ---------------------------------------------------------------------------------------+ 449 | * | Instance Private Method ZCL_CONTENT_REPOSITORY->GET_METADATA_FOR_SAP_OBJECT 450 | * +-------------------------------------------------------------------------------------------------+ 451 | * | [--->] IV_SAP_OBJECT TYPE SAEANWDID 452 | * | [--->] IT_DOCUMENT_TYPES TYPE TT_DOCUMENT_TYPES(optional) 453 | * | [<-()] RT_METADATA TYPE TT_METADATA 454 | * +-------------------------------------------------------------------------------------- 455 | METHOD get_metadata_for_sap_object. 456 | 457 | CLEAR rt_metadata. 458 | 459 | SELECT * FROM toaom 460 | INTO TABLE rt_metadata 461 | WHERE sap_object = iv_sap_object 462 | AND ar_object IN it_document_types 463 | AND ar_status = abap_true. 464 | 465 | ENDMETHOD. "get_metadata_for_sap_object 466 | ENDCLASS. 467 | --------------------------------------------------------------------------------