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

loop

Former Member
0 Likes
712

hi to all,

plz help me in this issue,

where there r no values in bseg_data1 it is giving no output for the bseg_data2(bseg_data2 is having values). so how can i write so that it

should work for both bseg_data1 and bseg_data2.

LOOP AT BSEG_DATA1.

READ TABLE BSEG_DATA2 WITH KEY XREF1 = BSEG_DATA1-XREF1.

IF SY-SUBRC EQ 0.

IT_FINAL-DIFF = BSEG_DATA2-DMBTR - BSEG_DATA1-DMBTR.

  • IT_FINAL-CHANGE = IT_FINAL-CHANGE + IT_FINAL-DIFF.

ENDIF.

MOVE : BSEG_DATA1-XREF1 TO IT_FINAL-XREF1.

MOVE : BSEG_DATA1-DMBTR TO IT_FINAL-DMBTR.

MOVE : BSEG_DATA2-DMBTR TO IT_FINAL-DMBTR1.

APPEND IT_FINAL.

CLEAR IT_FINAL.

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
682

Hi kiran,

1. how can i write so that it

should work for both bseg_data1 and bseg_data2.

Ofcourse, in that case,

u will have to use

2 DIFFERENT Loops.

a) one for BSEG_DATA1

b) another for BSEG_DATA2

regards,

amit m.

7 REPLIES 7
Read only

Former Member
0 Likes
683

Hi kiran,

1. how can i write so that it

should work for both bseg_data1 and bseg_data2.

Ofcourse, in that case,

u will have to use

2 DIFFERENT Loops.

a) one for BSEG_DATA1

b) another for BSEG_DATA2

regards,

amit m.

Read only

Former Member
0 Likes
682

if not bseg_data1[] is initial.

LOOP AT BSEG_DATA1.

READ TABLE BSEG_DATA2 WITH KEY XREF1 = BSEG_DATA1-XREF1.

IF SY-SUBRC EQ 0.

IT_FINAL-DIFF = BSEG_DATA2-DMBTR - BSEG_DATA1-DMBTR.

  • IT_FINAL-CHANGE = IT_FINAL-CHANGE + IT_FINAL-DIFF.

ENDIF.

MOVE : BSEG_DATA1-XREF1 TO IT_FINAL-XREF1.

MOVE : BSEG_DATA1-DMBTR TO IT_FINAL-DMBTR.

MOVE : BSEG_DATA2-DMBTR TO IT_FINAL-DMBTR1.

APPEND IT_FINAL.

CLEAR IT_FINAL.

ENDLOOP.

else.

LOOP AT BSEG_DATA2.

READ TABLE BSEG_DATA1 WITH KEY XREF1 = BSEG_DATA2-XREF1.

IF SY-SUBRC EQ 0.

MOVE : BSEG_DATA1-XREF1 TO IT_FINAL-XREF1.

MOVE : BSEG_DATA1-DMBTR TO IT_FINAL-DMBTR.

IT_FINAL-DIFF = BSEG_DATA2-DMBTR - BSEG_DATA1-DMBTR.

  • IT_FINAL-CHANGE = IT_FINAL-CHANGE + IT_FINAL-DIFF.

ENDIF.

MOVE : BSEG_DATA2-DMBTR TO IT_FINAL-DMBTR1.

APPEND IT_FINAL.

CLEAR IT_FINAL.

ENDLOOP.

endif.

Regards,

ravi

Read only

Former Member
0 Likes
682

Hi

if not bseg_data2[] is initial.

LOOP AT BSEG_DATA2.

READ TABLE BSEG_DATA1 WITH KEY XREF1 = BSEG_DATA2-XREF1.

IF SY-SUBRC EQ 0.

IT_FINAL-DIFF = BSEG_DATA2-DMBTR - BSEG_DATA1-DMBTR.

  • IT_FINAL-CHANGE = IT_FINAL-CHANGE + IT_FINAL-DIFF.

ENDIF.

MOVE : BSEG_DATA2-XREF1 TO IT_FINAL-XREF1.

MOVE : BSEG_DATA1-DMBTR TO IT_FINAL-DMBTR.

MOVE : BSEG_DATA2-DMBTR TO IT_FINAL-DMBTR1.

APPEND IT_FINAL.

CLEAR IT_FINAL.

ENDLOOP.

else.

your code...after checking if (bseg_data1 has any records

endif.

Regards,

Raj

Message was edited by: Rajasekhar Dinavahi

Read only

Former Member
0 Likes
682

Hello,

Yes, as Amit said you should use 2 loops.

Regs,

Venkat Ramanan N

Read only

Former Member
0 Likes
682

in that case u have to put two diff.logics.

if BSEG_DATA1[] is not initial.

LOOP AT BSEG_DATA1.

READ TABLE BSEG_DATA2 WITH KEY XREF1 = BSEG_DATA1-XREF1.

IF SY-SUBRC EQ 0.

IT_FINAL-DIFF = BSEG_DATA2-DMBTR - BSEG_DATA1-DMBTR.

  • IT_FINAL-CHANGE = IT_FINAL-CHANGE + IT_FINAL-DIFF.

ENDIF.

MOVE : BSEG_DATA1-XREF1 TO IT_FINAL-XREF1.

MOVE : BSEG_DATA1-DMBTR TO IT_FINAL-DMBTR.

MOVE : BSEG_DATA2-DMBTR TO IT_FINAL-DMBTR1.

APPEND IT_FINAL.

CLEAR IT_FINAL.

ENDLOOP.

else.

loop at BSEG2.

update/append it_final.

endloop.

endif.

Regards

Prabhu

Read only

Former Member
0 Likes
682

HI KIRAN,

LOOP AT BSEG_DATA2.

READ TABLE BSEG_DATA1 WITH KEY XREF1 = BSEG_DATA2-XREF1.

IF SY-SUBRC <> 0.

  • DO YOUR PROCESSING HERE

  • THIS WILL GIVE U THE MISSED RECORDS THAT ARE THERE IN * BSEG_DATA2 ONLY

ENDIF.

ENDLOOP.

-ANU

Read only

Former Member
0 Likes
682

I think the solution can be as below ....

LOOP AT BSEG_DATA1.

READ TABLE BSEG_DATA2 WITH KEY XREF1 = BSEG_DATA1-XREF1.

IF SY-SUBRC EQ 0.

IT_FINAL-DIFF = BSEG_DATA2-DMBTR - BSEG_DATA1-DMBTR.

<b>delete bseg_data2 index sy-tabix.</b>

<i>The delete statement would make it possible that you dont include the same record twice.</i>

ENDIF.

MOVE : BSEG_DATA1-XREF1 TO IT_FINAL-XREF1.

MOVE : BSEG_DATA1-DMBTR TO IT_FINAL-DMBTR.

MOVE : BSEG_DATA2-DMBTR TO IT_FINAL-DMBTR1.

APPEND IT_FINAL.

CLEAR IT_FINAL.

ENDLOOP.

Loop at bseg_data2.

*move the data as per your requirement.

append it_final.

clear it_final.

endloop.