Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Problem with cl_abap_tabledescr=>describe_by_data

Hello Xperts,

from the following code we are calling a method READ_SELECTIVELY:

    TYPES:
          t_struct    TYPE TABLE OF /BIC/VBPPP01j
    DATA:
        t_all_data    TYPE t_struct, 
        w_dref  type ref to data.

    GET REFERENCE OF t_all_data into w_dref.

    CALL METHOD ZCL_B_TECHNICAL_UTILITY=>READ_SELECTIVELY
      IMPORTING
        P_SEL_READ_DATA = w_dref.

Pls note: it is coded like this because method READ_SELECTIVELY is supposed to work generically with t_struct being a table of any type.

Declarations of method READ_SELECTIVELY:

method READ_SELECTIVELY.
public section.
  type-pools RSDRC .

  class-methods READ_CUBE_SELECTIVELY
    exporting
      !P_CUBE_SEL_READ_DATA type ref to DATA .

Coding of method READ_SELECTIVELY:

method READ_SELECTIVELY.
  DATA:
    go_sdescr        TYPE REF TO cl_abap_structdescr,
    go_sdescr_new    TYPE REF TO cl_abap_structdescr,
    go_tdescr        TYPE REF TO cl_abap_tabledescr,

    gdo_handle       TYPE REF TO data,
    gs_element       TYPE REF TO cl_abap_elemdescr,
    gt_components    type cl_abap_structdescr=>component_table,
    gs_component     like line of gt_components,
    gs_comp          like line of gt_components.

  field-symbols:
    <g_t_data>       TYPE STANDARD TABLE.

  go_tdescr ?= cl_abap_tabledescr=>describe_by_data( P_CUBE_SEL_READ_DATA ).
  go_sdescr ?= go_tdescr->get_table_line_type( ).

* Begin create dynamic standard table copy of P_CUBE_SEL_READ_DATA
  "   Create instances of dynamic structure and dynamic internal table
  go_sdescr_new  = cl_abap_structdescr=>create( P_COMPONENTS = gt_components p_strict = abap_false ).
  go_tdescr      = cl_abap_tabledescr=>create( go_sdescr_new ).

  "   Create data refence followed by table creation
  CREATE DATA gdo_handle TYPE HANDLE go_tdescr.
  ASSIGN gdo_handle->* TO <g_t_data>.
* End create dynamic standard table copy of P_CUBE_SEL_READ_DATA
...

The idea is to create a copy of the table passed thru parameter P_CUBE_SEL_READ_DATA. After that the copy will be filled and in a loop appended to P_CUBE_SEL_READ_DATA which will be returned to the calling coding (i.e. the first code snippet above). Makes sense?

Unfortunately it fails at the statement:

  go_tdescr ?= cl_abap_tabledescr=>describe_by_data( P_CUBE_SEL_READ_DATA ).

Any suggestions are very appreciated.

Former Member
replied

@Marcin: I don't think OP needs the RTTI at all. He can just de-reference the variable to some "compatible" field-symbol. Watsay?

Misleading here might be this statement

  • Begin create dynamic standard table copy of P_CUBE_SEL_READ_DATA

I so thought he needs local copy of the table. But of coure is he only needs to change original one, no reason to use RTTS, but working directly with table behind P_CUBE_SEL_READ_DATA suffice.

Regards

Marcin

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question