Skip to Content
Technical Articles
Author's profile photo Sandeep Kumar Mundlapati

AUC Settlment through BDC

Overview:

In this article you’ll learn about settlement process through BDC.

I hope this article will be helpful for those searching for BAPI for settlement. I didn’t find any BAPI being used for settlement but through SDN search I realized that this requirement can be achieved through BDC and there was no concise information about this. This article will help you a lot.

I recorded the AIAB (to create distribution rules) and AIBU(to create settlement) but the recording didn’t give us expected results until we did some changes in the recording process.

I’ll try to share very clear inputs on how to achieve the settlement in this article through BDC.

We had a requirement to settle the assets (AUC) and the inputs we get into the tables through CAPTILIZATION Fiori app input and using ODATA the custom tables were filled. I’ll not discuss anything related to Fiori app design or ODATA related but only the backend part(BDC) . When the user clicks on APPROVE button on app, the request goes to ODATA and ODATA calls BDC program in the backend. Here we are going to deal only about the backend process in detail.

ZCAP_DIST_RULES is one of the custom tables that holds all the assets details that we need to pass to create distribution rules for any AUC.

Here, Capitalization request number is just to identify a record that helps the user to track the AUC and assets details when the user processes from the front end (Fiori app).The below shown example table will be updated through ODATA via Fiori app.

 

Table

Table

And the table that you’ll see just below is updated whenever assets are created through a separate program that uses ‘BAPI_FIXEDASSET_CREATE1’ ; and the same assets’ information used to create the distribution rules are saved in this table.

Table%202

Table 2

Process explanation:

When we start recording directly, it won’t solve the purpose because if there are existing distribution rules already created then we get errors while settling AUCs.

So, to avoid the error, we must make sure that we pass only the document numbers that are used for settling. Instead of directly going into the t-code, while recording click on further selection criteria (as shown below), here we can pass the required document number and related information.

AIAB – T code.

 

We can see the information like in the below screenshot. Observe that as per the below screenshot there might be some existing rules already created ones(status in GREEN) and rules aren’t created(STATUS in RED). While settling we’ll get the error while settling at AIBU. To make sure that we get rid of this error, we use DETACH option so that all existing ones (GREEN) to RED status and these documents can be used for processing.

 

When we click on DETACH all records will turn to RED STATUS as shown. Now we can enter the distribution rules. Click on ENTER.

We can pass our assets that are used for settling.

In this example, for document 500000062, we have entered asset information as shown in the above, and the status turned to GREEN.

 

Either we can click on settlement or go to AIBU t-code(both are same).

AIBU – Settlement screen

At the bottom of the screen upon clicking on execute button, a successful message with a document number one will be seen (if entered information is fine to process) else we get an error. We can easily figure out the reasons for the error message.

 

BDC recording:

The following screenshots are only for understanding purpose and the data that I passed is different from the above.

AIAU – creating distribution rules for AUC

 

 

 

 

Settlement : AIBU recording.

 

Code:

The Sample code : Implementation

I am not presenting full code here as we can get better and clear information through recording.

As per our business scenario, we have first detached and created distribution rules. I have processed every AUC single time and for every AUC processing passed assets information along with sub number category + amount or percentage.

Finally settled them. Again the process continues for the next AUC processing. All errors will be captured too. Successfully generated settlement document will be stored in the table and if there are any errors while processing even those are updated in the table too.

LOOP AT lt_settle ASSIGNING FIELD-SYMBOL(<lf_settle>).
    IF <lf_settle> IS ASSIGNED.

