ABAP routine for calculating AR buckets using master data look up

 In Account receivables, there is a due date on which the outstanding amount has to be paid by the customer.

If the due date is passed and the customer has still not paid, the amount becomes overdue and bucket calculation starts. The AR bucket is the number of days calculated as current date – net due date.

Based on this difference, following categories can be defined – greater than 99 days, 75-99 days, 25-75 days and 1-25 days.

These categories may change in future, hence instead of directly using these range values in the code, we maintain them in master data table of info object like below-

Sample Info object nameSample AttributesSample Values
ZAR_BUCKET 75-99
 Days From  (ZAR_DF)75
 Days to (ZAR_DT)99

 

Here ZAR_BUCKET is the info object included in the target which should be populated via routine transformation using net due date and current date fields from the source. The attributes ZAR_DF (Days From) is the lower limit of the bucket (75) and ZAR_DT (Days to) is the upper limit of the bucket (99). The value of the info object ZAR_BUCKET is the bucket value (75-99).

Source fieldsTarget fieldsMapping
Net Due Date(ZAR_NDD)ZAR_BUCKETRoutine Transformation
Current Date (ZAR_CURRD)  

 

The routine transformation will look like below-

  DATA: AR_BUCKET TYPE /BIC/OIZAR_BUCKET,
         current_date TYPE sy-datum,
         net_due_date TYPE sy-datum,
         no_of_days type i.
 
 current_date = sy-datum.

no_of_days = current_date - SOURCE_FIELDS-/BIC/ZAR_NDD.
  if no_of_days > 0.
     SELECT SINGLE /BIC/ZAR_BUCKET from /BIC/MZAR_BUCKET INTO AR_BUCKET
     WHERE /BIC/ZAR_DF <= no_of_days
     AND   /BIC/ZAR_DT >= no_of_days
     AND    OBJVERS = 'A'.
 
  if sy-subrc = 0.
      RESULT = AR_BUCKET.
  endif.
 
  elseif no_of_days <= 0.
        RESULT = 'NOT OVERDUE'.
  endif.

This code assigns bucket to each record based on the net due date and current date difference. For example, if the difference is 82 days, then since, 82 is more than the lower limit i.e 75 and less than the upper limit which is 99, 75-99 bucket is assigned.

If the net due date is still not passed and  lies in future with respect to the current date, or if the net due date and the current date are same, then ‘NOT OVERDUE’ bucket is assigned.

 

Instead of looking up the master data we can use the range 75-99 directly in the code.

Like if no_of_days <75 and if no_of_days>99

But the drawback of this approach is that if the range limit changes in future, we have to change the routine. Whereas in the lookup approach, we just have to change the master data with new range values and activate it.

Comments

Popular posts from this blog

Sample ABAP program for Updating notepad file data to Internal table and Sending it to Application server

OPEN SQL EXAMPLES IN ABAP – PART 2

Domains and Data Elements