IT干货网

ABAP-SO-billinig plan

leader 2022年03月09日 SAP 149 0

IT虾米网

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

评论关闭
IT干货网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

ABAP-QRFC