Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Business Scenario:

Outbound interface to flatten the G/L hierarchy in the required format mentioned below which will be consumed by third party system. The flattening is based on G/L Account hierarchy in the bottom up format

In this example, we have used G/L Account (0GL_ACCOUNT) hierarchy.

G/L Account Hierarchy (ZGL_HIER_01)

Outbound Interface (Target flat file structure)

    Chart of Accounts for G/L Accounts – WCOA

MINOR_ACCT, MINOR_ACCT_NAME,

MAJOR_ACCT, MAJOR_ACCT_NAME,

ROLLUP1, ROLLUP1_NAME,

ROLLUP2, ROLLUP2_NAME,

ROLLUP3, ROLLUP3_NAME,

ROLLUP4, ROLLUP4_NAME,

ROLLUP5, ROLLUP5_NAME,

ROLLUP6, ROLLUP6_NAME,

ROLLUP7, ROLLUP7_NAME,

ROLLUP8, ROLLUP8_NAME

Approach:

  1. Create an OHD
  2. Create transformations to OHD from 0GL_ACCOUNT Texts
  3. In the transformations end routine write logic to populate the upper level nodes and its descriptions based on G/L Account and the hierarchy ZGL_HIER_01.

Solution:

  Step 1: Create an OHD (ZGLHIEOHD)

Step 2: Create transformations from G/L Account Info object

End Routine Logic:

*================================================================================================================*

DATA:   lt_hiernodes TYPE STANDARD TABLE OF /bi0/hgl_account,
         lt_nodetexts TYPE STANDARD TABLE OF rsthiernode,
         ls_hiernodes LIKE LINE OF lt_hiernodes,
         ls_nodetexts LIKE LINE OF lt_nodetexts,
         lt_result_pkg TYPE _ty_t_tg_1,
         ls_result_pkg LIKE LINE OF lt_result_pkg,
         lv_hierid TYPE rshieid,
         lv_account TYPE rsiobjnm,
         lv_levels TYPE i,
         lv_count TYPE i,
         lv_rollup_col_num TYPE i,
         lv_rollup_col(8).

FIELD-SYMBOLS: <fs_account> LIKE LINE OF lt_hiernodes,
                <fs_hiernodes> LIKE LINE OF lt_hiernodes,
                <fs_nodetexts> LIKE LINE OF lt_nodetexts,
                <fs_rollup> TYPE ANY,
                <fs_rollup_name> TYPE ANY.

* Get Hierarchy ID from Hierarchy Catelog
      SELECT SINGLE hieid
           FROM rshiedir
           INTO lv_hierid
           WHERE hienm = 'ZGL_HIER_01'. "'WOIS'.
* Get nodes (Hierarchy Node & G/L Accounts) based on Hierarchy ID
      SELECT *
           FROM /bi0/hgl_account
           INTO TABLE lt_hiernodes
           WHERE hieid = lv_hierid AND
                 objvers = 'A'.
* Get the Node descriptions
      SELECT *
           FROM rsthiernode
           INTO TABLE lt_nodetexts
           WHERE hieid = lv_hierid AND
           langu = 'E' AND
           objvers = 'A'.

SORT lt_nodetexts BY nodename.

LOOP AT RESULT_PACKAGE ASSIGNING <result_fields>.
* Since Chart of accounts are WCOA, we need to concatenate this to identify the G/L Accounts
      CONCATENATE 'WCOA' <result_fields>-minor_acct INTO lv_account.

      SORT lt_hiernodes BY nodename.
* If G/L Account is available in the hierarchy
      READ TABLE lt_hiernodes
           WITH KEY nodename = lv_account
           INTO ls_hiernodes
           BINARY SEARCH.

      IF sy-subrc = 0.
      SORT lt_hiernodes BY nodeid.

      READ TABLE lt_hiernodes
           WITH KEY nodeid = ls_hiernodes-parentid
           ASSIGNING <fs_hiernodes>
           BINARY SEARCH.

      ls_result_pkg-minor_acct = <result_fields>-minor_acct.
      ls_result_pkg-minor_acct_name = <result_fields>-minor_acct_name.
      ls_result_pkg-major_acct = <fs_hiernodes>-nodename.

      READ TABLE lt_nodetexts
           WITH KEY nodename = <fs_hiernodes>-nodename
           ASSIGNING <fs_nodetexts>
           BINARY SEARCH.

      ls_result_pkg-major_acct_name = <fs_nodetexts>-txtlg.

      lv_levels = ls_hiernodes-tlevel - 3.

      lv_count = 2.
* We need 8 levels
      DO 8 TIMES.

           READ TABLE lt_hiernodes
                WITH KEY nodeid = <fs_hiernodes>-parentid
                ASSIGNING <fs_hiernodes>.
           IF sy-subrc <> 0.
                EXIT.
           ENDIF.
* After major/minor nodes, the next level starts at 5 and then 7, 9..
           lv_rollup_col_num = 3 + lv_count.

           ASSIGN COMPONENT lv_rollup_col_num OF STRUCTURE ls_result_pkg  T<fs_rollup>.
           <fs_rollup> = <fs_hiernodes>-nodename.

           lv_rollup_col_num = lv_rollup_col_num + 1.

           ASSIGN COMPONENT lv_rollup_col_num OF STRUCTURE ls_result_pkg  TO  <fs_rollup_name>.

           READ TABLE lt_nodetexts
                WITH KEY nodename = <fs_hiernodes>-nodename
                ASSIGNING <fs_nodetexts>
                BINARY SEARCH.

           <fs_rollup_name> = <fs_nodetexts>-txtlg.

           lv_count = lv_count + 2.

      ENDDO.


      APPEND ls_result_pkg TO lt_result_pkg.

      CLEAR: ls_result_pkg, ls_hiernodes.

      ENDIF.

ENDLOOP.

REFRESH RESULT_PACKAGE.

RESULT_PACKAGE[] = lt_result_pkg[].

*================================================================================================================*

Output:

After executing the DTP, the output will be available in the specified folder as CSV file. If we open the CSV file with ";" as delimited, the output look like below.

Labels in this area