2022 Oct 09 11:26 AM
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 .
2022 Oct 09 11:49 AM
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.
2022 Oct 09 12:47 PM
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,Aditya2022 Oct 09 3:22 PM
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!
2022 Oct 09 9:09 PM
Just read now that you also proposed to remove duplicates...
2022 Oct 09 8:13 PM
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.