Skip to Content
avatar image
Former Member

print contents of Table property to a pdf

When you use an ALV in abap web dynpro, there is a feature which allows the user to print the contents of the ALV table directly to a pdf. Does this facility exist for a regular 'table' property created in a web dynpro view? If not, any ideas on how this functionality could be emulated?

In my current application, i have the system users download the table to excel and print from there, however this extra step is cumbersome

thanks/d

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Jul 07, 2009 at 02:40 PM

    i don't think that ability comes with a regular table. Just like in normal abap, the ALV brings a ton of functionality with it that a table control doesn't have.

    it's easy enough, if you have the licenses, to populate a table and throw it into a PDF - either skipping the web dynpro screen and going straight to the PDF.. or by displaying your table, have the user click some button and generate your PDF based on the values of your table.

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 07, 2009 at 02:51 PM

    >If not, any ideas on how this functionality could be emulated?

    I created a little sample class method that prints any ABAP internal table via the old list ALV - but does so dark so that it can be ran from BSP or Web Dynpro ABAP.

    I originally wrote this for BSP, but it can be easily adjusted for Web Dynpro. The only main difference would the use of the Web Dynpro Message Manager instead of the BSP one. Here are the parameters of the method:

    ITAB Importing Type Ref To DATA

    COL_DEF Importing Type TABLEVIEWCONTROLTAB

    PRINT_OPTIONS Importing Type ZES_SFPPRIP

    MESSAGES Importing Type Ref To CL_BSP_MESSAGES

    ITAB is any ABAP internal table of data. COL_DEF is an optional internal table that you can use to deduce the number of columns or change their order - like a field catalog in classic ALV.

    PRINT_OPTIONS is a copy of SFPPRIP (so that I could this funcitonality on 6.20) For 7.0 I would just suggest using the standard strucutre. This is the print options structure for forms output. This is how you can specify the printer ID, number of copies, etc. MESSAGES is the BSP Message Manager, but you could replace this with the WDA one or not issue any messages at all (instead just raise an exception).

    Here is the coding:

    METHOD print.
    *@78\QImporting@  ITAB  TYPE REF TO DATA
    *@78\QImporting@  COL_DEF TYPE TABLEVIEWCONTROLTAB OPTIONAL STABLEVIEWCOLUMN
    *@78\QImporting@  PRINT_OPTIONS TYPE SFPPRIP  Form Processing: Print Parameters
    *@78\QImporting@  MESSAGES  TYPE REF TO CL_BSP_MESSAGES Business Server Pages (BSP) Messages
    
      FIELD-SYMBOLS: <tab> TYPE table.
      ASSIGN itab->* TO <tab>.
    
    ****This sample uses the new ALV Object Model - Only available in WebAS 640+
    ****It will have to be changed (perhaps to use field catalogs and REUSE_ALV)
    ****in WebAS 620
      DATA: table   TYPE REF TO cl_salv_table.
      DATA: print_parameters TYPE pri_params,
            valid_flag(1) TYPE c.
    
    ****Convert the Input Print Parameters (Designed for Adobe Forms)
    ****Into the ABAP List format
      CALL FUNCTION 'GET_PRINT_PARAMETERS'
        EXPORTING
          authority              = print_options-authority
          copies                 = print_options-copies
          cover_page             = print_options-cover
          data_set               = print_options-dataset
          department             = print_options-division
          destination            = print_options-dest
          expiration             = print_options-lifetime
          immediately            = print_options-reqimm
          layout                 = 'X_65_255'
          list_name              = print_options-suffix2
          list_text              = print_options-covtitle
          new_list_id            = print_options-reqnew
          no_dialog              = abap_true
          receiver               = print_options-receiver
          release                = print_options-reqdel
        IMPORTING
          out_parameters         = print_parameters
          valid                  = valid_flag
        EXCEPTIONS
          archive_info_not_found = 1
          invalid_print_params   = 2
          invalid_archive_params = 3
          OTHERS                 = 4.
      IF sy-subrc <> 0 OR valid_flag NE abap_true.
        messages->add_message2( condition = 'print'
                                message = 'Invalid Print Parameters'(e01) ).
        RETURN.
      ENDIF.
    
    ****Start List Processing with our Print Parameters
      NEW-PAGE PRINT ON PARAMETERS print_parameters
                        NO DIALOG.
    
    ****Create the ALV Object Model
      DATA: salv_msg TYPE REF TO cx_salv_msg.
      DATA: error_string TYPE string.
      TRY.
          cl_salv_table=>factory(
            EXPORTING
              list_display = abap_true
            IMPORTING
              r_salv_table = table
            CHANGING
              t_table      = <tab> ).
        CATCH cx_salv_msg INTO salv_msg.
          messages->add_message_from_exception( condition = 'print'
                                                exception = salv_msg ).
          EXIT.
      ENDTRY.
    
    ****Process the Column Definitions
      DATA: columns TYPE REF TO cl_salv_columns_table.
    
    ****Get a reference to the columns object and set the optimize width.
      columns = table->get_columns( ).
      columns->set_optimize( abap_false ).
    
      DATA: l_col_def TYPE tableviewcontroltab.
    ****We have an iterator Class - Process it and get a columun defintion table
      IF col_def  IS NOT INITIAL.
        l_col_def = col_def.
      ENDIF.
    
    ****Adjust our column definition (otherwise know as Field Catalog) by the
    ****Column Dfinition table.
      IF l_col_def IS NOT INITIAL.
        DATA: scrtext_l TYPE scrtext_l,
              scrtext_m TYPE scrtext_m,
              scrtext_s TYPE scrtext_s,
              tooltip   TYPE lvc_tip.
        DATA: col TYPE salv_t_column_ref.
        FIELD-SYMBOLS: <wa_col> LIKE LINE OF col,
                       <wa_col_def> LIKE LINE OF l_col_def.
    ****Get a listing of all columns
        col = columns->get( ).
    ****Loop through all the columsn
        LOOP AT col ASSIGNING <wa_col>.
    ****Read to see if the current columns is in our Iterator
          READ TABLE l_col_def ASSIGNING <wa_col_def>
                WITH KEY columnname = <wa_col>-columnname.
          IF sy-subrc = 0.
    ****Field is in the iterator - set it visible.
            <wa_col>-r_column->set_visible( abap_true ).
    ****Is there an override title in the Iterator - if yes
    ****use it for all the column headers of the output
            IF <wa_col_def>-title IS NOT INITIAL.
              scrtext_l = <wa_col_def>-title.
              scrtext_m = <wa_col_def>-title.
              scrtext_s = <wa_col_def>-title.
              <wa_col>-r_column->set_long_text( scrtext_l ).
              <wa_col>-r_column->set_medium_text( scrtext_m ).
              <wa_col>-r_column->set_short_text( scrtext_s ).
            ENDIF.
    ****Is there an override tooltip in the Interator - if yes
    ****ues it for the tooltip of the output (actually meaningless
    ****for only printing - but hey you never know what you might
    ****use this for in the future :)
            IF <wa_col_def>-tooltipheader IS NOT INITIAL.
              tooltip = <wa_col_def>-tooltipheader.
              <wa_col>-r_column->set_tooltip( tooltip ).
            ENDIF.
          ELSE.
    ****Field is not in the Iterator - Hide it in the output
            <wa_col>-r_column->set_visible( abap_false ).
          ENDIF.
        ENDLOOP.
      ENDIF.
    
    ****Set the ALV to display (forces printing in the Dark = background or BSP)
      table->display( ).
      NEW-PAGE PRINT OFF.
    
      messages->add_message2( condition   = 'print'
                              message     = 'Print Output is complete'(i01)
                              messagetype = 'I' ).
    
    
    ENDMETHOD.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      thanks for the replies and suggestions. i will do a custom solution based on your feedback

      /cheers!