Skip to Content
avatar image
Former Member

flat hierachy into infoobjects

Hi

I have a customer that need to take the 0ORGUNIT hierarchy and define it as a flat hierarchy. This means that every node is going to be a infoobject that contains the data representing the node Level (TLEVEL). I have created a code, but I need some QA review from some expert to see if this code is going to work or not. Or if anyone else has other ideas on how this can be solved.

Here is the code and steps:

STEG 1:

-Create infoobjects, one for each nodelevel(TLEVEL). Use 0ORGUNIT as template

-Add the new infoobject as attributes to the 0ORGUNIT master data. Define as navigation attributes.

Suggestion to abap code

Tables: /bi0/PORGUNIT.
-----------------------------------------------------------------------
* ORGUNIT INTERNAL TABLE
* ic = input area
* wa = working area
* up = updated area
* it = internal tables
-----------------------------------------------------------------------
Data: ic_data like standard table of /bi0/PORGUNIT.
Data: wa_ic_data like /bi0/PORGUNIT.
Data: up_data like standard table of /bi0/PORGUNIT.
-----------------------------------------------------------------------
* HIERARCHY DECLARATIONS
* HASHED TABLE OF = Used when you have large data-sets with a lot of reads, but comparatively few writes. When declaring a hash table you have to also declare a UNIQUE KEY.
* HEADER LINE, means that there is an implicit header line or work area, so you do not need to create a separate explicit work area in which to read the data into.
-----------------------------------------------------------------------
Data: it_orgunit like hashed table of /bi0/horgunit with unique key hieid objvers nodeid iobjnm nodename .
Data: do_orgunit like hashed table of /bi0/horgunit with unique key hieid objvers nodeid iobjnm nodename.
Data: wa_orgunit like /bi0/horgunit,
      do_wa_orgunit like /bi0/horgunit.
Data: i/bi0/porgunit like /bi0/porgunit occurs 0 with header line.
Data: begin of p/bi0/porgunit occurs 100.
        include structure /bi0/porgunit.
Data:   index type i,
      end of p/bi0/porgunit.
----------------------------------------------------------------------------------
* COPY THE ORGUNIT HIERARCHY STRUCTURE INTO MEMORY
-----------------------------------------------------------------------------------
Select hieid objvers nodeid iobjnm nodename tlevel link parentid childid nextid intervl into table it_orgunit from /bi0/horgunit.
do_orgunit[] = it_orgunit[].
-----------------------------------------------------------------------------------
* SEARCH FOR PARENT NODE FOR ORGUNIT AND UPDATE THE P TABLE WITH THE NEW ROW
-----------------------------------------------------------------------------------
Data: doloop(2).
Sort ic_data by orgunit.
refresg up_data.
Loop at ic_data into wa_ic_data.
---------------------------------------------------------------------------------
*READ HIERACHY TABLE
---------------------------------------------------------------------------------
  Read table it_orgunit into wa_orgunit with key OBJVERS = 'A'.
  doloop = wa_orgunit–tlevel – 2.
  check doloop gt 0.
  do_wa_orgunit–parentid = wa_orgunit–parentid.
  do doloop times.
    read table do_orgunit into do_wa_orgunit
        with key objvers = ‘A’
    nodeid = do_wa_orgunit–parentid.
    check sy–subrc = 0.
    case do_wa_orgunit–tlevel.
    when ’12’.
      wa_ic_data–/bic/zorgl12 = do_wa_orgunit–nodename.
    when ‘11’.
      wa_ic_data–/bic/zorgl11 = do_wa_orgunit–nodename.
    when ‘10’.
      wa_ic_data–/bic/zorgl10 = do_wa_orgunit–nodename.
    when ‘09’.
      wa_ic_data–/bic/zorgl09 = do_wa_orgunit–nodename.
    when ‘08’.
      wa_ic_data–/bic/zorgl08 = do_wa_orgunit–nodename.
    when ‘07’.
      wa_ic_data–/bic/zorgl07 = do_wa_orgunit–nodename.
    when ‘06’.
      wa_ic_data–/bic/zorgl06 = do_wa_orgunit–nodename.
    when ‘05’.
      wa_ic_data–/bic/zorgl05 = do_wa_orgunit–nodename.
    when ‘04’.
      wa_ic_data–/bic/zorgl04 = do_wa_orgunit–nodename.
    when ‘03’.
      wa_ic_data–/bic/zorgl03 = do_wa_orgunit–nodename.
    when ‘02’.
      wa_ic_data–/bic/zorgl02 = do_wa_orgunit–nodename.
    endcase.
    do_wa_costcenter–tlevel = do_wa_orgunit–tlevel – 1.
  enddo.


  append wa_ic_data to up_data.
---------------------------------------------------------------------
* UPDATE DBTABLE
---------------------------------------------------------------------
  Update /bi0/porgunit from wa_ic_data.


endloop.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Apr 23 at 06:59 AM

    1. You are using obsolete ABAP. NEVER define a table with a header line. The header line and table have the same name, so you may easily confuse the two. Ambiguity is BAD. Always define a seperate work area. But also see LOOP AT ASSIGNING and READ... ASSIGNING...

    TABLES is also obsolete.

    2. You are updating the P table directly, but there are no checks to see if someone else is using it. Read about ENQUEUE/DEQUEUE and SAP table locking.

    3. You can simplify your CASE by using field symbols and ASSIGN

    If you want to know if it will work - then run it and see if it does what you intend. If it doesn't use the debug.

    Personally, I'd write a generic extractor on my BW system, and use that as my datasource, and use standard BW flows to update the InfoObject rather than doing it directly.

    Add comment
    10|10000 characters needed characters exceeded