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

GL balance calculation

Former Member
0 Likes
443

Hi all,

I got all credit and debit values in 1 internal table based on customer and GL, now i need to do S - H (Subtract).

I have tried At End but its not working effectively.

Anyone can suggest a better idea.

PSUEDO CODE.

LOOP AT WT_CTEMP INTO WA_CTEMP.

IF WA_CTEMP-SHKZG = 'H'. " H indicates Negative

WA_CFIN-BUKRS = WA_CTEMP-BUKRS.

WA_CFIN-HKONT = WA_CTEMP-HKONT.

WA_CFIN-LIFNR = WA_CTEMP-KUNNR.

WA_CFIN-VBUND = WA_CTEMP-VBUND.

WA_CFIN-DMBTR = WA_CTEMP-DMBTR.

WA_CFIN-WRBTR = WA_CTEMP-WRBTR.

WA_CFIN-WAERS = WA_CTEMP-WAERS.

WA_CFIN-SHKZG = WA_CTEMP-SHKZG.

COLLECT WA_CFIN INTO WT_CFIN.

ELSEIF WA_CTEMP-SHKZG = 'S'. " S indicates Positive

WA_CFIN-BUKRS = WA_CTEMP-BUKRS.

WA_CFIN-HKONT = WA_CTEMP-HKONT.

WA_CFIN-LIFNR = WA_CTEMP-KUNNR.

WA_CFIN-VBUND = WA_CTEMP-VBUND.

WA_CFIN-DMBTR = WA_CTEMP-DMBTR.

WA_CFIN-WRBTR = WA_CTEMP-WRBTR.

WA_CFIN-SHKZG = WA_CTEMP-SHKZG.

COLLECT WA_CFIN INTO WT_CFIN.

endif.

clear : WA_CTEMP, WA_CFIN.

ENDLOOP.

thanks.

Hi all,

I got all credit and debit values in 1 internal table based on customer and GL, now i need to do S - H (Subtract).

I have tried At End but its not working effectively.

Anyone can suggest a better idea.

PSUEDO CODE.

LOOP AT WT_CTEMP INTO WA_CTEMP.

IF WA_CTEMP-SHKZG = 'H'. " H indicates Negative

WA_CFIN-BUKRS = WA_CTEMP-BUKRS.

WA_CFIN-HKONT = WA_CTEMP-HKONT.

WA_CFIN-LIFNR = WA_CTEMP-KUNNR.

WA_CFIN-VBUND = WA_CTEMP-VBUND.

WA_CFIN-DMBTR = WA_CTEMP-DMBTR.

WA_CFIN-WRBTR = WA_CTEMP-WRBTR.

WA_CFIN-WAERS = WA_CTEMP-WAERS.

WA_CFIN-SHKZG = WA_CTEMP-SHKZG.

COLLECT WA_CFIN INTO WT_CFIN.

ELSEIF WA_CTEMP-SHKZG = 'S'. " S indicates Positive

WA_CFIN-BUKRS = WA_CTEMP-BUKRS.

WA_CFIN-HKONT = WA_CTEMP-HKONT.

WA_CFIN-LIFNR = WA_CTEMP-KUNNR.

WA_CFIN-VBUND = WA_CTEMP-VBUND.

WA_CFIN-DMBTR = WA_CTEMP-DMBTR.

WA_CFIN-WRBTR = WA_CTEMP-WRBTR.

WA_CFIN-SHKZG = WA_CTEMP-SHKZG.

COLLECT WA_CFIN INTO WT_CFIN.

endif.

clear : WA_CTEMP, WA_CFIN.

ENDLOOP.

thanks.

1 REPLY 1
Read only

Former Member
0 Likes
409

Please make sure that you understand 'Collect' well, it will collate(merge) records only if ALL non-numeric fields are same. Use f1 to understand it in detail.

As per your code, it will collate only if KUNNR, VBUND, WAERS and SHKZG are also same in records along with BUKRS and HKONT. So, make sure that you want to merge at what level.

Also, generally debit and credit values are stored in positive numbers only, so do note if you need to use a minus sign to get exact difference.

The code will depend on the level you want to collate. Something like below will work.

LOOP AT WT_CTEMP INTO WA_CTEMP.

IF WA_CTEMP-SHKZG = 'H'. " H indicates Negative

WA_CFIN-BUKRS = WA_CTEMP-BUKRS.

WA_CFIN-HKONT = WA_CTEMP-HKONT.

WA_CFIN-LIFNR = WA_CTEMP-KUNNR.

WA_CFIN-VBUND = WA_CTEMP-VBUND.

WA_CFIN-DMBTR = - WA_CTEMP-DMBTR. "use negative sign

WA_CFIN-WRBTR = - WA_CTEMP-WRBTR. "use negative sign

WA_CFIN-WAERS = WA_CTEMP-WAERS.

*WA_CFIN-SHKZG = WA_CTEMP-SHKZG. "comment this

COLLECT WA_CFIN INTO WT_CFIN.

ELSEIF WA_CTEMP-SHKZG = 'S'. " S indicates Positive

WA_CFIN-BUKRS = WA_CTEMP-BUKRS.

WA_CFIN-HKONT = WA_CTEMP-HKONT.

WA_CFIN-LIFNR = WA_CTEMP-KUNNR.

WA_CFIN-VBUND = WA_CTEMP-VBUND.

WA_CFIN-DMBTR = WA_CTEMP-DMBTR.

WA_CFIN-WRBTR = WA_CTEMP-WRBTR.

*WA_CFIN-SHKZG = WA_CTEMP-SHKZG. "comment this

COLLECT WA_CFIN INTO WT_CFIN.

endif.

clear : WA_CTEMP, WA_CFIN.

ENDLOOP.

Before using this code make sure that currency (WAERS) is same for every record, otherwise better to make it same by doing conversions prior to collect.

BR,

Diwakar