Showing posts with label Outsorting. Show all posts
Showing posts with label Outsorting. Show all posts

Thursday, April 3, 2025

Billing: Create Custom Outsort Check (Example 2)

Example 2:
FUNCTION ISU_VAL_ZTHOLD1 .
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(X_TE327) LIKE  TE327 STRUCTURE  TE327
*"  CHANGING
*"     REFERENCE(XY_OBJ) TYPE  ISU2A_BILLING_DATA
*"     REFERENCE(XY_OUTCNSO) LIKE  ERCHO-OUTCNSO
*"  EXCEPTIONS
*"      GENERAL_FAULT
*"----------------------------------------------------------------------
*  Compare ( Current Bill Amount + Uninvoiced Amount + Account Balance )
*    against Highest and Minimum Amounts
*"----------------------------------------------------------------------
  DATAls_erchz      LIKE erchz,
        lv_nettobtr   LIKE erchz-nettobtr,
        lv_uninvoiced LIKE erchz-nettobtr,
        lv_acc_bal    LIKE erchz-nettobtr,
        lv_outsorted  TYPE c,
        lv_deviation  LIKE ercho-deviation.

  LOOP AT xy_obj-bill-ierchz INTO ls_erchz
          WHERE buchrel 'X'.
    IF ls_erchz-abslkz IS INITIAL.
      lv_nettobtr lv_nettobtr + ls_erchz-nettobtr.
    ENDIF.
  ENDLOOP.

  PERFORM get_uninvoiced_amount USING xy_obj-st-wfkkvkp
                             CHANGING lv_uninvoiced.

  PERFORM get_account_balance USING xy_obj-st-wfkkvkp
                           CHANGING lv_acc_bal.

  lv_nettobtr lv_nettobtr + lv_acc_bal + lv_uninvoiced.

  CALL FUNCTION 'ISU_E25M_BETRW_WAERS_CORRECT'
    EXPORTING
      x_amount          lv_nettobtr
      x_currency        ls_erchz-twaers
    IMPORTING
      y_amount          lv_nettobtr
    EXCEPTIONS
      too_many_decimals 1
      OTHERS            2.
  IF sy-subrc NE 0.
    mac_msg_putx co_msg_error '274' 'AJ' x_te327-validation space
                           space space general_fault.
    IF 2MESSAGE e274(ajWITH spaceENDIF.
  ENDIF.
  break ogoh.
  IF lv_nettobtr > x_te327-value1.
    lv_deviation lv_nettobtr.
    lv_outsorted 'X'.
    mac_msg_putx co_msg_warning '003' 'ZMSG_BI' x_te327-validation xy_obj-bill-erch-belnr
                                            lv_nettobtr x_te327-value1 space.
    IF 2.
      MESSAGE e003(zmsg_biWITH '&' '&' '&' '&'.
*     &1: Bill Doc &2's account balance &3 exceeds threshold $&4
    ENDIF.
  ENDIF.

  IF NOT lv_outsorted IS INITIAL.
    CALL FUNCTION 'ISU_OUTSORT_IERCHO_WRITE'
      EXPORTING
        x_validation x_te327-validation
        x_deviation  lv_deviation
      CHANGING
        xy_iercho    xy_obj-bill-iercho
        xy_outcnso   xy_outcnso.
  ENDIF.
ENDFUNCTION.

Sunday, March 2, 2025

Billing: Create Custom Outsort Check (Example 1)

Example 1:
FUNCTION isu_val_zaccbal1 .
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(X_TE327) LIKE  TE327 STRUCTURE  TE327
*"  CHANGING
*"     REFERENCE(XY_OBJ) TYPE  ISU2A_BILLING_DATA
*"     REFERENCE(XY_OUTCNSO) LIKE  ERCHO-OUTCNSO
*"  EXCEPTIONS
*"      GENERAL_FAULT
*"----------------------------------------------------------------------
  DATAls_erchz      LIKE erchz,
        lv_nettobtr   LIKE erchz-nettobtr,
        lv_uninvoiced LIKE erchz-nettobtr,
        lv_acc_bal    LIKE erchz-nettobtr,
        lv_outsorted  TYPE c,
        lv_deviation  LIKE ercho-deviation.

  LOOP AT xy_obj-bill-ierchz INTO ls_erchz
          WHERE buchrel 'X'.
    IF ls_erchz-abslkz IS INITIAL.
      lv_nettobtr lv_nettobtr + ls_erchz-nettobtr.
    ENDIF.
  ENDLOOP.

  PERFORM get_uninvoiced_amount USING xy_obj-st-wfkkvkp
                             CHANGING lv_uninvoiced.

  PERFORM get_account_balance USING xy_obj-st-wfkkvkp
                           CHANGING lv_acc_bal.

  lv_nettobtr lv_nettobtr + lv_acc_bal + lv_uninvoiced.

  CALL FUNCTION 'ISU_E25M_BETRW_WAERS_CORRECT'
    EXPORTING
      x_amount          lv_nettobtr
      x_currency        ls_erchz-twaers
    IMPORTING
      y_amount          lv_nettobtr
    EXCEPTIONS
      too_many_decimals 1
      OTHERS            2.
  IF sy-subrc NE 0.
    mac_msg_putx co_msg_error '274' 'AJ' x_te327-validation space
                           space space general_fault.
    IF 2MESSAGE e274(ajWITH spaceENDIF.
  ENDIF.
  break ogoh.
  IF lv_nettobtr < x_te327-value1 OR
     lv_nettobtr > x_te327-value2.
    lv_deviation lv_nettobtr.
    lv_outsorted 'X'.
    mac_msg_putx co_msg_warning '002' 'ZMSG_BI' x_te327-validation xy_obj-bill-erch-belnr
                                            xy_obj-st-wfkkvkp-vkont lv_outsorted space.
    IF 2.
      MESSAGE e002(zmsg_biWITH '&' '&' '&' '&'.
*   &1: Bill Doc &2 Contract Account &3 is outsorted due to acc bal &4
    ENDIF.
  ENDIF.

  IF NOT lv_outsorted IS INITIAL.
    CALL FUNCTION 'ISU_OUTSORT_IERCHO_WRITE'
      EXPORTING
        x_validation x_te327-validation
        x_deviation  lv_deviation
      CHANGING
        xy_iercho    xy_obj-bill-iercho
        xy_outcnso   xy_outcnso.
  ENDIF.
ENDFUNCTION.

*&---------------------------------------------------------------------*
*&      Form  GET_UNINVOICED_AMOUNT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->IS_FKKVKP     Contract Account
*      <--cv_uninv_amt mount="" nbsp="" ninvoiced="" span="">
*----------------------------------------------------------------------*
FORM get_uninvoiced_amount  USING    is_fkkvkp  TYPE  fkkvkp
                            CHANGING cv_uninv  TYPE nettobtr.
  DATA:
    ls_eitr    TYPE eitr,
    lt_eitr    TYPE STANDARD TABLE OF eitr,
    ls_erch    TYPE erch,
    lt_erch    TYPE STANDARD TABLE OF erch,
    ls_dberchz TYPE dberchz,
    lt_dberchz TYPE STANDARD TABLE OF dberchz.

  SELECT INTO TABLE lt_eitr FROM eitr
    WHERE vkont       EQ is_fkkvkp-vkont
      AND simulation  EQ space
      AND tobreleasd  EQ space.
  IF sy-subrc IS INITIAL.
    IF lt_eitr IS NOT INITIAL.
      SELECT INTO TABLE lt_erch FROM erch
        FOR ALL ENTRIES IN lt_eitr
        WHERE belnr     EQ lt_eitr-belnr.
      IF lt_erch IS NOT INITIAL.
        SELECT INTO CORRESPONDING FIELDS OF TABLE lt_dberchz
            FROM dberchz1 AS JOIN dberchz3 AS e
              ON i~belnr    EQ e~belnr
             AND i~belzeile EQ e~belzeile
          FOR ALL ENTRIES IN lt_erch
          WHERE i~belnr   EQ lt_erch-belnr
            AND i~buchrel EQ 'X'.
      ENDIF.
    ENDIF.
  ENDIF.
  LOOP AT lt_dberchz INTO ls_dberchz.
    cv_uninv cv_uninv + ls_dberchz-nettobtr.
  ENDLOOP.
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  GET_ACCOUNT_BALANCE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->IS_FKKVKP     Contract Account
*      <--cv_acc_bal alance="" ccount="" nbsp="" span="">
*----------------------------------------------------------------------*
FORM get_account_balance  USING    is_fkkvkp   TYPE fkkvkp
                          CHANGING cv_acc_bal  TYPE nettobtr.
  DATA:
    ls_bal TYPE bapiaccbalances,
    lt_bal TYPE STANDARD TABLE OF bapiaccbalances.

  CALL FUNCTION 'BAPI_ACCOUNT_GETBALANCES'
    EXPORTING
      contractaccount  is_fkkvkp-vkont
      partner          is_fkkvkp-gpart
    TABLES
      account_balances lt_bal.
  LOOP AT lt_bal INTO ls_bal.
    CASE ls_bal-text.
      WHEN 'Open'.
        cv_acc_bal cv_acc_bal + ls_bal-withd_val.
      WHEN 'Credit'.
        cv_acc_bal cv_acc_bal ls_bal-withd_val.
    ENDCASE.
  ENDLOOP.
ENDFORM.

    Wednesday, October 2, 2019

    Billing: Create Custom Outsort Check (Part 2)


    1. Create custom function module starts with ISU_VAL_<Biling Validation Name>  with the following parameters:
      • Importing
        • X_TE327                LIKE TE327
      • Changing 
        • XY_OBJ                 TYPE ISU2A_BILLING_DATA
        • XY_OUTCNSO LIKE ERCHO-OUTCNSO
      • Exceptions
        • GENERAL_FAULT
    2. Validation parameters are set in X_TE327
    3. Call FM 'ISU_OUTSORT_IERCHO_WRITE' if needed to outsort the billing document
    4. Please refer to the following on how to configure outsorting check groups for billing:

    Sunday, September 1, 2019

    Billing: Create Custom Outsort Check (Part 1)


    1. Go to SPRO -> SAP Utilities -> Tools -> System Modifications -> User-Defined Enhancements for Billing -> Define Check List for Billing
    2. Enter new billing validation name, and text for the parameters

    Wednesday, October 5, 2016

    Billing: Define Checks per Outsorting Check Group for Billing


    1. Go to SPRO -> SAP Utilities -> Contract Billing -> Billing Execution -> Outsorting for Billing -> Define Checks per Outsorting Check Group for Billing
    2. Enter configuration details:
    3. Explanation:
      Field Name
      Usage
      Outsort. Chk grp
      Name of the Outsorting Check Group
      Billing Trans.
      01           Periodic Billing (01)
      02           Interim Billing (02)
      03           Final Billing for Move-Out (03)
      04           Period-End Billing (04)
      05           Service Territory Transfer (05)
      06           Manual Credit Memo/Backbilling (06)
      07           Contract Change (07)
      08           Customer change (08)
      Consecutive no.
      Consecutive number of checking per billing transaction
      Mass Simulation
                      No Restrictions
      1              Do Not Carry Out Check in Mass Simulation
      2              Only Carry Out Check in Mass Simulation
      Bill. Validation
      Refer to Value Table TE007
      Parameters 1 to 4
      Parameters for outsorting validation, these parameters behave differently per validation, typically used as range of amount to be validated
      Parameter 5
      Parameter for outsorting validation, this parameter accepts characters input
      Text
      Description of the outsorting check group defined.
    4. This outsort check group can then be assigned to contract.

    Friday, September 2, 2016

    Billing: Define Outsorting Check Groups for Billing


    1. Go to SPRO -> SAP Utilities -> Contract Billing -> Billing Execution -> Outsorting for Billing -> Define Outsorting Check Groups for Billing
    2. Enter Outsorting Check Group Name and its Text (Description)

    Friday, August 12, 2016

    Invoicing: Define Manual Bill Outsorting for Invoicing

    1. SPRO -> SAP Utilities -> Invoicing -> Invoice Processing -> Outsorting for Invoicing -> Define Manual Bill Outsorting for Invoicing
    2. Enter the reason for manual bill outsorting for invoicing, description, number of manual outsorting, outsorting for invoice or bill printing.
    3. Explanation:
      Field Name
      Usage
      Man. OS inv
      Reason for Manual Outsorting Invoice
      Text
      Description of the manual outsorting invoice
      No. man.OS
      Number of manual outsort, this will be the default number of outsortings upon entering the reason for manual outsorting invoice. The number of outsortings will be reduced whenever the contract account gets invoiced.
      OutSrt. Invoic.
      Indicates that this is an outsorting for Invoicing
      OutSrt. Print.
      Indicates that this is an outsorting for Bill Printing