Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

how to check identical values in internal table column

former_member815151
Discoverer
0 Kudos
3,630

This is my line items data's which is in an internal table . so for REGNO if the line item value is fully 'R' means it has to show "Completed" , if it is fully 'D' means it has to show " Delivered " if it is mixing with 'D' and 'R' means it has to show "Not completed"

The output should come like this .

5 REPLIES 5
Read only

Mahmoud-Farag
Participant
3,193

My Idea you can use : IF line_exists ()

IF line_exists( it[ REGNO = '100' Line_item = 'R' ] ) AND line_exists( it[ REGNO = '100 Line_item = 'D' ' ] )

-> Not completed
Elseif line_exists( it[ REGNO = '100 Line_item = 'R' ] )

-> Completed

Elseif line_exists( it[ REGNO = '100 Line_item = 'D' ] )

-> Delivered

. ENDIF.

Read only

adityaIngale
Active Participant
3,193

Hi jeniljeff,

You can use group by while looping Internal table, set required conditions and append values into Internal table.

https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-us/abaploop_at_itab_group_by.htm

Refer this link to know more about it.Regards,Aditya
Read only

adityaaufar
Participant
3,193

1. Copy your initial itab data to another itab (call it unique_by_regno)

2. sort and delete adjecent duplicate the unique_by_regno itab by REGNO field

3. Loop the unique_by_regno itab with assigning field_symbol

4. Within loop check each unique line of REGNO to the initial itab data whether the specified REGNO has line_item R or D or both), Should look something like this.

    loop at unique_regno ASSIGNING FIELD-SYMBOL(<line_regno>).
        if line_exists( initial_data[ regno = <line_regno>-regno line_item = 'R' ] ) AND
           line_exists( initial_data[ regno = <line_regno>-regno line_item = 'D' ] ).
           <line_regno>-line_item = 'NOT COMPLETED'.

        elseif line_exists( initial_data[ regno = <line_regno>-regno line_item = 'R' ] ).
         <line_regno>-line_item = 'RECEIVED'.

        elseif line_exists( initial_data[ regno = <line_regno>-regno line_item = 'D' ] ).
         <line_regno>-line_item = 'DELIVERED'.

        endif.
    ENDLOOP.

Good Luck, hopefully my answer helps!

Read only

3,193

Just read now that you also proposed to remove duplicates...

Read only

thkolz
Contributor
3,193

The solutions above might work for tables with a few entries, but performance-wise they're not very good.

From my point of view you should first remove duplicates:

SORT t_itab BY REGNO LINE_ITEM.
* Remove duplicates
DELETE ADJACENT DUPLICATES FROM t_itab.

LOOP AT t_itab ASSIGNING FIELD-SYMBOL(<fs_itab>).
  AT NEW regno.
*   For each new REGNO create entry in result table
    APPEND INITIAL LINE TO t_result ASSIGNING FIELD-SYMBOL(<fs_result>).
    <fs_result>-regno = <fs_itab>-regno.
  ENDAT.

  CASE <fs_itab>-line_item.
    WHEN 'D'.
      <fs_result>-line_item = 'DELIVERED'.
    WHEN 'R'.
      IF <fs_result>-line_item = 'DELIVERED'.
*       Had 'D' before => then it's not completed
        <fs_result>-line_item = 'NOT COMPLETED'.
      ELSE.
        <fs_result>-line_item = 'RECEIVED'.
      ENDIF.
  ENDCASE.

ENDLOOP.