05-15-2015 4:14 PM
Hi folks,
I just found something funny to make some objects, have two internal tables called itab1 and itab2, the itab1 is a TYPE SORTED TABLE coming from a TYPES statement called y_itab as show below:
Already itab2 was declared LIKE TABLE OF itab1 as shown above.
When performing code verification, SAP returns me with these two warnings below:
My question ... Knowing that the LIKE statement is used to declare an object when another has already been declared in the program (correct me if I'm wrong) and that the itab2 equals itab1, why these warnings occur?
BR,
Raphael Pacheco.
PS: Do not post codes, post explanations, let's discourse oks?
05-15-2015 10:14 PM
Let the correct answer:
The statement should be presented only itab2 LIKE itab1 because itab2 received itab1 of characteristics correctly. Despite giving warning, the itab2 LIKE TABLE OF itab1 statement causes the SAPSQL_PARSER_TODO_WARNING dump when used in SQL query.
Why this happened:
The internal table systemically was assembled as follows:
So, in a more visible, it would thus be:
ITAB2 [ ITAB1[ FIELD1 , FIELD2 , ...] ] (Or also called as "TABLE_LINE").
BR,
Raphael Pacheco.
05-15-2015 4:25 PM
Hello Raphael,
I think you should have used "itab2 LIKE itab1" and not "LIKE TABLE OF", because itab1 is already declared as table.
So your itab2 variable is a table in which each line contain a table (one field containing a table)...
Regards
05-15-2015 4:42 PM
Hi Brice!
You and others are correct, I know that declaring as itab2 LIKE itab1 it (itab2) respect what is set in itab1.
However, let us understand what happened, technically, why the itab2 was recognized as a "work-area" and also why he (SAP) said the itab2 not have all fields of itab1?
BR,
Raphael Pacheco.
05-15-2015 4:49 PM
Itab 2 contains only one field, this field is typed as table
Itab1[ ]
|_field1
|_field2
Itab2[ ]
|_field3[ ]
|_field1
|_field2
You can check it in debug mode, you will see that structure is clearly different.
Itab1 contains rows with two fields
Itab2 contains rows with a table containing itself two fields
05-15-2015 5:14 PM
Looks like you are running on older version than ABAP 731. In ABAP 731, the error is now upgraded to include that the variable could be WA or Internal table.
The work area (or internal table) "ITAB2" is not flat, or contains
reference or internal tables as components or internal tables as
components. as components.
Regards,
Naimesh Patel
05-15-2015 5:45 PM
Hi Naimesh!
My ABAP Kernel's version is 7.4 EHP7
BR,
Raphael Pacheco.
05-15-2015 7:19 PM
My bad. I thought it is the version issue where SAP has improved the error logging. But I think, it is something else. As I'm getting the error where as you are getting the warning. So, Can you paste the statement which is giving you the warning?
Regards,
Naimesh Patel
05-15-2015 4:27 PM
Your ITAB2 is deep internal table as component of ITAB1. Since you have used the ITAB2 LIKE TABLE OF ITAB.
Put a breakpoint and see in debug how both tables ITAB1 and ITAB2 are populated.
types:
BEGIN OF ty_partners,
customer type char10,
p_type type char02,
partner type char10,
end of ty_partners.
types: tt_partners type SORTED TABLE OF ty_partners
with UNIQUE key customer p_type.
data: itab type tt_partners,
itab2 like table of itab. "<<
data: wa_itab like line of itab.
insert wa_itab into itab index 1.
append itab to itab2.
write: 'done'.
If you define the table as using just LIKE, than it would the same structure table.
data: itab type tt_partners,
itab3 like itab. "<<
data: wa_itab like line of itab.
insert wa_itab into itab index 1.
itab3 = itab.
Regards,
Naimesh Patel
05-15-2015 4:31 PM
You are correct Naimest, itab2 is becoming a deep structure. Never knew that.
Thanks
Rajit
05-15-2015 4:27 PM
Hello Raphael,
According to my understanding, if you have already declared itab1 as "TYPE TABLE OF" then for itab2 only "LIKE itab1" will do the work.
I don't know why it is behaving like a work area. Maybe do a search with itab2 just to see in case it is declared again in some FORM or METHOD.
Thanks
Rajit
05-15-2015 4:53 PM
I think you have a select statement where to populate the internal table and the select statement has only subset of fields in itab2.
05-15-2015 10:14 PM
Let the correct answer:
The statement should be presented only itab2 LIKE itab1 because itab2 received itab1 of characteristics correctly. Despite giving warning, the itab2 LIKE TABLE OF itab1 statement causes the SAPSQL_PARSER_TODO_WARNING dump when used in SQL query.
Why this happened:
The internal table systemically was assembled as follows:
So, in a more visible, it would thus be:
ITAB2 [ ITAB1[ FIELD1 , FIELD2 , ...] ] (Or also called as "TABLE_LINE").
BR,
Raphael Pacheco.