
Transcription
SDN ContributionOffline Interactive Forms Using ABAPApplies to:Interactive Forms based on Adobe softwareSummaryThis paper shows the basic steps you need for creating an Interactive Form based on Adobe software for anoffline scenario using the SAP delivered function modules and the PDF object for extracting the data. Thepaper assumes that the reader has a basic understanding of PDF-based form development.Editor's note:In general, SAP recommends using Web Dynpro integration (Java or ABAP) of Interactive Forms forinteractive scenarios. The Web Dynpro framework handles the required XML transformations automaticallyin the background so that developers do not need to deal with this aspect manually and on an individualbasis.If you create an interactive scenario in transaction SFP, which was designed to meet printing requirements(i.e. for non-interactive output), you always need to manually code the transformation on the return trip of thePDF (to transfer data entered in the form into the backend).Author: Vani KrishnamoorthyCompany: SAP AmericaCreated on: 12 May 2006Author BioVani Krishnamoorthy is an SAP NetWeaver Tools Consultant for SAP America. 2006 SAP AG1
Table of ContentsAdobe Interactive Forms: Overview . 3Business Example . 3Designing a Form . 3Form Builder. 4Interface . 4Form Context . 5Form Layout . 5Generate and Send the Form . 6Data Retrieval and Processing . 6Get the Generated Function Module. 6Start the Form Processing . 6Call the Generated Function Module . 7End Form Processing. 8Send the Form to the Vendor. 8Generated Email . 11Payment Form Emailed to Vendor (PDF 82 KB) . 11Filled Form from the Vendor (PDF 82 KB). 11Extract Data . 11Upload the Form . 11Instantiate the PDF Object . 13Extract the Data . 14Update the Vendor Master . 15Related Content. 17Copyright. 18 2006 SAP AG2
Adobe Interactive Forms: OverviewSince SAP NetWeaver (Web) Application Server 6.40 (SAP NetWeaver 04), Adobe document services(ADS) have been available. This is a set of runtime services deployed on the Application Server that providea range of form and document creation and manipulation functions. The key capabilities of the ADS are thecreation of documents in PDF and various print formats from XML form templates and current system data,and the extraction of user-entered data from interactive PDF forms for rendering and generating AdobeForms. SAP has also provided a single programmatic interface called PDF Document Object (or PDF Object)that enables developers to communicate with ADS. PDF Object is available both in ABAP as well as Java.This paper shows the basic steps you need for creating an Adobe Interactive Form for offline scenario usingthe SAP delivered function modules and the PDF object for extracting the data. The paper assumes that thereader already has the basics of PDF based form development.Business ExampleThe business example in this paper is an offline scenario by which a vendor will be able to fill bankinformation and send this information back so that this can be updated in the vendor master. The SAPvendor no and vendor name are pre populated in the form. Then this form is emailed to the vendor. Thevendor completes the form and sends it back. The data from the PDF form is retrieved and the vendormaster is updated. This does not require any Web Dynpro developmentDesigning a FormThe first step for an offline scenario would be to design a form. This topic has been covered in detail in otherHow-To documents and is also explained in details in SAP documentation (Designing PDF Forms). Thesteps for form design are: Start transaction SFPCreate an interfaceCreate a form objectIn the context link the required parameters from the interfaceFinally create the layout of the form and activate the form.This creates a function module that encapsulates the form description. We will be creating an applicationprogram that collects the relevant data, calls this function module so as to generate the fillable PDF form.Make sure that the ADS is configured and ready for use (including a valid credential – See SAP Note736902). The credential is required if, for example, the form is to be saved after filling. 2006 SAP AG3
Form BuilderInterface 2006 SAP AG4
Form ContextForm Layout 2006 SAP AG5
Generate and Send the FormThe next step is to write the ABAP program which will create the form and email it to the vendor so that it canbe filled offline.The program will have the following steps: Data retrieval and processing : A select statement for the pre-populated informationObtain the name of the Generated Function Module of the formStart the form processingCall the Generated Function ModuleEnd form processingSend the form to the vendor using Business communication services (BCS)Data Retrieval and ProcessingThis can be as simple as a select statement to complex data selection. In this example we select the vendornumber, name and company code from the vendor table LFA1 based on the vendor from the selectionscreen* Get vendor dataselect single lifnr name1 bukrs from lfa1 into wa vndbnk where lifnr p lifnr.Get the Generated Function ModuleThe next step is to get the generated function module. Call function moduleFP FUNCTION MODULE NAME and pass the form name to it. The parameter e funcname will contain thename of the generated function module name.* First get name of the generated function modulecall function 'FP FUNCTION MODULE NAME'exportingi name 'ZVK TESTHD'importinge funcname fm name.Start the Form ProcessingForm printing needs to be explicitly opened and closed. Use the function FP JOB OPEN to open the formfor printing. The parameter ie outputparams determines printer settings. This parameter is also where weask the generated function module to return a PDF file back. Since this is an offline scenario and there is noprinting involved we need to suppress the printer dialog popup as well. Optionally there is a parameterconnection which can be used to determine the RFC destination for ADS. 2006 SAP AG6
* Set output parameters and open spool jobfp outputparams-nodialog 'X'." suppress printer dialog popupfp outputparams-GETPDF" launch print preview 'X'.call function 'FP JOB OPEN'changingie outputparams fp outputparamsexceptionscancel 1usage error 2system error 3internal error 4others 5.Call the Generated Function ModuleThis is similar to the generated function module in Smart Forms. Since the parameters of the functionmodule are defined in the interface, this will vary from form to form. However, /1bcdwb/docparams is astandard parameter. This is used to set the forms locale. This is also where we tell the form that it is fillable.Once this parameter is set - if the ADS is configured correctly (including the credential) - a fillable savableform will be returned when the function module is executed.* Set form language and country (- form locale)fp docparams-langu 'E'.fp docparams-country 'US'.fp docparams-FILLABLE 'X'.* Now call the generated function modulecall function fm nameexporting/1bcdwb/docparams fp docparamsZ VNDBNK wa vndbnkimporting/1BCDWB/FORMOUTPUT fp formoutputexceptions 2006 SAP AG7
usage error 1system error 2internal error 3others 4.End Form ProcessingUse the function FP JOB CLOSE to close the form for printing.* Close spool jobcall function 'FP JOB CLOSE'exceptionsusage error 1system error 2internal error 3others 4.Send the Form to the VendorThe PDF file generated is available in the parameter fp result which is returned by the generated functionmodule. The next step would be to extract this PDF and send it to the vendor using BCS.CALL FUNCTION 'SCMS XSTRING TO BINARY'EXPORTINGbuffer fp formoutput-PDF"PDF file from function moduleTABLESbinary tab lt att content hex.CLASS cl bcs DEFINITION LOAD.DATA:lo send request TYPE REF TO cl bcs VALUE IS INITIAL.lo send request cl bcs create persistent( ).* Message body and subjectDATA:lt message body TYPE bcsy text VALUE IS INITIAL, 2006 SAP AG8
lo document TYPE REF TO cl document bcs VALUE IS INITIAL.APPEND 'Dear Vendor,' TO lt message body.append ' ' to lt message body.APPEND 'Please fill the attached form and send it back to us.'TO lt message body.append ' ' to lt message body.APPEND 'Thank You,'TO lt message body.lo document cl document bcs create document(i type 'RAW'i text lt message bodyi subject 'Vendor Payment Form' ).DATA: lx document bcs TYPE REF TO cx document bcs VALUE IS INITIAL.TRY.lo document- add attachment(EXPORTINGi attachment type 'PDF'i attachment subject 'Vendor Payment Form'*I ATTACHMENT SIZE *I ATTACHMENT LANGUAGE SPACE*I ATT CONTENT TEXT *I ATTACHMENT HEADER i att content hex lt att content hex ).CATCH cx document bcs INTO lx document bcs.ENDTRY.* Add attachment* Pass the document to send requestlo send request- set document( lo document ).* Create senderDATA:lo sender TYPE REF TO if sender bcs VALUE IS INITIAL,l sendtype ADR6-SMTP ADDR value '[email protected]', 2006 SAP AG9
lo sender cl cam address bcs create internet address( l send ).* Set senderlo send request- set sender(EXPORTINGi sender lo sender ).* Create recipient*DATA:lo recipient TYPE REF TO if recipient bcs VALUE IS INITIAL.lo recipient cl sapuser bcs create( sy-uname ).** Set recipientlo send request- add recipient(EXPORTINGi recipient lo recipienti express 'X' ).lo send request- add recipient(EXPORTINGi recipient lo recipienti express 'X' ).* Send emailDATA: lv sent to all(1) TYPE c VALUE IS INITIAL.lo send request- send(EXPORTINGi with error screen 'X'RECEIVINGresult lv sent to all ).COMMIT WORK.message 'The payment form has been emailed to the Vendor' type 'I'. 2006 SAP AG10
Generated EmailPayment Form Emailed to Vendor (PDF 82 KB)Filled Form from the Vendor (PDF 82 KB)Extract DataOnce the vendor fills the form and sends it back the data needs to be extracted from the PDF file. In thisexample we are assuming that the vendor sends back the whole PDF file. But we can also make it easierand send only the data as an XML file when the vendor hits the SUBMIT button. For this we will use the PDFdocument object. SAP provides us with the interfaces IF FP (Form) and IF FP PDF OBJECT (PDF object).These two are the main interfaces which we will be using. The following are the steps to extract the datafrom the PDF file. Upload the form to the systemInstantiate a PDF object and assign the PDF file to the objectExtract the data from the PDF objectUpdate the vendor masterUpload the FormTo keep things simple in this example the filled form is saved in the C drive and uploaded usingCL GUI FRONTEND SERVICES. But there are many other options like sending the email directly to SAP,Receiving the data using http post etc. but this would be beyond the scope of this paper 2006 SAP AG11
CALL METHOD cl gui frontend services file open dialogCHANGINGfile table lt file tablerc lv rc*USER ACTION *FILE ENCODING EXCEPTIONSfile open dialog failed 1cntl error 2error no gui 3not supported by gui 4OTHERS 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.READ TABLE lt file tableINTO lv filenameINDEX 1.*lv filename p pdf.cl gui frontend services gui upload(EXPORTINGfilename lv filenamefiletype 'BIN'"BinaryIMPORTINGfilelength lv filelengthCHANGINGdata tab lt rawtabEXCEPTIONSfile open error 1 2006 SAP AG12
file read error 2no batch 3gui refuse filetransfer 4invalid type 5no authority 6unknown error 7bad data format 8header not allowed 9separator not allowed 10header too long 11unknown dp error 12access denied 13dp out of memory 14disk full 15dp timeout 16not supported by gui 17error no gui 18OTHERS 19 ).Instantiate the PDF ObjectThe uploaded file is just a stream of raw data. We need to extract just the data from this file. For this we feedthe data to the PDF object and use the methods to extract data. The first step would be to create a formobject. Once a form object is created we can create a PDF object and assign the file to this object. The PDFobject also needs to be informed that the mode would be to extract data. We can then generate a form byconnecting to the assigned ADS.* Get FP referenceDATA: lo fp TYPE REF TO if fp VALUE IS INITIAL,lo fp cl fp get reference( ).* For handling exceptionsDATA: lo fpex TYPE REF TO cx fp runtime VALUE IS INITIAL.TRY.*Create PDF Object using destination 'ADS' ( -- this is how it is*defined in SM59)DATA: lo pdfobj TYPE REF TO if fp pdf object VALUE IS INITIAL.lo pdfobj lo fp- create pdf object( connection 'ADS' ). 2006 SAP AG13
*Set documentlo pdfobj- set document(EXPORTINGpdfdata pdf data ).*Tell PDF object to extract datalo pdfobj- set extractdata( ).*Execute the call to ADSlo pdfobj- execute( ).Extract the DataNow that we have a PDF object we can extract the data by the simple call of a method. The extracted data isin XML format. We can do a transformation to convert the data to ABAP internal table. In this example thestandard identity transformation has been used which needs a few additional steps of replacing the XMLnamespace. But a custom transformation can be used instead and these additional steps can be avoided.DATA: xml data TYPE xstring,lt xml data TYPE STANDARD TABLE OF xstring.APPEND xml data TO lt xml data.lo pdfobj- get data(IMPORTINGformdata xml data ).* Convert XML data from XSTRING format to STRING formatDATA: lv xml data string TYPE string.CALL FUNCTION 'ECATT CONV XSTRING TO STRING'EXPORTINGim xstring xml dataIMPORTINGex string lv xml data string.* Remove NEW-LINE character from XML data in STRING formatCLASS cl abap char utilities DEFINITION LOAD.REPLACE ALL OCCURENCES OF cl abap char utilities newline IN 2006 SAP AG14
lv xml data string WITH ''.* Make the XML envelope compliant with identity transformREPLACE ' ?xml version "1.0" encoding "UTF-8"? data 'IN lv xml data stringWITH ' ?xml version "1.0" encoding "iso-8859-1"? asx:abap xmlns:asx "http://www.sap.com/abapxml" version "1.0" asx:values '.REPLACE ' /data 'IN lv xml data stringWITH ' /asx:values /asx:abap '.* Apply the identity transform and convert XML into ABAP in one stepDATA:wa VNDBNKwa VENDORtype ZVK VNDBNKtype ZHD VENDORVALUE IS INITIAL,value is initial,lv subrc TYPE sysubrc VALUE IS INITIAL,lt messtab TYPE STANDARD TABLE OF bdcmsgcoll,l key type SWR STRUCT-OBJECT KEY,l pack type zhd vendor-lifnr.CALL TRANSFORMATION idSOURCE XML lv xml data stringRESULT Z VNDBNK wa vndbnk.Update the Vendor MasterNow that the data is available in the internal table the vendor master is updated using standard SAP functioncalls. 2006 SAP AG15
Upload the form 2006 SAP AG16
Update Vendor MasterRelated Content1. Interactive Forms Based on Adobe Software2. Creating Print Forms3. Creating Interactive Forms 2006 SAP AG17
Copyright Copyright 2006 SAP AG. All rights reserved.No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG.The information contained herein may be changed without prior notice.Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries, pSeries, xSeries,zSeries, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, Informix, i5/OS, POWER, POWER5, OpenPower and PowerPC aretrademarks or registered trademarks of IBM Corporation.Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe SystemsIncorporated in the United States and/or other countries.Oracle is a registered trademark of Oracle Corporation.UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks ofCitrix Systems, Inc.HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C , World Wide Web Consortium, MassachusettsInstitute of Technology.Java is a registered trademark of Sun Microsystems, Inc.JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented byNetscape.MaxDB is a trademark of MySQL AB, Sweden.SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as theirrespective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. Allother product and service names mentioned are the trademarks of their respective companies. Data contained in this document servesinformational purposes only. National product specifications may vary.These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAPGroup") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors oromissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in theexpress warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting anadditional warranty.These materials are provided “as is” without a warranty of any kind, either express or implied, including but not limited to, the impliedwarranties of merchantability, fitness for a particular purpose, or non-infringement.SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or consequential damages that mayresult from the use of these materials.SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items contained within thesematerials. SAP has no control over the information that you may access through the use of hot links contained in these materials anddoes not endorse your use of third party web pages nor provide any warranty whatsoever relating to third party web pages.Any software coding and/or code lines/strings (“Code”) included in this documentation are only examples and are not intended to beused in a productive system environment. The Code is only intended better explain and visualize the syntax and phrasing rules ofcertain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errorsor damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or grossly negligent. 2006 SAP AG18
a range of form and document creation and manipulation functions. The key capabilities of the ADS are the creation of documents in PDF and various print formats from XML form templates and current system data, and the extraction of user-entered data from intera