2008 Jan 09 12:17 PM
for given objectid in a organization unit, using select statement how can i find the number of person associated with that object id.
for given objectid in a organization unit, using select statement how can i find the number of person associated with that object id.
2008 Jan 09 12:22 PM
Hi
You cannot directly find the person attached to the organizational unit directly by writing a select.
For this you have to use FM "RH_STRUC_GET" by passing the PLVAR = 01, OTYPE = 'O", OBJID = objectid and WEGID = 'O_S_P'. Then in the return internal table of RESULT_TAB count the number of records with OTYPE = 'P'. This will give you the number of persons in that organizational unit.
~ Ranganath
2008 Jan 10 11:36 AM
2008 Jan 10 11:44 AM
use like this
CALL FUNCTION 'SWI_GET_USERS_OF_ORG_UNIT'
EXPORTING
otype = 'O' " For organizational unit
objid = "Object ID (name) of org unit
tables
user_list = " internal table for output
EXCEPTIONS
NOT_FOUND = 1
NO_ACTIVE_PLVAR = 2
OTHERS = 3
You will get al users in this internal table. Use describe to get number
Regards,
Pankaj
2008 Jan 09 12:24 PM
Hi,
Use FM SWI_GET_USERS_OF_ORG_UNIT. Pass the object ID and type and you will get the list of users.
Regards,
Pankaj
2008 Jan 10 11:44 AM
Hi please check this coding,
REPORT yhr_tmp .
*DATA: pr_id LIKE zwfesc-pr_id VALUE '0008',
wf_loopc LIKE zwfesc-alevel VALUE 00,
TRIP TYPE SWC_OBJECT,
nacode LIKE zwfesc-acode VALUE '9004',
t_acode LIKE zwfesc-acode,
wf_initiator LIKE wfsyst-initiator,
DATA: int_org LIKE bapip0001b OCCURS 0 WITH HEADER LINE,
pe_return LIKE bapireturn.
DATA: l_appr_userid LIKE pa0105-usrid,
l_acode LIKE zwfesc-acode,
l_seq_no LIKE zwfesc-sl_no,
l_orgunit LIKE bapip0001b-org_unit,
l_nxt_orgunit LIKE bapip0001b-org_unit,
l_step LIKE zwfesc-step.
PARAMETER: p_userid LIKE pa0105-usrid.
CALL FUNCTION 'BAPI_EMPLOYEE_GETDATA'
EXPORTING
userid = p_userid
date = sy-datum
TABLES
org_assignment = int_org.
READ TABLE int_org INDEX 1.
IF sy-subrc EQ 0.
MOVE int_org-org_unit TO l_orgunit.
WHILE l_acode IS INITIAL.
PERFORM f_get_approver USING l_orgunit CHANGING
l_appr_userid
l_acode.
Check if initiator is chief of org unit
OR chief position is unoccupied
IF l_appr_userid EQ p_userid OR
l_appr_userid IS INITIAL.
CLEAR l_acode.
Find the next higher org unit
SELECT SINGLE sobid INTO l_nxt_orgunit FROM hrp1001
WHERE objid EQ l_orgunit
AND begda LE sy-datum
AND endda GE sy-datum
AND otype EQ 'O'
AND plvar EQ '01'
AND rsign EQ 'A'
AND relat EQ '002'.
IF sy-subrc = 0.
MOVE l_nxt_orgunit TO l_orgunit.
ELSE.
MOVE: 'E' TO pe_return-type,
'001' TO pe_return-code,
'No agent code found' TO pe_return-message.
ENDIF.
ENDIF.
ADD 1 TO l_seq_no.
ENDWHILE.
SELECT SINGLE step INTO l_step FROM zwfesc
WHERE pr_id EQ '008'
AND sl_no EQ l_seq_no
AND begda LE sy-datum
AND endda GE sy-datum
AND acode EQ l_acode.
ENDIF.
&----
*& Form F_GET_APPROVER
&----
text
----
-->P_INT_ORG_ORG_UNIT text
<--P_L_APPR_USERID text
<--P_L_ACODE text
<--P_L_SEQ_NO text
----
FORM f_get_approver USING p_org_unit
CHANGING p_appr_userid
p_acode.
DATA: l_pernr LIKE pa0000-pernr.
DATA: int_result LIKE swhactor OCCURS 0 WITH HEADER LINE.
DATA: int_commun LIKE bapip0105b OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'RH_STRUC_GET'
EXPORTING
act_otype = 'O'
act_objid = p_org_unit
act_wegid = 'ORGCHART'
act_plvar = ' '
act_begda = sy-datum
act_endda = sy-datum
TABLES
result_tab = int_result
EXCEPTIONS
no_plvar_found = 1
no_entry_found = 2
OTHERS = 3.
IF sy-subrc EQ 0.
LOOP AT int_result WHERE otype EQ 'C'.
ENDLOOP.
IF sy-subrc EQ 0.
SELECT SINGLE subty INTO p_acode FROM hrp1010
WHERE objid EQ int_result-objid.
ENDIF.
LOOP AT int_result WHERE otype EQ 'P'.
ENDLOOP.
IF sy-subrc EQ 0.
MOVE int_result-objid TO l_pernr.
CALL FUNCTION 'BAPI_EMPLOYEE_GETDATA'
EXPORTING
employee_id = l_pernr
date = sy-datum
TABLES
communication = int_commun.
LOOP AT int_commun WHERE subtype = '001'.
ENDLOOP.
MOVE int_commun-userid TO p_appr_userid.
ENDIF.
ELSE.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |