Application Development 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: 

FM for create billing schedule like VA42

Former Member
0 Kudos

Hi,

I need to update the billing plan and billing schedule for a contract.

I already have used SD_SALES_DOCUMENT_READ, (OK)

SD_SALES_BILLINGPLAN_READ (OK)

SD_SALES_BILLINGPLAN_CHANGE (OK)

what next? the ENDAT and TNDAT are updated, but I need the new records on FPLT.

What FM is the correct one to calculate the new dates and amounts for FPLT?

The button on VA42, is I think Create Dates (My SAP is in Spanish, that's why i say i think)

This is also done after changing the ENDAT and pressing Enter.

Thanks

4 REPLIES 4

madhu_vadlamani
Active Contributor
0 Kudos

Hi Rene,

Try to use SD_SALES_BILLINGPLAN_READ.

Regards,

Madhu.

former_member182040
Active Contributor
0 Kudos

After create contract order number


*GET LIST]
i_bapi_view-header = 'X'.
    i_bapi_view-item = 'X'.
    i_bapi_view-partner = 'X'.
    i_bapi_view-contract = 'X'.
    i_bapi_view-sdcond = 'X'.
    i_bapi_view-sdcond_add = 'X'.
    i_bapi_view-billplan = 'X'.
    i_bapi_view-configure = 'X'.
    sales_documents-vbeln = v_order.
    APPEND sales_documents.

    CALL FUNCTION 'BAPISDORDER_GETDETAILEDLIST'
      EXPORTING
        i_bapi_view            = i_bapi_view
      TABLES
        sales_documents        = sales_documents
        order_headers_out      = order_headers_out
        order_items_out        = order_items_out
        order_contracts_out    = order_contracts_out
        order_billingplans_out = order_billingplans_out
        order_billingdates_out = order_billingdates_out
        order_partners_out     = order_partners_out
        order_conditions_out   = order_conditions_out.


    LOOP AT order_billingplans_out WHERE itm_number = '000000'.
      hfplnr = order_billingplans_out-bill_plan.
    ENDLOOP.


CALL FUNCTION 'BILLING_SCHEDULE_READ'
      EXPORTING
        fplnr = hfplnr
      TABLES
        zfpla = hfpla
        zfplt = hfplt.
    MOVE hfpla TO hfpla2.
*READ TABLE zfpla2 INDEX 1.
    hfpla2-lodat = p_stat.
    hfpla2-tndat = p_end.
    hfpla2-rfpln = ''.
    hfpla2-lodar = ''.
    hfpla2-tndar = ''.
    hfpla2-fpart = p_bplan.
    hfpla2-perio = p_bplan.
    hfpla2-horiz = p_hori.
*** Very important to set field updkz = 'U' ***
    hfpla2-updkz = 'U'. "--> UPDATE!!
    APPEND hfpla2.
    CLEAR pos.
    CALL FUNCTION 'BILLING_SCHEDULE_SAVE'
      TABLES
        fpla_new = hfpla2
        fpla_old = hfpla
        fplt_new = hfplt " --> NEW
        fplt_old = hfplt.

    CALL FUNCTION 'SD_SALES_DOCUMENT_SAVE'
      EXPORTING
        i_no_messages = ' '.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.

Continue....

former_member182040
Active Contributor
0 Kudos

* UPDATE Billing Plan Item  level
 MOVE v_order TO doc .
      CALL FUNCTION 'SD_SALES_DOCUMENT_READ'
        EXPORTING
          document_number = doc.

      MOVE zbill-itm_number TO pos.

      CALL FUNCTION 'SD_SALES_BILLINGPLAN_READ'
        EXPORTING
          i_vbeln                = doc
          i_posnr                = pos
        IMPORTING
          e_fpla                 = e_fpla
        TABLES
          e_fplt                 = e_fplt
        EXCEPTIONS
          no_billingplan_allowed = 1
          no_billingplan_found   = 2
          OTHERS                 = 3.

      IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.

* Read the billing plan
      CALL FUNCTION 'BILLING_SCHEDULE_READ'
      EXPORTING
      fplnr = e_fpla-fplnr
* I_VFKDAT =
* I_BFKDAT =
      TABLES
      zfpla = zfpla
      zfplt = zfplt.

* Upddate the ZFPLT2 table with the new values
*MOVE zfplt TO zfplt2.
      MOVE zfpla TO zfpla2.

*READ TABLE zfpla2 INDEX 1.
      zfpla2-lodat = zbill-datesfrom.
      zfpla2-tndat = zbill-datesto.
      zfpla2-rfpln = ''.
      zfpla2-lodar = ''.
      zfpla2-tndar = ''.
      zfpla2-fpart = p_bplan.
      zfpla2-horiz = p_hori.
*** Very important to set field updkz = 'U' ***
      zfpla2-updkz = 'U'. "--> UPDATE!!

      APPEND zfpla2.
    ENDLOOP.
    CLEAR pos.
    CALL FUNCTION 'BILLING_SCHEDULE_SAVE'
      TABLES
        fpla_new = zfpla2
        fpla_old = zfpla
        fplt_new = zfplt " --> NEW
        fplt_old = zfplt.

    CALL FUNCTION 'SD_SALES_DOCUMENT_SAVE'
      EXPORTING
        i_no_messages = ' '.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.

Former Member
0 Kudos

Hi, thanks to all,

The table I need to update is fplt, fplt is already updated with the FM you mention.

I cant (is not a good idea ) update fplt this way, because I wold need to calculate the new billing dates. I want a way to simulate the option on the header billing plan that calculate the next billing dates according to fpla-endat and tndat and fpla-horiz.

The solution:

Use the actual FM to update TNDAT and ENDAT on FPLA, after that, execute VA42 with a batch input code that enter the document header, then goes to billing plan and calculate dates.

regards.