SQL Server, T-SQL, ASP.NET, Javascript, SAP, ABAP Programming

Kodyaz Development Resources

Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Vista, etc.
Welcome to Kodyaz Development Resources Sign in | Join | Help






SAP SmartForms Download as SmartForm PDF Format using WS_DOWNLOAD and cl_gui_frontend_services


In this ABAP tutorial, a Smartforms output is generated by the example ABAP report.
Then an SAP Smartform to PDF convert is in sample ABAP codes.
In the following steps Smartforms pdf file is downloaded to the SAP users' client computer.
cl_gui_frontend_services class file_save_dialog method is used to identify the download path and the Smartforms PDF file name.
CALL FUNCTION 'CONVERT_OTF' is used to convert Smartform OTF to PDF format.
At last the Smartforms download is managed by call function WS_DOWNLOAD.


Set Text Elements of the ABAP Report

The ABAP code is given at the end of this ABAP tutorial. But before you activate ABAP report, there are 2 text elements we should define and set values for. These two text elements are labels used on the SAP selection screen. First text element is the title of the selection frame. I chosed the text "Download Smartforms to Folder" as the title of the selection frame block. The second text element is the label of the file folder selection input textbox. These textbox with F4 help is requested open the file folder dialog and the SAP user can freely choose a folder where he or she wants to download the SmartForm in pdf format.

Follow the menu selections : "SAP Menu > Goto > Text elements > Text symbols"

sap-se80-menu-goto-text

The Text symbols tab is the default active tab. Enter a text for the text symbol 001. This text for text-001 will be used as the label text of the frame on screen where the pdf converted SAP Smart Form document file path information is requested from the user.

text001

Go to the Selection texts tab. You will see the PA_FILE entry without a text entered. This text will be seen on the GUI of the example ABAP report as the label of the input text area used for file folder path.

This file folder is contains the full path set for the Smart Form document which is convert to pdf format.

set-abap-report-selection-texts


Run the ABAP Report, Application Process Flow

After the text symbols and selection texts are defined on the ABAP report Text elements screen, ABAP developers are now ready to run the ABAP program. Press F8 to execute and run the ABAP report prepared to run a Smart Forms report and convert the smartforms output to PDF format and on the next step download the pdf smartform document on client computer into the selected folder.

When the ABAP application is started, the following screen is displayed.

Click on the yellow text area and press F4 or click on the small icon next to the input text area to open the cl_gui_frontend_services screen File Save Dialog screen. The ABAP code to perform the opening of the cl_gui_frontend_services file save dialog screen is triggered from the AT SELECTION-SCREEN ON VALUE-REQUEST FOR event. In the ABAP Report source code, you can see that in value-request for event the PERFORM  method calls the SelectFolder form routine.

sap-smart-forms-download-as-pdf-screen

When the cl_gui_frontend_services class successfully displays the below File Save Dialog screen, SAP users can choose the file folder and give a name for the pdf conversion of SmartForms report.
If you look at the ABAP codes where "CALL METHOD cl_gui_frontend_services=>FILE_SAVE_DIALOG" file_save_dialog method of the cl_gui_frontend_services class is called, the default folder path, default pdf file name of the SAP SmartForms document and the file type are all set. But as I noted the user can change the download path, Smartforms pdf file name using the File Save Dialog screen.

cl_gui_frontend_services-file-save-dialog

For example, I decided to download the pdf converted SAP Smart Forms output on my computer's desktop with a file name download-smartform.pdf

When you click on the Save button on the cl_gui_frontend_services file save dialog screen, the full path is displayed on the input textbox as shown below.

sap-smart-forms-download-path-selected

Now as you can see the SAP Smart Forms download path and the file name is selected.

SAP users are ready to press the F8 button or the sap-execute-icon SAP execute icon to start the ABAP program.

After the successfull execution of the sample ABAP program, a Smart Forms output is converted into pdf file format and the resultant pdf file is saved on the target download folder with the desired file name as shown below.

smartforms-report-download-on-client-desktop

The PDF output of the Smartforms document download-smartform.pdf is created on my computer desktop folder.
You can see the Smartform pdf output on the screenshot.





ABAP Code of the SAP Application which Convert Smart Forms to PDF Format and Downloads to Client

Here is the ABAP code that I use to convert Smartform to PDF file format.
Please pay attention to selection-screen block and selection-screen on value request for ABAP code blocks.
cl_gui_frontend_services class is used to call method file_save_dialog to display the file save dialog screen GUI to the SAP users.

REPORT ZDOWNLOADSM .

