Creating Sets in SAP ABAP
ABAPers often feels the need to have a set of values, often fixed, and not code dependant. ABAPer then do not required to change the program code every time if addition or change in the ‘Value Set’ happens. We can just use Sets (which are placed outside the code) for this flexibility.
What is a Set?
Sets are flexible structures for Organizing hierarchies and quantities.
Sets can be used for Grouping values or giving value intervals in a set and several sets into a hierarchy.
In SAP Sales and Delivery, if the sales organization for a specific place are to be placed in different ways we can use these SETS. Many a time, it is required to group these Sales Org to the types of customer . In order to maintain such data, SAP has provided a methodology known as Sets.
Steps for Creating Sets:
Go to Transaction GS01
Enter the following data:
1) Set name – Zname of the table.
2) Table name that contains the dimensions the set will use (You can create sets using a user table that contains specific dimensions from a table).
3) Select Set Type – we restrict our tutorial to Basic Set.
4)Reference Set- if you want to refer any existing set.
SAY..If u don’t want to use the reference set . than enter the name of set Z**********. In the next screen, enter the field name you want to take reference from(say, MATNR or WERKS).
Now we have to enter values inside the defined Set. We have to follow following screens:
Enter basic description of the Set. Also enter the values for your Set. Save and Exit.
Advantanges of Sets:
Reduces Maintenance, Advantageous for Functional Consultant, authorization can be given to Business User for the Set maintenance.
Create Set (GS01), Change Set(Gs02), Display Set(GS03), Delete Set(Gs04).
How to Read Sets in ABAP?
The data stored in SET can be read through function module G_SET_GET_ALL_VALUES. The FROM and TO values imported from the table parameter SET_VALUES gives the data stored in a set.
Example code for ABAPers
DATA: t_set_values TYPE TABLE OF rgsb4,
WA_TSETVALUES TYPE RGSB4.
CALL FUNCTION ‘G_SET_GET_ALL_VALUES’
client = sy-mandt
setnr = ‘Z_TEST1’
table = ‘MARA’
class = ‘0000’
fieldname = ‘MATNR’
set_values = t_set_values
set_not_found = 1
OTHERS = 2.
IF SY-SUBRC EQ 0.