Check If an Internal Table is Empty Using ABAP

Today you will learn how to check if an internal table is empty, there are 3 easy ways you can implement in your ABAP.

1. using SY-SUBRC statement.

Once you’ve executed an internal table using query, use the sy-subrc statement to check if the internal table is empty or not. If it’s empty the return value will be “4″, if it’s not empty then the return value will be “0″.

select ... into table itab from ...

if sy-subrc = 0.

"Your statement here



endif.

2. Using describe … lines.

This statement will return the lines in the internal table, if empty then the return value will be 0.

Data nRow TYPE i.

DESCRIBE TABLE itab LINES nrow.

if nrow = 0.

"Your statement here

endif.

3. Using IS INITIAL statement. If the internal table is INITIAL then it’s empty.

select * into table itab from ....

if itab is INITIAL. "INITIAL is EMPTY

"Your statement here
endif.

Subscribe in a reader

Comments

0 Responses to "Check If an Internal Table is Empty Using ABAP"

Post a Comment

Stay Updated