REDUCE Operator in ABAP- Use1

1

New REDUCE operator can be used in many ways.

 

 

Normally we use loop with increment count to get to know the specific matching record in an internal table.

2.jpg

OUTPUT

34

New REDUCE operator can be used to do the same in an improved way .

5.jpg

CODE

DATAls_spfli TYPE  spfli,
      lt_spfli TYPE TABLE OF spfli,
      count1   TYPE i,
      count2   TYPE i.

START-OF-SELECTION.
  SELECT FROM spfli INTO TABLE lt_spfli.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program sy-repid
      i_structure_name   'SPFLI'
    TABLES
      t_outtab           lt_spfli.

  LOOP AT lt_spfli INTO ls_spfli WHERE carrid 'LH'.
    count1 count1 + 1.
  ENDLOOP.

  WRITE:'Occourence of carrid- LH' COLOR 3count1 COLOR 3.

” COUNT operator use

  count2 REDUCE iINIT FOR ls IN lt_spfli
                     WHERE carrid 'LH' )
                     NEXT ).
  WRITE:'Occourence of carrid- LH'count2.

OUTPUT

6.jpg


 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s