WITH KEY mandt = I am trying to find a way to read an internal table that needs to be creat...">

Syntax error "no MANDT component" for READ TABLE <itab> WITH KEY mandt =

I am trying to find a way to read an internal table that needs to be created dynamically. I created the following report that populates a dynamic internal table with data.

On the last line, I try to read it using a key (e.g. mandt ), but I get a mandt error mandt :

The specified type has no structure and therefore does not have a component named MANDT.

I debugged and I see that <any_tab> was populated successfully and the table structure (field names) are correct. The problem occurs when I try to read a table in the workspace. Maybe I'm doing it wrong, but it seems like it can be done, and I feel like I'm missing out on something small.

The reason I'm trying to do this is because I discovered identical selection operations in the program and I want to buffer records in memory and read them from there to avoid access to the database. It is easy to implement, but I did not do it when the table, where clause and into OPEN SQL clause that I am trying to optimize are dynamic.

How to fix a syntax error?

 DATA: t681_rep TYPE TABLE OF t681 , wa_681 LIKE LINE OF t681_rep, tabref TYPE REF TO data , waref TYPE REF TO data. FIELD-SYMBOLS: <any_tab> TYPE ANY TABLE, <any_wa> TYPE ANY, <var1> TYPE ANY. "fill t681_rep SELECT * FROM t681 INTO TABLE t681_rep UP TO 1 ROWS WHERE kotab = 'A002'. READ TABLE t681_rep INTO wa_681 WITH KEY kotab = 'A002'. IF sy-subrc = 0. "if A002 is found create a table of that type and fill it CREATE DATA tabref TYPE TABLE OF (wa_681-kotab). ASSIGN tabref->* TO <any_tab>. SELECT * UP TO 10 ROWS FROM (wa_681-kotab) INTO TABLE <any_tab>. ENDIF. CREATE DATA waref TYPE a002. ASSIGN waref->* TO <any_wa>. READ TABLE <any_tab> ASSIGNING <any_wa> WITH KEY mandt = '800'. <- problem area IF sy-subrc = 0. "do stuff with <any_wa>... ENDIF. 
+7
source share
5 answers

You just need to specify the field name in parentheses.

 data: field type string. field = 'MANDT'. READ TABLE <any_tab> ASSIGNING <any_wa> WITH KEY (field) = '800'. IF sy-subrc = 0. "do stuff with <any_wa>... ENDIF. 
+5
source

AFAIK, you have to do this "long way":

 FIELD-SYMBOLS: <any_field> TYPE any. LOOP AT <any_tab> ASSIGNING <any_wa>. ASSIGN COMPONENT 'MANDT' OF STRUCTURE <any_wa> TO <any_field>. IF <any_field> <> 800. CONTINUE. ENDIF. " do stuff with <any_wa> - you will have to assign <any_field> again to access fields. ENDLOOP. 
+2
source

You are trying to effectively beat the database, it is a battle.

Just go to SE11, select your table, go to the technical parameters and change the technical parameters (type of buffering and buffering), for this you do not need an object modification key. You can also verify that the size category is correct.

+2
source

You can use RTTS to get table keys.

 data table_name type string. table_name = 'A002'. " Dynamically create the table type data the_table type ref to data. create data the_table type table of (table_name). " Use RTTS to get table keys data typedescription type ref to cl_abap_tabledescr. typedescription ?= cl_abap_tabledescr=>describe_by_data_ref( the_table ). data keys type abap_table_keydescr_tab. keys = typedescription->get_keys( ). 
+1
source
 REPORT y_test_dynamic_table. DATA: table_name TYPE string, typedescription TYPE REF TO cl_abap_tabledescr, keys TYPE abap_keydescr_tab, ls_key TYPE abap_keyname. table_name = 'ZYFRM_STG'. " Dynamically create the table type DATA the_table TYPE REF TO data. CREATE DATA the_table TYPE TABLE OF (table_name). " Use RTTS to get table keys typedescription ?= cl_abap_tabledescr=>describe_by_data_ref( the_table ). keys = typedescription->KEY. loop at keys INTO ls_key. *** ENDLOOP. 
0
source

Source: https://habr.com/ru/post/916926/


All Articles