‎2005 Aug 17 4:32 PM
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
‎2005 Aug 17 4:43 PM
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
‎2005 Aug 17 4:43 PM
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
‎2005 Aug 17 4:46 PM
How can I use it here ? Because I am dealing with variables like zzcredit, zzdebit zapplied credits for each adjustment type separately.
Santhosh
‎2005 Aug 17 5:01 PM
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
‎2005 Aug 17 5:07 PM
‎2005 Aug 17 5:43 PM
Thanks Rich, your suggesstion helped me.
Full points to you.
Santhosh
‎2005 Aug 17 4:50 PM
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
‎2005 Aug 17 5:03 PM
I tried that.. it changes the value of zappliedcreditsxx when it runs the second time for the same adjustment type.
‎2005 Aug 17 5:14 PM
You are updating zappliedcredits1 for both blart 'DZ' and 'ZA'. Is that what you want to do?
Rob
‎2005 Aug 17 4:58 PM
'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