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: 

Replacement for RFC_READ_TABLE?

Former Member
0 Kudos

Is there a best practice replacement for the restricted RFC_READ_TABLE?  OSS Note 382318 mentions that this remote function call is to be avoided, but there is not a recommended replacement solution.  Any help would be appreciated.

3 REPLIES 3

Former Member
0 Kudos

Hi Ziv - Thank you for the response - it was consistent with other answers I had seen - which is to develop a zRFC_READ_TABLE with authorization included.  Unfortunately, your post has been deleted. 

0 Kudos

Hi Bradley ,

You can try this fucntion  ,it works fine for me.

Hopes this help

BR

Ziv

FUNCTION yrfc_read_table.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(QUERY_TABLE) LIKE  DD02L-TABNAME
*"     VALUE(DELIMITER) LIKE  SONV-FLAG DEFAULT SPACE
*"     VALUE(NO_DATA) LIKE  SONV-FLAG DEFAULT SPACE
*"     VALUE(ROWSKIPS) LIKE  SOID-ACCNT DEFAULT 0
*"     VALUE(ROWCOUNT) LIKE  SOID-ACCNT DEFAULT 0
*"  TABLES
*"      OPTIONS STRUCTURE  RFC_DB_OPT
*"      FIELDS STRUCTURE  RFC_DB_FLD
*"      DATA STRUCTURE  BPCHAR2000
*"  EXCEPTIONS
*"      TABLE_NOT_AVAILABLE
*"      TABLE_WITHOUT_DATA
*"      OPTION_NOT_VALID
*"      FIELD_NOT_VALID
*"      NOT_AUTHORIZED
*"      DATA_BUFFER_EXCEEDED
*"----------------------------------------------------------------------
  DATA BEGIN OF table_structure OCCURS 10.
          INCLUDE STRUCTURE dfies.
  DATA END OF table_structure.
  DATA: table_type       TYPE dd02v-tabclass,
        number_of_fields TYPE i,
        line_cursor      TYPE i.
  DATA: BEGIN OF fields_int OCCURS 10,
          fieldname  LIKE table_structure-fieldname,
          type       LIKE table_structure-inttype,
          decimals   LIKE table_structure-decimals,
          length_src LIKE table_structure-intlen,
          length_dst LIKE table_structure-leng,
          offset_src LIKE table_structure-offset,
          offset_dst LIKE table_structure-offset,
        END OF fields_int.
  DATA: dref TYPE REF TO data.
  FIELD-SYMBOLS <d>.
  CALL FUNCTION 'DDIF_FIELDINFO_GET'
    EXPORTING
      tabname        = query_table
    IMPORTING
      ddobjtype      = table_type
    TABLES
      dfies_tab      = table_structure
    EXCEPTIONS
      not_found      = 1
      internal_error = 2
      OTHERS         = 3.
  IF sy-subrc <> 0.
    RAISE table_not_available.
  ENDIF.
  IF table_type = 'INTTAB'.
    RAISE table_without_data.
  ENDIF.
  ASSIGN COMPONENT 0 OF STRUCTURE data TO <d>.
  DESCRIBE TABLE fields LINES number_of_fields.
  IF number_of_fields = 0.
    LOOP AT table_structure.
      MOVE table_structure-fieldname TO fields-fieldname.
      APPEND fields.
    ENDLOOP.
  ENDIF.
  line_cursor = 0.
  LOOP AT fields.
    READ TABLE table_structure WITH KEY fieldname = fields-fieldname.
    IF sy-subrc NE 0.
      RAISE field_not_valid.
    ENDIF.
    IF line_cursor <> 0.
      IF no_data EQ space AND delimiter NE space.
        MOVE delimiter TO data+line_cursor.
      ENDIF.
      line_cursor = line_cursor + STRLEN( delimiter ).
    ENDIF.
    fields_int-fieldname  = table_structure-fieldname.
    fields_int-length_src = table_structure-intlen.
    fields_int-length_dst = table_structure-leng.
    fields_int-offset_src = table_structure-offset.
    fields_int-offset_dst = line_cursor.
    fields_int-type       = table_structure-inttype.
    fields_int-decimals   = table_structure-decimals.
    line_cursor = line_cursor + table_structure-leng.
    APPEND fields_int.
    fields-fieldtext = table_structure-fieldtext.
    fields-type      = table_structure-inttype.
    fields-length    = fields_int-length_dst.
    fields-offset    = fields_int-offset_dst.
    MODIFY fields.
  ENDLOOP.
  IF no_data EQ space.
    FIELD-SYMBOLS: <wa> TYPE ANY, <comp> TYPE ANY.
    CREATE DATA dref TYPE (query_table).
    ASSIGN dref->* TO <wa>.
    SELECT INTO CORRESPONDING FIELDS OF <wa>
      FROM (query_table)
      WHERE (options).
      IF sy-dbcnt GT rowskips.
        LOOP AT fields_int.
*          IF fields_int-type = 'P'.
*            ASSIGN COMPONENT fields_int-fieldname
*                OF STRUCTURE <wa> TO <comp>
*                TYPE     fields_int-type
*                DECIMALS fields_int-decimals.
*          ELSE.
          ASSIGN COMPONENT fields_int-fieldname
              OF STRUCTURE <wa> TO <comp>
              TYPE     fields_int-type.
*          ENDIF.
          MOVE <comp> TO
              <d>+fields_int-offset_dst(fields_int-length_dst).
        ENDLOOP.
        APPEND data.
        IF rowcount > 0 AND sy-dbcnt GE rowcount. EXIT. ENDIF.
      ENDIF.
    ENDSELECT.
  ENDIF.
ENDFUNCTION.

raymond_giuseppi
Active Contributor
0 Kudos

Check also 1434284 - FAQ| Authorization concept for generic table access, as, since this note was implemented, the VIEW_AUTHORITY_CHECK FM is used in this FM to check read authorization on the table, so check for your version and read the note as well as online documentation of authorization objects S_TABU_*.

Regards,

Raymond