SAP Database - The Unofficial SAP Knowledge Base

FETCH : ABAP Keyword a day

Print This Post Email This Post Written by admin on Feb 8th, 2008 | Filed under: SAP General

FETCH

Basic form
FETCH NEXT CURSOR c target.
Effect
Uses the cursor c to read the next line or lines from the dataset of a database table determined by OPEN CURSOR . The cursor must be a variable of the type CURSOR and must be explicitly opened with OPEN CURSOR . To specify the target area into which you read the selected data, use INTO clause target .

FETCH belongs to the Open SQL command set.

After each execution of the FETCH statement, the system field SY-DBCNT contains the number of lines read so far.

The return code value is set as follows:

SY-SUBRC = 0 At least one line was read.
SY_SUBRC = 4 No line was read.
Example
Output the passenger list for the Lufthansa flight 0400 on 28-02.1995:

TABLES SBOOK.
DATA C TYPE CURSOR,
WA LIKE SBOOK.
OPEN CURSOR C FOR SELECT * FROM SBOOK
WHERE
CARRID = 'LH ' AND
CONNID = '0400' AND
FLDATE = '19950228'
ORDER BY PRIMARY KEY.


DO.
FETCH NEXT CURSOR C INTO WA.
IF SY-SUBRC <> 0.
CLOSE CURSOR C. EXIT.
ENDIF.
WRITE: / WA-BOOKID, WA-CUSTOMID, WA-CUSTTYPE,
WA-SMOKER, WA-LUGGWEIGHT, WA-WUNIT,
WA-INVOICE.
ENDDO.

Related SELECT

If you like this post, you may as well like these too:

  1. DELETE : ABAP Keyword a day DELETE Delete from a database table - DELETE FROM dbtab WHERE condition. - DELETE FROM (dbtabname) WHERE condition. - DELETE dbtab. - DELETE *dbtab. - DELETE (dbtabname) … ....
  2. DESCRIBE : ABAP Keyword a day DESCRIBE Return attributes of a field - DESCRIBE FIELD f. Return attributes of an internal table - DESCRIBE TABLE itab. Determine distance between two fields - DESCRIBE DISTANCE BETWEEN...
  3. EXEC : ABAP Keyword a day EXEC Basic form EXEC SQL. Addition … PERFORMING form Effect In contrast to Open SQL , addressed database tables do not have to be known to the ABAP/4 Dictionary...
  4. CLOSE: ABAP Keyword a day CLOSEBasic form 1. CLOSE DATASET dsn.2. CLOSE CURSOR c.Basic form 1CLOSE DATASET dsn.EffectCloses the file dsn , ignoring any errors which may occur. CLOSE is required only if you...
  5. APPEND: ABAP Keyword a day APPEND Variants: 1. APPEND [wa TO|INITIAL LINE TO] itab. 2. APPEND LINES OF itab1 [FROM idx1] [TO idx2] TO itab2. 3. APPEND [wa TO] itab SORTED BY f.Variant 1...



Leave a Reply