Monday, July 9, 2012
This program is basically converts smartform output to PDF and displays that PDF data in Custom Container .
Steps:
Steps:
- Create one Smartform
- Get the OTF from smartform
- Convert the smartform into PDF format using function module CONVERT_OTF
- Load PDF data into HTML control CL_GUI_HTML_VIEWER->LOAD_DATA.
- Pass PDF data table
- Import URL
- Display PDF using CL_GUI_HTML_VIEWER->SHOW_URL
Example program steps
- Create one module pool program SAPMZPDF_DISPLAY.
- Create screen 1001. Attributes Tab-> Enter Short description - Screen to display PDF. Element List Tab->Define OKCODE.
- Click on LAYOUT button and define Custom Control on Screen. Name it as CUST_CONTROL.
- Flow Logic Tab-> Place the below code
"PBO PROCESS BEFORE OUTPUT. MODULE status_1001. "Status MODULE get_pdf_data. "Get PDF MODULE display_pdf. "Display PDF "PAI PROCESS AFTER INPUT. MODULE exit AT EXIT-COMMAND.
- TOP include contains declarations
*&---------------------------------------------------------------------* *& Include MZPDF_DISPLAYTOP Module Pool SAPMZPDF_DISPLAY *& *&---------------------------------------------------------------------* PROGRAM sapmzpdf_display. "Containers DATA: html_viewer TYPE REF TO cl_gui_html_viewer, main_container TYPE REF TO cl_gui_custom_container. TYPES: ty_it0002 TYPE pa0002, ty_it0008 TYPE pa0008, ty_control_par TYPE ssfctrlop, ty_output_options TYPE ssfcompop, ty_job_output_info TYPE ssfcrescl, ty_otf_data TYPE itcoo, ty_pdf TYPE tline. DATA: wa_it0002 TYPE ty_it0002, wa_it0008 TYPE ty_it0008, wa_control_par TYPE ty_control_par, wa_output_options TYPE ty_output_options, wa_job_output_info TYPE ty_job_output_info, wa_pdf TYPE ty_pdf. DATA: it_it0002 TYPE STANDARD TABLE OF ty_it0002, it_it0008 TYPE STANDARD TABLE OF ty_it0008, it_otf_data TYPE STANDARD TABLE OF ty_otf_data, it_pdf TYPE STANDARD TABLE OF ty_pdf, it_data TYPE STANDARD TABLE OF x255. DATA: gv_fm_name TYPE rs38l_fnam, gv_url TYPE char255, gv_content TYPE xstring, okcode TYPE sy-ucomm, gv_bin_filesize TYPE i. FIELD-SYMBOLS TYPE x.
-
MODULE status_1001.
*&---------------------------------------------------------------------* *& Module STATUS_1001 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE status_1001 OUTPUT. SET PF-STATUS 'STATUS1'. SET TITLEBAR 'T1'. ENDMODULE. " STATUS_1001 OUTPUT
- MODULE get_pdf_data.
*&---------------------------------------------------------------------* *& Module GET_PDF_DATA OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE get_pdf_data OUTPUT. PERFORM get_pdf_data. ENDMODULE. " GET_PDF_DATA OUTPUT
-
PERFORM get_pdf_data.
*&---------------------------------------------------------------------* *& Form GET_PDF_DATA *&---------------------------------------------------------------------* FORM get_pdf_data . IF it_pdf IS INITIAL. "Get data from DB SELECT * FROM pa0002 INTO TABLE it_it0002 UP TO 6 ROWS. SELECT * FROM pa0008 INTO TABLE it_it0008 UP TO 6 ROWS. "Get smartform function module name CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname = 'Z2DISPLAY_N_PDF' IMPORTING fm_name = gv_fm_name EXCEPTIONS no_form = 1 no_function_module = 2 OTHERS = 3. "Pass Printer related Parameters to Smartform wa_control_par-no_dialog = 'X'. " It supresses the Printer dialog. wa_control_par-getotf = 'X'. " Get OTF data wa_output_options-tddest = 'LOCAL'. " Set printer "Call Smartform CALL FUNCTION gv_fm_name EXPORTING control_parameters = wa_control_par output_options = wa_output_options IMPORTING job_output_info = wa_job_output_info TABLES tab_it0002 = it_it0002 tab_it0008 = it_it0008 EXCEPTIONS formatting_error = 1 internal_error = 2 send_error = 3 user_canceled = 4 OTHERS = 5. IF sy-subrc <> 0. ELSE . it_otf_data = wa_job_output_info-otfdata. "Convert OTF data to PDF CALL FUNCTION 'CONVERT_OTF' EXPORTING format = 'PDF' IMPORTING bin_filesize = gv_bin_filesize TABLES otf = it_otf_data lines = it_pdf EXCEPTIONS err_max_linewidth = 1 err_format = 2 err_conv_not_possible = 3 err_bad_otf = 4 OTHERS = 5. ENDIF. ENDIF. ENDFORM. " GET_PDF_DATA
-
MODULE display_pdf.
*&---------------------------------------------------------------------* *& Module DISPLAY_PDF OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE display_pdf OUTPUT. "create the controls and their containers IF main_container IS INITIAL. CREATE OBJECT main_container EXPORTING container_name = 'CUST_CONTROL' EXCEPTIONS cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5 OTHERS = 6. "convert pdf to xstring string LOOP AT it_pdf INTO wa_pdf. ASSIGN wa_pdf TO CASTING. CONCATENATE gv_content INTO gv_content IN BYTE MODE. ENDLOOP. "create PDF Viewer object CREATE OBJECT html_viewer EXPORTING parent = main_container. IF sy-subrc <> 0. "NO PDF viewwer ENDIF. "Convert xstring to binary table to pass to the LOAD_DATA method CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' EXPORTING buffer = gv_content TABLES binary_tab = it_data. " Load the HTML CALL METHOD html_viewer->load_data( EXPORTING type = 'application' subtype = 'pdf' IMPORTING assigned_url = gv_url CHANGING data_table = it_data EXCEPTIONS dp_invalid_parameter = 1 dp_error_general = 2 cntl_error = 3 OTHERS = 4 ). IF sy-subrc <> 0. WRITE:/ 'ERROR: CONTROL->LOAD_DATA'. EXIT. ENDIF. "Show it CALL METHOD html_viewer->show_url( url = gv_url in_place = 'X'). IF sy-subrc <> 0. WRITE:/ 'ERROR: CONTROL->SHOW_DATA'. EXIT. ENDIF. ENDIF. ENDMODULE. " DISPLAY_PDF OUTPUT
-
MODULE exit AT EXIT-COMMAND.
*&---------------------------------------------------------------------* *& Module EXIT INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE exit INPUT. CASE okcode. WHEN 'BACK' OR 'EXIT' OR 'CANCEL'. CALL METHOD html_viewer->free. IF sy-subrc <> 0. WRITE:/ 'CONTROL ERROR'. EXIT. ENDIF. CALL METHOD main_container->free. IF sy-subrc <> 0. WRITE:/ 'CONTROL ERROR'. EXIT. ENDIF. CALL METHOD cl_gui_cfw=>flush. IF sy-subrc <> 0. WRITE:/ 'CONTROL ERROR'. EXIT. ENDIF. LEAVE PROGRAM. ENDCASE. ENDMODULE. " EXIT INPUT
Followers
Popular Posts
- ABAP - ALV Report example with steps
- ABAP - Step by step tutorial on Smart Forms - Template Node
- ABAP - Sending email with pdf attachment
- SAP Adobe Form - Steps to create simple ADOBE Form and calling it from ABAP Program
- SAP ABAP - CL_ABAP_CHAR_UTILITIES class usage
- ABAP - Multiple value selection from F4 help for SELECT-OPTIONS
- Execute ABAP Report using SUBMIT statement
- ABAP - Select all or Deselect all in ALV or Check box handling in ALV
- Web Dynpro ABAP ALV - ON_CLICK event
- ABAP - Dynamic WHERE clause
Thank you so much for providing such a useful information about SAP Consulting.
ReplyDeleteNice way!
ReplyDeleteThank you very much for useful info and i implemented code as above it is working fine but now i have a issue like i created alv grid in grid i selected first record its displaying perfectly but if i select next record and print it is showing old form only please help me.
ReplyDeletethank you,
KK
Hi,
ReplyDeletethis is karthick. implemented code as above it is working fine. But i want to disable print and Save Button, Plz help me
ReplyDeleteExcellent information with unique content and it is very useful to know about the information based on blogs.
Hadoop online Training