on 2012 Jan 30 11:10 AM
Hi all,
Do you know any FM to obtain all the users with some attribute?
For example, I want to get all the users with the attribute Company Code (BUK) equal to '0180' or i want to know all the users with the attribute Cost Center (CNT) equal to 1000000000, etc.
I usually use the FM BBP_READ_ATTRIBUTES for read the attributes of one specific user in PPOSA_BBP.
I don't know if exits some FM or other way to obtain it or if I need to create a FM to do some selects statements to the tables HRP1001, HRV1222A, etc...
Thanks in advance.
Regards,
Ricardo.
Request clarification before answering.
Hello Ricardo,
there is no standard function module covering your request.
One solution could be :
1-Get objects O and S having attributeu2019s value you look for by selection from HRV1222A view
1.1 For object type u2018Ou2019, get all organizational units below current organizational unit using RH_STRUCT_GET function module
a- Get users from each OU found above using BBP_OM_STRUC_GET_USER_FROM_ORG function module
b- For each user, get attribute values using HR_GENAT_READ_ATTRIBUTES function module.
c- Check useru2019s attribute values are not excluded.
1.2 For object type u2018Su2019, do steps b and c from paragraph 1.1
Regards.
Laurent.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Laurent ,
I'm going to create a test report for test your solution.
This morning I did a sql trace for know the tables used, and I did another test report and It seems that works fine.
But, I don't like my solution so much. There are too many nested selects statements and loops...
REPORT ztest_ricardo.
TABLES: but000, hrp1001, hrv1222a.
PARAMETERS: p_attrib LIKE hrv1222a-attrib OBLIGATORY DEFAULT 'BUK',
p_value LIKE hrv1222a-low OBLIGATORY DEFAULT 'EC1CLNT200\0180'.
START-OF-SELECTION.
DATA: lt_hrv1222a TYPE hrv1222a OCCURS 0 WITH HEADER LINE.
SELECT * FROM hrv1222a INTO TABLE lt_hrv1222a
WHERE plvar EQ '01'
AND begda LE sy-datum
AND endda GE sy-datum
AND istat EQ '1'
AND attrib EQ p_attrib
AND low EQ p_value.
LOOP AT lt_hrv1222a.
SELECT SINGLE * FROM hrp1001
WHERE plvar EQ '01'
AND otype EQ lt_hrv1222a-otype
AND objid EQ lt_hrv1222a-objid
AND subty EQ 'A002'
AND istat EQ '1'
AND begda LE sy-datum
AND endda GE sy-datum
AND sclas EQ 'O'.
CHECK sy-subrc EQ 0.
SELECT * FROM hrp1001
WHERE plvar EQ '01'
AND varyf EQ hrp1001-otjid
AND subty EQ 'A003'
AND istat EQ '1'
AND begda LE sy-datum
AND endda GE sy-datum
AND sclas EQ 'O'.
CHECK sy-subrc EQ 0.
SELECT SINGLE * FROM hrp1001
WHERE plvar EQ '01'
AND varyf EQ hrp1001-otjid
AND subty EQ 'B008'
AND istat EQ '1'
AND begda LE sy-datum
AND endda GE sy-datum
AND sclas EQ 'S'.
CHECK sy-subrc EQ 0.
SELECT SINGLE * FROM hrp1001
WHERE plvar EQ '01'
AND sclas EQ 'US'
AND otype EQ hrp1001-otype
AND objid EQ hrp1001-objid
AND begda LE sy-datum
AND endda GE sy-datum
AND otype EQ 'CP'
AND subty EQ 'B208'.
IF sy-subrc EQ 0.
WRITE: / hrp1001-sobid.
ENDIF.
ENDSELECT.
ENDLOOP.
Thanks for your help. With my test report didn't works fine, Now is working perfect with your solution.
Here is the code:
REPORT ztest_ricardo.
TABLES: hrv1222a.
PARAMETERS: p_attrib LIKE hrv1222a-attrib OBLIGATORY DEFAULT 'BUK',
p_value LIKE hrv1222a-low OBLIGATORY DEFAULT 'EC1CLNT200\0176'.
START-OF-SELECTION.
DATA: lt_hrv1222a TYPE hrv1222a OCCURS 0 WITH HEADER LINE,
lt_result_struc TYPE struc OCCURS 0 WITH HEADER LINE,
lt_result_obj TYPE objec OCCURS 0 WITH HEADER LINE,
lt_start_obj TYPE hrtb_object WITH HEADER LINE,
lt_users TYPE hrbcitb_user WITH HEADER LINE,
lt_user_tab TYPE hrbcitb_user WITH HEADER LINE,
lt_attributes TYPE hrtb_attrib WITH HEADER LINE,
lt_attrib_ext TYPE hrtb_attvalrt WITH HEADER LINE,
lv_realo TYPE realo.
SELECT * FROM hrv1222a INTO TABLE lt_hrv1222a
WHERE plvar EQ '01'
AND begda LE sy-datum
AND endda GE sy-datum
AND istat EQ '1'
AND attrib EQ p_attrib
AND low EQ p_value.
LOOP AT lt_hrv1222a.
IF lt_hrv1222a-otype EQ 'O'.
REFRESH: lt_result_struc.
CALL FUNCTION 'RH_STRUC_GET'
EXPORTING
act_otype = lt_hrv1222a-otype
act_objid = lt_hrv1222a-objid
act_wegid = 'O-O_DOWN'
TABLES
result_struc = lt_result_struc[]
EXCEPTIONS
no_plvar_found = 1
no_entry_found = 2
OTHERS = 3.
CHECK lt_result_struc[] IS NOT INITIAL.
LOOP AT lt_result_struc.
REFRESH: lt_start_obj, lt_user_tab.
lt_start_obj-otype = lt_result_struc-otype.
lt_start_obj-objid = lt_result_struc-objid.
APPEND lt_start_obj.
CALL FUNCTION 'BBP_OM_STRUC_GET_USER_FROM_ORG'
EXPORTING
start_objects = lt_start_obj[]
IMPORTING
user_tab = lt_user_tab[]
EXCEPTIONS
path_not_found = 1
error_reading_structure = 2
no_roots = 3
invalid_roots = 4
internal_error = 5
OTHERS = 6.
APPEND LINES OF lt_user_tab TO lt_users.
ENDLOOP.
ELSE. "S
REFRESH: lt_result_obj.
CALL FUNCTION 'RH_STRUC_GET'
EXPORTING
act_otype = lt_hrv1222a-otype
act_objid = lt_hrv1222a-objid
act_wegid = 'O-O_DOWN'
TABLES
result_objec = lt_result_obj[]
EXCEPTIONS
no_plvar_found = 1
no_entry_found = 2
OTHERS = 3.
LOOP AT lt_result_obj.
lt_users-orgobjid-otype = lt_result_obj-otype.
lt_users-orgobjid-objid = lt_result_obj-objid.
lt_users-uname = lt_result_obj-short.
APPEND lt_users. CLEAR lt_users.
ENDLOOP.
ENDIF.
ENDLOOP.
SORT lt_users.
DELETE ADJACENT DUPLICATES FROM lt_users.
APPEND p_attrib TO lt_attributes.
LOOP AT lt_users.
AT NEW orgobjid-objid.
REFRESH: lt_attrib_ext.
lv_realo = lt_users-orgobjid-objid.
CALL FUNCTION 'HR_GENAT_READ_ATTRIBUTES'
EXPORTING
scenario = 'BBP'
otype = lt_users-orgobjid-otype
realo = lv_realo
attributes = lt_attributes[]
IMPORTING
attrib_ext = lt_attrib_ext[]
EXCEPTIONS
internal_error = 1
invalid_object = 2
invalid_scenario = 3
invalid_attribute = 4
no_authority = 5
OTHERS = 6.
ENDAT.
READ TABLE lt_attrib_ext WITH KEY low = p_value.
IF sy-subrc EQ 0.
WRITE:/ lt_users-uname.
ENDIF.
ENDLOOP.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.