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: 

Billing schedule Dates using a BAPI/FM for a sales order line

Former Member
0 Kudos

Hello,

I am trying to update a sales order line with an Item category which inturn updates the Billing Plan.

I am able to update the sales order with required details and the default billing plan.

Now I want to change the Billing schedule i.e the Billing Plan dates Invoice end date and the percantage etc whcih I am trying to do using

SD_ORDER_BILLING_SCHEDULE AND BILLING_SCHEDULE_MAINTAIN AND THEN BILLING_SCHEDULE_SAVE.

This for some reason will not update the Billing schedule.

It triggers the user exists etc but even though I pass all the required details in the Old and new FPLA and FPLT tables...it is not helping.

When I tried using BILLING_SCHEDULE_DIALOG it opens the screen with the Billing plan in edit mode.

Is there any other way to do the updates.I tried changing in the User exist etc. I also checked the program sdfpla02.

Many thanks,

Krishna.

Edited by: Krishna on Mar 21, 2011 8:30 PM

1 ACCEPTED SOLUTION

former_member182040
Active Contributor
0 Kudos

See the following example


* Read the billing plan
    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'.

 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'.
*-

3 REPLIES 3

former_member182040
Active Contributor
0 Kudos

See the following example


* Read the billing plan
    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'.

 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'.
*-

0 Kudos

Many thanks for prompt response, I did all but missed the UPDKZ ....was just wondering...over looked while debugging...

0 Kudos

Hi Krupa ,

how to fill zfplt " --> NEW with the new dates ??,

is there any FM to do that ??