04-16-2008 7:26 AM
Hi All,
I have one report prg wich gives op in sap script.
I want same output in pdf and have to save on hard disk.
please suggest me wat procedure i have to follow.
It's urgent
04-16-2008 7:29 AM
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 error-handling for the sake of simplicity and the programmer is assumed to possess knowledge of creation of function 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
😎 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
*____________________________________________________________________________________
****
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-280D-11CF-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 SY-SUBRC 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 RSSCF-TDFORM 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
04-16-2008 7:29 AM
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 error-handling for the sake of simplicity and the programmer is assumed to possess knowledge of creation of function 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
😎 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
*____________________________________________________________________________________
****
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-280D-11CF-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 SY-SUBRC 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 RSSCF-TDFORM 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
04-16-2008 7:32 AM
Check below link: [Converting SAP Script outputs to PDF file|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/49e15474-0e01-0010-9cba-e62df8244556]
04-16-2008 7:33 AM
hi,
what you can do is you can send the script to any mail id and in your SCOT you can define out going format for script as PDF format.
Atul
04-16-2008 7:33 AM
here is the code to follow
REPORT Z1SCRIPT_TO_PDF .
****************************DECLARATIONS********************************
DATA: BEGIN OF ITAB OCCURS 0,
CARRID TYPE SFLIGHT-CARRID,
CONNID TYPE SFLIGHT-CONNID,
PRICE TYPE SFLIGHT-PRICE,
END OF ITAB.
DATA: struct TYPE ITCPO.
DATA: PDFTAB TYPE TABLE OF TLINE WITH HEADER LINE,
DATAB TYPE TABLE OF ITCOO WITH HEADER LINE,
DATA: BINFILESIZE TYPE I,
FILE_NAME TYPE STRING,
FILE_PATH TYPE STRING,
FULL_PATH TYPE STRING.
© 2006 SAP AG 4
****************************END OF DECLARATIONS********************************
*To specify Printer name*
struct-tddest = 'LP01'.
*To specify no Print Preview*
struct-tdnoprev = 'X'.
*To access the SAP Script output in OTF format*
struct-tdgetotf = 'X'.
***************************SAPSCRIPT GENERATION********************************
CALL FUNCTION 'OPEN_FORM'
EXPORTING
* APPLICATION = 'TX'
* ARCHIVE_INDEX =
* ARCHIVE_PARAMS =
DEVICE = 'PRINTER'
DIALOG = space
FORM = 'ZSCRIPT'
* LANGUAGE = SY-LANGU
OPTIONS = struct
* MAIL_SENDER =
* MAIL_RECIPIENT =
* MAIL_APPL_OBJECT =
* RAW_DATA_INTERFACE = '*'
* SPONUMIV =
* IMPORTING
* LANGUAGE =
* NEW_ARCHIVE_PARAMS =
* RESULT =
EXCEPTIONS
CANCELED = 1
DEVICE = 2
FORM = 3
© 2006 SAP AG 5
OPTIONS = 4
UNCLOSED = 5
MAIL_OPTIONS = 6
ARCHIVE_ERROR = 7
INVALID_FAX_NUMBER = 8
MORE_PARAMS_NEEDED_IN_BATCH = 9
SPOOL_ERROR = 10
CODEPAGE = 11
OTHERS = 12
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'START_FORM'
EXPORTING
* ARCHIVE_INDEX =
FORM = 'ZSCRIPT'
* LANGUAGE = ' '
* STARTPAGE = ' '
* PROGRAM = ' '
* MAIL_APPL_OBJECT =
* IMPORTING
* LANGUAGE =
EXCEPTIONS
FORM = 1
FORMAT = 2
UNENDED = 3
UNOPENED = 4
UNUSED = 5
SPOOL_ERROR = 6
CODEPAGE = 7
OTHERS = 8
.
© 2006 SAP AG 6
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = 'ELEM1'
FUNCTION = 'SET'
TYPE = 'BODY'
WINDOW = 'MAIN'
* IMPORTING
* PENDING_LINES =
EXCEPTIONS
ELEMENT = 1
FUNCTION = 2
TYPE = 3
UNOPENED = 4
UNSTARTED = 5
WINDOW = 6
BAD_PAGEFORMAT_FOR_PRINT = 7
SPOOL_ERROR = 8
CODEPAGE = 9
OTHERS = 10
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
SELECT CARRID CONNID PRICE FROM SFLIGHT INTO TABLE ITAB.
LOOP AT ITAB.
CALL FUNCTION 'WRITE_FORM'
© 2006 SAP AG 7
EXPORTING
ELEMENT = 'ELEM2'
FUNCTION = 'SET'
TYPE = 'BODY'
WINDOW = 'MAIN'
* IMPORTING
* PENDING_LINES =
EXCEPTIONS
ELEMENT = 1
FUNCTION = 2
TYPE = 3
UNOPENED = 4
UNSTARTED = 5
WINDOW = 6
BAD_PAGEFORMAT_FOR_PRINT = 7
SPOOL_ERROR = 8
CODEPAGE = 9
OTHERS = 10
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDLOOP.
CALL FUNCTION 'END_FORM'
* IMPORTING
* RESULT =
EXCEPTIONS
UNOPENED = 1
BAD_PAGEFORMAT_FOR_PRINT = 2
SPOOL_ERROR = 3
CODEPAGE = 4
OTHERS = 5
.
© 2006 SAP AG 8
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'CLOSE_FORM'
* IMPORTING
* RESULT =
* RDI_RESULT =
TABLES
OTFDATA = DATAB[]
EXCEPTIONS
UNOPENED = 1
BAD_PAGEFORMAT_FOR_PRINT = 2
SEND_ERROR = 3
SPOOL_ERROR = 4
CODEPAGE = 5
OTHERS = 6
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
***************************END OF SAPSCRIPT GENERATION********************************
***************************CONVERTING OTF DATA TO PDF DATA****************************
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
* MAX_LINEWIDTH = 132
* ARCHIVE_INDEX = ' '
© 2006 SAP AG 9
* COPYNUMBER = 0
* ASCII_BIDI_VIS2LOG = ' '
* PDF_DELETE_OTFTAB = ' '
IMPORTING
BIN_FILESIZE = BINFILESIZE
* BIN_FILE =
TABLES
otf = DATAB[]
lines = PDFTAB[]
* EXCEPTIONS
* ERR_MAX_LINEWIDTH = 1
* ERR_FORMAT = 2
* ERR_CONV_NOT_POSSIBLE = 3
* ERR_BAD_OTF = 4
* OTHERS = 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.
*****************TAKING THE DOWNLOAD FILE PATH AS USER INPUT*************************
CALL METHOD cl_gui_frontend_services=>file_save_dialog
* EXPORTING
* WINDOW_TITLE =
* DEFAULT_EXTENSION =
* DEFAULT_FILE_NAME =
* FILE_FILTER =
* INITIAL_DIRECTORY =
* WITH_ENCODING =
* PROMPT_ON_OVERWRITE = 'X'
CHANGING
© 2006 SAP AG 10
filename = FILE_NAME
path = FILE_PATH
fullpath = FULL_PATH
* USER_ACTION =
* FILE_ENCODING =
* EXCEPTIONS
* CNTL_ERROR = 1
* ERROR_NO_GUI = 2
* NOT_SUPPORTED_BY_GUI = 3
* others = 4
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
****************************DOWNLOADING THE PDF DATA**********************************
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE = binfilesize
FILENAME = 'D:myfile.pdf'
FILETYPE = 'BIN'
* APPEND = ' '
* WRITE_FIELD_SEPARATOR = ' '
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
© 2006 SAP AG 11
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* TRUNC_TRAILING_BLANKS_EOL = 'X'
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* IMPORTING
* FILELENGTH =
tables
data_tab = PDFTAB[]
* FIELDNAMES =
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
u can also folow the link to get a pdf on this topicit will be very helpful
cheers
sharad.
04-16-2008 7:44 AM
Hi,
Check the sample code and code accordingly
REPORT zzz_jaytest .
Types Declaration
TYPES : BEGIN OF ty_pa0001,
pernr TYPE pa0001-pernr,
bukrs TYPE pa0001-bukrs,
werks TYPE pa0001-werks,
END OF ty_pa0001.
Internal Table Declaration
DATA : i_pa0001 TYPE STANDARD TABLE OF ty_pa0001, "For pa0001 Details
i_otf TYPE STANDARD TABLE OF itcoo, "For OTF data
i_content_txt TYPE soli_tab, "Content
i_content_bin TYPE solix_tab, "Content
i_objhead TYPE soli_tab,
Work Area Declaration
w_pa0001 TYPE ty_pa0001, "For pa0001 Details
w_res TYPE itcpp, "SAPscript output
"parameters
w_otf TYPE itcoo, "For OTF
w_pdf TYPE solisti1, "For PDF
w_transfer_bin TYPE sx_boolean, "Content
w_options TYPE itcpo, "SAPscript output
"interface
Variable Declaration
v_len_in TYPE so_obj_len,
v_size TYPE i.
Constants Declaration
CONSTANTS : c_x TYPE c VALUE 'X', "X
c_locl(4) TYPE c VALUE 'LOCL', "Local Printer
c_otf TYPE sx_format VALUE 'OTF', "OTF
c_pdf TYPE sx_format VALUE 'PDF', "PDF
c_printer TYPE sx_devtype VALUE 'PRINTER', "PRINTER
c_bin TYPE char10 VALUE 'BIN', "BIN
c_name TYPE string VALUE 'C:\ZZZ_JAYTEST.PDF',"Downloading
"File Name
c_form(11) TYPE c VALUE 'ZZZ_JAYTEST'. "Form Name
START-OF-SELECTION.
Selecting the records from pa0001
SELECT pernr bukrs werks FROM pa0001
INTO TABLE i_pa0001 UP TO 10 ROWS.
Setting the options
w_options-tdcopies = 1 ."Number of copies
w_options-tdnoprev = c_x."No print preview
w_options-tdgetotf = c_x."Return of OTF table
w_options-tddest = c_locl."Spool: Output device
Opening the form
CALL FUNCTION 'OPEN_FORM'
EXPORTING
form = c_form
device = c_printer
language = sy-langu
OPTIONS = w_options
IMPORTING
RESULT = w_res.
LOOP AT i_pa0001 INTO w_pa0001.
Writting into the form
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'MAIN'
window = 'MAIN'.
ENDLOOP.
Closing the form
CALL FUNCTION 'CLOSE_FORM'
IMPORTING
RESULT = w_res
TABLES
otfdata = i_otf
EXCEPTIONS
unopened = 1
bad_pageformat_for_print = 2
send_error = 3
spool_error = 4
codepage = 5
OTHERS = 6.
IF sy-subrc 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Converting OTF data to single line
LOOP AT i_otf INTO w_otf.
CONCATENATE w_otf-tdprintcom w_otf-tdprintpar
INTO w_pdf.
APPEND w_pdf TO i_content_txt.
ENDLOOP.
Converting to PDF Format
CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
EXPORTING
format_src = c_otf
format_dst = c_pdf
devtype = c_printer
CHANGING
transfer_bin = w_transfer_bin
content_txt = i_content_txt
content_bin = i_content_bin
objhead = i_objhead
len = v_len_in
EXCEPTIONS
err_conv_failed = 1
OTHERS = 2.
v_size = v_len_in.
Downloading the PDF File
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = v_size
filename = c_name
filetype = c_bin
TABLES
data_tab = i_content_bin.
If you r using this function module check it once....
call function 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = v_len_in
TABLES
otf = i_otf
lines = i_tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
others = 4.
Fehlerhandling
if sy-subrc 0.
*
endif.
or u can use the standard program RSTXPDFT4 to download the script into PDF format onto a particular location
++ One more method to convert the sapscript to pdf file :++*
first generate a Spool Request for the required Sapscript
then goto transaction SP01 and copy the generated Spool Request number
now execute the SAP report RSTXPDFT4
here enter the copied Spool request number and the target directory into the parameters
execute the report
required pdf file will be generated into the target directory
i hope it will help you out
Please refer this simple program:
http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm
http://searchsap.techtarget.com/tip/0,289483,sid21_gci1121833,00.html
Regards,
Raj.