You are on page 1of 14

LOGIN BECOME A MEMBER RSS

SearchSAP.com
o o SAP Topics News

o o

Tutorials

o o o o o o o o Blogs White Papers Expert Advice

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

Requires Free Membership to View


LOGIN

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.

- Hannah Smalltree, Editorial Director

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.

Decisions that Drive Success download this IBM whitepaper today! -

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

opportunity to check it with Acrobat Reader 6.


*____________________________________________________________________________________ **** **** Code inside top include LZ5_DS_PDFTOP of function group Z5_DS_PDF **** FUNCTION-POOL Z5_DS_PDF. "MESSAGE-ID .. *---------------------------------------------------------------------* * CLASS CL_GUI_PDF DEFINITION * *---------------------------------------------------------------------* * ........ * *---------------------------------------------------------------------* CLASS CL_GUI_PDF DEFINITION INHERITING FROM CL_GUI_CONTROL. PUBLIC SECTION. TYPES: COL_TYPE TYPE INT4. METHODS: CONSTRUCTOR IMPORTING !PARENT TYPE REF TO CL_GUI_CONTAINER VALUE(SHELLSTYLE) TYPE I OPTIONAL VALUE(DISP_MODE) TYPE I OPTIONAL VALUE(LIFE_TIME) TYPE I OPTIONAL VALUE(NAME) TYPE STRING OPTIONAL EXCEPTIONS CNTL_ERROR CNTL_INSTALL_ERROR. METHODS: LOADFILE IMPORTING VALUE(FILENAME) TYPE STRING EXCEPTIONS FILE_NOT_FOUND. METHODS: REFRESH. METHODS: DISPATCH REDEFINITION. ENDCLASS. DATA: MY_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER. DATA: MY_PDF TYPE REF TO CL_GUI_PDF. data: ok_code like sy-ucomm. data: file_name type string. *********************************************************************** * custom control class implementation *********************************************************************** CLASS CL_GUI_PDF IMPLEMENTATION. METHOD CONSTRUCTOR. DATA: CTRL_NAME(80) TYPE C. IF NOT CL_GUI_OBJECT=>ACTIVEX IS INITIAL. CTRL_NAME = '{CA8A9780-280D11CF-A24D-444553540000}'. ELSE. RAISE CNTL_ERROR. ENDIF. CALL METHOD SUPER>CONSTRUCTOR EXPORTING CLSID = CTRL_NAME SHELLSTYLE = SHELLSTYLE PARENT = PARENT LIFETIME = LIFE_TIME NAME = NAME EXCEPTIONS CNTL_SYSTEM_ERROR = 1 OTHERS = 2. CASE SY-SUBRC. WHEN 1. RAISE CNTL_INSTALL_ERROR. WHEN 2. RAISE CNTL_ERROR. ENDCASE. CALL METHOD CL_GUI_CFW=>SUBSCRIBE EXPORTING REF = ME SHELLID = ME->H_CONTROL-SHELLID EXCEPTIONS OTHERS = 1. IF SYSUBRC NE 0. RAISE CNTL_ERROR. ENDIF. ENDMETHOD. METHOD LOADFILE. CALL METHOD ME->CALL_METHOD EXPORTING METHOD = 'LoadFile' P_COUNT = 1 P1 = FILENAME. ENDMETHOD. METHOD REFRESH. CALL METHOD ME->CALL_METHOD EXPORTING METHOD = 'Refresh' P_COUNT = 0. ENDMETHOD. METHOD DISPATCH. CALL METHOD CL_GUI_CFW=>FLUSH. IF SY-SUBRC NE 0. RAISE CNTL_ERROR. ENDIF. ENDMETHOD. ENDCLASS. **** **** End of code for LZ5_DS_PDFTOP **** *____________________________________________________________________________________ **** **** Code for Function Module Z_DS_CREATE_LOCAL_PDF_FILE **** FUNCTION

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. **** ****

End of example program Z5_DS_SCRIPT2PDF **** *____________________________________________________________________________________

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

pdf sap sapscript

This was first published in October 2003


Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk. BACK TO TOP

You May Also Be Interested In...


MORE BACKGROUND Chapter 7: 'Creating advanced reports with the SAP query tool' 9. Assigning saved search criteria

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.

1. Supply Chain Management (SCM) 2. Virtualization 3. Basis and Administration


Not a member? We'll activate your FREE membership with your subscription.

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

o o o o o o o o o Blogs White Papers Expert Advice

More from Related TechTarget Sites



MANUFACTURING ERP ORACLE DATA MANAGEMENT DATA MANAGEMENT UK BUSINESS ANALYTICS

CRM CONTENT MANAGEMENT

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.

IT Challenge: Barcode integration with manufacturing IT systems


In this IT Challenge, learn which manufacturing software systems should be integrated with barcode technology.

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

You might also like