‎2006 Nov 08 6:12 PM
Hi,
I need to append the records from GT_OUT to GT_FINAL based on condition. see the coding below. But it is giving repeated data.
if GP_EKGRP eq 'X'.
LOOP AT GT_OUT where Fname+0(5) = 'EKGRP'.
*read table gt_out with key Fname+0(5) = 'EKGRP'.
If sy-subrc eq 0.
MOVE-CORRESPONDING: GT_out TO GT_final.
append gt_final.
endif.
endloop.
endif.
loop at gt_out where Fname+0(5) = 'NETWR'.
if GP_DIFWR eq 'X'.
*read table gt_out with key Fname+0(5) = 'NETWR'.
if sy-subrc eq 0.
MOVE-CORRESPONDING: GT_out TO GT_final.
append gt_final.
endif.
endif.
ENDLOOP.
Could you plz help me.
Regards
Reddy
‎2006 Nov 08 6:16 PM
Hi,
Check how you are populating the internal table GT_OUT..To make sure the records is not duplicate in GT_OUT..
Thanks,
Naren
Message was edited by: Narendran Muthukumaran
‎2006 Nov 08 6:16 PM
If you only want one instance of the record based on the FNAME, then you need to READ the GT_FINAL and check sy-subrc <> 0.
if GP_EKGRP eq 'X'.
LOOP AT GT_OUT where Fname+0(5) = 'EKGRP'.
<b>read table gt_final with key Fname+0(5) = 'EKGRP'.
</b> If sy-subrc <b><></b> 0.
MOVE-CORRESPONDING: GT_out TO GT_final.
append gt_final.
endif.
endloop.
endif.loop at gt_out where Fname+0(5) = 'NETWR'.
if GP_DIFWR eq 'X'.
read table <b>gt_final</b> with key Fname+0(5) = 'NETWR'.
if sy-subrc <b><></b> 0.
MOVE-CORRESPONDING: GT_out TO GT_final.
append gt_final.
endif.
endif.
ENDLOOP.Regards,
Rich Heilman
‎2006 Nov 08 7:41 PM
Hi Rich,
I need to append all the records where Fname = EKGRP. Say for a particular Ebeln has Fname EKGRP 5 times. I need to append all the five records.
Regards
Reddy
‎2006 Nov 08 7:43 PM
‎2006 Nov 08 7:45 PM
Make sure to clear the line before moving to it. This will insure that it is clean.
if GP_EKGRP eq 'X'.
LOOP AT GT_OUT where Fname+0(5) = 'EKGRP'.
*read table gt_out with key Fname+0(5) = 'EKGRP'.
If sy-subrc eq 0.
<b>clear gt_final.</b>
MOVE-CORRESPONDING: GT_out TO GT_final.
append gt_final.
endif.
endloop.
endif.Regards,
Rich Heilman
‎2006 Nov 08 8:27 PM
Rich - yes it is working but I need to put such type 13 conditions. It means i have to loop the same table for 13 times. what about performance. Pls find the pease of code for 3 conditions.. it is working but..
if GP_EKGRP eq 'X'.
LOOP AT GT_OUT where Fname+0(5) = 'EKGRP'.
*read table gt_out with key Fname+0(5) = 'EKGRP'.
If sy-subrc eq 0.
clear gt_final.
MOVE-CORRESPONDING: GT_out TO GT_final.
append gt_final.
endif.
endloop.
endif.
if GP_DIFWR eq 'X'.
loop at gt_out where Fname+0(5) = 'NETWR'.
*read table gt_out with key Fname+0(5) = 'NETWR'.
if sy-subrc eq 0.
clear gt_final.
MOVE-CORRESPONDING: GT_out TO GT_final.
append gt_final.
endif.
ENDLOOP.
endif.
if GP_ittxt eq 'X'.
loop at gt_out where tabname+0(9) = 'EINKBELEG'.
*read table gt_out with key Fname+0(5) = 'NETWR'.
clear gt_final.
MOVE-CORRESPONDING: GT_out TO GT_final.
append gt_final.
ENDLOOP.
endif.
‎2006 Nov 08 8:43 PM
you dont have to write the loop multiple times.
Loop it once without any condition.
check condition 1,
perform ur task,
else check condition 2,
perform ur task,
and so on
endloop.
hope this helps.
‎2006 Nov 08 8:48 PM
if GP_EKGRP eq 'X'.
LOOP AT GT_OUT.
if gt_out-Fname+0(5) = 'EKGRP'
MOVE-CORRESPONDING: GT_out TO GT_final.
append gt_final.
elseif gt_out-Fname+0(5) = 'NETWR'
MOVE-CORRESPONDING: GT_out TO GT_final.
append gt_final.
and so on u can add.
endif.
endloop.
thanks,
shree.
‎2006 Nov 08 8:54 PM
Not exactly sure of your requirment, but you don't have to loop 13 times, but just once.
LOOP AT GT_OUT.
if GP_EKGRP eq 'X'
and gt_out-Fname+0(5) = 'EKGRP'..
clear gt_final.
MOVE-CORRESPONDING: GT_out TO GT_final.
append gt_final.
continue.
endif.
if GP_DIFWR eq 'X'
and gt_out-Fname+0(5) = 'NETWR'..
clear gt_final.
MOVE-CORRESPONDING: GT_out TO GT_final.
append gt_final.
continue.
endif.
endloop.
Regards,
Rich Heilman