cancel
Showing results for 
Search instead for 
Did you mean: 

BADI for billing creation

DeeptiK
Explorer

Hello,

We are using S/4HANA public cloud system. I have requirement to stop billing creation if the complete sales kit is not copied on one billing document. We are currently using the copy control routine (BADI Custom Data Transfer for Billing Documents SD_BIL_DATA_TRANSFER).

But this BADI gets triggered for each item before creation and it does not give me visibility to the other items on the list. So it becomes impossible to check if all kit items are copied on this invoice or not.

I could not find any other billing related BADI where the complete item table can be accessed at once.

Has someone dealt with similar requirement? Or know of a BADI we can use in this case?

Thanks,

Deepti

OwenLiu
Product and Topic Expert
Product and Topic Expert

Thanks for your question.

As suggested in the blog, I have removed tag "SAP S/4HANA Cloud".

https://blogs.sap.com/2021/05/25/choosing-the-correct-tags-for-sap-s-4hana-cloud-in-the-sap-communit...

View Entire Topic
vhardzeyenka
Product and Topic Expert
Product and Topic Expert

Hi,

If this is still relevant, probably i have a Developer Extensibility (3SL system) workaround solution for you.

Not sure about this particular BADI, but solution is definitely working for the similar  case: FIN_ACDOC_ITEM_SUBSTITUTION BADI, that get triggered for every line item, and within a BADI you don't see other line items values. 

So, this workaround is based on the assumption that all BADIs for ALL LINE ITEMS GET TRIGGERED IN SINGLE RUNTIME SESSION. If so, solution is pretty simple.

You need to create a Singleton class with a lifetime limited by one Billing Document creation. 

Imagine, you have 3 line items for Billing Document, so your SD_BIL_DATA_TRANSFER BADI works 3 times (within one runtime session).

For first line (first BADI triggering) you create your Singleton instance and store there current line item values.

For next lines (next BADI triggering) you get existing Singleton instance, add value of current line item and also you can check values from other line items. 

Implementation steps are the following:

1 In ADT create Singleton class, it can looks like:

CLASS zcl_singleton DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.

    CLASS-METHODS get_instance
      RETURNING
        VALUE(ro_instance) TYPE REF TO zcl_singleton .

    METHODS add_lineitem
      IMPORTING
        is_lineitem TYPE <YOUR_LINE_ITEM>.

    METHODS get_lineitems
      RETURNING VALUE(rt_lineitems) TYPE <YOUR_LINE_ITEM_TAB>.

  PROTECTED SECTION.
  PRIVATE SECTION.
    CLASS-DATA mo_instance TYPE REF TO zcl_singleton .
    DATA mt_lineitem TYPE STANDARD TABLE OF <YOUR_LINE_ITEM_TAB>.

ENDCLASS.

CLASS zcl_acdoc_fins_item_subs IMPLEMENTATION.

  METHOD get_instance.
    IF mo_instance IS NOT BOUND.
      mo_instance = NEW zcl_singleton( ).
    ENDIF.
    ro_instance = mo_instance.
  ENDMETHOD.

  METHOD add_lineitem.
    " TODO add new line item
  ENDMETHOD.

  METHOD get_lineitems
    rt_lineitems = mt_lineitem.
  ENDMETHOD.

ENDCLASS.

2 Release this class for Key User Extensibility. You can call this class from you BADI.

  1. Go to class Properties -> API State -> Use System-Internally (Contract 1) -> Add.
  2. Choose:
    • Release State: Released
    • Use in Key User Apps
  3. Add it to Transport Request.

3 Implement your BADI logic. It can looks like: 

* Your BADI Logic ...

* Create Instance of you buffer class - for first line item of Billing Document
* Or get existing one - for other line items
DATA(lo_buffer) = zcl_singleton=>get_instance( ). 

* Add current line item values 
lo_buffer->add_lineitem( <YOUR_LINE_ITEM> ).

* Get all line items for entire document (that has been added to the buffer already)
DATA(lt_line_items) = lo_buffer->get_lineimtes( ).

* Do whatever logic you need with your Billing Document

Hope it helpful.

Best Regards

Vitali