Get Example source ABAP code based on a different SAP table
ID FETCH • FETCH ABAP_STATEMENT_OSQL • INTO FETCH • APPENDING FETCH • NEXT CURSOR FETCH
FETCH> Short Reference >
ABAP_SYNTAX FETCH NEXT CURSOR dbcur INTO$|APPENDING ...>. >
What does it do? The AB-SQL > statement FETCH> takes the rows requested by the INTO> or APPENDING> addition from the result set of the database cursor> linked with the cursor variable dbcur> from the current cursor position and assigns them to the data objects specified there. The cursor variable dbcur> must be a host variable> declared with the special predefined data type cursor>, which was opened with the statement OPEN CURSOR>> or that was assigned an open cursor. Otherwise, a catchable exception of the class CX_SY_OPEN_SQL_DB> is raised. The syntax and meaning of the addition INTO> or APPENDING> are the same as the identically named additions> of the SELECT> statement, with the exception that no inline declarations can be made there without the addition NEW>> and no LOB handles> can be created. BEGIN_SECTION SAP_INTERNAL_HINT LOB Handles will be supported in a later release but not for WITH HOLD>. END_SECTION SAP_INTERNAL_HINT If non-table-like data objects are specified after INTO>, one row is extracted. If an internal table is specified after INTO> or APPENDING>, either all rows are extracted or as many as specified in the addition PACKAGE SIZE>>. The statement FETCH> moves the position of the database cursor that is linked with dbcur> by the number of extracted rows to the next row to be extracted. If the last row of the result set was extracted in a FETCH> statement, each subsequent FETCH> statement in which dbcur> is linked with the same database cursor sets sy-subrc> to 4, without affecting the data objects specified after INTO> or APPENDING>. System Fields> The statement FETCH> sets the values of the system fields sy-subrc> and sy-dbcnt>. sy-subrc>>Meaning> 0At least one row was extracted from the result set. 4No row was extracted. After every row extraction, the statement FETCH> sets sy-dbcnt > to the number of rows extracted so far from the relevant result set. If an overflow occurs because the number or rows is greater than 2,147 ,483,647, sy-dbcnt> is set to -1. If no row can be extracted, sy-dbcnt> is set to 0.