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: 

index operation at internal tables type "any table" NOT POSSIBLE??

Former Member
0 Kudos
7,046

Hi all!

I've got a class method doing a lot of generic work...

class method interface: pt_mytab type any table

I failed when trying to read single data records by:

read table pt_mytab with key ... OR

read table pt_mytab index ...

SYNTAX CHECK ERROR: no explicit or implicit index operation hashed tables or internal tables of type "any table" possible

Is there a way to do this?

Best regards,

Christoph

PS:

I also tried the following facing the same problem:

In this class I dynamically create a internal table by

create data lr_table_ref type handle lcl_table_descr.

Assign lr_table_ref->* to <lt_bew_data>.

Also read table <lt_bew_data> is not possible (also type any table of course)

Message was edited by:

Christoph Aschauer

1 ACCEPTED SOLUTION

Former Member
985

I'm not quite sure, what you mean. But... for a programmer its never concrete until they see code, so here it goes:


REPORT zhm_fun.

DATA lr_data TYPE REF TO data.
FIELD-SYMBOLS: <lt_tab>    TYPE ANY TABLE,
               <ls_struct> TYPE any.

CREATE DATA lr_data TYPE TABLE OF your_table.
ASSIGN lr_data->* TO <lt_tab>.

SELECT *
FROM your_table
INTO TABLE <lt_tab>
UP TO 10 ROWS.

READ TABLE <lt_tab> ASSIGNING <ls_struct> WITH KEY ('ABC') = 'XXX'.
*READ TABLE <lt_tab> ASSIGNING <ls_struct> INDEX 5.

in case you want to enable the second READ TABLE, then your definition should be:


FIELD-SYMBOLS: <lt_tab>    TYPE INDEX TABLE,

instead of


FIELD-SYMBOLS: <lt_tab>    TYPE ANY TABLE,

reason:

ANY TABLE means STANDARD TABLE or HASHED TABLE or SORTED TABLE

INDEX TABLE means STANDARD TABLE or SORTED TABLE (table type on which an INDEX-operation is possible)

Is this what you wanted???

Cheers,

Hristo

7 REPLIES 7

varma_narayana
Active Contributor
0 Kudos
985

Hi Cristopher:

When you declare a Generic (Any Table) internal table you cannot perform any operations on that internal table.

It can be only used as a Formal Parameter of the Methods, FMs, Subroutines.

So to access the Data Declare a Local internal table as Standard table etc.

Copy the Generic table to Standard table and then access it.

<b>reward if Helpful.</b>

0 Kudos
985

Hi,

thanks for your answer. That's what I did, but I just wanted to access this table dynamically and not to use different standard tables. The "problem" is that the structure of my table (of type any table) varies. So internally I use different standard tables of a specific DDIC structure type.

Thanks for your reply!

Christoph

uwe_schieferstein
Active Contributor
0 Kudos
985

Hello Christoph

I assume that you have to go the "fully dynamic" way as shown in my sample report <b>ZUS_SDN_DYNAMIC_ITAB</b>:

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_DYNAMIC_ITAB
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_dynamic_itab.


PARAMETER:
  p_tabnam   TYPE tabname  DEFAULT 'KNB1'.
*
DATA: gdo_data TYPE REF TO data.

FIELD-SYMBOLS:
  <gt_itab> TYPE STANDARD TABLE,
  <gs_line> TYPE ANY,
  <gd_fld>  TYPE ANY.


START-OF-SELECTION.

  CREATE DATA gdo_data TYPE TABLE OF (p_tabnam).
  ASSIGN gdo_data->* TO <gt_itab>.

END-OF-SELECTION.

  SELECT * FROM  (p_tabnam) INTO TABLE <gt_itab>.


  LOOP AT <gt_itab> ASSIGNING <gs_line>.
    ASSIGN COMPONENT 'BUKRS' OF STRUCTURE <gs_line> TO <gd_fld>.

    IF ( <gd_fld> = '1000' ).
      MESSAGE 'BUKRS = 1000' TYPE 'I'.
      EXIT.
    ENDIF.

  ENDLOOP.

END-OF-SELECTION.

Regards

Uwe

0 Kudos
985

Hi Uwe,

thanks for your reply. Thats exactly what I did... But if you try:

read table into ... INDEX ... the syntax check error occurs.

I think there is no way to do what I want. I used different standard tables of a DDIC type and do the indexed read on this internal table.

Viele Grüße,

Christoph

0 Kudos
985

Hello Christoph

I do not think it is possible because the ABAP runtime would need to know the static type of your table which - of course - has no static type.

Regards

Uwe

Former Member
986

I'm not quite sure, what you mean. But... for a programmer its never concrete until they see code, so here it goes:


REPORT zhm_fun.

DATA lr_data TYPE REF TO data.
FIELD-SYMBOLS: <lt_tab>    TYPE ANY TABLE,
               <ls_struct> TYPE any.

CREATE DATA lr_data TYPE TABLE OF your_table.
ASSIGN lr_data->* TO <lt_tab>.

SELECT *
FROM your_table
INTO TABLE <lt_tab>
UP TO 10 ROWS.

READ TABLE <lt_tab> ASSIGNING <ls_struct> WITH KEY ('ABC') = 'XXX'.
*READ TABLE <lt_tab> ASSIGNING <ls_struct> INDEX 5.

in case you want to enable the second READ TABLE, then your definition should be:


FIELD-SYMBOLS: <lt_tab>    TYPE INDEX TABLE,

instead of


FIELD-SYMBOLS: <lt_tab>    TYPE ANY TABLE,

reason:

ANY TABLE means STANDARD TABLE or HASHED TABLE or SORTED TABLE

INDEX TABLE means STANDARD TABLE or SORTED TABLE (table type on which an INDEX-operation is possible)

Is this what you wanted???

Cheers,

Hristo

0 Kudos
985

Hi Hristo,

Cool!!! thanks a lot! Thats exactly what I was looking for. Didn't know that thing with index table as interface description type, nor the thing: with key ('KEY') = ... .

Of course, I assigned you the points for "solved problem".

Best regards,

Christoph