2014 Feb 19 8:25 AM
How to capture standard domain values ( Ex :- VBTYP EQ 'V' ) OR ( VBTYP EQ 'C' ) in our program instead of hard coding..?
Thanks in advance..............
2014 Feb 19 8:37 AM
hi mahi,
What do you exactly want.. ? If you don't want to hard code the values in program , then try creating constants and use the constant in program..
Regards,
Sivaganesh
2014 Feb 19 8:44 AM
i think we should not use even CONSTANTS (keyword) also..
is there any alternative way..?
Can we give on example..?
2014 Feb 19 8:49 AM
2014 Feb 19 9:33 AM
Sivaganesh Krishnan wrote:
why can't you use constants.. ?
Good question. If the values are only ever going to be all of the domain, then you should use the function module as already supplied.
Otherwise use constants. It is what they are for. Any other solution is piling up a world of pain when it comes to maintanence.
Do not use TVARVC to store constants. That would be VERY bad program design. The only time to use TVARVC is when you want to be able to alter some aspects of the a program directly in production. Even then, there may be better solutions.
2014 Feb 19 8:41 AM
Hi Mahi,
either you declare those fields for a variable in initialization, and whele fetching data
just check these values.
DATA : lv_field type char .
lv_field = { put your all values here for VBTYP }.
at the time of fetching you can check through lv_field, that it matches your record or not.
2014 Feb 19 8:48 AM
2014 Feb 19 9:18 AM
Hi Mahi,
Use function module DD_DOMVALUES_GET.
In your case VBTYP domain has 65 predefined values.
Regards,
Vineesh
2014 Feb 19 10:25 AM
In our projects, the best practise, that was developed is to store the domain values in the atributes part of a global class (static constant). This way you earn the advantage of where-used list (which you lose in e.g. a global constant in a report). You access the constant via expression zcl_classname=>gc_constant_name, which also gives the code another semantic part.
2014 Feb 19 10:41 AM
Hi Every one..thanks for such huge response...
Below is the one want to change..instead of hard coding ( 'v' and 'c' ).
If need to do this with TVARV and reply back with a clear solution.
Thanks....
2014 Feb 19 10:51 AM
personally, i would probably resolve this issue with a select-option (or data range if select option not possible).
The reason being is
1- it cuts down on more over worked solution - going off to maintain TVARV and remembering it when you want to maintain the program 18 months later etc.
2-flexible for users
create your selection screen.
set the values in an initialisation/load-of-program event (or somewhere before the select is done).
The code remains easy to maintain from one point - the actual program.
Users can 'add/remove' entries if you use a select-option - so it is not rigid.
Whilst there is some element that it is 'hardcoded' you are providing flexible maintenance, user friendly interface allowing deviation to the C / V 'normal' combo. Change the select statement to use the IN operator against the select option - you are avoiding repeated select statements.
dont over engineer a simple requirement - everyone is a winner with this approach!
2014 Feb 19 10:51 AM
You already was given recommendations (not using TVARV, using global constants). Is there anything you did not understand?
2014 Feb 19 10:54 AM
VBTYP isn't part of VBFA... but anyway, 34 years of programming experience, 14 of them with ABAP, tells me:
Define constants for 'V' and 'C' with meaningful names, e.g. c_purchase_order and c_order . This is correct and good programming practice (Note, Jozef's and Steve's answers are good variants of this).. All other solutions are, for this requirement, bad programming.
You do not, and should not do this with TVARVC.