Skip to Content
0
May 05, 2008 at 09:50 AM

Regarding ABAP-HR Code

138 Views

Hi Friends

I am new to ABAP-HR.I am trying to analyze below peace of code but not yet succeeded till.

So any one please illustrates me the below peace of code step-by-step.

DATA: is_i77pr LIKE t77pr.

DATA: temp1 LIKE result_struc_obj.

DATA: temp2 LIKE result_struc_obj.

DATA: tmp_pnext LIKE struc-pnext.

DATA: mgr_name LIKE objec-stext.

DATA: tmp_sytabx LIKE sy-tabix.

CLEAR: result_tab_obj.

REFRESH: result_tab_obj.

  • evpath = 'ZPXO_GEN'.

CALL FUNCTION 'RH_STRUC_GET_MULTIPLE_ROOTS'

EXPORTING

act_wegid = evpath

  • ACT_INT_FLAG =

  • ACT_PLVAR = ' '

act_svect = '1'

act_begda = sy-datum

act_endda = sy-datum

act_tdepth = 0

act_tflag = 'X'

act_vflag = 'X'

act_sflag = 'X'

act_recurs = 'X'

act_text_buffer_fill = 'X'

authority_check = 'X'

  • BUFFER_MODE = ' '

keep_order = 'X'

  • IMPORTING

  • ACT_PLVAR =

  • ROOT_COPY =

TABLES

root_objects = root_objects

result_objec = result_objec_obj

result_struc = result_struc_obj

EXCEPTIONS

no_plvar_found = 1

no_entry_found = 2

path_not_found = 3

root_not_found = 4

OTHERS = 5

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

  • Delete Root Org Unit's Chief Personnel No.

LOOP AT root_objects.

REFRESH: result_tab_obj.

CLEAR: result_tab_obj.

CALL FUNCTION 'RH_STRUC_GET'

EXPORTING

act_otype = 'O'

act_objid = root_objects-objid

act_wegid = 'ZPX_CFPN'

act_begda = begda

act_endda = endda

TABLES

result_tab = result_tab_obj

EXCEPTIONS

no_plvar_found = 1

no_entry_found = 2

OTHERS = 3.

LOOP AT result_tab_obj WHERE otype = 'P'.

  • Append Root Org Unit's Mgr Name into Description...

CLEAR: mgr_name.

LOOP AT result_objec_obj WHERE otype = 'P' AND objid = result_tab_obj-objid.

mgr_name = result_objec_obj-stext.

CONCATENATE mgr_name ')' INTO mgr_name.

CONCATENATE '(Mgr:' mgr_name INTO mgr_name

SEPARATED BY space.

EXIT.

ENDLOOP.

IF sy-subrc = 0.

LOOP AT result_objec_obj WHERE otype = 'O' AND objid = root_objects-objid.

CONCATENATE result_objec_obj-stext mgr_name INTO result_objec_obj-stext

SEPARATED BY space.

MODIFY result_objec_obj. CLEAR result_objec_obj.

ENDLOOP.

ENDIF.

CLEAR: temp1, temp2.

  • Get references of Chief person...

LOOP AT result_struc_obj

WHERE otype = result_tab_obj-otype

AND objid = result_tab_obj-objid.

MOVE-CORRESPONDING result_struc_obj TO temp1.

ENDLOOP.

  • Get reference of Root Org.Unit...

LOOP AT result_struc_obj

WHERE otype = root_objects-otype

AND objid = root_objects-objid.

MOVE-CORRESPONDING result_struc_obj TO temp2.

ENDLOOP.

CLEAR : tmp_sytabx .

LOOP AT result_struc_obj

WHERE otype = result_tab_obj-otype

AND objid = result_tab_obj-objid

AND pup = temp2-seqnr.

tmp_sytabx = sy-tabix.

ENDLOOP.

LOOP AT result_objec_obj

WHERE otype = result_tab_obj-otype

AND objid = result_tab_obj-objid.

IF sy-tabix = tmp_sytabx.

DELETE result_objec_obj.

EXIT.

ENDIF.

ENDLOOP.

DELETE result_struc_obj

WHERE otype = result_tab_obj-otype

