Many times we need to maintain some Sets in SAP; normally we use these Sets in Boolean Logic formulas, Report writer, Allocation, Planning, Rollups, and Currency Translation in Financial accounting and controlling Module. But we can also use these basic sets to store some validation related values.
Types of Sets:
- 1. Basis Sets.
- 2. Data Sets.
- 3. Single-dimension Sets.
- 4. Multi-dimension Sets.
Now the purpose of this document is to explain how these Sets are important in ABAP, and how we can access these maintained sets in our ABAP Program.
Example: Maintain List of User using sets and check these user details in abap program.
Creation of Sets:
Go to Transaction Code GS01; put your Set name which you want to create. And for the Set we need to maintain Basis data, Click F4 help, then it will ask you for below 3 options.
Depending on your requirement you can select the table. For example we selected BNAME from USR01 table for user details.
Now, we have maintained value as shown in below screen:
All the values maintained against Set are stored in table SETLEAF.
Important Transaction Code for Sets:
GS01 Create set
GS02 Change Set
GS03 Display Set
GS04 Delete set
GS07 Exports sets
GS08 Import sets
GS09 Copy sets from client
Benefits of Using Sets:
In most cases, we create custom table and provide maintenance of the table to store some validation related values. We can maintain those values against a Set. If volumes of values are huge then avoid maintaining it using Sets.
Use sets to maintain TVARV values.
Using Sets in ABAP:
Getting all the maintained values against one set.
DATA: t_set TYPE TABLE OF rgsb4,
wa_set TYPE rgsb4.
DATA: v_check TYPE C VALUE ‘ ‘.
CALL FUNCTION ‘G_SET_GET_ALL_VALUES’
client = sy-mandt
setnr = ‘ZSET’
table = ‘USR01’
class = ‘0000’
fieldname = ‘BNAME’
set_values = T_SET
set_not_found = 1
OTHERS = 2.
Here, table T_SET contains all the values belonging to SET ‘ZSET’.
You can also use the below Function Module to Create/Maintain Sets.
Creation of Set using FM.
CALL FUNCTION ‘G_SET_CREATION’
set_class = ‘0000’ “Set class
set_name = ‘ZSET ” Set Name (not ID) of Set to be Created
table = ” Table for which the Set is to be Created
types = ” Set Types Allowed (BSMD)
* field = SPACE ” Field for New Set
* kokrs = ” Controlling Area for CO Groups
* lib = ” Report Library for RW Sets Generated
* rname = ” Report for Generated RW Sets
* eccs_dimen = “EC-CS Org. Unit
* eccs_itclg = “EC-CS Chart of Accounts
* eccs_sityp = “EC-CS Subitem Category
* use_group_maintenance = SPACE Use Group Maintenance for CO Groups
new_set = “Set ID (not Name) of the New Set
WRONG_TABLE = 1
WRONG_SET_NAME = 2
NO_SET_CREATED = 3
WRONG_SETCLASS = 4
SET_ALREADY_EXISTS = 5
WRONG_TYPE = 6
WRONG_FIELD = 7
NO_FIELD_PICKED = 8
NO_TYPE_PICKED = 9
GROUP_MAINTENANCE_ERROR = 10
Maintenance of Sets:
CALL FUNCTION ‘G_SET_MAINTENANCE’
* CLASS_MASK = ‘ ‘
* TABLE_MASK = ‘ ‘
* MASTER_FLAG = ‘ ‘
* USE_GROUP_MAINTENANCE = ‘ ‘
* SHOW_GROUP_VALUE = ‘ ‘
* CLASS =
SET = ‘ZSET’
* TABLE =
ILLEGAL_FUNCTION = 1
NO_SETS = 2
NO_SET_PICKED = 3
SET_NOT_FOUND = 4
NO_AUTHORITY = 5
OBJECT_CREATED_BY_SAP = 6
GROUP_MAINTENANCE_ERROR = 7
DYNAMIC_SET_ERROR = 8
OTHERS = 9
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
Getting set value using Set IDs:
DATA: w_setid LIKE sethier-setid,
int_vlaues TYPE STANDARD TABLE OF rgsbv.
CALL FUNCTION ‘G_SET_GET_ID_FROM_NAME’
shortname = ‘ZSET’ “Set Name
new_setid = w_setid
OTHERS = 1.
IF sy-subrc NE 0.
WRITE ‘Invalid Set’.
CALL FUNCTION ‘G_SET_FETCH’
setnr = w_setid
set_lines_basic = int_vlaues
OTHERS = 1.