Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Display a pop-up as PDF

Former Member
0 Kudos

Hi All,

I have a table control and in that I have an attachment icon to display PO item text. Requirement is if I click on that

The item text should be displayed as pdf pop-up. Any help on this..

Thanks

Asha

2 REPLIES 2

Former Member
0 Kudos

Hi Asha,

           I think below code will help you..

  

          DATA:
                mstr_print_params TYPE pri_params,
                 mc_valid(1)      TYPE c,
                 E_SPOOLID        TYPE  TSP01-RQIDENT.

*"  EXPORTING
    DATA:
  l_lay    TYPE pri_params-paart,
  l_lines  TYPE pri_params-linct,
  l_cols   TYPE pri_params-linsz.

*Types
  TYPES:
  t_pripar TYPE pri_params,
  t_arcpar TYPE arc_params.
  "Work areas
  DATA:
  l_pripar_line TYPE t_pripar,
  l_arcpar_line TYPE t_arcpar.
     DATA: lt_pdf TYPE TABLE OF tline,
      ls_pdf LIKE LINE OF lt_pdf,
      lv_url TYPE char255,
      lv_buffer TYPE string,
     lv_content  TYPE xstring,

      lt_data TYPE STANDARD TABLE OF x255,

     lo_dialog_container TYPE REF TO cl_gui_dialogbox_container,
     lo_html    TYPE REF TO cl_gui_html_viewer.

  l_lay   = 'X_65_132'.
  l_lines = 65.
  l_cols  = 160.


  "Read, determine, change spool print parameters and archive parameters
  CALL FUNCTION 'GET_PRINT_PARAMETERS'
    EXPORTING
      in_archive_parameters  = l_arcpar_line
      in_parameters             = l_pripar_line
      layout                        = l_lay
      line_count                  = l_lines
      line_size                    = l_cols
      no_dialog                   = 'X'
    IMPORTING
      out_archive_parameters = l_arcpar_line
      out_parameters             = mstr_print_params
      valid                  = mc_valid
    EXCEPTIONS
      archive_info_not_found = 1
      invalid_print_params   = 2
      invalid_archive_params = 3
      OTHERS                 = 4.
.
  SELECT * FROM znvta1
           INTO TABLE lt_znvtab1 UP TO 10 ROWS.
*--Generating the SPOOL with the Internal Table Data
  IF mc_valid NE space AND sy-subrc = 0.
    mstr_print_params-prrel = space.
    mstr_print_params-primm = space.


  NEW-PAGE PRINT ON PARAMETERS mstr_print_params NO DIALOG NO-TITLE NO-HEADING.
  ENDIF.
  LOOP AT lt_znvtab1 INTO wa_znvtab1.
    WRITE:/ wa_znvtab1-vbeln.
  ENDLOOP.
  e_spoolid = sy-spono.
  NEW-PAGE PRINT OFF.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
    EXPORTING
      src_spoolid              = e_spoolid
    TABLES
      pdf                      = lt_pdf
    EXCEPTIONS
      err_no_abap_spooljob     = 1
      err_no_spooljob          = 2
      err_no_permission        = 3
      err_conv_not_possible    = 4
      err_bad_destdevice       = 5
      user_cancelled           = 6
      err_spoolerror           = 7
      err_temseerror           = 8
      err_btcjob_open_failed   = 9
      err_btcjob_submit_failed = 10
      err_btcjob_close_failed  = 11
      OTHERS                   = 12.


FIELD-SYMBOLS: <Fs_x> TYPE x.

* convert pdf to xstring string
  LOOP AT lt_pdf INTO ls_pdf.
    ASSIGN ls_pdf TO <fs_x> CASTING.
    CONCATENATE lv_content <fs_x> INTO lv_content in BYTE MODE.
  ENDLOOP.

*  CREATE OBJECT lo_docking_container
*    EXPORTING
*      repid     = sy-repid
*      dynnr     = sy-dynnr
*      side      = lo_docking_container->dock_at_right
*      extension = 1200.

CREATE OBJECT   lo_dialog_container
  EXPORTING
*    parent                      =
    width                       = 150
    height                      = 150
*    style                       =
*    repid                       =
*    dynnr                       =
*    lifetime                    = lifetime_default
*    top                         = 0
*    left                        = 0
*    caption                     =
*    no_autodef_progid_dynnr     =
*    metric                      = 0
*    name                        =
  EXCEPTIONS
    cntl_error                  = 1
    cntl_system_error           = 2
    create_error                = 3
    lifetime_error              = 4
    lifetime_dynpro_dynpro_link = 5
    event_already_registered    = 6
    error_regist_event          = 7
    others                      = 8
    .

       CALL METHOD lo_dialog_container->set_visible
                  EXPORTING
                    visible           = ' '
