Wednesday 17 February 2021

Simple way to generate a pdf of adobe form and save it in local pc in Webdynpro on clicking hyperlink.

Introduction:

I came across a situation where on clicking the hyperlink in a webdynpro application a pdf of an adobe form to be generated and downloaded in the local system.

So I found the simplest way to make my work done using Webdynpro element(LinkToAction) and simple block of code for pdf generation.

Step1:

Create an adobe form to which pdf have to be generated.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Development, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Guides, SAP ABAP Learning

The preview of our adobe form:

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Development, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Guides, SAP ABAP Learning

Step 2:

Now create a webdynpro application in which we want to call the form.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Development, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Guides, SAP ABAP Learning

Give the description, save, check and activate the application.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Development, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Guides, SAP ABAP Learning

Step 3:

Create a text view in the application for the text display purpose.

Right click on RootElementContainer and select insert element.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Development, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Guides, SAP ABAP Learning

Give the ID and Select TextView from dropdown.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Development, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Guides, SAP ABAP Learning

Give the text for property ‘text’.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Development, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Guides, SAP ABAP Learning

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Development, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Guides, SAP ABAP Learning

Step 4:

Insert another UI element ‘LinkToAction’.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Development, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Guides, SAP ABAP Learning

Click on create icon of ‘onAction’ property and give the name and description for action method.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Development, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Guides, SAP ABAP Learning

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Development, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Guides, SAP ABAP Learning

Double click on the method and paste the following code:

METHOD onactionon_link_click .

DATA: lv_fmname TYPE fpname.
DATA: fp_docparams TYPE sfpdocparams.
DATA: fp_formoutput TYPE fpformoutput.
DATA : function TYPE funcname,
ftype TYPE fpinterfacetype,
fname TYPE funcname.
DATA : outputparams TYPE sfpoutputparams.
DATA: filename TYPE string,
path TYPE string,
fullpath TYPE string,
default_extension TYPE string VALUE 'PDF'.

**--OPEN JOB FOR ADOBE
outputparams-nodialog = 'X'.

outputparams-preview = 'X'.

outputparams-dest = 'LP01'.

outputparams-getpdf = 'X'.

CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
ie_outputparams = outputparams
EXCEPTIONS
cancel = 1
usage_error = 2
system_error = 3
internal_error = 4
OTHERS = 5.

IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
i_name = 'ZADOBE_TEST'
IMPORTING
e_funcname = lv_fmname.

fp_docparams-langu = 'E'.

fp_docparams-country = 'IN'.

fp_docparams-fillable = 'X'.

fp_docparams-dynamic = 'X'.

CALL FUNCTION '/1BCDWB/SM00000135'
EXPORTING
/1BCDWB/DOCPARAMS = fp_docparams
IMPORTING
/1BCDWB/FORMOUTPUT = fp_formoutput
EXCEPTIONS
USAGE_ERROR = 1
SYSTEM_ERROR = 2
INTERNAL_ERROR = 3
OTHERS = 4
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

CALL FUNCTION 'FP_JOB_CLOSE' .

IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

cl_wd_runtime_services=>attach_file_to_response( i_filename = 'Adobeformgen.pdf'
i_content = fp_formoutput-pdf
i_mime_type = 'application/pdf' ).

ENDMETHOD.
 
Step 5:

Create the webdypro application and test it.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Development, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Guides, SAP ABAP Learning

Activate and test.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Development, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Guides, SAP ABAP Learning

The output in webynpro application.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Development, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Guides, SAP ABAP Learning

Step 6:

Click on the hyperlink.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Development, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Guides, SAP ABAP Learning

We can find the attachment saved in downloads folder of local desktop .

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Development, SAP ABAP Career, SAP ABAP Preparation, SAP ABAP Guides, SAP ABAP Learning

Note: Even after we can save the pdf in our desired location.

No comments:

Post a Comment