banner ads

ABAP For Iteration with Where condition | For Statement with Where clause | For syntax with Where condition


FOR Iteration with where condition

As of ABAP 740, There is a new iteration expression available – FOR. This can be used along with VALUE to populate the desired data. ABAP 740 has lot of new features and FOR is one of them. FOR is the Iteration Expression. An iteration expression is to perform the iteration on the table. 


FOR Expression in ABAP 7.40

In this article we are discussing about one of the most important feature of new ABAP that is for statement or for iteration expression with where clause or where condition. SAP has introduced for as an alternative of loop statement but with consideration of performance. In this blog we will see how to use where clause or where condition in For syntax.

In last article we have discussed about how to use For iteration in SAP ABAP. If you didn’t read that article then please click here to read For Iteration Expression in SAP ABAP.

Below is the sample code for your reference which I have used in Video session available on youtube. Click here to see video session on For statement with where clause in Sap Abap. As you can copy this code for practice purpose only and can see how does it work in actual ABAP Platforms.


FOR Statement with Where condition


REPORT ZTEST_FOR.


types BEGIN OF ty_empdata,
        name 
TYPE char10,
        city 
TYPE char10,
        
END OF ty_empdata,

      tty_empdata 
TYPE STANDARD TABLE OF ty_empdata WITH EMPTY KEY,
      tty_city    
TYPE STANDARD TABLE OF char10 WITH EMPTY KEY.


DATA(lt_empdata) = VALUE tty_empdata(
                                     
name 'Jackson' city 'MUMBAI' )
                                     
name 'Ramesh'  city 'Pune' )
                                     
name 'Mahesh'  city 'banglore' )
                                     
name 'swapnil' city 'MUMBAI' ) ).


write 'TABLE DATA'.


LOOP AT lt_empdata ASSIGNING FIELD-SYMBOL(<FS_EMPDATA>).
  
WRITE / <FS_EMPDATA>-NAMESPACE<FS_EMPDATA>-CITY.
ENDLOOP.

skipskip.

write 'where condition'.

data(lt_city) = VALUE tty_cityFOR ls_empdata IN lt_empdata
                                
WHERE city 'MUMBAI')
                                
ls_empdata-city ) ).

LOOP AT lt_city INTO DATA(ls_city) .

  
write / ls_city.

ENDLOOP.




Output



Technical Explanation of program.

 1) Defined structure with two fields.


     2)  Defined table type in order to create internal table.

 


     3)  Created internal table and filled with values.



     4)  Display values in internal table.




     5) Logic to read data from table using FOR statement and where clause


     6) Display final data after for and where condition.




     7)  Output.





Good Work !!!!

Now you have learnt how to use FOR iteration with where condition in SAP ABAP so now you can easily replace Loop with For statement and write code.

Thanks for reading. 😀







2 comments:

  1. that for with where stated above does not work

    ReplyDelete
  2. CASINO HOTEL CASINO, LAS VEGAS, NV
    Casino hotel and casino in Las 의왕 출장마사지 Vegas, NV - Find reviews and discounts for titanium tubing AAA/AARP members, seniors, 논산 출장샵 long stays & military. Book 전주 출장샵 now! 거제 출장샵

    ReplyDelete