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

SAP ABAP/JAVA DEVELOPER TIPS

Getting around RFC_READ_TABLE limitations


James Tarver
08.04.2004
Rating: -2.69- (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
...

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



RELATED CONTENT
SAP ABAP/Java developer tips
How to do additional dialog processing after SAP COMMIT WORK statement
How to find a piece of SAP ABAP code without debugging
How to read an SAP transaction in an ABAP code
How to provide an SAP R/3 4.5B application server with a Web service interface
How to find owners and transports of deleted ABAP programs
Fixing a common OPEN_FORM and START_FORM error in SAPscript
Select Text fields: Case-insensitive
Is this the quickest way to find a BADI?
Easily debug error messages in SAP processes
Accessing private attributes in ABAP Objects

SAP interface technologies
SAP CTO expects today's SAP applications to be running in 2020
SAP TechEd 09 keynoters: Managing change today like trying to board a speeding train
SAP's Web 2.0 strategy makes way for social networking in business apps
Error when clicking the SAP GUI logon button
SAP applications demo: BP's key mapping
Viewing a list of SAP interfaces
Interface a locally developed application with SAP
Will there always be an implicit commit in an RFC?
Is there a way to search within IDocs using a purchase order number?
Configuring the JDBC Connector Service to perform database lookups

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


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.



NetWeaver SAP White Papers
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, 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