* Making sure that distribution rules are not saved
* If saved then AIAB processing will skip and goes to
* AS02 and AIBU.
      IF <lf_settle>-flag NE 'AIAB'.

        PERFORM bdc_dynpro      USING 'SAPMA15B' '0110'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'P_DISVAR'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=SEKS'.

        IF <lf_settle> IS ASSIGNED.

          PERFORM bdc_field       USING 'AICOM-BUKRS'
                                        lv_header-company_code.
          PERFORM bdc_field       USING 'AICOM-ANLN1'
                                        <lf_settle>-auc.
        ENDIF.

        PERFORM bdc_field       USING 'AICOM-ANLN2'
                                      '0'.
        PERFORM bdc_field       USING 'P_DISVAR'
                                      ''.
        PERFORM bdc_dynpro      USING 'SAPLSSEL' '1104'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=CRET'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      '%%DYN014-LOW'.

        IF <lf_settle> IS ASSIGNED.

          PERFORM bdc_field       USING '%%DYN003-LOW'
                                       <lf_settle>-fical_year.

          PERFORM bdc_field       USING '%%DYN006-LOW'
                                        <lf_settle>-document_no.

          PERFORM bdc_field       USING '%%DYN008-LOW'
                                        <lf_settle>-reference.

          PERFORM bdc_field       USING '%%DYN012-LOW'
                                        <lf_settle>-po_number.

          PERFORM bdc_field       USING '%%DYN013-LOW'
                                        <lf_settle>-po_item_number.

          PERFORM bdc_field       USING '%%DYN014-LOW'
                                         <lf_settle>-sequence_no.
        ENDIF.


        PERFORM bdc_dynpro      USING 'SAPMA15B' '0110'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'P_DISVAR'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=AUSF'.

        IF <lf_settle> IS ASSIGNED.

          PERFORM bdc_field       USING 'AICOM-BUKRS'
                                        lv_header-company_code.

          PERFORM bdc_field       USING 'AICOM-ANLN1'
                                         <lf_settle>-auc.
        ENDIF.

        PERFORM bdc_field       USING 'AICOM-ANLN2'
                                      '0'.
        PERFORM bdc_field       USING 'P_DISVAR'
                                      ''.
        PERFORM bdc_dynpro      USING 'SAPMSSY0' '0120'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      '07/03'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=&ALL'.
        PERFORM bdc_dynpro      USING 'SAPMSSY0' '0120'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      '07/03'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=BURG'.
        PERFORM bdc_dynpro      USING 'SAPLKOBS' '0130'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'COBRB-PROZS(01)'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '/00'.

        LOOP AT lt_dist ASSIGNING FIELD-SYMBOL(<lf_dist>)
          WHERE capitalization_request =  <lf_settle>-capitalization_request
            AND    auc                        = <lf_settle>-auc  "new
            AND    document_no                = <lf_settle>-document_no
            AND    sequence_no                = <lf_settle>-sequence_no
            AND    po_number                  = <lf_settle>-po_number  "new
            AND    po_item_number             = <lf_settle>-po_item_number  "new
            AND    fical_year                 = <lf_settle>-fical_year.

          IF <lf_dist> IS ASSIGNED.

            READ TABLE lt_asset ASSIGNING FIELD-SYMBOL(<lf_asset>) WITH KEY
                  capitalization_request = <lf_dist>-capitalization_request
                  fa_asset               = <lf_dist>-settlement_receiver_asset.

            IF <lf_asset> IS ASSIGNED.

              lv_count = lv_count + 1.

              CONCATENATE <lf_asset>-main_asset '-0' INTO DATA(lv_auc).
              CONDENSE lv_auc.

* Passing FXA value
              CONCATENATE 'COBRB-KONTY(' lv_count ')' INTO DATA(lv_konty).
              CONDENSE lv_konty.


              PERFORM bdc_field       USING  lv_konty
                                             'FXA'.

* Passing asset number
              CONCATENATE 'DKOBR-EMPGE(' lv_count ')' INTO DATA(lv_dkobr).
              CONDENSE lv_dkobr.
              PERFORM bdc_field       USING lv_dkobr
                                             lv_auc .

              IF  <lf_dist>-amount IS NOT INITIAL.
                lv_amount = <lf_dist>-amount.

                IF lwa_defaults-dcpfm NE 'X'.
                  REPLACE ALL OCCURRENCES OF '.' IN lv_amount WITH ','.
                ENDIF.
* Passing amount value
                CONCATENATE 'COBRB-BETRR(' lv_count ')' INTO DATA(lv_betrr).
                CONDENSE lv_betrr.
                PERFORM bdc_field       USING lv_betrr
                                              lv_amount.

              ENDIF.

              IF <lf_dist>-percentage IS NOT INITIAL.
                lv_per = <lf_dist>-percentage.

                IF lwa_defaults-dcpfm NE 'X'.
* Passing percentage value
                  lv_per = <lf_dist>-percentage.
                  REPLACE ALL OCCURRENCES OF '.' IN lv_per WITH ','.
                ENDIF.

                CONCATENATE 'COBRB-PROZS(' lv_count ')' INTO DATA(lv_prozs).
                CONDENSE lv_prozs.

                PERFORM bdc_field       USING lv_prozs "'COBRB-PROZS
                                              lv_per." percentage .
              ENDIF.

            ENDIF.
          ENDIF.

        ENDLOOP.

        PERFORM bdc_dynpro      USING 'SAPLKOBS' '0130'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'COBRB-KONTY(01)'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=BACK'.
        PERFORM bdc_dynpro      USING 'SAPMSSY0' '0120'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      '07/03'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=BUCH'.
        PERFORM bdc_dynpro      USING 'SAPLSPO1' '0200'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                     '=YES'.

        DATA(v_mode) = lc_a.

        CALL TRANSACTION 'AIAB' USING gt_bdcdata
            MODE v_mode
            UPDATE 'S'
            MESSAGES INTO lt_return.

* Updating flag for particular document number and sequence number
        IF sy-subrc = 0.
          DATA(lv_flag) = 'AIAB'.
        ENDIF.

        IF lt_return IS NOT INITIAL.
          EXIT.
        ENDIF.

        CLEAR : gt_bdcdata.

      ENDIF.


*************************************************************

* If already document is saved for AUC while settling for any asset
* then skip it.

      IF <lf_settle>-document IS INITIAL.

