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

DATA declaration in ABAP

Former Member
0 Likes
858

Hello!

I found this declaration in a method (part of a Web Dynpro, but that souldn't matter here):

DATA lv_sysid TYPE sy-sysid.


In the ABAP basic course, I learned that I can use DATA ... TYPE in combination with a type or DATA .... LIKE in combination with an existing data object.


From my understanding, sy-sysid is a data object, so why can it be used in combination with DATA ... TYPE? Shouldn't it be DATA lv_sysid LIKE sy-sysid?


Best regards

Jan



1 ACCEPTED SOLUTION
Read only

retired_member
Product and Topic Expert
Product and Topic Expert
0 Likes
752

Your question makes perfect sense!

In a better world, there would be the dictionary structure SYST and the ABAP data object SY and it would be

TYPE SYST-SYSID

LIKE SY-SYSID

and nothing else.

Alas, and as documented, in ABAP, SYST as well as SY are both built-in types and objects and you can mix TYPE and LIKE as you will   .

Horst

5 REPLIES 5
Read only

tapomay_sanyal
Participant
0 Likes
752

Hi Jan,

We use Like only against DATA OBJECTS & data objects inturn are created with respect to elementary data types or dictionary data types.

e.g:

DATA: data_obj type data_type.

DATA: DATA_another_obj like data_obj (Valid)

or

DATA: DATA_another_obj type data_type is also valid.

In your example,

DATA lv_sysid TYPE sy-sysid is perfect as the created object/variable lv_sysid is of type SYSID of the dictionary structure SYST, base type of the variable lv_sysid will be character with length 8

Hope this explains your query!

Feel free to add further questions.

---BR----

Tapomay

Read only

0 Likes
752

Thank you, Tapomay

I was a bit confused because sy-sysid can also contain a value, which I thought is specific for a object/variable. Seems that sy-sysid is both - a type and a data object.

Best regards

Jan

Read only

retired_member
Product and Topic Expert
Product and Topic Expert
0 Likes
753

Your question makes perfect sense!

In a better world, there would be the dictionary structure SYST and the ABAP data object SY and it would be

TYPE SYST-SYSID

LIKE SY-SYSID

and nothing else.

Alas, and as documented, in ABAP, SYST as well as SY are both built-in types and objects and you can mix TYPE and LIKE as you will   .

Horst

Read only

0 Likes
752

Thank you, Horst!

Best regards

Jan

Read only

Former Member
0 Likes
752

This message was moderated.