DATA : gt_vbak TYPE TABLE OF vbak.

DATA :
  form_name TYPE rs38l_fnam,
  gs_control_params TYPE ssfctrlop,
  gs_output_options TYPE ssfcompop.

DATA :
  t_otfdata TYPE ssfcrescl,
  t_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE, " SAPscript: Text Lines
  t_otf TYPE itcoo OCCURS 0 WITH HEADER LINE, " OTF Structure
  w_bin_filesize(10) TYPE c.

DATA :
  gv_initialDirectory TYPE STRING,
  gv_filename TYPE STRING,
  gv_path TYPE STRING,
  gv_fullpath TYPE STRING.

CONSTANTS : c_defaultpath(100) TYPE C VALUE 'C:\'.

SELECTION-SCREEN BEGIN OF BLOCK BLOCK-1 WITH FRAME TITLE TEXT-001.
  PARAMETERS : pa_file LIKE RLGRAP-FileName DEFAULT c_defaultpath.
SELECTION-SCREEN END OF BLOCK BLOCK-1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_file.
  PERFORM u_SelectFolder USING pa_file.


START-OF-SELECTION.
  PERFORM uf_GetReportData.
  PERFORM uf_GetSmartFormModuleName.
  PERFORM uf_RunSmartForm.
  PERFORM uf_ConvertToOTF.
  PERFORM uf_DownloadToClient.
END-OF-SELECTION.

form U_SELECTFOLDER using p_pa_file.

  DATA :
    lv_subrc LIKE sy-subrc,
    lt_it_tab TYPE filetable.

  IF pa_file IS INITIAL.
    gv_initialDirectory = 'C:\'.
  ELSE.
    gv_initialDirectory = pa_file.
  ENDIF.

  " Display File Open Dialog control/screen
  CALL METHOD cl_gui_frontend_services=>FILE_SAVE_DIALOG
  EXPORTING
    WINDOW_TITLE = 'Save SmartForm as ...'
    DEFAULT_EXTENSION = '.pdf'
    DEFAULT_FILE_NAME = 'smartform.pdf'
    FILE_FILTER = '.pdf'
    INITIAL_DIRECTORY = gv_initialDirectory
  CHANGING
    FILENAME = gv_filename
    PATH = gv_path
    FULLPATH = gv_fullpath.

  IF sy-subrc = 0.
    " Write path on input area
    p_pa_file = gv_fullpath.
  ENDIF.

endform. " U_SELECTFOLDER

form UF_DOWNLOADTOCLIENT .

  DATA : lv_filename(128) TYPE C.

  lv_filename = gv_fullpath.

  CALL FUNCTION 'WS_DOWNLOAD'
  EXPORTING
    BIN_FILESIZE = w_bin_filesize
    FILENAME = lv_filename
    FILETYPE = 'BIN'
  TABLES
    data_tab = t_pdf_tab
  EXCEPTIONS
    FILE_OPEN_ERROR = 1
    FILE_WRITE_ERROR = 2
    INVALID_FILESIZE = 3
    INVALID_TYPE = 4
    NO_BATCH = 5
    UNKNOWN_ERROR = 6
    INVALID_TABLE_WIDTH = 7
    GUI_REFUSE_FILETRANSFER = 8
    CUSTOMER_ERROR = 9
    NO_AUTHORITY = 10
    OTHERS = 11.

endform. " UF_DOWNLOADTOCLIENT

form UF_GETREPORTDATA .

  SELECT * FROM vbak INTO TABLE gt_vbak
    WHERE vbeln EQ '0100000004'.

endform. " UF_GETREPORTDATA

form UF_GETSMARTFORMMODULENAME .

  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  EXPORTING
    formname = 'ZSMARTFORMS_SALES_DOCUMENTS'
  IMPORTING
    fm_name = form_name
  EXCEPTIONS
    no_form = 1
    no_function_module = 2
    OTHERS = 3.

endform. " UF_GETSMARTFORMMODULENAME

form UF_RUNSMARTFORM .

  gs_output_options-tdnoprev = 'X'.
  gs_control_params-no_dialog = 'X'.
  gs_control_params-getotf = 'X'.

  CALL FUNCTION form_name
  EXPORTING
    control_parameters = gs_control_params
    output_options = gs_output_options
    user_settings = 'X'
  IMPORTING
    job_output_info = t_otfdata
  TABLES
    it_vbak = gt_vbak
  EXCEPTIONS
    formatting_error = 1
    internal_error = 2
    send_error = 3
    user_canceled = 4
    OTHERS = 5.

endform. " UF_RUNSMARTFORM

