Application Development and Automation 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: 
Read only

How to change from this obsolete code?

Former Member
0 Likes
3,629

Hi ,

I have been trying to substitute this following obsolete code :


TABLES:ICON.
.....
.....
START-OF-SELECTION.
SELECT * FROM ICON ORDER BY NAME.

with the following code , but it's not working -

DATA: ICON_STRU TYPE ICON,
      ICON_TAB TYPE TABLE OF ICON_STRU .
.....
.....
START-OF-SELECTION.
SELECT * FROM ICON_TAB ORDER BY NAME.

& when doing syntax check , it is giving following error:

The type "ICON_STRU" is unknown.

Since "Tables : ICON." is actually trying to create a structure with all the fields present in the DDIC table ICON , hence I substituted the code with :

DATA: ICON_STRU TYPE ICON,

which is doing the same thing i.e. creating a local structure with all the fields from ICON table

& then I am creating an Internal Table with this following code -

ICON_TAB TYPE TABLE ICON_STRU .

So , can anyone please tell me , what I am doing wrong in this coding?

Thanks & Regards,

Namrata

1 ACCEPTED SOLUTION
Read only

DoanManhQuynh
Active Contributor
3,267

Sorry, if you need icon for display why dont just declare: TYPE-POOLS icon?

Otherwise, since ICON_STRU is variable ( under DATA statement) you can change ICON_TAB LIKE TABLE OF ICON_STRU. You should read about TYPE and DATA statement in F1 help.

15 REPLIES 15
Read only

Former Member
3,267

hi,

this is extremely basic stuff, I suggest you do the following:

Go to se38, then CTL+F8, then type in Select into. This should explain what you're trying to achieve.

Kind regards, Rob Dielemans

Read only

0 Likes
3,267

Hi Rob,

You mean there is nothing wrong in declaring using this following code?

 Data: ICON_STRU TYPE ICON,

    ICON_TAB TYPE TABLE ICON_STRU .

But then in SE38 , why I'm getting this error - 'The type "ICON_STRU" is unknown.'

Also, I didn't get you what you wrote in the following - "Go to se38, then CTL+F8, then type in Select into." Can you please tell in more details?

Read only

0 Likes
3,267

I'm already using SE38 for coding! I didn't understand what you are pointing to...

Read only

matt
Active Contributor
3,267

He means that if you look at the syntax of SELECT you'll see why

SELECT * FROM ICON_TAB ORDER BY NAME.

is nonsense, and if you read a little about DATA and TYPES keyword in the documentation, you'll probably be able to work out why the below doesn't work (especially - and this is a hint - if you read the documentation for LIKE as well).

DATA: ICON_STRU TYPE ICON,
      ICON_TAB TYPE TABLE OF ICON_STRU .

For syntax errors, always carefully read the syntax in the documentation.

Read only

RaymondGiuseppi
Active Contributor
3,267

Perform some search on DATA and TYPE(S) in Abap online documentation, and guess yourself 😉

Read only

Patrick_vN
Active Contributor
0 Likes
3,267

How about:

SELECT [fieldlist] FROM icon INTO TABLE @DATA(lt_icon_data). (No * because it might be you don't need all the columns?)


And when LOOP-ing (or READ TABLE-ing):

LOOP AT lt_icon_data into data(ls_icon_data).

..

ENDLOOP.

Read only

0 Likes
3,267

Hi

What is "@DATA"? I didnt read this syntax in any book or abap documentation.

I mean the statement can be like this -

SELECT * FROM ICON ORDER BY NAME.

Then what is wrong in that? Not giving any error in SE38 and much simpler than all those jargons all of you used here just to confuse me more!!

Read only

0 Likes
3,267

It's new ABAP 7.4+ syntax. Won't work in an earlier release. We don't know what release you're working with, so people are trying to be helpful and suggesting new syntax, assuming it's applicable in your case.

Read only

matt
Active Contributor
0 Likes
3,267
Read only

0 Likes
3,267

namrata.chaki, the @data is for inline declaration. It basically declares the internal table based on the fieldlist in your SQL. In short, you would not need to declare the internal table separately up front (see https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abendata_inline.htm for more details).

And, no intention whatsoever to confuse you in any way. Just trying to help.

jelena.perfiljeva thanks! 😛

Read only

Jelena_Perfiljeva
Active Contributor
3,267

In this case the message means exactly what it says. ICON_STRU is not a type. It's a structure.

This code passes syntax check, for example:

DATA: icon_stru TYPE icon,
 icon_tab TYPE TABLE OF icon.

START-OF-SELECTION.
 SELECT * FROM icon
 INTO TABLE icon_tab
 ORDER BY name.

Type is either a dictionary type or what we define in the program using TYPES command. What is defined using DATA is a variable (of certain type).

Actually I ran into this a few times and got confused for a moment too. It kind of makes you think ICON_STRU doesn't exist at all but it is right there. 🙂 Have to really read this message carefully.

I agree with others that using SELECT * is not a good practice, unless you actually need all the data. I find that in the old programs SELECT * frequently comes hand in hand with TABLES. Lazy programming. 😞

Read only

0 Likes
3,267

Yes Agreed.

Read only

DoanManhQuynh
Active Contributor
3,268

Sorry, if you need icon for display why dont just declare: TYPE-POOLS icon?

Otherwise, since ICON_STRU is variable ( under DATA statement) you can change ICON_TAB LIKE TABLE OF ICON_STRU. You should read about TYPE and DATA statement in F1 help.

Read only

0 Likes
3,267

TYPE-POOLS is obsolete

I feel that if another person suggests OP reads Help they'll completely lose it. 🙂