Monday, December 20, 2010
The below sample program is used to print the another program(called program) output using SUBMIT statement and reads spool and converts spool into PDF. Download PDF using GUI_DOWNLOAD as binary file.

REPORT ztest_print.

TABLES:
tsp01.
"Variables
DATA:
    l_lay    TYPE pri_params-paart,
    l_lines  TYPE pri_params-linct,
    l_cols   TYPE pri_params-linsz,
    l_val    TYPE c.
*Types
TYPES:
    t_pripar TYPE pri_params,
    t_arcpar TYPE arc_params.
"Work areas
DATA:
    lw_pripar TYPE t_pripar,
    lw_arcpar TYPE t_arcpar.

"Variables
DATA:
    l_no_of_bytes TYPE i,
    l_pdf_spoolid LIKE tsp01-rqident,
    l_jobname     LIKE tbtcjob-jobname,
    l_jobcount    LIKE tbtcjob-jobcount,
    file_name     type string.
"Types
TYPES:
    t_attachment     TYPE  solisti1,
    t_pdf            TYPE  tline.
"Workareas
DATA :
    w_attachment     TYPE  t_attachment,
    w_pdf            TYPE  t_pdf.
"Internal Tables
DATA :
    i_attachment     TYPE STANDARD TABLE OF t_attachment,
    i_pdf            TYPE STANDARD TABLE OF t_pdf.
*&---------------------------------------------------------------------*
*& Selection-screen
*&---------------------------------------------------------------------*
parameters:
p_file  type ibipparms-path.

at selection-screen on value-request for p_file.
  perform f4_for_p_file changing file_name .

*&---------------------------------------------------------------------*
*& start-of-selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.

  l_lay   = 'X_65_132'.
  l_lines = 65.
  l_cols  = 132.
  "Read, determine, change spool print parameters and archive parameters
  CALL FUNCTION 'GET_PRINT_PARAMETERS'
    EXPORTING
      in_archive_parameters  = lw_arcpar
      in_parameters          = lw_pripar
      layout                 = l_lay
      line_count             = l_lines
      line_size              = l_cols
      no_dialog              = 'X'
    IMPORTING
      out_archive_parameters = lw_arcpar
      out_parameters         = lw_pripar
      valid                  = l_val
    EXCEPTIONS
      archive_info_not_found = 1
      invalid_print_params   = 2
      invalid_archive_params = 3
      OTHERS                 = 4.
  IF l_val <> space AND sy-subrc = 0.
    lw_pripar-prrel = space.
    lw_pripar-primm = space.

    SUBMIT ztest_to_be_printed TO SAP-SPOOL SPOOL PARAMETERS lw_pripar
                               ARCHIVE PARAMETERS lw_arcpar
                               WITHOUT SPOOL DYNPRO AND RETURN.

    SELECT MAX( rqident )
    FROM tsp01
    INTO tsp01-rqident
    WHERE rqowner = sy-uname.

    CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
      EXPORTING
        src_spoolid   = tsp01-rqident
        no_dialog     = ' '
      IMPORTING
        pdf_bytecount = l_no_of_bytes
        pdf_spoolid   = l_pdf_spoolid
        btc_jobname   = l_jobname
        btc_jobcount  = l_jobcount
      TABLES
        pdf           = i_pdf.

    CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
      EXPORTING
        line_width_src              = 134
        line_width_dst              = 255
      TABLES
        content_in                  = i_pdf
        content_out                 = i_attachment
      EXCEPTIONS
        err_line_width_src_too_long = 1
        err_line_width_dst_too_long = 2
        err_conv_failed             = 3
        OTHERS                      = 4.
    IF sy-subrc <> 0.
      MESSAGE s000(0k) WITH 'Conversion Failed'.
      EXIT.
    ENDIF.

    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename = 'C:\Documents and Settings\Administrator\Desktop\venkat.pdf'
        filetype = 'BIN'
      TABLES
        data_tab = i_attachment.

  ENDIF.
*&---------------------------------------------------------------------*
*&      Form  F4_FOR_p_file
*&---------------------------------------------------------------------*
form f4_for_p_file changing file.
  data:
  l_field_name like  dynpread-fieldname value 'P_FILE'.


  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
      field_name    = l_field_name
    IMPORTING
      file_name     = p_file.

  file = p_file.
endform.                    " F4_FOR_p_file

1 comment:

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.