Programming

How to Prepare an Interactive PDF Form for SAP

In this blog post, we’ll teach you how to prepare an interactive PDF form for SAP, using SAP Interactive Forms by Adobe.

 

First, prepare a new form object to use in the following instructions. To be able to check this form object quickly, you should use the Preview PDF. To do this, create a print program, and then set the preview data for the form. We’ll describe how to do so in the following sections.

 

Creation of a New Form

For the first steps with interactive PDF forms you need a very simple interface that has a single table. For this purpose, the table of customers from a flight booking application will be used. Follow these steps to create the interface:

  1. Start Transaction SFP, and create a new interface with the name “Z_IFBA_BOOK_ DDIC_02”. Use the description “Interface for my first interactive form”.
  2. Add a parameter to the interface. Set the Parameter Name as “CUSTOMERS”, the Typing as TYPE, and the Type Name as “TY_CUSTOMERS”. The parameter isn’t optional, and no value is passed so no checkboxes need to be selected.
  3. Finally, save the interface and activate it. The interface should look that shown below.

Interface Z_IFBA_BOOK_DDIC_02

 

Next, create a new form. Follow these steps:

  1. In the initial screen of Transaction SFP, create a new form with the name “Z_IFBA_BOOK_FORM_03”. As Interface, select the previously created interface Z_IFBA_BOOK_DDIC_02, and as Description, use “A first interactive form”.
  2. Add the CUSTOMERS interface parameter to the context.
  3. Deactivate all fields except ID and NAME.
  4. Switch to the Layout tab to create the initial layout for the form.
  5. Save and activate the form.7

Print Program for Generating Preview Data

Now you need a print program to test the form in print view or to generate test data. Create the print program for this example as follows:

  1. Start Transaction SE38, and create a new program with the name “Z_IFBA_BOOK_ INTERACTIVE”.
  2. Use the ABAP program code shown below.
  3. Save and activate the program.
  4. Now create preview data.

At this point, it should be noted that the print program shown below creates a dynamic, interactive PDF form for the preview. For this purpose, the two fields fillable and dynamic are set in docparams. These two lines of code are highlighted in bold.

 

PROGRAM z_ifba_book_interactive.

 

* Screen definition

PARAMETERS:

   p_form TYPE fpwbformname DEFAULT 'Z_IFBA_BOOK_FORM_03',

   p_langu TYPE spras DEFAULT 'D',

   p_ctry TYPE land1 DEFAULT 'DE'.

 

* Data declaration

DATA:

" variables

   gv_fmname TYPE rs38l_fname,

   gv_err_string TYPE string,

" structures

   gs_docparams TYPE sfpdocparams,

   gs_outputpar  TYPE sfpoutputparams,

" tables

   gt_customers TYPE ty_customers,

" references

   gx_exc_api TYPE REF TO cx_fp_api.

 

* Processing

" data determination

SELECT *

   INTO TABLE gt_customers

   FROM scustom

   UP TO 10 ROWS

   ORDER BY PRIMARY KEY.

 

" Determination of the generated function module

 

TRY.

 

   CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'

       EXPORTING

           i_name = p_form

       IMPORTING

           e_funcname = gv_fmname.

 

" Error handling

CATCH cx_fp_api_repository " TRY.

             cx_fp_api_usage

             cx_fp_api_internal

   INTO gx_exc_api.

 

gv_err_string = gx_exc_api->get_text( ).

MESSAGE gv_err_string TYPE 'E'.

 

ENDTRY. " CATCH cx_fp_api_repository " TRY.

 

" Start printjob

gs_outputpar-reqnew = abap_true.

 

CALL FUNCTION 'FP_JOB_OPEN'

   CHANGING

       ie_outputparams = gs_outputpar

   EXCEPTIONS

       cancel = 1

       usage_error = 2

       system_error = 3

       internal_error = 4

       OTHERS = 5.

 

IF NOT sy-subrc IS INITIAL. "CALL FUNCTION

" Error, inform user

 

MESSAGE ID sy-msgid

        TYPE sy-msgty

        NUMBER sy-msgno

        WITH sy-msgv1

             sy-msgv2

             sy-msgv3

             sy-msgv4.

 

ENDIF. "IF NOT sy-subrc IS INITIAL. "CALL FUNCTION

 

" define language and country

