在ABAP程序中使用集

标签:
set集 |
分类: ABAP-Basic |
Introduction:
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:
Maintaining Sets:
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.
http://scn.sap.com/servlet/JiveServlet/downloadImage/102-45313-1-263084/SDN1.JPG
Depending on your requirement you can select the table. For example we selected BNAME from USR01 table for user details.
http://scn.sap.com/servlet/JiveServlet/downloadImage/102-45313-1-263086/616-400/SDN1.JPG
Now, we have maintained value as shown in below screen:
http://scn.sap.com/servlet/JiveServlet/downloadImage/102-45313-1-263087/SDN1.JPG
All the values maintained against Set are stored in table SETLEAF.
Important Transaction Code for Sets:
GS01
GS02
GS03
GS04
GS07
GS08
GS09
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.
Example:
DATA: t_set TYPE TABLE OF rgsb4,
wa_set TYPE rgsb4.
DATA: v_check TYPE C VALUE ' '.
client = sy-mandt
fieldname
TABLES
set_values
EXCEPTIONS
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
*
*
*
*
*
*
*
*
Maintenance of Sets:
CALL FUNCTION 'G_SET_MAINTENANCE'
*
*
*
*
*
IMPORTING
*
*
EXCEPTIONS
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
ENDIF.
Getting set value using Set IDs:
DATA: w_setid
int_vlaues
CALL
EXPORTING
shortname
IMPORTING
new_setid
EXCEPTIONS
OTHERS
IF sy-subrc
WRITE
ENDIF.
CALL
EXPORTING
setnr
TABLES
set_lines_basic = int_vlaues
EXCEPTIONS
OTHERS