AND objid = result_tab_obj-objid

AND pup = temp2-seqnr.

  • 1. If the value in field STRUCS-PDOWN for object U, which is

  • located above D, corresponds to the value STRUCS-SEQNR for D,

  • set the value of U STRUCS-PDOWN to the value of D STRUCS-PNEXT.

  • Reduce the value of U STRUCS-VCOUNT by 1.

CLEAR: tmp_pnext.

tmp_pnext = temp1-pup.

LOOP AT result_struc_obj WHERE seqnr = tmp_pnext.

result_struc_obj-vcount = result_struc_obj-vcount - 1.

MODIFY result_struc_obj. CLEAR result_struc_obj.

ENDLOOP.

CLEAR: tmp_pnext.

tmp_pnext = temp1-seqnr.

LOOP AT result_struc_obj WHERE pdown = tmp_pnext.

result_struc_obj-pdown = temp1-pnext.

MODIFY result_struc_obj. CLEAR result_struc_obj.

ENDLOOP.

  • 2. If an object P exists, for which the value STRUCS-PNEXT corresponds

  • to the value of D STRUCS-SEQNR, set the value of P STRUCS-PNEXT

  • to the value of D STRUCS-PNEXT.

CLEAR: tmp_pnext.

tmp_pnext = temp1-seqnr.

LOOP AT result_struc_obj WHERE pnext = tmp_pnext.

result_struc_obj-pnext = temp1-pnext.

MODIFY result_struc_obj. CLEAR result_struc_obj.

ENDLOOP.

  • 3. If an object N exists, for which the value STRUCS-PREV corresponds to

  • the value of D STRUCS-SEQNR, set the value of N STRUCS-PPREV to the value

  • of D STRUCS-PPREV.

CLEAR: tmp_pnext.

tmp_pnext = temp1-seqnr.

LOOP AT result_struc_obj WHERE pprev = tmp_pnext.

result_struc_obj-pprev = temp1-pprev.

MODIFY result_struc_obj. CLEAR result_struc_obj.

ENDLOOP.

ENDLOOP.

ENDLOOP.

  • @ start of code - vinay golchha

  • Data declarations

data : root_orgid type realo.

DATA : root_mgr_pernr TYPE realo.

DATA : emp_pernr TYPE realo.

DATA : mgr_pernr TYPE realo.

DATA : org_unit_id TYPE realo.

DATA : pernr_tabix LIKE sy-tabix.

DATA : struc_tabix LIKE sy-tabix.

DATA: leading_pos LIKE hrobject OCCURS 0 WITH HEADER LINE.

DATA : direct_emp_flag TYPE c VALUE ' '.

DATA: i1001 LIKE hri1001 OCCURS 0 WITH HEADER LINE.

DATA : root_mgr_pernr1 TYPE sobid.

DATA : result_objec_obj1 LIKE STANDARD TABLE OF result_objec_obj WITH HEADER LINE.

DATA : org_seqnr TYPE sseqnr.

  • Loop through all the root org units

LOOP AT root_objects.

result_objec_obj1[] = result_objec_obj[].

  • Get the Root Org Unit

root_orgid = root_objects-objid.

  • Get the Manager of the Root Org Unit

CALL FUNCTION 'RH_GET_LEADER'

EXPORTING

plvar = '01'

keydate = sy-datum

otype = 'O'

objid = root_orgid

IMPORTING

leader_id = root_mgr_pernr

EXCEPTIONS

no_leader_found = 1

no_leading_position_found = 2

OTHERS = 3.

IF sy-subrc <> 0.

  • MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

  • WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

  • Looping through the Employees for Root Org Unit

LOOP AT result_objec_obj1 WHERE otype = 'P'.

emp_pernr = result_objec_obj1-objid.

  • Set thye direct employee flag to blank

direct_emp_flag = ' '.

  • Get the leading positions

REFRESH leading_pos.

CALL FUNCTION 'RH_GET_LEADING_POSITION'

EXPORTING

plvar = '01'

otype = 'P'

sobid = emp_pernr

TABLES

leading_pos = leading_pos

EXCEPTIONS