gs_docparams-langu = p_langu.

gs_docparams-country = p_ctry.

 

" define form as interactive

gs_docparams-fillable = abap_true.

gs_docparams-dynamic = abap_true.

 

" Call the generated function module (form)

CALL FUNCTION gv_fmname

   EXPORTING

       /1bcdwb/docparams = gs_docparams

       customers = gt_customers

   EXCEPTIONS

       usage_error = 1

       system_error = 2

       internal_error = 3

       OTHERS = 4.

IF NOT sy-subrc IS INITIAL. " CALL FUNCTION gv_fmname

" Error, inform user

 

MESSAGE ID sy-msgid

        TYPE sy-msgty

        NUMBER sy-msgno

        WITH sy-msgv1

             sy-msgv2

             sy-msgv3

             sy-msgv4.

 

ENDIF. " IF NOT sy-subrc IS INITIAL. " CALL FUNCTION gv_fmnam

 

" Close print job

CALL FUNCTION 'FP_JOB_CLOSE'

   EXCEPTIONS

       usage_error = 1

       system_error = 2

       internal_error = 3

       OTHERS = 4.

IF NOT sy-subrc IS INITIAL. "CALL FUNCTION

 

" Error, inform user

 

MESSAGE ID sy-msgid

        TYPE sy-msgty

        NUMBER sy-msgno

        WITH sy-msgv1

             sy-msgv2

             sy-msgv3

             sy-msgv4.

 

ENDIF. "IF NOT sy-subrc IS INITIAL. "CALL FUNCTION

 

Prepare Preview PDF

To use the Preview PDF, you need to set its properties as the last step of the preparations. To do this, follow these steps:

  1. Start Transaction SFP, select the Z_IFBA_BOOK_FORM_03 form you just created, and then go to form editing (in change mode).
  2. There, switch to the Layout tab to view the form in Adobe LiveCycle Designer.
  3. Choose Edit > Form Properties, and go to the Preview page of the dialog that appears.

In the following three steps, you set the properties of the PDF form for preview. Like the print program, the Preview PDF should display a dynamic, interactive PDF form. In addition, you define the preview data. The Form Properties dialog and the corresponding page are shown in the next figure.

  1. Set the Preview Type to Interactive Form.
  2. In the Preview Adobe XML Form Preview As field, select Dynamic XML Form.
  3. Finally, in the Data File field, select the file you created in the previous section when generating the preview data.

Preview Page of the Form Properties Dialog

 

Preview PDF of Interactive PDF Forms

When a PDF document is created in Adobe LiveCycle Designer, usage rights aren’t added. Therefore, when using Preview PDF to test interactive PDF forms, the warning dialog that inputs can’t be saved appears. You can select the Don’t Show Again checkbox to avoid having to confirm the dialog each time you test.

 

Note that due to the lack of usage rights, individual functions may be available in a limited way. In this case, you must create the PDF form using the print program created in this chapter and then use it for testing.

 

Copy Form Template to Use in Multiple Examples

You can create a copy of the form you’ve just created at this point. This makes it possible to distribute the following examples over several forms for test purposes. You can create a new form at your discretion, for example, after each section, by copying the empty form.

 

Now create a copy of the Z_IFBA_BOOK_FORM_03 form and give it the name “Z_IFBA_BOOK_FORM_03_LEER”, for example. This completes the preparations.

 

Editor’s note: This post has been adapted from a section of the book SAP Interactive Forms by Adobe by Timo Ortiz.

Recommendation

SAP Interactive Forms by Adobe
SAP Interactive Forms by Adobe

Learn how to design forms with confidence! Hone your skills from creation to output with this comprehensive guide to SAP Interactive Forms by Adobe. See how to set up the software and configure your system, then start building forms and templates—whether you’re working with Adobe LiveCycle Designer Structure or using more advanced script programs. Get the latest updates, including cloud services, implementation for SAP S/4HANA, and new tools like SAP Forms Service by Adobe. With detailed, step-by-step instructions throughout, this book is the perfect resource for anyone who works with SAP Interactive Forms by Adobe!

Learn More
SAP PRESS
by SAP PRESS

SAP PRESS is the world's leading SAP publisher, with books on ABAP, SAP S/4HANA, SAP CX, intelligent technologies, SAP Business Technology Platform, and more!

Comments