You are on page 1of 8

Embedding Attachments in SAP ADOBE form

There is a common requirement given by client wherein they ask to generate PDF files (output) based on
the data entered in SAP WebDynpro ABAP input screen.

Data entered in Input form can be:

 Simple Text
 Formatted Text
 Attachment etc.…

This article deals with displaying ATTACHMENTS in attachment section of output form (SAP ADOBE
form) and approach to achieve it.
Please refer to below image.
Note: This document is not specific to WebDynpro ABAP and can be leveraged as far as data (Input
Form + Attachment) can be supplied to methods/FM mentioned in below sections.
 

Challenges
 

1. Transferring the Data from SAP WebDynpro input screen to SAP ADOBE form.

Pre-requisite
 

Understanding on

1. WebDynpro ABAP
2. ABAP

Facts
 
1. Details (content/mime type/filename) about the attachments can be retrieved via
CONTENT_NODE in case WebDynpro screen is used for uploading the attachments.

Steps
 

1.   Generate Input content in PDF template


 

List/Order of Function Modules required to get ‘Input Content in PDF format’.

S.N Descriptio Important


Function Module Code Snippet
o. n Pointers

   CALL FUNCTION

To get ‘FP_FUNCTION_MODULE_NA

Function ME’
Importing
Module
FP_FUNCTION_MODUL parameter for           EXPORTING
1 name of
E_NAME FM is ‘PDF               i_name       
the PDF
template name’
form/ = FORM_TEMPLATE_NAME

Template           IMPORTING

              e_funcname = FM_NAME.

2 FP_JOB_OPEN To open a Set the value in structure

PDF form ‘fp_outputparams’ based on

output job configuration in system.

fp_outputparams-nodialog     

= ‘X’.

fp_outputparams-nopreview =

‘X’.

fp_outputparams-dest                 
= ‘LOCL’.

fp_outputparams-device           

= ‘PRINTER’.

fp_outputparams-reqnew         

= ‘X’.      CALL FUNCTION

‘FP_JOB_OPEN’

          CHANGING

              ie_outputparams =

fp_outputparams.

          CALL FUNCTION fm_name

                    EXPORTING

             

/1bcdwb/docparams =

Importing fp_docparams

parameter will                     EXP_PAR1                        =

be interface VAL1

Interface parameters, EXP_PAR2                        = VAL2

FM name for PDF form to the PDF and so get all                     EXCEPTIONS
3
(received from S.No.1) form/Tem the data for the
                          usage_error              =
plate interface
1
parameters

before calling                           system_error          =

this FM. 2

                          internal_error        =

                          OTHERS                         

= 99.
    CALL FUNCTION

‘FP_JOB_CLOSE’

          IMPORTING

To close               e_result            =  RESULT

4 FP_JOB_CLOSE the PDF           EXCEPTIONS


output job
              usage_error        = 1

              system_error    = 2

              internal_error    = 3

              OTHERS                    = 99.

    CALL FUNCTION

‘RSPO_ADSP_GET_PARTLIST’

          EXPORTING

              rqident                   
Based on
=   SPOOL_ID
Returns theRESULTpara

the part meter got           IMPORTING


RSPO_ADSP_GET_PART
5 list and the from S.No.4,               old_document
LIST
number of take
= adsp_old_document
ADS parts latest SPOOL
          TABLES
ID.
              partlist                   

= adsp_partlist

          EXCEPTIONS

              OTHERS                = 99.

6 RSPO_ADSP_GET_PDF Provides LV_CONTEN       CALL FUNCTION


T is of type
PDF data XSTRING and
post execution ‘RSPO_ADSP_GET_PDF’
of an ADS of this FM, we
will get PDF           EXPORTING
part data in this
              rqident                      =  SPOOL

ID

              navindex                = ‘1’

              old_document 

= adsp_old_document

          IMPORTING

              pdf_data               
variable.
 
= LV_CONTENT  (XSTRING)
LV_CONTEN
Twill be used
inSTEP3.           TABLES

              partlist                     

= adsp_partlist

          EXCEPTIONS

              no_such_job      = 1

              wrong_jobtype = 2

              OTHERS                    = 99.

Note: In above table, all the words in BOLD/ITALIC, needs to be defined and passed as per
requirement.
 

2.   Generate Attachment content


 

While uploading the attachments (refer to picture on Requirement Section) you can get of below values for
all the attachments:

 CONTENT (in XSTRING)


 FILENAME (in STRING)
 MIMETYPE (in STRING)

Value of above attributes will be available in CONTEXT NODE for all the attachments.

Note: This is not specific to WebDynpro ABAP, but can be used anywhere in ABAP, as far as above
mentioned 3 attributes can be retrieved.
 

DATA ls_attachment        TYPE sfpattachments.


DATA lt_attachments      TYPE tfpattachments.
LOOP AT LIST_OF_ATTACHMENT INTO ATTACHMENT.
ls_attachment-data           = ATTACHMENT  -content.
ls_attachment-name           = ATTACHMENT  -filename.
ls_attachment-filename     = ATTACHMENT  -filename.
ls_attachment-mimetype     = ATTACHMENT  -mimetype.
ls_attachment-description =  ATTACHMENT -filename. (This is based on user input)
ENDLOOP.
INSERT ls_attachment INTO TABLE lt_attachments.
 

Note: LIST_OF_ATTACHMENT internal table should have list of attachments having


CONTENT/FILENAME/MIMETYPE.
In case of WebDynpro ABAP, using CONTEXT_NODE, we can fill LIST_OF_ATTACHMENT.
 

3.   Prepare PDF Output


 

Merge the content received from above steps i.e. Generate Input content in PDF template andGenerate
Attachment content
DATA lv_dest                    TYPE rfcdest VALUE ‘ADS’.
DATA lv_full_content     TYPE xstring.
DATA lo_pdfobj                 TYPE REF TO if_fp_pdf_object.
DATA lo_fpex                     TYPE REF TO cx_fp_runtime.
lv_dest = cl_fp=>get_ads_connection( ).
        TRY.
              “Create PDF Object.
              lo_pdfobj = cl_fp=>get_reference( )->create_pdf_object( connection = lv_dest ).
              “Set document
              lo_pdfobj->set_document( pdfdata =  lv_content ).
              “Set attachment.
              lo_pdfobj->set_attachments( attachments = lt_attachments  ).
              “Execute, call ADS.
              lo_pdfobj->execute( ).
              “Get result..
              lo_pdfobj->get_document( IMPORTING pdfdata =  lv_full_content  ).
           CATCH cx_fp_runtime INTO lo_fpex.
        ENDTRY.
 

After execution of above code, variable ‘LV_FULL_CONTENT’ which is of type XSTRING, will have
PDF content (INPUT DATA + ATTACHMENTS).

Developer can use this content to:

 Dynamically create a PDF file and store in some on ContentServer example DMS
 Download it as PDF, by using below code

CALL METHOD cl_wd_runtime_services=>attach_file_to_response


 EXPORTING
         i_filename                 = ‘test.pdf’
         i_content                    = lv_full_content
         i_mime_type           = ‘application/pdf’
         i_in_new_window = abap_true.

You might also like