*                  EXCEPTIONS
*                    cntl_error        = 1
*                    cntl_system_error = 2
*                    others            = 3
                        .
        IF sy-subrc <> 0.
*                 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.

IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

  CREATE OBJECT lo_html
    EXPORTING
      parent = lo_dialog_container.

* Convert xstring to binary table to pass to the LOAD_DATA method
  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer     = lv_content
    TABLES
      binary_tab = lt_data.

* Load the HTML
  lo_html->load_data(
    EXPORTING
      type         = 'application'
      subtype      = 'pdf'
    IMPORTING
      assigned_url         = lv_url
    CHANGING
      data_table           = lt_data
    EXCEPTIONS
      dp_invalid_parameter = 1
      dp_error_general     = 2
      cntl_error           = 3
      OTHERS               = 4 ).

* Show it
  lo_html->show_url( url = lv_url  in_place = 'X' ).

    CALL METHOD lo_dialog_container->set_visible
                  EXPORTING
                    visible           = 'X'
*                  EXCEPTIONS
*                    cntl_error        = 1
*                    cntl_system_error = 2
*                    others            = 3
                        .
        IF sy-subrc <> 0.
*                 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.

ENDCASE.

Thanks,

Nikita.

Former Member
0 Kudos

Hi,

       Please check this code .

   Please check below code and change bold letter's value's accordingly. 

                   

  •    SET PF-STATUS 'Y_PDF'.      " Cretae PF Status as below Screen Shot and Activate
  •   "   User Command to generate PDF Form

   AT USER-COMMAND.
  CASE SY-UCOMM.
    WHEN 'PDF'.
    DATA: L_PARAMS TYPE PRI_PARAMS,
            L_VALID TYPE STRING,
            W_SPOOL_NR LIKE TSP01-RQIDENT.
* TO GET PRINT PARAMETERS
      CALL FUNCTION 'GET_PRINT_PARAMETERS'
        IMPORTING
          OUT_PARAMETERS = L_PARAMS
          VALID          = L_VALID.
      IF SY-SUBRC <> 0.
      ENDIF.
* Internal table for Selection Screen
DATA: BEGIN OF I_RSPARAMS OCCURS 0.
       INCLUDE STRUCTURE RSPARAMS.
DATA: END OF I_RSPARAMS.
* Store the current selection screen details
CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
  EXPORTING
    CURR_REPORT           = SY-REPID
*IMPORTING
*   SP                    =
  TABLES
    SELECTION_TABLE       = I_RSPARAMS
*EXCEPTIONS
*   NOT_FOUND             = 1
*   NO_REPORT             = 2
*   OTHERS                = 3
          .
IF SY-SUBRC <> 0.
*MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*SUBMIT TO GET THE SPOOL NUMBER
SUBMIT YTEST123 WITH SELECTION-TABLE I_RSPARAMS   

" PUT your program name like m using my YTEST123 .


                TO SAP-SPOOL
                SPOOL PARAMETERS L_PARAMS
                WITHOUT SPOOL DYNPRO
                AND RETURN.
* SELECT THE RECENTLY CREATED SPOOL
      SELECT MAX( RQIDENT ) INTO W_SPOOL_NR FROM TSP01
              WHERE RQCLIENT = SY-MANDT
               AND   RQOWNER  = SY-UNAME.
* REPORT TO GENERATE SPOOL NUMBER FOR PDF CONVERT
      SUBMIT RSTXPDF5 WITH SPOOLNO  = W_SPOOL_NR
                WITH DSTDEVIC = 'LP01' AND RETURN .    

"  your output device name like LP01,   LOCL

'
      IF SY-SUBRC EQ 0.
        CLEAR W_SPOOL_NR.
* SELECT THE RECENTLY CREATED SPOOL FOR PDF
        SELECT MAX( RQIDENT ) INTO W_SPOOL_NR FROM TSP01
                 WHERE RQCLIENT = SY-MANDT
               AND   RQOWNER  = SY-UNAME.


* REPORT TO DOWNLOAD PDF SPOOL TO GUI
        SUBMIT RSTXPDFT5 WITH SPOOLID = W_SPOOL_NR
                 AND RETURN.
      ENDIF.
  ENDCASE.

Regard's

Smruti Ranjan