Code template for redefinition of /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM

📟 get_pdf

placeholder function – replace with the relevant business logic

📟 check_msg_and_raise_exceptions

Take a look at Generic Exception handling (BAPIRET2) in OData

  METHOD /iwbep/if_mgw_appl_srv_runtime~get_stream.
    DATA: lv_entity_type TYPE string.
    DATA: lv_keys TYPE z_structure.
    DATA: lo_message_container TYPE REF TO /iwbep/if_message_container.
    DATA: lv_header TYPE ihttpnvp.
    DATA: lv_stream            TYPE ty_s_media_resource.
    DATA: lv_return TYPE bapiret2.
    DATA: lt_return            TYPE bapiret2_t.

*--- Basic requirements
    lv_entity_type = io_tech_request_context->get_entity_type_name( ).
    lo_message_container = mo_context->get_message_container( ).

    CASE lv_entity_type.

*--- When EntityType XYZ do the following
      WHEN zcl_..._mpc=>gc_xyz.

*-- read keys
    io_tech_request_context->get_converted_keys(
      IMPORTING
        es_key_values = lv_keys
    ).

*-- get pdf - execute business logic
        get_pdf(
          EXPORTING
            iv_parameter_a = lv_keys-parameter_a
          IMPORTING
            ev_pdf_xstring = lv_stream-value
            es_return      = lv_return
        ).

        lv_stream-mime_type = 'application/pdf'. "set mime type accordingly

*-- check errors
        IF lv_return IS NOT INITIAL.
          APPEND lv_return TO lt_return.
          check_msg_and_raise_exceptions(
            EXPORTING
              it_messages         = lt_return
              i_message_container = lo_message_container
          ).
        ENDIF.

*-- copy data to ref
        copy_data_to_ref( EXPORTING is_data = lv_stream
                          CHANGING  cr_data = er_stream ).

*-- set header
        lv_header = VALUE ihttpnvp( name  = 'Content-Disposition'
                                    value = |outline; filename="{ escape( val = 'xyz.pdf' format = cl_abap_format=>e_url ) }";| ). "set pdf name accordingly
        set_header( lv_header ).

      WHEN OTHERS.
        super->/iwbep/if_mgw_appl_srv_runtime~get_stream(
          EXPORTING
            iv_entity_name          = iv_entity_name
            iv_entity_set_name      = iv_entity_set_name
            iv_source_name          = iv_source_name
            it_key_tab              = it_key_tab
            it_navigation_path      = it_navigation_path
            io_tech_request_context = io_tech_request_context
            IMPORTING
              er_stream             = er_stream
              es_response_context   = es_response_context ).
    ENDCASE.

  ENDMETHOD.

Leave a Reply

Your email address will not be published. Required fields are marked *