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

closing bal calculation

former_member841898
Participant
0 Likes
864

hi frnds,

i cant make out a certain logic , the problem is like this.

e.g. i have a g/l account no. say 13005(bsis-hkont).

now total amount of this g/l account no. on 01.08.2005(bsis-budat) is 900 , on 02.08.2005 is 1000 , on 03.08.2005 is 500 - and so on.......

now i have to show closing bal on 01.08.2005 is 900, <b>on 02.08.2005 is 1900</b> (i.e. 900 + 1000) , <b>on 03.08.2005 is 1400</b> (i.e. 1900 - 500) ,

now my sel-screen cosists of g/l account no(hkont) and posting date (budat).

now note: 01.08.2005 is the first posting date of this g/l account no.

everything is ok fine when i m giving the date range from i.e. 01.08.2005 to 03.08.2005 -


the closing balance is coming 100% correct i.e.

on 01.08.2005 is 900 , on 02.08.2005 is 1900 , on 03.08.2005 is 1400.

now my date range will be from 02.08.2005 to 03.08.2005 ,the closing balance on

02.08.2005 is coming 1000 and not 1900 i.e ( amt of 01.08.2005, 900 + amount of

02.08.2005 ,1000).

i have to show closing bal on 02.08.2005 as 1900 ( i.e. in sel-screen date wiil be

02.08.2005 to 03.08.2005 but the amount of 01.08.2005 will also be calculated

according to the requirement)

i m waiting for ur valuable suggestions .

pls help me out.

regards

pankaj

5 REPLIES 5
Read only

former_member189629
Active Contributor
0 Likes
813

Pankaj,

This is quiet a common issue. What I'd suggest will be to maintain the op & CL bals ni a Z table based on the posting dates and doc nos ad the key fields. I mean, whenever you are calculating the value for closing balance, insert it into a Z table so that you will not face such problems in future. Such reports are supposed to be run for the date range of the 1st and last days of a month, but since u wanna daily run, i suggest u archive these values in a Z table and retrieve from it.

If u can't do that for whatever reason, check programatically if the date-low is the 1st day of the month. If not, calculate the balance from date-low minus 1 (from 01.08.2005 in ur case)

Hope this helps... reward if it does

Regards,

Karthik

Read only

0 Likes
813

hi sir

can u give me some more details on 2 nd method.

i m sending u my code.

&----


*& Report ZGL *

*& *

&----


*& *

*& *

&----


REPORT zgl NO STANDARD PAGE HEADING..

TABLES: bsis.

DATA: BEGIN OF ibsis OCCURS 0,

hkont LIKE bsis-hkont,

budat LIKE bsis-budat,

shkzg LIKE bsis-shkzg,

dmbtr TYPE bsis-dmbtr,

waers LIKE bsis-waers,

END OF ibsis.

TYPES: BEGIN OF st_tab,

*budat LIKE bsis-budat,

hkont LIKE bsis-hkont,

budat LIKE bsis-budat,

shkzg LIKE bsis-shkzg,

dmbtr LIKE bsis-dmbtr,

waers LIKE bsis-waers,

END OF st_tab.

DATA: itab TYPE STANDARD TABLE OF st_tab INITIAL SIZE 0,

wa TYPE st_tab,

wa_d TYPE st_tab. " dummy work area

*DATA: itab1 TYPE STANDARD TABLE OF st_tab INITIAL SIZE 0 WITH HEADER LINE.

DATA: sum_comp TYPE p DECIMALS 2,

sum1 TYPE p DECIMALS 2,

sum2 TYPE p DECIMALS 2.

SELECT-OPTIONS: s_gl FOR bsis-hkont,

s_budat for bsis-budat.

start-of-selection.

SELECT hkont budat shkzg dmbtr waers FROM bsis INTO corresponding fields of TABLE ibsis WHERE hkont IN s_gl and budat in s_budat.

IF sy-subrc <> 0.

WRITE:/ 'no records'.

ENDIF.

DELETE: ibsis WHERE hkont <> 13001 AND hkont <> 13002 AND hkont <> 13003 AND hkont <> 13005.

LOOP AT ibsis.

MOVE-CORRESPONDING ibsis TO wa.

IF ibsis-shkzg = 'S'. "debit

wa-dmbtr = ibsis-dmbtr * 1.

ELSEIF ibsis-shkzg = 'H'. "credit

wa-dmbtr = ibsis-dmbtr * - 1.

ENDIF.

APPEND wa TO itab.

CLEAR wa.

ENDLOOP.

SORT itab BY hkont ASCENDING budat ASCENDING .

LOOP AT itab INTO wa.

wa_d = wa.

AT NEW hkont.

WRITE:/50 'ACCOUNT NO#' , wa_d-hkont color 3.

skip 2.

endat.

AT NEW budat.

WRITE:/ wa_d-budat .

ENDAT.

AT END OF budat.

SUM .

sum_comp = wa-dmbtr.

sum1 = sum1 + sum_comp.

WRITE: 38 sum1 COLOR 4.

SKIP.

ENDAT.

at end of hkont.

sum1 = 0 .

uline.

endat.

ENDLOOP.

*==================================================

Read only

0 Likes
813

B4 changing ur code, I sugest u ask ur functional team at what date intervals they r gonna run this rept. If it is monthly (from 1st day - last day of a month), it need not be changed. Moreover, suggest ur sr. abap heads abt maintaining the values in a Z table... Meanwhile, i will c ur code

Read only

0 Likes
813

sir,

it will run on any date like from 03.08.2005 to 09.08.2005,

but the closing bal of 03.08.2005 will also contain the bal

of date previous than 03.08.2005 .

z table could not be maintained for some reasons.

pls run my code .

regards

pankaj

Read only

former_member841898
Participant
0 Likes
813

This message was moderated.