 |
 |
| SAP Tips: |
|
 |
 |

ABAP/JAVA DEVELOPER TIPS
Getting around RFC_READ_TABLE limitations
James Tarver 08.04.2004
Rating: -2.83- (out of 5) Hall of fame tip of the month winner




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.
Code
function zrvc_read_table.
*"----------------------------------------------------------------------
*"*"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.
 |

|
Rate this Tip
|
To rate tips, you must be a member of SearchSAP.com. Register now
to start rating these tips. Log in if you are already a member.
|

Submit a Tip
|


');
// -->
DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.
|
 |
|
|
 |
|
 |
 |
 |
 |
| TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of . |
|
| | |
All Rights Reserved, , TechTarget |
SearchSAP.com is a search service provided by TechTarget and is completely independent of and not affiliated with SAP AG.
|
|
|
|
|