Also der Abfrageteil im Java, den hat der Kollege neben mir geschrieben. Da kann ich nicht helfen.
Aber der Return lässt sich so realisieren.
RFC - fähiger Funktionsbaustein zum lesen beliebiger transparenter Tabellen
mit XML-Ausgabe
Import
Tabelle z.B. 'MARA'
Felder die gelesen werden sollen 'ERNAM ERDAT'
Export
Fehler wenn > 0
Die Optiontabellen
ta_sopt1 'I' EQ' '20000101' 20001231'
Where tabelle
(und ab hier gehts los ohne das Wort WHERE!)
erdat in ta_sopt1
and matnr like '12345%'
TA_RESULT ist XML
WICHTIG:
In Java erst nach <lines> parsen und dann die XML-Daten parsen!
function z_getdata.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(TABNAME) TYPE TABNAME
*" VALUE(FIELDLIST) TYPE DI_DATA DEFAULT '*'
*" EXPORTING
*" VALUE(ERROR) TYPE SY-SUBRC
*" TABLES
*" TA_WHERE STRUCTURE ABAPSOURCE
*" TA_SOPT1 STRUCTURE JBRVALRAN OPTIONAL
*" TA_SOPT2 STRUCTURE JBRVALRAN OPTIONAL
*" TA_SOPT3 STRUCTURE JBRVALRAN OPTIONAL
*" TA_SOPT4 STRUCTURE JBRVALRAN OPTIONAL
*" TA_SOPT5 STRUCTURE JBRVALRAN OPTIONAL
*" TA_RESULT STRUCTURE RTXTLDAT
*"----------------------------------------------------------------------
* HK 07.05.2009 Allgemeiner Datenleser für transparente Tabellen
* HK 16.07.2009 Code gestrafft
*
type-pools: slis,
ixml.
types : begin of ty_katalog,
position type tabfdpos,
fieldname type fieldname,
end of ty_katalog.
data : my_cursor type cursor,
my_cursor1 type cursor,
my_client(1) type c,
field_type(1) type c,
ta_katalog type table of ty_katalog,
l_structure type ref to data,
l_table type ref to data,
struc_desc type ref to cl_abap_structdescr,
ls_lvc_fcat type lvc_s_fcat,
lt_lvc_fcat type lvc_t_fcat,
l_ixml type ref to if_ixml,
l_encoding type ref to if_ixml_encoding,
l_streamfactory type ref to if_ixml_stream_factory,
l_ostream type ref to if_ixml_ostream,
l_renderer type ref to if_ixml_renderer,
l_document type ref to if_ixml_document,
l_xml_size type i,
l_rc type i,
l_string(256) type c,
l_element_000 type ref to if_ixml_element,
l_element_001 type ref to if_ixml_element,
l_element_dummy type ref to if_ixml_element,
l_tag_c(256) type c,
l_tag type string,
l_value_c(256) type c,
l_value type string.
field-symbols : <it_table> type standard table,
<dyn_str> type any,
<str_comp> type abap_compdescr,
<dyn_wa> type any,
<dyn_fi> type any,
<katalog> type ty_katalog.
* CALL FUNCTION 'VIEW_AUTHORITY_CHECK'
* EXPORTING
* view_action = 'S'
* view_name = tabname
* EXCEPTIONS
* no_authority = 2
* no_clientindependent_authority = 2
* no_linedependent_authority = 2
* OTHERS = 1.
* error = sy-subrc.
* CHECK error = 0.
refresh : ta_result, ta_katalog.
open cursor my_cursor
for
select position fieldname
from dd03l
where tabname = tabname
and as4local = 'A'
and intlen > 0.
fetch next cursor my_cursor
into corresponding fields of table ta_katalog.
error = sy-subrc.
close cursor my_cursor.
check error = 0.
sort ta_katalog by position.
loop at ta_katalog assigning <katalog>.
<katalog>-position = sy-tabix.
endloop.
if fieldlist <> '*'.
loop at ta_katalog assigning <katalog>.
find <katalog>-fieldname in fieldlist.
if sy-subrc <> 0.
delete ta_katalog.
endif.
endloop.
endif.
create data l_structure type (tabname).
assign l_structure->* to <dyn_str>.
struc_desc ?= cl_abap_typedescr=>describe_by_data( <dyn_str> ).
loop at struc_desc->components assigning <str_comp>.
ls_lvc_fcat-fieldname = <str_comp>-name.
ls_lvc_fcat-ref_table = tabname.
append ls_lvc_fcat to lt_lvc_fcat.
endloop.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = lt_lvc_fcat
importing
ep_table = l_table.
assign l_table->* to <it_table>.
clear my_client.
find 'MANDT' in fieldlist.
if sy-subrc = 0.
my_client = 'X'.
endif.
if my_client = ' '.
find 'CLIENT' in fieldlist.
if sy-subrc = 0.
my_client = 'X'.
endif.
endif.
if my_client = 'X'.
open cursor my_cursor1 for
select (fieldlist)
from (tabname)
client specified
where (ta_where).
else.
open cursor my_cursor1 for
select (fieldlist)
from (tabname)
where (ta_where).
endif.
fetch next cursor my_cursor1
into corresponding fields of table <it_table>.
error = sy-subrc.
close cursor my_cursor1.
check error = 0.
define xml_dummy.
l_element_dummy = l_document->create_simple_element(
name = &1
value = &2
parent = l_element_001 ).
end-of-definition.
define make_data.
write &2 to l_string.
l_value = l_string.
xml_dummy &1 l_value.
end-of-definition.
l_ixml = cl_ixml=>create( ).
l_streamfactory = l_ixml->create_stream_factory( ).
l_encoding = l_ixml->create_encoding( character_set = 'ISO-8859-1'
byte_order = if_ixml_encoding=>co_none ).
l_ostream = l_streamfactory->create_ostream_itable(
table = ta_result[] ).
call method l_ostream->set_encoding
exporting
encoding = l_encoding.
l_document = l_ixml->create_document( ).
l_tag = tabname.
" l_value = ''.
l_element_000 = l_document->create_simple_element(
name = l_tag
" value = l_value
parent = l_document ).
loop at <it_table> assigning <dyn_wa>.
l_tag = 'item'.
" l_value = ''.
l_element_001 = l_document->create_simple_element(
name = l_tag
" value = l_value
parent = l_element_000 ).
do.
assign component sy-index of structure <dyn_wa> to <dyn_fi>.
if sy-subrc <> 0.
exit.
endif.
read table ta_katalog with key position = sy-index
assigning <katalog>.
if sy-subrc = 0.
write <katalog>-fieldname to l_tag_c.
l_tag = l_tag_c.
describe field <dyn_fi> type field_type.
if field_type = 'N'
or field_type = 'P'.
write <dyn_fi> to l_value_c.
else.
l_value_c = <dyn_fi>.
endif.
l_value = l_value_c.
shift l_value left deleting leading space.
make_data l_tag l_value.
endif.
enddo.
endloop.
l_renderer = l_ixml->create_renderer( ostream = l_ostream
document = l_document ).
l_rc = l_renderer->render( ).
l_xml_size = l_ostream->get_num_written_raw( ).
endfunction.