no_lead_pos_found = 1

OTHERS = 2.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

  • Loop through the leading positions if there are

  • multiple leading positions

LOOP AT leading_pos.

org_unit_id = leading_pos-objid.

  • Get the Manager

REFRESH i1001.

CALL FUNCTION 'RHOM_READ_RELAT_BUFFERED'

EXPORTING

otype = 'S'

objid = leading_pos-objid

plvar = '01'

subty = 'A008'

TABLES

i1001 = i1001

EXCEPTIONS

no_active_plvar = 1

OTHERS = 2.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

root_mgr_pernr1 = root_mgr_pernr.

READ TABLE i1001 WITH KEY sobid = root_mgr_pernr1.

  • If manager found set directly reporting flag as 'X'

IF sy-subrc = 0.

direct_emp_flag = 'X'.

EXIT.

ENDIF.

ENDLOOP.

  • If the current Employee manager is NOT equal to Root Org Unit's Manager

IF direct_emp_flag = ' '.

  • Get sequence number of org unit

READ TABLE result_struc_obj

WITH KEY otype = root_objects-otype

objid = root_objects-objid.

org_seqnr = result_struc_obj-seqnr.

  • Remove entry from result_struc_obj and modify the table accordingly

CLEAR : temp1, temp2,tmp_sytabx.

LOOP AT result_struc_obj

WHERE otype = 'P'

AND objid = emp_pernr

AND pup = org_seqnr.

MOVE-CORRESPONDING result_struc_obj TO temp1.

ENDLOOP.

LOOP AT result_struc_obj

WHERE otype = root_objects-otype

AND objid = root_objects-objid.

MOVE-CORRESPONDING result_struc_obj TO temp2.

ENDLOOP.

CLEAR struc_tabix.

LOOP AT result_struc_obj

WHERE otype = 'P'

AND objid = emp_pernr

AND pup = temp2-seqnr.

struc_tabix = sy-tabix.

ENDLOOP.

LOOP AT result_objec_obj

WHERE otype ='P'

AND objid = emp_pernr.

  • Delete entry for directly reporting employee

IF sy-tabix = struc_tabix.

DELETE result_objec_obj.

EXIT.

ENDIF.

ENDLOOP.

DELETE result_struc_obj

WHERE otype = 'P'

AND objid = emp_pernr

AND pup = temp2-seqnr.

  • Delete count of vertically related objects by 1

  • if record deleted

CLEAR tmp_pnext.

tmp_pnext = temp1-pup.

LOOP AT result_struc_obj WHERE seqnr = tmp_pnext.

result_struc_obj-vcount = result_struc_obj-vcount - 1.

MODIFY result_struc_obj.

CLEAR result_struc_obj.

ENDLOOP.

  • Set the down pointer of the record previous to the

  • deleted one to the next pointer of the deleted one

CLEAR tmp_pnext.

tmp_pnext = temp1-seqnr.

LOOP AT result_struc_obj WHERE pdown = tmp_pnext.

result_struc_obj-pdown = temp1-pnext.

MODIFY result_struc_obj.

CLEAR result_struc_obj.

ENDLOOP.

  • Set the next pointer of the record previous to the deleted

  • one to the next pointer of the deleted one

CLEAR tmp_pnext.

tmp_pnext = temp1-seqnr.

LOOP AT result_struc_obj WHERE pnext = tmp_pnext.

result_struc_obj-pnext = temp1-pnext.

MODIFY result_struc_obj.

CLEAR result_struc_obj.

ENDLOOP.

  • Set the value of previous pointer

CLEAR tmp_pnext.

tmp_pnext = temp1-seqnr.

LOOP AT result_struc_obj WHERE pprev = tmp_pnext.

result_struc_obj-pprev = temp1-pprev.

MODIFY result_struc_obj.

CLEAR result_struc_obj.

ENDLOOP.

ENDIF.

ENDLOOP.

ENDLOOP.

  • @ End of Code - Vinay Golchha

REFRESH: result_objec, result_struc.

CLEAR: result_objec, result_struc.

result_objec[] = result_objec_obj[].

result_struc[] = result_struc_obj[].

Regards,

Sree