Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

read data from standard table

Former Member
0 Kudos

hi all,

i want to read data of mkpf from a remote client (clnt 1) any idea how to do tht?

points would be rewarded.

rgds

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Sure, just use an RFC destination, and the function module in this example. If the client would be in the same instance, then you could simply do SELECT and specify the MANDT in the WHERE clause, but if you are going across systems, then this function will help. You can create RFC destinations in SM59, but you should probably get with your basis people before doing so.



report zrich_0001.

data: opt type table of rfc_db_opt with header line.
data: fld type table of rfc_db_fld with header line.
data: tab type table of tab512 with header line.

parameters: p_matnr type mard-matnr,
            p_werks type mard-werks,
            p_lgort type mard-lgort.


fld-fieldname = 'LABST'.
append fld.

concatenate 'MATNR' '=' p_matnr into opt-text separated by space.
append opt.

concatenate 'and' 'WERKS' '=' p_werks into opt-text separated by space.
append opt.

concatenate 'and' 'LGORT' '=' p_lgort into opt-text separated by space.
append opt.

call function 'RFC_READ_TABLE'
  exporting
    query_table                = 'MARD'
*   DELIMITER                  = ' '
*   NO_DATA                    = ' '
*   ROWSKIPS                   = 0
*   ROWCOUNT                   = 0
  tables
    options                    = opt
    fields                     = fld
    data                       = tab
 exceptions
   table_not_available        = 1
   table_without_data         = 2
   option_not_valid           = 3
   field_not_valid            = 4
   not_authorized             = 5
   data_buffer_exceeded       = 6
   others                     = 7.

write:/ tab.

Regards,

Rich Heilman

11 REPLIES 11

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Sure, just use an RFC destination, and the function module in this example. If the client would be in the same instance, then you could simply do SELECT and specify the MANDT in the WHERE clause, but if you are going across systems, then this function will help. You can create RFC destinations in SM59, but you should probably get with your basis people before doing so.



report zrich_0001.

data: opt type table of rfc_db_opt with header line.
data: fld type table of rfc_db_fld with header line.
data: tab type table of tab512 with header line.

parameters: p_matnr type mard-matnr,
            p_werks type mard-werks,
            p_lgort type mard-lgort.


fld-fieldname = 'LABST'.
append fld.

concatenate 'MATNR' '=' p_matnr into opt-text separated by space.
append opt.

concatenate 'and' 'WERKS' '=' p_werks into opt-text separated by space.
append opt.

concatenate 'and' 'LGORT' '=' p_lgort into opt-text separated by space.
append opt.

call function 'RFC_READ_TABLE'
  exporting
    query_table                = 'MARD'
*   DELIMITER                  = ' '
*   NO_DATA                    = ' '
*   ROWSKIPS                   = 0
*   ROWCOUNT                   = 0
  tables
    options                    = opt
    fields                     = fld
    data                       = tab
 exceptions
   table_not_available        = 1
   table_without_data         = 2
   option_not_valid           = 3
   field_not_valid            = 4
   not_authorized             = 5
   data_buffer_exceeded       = 6
   others                     = 7.

write:/ tab.

Regards,

Rich Heilman

0 Kudos

hi rich,

thanx a lot for your input.

i hava to get allthe data form mara into an internal table & the client isnot in the same instance we are going accross system . can uplz let me know how to do this? & wht are the limitation of this fm?

ecpecting an answer!

rgds

0 Kudos

also when i execute your code i get dump:

error in assign assignment in program SAPLSDTX.

rgds

0 Kudos

Not sure where the dump is coming from, but here is another example, here you are specifing the fields that you want to return in the FLD table, and the TAB table should be filled with data, which is comma delimited. Make sure that you point the RFC destination correct, in this code it is pointed to NONE, which means that it will execute this in the local system.



REPORT  rich_0001.


DATA: opt TYPE TABLE OF rfc_db_opt WITH HEADER LINE.
DATA: fld TYPE TABLE OF rfc_db_fld WITH HEADER LINE.
DATA: tab TYPE TABLE OF tab512 WITH HEADER LINE.

DATA : r_descr TYPE REF TO cl_abap_structdescr.

DATA : idetails TYPE abap_compdescr_tab,
       xdetails TYPE abap_compdescr.

DATA: lv_table TYPE dd02l-tabname VALUE 'MARA'.


* Get the structure of the table.
r_descr ?= cl_abap_typedescr=>describe_by_name( lv_table ).
idetails[] = r_descr->components[].

LOOP AT idetails INTO xdetails.
  fld-fieldname = xdetails-name.
  fld-length    = xdetails-length.
  APPEND fld.
ENDLOOP.


CALL FUNCTION 'RFC_READ_TABLE' DESTINATION 'NONE'
  EXPORTING
    query_table                = lv_table
    delimiter                  = ','
*   NO_DATA                    = ' '
*   ROWSKIPS                   = 0
*   ROWCOUNT                   = 0
  TABLES
    OPTIONS                    = opt
    fields                     = fld
    data                       = tab
 EXCEPTIONS
   table_not_available        = 1
   table_without_data         = 2
   option_not_valid           = 3
   field_not_valid            = 4
   not_authorized             = 5
   data_buffer_exceeded       = 6
   OTHERS                     = 7.
LOOP AT tab.
  WRITE:/ tab.
ENDLOOP.

REgards,

RIch Heilman

0 Kudos

hi,

once again thanx foryour input.

iam getting dump :data buffer exceeded. any idea how to resolve this??

rgds

0 Kudos

Not sure, it appears to only allow so much data to be brought back in the TAB table.

Regards,

RIch Heilman

0 Kudos

this is my code: when i dont comment it_fields-fieldname = 'EBELN'. i<b> get the purchase order number. BUt when i comment it_fields-fieldname = 'EBELN' it i get error data buffer exceeded</b>.

data: it_option type table of rfc_db_opt with header line.

data: it_data type table of tab512 with header line.

data: it_fields type RFC_DB_FLD occurs 0 with header line.

*it_fields-fieldname = 'EBELN'.

*append it_fields.

CALL FUNCTION 'RFC_READ_TABLE' DESTINATION 'clnt2'

EXPORTING

QUERY_TABLE = 'EKKO'

  • DELIMITER = ' '

  • NO_DATA = ' '

  • ROWSKIPS = 0

  • ROWCOUNT = 0

TABLES

OPTIONS = it_option

FIELDS = it_fields

DATA = it_data.

  • EXCEPTIONS

  • TABLE_NOT_AVAILABLE = 1

  • TABLE_WITHOUT_DATA = 2

  • OPTION_NOT_VALID = 3

  • FIELD_NOT_VALID = 4

  • NOT_AUTHORIZED = 5

  • DATA_BUFFER_EXCEEDED = 6

  • OTHERS = 7

loop at it_data.

write: it_data.

endloop.

kindly tellme whts wrong with this code.

rgds

Message was edited by:

abbaper

Message was edited by:

abbaper

0 Kudos

Check notes 758278 and 382318 and maybe others.

Rob

0 Kudos

If you don't specify fields, it may be trying to pull all the fields for every row, hence overloading the buffer. You must either specify fields and/or use a WHERE clause to get a subset of the data.

Regards,

Rich Heilman

0 Kudos

hi,

once again thnax for your input.

basically i want all the fields data i.e complete data of ekko , mara.

can u plz tell me how to achieve this.

also how can i use where clause when iam getting data from across the system?

expecting an answer!.

rgds.

Message was edited by:

abbaper

0 Kudos

This use of a WHERE clause is illistrated in my first example program.

Regards,

Rich Heilman