cancel
Showing results for 
Search instead for 
Did you mean: 

Print internal table

Former Member
0 Kudos

Hi ,

I have created a view with a table inside. This table is bound to a node that contains data from a service

call.

The view is embeded in the window and the data in the table can be displayed on the screen. I would like

to print this table. How do I code this? Please give me suggestions.

ps. I don't want to display in ALV format.

Thanks,

AS.

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Anna,

Try check this [article here|http://www.sapdev.co.uk/sap-webapps/sap-webdynpro/wdp_printtable.htm]. It discusses the same.

Regards,

Uday

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

The article that you link to appears to be a direct copy of the source code that I wrote and published here on SCN. It is also available for download from this google code page:

http://abap-sdn-examples-tpj.googlecode.com/files/NUGG_WEB_PRINT_TABLE.nugg

uday_gubbala2
Active Contributor
0 Kudos

Hi Thomas,

I was actually first trying to pull out your article but couldn't manage to find it. I remember seeing a copy of the same in sapdev and so passed on the plagiarism!

Former Member
0 Kudos

Hello Thomas, Bala, and everyone,

Thanks for your help!

I have read the thread on the site and it helped me a lot.

https://forums.sdn.sap.com/click.jspa?searchID=19966169&messageID=6264121

I now created 2 methods in component controller fill_data( ) and print( ).

In the view controller, I call the fill_data( ) and pint( ) methods. The data is populated into the table

and displayed on the screen, but it doesn't print the table for me. Do I have to choose which printer it

should send to or I missed some steps?

Please advise.

Thanks,

AS.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

If you aren't asking the user for some print parameters and passing them into your print method then it will fall back to the user default parameters. If this is the case then make sure there is a default printer and that the user has print immediately set in the printer defaults. Otherwise if you check the spool you should find the pending print request there. I personally popup a little printer dialog window (reusable WDA component) to ask the user to set their print parameters and pass those into the print method. Also keep in mind that any frontend printers setup will not funciton since there is no connection to a SAPGUI.

Former Member
0 Kudos

Hi Thomas,

I would like to have a popup dialog window to ask the user to set their print parameters and pass those into the print method as well.

Would you tell me what WDA component I should use? Would you give me some guidance? I am new Web dynpro programmer.

Thanks,

AS.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

There is no standard component that I know of. I had built my own. It doesn't take long. Just expose the fields from the print parameters interface of the print method.

Former Member
0 Kudos

Hi Thomas,

Can I simply create a pop up window and prompt user to enter the printer

information? After I get the information, I then pass them to the print method.

Thanks,

AS.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Sure, it doesn't have to be complicated. Although something like a printer dialog would be pretty reusable, that is why I suggested a reusable component.

Former Member
0 Kudos

Hi Thomas,

I have created a view and a popup window. In this view context, I created a node that is bound to SFPPRIP structure.

I have user to enter output device (DEST) .

I don't know how to declear it_message and print_options to make the method PRINT to work.

Could you look at the code below and give me some suggestions on the input for the print method?


method GET_PRINT_PARAM .
* get print input
  data: context_node type ref to if_wd_context_node,
          elem_print type ref to if_wd_context_element,
          stru_print type if_componentcontroller=>element_printing,
          item_dest like stru_print-dest.

  context_node = wd_context->get_child_node( name = 'PRINTINT' ).
  elem_print = context_node->get_element( ).

  elem_print->get_attribute(
    exporting
      name = 'DEST'
    importing
      value = item_dest ).

*   fill the internal table
 data: elem_sflightinfo type ref to if_wd_context_element,
         stru_sflightinfo type table of if_componentcontroller=>element_sflightinfo initial size 0,
         w_itab           like line of stru_sflightinfo.

     context_node = wd_context->get_child_node( name = 'SFLIGHTINFO').

     select * from sflight
      into corresponding fields of table stru_sflightinfo.

* BIND table to context node flighttab
  call method context_node->bind_table
    exporting
      new_items = stru_sflightinfo.

* for print method
data: it_out type ref to data,
        it_message type ref to CL_BSP_MESSAGES. "I know it is wrong, but what should I use?

get reference of stru_sflightinfo into it_out.

  wd_this->print(
*   col_def =                              " tableviewcontroltab
    itab     =  it_out                      " ref to data
*   iterator =                               " ref to if_htmlb_tableview_iterator
    messages =   it_message      " ref to cl_bsp_messages(wrong. but what to pass?) 
    print_options = item_dest     " sfpprip  (I know it is wrong, but don't know what to pass?)
  ).

endmethod.

PRINT method


method PRINT .
  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.
  DATA: iterator_error TYPE REF TO cx_sy_dyn_call_illegal_method.
****We have an iterator Class - Process it and get a columun defintion table
  IF col_def  IS INITIAL AND
     iterator IS NOT INITIAL.
    DATA: p_overwrites TYPE tableviewoverwritetab.
    TRY.
        iterator->get_column_definitions(
             EXPORTING
               p_tableview_id = 'itab'
             CHANGING
               p_column_definitions = l_col_def
               p_overwrites         = p_overwrites ).
      CATCH cx_sy_dyn_call_illegal_method INTO iterator_error.
        messages->add_message_from_exception( condition = 'print'
                                              exception = iterator_error ).
        EXIT.
    ENDTRY.
*****User supplied a column definition table directly - us it
  ELSEIF col_def  IS NOT INITIAL.
    l_col_def = col_def.
  ENDIF.

****Adjust our column definition (otherwise know as Field Catalog) by the
****Iterator or 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.

Your help is greatly appreciated.

AS.

Edited by: Anna Smith on Dec 18, 2008 4:25 PM

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

First I would suggest adjusting the it_message parameter on the print method. Right now it expects the BSP message manager since this code originally came from BSP. I would either remove this parameter and all usage of it in the code or adjust this code sample to use the Web Dynpro message manager class instead.

For print_options, I used a custom ddic structure named zes_sfpprip. I did this because the original sample was used in the Advanced BSP Programming book and we wanted the code samples to work on 6.20 and the SAP data type SFPPRIP didn't exist on that release. Therefore we created a z-copy of the structure. Since you are working on 7.0 obviously - you can just change the print method interface to use SFPPRIP and save yourself the trouble.

Former Member
0 Kudos

Hi Thomas,

Thank you so much for your reply.

I have actually commented out the message in my code and declared it_option as SFPPRIP type.

I just get stuck on the it_option. it is empty now and I don't know what value I should assign to it so that

it fulfills the 'GET_PRINT_PARAMETERS' function.


  wd_this->print(
*   col_def          =                       " tableviewcontroltab
    itab               = it_out              " ref to data
*   iterator          =                       " ref to if_htmlb_tableview_iterator
    messages     = it_message     " ref to cl_bsp_messages
    print_options = it_option          " sfpprip

 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
...

Sincerely appreciate your help.

AS.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I'm not sure I understand your question. it_option would hold your printer parameters - like what printer you want to send the output to, the number of copies, etc. You can look at the structure SFPPRIP to see what options are available. These are the options you would show to the user in the printer dialog, then copy them into it_option and pass them into the print method to control the output.

Former Member
0 Kudos

Thanks, Thomas.

The following is the print_options's parameters. I want to assign values such as authority, copies, cover,

dataset, division, dest, lifetime, reqimm, suffix2, covtitle, reqnew,receiver, and reqdel to it_options to fulfill

the function, but I am now sure what I should provide here. This is my first web dynpro project and I have no experience with this.


 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.

I want to make all the values default except the print_options-dest and print_options-copies.

Could you give me some suggestions?

Thanks,

AS.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>I want to make all the values default except the print_options-dest and print_options-copies.

I still confess that I don't exactly understand where the problem is. If you want to pass in some default values, then just hardcode values for the rest of the print_options. Put dest and copies into some dialog to query the user for those values. Maybe I'm missing the core of your question.

Former Member
0 Kudos

Hi Thomas,

Sorry for not explaining my question well.

I am now trying to hard code the values for print_option-authority, print_option-cover, print_option-dataset, etc and have user to enter print_option-dest and print_option-copies. However, what should I hard code for print_option-authority, print_option-cover ... ?

Thanks,

AS.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Here are the defaults that I used. Some I look up from the user settings. Not every field in the structure has to be supplied a value.

constants: lc_usr01_delete type usr01-spda value 'D',
               lc_usr01_immed  type usr01-spdb value 'G'.
  data:      l_usr01         type usr01.
  constants:   c_default(1)        type        c                 value '*'.

* read user defaults
  select single * from usr01 into l_usr01
                             where bname = sy-uname.
  if sy-subrc = 0.
    if l_defaultparams is not initial.
*   output device
      if l_defaultparams->dest is initial or l_defaultparams->dest = c_default.
        l_defaultparams->dest = l_usr01-spld.
      endif.

*   flag delete after print
      if l_defaultparams->reqdel = c_default or
         l_defaultparams->reqdel is initial.
        if l_usr01-spda = lc_usr01_delete.
          l_defaultparams->reqdel = abap_true.
        else.
          l_defaultparams->reqdel = abap_false.
        endif.
      endif.

*   print immediately
      if l_defaultparams->reqimm = c_default or
         l_defaultparams->reqimm is initial.
        if l_usr01-spdb = lc_usr01_immed.
          l_defaultparams->reqimm = abap_true.
        else.
          l_defaultparams->reqimm = abap_false.
        endif.
      endif.

*   parameters valid?
      if l_defaultparams->reqdel <> abap_true.
        l_defaultparams->reqdel = abap_false.
      endif.
      if l_defaultparams->reqimm <> abap_true.
        l_defaultparams->reqimm = abap_false.
      endif.

* set reasonable values if there are still some defaults left
      if l_defaultparams->reqdel = c_default.
        l_defaultparams->reqdel = abap_false.
      endif.
      if l_defaultparams->reqimm = c_default.
        l_defaultparams->reqimm = abap_false.
      endif.
      if l_defaultparams->dest = c_default.
        clear l_defaultparams->dest.
      endif.

    else.
*   output device
      if defaultparams-dest is initial or defaultparams-dest = c_default.
        defaultparams-dest = l_usr01-spld.
      endif.

*   flag delete after print
      if defaultparams-reqdel = c_default or
         defaultparams-reqdel is initial.
        if l_usr01-spda = lc_usr01_delete.
          defaultparams-reqdel = abap_true.
        else.
          defaultparams-reqdel = abap_false.
        endif.
      endif.

*   print immediately
      if defaultparams-reqimm = c_default or
         defaultparams-reqimm is initial.
        if l_usr01-spdb = lc_usr01_immed.
          defaultparams-reqimm = abap_true.
        else.
          defaultparams-reqimm = abap_false.
        endif.
      endif.

*   parameters valid?
      if defaultparams-reqdel <> abap_true.
        defaultparams-reqdel = abap_false.
      endif.
      if defaultparams-reqimm <> abap_true.
        defaultparams-reqimm = abap_false.
      endif.

* set reasonable values if there are still some defaults left
      if defaultparams-reqdel = c_default.
        defaultparams-reqdel = abap_false.
      endif.
      if defaultparams-reqimm = c_default.
        defaultparams-reqimm = abap_false.
      endif.
      if defaultparams-dest = c_default.
        clear defaultparams-dest.
      endif.
    endif.
  endif.

Former Member
0 Kudos

Hi Thomas,

The issue has been resolved.

Thank you very much for your help!

Merry Christmas and Happy New Year!

AS.

Answers (2)

Answers (2)

Former Member
0 Kudos

hi

in this u have to use code wizard

1 first take values from database table into internal table.

2.then bind this table to context node of the table .

3.when u bind internal table to context node of table the values r automatically reflected.

i hope u understand

Regards reeha

Former Member
0 Kudos

Anna,

check this thread you may get some idea

https://forums.sdn.sap.com/click.jspa?searchID=19966169&messageID=6264121

Thanks

Bala Duvvuri