Quantcast
Channel: SCN : All Content - Web Dynpro ABAP
Viewing all articles
Browse latest Browse all 3667

Downloading Table UI Element Date in Webdynpro

$
0
0

Hi Guys,

Here is an example which shows how data displayed in Table UI element can downloaded.

 

  1. Design the Webdynpro component as shown below
  2. Create a Node: MARA with 0:N Cardinality in  Component Controller Context

 

View:

 



3. Map the context of Component Controller to View Controller Context and write the below code in WDDOINIT method to fill Table with data

   METHOD wddoinit .

DATA lo_nd_material TYPE REF TO if_wd_context_node.
DATA lo_el_material TYPE REF TO if_wd_context_element.
DATA lt_material TYPE wd_this->elements_material.

lo_nd_material
= wd_context->get_child_node( name = wd_this->wdctx_material ).

SELECT * FROM mara
INTO TABLE lt_material
UP TO 25 ROWS.

IF lt_material[] IS NOT INITIAL.
lo_nd_material
->bind_table( lt_material ).
ENDIF.

ENDMETHOD.


4. Create action for button DOWNLOAD_DATA and write the below code

  METHOD onactiondownload_data.
** Read the Table UI Element data into Internal Table
DATA lo_nd_material TYPE REF TO if_wd_context_node.
DATA lo_el_material TYPE REF TO if_wd_context_element.
DATA ls_material TYPE wd_this->element_material.
DATA lt_mara TYPE wd_this->elements_material.
DATA ls_mara LIKE LINE OF lt_mara.
DATA lv_record TYPE string.

lo_nd_material
= wd_context->get_child_node( name = wd_this->wdctx_material ).
lo_nd_material
->get_static_attributes_table( IMPORTING table = lt_mara ).

** Move all the contents of Internal Table to String Variable
IF lt_mara[] IS NOT INITIAL.
LOOP AT lt_mara INTO ls_mara.
CONCATENATE lv_record
ls_mara
-matnr
ls_mara
-ersda
ls_mara
-ernam
ls_mara
-laeda
ls_mara
-aenam
cl_abap_char_utilities
=>newline
INTO lv_record
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
CLEAR ls_mara.
ENDLOOP.
ENDIF.

** Move the String Value to the XSTRING Value
data: lv_xstring type xstring.


CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text          lv_record
IMPORTING
BUFFER         lv_xstring
EXCEPTIONS
FAILED        
= 1
OTHERS         = 2
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

wdr_task
=>client_window->client->attach_file_to_response(
I_FILENAME
= 'TableData.XLS'
I_CONTENT  
= lv_xstring
I_MIME_TYPE  
= 'EXCEL' ).

5. Save,Activate and create the webdynpro application.


 

 

 

6. Once clicked on ‘Download Data’ button the below popup appears

 

 

 

 

Below is the excel data downloaded from the table ui element




Regards,

Rafi


Viewing all articles
Browse latest Browse all 3667

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>