RFC_READ_TABLE is an RFC that allows users to read a table remotely. This is important
particularly to Java developers using JCO to communicate with an ABAP back-end. Unfortunately,
RFC_READ_TABLE has size limitations; it also incorrectly reads binary data. The code below gets
around those limitations. Note: no authorization checking takes place; that will need to be
embedded in your version of the code. Also, you will need to define a table type with FIELDNAME as
a line type.
function zrvc_read_table.
Requires Free Membership to View
When you register, you will start receiving targeted emails from my award-winning team of editorial writers. Our goal is to keep you informed on the hottest topics and biggest challenges faced by SAP professionals today.
Hannah Smalltree, Editorial Director*"*"Local interface:
*" IMPORTING
*" VALUE(IV_TABNAME) TYPE TABNAME
*" VALUE(IT_FIELDNAMES) TYPE ZRVC_TT_FIELDNAMES
*" VALUE(IT_SELECT_OPTIONS) TYPE STRINGTAB
*" EXPORTING
*" VALUE(EV_RC) TYPE INT4
*" VALUE(EV_MSG) TYPE STRING
*" VALUE(ET_STRINGTAB) TYPE STRINGTAB
*"----------------------------------------------------------------------
*/References
data:
lr_error type ref to cx_root,
lr_dataref type ref to data.
*/Variables
data:
lv_string type string,
lv_temp type string,
ls_dfies type dfies,
lt_dfies type ddfields,
lt_alldfies type ddfields.
field-symbols:
<lt_tab> type any table,
<ls_line> type any,
<lv_any> type any.
*/Initialize
if iv_tabname is initial.
ev_rc = 4.
ev_msg = 'Missing table name.'.
return.
endif.
*/Since this is an RFC, embed everything in a try/catch; catch any */exception and pass message along to caller
try.
*/Get meta data for table
call function 'DDIF_NAMETAB_GET'
exporting
tabname = iv_tabname
tables
dfies_tab = lt_alldfies
exceptions
others = 2.
if sy-subrc <> 0.
ev_rc = 4.
ev_msg = 'Table not found; please try again.'.
return.
endif.
if it_fieldnames is initial.
*/No restrictions provided; use all fields
lt_dfies = lt_alldfies.
else.
*/Verify that all fieldnames specified exist in table
loop at it_fieldnames assigning <lv_any>.
read table lt_alldfies into ls_dfies with key fieldname =
<lv_any>. if sy-subrc <> 0.
*/Specified field not found in table
ev_rc = 4.
concatenate 'Field' <lv_any> 'not found in table' iv_tabname
into ev_msg separated by space.
return.
endif.
*/Fieldname found; insert line into working dfies table
insert ls_dfies into table lt_dfies.
endloop.
endif.
create data lr_dataref type standard table of (iv_tabname).
assign lr_dataref->* to <lt_tab>.
select * from (iv_tabname) into table <lt_tab>
where (it_select_options).
loop at <lt_tab> assigning <ls_line>.
clear: lv_string.
loop at lt_dfies into ls_dfies.
clear: lv_temp.
assign component ls_dfies-position of structure <ls_line> to <lv_any>.
lv_temp = <lv_any>. "force the type conversion
if lv_string is initial.
lv_string = lv_temp.
else.
concatenate lv_string '|' lv_temp into lv_string.
endif.
endloop.
insert lv_string into table et_stringtab.
endloop.
catch cx_root into lr_error.
ev_rc = 4.
ev_msg = lr_error->get_text( ).
endtry.
endfunction.
This was first published in August 2004
Join the conversationComment
Share
Comments
Results
Contribute to the conversation