SAP Tips: How to use dynamic variants in TVARVC table in ABAP development
Avoiding hard coding in programs can sometimes be difficult, but it is essential in order to maintain the integrity of your SAP system and avoid a maintenance headache going forward.
SAP has a standard solution to this conundrum – table TVARVC.
This table can be maintained using transaction STVARV.
See below for the transaction. It has the option to add single variables for using with a PARAMETER selection in an ABAP program/transaction, or the option to use SELECT-OPTIONS in an ABAP program/transaction.
Once you create and save your entries in transaction STVARV, the entries are written out to table TVARVC, as below.
As can be seen, the “Type” refers to “S” for SELECT-OPTIONS and “P” for “PARAMETERS” in your ABAP program.
For example, your ABAP statement to read a parameter could look something like:
SELECT SINGLE low
WHERE type = ‘P’ AND name = ‘variable name’.
This saves you from hard coding and means whenever a variable changes its value, you can amend using transaction STVARV instead of amending the ABAP program directly.
I hope you find this useful. Stay tuned for another SAP Tip from Eursap soon!
Be sure to also check out Eursap’s SAP Blog for more in depth articles.