SAP aging ABAP

I have to calculate the aging for open items in Accounts Receivable.
The aging has to be done based on the baseline date from BSID.
Now it is to be done like this:
Current.
Aging 1: 1-30 days
Aging 2: 31-60
Aging 3: 61-90
Aging 4: over 90 days

Question 1 : What is the code snippet or How to do it?

Here's a short example :
REPORT zforum25 .
*data
DATA : BEGIN OF aging OCCURS 4,
no(1),
from(2),
to(5),
END OF aging.

DATA: itab TYPE bsid OCCURS 0 WITH HEADER LINE.
DATA:BEGIN OF atab OCCURS 0,
no LIKE aging-no,
bldat LIKE bsid-bldat,
bukrs LIKE bsid-bukrs,
gjahr LIKE bsid-gjahr,
belnr LIKE bsid-belnr,
END OF atab.

DATA difday TYPE sy-dbcnt.
*sel-screen
PARAMETERS currdate LIKE sy-datum DEFAULT sy-datum.
PARAMETERS bukrs LIKE itab-bukrs.
SELECT-OPTIONS kunnr FOR itab-kunnr.

START-OF-SELECTION.
*abbreviation !
APPEND '10130' TO aging.
APPEND '23160' TO aging.
APPEND '36190' TO aging.
APPEND '49199999' TO aging.
*select data
SELECT * FROM bsid INTO TABLE itab
WHERE bukrs = bukrs
AND kunnr IN kunnr.
*migration
LOOP AT itab.
CLEAR atab.
MOVE-CORRESPONDING itab TO atab.

*assigning age of invoices
difday = currdate - itab-bldat."bldat = invoice date
LOOP AT aging WHERE from LE difday
AND to GE difday.
ENDLOOP.

IF sy-subrc = 0.
MOVE aging-no TO atab-no.
ELSE.
*error -> check customizing of aging / bldat of invoice
MESSAGE s001(00) WITH 'cannot assign' atab-bukrs atab-belnr atab-gjahr.
ENDIF.
COLLECT atab.
ENDLOOP.
*print
SORT atab.
LOOP AT atab.
AT NEW no.
WRITE: / atab-no.
ENDAT.
WRITE: / atab-bldat, atab-bukrs, atab-belnr, atab-gjahr.
ENDLOOP.



Question 2 :what if I have to consider open items from this and consider it for each customer.
So basically I am going to get the customer information based on kunnr from BSID and KNA1.
Then I have to consider only the open items and not the closed ones and sum up the amount de for each of the open items for each customer.
Now this flat file has to be generated quarterly based on the 'as-of' date for that particular quarter, so I think I can make a selection for the period for which the data has to be collected out.

Answer -a report , which is similar to your query is RFDOPR00 (Customer Evaluation with OI Sorted List)

- your 2nd query:
--you need select-option: bsid-budat or bsid-monat
to select data quarterly from bsid

Question 3. I have been unable to find the program that you said in our SAP system. Another thing...I have to add up the Amount due in Loc currency (DMBTR) from BSID for each customer.
How do I do that? When I am caculating aging, I am using baseline date field (ZFBDT).
Is that wrong? I am using that instead of the BLDAT.
Also, I have to only consider open items. Now I am not sure how I am getting the open items.

Answer :
1) Report RFDOPR00 is in rel. 4.6 an 4.7 !
2) with collect-command in an own internal table:

E.g.: data : begin of sumtab occurs 0,
kunnr type bsid-kunnr,
dmbtr type bsid-dmbtr,

loop at itab. " loop your founded post.-documents
Move-corresponding itab to sumtab.
Collect sumtab.
endloop.


3) bldat normally is the default-value for zfbdt - but zfbdt is editable with TA FB02 in opposite to bldat
-> bldat = invoice date (usual)

4) Tables in FI:
BSID = open items
BSAD = regulated items
BSEG = all items
-> so you've to select only table bsid !

Question 4:
Now can you tell me where and how to look for the program that you have mentioned? RFDOPR00.
ALso if u can give me an example of how to use it becoz I am new to abap and don't know many things..so please help.
The other thing is I understand yur answrs to my last question.....here is what I need to know.
Now when I am doing aging, I get it done for each customer for all open items. when I run my program as of now, it gives me a numbers of values with different dates for that customer and all the amounts assocated with it. Now this report that I am writing will be run only quarterly and for all the customers in the quarter and not for individual customers.
So I have to get summed up values for all customers for a quarter which should include information about the amunt due for each customer in that quarter.
I will try and implement what you have suggested to sum up the amount due but please help with the quater thing. I am right now getting it for only one customer through the way you suggested.

Answer :
1)you can display and execute RFDOPR00 with SE38 or SA38

2)try this code (summation of Kunnr/aging-no.)