* Calling AIBU
        PERFORM bdc_dynpro      USING 'SAPMA12B' '0100'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'LKO74-TESTLAUF'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=AUSF'.
        PERFORM bdc_field       USING 'ANLA-BUKRS'
                                       lv_header-company_code.
        PERFORM bdc_field       USING 'ANLA-ANLN1'
                                       <lf_settle>-auc.
        PERFORM bdc_field       USING 'ANLA-ANLN2'
                                      '0'.

        IF i_postdate IS NOT INITIAL.
          WRITE i_postdate TO lv_postdate.
        ENDIF.

        IF i_assetvaldate IS NOT INITIAL.
          WRITE i_assetvaldate TO lv_assetdate.
        ENDIF.

        PERFORM bdc_field       USING 'ANEK-BLDAT'
                                       lv_postdate."Document date
        PERFORM bdc_field       USING 'ANEP-BZDAT'
                                       lv_assetdate."Asset value date
        PERFORM bdc_field       USING 'ANEK-BUDAT'
                                       lv_postdate. "Posting date
        PERFORM bdc_field       USING 'ANBZ-MONAT'
                                      '10'.
        PERFORM bdc_field       USING '*KOMK1-BLART'
                                      'AA'. "Document type
        PERFORM bdc_field       USING '*KOMK1-XBLNR'
                                       <lf_settle>-reference.
        PERFORM bdc_field       USING 'LKO74-TESTLAUF'
                                      ''.
        PERFORM bdc_field       USING 'LKO74-LIST'
                                      'X'.

        v_mode = lc_a.

        CALL TRANSACTION 'AIBU' USING gt_bdcdata
            MODE v_mode
            UPDATE 'S'
            MESSAGES INTO lt_return.

* Get Fiscal year information
        CALL FUNCTION 'GET_CURRENT_YEAR'
          EXPORTING
            bukrs = lv_header-company_code
            date  = sy-datum  " Posting date
          IMPORTING
            curry = lv_fiscal.

      ENDIF.

      CLEAR: lwa_mode, gt_bdcdata.
.

**Format Message for lt_return
      LOOP AT lt_return INTO DATA(lwa_return).

        CALL FUNCTION 'FORMAT_MESSAGE'
          EXPORTING
            id        = lwa_return-msgid
            lang      = sy-langu
            no        = lwa_return-msgnr
            v1        = lwa_return-msgv1
            v2        = lwa_return-msgv2
            v3        = lwa_return-msgv3
            v4        = lwa_return-msgv4
          IMPORTING
            msg       = lv_text
          EXCEPTIONS
            not_found = 1
            OTHERS    = 2.

        CLEAR lwa_bapi.
        lwa_bapi-type = lwa_return-msgtyp.
        IF lv_text IS NOT INITIAL.
          CONCATENATE lv_text ' ' lwa_return-fldname INTO lwa_bapi-message .
        ELSE.
          CONCATENATE lwa_return-msgv1 ' ' lwa_return-fldname INTO lwa_bapi-message .
        ENDIF.
        APPEND lwa_bapi TO et_return.

        IF lwa_bapi-type = 'E'.
          lv_msgtp = lwa_bapi-message.
          CONCATENATE lv_msgtp ';  ' lv_msg INTO lv_msg.
          CLEAR lv_msgtp.
        ENDIF.

        IF lwa_return-tcode = 'AIBU' AND lwa_return-msgtyp = 'S'.
          DATA(lv_fisdoc) = lwa_return-msgv1.
        ENDIF.

        CLEAR : lwa_return,lv_text, lwa_bapi.

      ENDLOOP.

* Updating Distribution rules internal table
      LOOP AT lt_dist ASSIGNING FIELD-SYMBOL(<lf_dtl>)
        WHERE  capitalization_request     = <lf_settle>-      capitalization_request
        AND    auc                        = <lf_settle>-auc  "new
        AND    document_no                = <lf_settle>-document_no
        AND    sequence_no                = <lf_settle>-sequence_no
        AND    po_number                  = <lf_settle>-po_number  "new
        AND    po_item_number             = <lf_settle>-po_item_number  "new
        AND    fical_year                 = <lf_settle>-fical_year.

        IF sy-subrc  = 0 .
          <lf_dtl>-message  = lv_msg.

          IF lv_fisdoc IS NOT INITIAL.
            <lf_dtl>-document = lv_fisdoc.
            <lf_dtl>-fs_year  = lv_fiscal.
            <lf_dtl>-flag     = lv_flag.
          ENDIF.
        ENDIF.

      ENDLOOP.

      CLEAR  : lt_return, lv_fisdoc, lv_fiscal, lv_flag, lv_msg.

    ENDIF.
  ENDLOOP.

  MODIFY zcap_dist_rules FROM TABLE lt_dist.

ENDFUNCTION.

 

NOTE: This table zcap_dist_rules that contains document created is used to show on Fiori App.

 

Summary : We have seen that detaching and creating distribution rules will avoid us getting errors while settling AUCs through BDC. It will help us to clear all the manual distribution rules that were created if there are any.

Q and A : Please let me know for any questions or suggestions.

 

Sandeep Kumar Mundlapati

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.