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

declaring varaiable

Former Member
0 Likes
559

HI,

Which one is the best practice of declaring variable and why?

vbeln like vbak-vbeln

or

vbeln type vbeln.

does declaring LIKE will effect the performance of the program?

6 REPLIES 6
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
537

Not sure that it matters. I believe it to be personal preference when using the table name and field instead of the data element directly.

vbeln type vbak-vbeln    <-  using table name and field

vbeln type vbeln           <- using data element.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
537

Hi!

Declaring will not affect the program runtime.

You can use the way you like better.

Regards

Tamá

Read only

Former Member
0 Likes
537

Hi,

you can use LIKE to refer to any object that has been declared using DATA or a similar statement, and is visible in the current context. The object only has to have been declared. It is irrelevant whether the data object already exists in memory when you make the LIKE reference.

In principle, the local data objects in the same program are visible. As with local data types, there is a difference between local data objects in procedures and global data objects. Data objects defined in a procedure obscure other objects with the same name that are declared in the global declarations of the program.

<b>TYPE:</b>

Example: TYPE <type>

to refer to any data type <type> that is already known at this point in the program

When you refer to known data types using the TYPE addition, the visibility of the data types is important.

The predefined ABAP types (C, D, F, I, N, P, T, and X) are always visible. You cannot declare types with the same names as these data types, either in the program or in the ABAP Dictionary.

When we talk about the visibility of local data types in the program, we must differentiate between local data types in procedures and global data types. Data types defined in a procedure obscure other objects with the same name that are declared in the global declarations of the program. All local data types in a program obscure data types with the same names in the ABAP Dictionary. This also applies to data types from type groups.

In the ABAP Dictionary, different visibility rules apply to standalone data types and the data types stored in type groups. Data types in type groups obscure standalone data types with the same names. However, this should be an exceptional situation. All data types in the ABAP Dictionary should be in the same namespace. When you create a standalone data type, the system displays a warning if the name begins with the name of a type group followed by an underscore. Equally, you cannot create a type group if there is already a standalone data type with the same name followed by an underscore.

Regards

Sudheer

Read only

Former Member
0 Likes
537

Performance wise there is not much of a difference but SAP is moving away from LIKE in OO context.

Read only

Former Member
0 Likes
537

Hi Neha,

Bith the declarations are helpful and also best performance wise.

But for a huge program, we go for the <b>TYPES</b> declaration as it holds the reusability concept unlike the <b>LIKE</b> declaration. So in some kind, we can say that a little bit of performance can be improved using <b>TYPES</b> rather than <b>LIKE</b> in our program.

Hope this resolves your query.

Reward all the helpful answers.

Regards

Read only

Former Member
0 Likes
537

I feel there will not be any performance difference while execution. If at all there can be any diffence, then it should be during the intermediate code generation. Both these codes will result in same ABAP intermediate codes and will be executed by the ABAP engine in same fashion.