100% found this document useful (1 vote)
301 views23 pages

Avoid Hardcoding in SAP by Using TVARVC-ABAP

Avoid Hardcoding in SAP by using TVARVC-ABAP

Uploaded by

Sam One
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
301 views23 pages

Avoid Hardcoding in SAP by Using TVARVC-ABAP

Avoid Hardcoding in SAP by using TVARVC-ABAP

Uploaded by

Sam One
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Mickael QUESNOT ©

Avoid Hardcoding in SAP by using TVARVC

1.1 Maintaining Entries in Table TVARVC

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.

Due to Hardcode, code changes is required every time for addition/modification/deletion in


the data which requires additional technical efforts along with functional for inputs & testing.
Due to Z-table creation also Additional ABAP efforts are required for DDIC creation, table
maintenance generator, domains creation or assignment, etc.

A simple Scenario or User Requirement where hardcode/z-tables should be required:

At time of sales order save, a delivery block by default with code is required in User exit
MV45AFZZ.

Code is written with hardcoded as following:

*Blocage livraison poste financés


CASE T180-TRTYP.

WHEN 'H'.

CLEAR GS_VBPA_RG.
LOOP AT XVBPA INTO GS_VBPA_RG WHERE PARVW = 'RG'.
CLEAR GS_VBPA_AG.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
1
Mickael QUESNOT ©

READ TABLE XVBPA INTO GS_VBPA_AG WITH KEY PARVW = 'AG'.


CHECK GS_VBPA_AG-KUNNR NE GS_VBPA_RG-KUNNR.
VBAK-FAKSK = 'Z1'.
ENDLOOP.

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.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
2
Mickael QUESNOT ©

For this small additions/modifications/deletion, ABAP hardcoding will be required or custom


table should be created to store the sales organization and their corresponding values which
requires additional development efforts (in creation of DDIC, its maintenance, domains, etc.).

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.

Transaction code: STVARV

There are two sections under STVARV to store parameters and Selection options.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
3
Mickael QUESNOT ©

Parameter is used when we must store only single level of data like a value.

–> Click on edit then Create Button

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
4
Mickael QUESNOT ©

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
5
Mickael QUESNOT ©

Flag Include changed entries in transport request:

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
6
Mickael QUESNOT ©

Save :

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
7
Mickael QUESNOT ©

Se16n

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
8
Mickael QUESNOT ©

Mickaël QUESNOT © - Copyright

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

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
10
Mickael QUESNOT ©

After

Mickaël QUESNOT © - Copyright

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.

Select options used when we must store multi-level of data.

–>Select Select options tab and click on create

–> Enter the Variable name and click on multiple selections

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
12
Mickael QUESNOT ©

–> click on select ranges and enter the values:

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
13
Mickael QUESNOT ©

–> Save

Mickaël QUESNOT © - Copyright

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”.

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
15
Mickael QUESNOT ©

Se16n

Before

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
16
Mickael QUESNOT ©

After

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
17
Mickael QUESNOT ©

*Pricing Communications-Condition Record

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.

IF SY-SUBRC = 0 AND GS_XKOMV-KBETR IS NOT INITIAL. "Condition Amount or Percentage

CASE VBAK-VBELN.

WHEN ' '.

IF VBAK-LIFSK IS INITIAL. "Delivery Block (Document Header)


*Blocage livraison pour encaissement d'acompte
VBAK-LIFSK = GS_TVARVC-HIGH.
ENDIF.

If any user is having the authorization of STVARV or SM30 in production system, then entries
could be changed without any TR.

Result

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
18
Mickael QUESNOT ©

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
19
Mickael QUESNOT ©

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
20
Mickael QUESNOT ©

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
21
Mickael QUESNOT ©

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
22
Mickael QUESNOT ©

Mickaël QUESNOT © - Copyright

https://www.linkedin.com/in/mickaelquesnot/
23

You might also like