form UF_CONVERTTOOTF .

  t_otf[] = t_otfdata-otfdata[].

  CALL FUNCTION 'CONVERT_OTF'
  EXPORTING
    FORMAT = 'PDF'
    MAX_LINEWIDTH = 132
  IMPORTING
    BIN_FILESIZE = w_bin_filesize
  TABLES
    otf = t_otf
    lines = t_pdf_tab
  EXCEPTIONS
    ERR_MAX_LINEWIDTH = 1
    ERR_FORMAT = 2
    ERR_CONV_NOT_POSSIBLE = 3
    ERR_BAD_OTF = 4.

endform. " UF_CONVERTTOOTF

Let me explain the above ABAP code in brief.
There are exactly 5 PERFORM calls to functions within the ABAP program.
These Perform calls are :
PERFORM uf_GetReportData.
PERFORM uf_GetSmartFormModuleName.
PERFORM uf_RunSmartForm.
PERFORM uf_ConvertToOTF.
PERFORM uf_DownloadToClient.

PERFORM uf_GetReportData.

In this function SAP database tables are queried for the raw data of the SAP Smart Forms report.
The result set of the ABAP SELECT query is stored in an ABAP internal table.

PERFORM uf_GetSmartFormModuleName.

This function contains a very basic Function Call to get the function name of the SAP Smart Forms report.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' is the main ABAP code of this code block.
ssf_function_module_name is always called in ABAP codes to get the function module name of the SAP Smart Forms report using the name of the Smartforms report.

PERFORM uf_RunSmartForm.

In this function the Smart Forms report is executed using CALL FUNCTION form_name function call.
Before the SAP Smartform document is generated, Smartforms output options and control parameter are set to value so that there will be no dialog screen, no print preview screen and the output will be generated in otf format.

PERFORM uf_ConvertToOTF.

The important ABAP code in this function is the CALL FUNCTION 'CONVERT_OTF' function call.
The OTF data is converted to PDF format in this stage of the ABAP report.
The code to convert Smartforms OTF output to PDF takes place here with call function Convert_OTF.

PERFORM uf_DownloadToClient.

ABAP code CALL FUNCTION 'WS_DOWNLOAD' enables the pdf output of the SAP Smartforms document to be downloaded to the client computer with given file folder, file name, etc parameters.
The ABAP function WS_DOWNLOAD is marked as obsolete but still works successfully in order to download Smartforms pdf file on users' computers.





SAP Resources

SAP Tutorial

SAP Forums

SAP Tools

SAP Transaction Codes Table














Related SAP Tutorial and ABAP Tutorials

