SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

SmartForm Displaying/Previewing



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Smartforms, SapScripts, PDF
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Wed Mar 04, 2009 5:18 pm    Post subject: SmartForm Displaying/Previewing Reply with quote

Version 1.0
Author WATTO
Source from: http: /www.watto.org/program/abap/download/Z_SMARTFORM_TEMPLATE_DISPLAY.abap

Description: A template program for running a SmartForm and previewing it. The previewing is done separate to the standard previewing, so that you can have control over the pages separately. Includes the following functionality...

Features:
- Generate a SmartForm output
- Display and navigate between pages
- Can do your own manipulation of the output prior to display

Code:
REPORT z_smartform_template_display.

DATA:
  v_control_params TYPE ssfctrlop,
  v_output_options TYPE ssfcompop,
  v_output_info    TYPE ssfcrescl.


* OTF Data for previewing
DATA:
  i_otf TYPE tsfotf,
  v_otf LIKE LINE OF i_otf.

* A single page
DATA:
  v_preview_page TYPE itcoo,
  i_preview_page TYPE STANDARD TABLE OF itcoo.

DATA:
  BEGIN OF i_gui_preview OCCURS 0.
        INCLUDE STRUCTURE itcoo.
DATA:
  END OF i_gui_preview.

* Bitmaps used in the preview
TYPES:
  BEGIN OF t_bitmaps,
    bm_index      LIKE sy-tabix, " Index in Table OTF
    bm_doc_id(42) TYPE c,        " DOC-ID of the Bitmap
  END OF t_bitmaps.

DATA:
  v_bitmaps TYPE t_bitmaps,
  i_bitmaps TYPE STANDARD TABLE OF t_bitmaps.


* details about the preview
TYPES:
  BEGIN OF t_preview_info,
    curr_pag LIKE ssfpp-tdpages, " Page Number
    op_index LIKE sy-tabix,      " Index in Table OTF
  END OF t_preview_info.

DATA:
  v_preview_info TYPE t_preview_info,
  i_preview_info TYPE STANDARD TABLE OF t_preview_info.


*---------------------------------------------------------------------*
*       START-OF-SELECTION
*---------------------------------------------------------------------*
START-OF-SELECTION.

  CLEAR:
    v_output_info.


  PERFORM setup_smartform_for_display.

  PERFORM run_smartform
    USING 'MYSMARTFORM'
      v_control_params
      v_output_options
    CHANGING
      v_output_info.

*   Retrieve the generated output
  i_otf = v_output_info-otfdata.

*   prepare the data for previewing.
  PERFORM load_preview_bitmaps.
  PERFORM get_preview_page_count.

*   Loads page 1 of the preview
  PERFORM show_preview_page
    USING
      1.



*---------------------------------------------------------------------*
*       FORM setup_smartform_for_display
*---------------------------------------------------------------------*
* [+] Sets the parameters for PDF conversions
*---------------------------------------------------------------------*
FORM setup_smartform_for_display.

  CLEAR:
    v_control_params,
    v_output_options.

  v_output_options-tddest     = 'LOCP'.
  v_output_options-tdprinter  = 'SAPWIN'.
  v_output_options-tdnewid    = 'X'.
  v_output_options-tdimmed    = space.
  v_output_options-tddelete   = 'X'.
  v_output_options-tdlifetime = 1.
  v_output_options-tdfinal    = 'X'.

  v_control_params-no_dialog  = 'X'.
  v_control_params-device     = 'PRINTER'.
  v_control_params-preview    = 'X'.
  v_control_params-getotf     = 'X'.

ENDFORM.                    "setup_smartform_for_display


*---------------------------------------------------------------------*
*       FORM run_smartform
*---------------------------------------------------------------------*
* [+] Runs the SmartForm of the given name
*---------------------------------------------------------------------*
FORM run_smartform
  USING
    p_form_name TYPE c
    p_control_params TYPE ssfctrlop
    p_output_options TYPE ssfcompop
  CHANGING
    p_output_info TYPE ssfcrescl.

  DATA:
    lv_function_name TYPE rs38l_fnam.

* Find the SmartForm function module name
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = p_form_name
    IMPORTING
      fm_name            = lv_function_name
    EXCEPTIONS
      no_form            = 1
      no_function_module = 2
      OTHERS             = 99.

  IF sy-subrc <> 0.
    EXIT.
  ENDIF.

* Run the SmartForm function module
  CALL FUNCTION p_form_name
    EXPORTING
      control_parameters = p_control_params
      output_options     = p_output_options
      user_settings      = ' '
    IMPORTING
      job_output_info    = p_output_info
    EXCEPTIONS
      formatting_error   = 1
      internal_error     = 2
      send_error         = 3
      user_canceled      = 4
      OTHERS             = 99.

ENDFORM.                    "run_smartform



*----------------------------------------------------------------------
*       FORM load_preview_bitmaps
*----------------------------------------------------------------------
* [+] Prepares the bitmap images used in the print preview
*----------------------------------------------------------------------
FORM load_preview_bitmaps.

  CLEAR:
    v_bitmaps,
    i_bitmaps.

  LOOP AT i_otf
     INTO v_otf
    WHERE tdprintcom = 'BM'.

    IF v_otf-tdprintpar+11(1) = 'D'.
      v_bitmaps-bm_index  = sy-tabix.
      v_bitmaps-bm_doc_id = v_otf-tdprintpar+16(42).
      APPEND v_bitmaps TO i_bitmaps.
    ENDIF.

  ENDLOOP.

ENDFORM.                    "load_preview_bitmaps


*----------------------------------------------------------------------
*       FORM get_preview_page_count
*----------------------------------------------------------------------
* [+] Gets the number of pages in this preview.
* [+] Sets up the i_preview_info
*----------------------------------------------------------------------
FORM get_preview_page_count.

