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
-
Economics & Finance
Finding a particular value in internal table itab in ABAP
You can use a READ statement in combination with TRANSPORTING NO FIELDS to find a particular value in an internal table without transferring data to a work area. This approach is more efficient as it skips the data transfer process and avoids unnecessary loops.
Basic Syntax
The TRANSPORTING NO FIELDS clause tells ABAP to only check if the record exists without copying any field values to the work area ?
READ TABLE itab WITH KEY field_name = 'value' TRANSPORTING NO FIELDS. IF sy-subrc = 0. " Record found - perform required actions ELSE. " Record not found ENDIF.
Example
Here's a practical example showing how to search for a specific value in an internal table ?
DATA: BEGIN OF wa_employee,
emp_id TYPE string,
emp_name TYPE string,
END OF wa_employee.
DATA: itab_employees LIKE TABLE OF wa_employee.
" Fill the internal table with sample data
wa_employee-emp_id = '001'.
wa_employee-emp_name = 'John'.
APPEND wa_employee TO itab_employees.
wa_employee-emp_id = '002'.
wa_employee-emp_name = 'Alice'.
APPEND wa_employee TO itab_employees.
" Search for employee with ID 'ABC'
READ TABLE itab_employees WITH KEY emp_id = 'ABC' TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
WRITE: 'Employee with ID ABC found.'.
ELSE.
WRITE: 'Employee with ID ABC not found.'.
ENDIF.
The output of the above code is ?
Employee with ID ABC not found.
Benefits
Using TRANSPORTING NO FIELDS provides several advantages ?
- Performance: No data transfer overhead
- Memory efficiency: Avoids unnecessary work area population
- Clean code: Clear intent to only check existence
Conclusion
The READ TABLE statement with TRANSPORTING NO FIELDS is an efficient way to check if a specific value exists in an ABAP internal table without the overhead of data transfer operations.
