Skip to Content
Technical Articles

Display the Adobe form in the PDF format through Gateway Service

Introduction:

This blog post is about to display the Adobe form in the PDF format through the Gateway Service.

In this blog post you can see the steps for how to display the Adobe form in the form of PDF through Gate way Service.

Requirement:

Display the PDF Format of Adobe form using the Gate Service. Whenever execute the URL from the Gateway system, it needs to display the adobe form in the form of PDF Format.

 

Steps to Required:

Step1: Need to create a ODATA Project.

  • Go to the Transaction SEGW and click and on Create Button to create a project.
  • Create a Project as ZPPM_PDF_AAR, and Package details as shown in the below screen.

  •  Expand the Project which we have created just now then need to  create entity type to define the Properties.
  • Expand the Data Model, under that Right click on the Entity types then click on create as show in below.

 

  • Enter the Entity Name as required and click on ok.

 

 

  • After that will get the below screen. Here we need to check the check box for Media type as in the below screen shot.

          Note: Don’t forgot to check the Media type for the Entity Type, If not we did not get the image                       in the Service output.

 

  • To define the Properties, expand the Entity type and double click on the Properties then click on the Append row button to add the properties as shown in the below screen.

  • Then define the properties as required. For the AAR Adobe form I have defined the below properties and check the Key box for the Key fields as shown in the below screen.

 

  • Once done with the above steps click on the Generate Runtime Artifacts as below.
  • It will help us to create the Classes to define custom Code. It will navigate to the next screen as show in the below and click on ok button.

 

  • To define the Code, go to the Runtime Artifacts of the Project and double click on the DPC_EXT as shown in the below.

 

Step2:  Implement the Code to Download the Adobe form

Redefine Define method marking Mime Type and the GET_STREAM

  • Now we need to redefine DEFINE Method in MPC_EXT class as below.
  • In this class we can define the type of media. Like as per requirement we need to PDF so I have defined as pdf .

  • Need to maintain the below piece of code in the Define Method.

METHOD define.

DATA:

lo_entity TYPE REF TO /iwbep/if_mgw_odata_entity_typ,

lo_property TYPE REF TO /iwbep/if_mgw_odata_property.

super->define( ).

lo_entity = model->get_entity_type( iv_entity_name = ‘pdf’ ).

IF lo_entity IS BOUND.

lo_property = lo_entity->get_property( iv_property_name = ‘mime_type’ ).

lo_property->set_as_content_type( ).

ENDIF.

ENDMETHOD.

In DPC_EXT Class:

  • Redefine the Get stream method and as in the DPC_EXT as below.
  • Get Stream mainly useful for the Upload or download  the files.

 

  • Maintain the below Piece of code in the GET_STREAM Method.

METHOD /iwbep/if_mgw_appl_srv_runtime~get_stream.

**– Data Declarations

DATA: lv_funcname TYPE funcname,

ls_outputparams TYPE sfpoutputparams,

ls_docparams TYPE sfpdocparams,

ls_formoutput TYPE fpformoutput,

ls_stream TYPE ty_s_media_resource,

lv_pia TYPE char32,

lv_proj TYPE char32.

**– Constants

CONSTANTS: lc_pia TYPE char32 VALUE ‘PIAGuid’,

lc_proj TYPE char32 VALUE ‘ProjGuid’,

lc_name TYPE fpname VALUE ‘ZPPM_AAR_FORM’,

lc_us TYPE land1 VALUE ‘US’.

***__ Read key data.
LOOP AT it_key_tab INTO DATA(ls_data)   ##INTO_OK.

CASE ls_data-name.

WHEN lc_pia.

lv_pia = ls_data-value.

WHEN lc_proj.

lv_proj = ls_data-value.

ENDCASE.

ENDLOOP.

**–Call the Function Module Name for the Adobe Form

TRY.

CALL FUNCTION ‘FP_FUNCTION_MODULE_NAME’

EXPORTING

i_name = lc_name

IMPORTING

e_funcname = lv_funcname.

CATCH cx_root ##NO_HANDLER ##CATCH_ALL.

**–Handle Exceptions with Try – catch

ENDTRY.

**–Opening the Job

ls_outputparams-nodialog = abap_true.

ls_outputparams-preview = abap_true.

ls_outputparams-getpdf = abap_true.

CALL FUNCTION ‘FP_JOB_OPEN’

CHANGING

ie_outputparams = ls_outputparams

EXCEPTIONS ##FM_SUBRC_OK

cancel = 1

usage_error = 2

system_error = 3

internal_error = 4

OTHERS = 5.

ls_docparams-langu = sy-langu.

ls_docparams-country = lc_us.

**– Function to get the Form

CALL FUNCTION lv_funcname

EXPORTING

/1bcdwb/docparams = ls_docparams

iv_proj_guid = lv_proj “‘005056B056C91ED89DA0FA3E3E1BE0DC’

iv_pia_guid = lv_pia “‘0A14860E3D8A1EE98691CCF06AF99B66’

IMPORTING

/1bcdwb/formoutput = ls_formoutput

EXCEPTIONS ##FM_SUBRC_OK

usage_error = 1

system_error = 2

internal_error = 3

OTHERS = 4.

**–Closing the Job

CALL FUNCTION ‘FP_JOB_CLOSE’

EXCEPTIONS ##FM_SUBRC_OK

usage_error = 1

system_error = 2

internal_error = 3

OTHERS = 4.

**–Converting the PDF to XString

ls_stream-value = ls_formoutput-pdf.

ls_stream-mime_type = TEXT-001. “application/pdf”

copy_data_to_ref( EXPORTING is_data = ls_stream CHANGING cr_data = er_stream ).

ENDMETHOD.

Step3: Testing the Service

Register GW service, and we are ready for testing.

 

URI:

/sap/opu/odata/sap/ZPPM_PDF_AAR_SRV/FormSet(PIAGuid=’005056B056C91ED88AF1496BDB4080DC’,ProjGuid=’005056B056C91ED88AF1496BDB27A0DC’)/$value

 

Note: In the above URL, $value refers to the Stream method.

Output Screen:

After Execution of above URL:

 

Downloaded Adobe Form:

 

Conclusion:

By following above steps we can download or view the adobe form through the Gate way Service or we can download the smart form also but there is a small difference between these two. The difference is function modules what ever we are using  in the DPC_EXT class but the remaining Steps are same.

 

Hope this is useful.

Thanks in Advance !!

Be the first to leave a comment
You must be Logged on to comment or reply to a post.