Application Development 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: 

Data declaration in ABAP

Former Member
0 Kudos

hi,

i want to know which of the below mentioned option is a better practice when it comes to declaring data or constants in ABAP.


a.     Master Table- Field

b.     Data element.

Thanks

Abhinav

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

This conversation looks like all discussions about myths. I really wonder on which factual arguments people say that "TYPE Master Table- Field" is not recommended. I've heard about this myth for 15 years. Can anybody find this in the official ABAP Programming Guidelines?

11 REPLIES 11

MukeshKumar
Participant
0 Kudos

Hi , If you are using a constant or data in one program only, you should go for local declaration though for SELECT-OPTIONS, you can create a new structure in the absence of a standard structure. If you need to create a table, you can either directly define the fields with elementary types or create a data element for them. That decision is dependent upon whether you want to use the field in multiple tables or structure. If 'Yes', you should create a Data Element for it and create Label-text, F1 help and possibly F4 help using Domain. Hope it clarifies. Best Regards !

0 Kudos

hi mukesh,

thanks for the reply. my question is if we have standard data element say MATNR,  then when i am declaring a variable what would be better way :

gv_matnr TYPE MATNR
or

gv_matnr TYPE MARA-MATNR.

0 Kudos

Dear Abhinav,

Both ways are same its just for declaring variables or fields, Both ways are standardly recommended Abaper use as per their ease.

If you are thinking about performance I don't think it reflects to any performance.

I hope this help you.

Regards,

Muhammad Taha

0 Kudos

Hi , it's the first option you should use because data elements are not table-specific and they can be used in multiple tables for defining fields in them. Also, please refer SAP Help for more details. where it shows an example to define a field using this statement:

DATA CONNID TYPE S_CONN_ID.

Best Regards.

0 Kudos

my opinion,

Both ways are same in performance, but i prefer to declare variables with table name, because it increases the readability of your code. at the time of analysis it makes more sense to your declaration.

Hope this helps.

former_member183164
Active Participant
0 Kudos

Hi,

Both will give the same result without decreasing the performance of the program.

But I like to use Data Element.

MukeshKumar
Participant
0 Kudos

This message was moderated.

Former Member
0 Kudos

Hi Abhinav,

It is recommended to use data element if you define any variable in program.This is the best programming practice.In old codes you may find variable declaration with table-field name, but in new codes it is recommended to use data elements.

DATA : gv_matnr TYPE matnr   (recommended )

DATA : gv_matnr TYPE mara-matnr ( not recommended )

Regards,

Rakesh

Former Member
0 Kudos

Hi abhinav ,

when i first used ABAP i used to declare like this

data:matnr type matnr .

But as i went on with regular practice and came to work in real time i declared the like this :

data: matnr type mara-matnr .

When declaring long internal tables and many internal tables for producing structure during report production  it will be helpful for yourself only to differentiate from where the the table data has come from during your own see through (checking your own code) of code . Now this procedure helped me while coding , and it depends upon you which method u would prefer .

Hope this description helps you .

Take care ,

Rohan

Sandra_Rossi
Active Contributor
0 Kudos

This conversation looks like all discussions about myths. I really wonder on which factual arguments people say that "TYPE Master Table- Field" is not recommended. I've heard about this myth for 15 years. Can anybody find this in the official ABAP Programming Guidelines?

Clemenss
Active Contributor
0 Kudos

Hi,

My 2 cents:

Since some ABAP releases <field>-<tablename> can be used in function and method interface parameter declaration too. In the ABAP source you use the field in a specific table-related context. So use this table for declarations. Even unexperienced people will be happy when maintenance has to be done. At first glance, you know what it's all about.

Btw, one of the worst sources for style hints are ABAP Example programs.

SAP knows and disabled ABAP test cockpit checks for their own code.


Regards,

Clemens