Avoid Hardcoding in SAP by Using TVARVC-ABAP
Avoid Hardcoding in SAP by Using TVARVC-ABAP
The transactions STVARV and STVARVC are available for maintaining the table variants. With
transaction STVARV you can maintain the entries in table TAVRVC for the current client
(display/change/add). Transaction STVARVC only allows you to maintain the entries in client
000.
At the time of discussing client’s pain points and challenges which they are facing or reviewing
the ABAP codes we have noticed that many variables are hardcoded, or many Z-tables are
present in the SAP system for maintenance of data to use in user exits, BADI’s, Reports, Forms,
etc.
At time of sales order save, a delivery block by default with code is required in User exit
MV45AFZZ.
WHEN 'H'.
CLEAR GS_VBPA_RG.
LOOP AT XVBPA INTO GS_VBPA_RG WHERE PARVW = 'RG'.
CLEAR GS_VBPA_AG.
https://www.linkedin.com/in/mickaelquesnot/
1
Mickael QUESNOT ©
WHEN OTHERS.
CLEAR GS_VBPA_RG.
LOOP AT XVBPA INTO GS_VBPA_RG WHERE UPDKZ = 'I'
AND PARVW = 'RG'.
CLEAR GS_VBPA_AG.
READ TABLE XVBPA INTO GS_VBPA_AG WITH KEY PARVW = 'AG'.
CHECK SY-SUBRC IS INITIAL.
VBAK-FAKSK = 'Z1'.
ENDLOOP.
ENDCASE.
User Challenges :
1. In future, you need to change the delivery block.
https://www.linkedin.com/in/mickaelquesnot/
2
Mickael QUESNOT ©
Solution:
TVARVC:
TVARVC is standard table given by SAP to store the data under variants. we can put the values
in TVARVC table to avoid hardcoding and/or creation of custom tables.
There are two sections under STVARV to store parameters and Selection options.
https://www.linkedin.com/in/mickaelquesnot/
3
Mickael QUESNOT ©
Parameter is used when we must store only single level of data like a value.
https://www.linkedin.com/in/mickaelquesnot/
4
Mickael QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/
5
Mickael QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/
6
Mickael QUESNOT ©
Save :
https://www.linkedin.com/in/mickaelquesnot/
7
Mickael QUESNOT ©
Se16n
https://www.linkedin.com/in/mickaelquesnot/
8
Mickael QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/
9
Mickael QUESNOT ©
In ABAP, we can extract this value by the below snippet for using it in the program:
Before
https://www.linkedin.com/in/mickaelquesnot/
10
Mickael QUESNOT ©
After
https://www.linkedin.com/in/mickaelquesnot/
11
Mickael QUESNOT ©
SELECT SINGLE LOW INTO GV_LOW FROM TVARVC WHERE NAME = 'ZFAKSK'.
CHECK SY-SUBRC = 0.
VBAK-FAKSK = GV_LOW.
https://www.linkedin.com/in/mickaelquesnot/
12
Mickael QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/
13
Mickael QUESNOT ©
–> Save
https://www.linkedin.com/in/mickaelquesnot/
14
Mickael QUESNOT ©
Please note: Creation and modification via STVARV don’t ask for Transport request unless we
have not marked the checkbox “Include Changed entries in transport request”.
https://www.linkedin.com/in/mickaelquesnot/
15
Mickael QUESNOT ©
Se16n
Before
https://www.linkedin.com/in/mickaelquesnot/
16
Mickael QUESNOT ©
After
https://www.linkedin.com/in/mickaelquesnot/
17
Mickael QUESNOT ©
CLEAR GS_TVARVC.
SELECT SINGLE * INTO GS_TVARVC FROM TVARVC WHERE NAME = 'ZKSCHL_LIFSK'.
CLEAR GS_XKOMV.
READ TABLE XKOMV INTO GS_XKOMV WITH KEY KSCHL = GS_TVARVC-LOW.
CASE VBAK-VBELN.
If any user is having the authorization of STVARV or SM30 in production system, then entries
could be changed without any TR.
Result
https://www.linkedin.com/in/mickaelquesnot/
18
Mickael QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/
19
Mickael QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/
20
Mickael QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/
21
Mickael QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/
22
Mickael QUESNOT ©
https://www.linkedin.com/in/mickaelquesnot/
23