Professional Documents
Culture Documents
SearchSAP.com
o o SAP Topics News
o o
Tutorials
Home Topics SAP administration SAPscript and Smart Forms Get SAPScript output as PDF and launch Acrobat inside SAPGUI itself
Get SAPScript output as PDF and launch Acrobat inside SAPGUI itself
Dushyant Shetty E-mail Print A AA AAA LinkedIn Facebook Twitter Share This Reprints
A very common requirement for programmers writing ABAP code for printing using SAPScript Forms is to redirect output to a PDF (Adobe Acrobat) file. I struggled for a few days trying to find a solution to this. Though I found quite a few examples on the web, it was difficult figuring out which technique was optimal. This tip is borne out of these struggles. This is an example of how to use ABAP code to save output of a print routine using a SAPScript form into PDF format and also display it within the SAP frontend itself. This routine proves extremely useful to provide users the ability to save local copies of output and preview it within the user-friendly Acrobat Reader control, all without leaving the SAP frontend or your program. Since function modules are used, the code is portable and this technique can be used in any other ABAP program as well. Two function modules, Z_DS_CREATE_LOCAL_PDF_FILE and
Z_DS_CALL_PDF_VIEWER need to be created. I have used a function group called Z5_DS_PDF for this purpose. The function group contains the ABAP objects code for declaration and implementation of a class that encapsulates the Acrobat application functionality. The function group also contains a screen '0901', that epresents our PDF viewer and one PBO and one PAI block for the same screen. Note: The following example has been stripped of essential errorhandling for the sake of simplicity and the programmer is assumed to possess knowledge of creation of function
When you register, you will start receiving targeted emails from my award-winning team of editorial writers. Our goal is to keep you informed on the hottest topics and biggest challenges faced by SAP professionals today.
E-mail Address:
By submitting your registration information to SearchSAP.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSAP.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.
groups, function modules, screens and SAPScript forms. ABAP objects or custom controls knowledge is not mandatory. Be patient when trying this out and follow all instructions thoroughly. The results will be worth the effort. Steps to follow to get this example running: 1) Create a function group (Example : Z5_DS_PDF) 2) Define the top include and place the code listed below into it (LZ5_DS_PDFTOP) 3) Create screen '0901' in function group with three elements: a) Pushbutton CLOSE at the top with function code 'CLO' (this is to exit preview screen) b) Custom control container (Large- spanning entire screen) named MY_CONTAINER c) The customary OK code field called OK_CODE Note: The names of the elements should be exactly as described above 4) Create one output and one input module in the flow logic of screen '0901' for which the code is provided below 5) Define two function modules with the following signatures: a) FUNCTION Z_DS_CREATE_LOCAL_PDF_FILE EXPORTING REFERENCE(AFILENAME) LIKE RLGRAP-FILENAME TABLES OTF_LINES STRUCTURE ITCOO b) FUNCTION Z_DS_CALL_PDF_VIEWER IMPORTING VALUE(FILENAME) TYPE STRING Code is provided below. 6) Compile and activate the function group 7) Create a simple SAPScript form with one page and one window 8) Define one element in the text for the main window called 'HELLO' and some static text in it 9) Check and activate the form 10) Create the example program (Example : Z5_DS_SCRIPT2PDF) with the below code 11) Run the example NOTES: I tested this code in R/3 version 4.6C but it should work in all 4.6 setups. I'm pretty sure some of the ABAP objects code I have used may not work with R/3 4.0 versions and earlier. Also, it works perfectly only when Acrobat Reader is installed on the presentation server. I have checked it with Acrobat versions 4 and 5 but I haven't had the
Z_DS_CREATE_LOCAL_PDF_FILE . *"---------------------------------------------------------------------*"*"Local interface: *" EXPORTING *" REFERENCE(AFILENAME) LIKE RLGRAP-FILENAME *" TABLES *" OTF_LINES STRUCTURE ITCOO *"---------------------------------------------------------------------- DATA: PDF_LINES LIKE TLINE OCCURS 1000 WITH HEADER LINE, ARCH LIKE TOA_DARA, NO_LINES TYPE I. CALL FUNCTION 'CONVERT_OTF' EXPORTING FORMAT = 'PDF' IMPORTING BIN_FILESIZE = NO_LINES TABLES OTF = OTF_LINES LINES = PDF_LINES. CALL FUNCTION 'DOWNLOAD' EXPORTING BIN_FILESIZE = NO_LINES FILENAME = 'c:test.pdf' FILETYPE = 'BIN' IMPORTING ACT_FILENAME = AFILENAME TABLES DATA_TAB = PDF_LINES. ENDFUNCTION. **** **** End of Code for Z_DS_CREATE_LOCAL_PDF_FILE **** *____________________________________________________________________________________ **** **** Code for Function Module Z_DS_CALL_PDF_VIEWER **** FUNCTION Z_DS_CALL_PDF_VIEWER . *"---------------------------------------------------------------------*"*"Local interface: *" IMPORTING *" VALUE(FILENAME) TYPE STRING *"---------------------------------------------------------------------- FILE_NAME = FILENAME. IF MY_CONTAINER IS INITIAL. CREATE OBJECT MY_CONTAINER EXPORTING CONTAINER_NAME = 'MY_CONTAINER'. CREATE OBJECT MY_PDF EXPORTING NAME = 'MY_PDF' PARENT = MY_CONTAINER. ENDIF. CALL SCREEN 901. " Ensure screen is created as per instructions ENDFUNCTION. **** **** End of Code for Z_DS_CALL_PDF_VIEWER **** *____________________________________________________________________________________ **** **** Flow Logic for screen '0901' **** PROCESS BEFORE OUTPUT. MODULE INIT. PROCESS AFTER INPUT. MODULE USER_COMMAND_0901. **** **** End of Flow Logic for screen '0901' **** *____________________________________________________________________________________ **** **** PBO module INIT for screen '0901' **** MODULE init OUTPUT. call method my_pdf->loadfile exporting filename = file_name. ENDMODULE. " init OUTPUT **** **** End of PBO module INIT for screen '0901' **** *____________________________________________________________________________________ **** **** PAI module USER_COMMAND_901 for screen '0901' **** MODULE USER_COMMAND_0901 INPUT. case ok_code. when 'CLO'. set screen 0. endcase. ENDMODULE. " USER_COMMAND_0901 INPUT **** **** End of PAI module USER_COMMAND_901 for screen '0901' **** *____________________________________________________________________________________ **** **** Example program Z5_DS_SCRIPT2PDF **** *&---------------------------------------------------------------------* *& Report Z5_DS_SCRIPT2PDF *
*& * *&---------------------------------------------------------------------* *& This report works only if the function modules * *& Z_DS_CREATE_LOCAL_PDF_FILE and Z_DS_CALL_PDF_VIEWER already exist * *& Also use an already existing simple SAPScript Form that contains a * *& window "MAIN" and rework printing code if necessary, remember to * *& change the output device name in OPTIONS-TDDEST * *& * *&---------------------------------------------------------------------* REPORT Z5_DS_SCRIPT2PDF. *----------------------------------------------------------------------* PARAMETERS: FORM LIKE RSSCFTDFORM DEFAULT 'Z5_DS_HELLO2'. "your form DATA: OTF_LINES LIKE ITCOO OCCURS 1000 WITH HEADER LINE, OPTIONS TYPE ITCPO, FILENAME LIKE RLGRAP-FILENAME, FILENAME_S TYPE STRING. START-OF-SELECTION. OPTIONS-TDDEST = 'LP01'. * Replace 'LP01' above with your default output device OPTIONS-TDCOPIES = 1. OPTIONS-TDGETOTF = 'X'. " the key to returning OTF data ************************************************************************ * Open the SapScript Form with the name "form" * ************************************************************************ CALL FUNCTION 'OPEN_FORM' EXPORTING FORM = FORM " name of form (SE71) OPTIONS = OPTIONS DIALOG = ' '. ************************************************************************ * Execute the element "HELLO" in window MAIN * - Nothing happens if /E HELLO is not declared in MAIN ************************************************************************ CALL FUNCTION 'WRITE_FORM' EXPORTING ELEMENT = 'HELLO' "execute element /E HELLO TYPE = 'BODY'. "normal output ************************************************************************ * Close the current SapScript Form ************************************************************************ CALL FUNCTION 'CLOSE_FORM' TABLES OTFDATA = OTF_LINES. " Retrieve all the OTF so far ************************************************************************ * Code for PDF Formatting and creation of local File ************************************************************************ CALL FUNCTION 'Z_DS_CREATE_LOCAL_PDF_FILE' IMPORTING AFILENAME = FILENAME TABLES OTF_LINES = OTF_LINES. FILENAME_S = FILENAME. ************************************************************************ * Code to launch Adobe Acrobat inplace in SAPGUI ************************************************************************ CALL FUNCTION 'Z_DS_CALL_PDF_VIEWER' EXPORTING FILENAME = FILENAME_S. **** ****
Dig Deeper
PEOPLE WHO READ THIS ALSO READ...
o o o o
Convert SAPScript or ABAP lists to PDF format How to send SAP reports in PDF format What is SAP? - Definition from Whatis.com What is TCP/IP (Transmission Control Protocol/Internet
Protocol)? - Definition from Whatis.com o What is cloud computing? - Definition from Whatis.com
RELATED TAGS
o o o
MORE DETAILS How to fix a slip print-out error in an SAP Smart Form Modifying standard SAP Smart Forms for purchase orders
Vendor ResourcesMORE
Making your business intelligence strategy a success (eGuide) Recession Proofing Your Organization with Electronic... (White Paper) Tips for optimizing your document management strategy (eGuide) Streamlined Build and Deployments Powered by Jazz -... (Webcast)
GET E-MAIL UPDATES Submit your e-mail below to receive SAP-related news, tech tips and more, delivered to your inbox.
ADS BY GOOGLE
#1 Network Security ClassDon't Miss This Intensive 5 Day Course. Stay Up on the Newest HacksOffensive-Security.com/PenTesting Manage Microsoft WindowsStreamline Windows Administration and Management. Free 30-day Trialwww.systemtools.com PDF Libraries for JavaGenerate, Merge, Append, Barcodes And So Much More, Free Evaluation!www.cete.com/Products/Dynamic_PDF_J Microsoft Windows7 Buy A Windows7 PC & get a Chance to Win a Volkswagon Polo. Know Morewww.microsoft.com
News
o o SAP Topics
o o Tutorials
Manufacturing ERP Expert lists top 5 ERP change management best practices
Panorama Consultings study of 2,000 ERP deployments found that thorough planning and communication are common themes in ERP change management best practices.
Keeping devices, apps under close watch key to mobile ERP security
Mobile ERP networks are creating new security concerns for IT. Experts says keeping a close eye on employee devices is the first step in alleviating these concerns.
All Rights Reserved, Copyright 2000 - 2011, TechTarget
ABOUT US CONTACT US SITE INDEX PRIVACY POLICY ADVERTISERS BUSINESS PARTNERS EVENTS MEDIA KIT TECHTARGET CORPORATE SITE REPRINTS SITE MAP