05-29-2016 5:02 AM
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
05-30-2016 7:43 AM
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?
05-29-2016 5:34 AM
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 !
05-29-2016 8:37 AM
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.
05-29-2016 9:45 AM
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
05-29-2016 1:23 PM
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.
05-30-2016 5:09 AM
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.
05-29-2016 1:29 PM
Hi,
Both will give the same result without decreasing the performance of the program.
But I like to use Data Element.
05-29-2016 8:07 PM
05-29-2016 10:53 PM
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
05-30-2016 7:34 AM
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
05-30-2016 7:43 AM
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?
05-30-2016 8:13 AM
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