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

Reg. Read statement

Former Member
0 Likes
717

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

9 REPLIES 9
Read only

Former Member
0 Likes
686

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

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
686

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

Read only

0 Likes
686

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

Read only

0 Likes
686

Ok, so then you original code should work. What exactly is the problem?

REgards,

Rich Heilman

Read only

0 Likes
686

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

Read only

0 Likes
686

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.

Read only

0 Likes
686

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.

Read only

0 Likes
686

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.

Read only

0 Likes
686

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