Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

SAP EWM Help Latest Questions

  • 0
  • 0
DPM125
Beginner

How can you use the new FOR expression to loop through a table and build a new one?

This replaces the need for LOOP AT, IF, and APPEND all in one line—powerful and readable.

*&---------------------------------------------------------------------*
*& Report  ZREP_LCLCLASS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zrep_lclclass.
TYPESBEGIN OF ty_user,
         name   TYPE string,
         status TYPE string,
       END OF ty_user.

DATAlt_users TYPE STANDARD TABLE OF ty_user WITH EMPTY KEY,
      lt_names TYPE STANDARD TABLE OF string WITH EMPTY KEY.

lt_users VALUE #(
  name 'Alice'   status 'ACTIVE' )
  name 'Bob'     status 'INACTIVE' )
  name 'Charlie' status 'ACTIVE' )
).

lt_names VALUE string_table(
  FOR user IN lt_users
  WHERE status 'ACTIVE' )
  user-name )
).

LOOP AT lt_names INTO DATA(name).
  WRITE/ name.
ENDLOOP.

 

Output:
Alice
Charlie

Related Questions

Leave an answer

Leave an answer