REPORT zforum25 .
*data
DATA : BEGIN OF aging OCCURS 4,
no(1),
from(2),
to(5),
END OF aging.

DATA: itab TYPE bsid OCCURS 0 WITH HEADER LINE.
DATA:BEGIN OF atab OCCURS 0,
kunnr LIKE bsid-kunnr,
no LIKE aging-no,
dmbtr LIKE bsid-dmbtr,
END OF atab.

DATA difday TYPE sy-dbcnt.
*sel-screen
PARAMETERS currdate LIKE sy-datum DEFAULT sy-datum.
PARAMETERS bukrs LIKE itab-bukrs.
SELECT-OPTIONS: kunnr FOR itab-kunnr,
budat FOR itab-budat DEFAULT '20050401' TO '20050630'.

START-OF-SELECTION.
*abbreviation !
APPEND '10130' TO aging.
APPEND '23160' TO aging.
APPEND '36190' TO aging.
APPEND '49199999' TO aging.
*select data
SELECT * FROM bsid INTO TABLE itab
WHERE bukrs = bukrs
AND kunnr IN kunnr
AND budat IN budat.
*migration
LOOP AT itab.
CLEAR atab.
*correct sign
IF itab-shkzg = 'H'.
itab-dmbtr = itab-dmbtr * -1.
ENDIF.
MOVE-CORRESPONDING itab TO atab.

*assigning age of invoices
difday = currdate - itab-bldat."bldat = invoice date
LOOP AT aging WHERE from LE difday
AND to GE difday.
ENDLOOP.

IF sy-subrc = 0.
MOVE aging-no TO atab-no.
ELSE.
*error -> check customizing of aging / bldat of invoice
MESSAGE s001(00) WITH 'cannot assign' .
ENDIF.



COLLECT atab.
ENDLOOP.
*print
SORT atab.
LOOP AT atab.
WRITE: / atab-kunnr, atab-no, atab-dmbtr.
ENDLOOP.


question 5
I looked at the program RFDOPR00 but I only need the name1, stras, ort01, regio, pstlz, kunnr fields from the KNA1 table which I am able to extract. The problem that I am facing is, the aging is like this:

first 1-30 days current.
next 30 days -Aging 1
31-60-Aging 2
61-90 Aging 3
over 90 days -Aging 4.

So I have 5 buckets. And it works in the reverse order ie. May backwards to whenever for all customers and for all open items for each customer. Ok...now for aging, I basically have to show the 'DMBTR' ie. the amount due in local currency for which ever bucket the customer falls in for all open items taken into consideration at the same time. So this is what I am not able to do ie. sum the amount up for each individual customer for all open items for that customer. I don't have to just say that it falls in this group or in this date. I have to write out the total amount that is due for all open items. Also if the program is run only on the period-ending date and on my screen I just have to take in that date and use it in my queries, can you give an example?

Answer 6 :
if i've undertsood correctly,
you'll sum up per customer :

so the only thing you've to do is to change table
atab (or create a new table btab)


DATA:BEGIN OF atab OCCURS 0,
kunnr LIKE bsid-kunnr,
*no LIKE aging-no,-> delete that line
dmbtr LIKE bsid-dmbtr,
END OF atab.


so you get the sum per customer


Question7 : how did you get the aging *abbreviations? I have to add another period before all the aging buckets which is the current period of 30 days. Also if you can tell me how to take in only on budat and use that to perform the mmy queries for all dates before that, it would be very helpful. What I mean is if on my screen I take in only one date say 06/22/2005 which is the period ending date. but the query should get me data for all dates before this date i.e. 06/21/2005.

Answer :
1) abbreviation: APPEND '10130' TO aging.
-> long:
move '1' to aging-no.
move '01' to aging-from.
move '30' to aging-to.
append aging.

2)
>but the query should get me data for all dates before >this date i.e. 06/21/2005


select ...
where budat le currdate.

Question 8
The problem I am facing is of calculating the amount due for each customer individually for the open items. Right now, it gets summed up one after the other for all the entries. What I cannot do is do the sum for all entries of each customer number. suppose there are 5 entries for kunnr 123 and 4 entries for kunnr 345. The first five entries get summed up one after the other but then the sixth one gets added to the same number which I am getting after the 5th addition which should be the last one for the first kunnr. But I cannot figure out how to write my code to do that.

Answer :-> pls use abap command collect:


DATA:BEGIN OF sumtab OCCURS 0,
kunnr LIKE bsid-kunnr,
dmbtr LIKE bsid-dmbtr,
END OF sumtab.

sort itab by kunnr.
loop at itab.
if itab-shkzg = 'H'.
itab-dmbtr = itab-dmbtr * -1.
endif.
move-corresponding itab to sumtab.
collect sumtab.
endloop.

Related Posts by Categories



0 comments: