Hi!
I have this code.
DATA loop1 TYPE sy-tabix.
DATA enc1 TYPE char1.
DATA loop2 TYPE sy-tabix.
DATA enc2 TYPE char1.
data auxloop2 type sy-tabix.
DATA loop3 TYPE sy-tabix.
data auxloop3 type sy-tabix.
DATA enc3 TYPE char1.
DATA ltable1 TYPE sy-tabix.
DEFINE next_line.
if &1-consunum = &2-consunum.
&4 = 'X'.
add 1 to &3.
elseif &4 = 'X' and ( &1-consunum <> &2-consunum ) .
exit.
elseif &4 = '' .
add 1 to &3.
endif.
END-OF-DEFINITION.
DEFINE next_line2.
if &1-consunum = &2-consunum and &1-consupos = &2-consupos.
&4 = 'X'.
add 1 to &3.
elseif &4 = 'X'
and ( &1-consunum <> &2-consunum or &1-consupos <> &2-consupos ) .
exit.
elseif &4 = '' .
add 1 to &3.
endif.
END-OF-DEFINITION.
SORT lt_cosu_cab_aux BY consunum.
SORT lt_cosu_pos_aux BY consunum.
SORT lt_cosu_dme_aux BY consunum.
DESCRIBE TABLE lt_cosu_cab_aux LINES ltable1.
loop2 = 1.
loop3 = 1.
DO ltable1 TIMES.
loop1 = sy-tabix.
READ TABLE lt_cosu_cab_aux ASSIGNING <fs_cosu_cab> INDEX loop1.
enc2 = ''.
auxloop2 = loop2.
DO.
READ TABLE lt_cosu_pos_aux ASSIGNING <fs_cosu_pos> INDEX loop2.
IF sy-subrc EQ 0.
next_line <fs_cosu_cab> <fs_cosu_pos> loop2 enc2.
IF enc2 EQ 'X'.
enc3 = ''.
auxloop3 = loop3.
DO.
READ TABLE lt_cosu_dme_aux ASSIGNING <fs_cosu_dme> INDEX loop3.
IF sy-subrc EQ 0.
next_line2 <fs_cosu_pos> <fs_cosu_dme> loop3 enc3.
IF enc3 EQ 'X'.
READ TABLE gt_cosu_cab TRANSPORTING NO FIELDS
WITH TABLE KEY mandt = sy-mandt
consunum = <fs_cosu_cab>-consunum
.
IF sy-subrc NE 0.
INSERT <fs_cosu_cab> INTO TABLE gt_cosu_cab.
APPEND <fs_cosu_cab> TO lt_cosu_cab.
READ TABLE gt_cosu_pos TRANSPORTING NO FIELDS
WITH TABLE KEY mandt = sy-mandt
consunum = <fs_cosu_pos>-consunum
consupos = <fs_cosu_pos>-consupos
.
IF sy-subrc NE 0.
INSERT <fs_cosu_pos> INTO TABLE gt_cosu_pos.
APPEND <fs_cosu_pos> TO lt_cosu_pos.
INSERT <fs_cosu_dme> INTO TABLE gt_cosu_dme.
APPEND <fs_cosu_dme> TO lt_cosu_dme.
ENDIF.
ENDIF.
ENDIF.
ELSE.
EXIT.
ENDIF.
ENDDO.
if enc3 = ''.
loop3 = auxloop3.
endif.
ENDIF. ""
ELSE.
EXIT.
ENDIF.
ENDDO.
if enc2 = ''.
loop2 = auxloop2.
endif.
ENDDO. "DO ltable1
The thing with this code is that, for example, when the cosunum in <fs_cosu_cab> does not have coincidences in <fs_cosu_pos> and <fs_cosu_dme> the code continue to increment the cosunum in <fs_cosu_pos> and <fs_cosu_dme> but not in <fs_cosu_cab>. So it does not matter if there is more coincidences in <fs_cosu_cab> it is not reading it.
i do not know if i am being enough clear.
Thanks.