* Internal variables
  DATA:
    lv_pages LIKE ssfpp-tdpages.

* Clear variables
  CLEAR:
    lv_pages,
    v_preview_info,
    i_preview_info.

  REFRESH:
    i_preview_info.

  LOOP AT i_otf
     INTO v_otf
    WHERE tdprintcom = 'OP'. "Open Page

    v_preview_info-op_index = sy-tabix.
    ADD 1 TO lv_pages.
    v_preview_info-curr_pag = lv_pages.

    APPEND v_preview_info TO i_preview_info.

  ENDLOOP.

  CLEAR:
    v_preview_info.

ENDFORM.                    "get_preview_page_count



*----------------------------------------------------------------------
*       FORM show_preview_page
*----------------------------------------------------------------------
* [+] Loads the given page number in the preview
*----------------------------------------------------------------------
FORM show_preview_page
  USING
    p_page_number TYPE txpagenr.

* Internal variables
  DATA:
    lv_current_index LIKE sy-tabix.

* Clear variables
  CLEAR:
    v_preview_page,
    i_preview_page.

  REFRESH
    i_preview_page.



  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      percentage = 25
      text       = 'Please wait...'.



* already on the correct page
  CHECK v_preview_info-curr_pag <> p_page_number.


  READ TABLE i_preview_info
        INTO v_preview_info
       INDEX p_page_number.

  CHECK sy-subrc = 0.

* preview header data
  v_preview_page-tdprintcom = '//'.
  APPEND v_preview_page TO i_preview_page.

* preview page data
  lv_current_index = v_preview_info-op_index.

  DO.
    READ TABLE i_otf
          INTO v_otf
         INDEX lv_current_index.

    IF sy-subrc <> 0.
      EXIT.
    ENDIF.

    v_preview_page = v_otf.

    CASE v_preview_page-tdprintcom.
      WHEN 'RD'. "Raw Data
        APPEND v_preview_page TO i_preview_page.
      WHEN 'EP'. "Close Page
        APPEND v_preview_page TO i_preview_page.
        EXIT.
      WHEN OTHERS.
        APPEND v_preview_page TO i_preview_page.
    ENDCASE.

    ADD 1 TO lv_current_index.
  ENDDO.

ENDFORM.                    "show_preview_page


*----------------------------------------------------------------------
*       FORM show_next_page
*----------------------------------------------------------------------
* [+] Shows the next page
*----------------------------------------------------------------------
FORM show_next_page.
  DATA: lv_page_number TYPE txpagenr,
        lv_last_page   TYPE i.

  lv_page_number = v_preview_info-curr_pag.
  ADD 1 TO lv_page_number.

  DESCRIBE TABLE i_preview_info LINES lv_last_page.

  IF lv_page_number > lv_last_page.
    lv_page_number = lv_last_page.
  ENDIF.


  IF lv_page_number <> v_preview_info-curr_pag.

    PERFORM show_preview_page
      USING
        lv_page_number.

  ENDIF.

ENDFORM.                    "show_next_page



*----------------------------------------------------------------------
*       FORM show_previous_page
*----------------------------------------------------------------------
* [+] Shows the previous page
*----------------------------------------------------------------------
FORM show_previous_page.
  DATA: lv_page_number TYPE txpagenr.

  lv_page_number = v_preview_info-curr_pag.
  SUBTRACT 1 FROM lv_page_number.

  IF lv_page_number <= 0.
    lv_page_number = 1.
  ENDIF.

  IF lv_page_number <> v_preview_info-curr_pag.

    PERFORM show_preview_page
      USING
        lv_page_number.

  ENDIF.

ENDFORM.                    "show_previous_page



*----------------------------------------------------------------------
*       FORM show_first_page
*----------------------------------------------------------------------
* [+] Shows the first page
*----------------------------------------------------------------------
FORM show_first_page.
  DATA: lv_page_number TYPE txpagenr.

  lv_page_number = 1.

  IF lv_page_number <> v_preview_info-curr_pag.

    PERFORM show_preview_page
      USING
        lv_page_number.

  ENDIF.

ENDFORM.                    "show_first_page



*----------------------------------------------------------------------
*       FORM show_last_page
*----------------------------------------------------------------------
* [+] Shows the first page
*----------------------------------------------------------------------
FORM show_last_page.
  DATA: lv_page_number TYPE txpagenr.

  DESCRIBE TABLE i_preview_info LINES lv_page_number.

  IF lv_page_number <> v_preview_info-curr_pag.

    PERFORM show_preview_page
      USING
        lv_page_number.

  ENDIF.

ENDFORM.                    "show_last_page


*----------------------------------------------------------------------
*       MODULE display_preview
*----------------------------------------------------------------------
* [+] Prepares the print preview for being displayed
*
*   THIS SHOULD BE PUT IN THE "PROCESS BEFORE OUTPUT" OF THE SCREEN
*
*----------------------------------------------------------------------
MODULE display_preview OUTPUT.

  CALL FUNCTION 'PREPARE_OTF_FOR_GUI_PREVIEWER'
    EXPORTING
      otf_raw         = i_preview_page[]
      defined_bitmaps = i_bitmaps[]
    IMPORTING
      otf_preview     = i_gui_preview[]
    TABLES
      otf             = i_otf[]
    EXCEPTIONS
      OTHERS          = 0.

* show the preview
  CALL 'C_TRADR'  ID 'OUTTAB' FIELD i_gui_preview[]
                  ID 'APPL'   FIELD 'SCRIPT'.

ENDMODULE.                    "display_preview OUTPUT
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Smartforms, SapScripts, PDF All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.