Home > SAP Tips > ABAP/Java developer tips > Getting around RFC_READ_TABLE limitations
SAP Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

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


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
ABAP/Java developer tips
Select Text fields: Case-insensitive
Finding BADIs you can use
Is this the quickest way to find a BADI?
ABAP Objects in SAP Workflow to provide improved performance
Easily debug error messages in SAP processes
Accessing private attributes in ABAP Objects
Find a BADI in a minute
Top 10 SAP tips of 2007
How to transport an SAP query in R/3 4.6x
How to switch off message determination in BAPI_PO_CREATE1

SAP Interface Technologies
An ABAP user wants to learn XI
Select Text fields: Case-insensitive
Finding BADIs you can use
Quiz: SAP ABAP development
SAP exec discusses Imagineering, the future of development
Tools for enabling SAP screens on a BlackBerry
Is there a 'load of program' option in report generation?
Deleting entries from a dynamic table
Defining a structure in a report
SAP applications demo: BP's key mapping

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
Application Link Enabling  (SearchSAP.com)
IDoc  (SearchSAP.com)
Remote Function Call  (SearchSAP.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

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.

HomeNewsTopicsBlogsTipsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
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 technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2000 - 2008, TechTarget | Read our Privacy Policy
SearchSAP.com is a search service provided by TechTarget and is completely
independent of and not affiliated with SAP AG.
  TechTarget - The IT Media ROI Experts