https://answers.sap.com/questions/8218304/billing-schedule-dates-using-a-bapifm-for-a-sales-.html

 

Function group: V60F

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

 

posted on 2021-03-26 16:23  ricoo  阅读(577)  评论(0编辑  收藏  举报