cancel
Showing results for 
Search instead for 
Did you mean: 

dowload data in table ui element to ms excel and append row delete row func

sahai
Contributor
0 Kudos

hello all,

in a requirement of mine i have a table ui element with me ...the data is being displayed in it but now i want my data to be downloaded in ms excel ...also i have to append row ...........

i s there any standard class availiable for it such as availiable in alv or i will have to code for them seperately if later is the case kindly help me in this with codes for the same.

thanks and regards,

sahai.s

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Sahai,

You need to convert your data to XSTRING.

Following code is for your referrence:-

loop at LT_SFLIGHT into LS_SFLIGHT.

concatenate TEXT LS_SFLIGHT-CARRID

LS_SFLIGHT-CONNID

LS_SFLIGHT-FLDATE

LS_SFLIGHT-CURRENCY

LS_SFLIGHT-PLANETYPE

CL_ABAP_CHAR_UTILITIES=>NEWLINE into TEXT separated by

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.

endloop.

call function 'SCMS_STRING_TO_XSTRING'

exporting

TEXT = TEXT

importing

BUFFER = XTEXT.

WDR_TASK=>CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE(

**path to the word file

I_FILENAME = 'WDP.xls'

  • String Variable

I_CONTENT = XTEXT

  • File Type

I_MIME_TYPE = 'EXCEL' ).

Another way to convert the string to xstring:-

METHOD convert_file .

CONSTANTS

lc_utf TYPE abap_encoding VALUE 'UTF-8'.

DATA:

lv_string TYPE string,

lr_conv TYPE REF TO cl_abap_conv_out_ce.

lr_conv = cl_abap_conv_out_ce=>create( encoding = lc_utf ).

lr_conv->convert( EXPORTING data = i_xml IMPORTING buffer = r_xml ).

ENDMETHOD.

And for append a row do as given in the link provided by Sarbjeet .

Thanks & Regards,

Monishankar C

Former Member
0 Kudos

Hi Sahai,

To upload data from table to excel.. please check this wiki..

http://wiki.sdn.sap.com/wiki/display/WDABAP/Downloadafileintoexcel+sheet.

Cheers..

Kris.

gill367
Active Contributor
0 Kudos

HI

CODE FOR EXPORTING TO EXCEL

i have wrotten it for my table which is bound to a node named "ZDEALER" with attributes ID, NAME, LOCATION, STAUS

you can make the required changes.


    data LO_ND type ref to IF_WD_CONTEXT_NODE.
  data LO_EL type ref to IF_WD_CONTEXT_ELEMENT.
  data LT type WD_THIS->ELEMENTS_ZDEALER.
  data LS type WD_THIS->ELEMENT_ZDEALER.
data STR    type STRING.
  data XSTR  type XSTRING.

  LO_ND = WD_CONTEXT->GET_CHILD_NODE( NAME = 'ZDEALER' ).

  LO_ND->GET_STATIC_ATTRIBUTES_TABLE(
    importing
      TABLE = LT ).
  loop at LT into LS.    concatenate str LS-ID
                LS-NAME
                LS-LOCATION
                LS-STATUS
               CL_ABAP_CHAR_UTILITIES=>NEWLINE into str separated by
                CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.  endloop.
 
call function 'SCMS_STRING_TO_XSTRING'
    exporting
      TEXT   = STR
    importing
      BUFFER = XSTR.

CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE(
**path to the word file
    I_FILENAME = 'WDP.xls'
* String Variable
    I_CONTENT =  XSTR
* File Type
    I_MIME_TYPE = 'EXCEL' ).

also for appending a row write a logic like as suggested in

this for inserting i guess you can make the required changes

thanks

sarbjeet singh

sahai
Contributor
0 Kudos

hi sarb,

thanks for answering .....i already tried this code but the problem as that my ztable has some field of type int4..

loop at LT into LS.    concatenate str LS-ID
                LS-NAME
                LS-LOCATION
                LS-STATUS
               CL_ABAP_CHAR_UTILITIES=>NEWLINE into str separated by
                CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.  endloop.

so this will be a problem as int4 is not supported by string so i will have to change the data type to n any syuggestion? regarding this?

also do tell me using a table ui element is a good option or table ui element will do...i chose table ui element because it is easier to code...what say ?

regards,

sahai.s

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

> so i will have to change the data type to n any syuggestion

For these fields just perform a WRITE into a character based field. Then concatenate in the temporary character based field.

>i chose table ui element because it is easier to code...what say ?

Are you saying you choose the table over the ALV because it is easier to code? That is probably a poor reason to avoid ALV (which isn't really difficult to program). I was kind of wondering why you wouldn't just use the Excel download of the ALV.