This blog shows the gateway project data model to obtain the data from the PDF file by implementing the ‘GET_STREAM’ method. The objective is to pass the Smart form Name as an attribute of the entity set and get the PDF file.

Requirement: That all kinds of mail format are stored in smart form like Conformation mail, Dunning mail etc. and that the format required in frontend.

 

Below structure to be used as the source of our project data model.

 

Here are two different smart forms created as a demo.

 

Now create Project from Gateway Service Builder(SEGW).

 

Create data model by importing from DDIC structure ‘SSFSCREEN’. Provide the structure and entity type name.

 

Enable the Media flag for the entity type.

 

Generate the artifacts in gateway service builder.

Generate Artifacts

 

Redefine the GET_STREAM method of DPC Extension class.

 

Implementation of the code in the GET_STREAM method.

Source Code:

  METHOD /iwbep/if_mgw_appl_srv_runtime~get_stream.
** Declaration
    DATA :ls_key    LIKE LINE OF it_key_tab,
          gs_stream TYPE ty_s_media_resource.

    DATA : lv_fm_name        TYPE rs38l_fnam,
           control_parameter TYPE ssfctrlop,
           output_options    TYPE ssfcompop,
           lw_ssfcrescl      TYPE ssfcrescl.

    DATA : lt_otf      TYPE TABLE OF itcoo,
           lt_pdf_tab  TYPE TABLE OF tline,
           gv_bin_file TYPE xstring.

    IF iv_entity_set_name = 'SFormSet'.
      IF it_key_tab IS NOT INITIAL.
        DATA(lv_sf_name) = CONV tdsfname( it_key_tab[ name = 'Fname' ]-value ).
* Get the smartform FM name
        CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
          EXPORTING
            formname           = lv_sf_name
          IMPORTING
            fm_name            = lv_fm_name
          EXCEPTIONS
            no_form            = 1
            no_function_module = 2
            OTHERS             = 3.
        IF sy-subrc <> 0.
          RETURN.
        ENDIF.

        control_parameter-langu  = 'EN'.
        control_parameter-getotf = abap_true.
        control_parameter-preview = space.
        control_parameter-no_dialog = abap_true.

        output_options-tddest    = 'LOCL'.
        output_options-xdfcmode  = abap_true.
        output_options-tdnewid   = abap_true.
        output_options-tdimmed   = abap_true.
        output_options-tdprinter = 'PDFUC'.
        output_options-tddelete = space.

* call smartform fucntion mdoule
        CALL FUNCTION lv_fm_name
          EXPORTING
            control_parameters = control_parameter
            output_options     = output_options
            user_settings      = 'X'
          IMPORTING
            job_output_info    = lw_ssfcrescl
          EXCEPTIONS
            formatting_error   = 1
            internal_error     = 2
            send_error         = 3
            user_canceled      = 4
            OTHERS             = 5.
        IF sy-subrc <> 0.
          RETURN.
        ENDIF.


        REFRESH lt_otf[].
        lt_otf[] = lw_ssfcrescl-otfdata[].
        CLEAR : gv_bin_file.

* Convert OTF data to PDF
        CALL FUNCTION 'CONVERT_OTF'
          EXPORTING
            format                = 'PDF'
          IMPORTING
            bin_file              = gv_bin_file
          TABLES
            otf                   = lt_otf
            lines                 = lt_pdf_tab
          EXCEPTIONS
            err_max_linewidth     = 1
            err_format            = 2
            err_conv_not_possible = 3
            err_bad_otf           = 4
            OTHERS                = 5.
        IF sy-subrc <> 0.
          RETURN.
        ENDIF.

        gs_stream-mime_type = 'application/pdf'.
        gs_stream-value     = gv_bin_file.

        CALL METHOD me->copy_data_to_ref
          EXPORTING
            is_data = gs_stream
          CHANGING
            cr_data = er_stream.
      ENDIF.
    ENDIF.

  ENDMETHOD.

 

Now registered the service( /IWFND/MAINT_SERVICE).

Register Service

 

Now test the service in the gateway client( /IWFND/GW_CLIENT ).

Lets provide the entity set name and pass the smart form name as the key and use addition- $value

Test 1

 

Test 2

 

Conclusion:

  • This blog should give you a clear idea on how to pass smart form as a key in frontend and get the output in PDF of that smart form in frontend.
  • If you have any query on this blog, please list them below and I will be happy to answer.

 

Tags: OData
Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x