cancel
Showing results for 
Search instead for 
Did you mean: 

Routine help and suggestions required (Span of control)

anubhav_kumar2
Explorer
0 Kudos

Hello all

I require some help regarding a routine coding.

I have created a hierarchy of employees. The users now require a span of control key figure base on a unique pattern within this hierarchy...

UserName                                   Span of control

ABC                                                       3

    PQR                                                   1

            STU                                            0

    XYZ                                                    1

           123                                              0

            456                                             0

    DEF                                                    2    

           GHI                                               1

                 JKL                                         0

ABC is the main manager. ABC heads PQR, XYZ & DEF. PQR is the manager of STU. XYZ is the manager of 123 & 456. DEF is the manager of GHI.

Now...

1. JKL is the subordinate of GHI. This is 1st level of subordinates for ABC. GHI is the subordinate of DEF. This is 2nd level of subordinates for ABC. Then DEF is also the subordinate of ABC. So ABC gets a 1+1+1 = 3.

2. 123,456 are 2 subordinates of XYZ. This is 1st level. Then XYZ is the 2nd level for ABC. So ABC gets 1+1=2.

3. STU is the 1st level of subordinates. Then PQR is 2nd level of subordinates for ABC. So ABC gets 1+1 = 2.

Since 3 is the biggest count, the loop should populate 3 against ABC's span of control.

PQR, XYZ & GHI have only 1 level of subordinates so gets 1 span of control.

DEF has GHI & GHI has JKL as subordinates so gets a 2 span of control.

STU,123,456,JKL dont have any subordinates so gets 0 span of control.

I tried hard but was unable to code a loop that could populate such data in the DSO. This is different from the regular count of subordinates.

Is this logic even logical to code for?

Thanks.

Accepted Solutions (0)

Answers (1)

Answers (1)

sander_vanwilligen
Active Contributor
0 Kudos

Hi,

In my opinion there is certainly a logic for coding. I only wonder how your DataSource looks like. Which fields are available, e.g. to determine the exact position in the hierarchy.

Please give more details on the source data.

Best regards,

Sander

anubhav_kumar2
Explorer
0 Kudos

Hi Sander

Im sorry but I made a mistake while typing out the logic. Actually its this:-

UserName                                   Span of control

ABC                                                       2

    PQR                                                   1

            STU                                            0

    XYZ                                                    1

           123                                              0

            456                                             0

    DEF                                                    2    

           GHI                                               1

                 JKL                                         0

ABC will have 2 span of control coz the max span of controls between PQR, XYZ & DEF (ABC's subordinates) is 1,1,2 = 2.

This logic is varying in terms of hierarchy nodes.

For ex: If I loop by employees, GHI will get 1 subordinate (hence 1 span of control)... DEF will get 2 since GHI is a subordinate with 1 more subordinate.

But when it will eventually reach ABC... they want max span of control and thus the logic for finding the SOC for other nodes doesnt match with ABC's logic.

And we need to diffrentiate ABC from other nodes.

I only wonder how your DataSource looks like. Which fields are available, e.g. to determine the exact position in the hierarchy.

Please give more details on the source data.

The datasource is a generic datasource with Employee no. (PERNR) and account manager fields etc.

The hierarchy has been generated via z program in 0employee from datasource 80EMPLOYEEH.

former_member185132
Active Contributor
0 Kudos

Hi Anubhav,

You'll have to use recursion. Not good for performance, but as the data structure (the hierarchy) is recursive, the code too will have to be.

First, create a subroutine thusly:


FORM POPULATE_SPAN USING PERNR TYPE <<data_type_of_pernr>>

  CHANGING CT_SPAN TYPE <<table containing PERNR, MGR and SPAN>>

  MAX_SPAN TYPE i.

  FIELD-SYMBOLS: <SPAN> LIKE LINE OF CT_SPAN.

  MAX_SPAN = -1.

  DATA TEMP_SPAN type i.

  LOOP AT CT_SPAN ASSIGNING <SPAN> WITH KEY MGR = PERNR.

  PERFORM POPULATE_SPAN USING <SPAN>-PERNR CHANGING CT_SPAN TEMP_SPAN. " Recursive call to find spans of children

  IF MAX_SPAN < TEMP_SPAN.

  MAX_SPAN = TEMP_SPAN.

  ENDIF.

  ENDLOOP.

  READ TABLE CT_SPAN ASSIGNING <SPAN> WITH KEY PERNR = PERNR.

  IF SY-SUBRC = 0.

<SPAN>-SPAN = MAX_SPAN + 1.

  ENDIF.

  IF MAX_SPAN = -1. " It is a leaf node

  MAX_SPAN = 0.

  ENDIF.

ENDFORM.

The subroutine will have to be in the 2nd part global of the end routine. You will also have to declare the data type of the CT_SPAN table in the same global area.

Then, in the End Routine do the following:


" Fill up LT_SPAN (same struct as CT_SPAN) with the data from RESULT_PACKAGE. Leave the Span field with empty.

DATA MAX_SPAN type i.

READ LT_SPAN ASSIGNING <SPAN> WITH KEY MGR = ''. " Get the root node

IF sy-subrc = 0

  PERFORM POPULATE_SPAN USING <SPAN>-PERNR CHANGING LT_SPAN MAX_SPAN.

  <SPAN>-SPAN = MAX_SPAN.

ENDIF.

" Loop at the ResultPackage, lookup the LT_SPAN table and populate the span in your result package

Regards,

Suhas

anubhav_kumar2
Explorer
0 Kudos

I will try this.

However, please read my second reply.

The logic is very weird. It wants to perform different logic for managers.

For ex: If I loop by employees, GHI will get 1 subordinate (hence 1 span of control)... DEF will get 2 since GHI is a subordinate with 1 more subordinate.

But when it will eventually reach ABC... they want max span of control and thus the logic for finding the SOC for other nodes doesnt match with ABC's logic.

And we need to differentiate ABC from other nodes. Other managers need to be given a specific post so that we can use the +1 logic... and for ABC we need to state it to be a super manager so that it can use the max from subordinates logic.

Is your code solving that issue?

former_member185132
Active Contributor
0 Kudos

Yes, I am aware of the special requirement for the root node (ABC in your example) and it is already handled. 

It is for this reason that I placed the <SPAN>-SPAN = MAX_SPAN line in the End Routine. If there wasn't that special requirement, this line wouldn't be needed as the subroutine itself was doing everything necessary.

So please try it out and let me know if you face problems.