Google Search - Blog...........

Showing posts with label uploading csv files into ui element of tables.. Show all posts
Showing posts with label uploading csv files into ui element of tables.. Show all posts

ABAP - Upload CSV File Into A Table UI Element.

This Code snippet helps you to upload a .CSV file into a table UI element
First create a node of the same structure as the .CSV file and then bind it to a table in the layout and use the following coding in the On Action method of the Upload button that you have created.


begin of wa, " structure of the node/file
mandt type mandt,
matnr type matnr,
end of wa,
itab like table of wa,
rows type standard table of string , " will hold the entire contents
wa_rows(300) type c .
DATA lo_el_context TYPE REF TO if_wd_context_element.
DATA ls_context TYPE wd_this->element_context.
DATA lv_contents LIKE ls_context-contents.
* get element via lead selection
lo_el_context = wd_context->get_element( ).
* get single attribute
lo_el_context->get_attribute(
EXPORTING
name = `CONTENTS`
IMPORTING
value = lv_contents ).
DATA : loc_conv TYPE REF TO cl_abap_conv_in_ce,
var_string TYPE string, " holds the string value of the file
inst type ref to CL_SWF_UTL_CONVERT_XSTRING,
inst1 type ref to cl_abap_conv_in_ce.
CALL METHOD cl_abap_conv_in_ce=>create
EXPORTING
input = lv_contents
encoding = 'UTF-8'
replacement = '?'
ignore_cerr = abap_true
RECEIVING
conv = loc_conv.
CALL METHOD loc_conv->read
IMPORTING
data = var_string.
SPLIT var_string AT CL_ABAP_CHAR_UTILITIES=>CR_LF INTO TABLE ROWS.
LOOP AT ROWS INTO WA_ROWS .
split wa_rows at ',' into wa-mandt wa-matnr.
append wa to itab.
ENDLOOP.
DATA lo_nd_table TYPE REF TO if_wd_context_node.
DATA lo_el_table TYPE REF TO if_wd_context_element.
DATA ls_table TYPE wd_this->element_table.
* navigate from to via lead selection
lo_nd_table = wd_context->get_child_node( name = wd_this->wdctx_table ).
* get element via lead selection
lo_el_table = lo_nd_table->get_element( ).
lo_nd_table->bind_table( itab ).