Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Using subset of items present in the list in SAP Program
When working with SAP programs, you often need to handle scenarios where only a subset of items from a list should be processed. There are several approaches you can use depending on your specific requirements.
Using SWITCH CASE Statement
You can use a SWITCH CASE statement to handle your scenario. This is a good choice if you know well in advance what all properties are required and what is not required. Also, it will let you to unit test your code effectively.
Example
Here's how you can implement a SWITCH CASE approach in ABAP ?
DATA: lv_item_type TYPE string,
lv_process TYPE abap_bool.
CASE lv_item_type.
WHEN 'MATERIAL'.
lv_process = abap_true.
WHEN 'SERVICE'.
lv_process = abap_true.
WHEN 'EQUIPMENT'.
lv_process = abap_false.
WHEN OTHERS.
lv_process = abap_false.
ENDCASE.
IF lv_process = abap_true.
" Process the item
ENDIF.
Using Dictionary Collections
Otherwise, you can go for a collection like a dictionary. This approach provides more flexibility when the subset criteria may change dynamically at runtime.
Example
Using internal tables as dictionary-like structures in ABAP ?
TYPES: BEGIN OF ty_filter,
item_type TYPE string,
include TYPE abap_bool,
END OF ty_filter.
DATA: lt_filter TYPE TABLE OF ty_filter,
ls_filter TYPE ty_filter.
" Define filter criteria
ls_filter-item_type = 'MATERIAL'.
ls_filter-include = abap_true.
APPEND ls_filter TO lt_filter.
ls_filter-item_type = 'SERVICE'.
ls_filter-include = abap_true.
APPEND ls_filter TO lt_filter.
" Check if item should be processed
READ TABLE lt_filter INTO ls_filter
WITH KEY item_type = lv_item_type.
IF sy-subrc = 0 AND ls_filter-include = abap_true.
" Process the item
ENDIF.
Alternative Data Structures
You can think of using HashSet or hashtable as well, it entirely depends upon the usage of the list created. In SAP ABAP, you can use sorted or hashed internal tables for better performance when dealing with large datasets.
Conclusion
Choose SWITCH CASE for static, well-defined subsets and dictionary-like collections for dynamic filtering requirements. The approach depends on your specific use case and performance needs.
