Skip to Content
avatar image
Former Member

SALV to spool

Hi All,

I have developed an ALV report using SALV (cl_salv_table=>factory) . The requirement is to download the ALV output to PDF.

Inorder to achieve this I will have to write the output to the spool and then convert the spool to PDF.

Please do let me know how the ALV output can be written to spool.

Thanks,

Maansi

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Jul 28, 2010 at 07:16 AM

    Hi Maansi,

    We had a discussion on extracting spool no here

    Regards

    Marcin

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Maansi,

      I was thinking a while about your issue. It seems that when you call method set_print_only outside method handler your ALV is send to spool, otherwise (when called within that method) it doesn't even seem to execute "print" command, so the spool is never generated. The problem in first solution is that just right after calling set_print_only you are not able to do any further processing (the program simply doesn't reach next statement), so you are not able to download your spool to PDF afterwards.

      Anyhow I found different solution. See below

      "let's say your program calls Z_ALV_PRINT.
      ...
      METHOD on_user_command.
          ...
          CASE e_salv_function.
            WHEN 'PDF'.
      "when PDF button pressed, set flag in ABAP memory requesting print command
              EXPORT flag = 'X' TO MEMORY ID 'DO_PRINT'.  
      
      "and submit your report again to perfrom just PRINT 
              SUBMIT Z_ALV_PRINT AND RETURN.
      
      "here the processing is back after the print has been send to spool, 
      "now you are able to select latest spool entry to get that number
              SELECT MAX( rqident ) INTO g_spool FROM tsp01
                                        WHERE rqclient = sy-mandt
                                        AND   rqowner  = sy-uname.
      "...here download to PDF
          ENDCASE.
        ENDMETHOD. 
      ENDCLASS.              
      
      "normaly report will display ALV on screen, but when submited with flag set
      "it will do a print to spool instead
      START-OF-SELECTION.
        SELECT * INTO CORRESPONDING FIELDS OF TABLE ispfli FROM spfli UP TO 100 ROWS.
        CALL METHOD cl_salv_table=>factory
          IMPORTING
            r_salv_table = gr_table
          CHANGING
            t_table      = ispfli.
        
        gr_table->set_screen_status( pfstatus = 'SALV_TABLE_STANDARD'
      ...
      
      "now import flag from ABAP memory and see if print requested, 
      "if so do a print, not a table display 
      
        DATA: g_flag TYPE c.
        IMPORT flag = g_flag FROM MEMORY ID 'DO_PRINT'.
        
        IF g_flag = 'X'.
          lo_print = gr_table->get_print( ).
          " get print parameters
          CALL FUNCTION 'GET_PRINT_PARAMETERS'
            EXPORTING
              no_dialog              = 'X'
            IMPORTING
              valid                  = gw_valid
              out_parameters         = gw_pparams
            EXCEPTIONS
              archive_info_not_found = 1
              invalid_print_params   = 2
              invalid_archive_params = 3
              OTHERS                 = 4.
      
          CONCATENATE 'test' sy-datum sy-uzeit INTO gw_pparams-prtxt SEPARATED BY space.
       
          lw_print_ctrl = lo_print->get_print_control( ).
          lw_print_ctrl-pri_params = gw_pparams.
          lo_print->set_print_control( lw_print_ctrl ).
          lo_print->set_print_only( if_salv_c_bool_sap=>true ).
      
      "free the flag in memory
          FREE MEMORY ID 'DO_PRINT'.
        ENDIF.
      
        gr_table->display( ).
      

      As descirbed in the comments: normally report will show ALV display, but when flag is set the print to spool will be done.

      So in fact you are executing the print in "fly" and when you back from the print program you can get latest spool no and use that one to download the results to pdf.

      Works fine, tested 😊

      Regards

      Marcin

  • Jul 27, 2010 at 07:58 AM

    This works excatly the same as with OO ALV in background. To export its content to spool in ABAP List format you need to pass empty docking container as parent

    DATA: r_dock TYPE REF TO cl_gui_docking_container,
          r_salv TYPE REF TO cl_salv_table.
    
    DATA: it_sflight TYPE TABLE OF sflight.
    
    INITIALIZATION.
      SELECT * FROM sflight INTO TABLE it_sflight UP TO 10 ROWS.
    
    
    START-OF-SELECTION.
      CALL SCREEN 100.
    
    
    MODULE pbo OUTPUT.
      IF sy-batch = 'X'.
        "initial docking container  as parent
        CALL METHOD cl_salv_table=>factory
          EXPORTING
            r_container  = r_dock
          IMPORTING
            r_salv_table = r_salv
          CHANGING
            t_table      = it_sflight.
      ENDIF.
    
      r_salv->display( ).
    
    ENDMODULE.                    
    

    Now pick your spool no and pass it to program RSTXPDFT4 . It will do necessary conversion for you.

    Regards

    Marcin

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Marcin,

      I did it as mentioned by you, but the spool number is not getting populated. here is my code:

      DATA: gr_dock TYPE REF TO cl_gui_docking_container.
      
        TRY.
            CALL METHOD cl_salv_table=>factory
               EXPORTING
                r_container  = gr_dock
              IMPORTING
                r_salv_table = gr_table
              CHANGING
                t_table      = xt_output.
          CATCH cx_salv_msg.                                  "#EC NO_HANDLER
        ENDTRY.
      ..........
      gr_table->display( ).
      g_spool = sy-spono.           " Here the spool number is '0'. 
      
      

      Please let me knw how can I get the spool number.

      Thanks,

      Maansi.

  • avatar image
    Former Member
    Jul 27, 2010 at 08:04 AM

    Hi Maansi,

    Get the Spool request id from tsp01 using the user id and client

    Pass the Spool id to the FM: CONVERT_ABAPSPOOLJOB_2_PDF

    Then, Use the function "GUI_DOWNLOAD" to download the generated PDF.

    Check the below Link

    [http://www.sapdev.co.uk/reporting/rep_spooltopdf.htm]

    Edited by: Raj on Jul 27, 2010 1:37 PM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 28, 2010 at 06:44 AM

    Hi Maansi,

    Please visit these links.

    I guess it will give you answer to your problem.

    1. [Spool 1|Convert ABAP Report's Output into PDF Format..;

    2. [Spool 2|creating spool before displaying output;

    May it helps you.

    Regards.

    DS.

    Add comment
    10|10000 characters needed characters exceeded