I'm trying to use this SELECT statement in ABAP:
SELECT DISTINCT * FROM dbtab
INTO CORRESPONDING FIELDS OF TABLE itab
WHERE field1+7(16) IN s_field1
AND field2 IN s_field2.
but I can't use offset for a dbtab column. How can I solve this problem?
I'm trying to avoid loop like
SELECT DISTINCT * FROM dbtab
WHERE field2 IN s_field2.
IF field1+7(16) IN s_field1
...
endif.
endselect.
OFFSET and FETCH Clause are used in conjunction with SELECT and ORDER BY clause to provide a means to retrieve a range of records. The OFFSET argument is used to identify the starting point to return rows from a result set. Basically, it exclude the first set of records.
The OFFSET clause in a SELECT query causes the result set to start some number of rows after the logical first item. The result set is numbered starting from zero, so OFFSET 0 produces the same result as leaving out the OFFSET clause.
OFFSET in SQL is generally used with the ORDER BY clause with a value greater than or equal to zero. Syntax using OFFSET: SELECT column_names FROM table_name ORDER BY column_names OFFSET n ROWS //n is the number of rows to be excluded.
If a limit count is given, no more than that many rows will be returned (but possibly fewer, if the query itself yields fewer rows). LIMIT ALL is the same as omitting the LIMIT clause, as is LIMIT with a NULL argument. OFFSET says to skip that many rows before beginning to return rows.
You can't use offset in OPEN SQL.
I would recommend to make a SELECT into an internal table and loop over it like this.
SELECT DISTINCT * FROM dbtab
INTO CORRESPONDING FIELDS OF TABLE itab
WHERE field2 IN s_field2.
LOOP AT dbtab into wa_itab.
IF wa_itab-field1+7(16) IN s_field1
...
ENDIF.
ENDLOOP.
On the other hand I would also define the internal table as SORTED or HASHED or if you prefer try to SORT itab by the field you are making the comparison. Field symbols could be an alternative also.
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With