when working on Custom programs we sometimes end up using Hard-coded values in check conditions, select conditions etc … There is a lot of methods to avoid Hardcoded values as using TVARVC table or create a custom table There is also Sets.
In this Tips and tricks blog post I will show you how to create a SET and use it in your Custom program.
In this example i will create a SET containing the list of plants and then I will read the data in a custom program and use them in a CHECK condition.
Create a SET using Transaction GS01
Go to transaction GS01 and populate the Set Name , the Table Name and click enter .
Populate the field name.
Populate the set values and save.
When you save the Set the system will not ask you to create a Transport Request so you need to do it manually I will show you later how to create a transport request for a SET.
Change a Set using Transaction GS02
Go to transaction GS02, specify the set name and hit Enter.
Here you can change the values of your set and save.
Display a Set using transaction GS03
Go to transaction GS03, specify the Set name and hit enter.
Call a SET in a program
Source Code
REPORT Z_RIM_ABASSI. TABLES: MARC. DATA: GT_WERKS LIKE RGSB4 OCCURS 0 WITH HEADER LINE. *-- Create a range to store the data from the Set RANGES: R_WERKS FOR MARC-WERKS. *-- Read the set CALL FUNCTION 'G_SET_GET_ALL_VALUES' EXPORTING SETNR = '0000Z_WERKS_SET' TABLES SET_VALUES = GT_WERKS EXCEPTIONS SET_NOT_FOUND = 1 OTHERS = 2. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. *-- populate the range CLEAR R_WERKS[]. R_WERKS-SIGN = 'I'. R_WERKS-OPTION = 'EQ'. LOOP AT GT_WERKS. R_WERKS-LOW = GT_WERKS-FROM. APPEND R_WERKS. ENDLOOP.
How to transport a set
Go to transaction GS02 and specify your Set Name
Go to utilities -> transport -> Transport Request
Select Sets and click on
Select the SET and click on execute
Now create your Transport Request