Sunday 6 July 2014

Enhance DataSource in BI report

Let me give you some background who are working in ABAP only and never seen any BI transaction.
In BI/BW report data source is ECC and here its OFI_AP_4 for Financial Accounting: Vendors. In this structure we have standard fields which will be pulled by BI. But if there is some requirement like in BI system some more fields need to be pulled then the Enhance DataSource in BI report comes into picture.

Go to RSA6 tcode and follow the path for which we need to enhance the standard BI report.
Here we are enhancing the Financial Accounting: Vendors.




 Double click on the ExtractStruct.



Do Append Structure for new fields in the BI report.




Don’t forget to remove the check like below:


Go to CMOD and create a project:



Use the Enhancement Assignment (RSAP0001):


We need to implement the component EXIT_SAPLRSAP_001:


CODE:


*&---------------------------------------------------------------------*
*&  Include           ZXRSAU01
*&---------------------------------------------------------------------*

  DATAit_dtfiap_3 TYPE TABLE OF dtfiap_3,
        wa_dtfiap_3 TYPE dtfiap_3,
        lit_dtfiap_3 TYPE TABLE OF dtfiap_3.

  TYPESBEGIN OF t_lfa1,
          lifnr TYPE lifnr,     " Vendor
          name2 TYPE name2_gp,  " Vendor name
          ktokk TYPE ktokk,     " Vendor Group
          werks TYPE werks_d,   " Plant
         END OF t_lfa1.

  TYPESBEGIN OF t_t001w,
           werks TYPE werks_d,
           name1 TYPE name1,
         END OF t_t001w.

  TYPESBEGIN OF t_with_item,
              bukrs TYPE bukrs,
              belnr TYPE belnr_d,
              gjahr TYPE gjahr,
              buzei TYPE buzei,
              witht TYPE witht,
              wt_withcd TYPE wt_withcd,
              wt_qsshh TYPE wt_bs,
              wt_qbshh TYPE wt_wt,
              wt_acco TYPE wt_acno,
              qsatz TYPE WT_QSATZ,
         END OF t_with_item.

  DATAit_lfa1 TYPE STANDARD TABLE OF t_lfa1 INITIAL SIZE 0,
        wa_lfa1 TYPE t_lfa1,
        lit_lfa1 TYPE STANDARD TABLE OF t_lfa1 INITIAL SIZE 0.

  DATAit_t001w TYPE STANDARD TABLE OF t_t001w INITIAL SIZE 0,
        wa_t001w TYPE t_t001w.

  DATAit_with_item TYPE STANDARD TABLE OF t_with_item INITIAL SIZE 0,
        wa_with_item TYPE t_with_item.

  CASE i_datasource.

    WHEN '0FI_AP_4'.

      REFRESH it_dtfiap_3.

      it_dtfiap_3[] c_t_data[].

      lit_dtfiap_3[] it_dtfiap_3[].

      SORT lit_dtfiap_3[] BY lifnr.
      DELETE ADJACENT DUPLICATES FROM lit_dtfiap_3[] COMPARING lifnr.
      SELECT lifnr
             name2
             ktokk
             werks
        FROM lfa1
        INTO TABLE it_lfa1
        FOR ALL ENTRIES IN lit_dtfiap_3
        WHERE lifnr lit_dtfiap_3-lifnr.

      IF sy-subrc 0.
        SORT it_lfa1 BY lifnr.

        SORT lit_lfa1[] BY werks.
        DELETE ADJACENT DUPLICATES FROM lit_lfa1[] COMPARING werks.
        SELECT werks
               name1
          FROM t001w
          INTO TABLE it_t001w
          FOR ALL ENTRIES IN lit_lfa1
          WHERE werks lit_lfa1-werks.

        IF sy-subrc 0.
          SORT it_t001w BY werks.
        ENDIF.
      ENDIF.

      SELECT bukrs
             belnr
             gjahr
             buzei
             witht
             wt_withcd
             wt_qsshh
             wt_qbshh
             wt_acco
             qsatz
        FROM with_item
        INTO TABLE it_with_item
        FOR ALL ENTRIES IN it_dtfiap_3
        WHERE bukrs it_dtfiap_3-bukrs AND
              belnr it_dtfiap_3-belnr AND
              gjahr it_dtfiap_3-gjahr AND
              buzei it_dtfiap_3-buzei.
        IF sy-subrc 0.
          SORT it_with_item BY bukrs belnr gjahr buzei.
        ENDIF.

      LOOP AT it_dtfiap_3 INTO wa_dtfiap_3.

        READ TABLE it_lfa1 INTO wa_lfa1 WITH KEY lifnr wa_dtfiap_3-lifnr BINARY SEARCH.
        IF sy-subrc 0.
          wa_dtfiap_3-zz_name2 wa_lfa1-name2.  " Vendor name
          wa_dtfiap_3-zz_ktokk wa_lfa1-ktokk.  " Vendor Group
          wa_dtfiap_3-zz_werks wa_lfa1-werks.  " Plant

          READ TABLE it_t001w INTO wa_t001w WITH KEY werks wa_lfa1-werks BINARY SEARCH.
          IF sy-subrc 0.
            wa_dtfiap_3-zz_name1 wa_t001w-name1.     " Plant Description
          ENDIF.
        ENDIF.

        READ TABLE it_with_item INTO wa_with_item with key bukrs wa_dtfiap_3-bukrs
                                                           belnr wa_dtfiap_3-belnr
                                                           gjahr wa_dtfiap_3-gjahr
                                                           buzei wa_dtfiap_3-buzei
                                                           BINARY SEARCH.
        IF sy-subrc 0.
             wa_dtfiap_3-zz_witht wa_with_item-witht.
             wa_dtfiap_3-zz_wt_withcd wa_with_item-wt_withcd.
             wa_dtfiap_3-zz_wt_qsshh wa_with_item-wt_qsshh.
             wa_dtfiap_3-zz_wt_qbshh wa_with_item-wt_qbshh.
             wa_dtfiap_3-zz_wt_acco wa_with_item-wt_qbshh.
             wa_dtfiap_3-zz_qsatz wa_with_item-qsatz.
        ENDIF.

        MODIFY  it_dtfiap_3 FROM  wa_dtfiap_3.
        CLEAR wa_dtfiap_3", wa_vbrp, wa_vbrk.



      ENDLOOP.
      REFRESH c_t_data.
      c_t_data[] it_dtfiap_3[].


  ENDCASE.




Now its time to run the report and see the output:






1 comment:

  1. Thanks for sharing this Information, Got to learn new things from your Blog on SAP SF.SAP SF

    ReplyDelete