cancel
Showing results for 
Search instead for 
Did you mean: 

how to convert ABAPLIST to RTF or Excel file in WebDynpro?

tony_zheng
Explorer
0 Kudos

Hi all:

as you know, after we run a traditional program in SAPGUI backend, we could click List->Save/Send->File to save the result to a file, then a popup window will be shown to let user select which format the list to be saved (such as unconverted, Spreadsheet, Rich text format,HTML Format or In the clipboard). after user select one format, the corresponding download UI will be displayed (please refer to FM 'LIST_DOWNLOAD' for more details.).

Now I would like implement the same download function in Webdynpro, the following is the code for ABAPLIST to text file(call FM 'LIST_TO_TXT'), and I also know how to handle HTML format(call FM 'WWW_HTML_FROM_LISTOBJECT', but For Spreadsheet and RTF format, I could not find any FM to call (FM 'LIST_CONVERT_TO_DAT' and 'LIST_CONVERT_TO_RTF' are tightly coupled with dynpro with special parameters, and could not be used in Webdynpro like text or html format.)

Edited by: Tony Zheng on Apr 27, 2010 9:43 AM

Accepted Solutions (1)

Accepted Solutions (1)

ChrisPaine
Active Contributor
0 Kudos

Hi Tony,

you are very unlikely to ever have an "ABAPLIST" in a WebDynpro application - the whole point is that it looks much nicer than that!

Tha ALV functionality for displaying tables has built into it functionality for exporting to Excel and PDF. I would reccomend using that.

Or are you trying to build a WD view on a spool viewer for example?

Cheers,

Chris

ChrisPaine
Active Contributor
0 Kudos

Hi Tony,

looking at your code example I see now.

I don't know of anything to do this - I suggest you'd be better off posting in the generic ABAP forum - as it's not really a WD question on how to convert an ABAPLIST to an RTF (granted - you'd probably have lots of responses along the lines of the FMs you already have but that are dialog driven - but I think you'd get a better response.)

I would be tempted to rebuild the original program in WD ABAP rather than spending effort converting from a spool. But you know your situation best.

Cheers,

Chris

tony_zheng
Explorer
0 Kudos

hi Chris:

in my Webdynpor application, I get ABAPLIST from backend API. need convert this ABAPLIST to different file format to download. So my input parameter is exactly a ABAPLIST, and could not use ALV.

so I need find the corresponding basis API to do the format convertion.

the above code is the sample code for text format convertion I used, which submit a report to memory and get ABAPLIST from memory, then do the further processing.

thanks.

tony_zheng
Explorer
0 Kudos

hi Chris:

yes, it's not a really WD question. but a basis API question on how to convert ABAPLIST to excel or rtf format, which could be used in Webdynpro downloaded. So I posted this thread to ABAP general again.

I have found FM 'LIST_TO_TXT' for text format and 'WWW_HTML_FROM_LISTOBJECT'' for html format. but for excel and rtf format, FM 'LIST_CONVERT_TO_DAT' and 'LIST_CONVERT_TO_RTF' are dialog driven and it is not a pure API which could be reused. So I had to continue to find the solution.

thanks.

Answers (1)

Answers (1)

tony_zheng
Explorer
0 Kudos

the following is the code for donwload ABAPLIST as a text file in Webdynpro:

METHOD onactiondownload_txt_file . 

  DATA lv_filename TYPE string. 
  DATA lv_content TYPE xstring. 
  DATA lv_mine_type TYPE string. 

  DATA: lt_abaplist    TYPE TABLE OF abaplist, 
        lt_ascii       TYPE TABLE OF char255, 
        lt_html        TYPE soli_tab. 
  FIELD-SYMBOLS: 
        <ls_html>      TYPE soli. 
  DATA: lv_html_string TYPE string. 

  SUBMIT yas_study_abaplist_rep 
    EXPORTING LIST TO MEMORY AND RETURN. 

  CALL FUNCTION 'LIST_FROM_MEMORY' 
    TABLES 
      listobject = lt_abaplist 
    EXCEPTIONS 
      not_found  = 1 
      OTHERS     = 2. 
  CHECK sy-subrc = 0. 

  CALL FUNCTION 'LIST_TO_TXT' 
*   EXPORTING 
*     LIST_INDEX               = -1 
    TABLES 
      listtxt                  = lt_html 
     LISTOBJECT               = lt_abaplist 
*   EXCEPTIONS 
*     EMPTY_LIST               = 1 
*     LIST_INDEX_INVALID       = 2 
*     OTHERS                   = 3 
            . 


  LOOP AT lt_html ASSIGNING <ls_html>. 
    CONCATENATE lv_html_string <ls_html>-line INTO lv_html_string RESPECTING BLANKS. 
  ENDLOOP. 
  WRITE: lv_html_string. 


  DATA lv_html_xstring TYPE xstring. 
  CALL FUNCTION 'SCMS_STRING_TO_XSTRING' 
    EXPORTING 
      text           = lv_html_string 
*     MIMETYPE       = ' ' 
*     ENCODING       = 
     IMPORTING 
       buffer        = lv_html_xstring 
*   EXCEPTIONS 
*     FAILED         = 1 
*     OTHERS         = 2 
          . 

  lv_content = lv_html_xstring. 
  lv_filename = 'testfile'. 
  lv_mine_type = 'text/plain'. 

  cl_wd_runtime_services=>attach_file_to_response( 
    EXPORTING 
      i_filename      = lv_filename 
      i_content       = lv_content 
      i_mime_type     = lv_mine_type 
      i_in_new_window = abap_true 
      i_inplace       = abap_false 
*      i_in_new_window = abap_true "  this parameter means if open a new window 
*      i_inplace       = abap_true  " this parameter means if open the file right now in the old or new window. 
*      EXCEPTIONS 
*        others          = 1 
  ). 
ENDMETHOD.