SAP Notes - How to Read OSS Note
Find Accounting Document Number From Invoice Number in Smartforms
SAP Currency Table for Currency Text in ABAP Development
ABAP Transport Error : Object CUAD ReportName is Inactive
Enable SAP Users Create Own Layout Variants using set_table_for_first_display
ABAP bapi_salesorder_change to Delete Sales Order in SAP
How to Copy SAP Variants of ABAP Reports Using RS_COPY_SELECTION_SETS Function Module
Display SAP Logical Database using SE36 or ABAP Report at Attributes Screen
SAP T682 Conditions: Access Sequences Table
Sales Tables among ABAP Tables (SAP Sales and Distribution SD Tables)
ABAP Function Module rv_invoice_document_read to Read SAP Invoice Data Details
Read SAP Customer Data from KNA1 using kna1_single_reader ABAP Function Module
How to Upload Data to SAP from Excel File using alsm_excel_to_internal_table Function Module
ALV Grid Color - Table Row Background Color in ALV List
Display SAP Documentation using bmenu_show_documentation ABAP Function Module
Multi Color ALV Grid Color Alternate using ALV Layout info_fname Property
How to Debug SmartForms - Debugging SAP SmartForm in ABAP ?
How to Display SAP Transaction in a New Session Or in New Window using ABAP4_Call_Transaction Function Module
How to Open SAP Transaction in New Window Or in New Session using ABAP cc_call_transaction_new_task Function Module
ABAP Tutorial - How to Set Default Date Range in SAP Selection Screen for Date Parameter
ABAP Tutorial - Upload SAP Data to Excel using xxl_simple_api Function Module
How to Download, Upload and Share SAP Favorites Menu
How Find SAP SmartForms Function Module Name
How to Open PopUp_To_Confirm Screen When Delete Function Key is Pressed for Confirmation
SAP Email Send using ABAP efg_gen_send_email Function Call
SAP SmartForms Download as SmartForm PDF Format using WS_DOWNLOAD and cl_gui_frontend_services
SAP Symbols List - Display List of Symbols using ABAP Symbols Report
Display SAP Icons using ABAP Code - SAP Icon List
How to Configure Default ABAP Editor to ABAP WorkBench Front End Editor New
ABAP - Create Hierarchy Tree List using rs_tree_construct, rs_tree_list_display and snodetext
SAP Tutorial for ABAP Developers - Create Number Range Object using SAP Transaction Code SNRO
Create CL_GUI_ALV_GRID ALV Grid Column Header using ABAP Data Element
How to Create SAP Transaction Code using SAP SE93 Transaction
SAP Tutorial - Create Transaction Code for ABAP Module Pools
How to Upload Bitmap Image to SAP using SAP Transaction SE78
SAP Custom Splitter Container cl_gui_splitter_container ABAP Example Code
Message no. 00264 : Status STATUS of the user interface ZREPORT missing
Request Single Spool Record for SmartForms Call within an ABAP Loop using output_options tdnewid
ABAP Tutorial - SAP Split and ABAP Split String Function
Upload Data from Excel File in ABAP using TEXT_CONVERT_XLS_TO_SAP
Display SAP Product Hierarchy using Table T179T VTEXT Field on cl_gui_alv_tree ABAP ALV Tree Object
SAP Product Hierarchy - Example ABAP Program using rv_produkthierarchie_text_get Function
SAP Sales Division SPART Text Description for Different Languages in TSPAT Table
SAP Sales Distribution Channel VTWEG Text Description for Different Languages in TVTWT Table
SAP Sales Organization VKORG Text Description for Different Languages in TVKOT Table
SAP Tutorial - Convert Spool Request to PDF File using RSTXPDFT4 ABAP Report
ABAP Tutorial - How to Generate Random Number for a Given Range of Numbers using RANDOM_I2 Function Module
ABAP Tutorial - How to Generate Random Number for a Given Range of Numbers using QF05_RANDOM_INTEGER
SAP ABAP Tutorial - ALV Grid Example with cl_gui_alv_grid and Screen Painter
How to Create Favorites and Add SAP Transaction Code in SAP Favorites Menu Folder
How to Display Keys in All Dropdown Lists on SAP Screens
SAP EXAM - ABAP EXAM : Free Online Certification SAP Questions and Answers to Tests
How to Delete All Breakpoints within ABAP Code using SAP ABAP Editor (SE80)
SAP Tutorial - How to Translate Text Module in Smartforms (Translation for Smartforms)
SAP Transaction - Create Transaction Code for ABAP Program or Selection Screen
SAP Smartforms Tutorial - Create Smartforms Example
SAP Smartforms - How to Call Smartform within ABAP Program
Smartforms Program Lines Error - Field "TITLE" is unknown. It is neither in one of the specified tables nor defined by a "DATA" statement.
Smartforms System Field &SFSY-JOBPAGES& - Total Number of Pages on a SmartForm document
What is OSS - Online SAP Support Notes ?
Sales Tables among SAP ABAP Tables (Sales and Distribution SD Tables)
ABAP ACE_SOP_CLIENT_READ Function Call to Read System Clients Table t000
Free MaxDB Training on MaxDB Database and Administration from SAP
SAP Download MaxDB Database Software
SAP - ABAP Checkbox in Selection Screen Example
SAP - ABAP Radio Button Selection Screen Example
SAP - ABAP ALV Grid Sample Code using REUSE_ALV_GRID_DISPLAY
ABAP Code to Display SAP Table Contents
How to Remove Preceeding Zeros in ABAP Development
Valid ABAP TRTYP SAP Transaction Type List
How to Find the SAP Transaction Code of the Current Screen Displayed ?
How to Find the Menu Path of a SAP Tansaction Code using SEARCH_SAP_MENU
SAP Smart Forms Tutorial and Smart Forms Resources
SAP Training Cource BC470 Form Printing with SAP Smart Forms
SAP MiniWAS Web Application Server 6.20 and SAP DB Installation for Windows and Troubleshooting
Download SAP GUI for Windows 7.10 and 6.20 from SMP
Introduction to SAP ABAP Programming
Complete List of SAP Modules
SAP Module Abbreviations
Complete List of SAP Sales and Distribution Module (SD) Sub-Modules
List of SAP Standard Material Types
Message Types in Method Return Parameters for SAP Modules
Built-in ABAP Type List or Predefined ABAP Types for SAP Systems






Copyright © 2004 - 2010 Eralper Yilmaz. All rights reserved.
Powered by Community Server, by Telligent Systems