Backward loop of internal table in ABAP

Use the keyword: STEP and provide sign as -(negative) which is backward direction and the number of specifies how many records we want to iterate over.

Report

REPORT yr_back_loop.

SELECT *
  FROM  ytl_ab_stu_det
  INTO TABLE @DATA(lt_stu).
WRITE: / 'Forward loop:'.
LOOP AT lt_stu INTO DATA(lr_stu).
  WRITE: / lr_stu-stu_id, lr_stu-stu_name, lr_stu-stu_branch, lr_stu-stu_marks.
ENDLOOP.
SKIP 3.
WRITE: / 'Backward loop:'.
LOOP AT lt_stu INTO lr_stu STEP -1.
  WRITE: / lr_stu-stu_id, lr_stu-stu_name, lr_stu-stu_branch, lr_stu-stu_marks.
ENDLOOP.

Output




********************************Thank You*****************************


Comments

Popular posts from this blog

New syntax for append- VALUE (new syntax 7.4+) in ABAP

Read statement new syntax in ABAP. (7.4+).

Concatenation new syntax( 7.4+ ).