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

help in the abap code

Former Member
0 Likes
938

hi folks,

In this piece of code I have to add the credits and debits for each adjustment type like 'DZ',

'ZA','ZW' separately and store it (like in zappliedcredits1, zappliedcredits2, zappliedcredits3) as I am looping the data,

<b>The question I am facing is, as I loop through patcloseditemsitab there is a possiblity that it loops through the same adjustment type more than once for a given set of data and at this situation it updates the values in 'zzdebitxx' and 'zzcreditxx' resulting in the wrong value in the overallbalance. To avoid that I used 'clear zzdebitxx' and 'clear zzcreditxx' after the loop but then the value in 'zappliedcredits1' got updated with the wrong value.</b>

I hope I have explained my issue and everytime I check each of these adjustment types it has to get updated properly in the given scenario how can i do this?

It would be really helpful.

The code goes like this...

Insert lines of patopenitemsitab into table

patcloseditemsitab.

loop at patcloseditemsitab into wa_payadjustment.

case wa_payadjustment-blart.

when 'DZ'.

if wa_payadjustment-wrbtr = ' '.

continue.

elseif wa_payadjustment-shkzg = 'H'.

add wa_payadjustment-wrbtr to zzcredit1.

elseif wa_payadjustment-shkzg = 'S'.

add wa_payadjustment-wrbtr to zzdebit1.

endif.

ctext2 = 'CUSTOMER PAYMENT'.

zappliedcredits1 = zzdebit1 - zzcredit1.

when 'ZA'.

if wa_payadjustment-wrbtr = ' '.

continue.

elseif wa_payadjustment-shkzg = 'H'.

add wa_payadjustment-wrbtr to zpayment.

add wa_payadjustment-wrbtr to zzcredit1.

elseif wa_payadjustment-shkzg = 'S'.

add wa_payadjustment-wrbtr to zpayment.

add wa_payadjustment-wrbtr to zzdebit1.

endif.

ctext2 = 'CHECK BY PHONE'.

zappliedcredits1 = zzdebit1 - zzcredit1.

.

.

.

.

.

when 'ZW'.

if wa_payadjustment-wrbtr = ' '.

continue.

elseif wa_payadjustment-shkzg = 'H'.

add wa_payadjustment-wrbtr to zzcredit2.

elseif wa_payadjustment-shkzg = 'S'.

add wa_payadjustment-wrbtr to zzdebit2.

endif.

ctext2 = 'PAYMENT'.

zappliedcredits3 = zzdebit3 - zzcredit3.

when others.

continue.

endcase.

if sy-subrc = 0.

ztotalappliedcredits = zappliedcredits1 + zappliedcredits2 ........ zappliedcredits3.

endloop.

Thanks

Santhosh

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
912

I was thinking that you where updating a internal table at first.

Can you make it that the internal table patcloseditemsitab only has one record per type. When building that table, use COLLECT instead of APPEND. This will collect the numeric values into one record per the table key, which is all the fields to the left of the numeric fields.

Regards,

Rich Heilman

Message was edited by: Rich Heilman

Message was edited by: Rich Heilman

Message was edited by: Rich Heilman

9 REPLIES 9
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
913

I was thinking that you where updating a internal table at first.

Can you make it that the internal table patcloseditemsitab only has one record per type. When building that table, use COLLECT instead of APPEND. This will collect the numeric values into one record per the table key, which is all the fields to the left of the numeric fields.

Regards,

Rich Heilman

Message was edited by: Rich Heilman

Message was edited by: Rich Heilman

Message was edited by: Rich Heilman

Read only

0 Likes
912

How can I use it here ? Because I am dealing with variables like zzcredit, zzdebit zapplied credits for each adjustment type separately.

Santhosh

Read only

0 Likes
912

I cannot do that because 'patcloseditemsitab' has data related to non-adjustment types too which i have to display in the form, it is a part of the whole big process that is going to display the data in the form in the final section. so I cannot disturb that.

Is there a way using variables I can get the data at each instance and store them like in zappliedcreditsxx for each adjustment type and taking into consideration as to how many times it gets executed for record -- add them to a final variable that gives the exact summation of all the adjustment types for that particular order.

Santhosh

Read only

0 Likes
912

Yes, build another itab using the COLLECT keyword.

Regards,

Rich Heilman

Read only

0 Likes
912

Thanks Rich, your suggesstion helped me.

Full points to you.

Santhosh

Read only

Former Member
0 Likes
912

You say that you are clearing zzdebitxx and zzcreditxx after the loop, but I don't see it in your code. In any event, you should clear them within the loop.

Rob

Read only

0 Likes
912

I tried that.. it changes the value of zappliedcreditsxx when it runs the second time for the same adjustment type.

Read only

0 Likes
912

You are updating zappliedcredits1 for both blart 'DZ' and 'ZA'. Is that what you want to do?

Rob

Read only

Former Member
0 Likes
912

'there is a possiblity that it loops through the same adjustment type more than once for a given set of data'

I'm not clear why this happen. Does it means there is duplicate entries in your internal table?

Can you explain this point more details?

thanks a lot