Guest User

Untitled

a guest
Jan 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. /*
  2. ebs_dupresp.sql
  3. Contact: John Piwowar
  4. Purpose: Grant one user's responsbilities to another, optionally
  5. creating the target user
  6. Notes: ...
  7. */
  8.  
  9. SET serveroutput on size 1000000 format word_wrapped
  10. SET verify off feedback off
  11.  
  12. --Readability improvements. First time for everything.
  13. DEFINE src=&1
  14. DEFINE targ=&2
  15.  
  16. PROMPT Source user: &&src
  17. PROMPT Target user: &&targ
  18. PROMPT CTRL-C might be a good idea if these are incorrect/reversed.
  19. ACCEPT create_user_pref prompt 'Create &&targ if non-existent? (y/N) '
  20.  
  21. DECLARE
  22. src_user APPLSYS.FND_USER.USER_NAME%TYPE := upper('&&src');
  23. targ_user APPLSYS.FND_USER.USER_NAME%TYPE := upper('&&targ');
  24. create_flag BOOLEAN := FALSE;
  25. targ_userid APPLSYS.FND_USER.USER_ID%TYPE := NULL;
  26.  
  27. --Cursor to pull source user's responsbilities
  28. --Note: does not pull end-dated responsibilities, since they were
  29. -- presumably end-dated for a reason. Also retains forward-looking
  30. -- end dates
  31. CURSOR cGetResps (user_in APPLSYS.FND_USER.USER_NAME%TYPE)
  32. IS
  33. SELECT a.application_short_name app
  34. , r.responsibility_key key
  35. , t.responsibility_name respname
  36. , s.security_group_key secgrp
  37. , g.end_date
  38. FROM apps.fnd_user_resp_groups_direct g
  39. , applsys.fnd_responsibility r
  40. , applsys.fnd_user u
  41. , applsys.fnd_application a
  42. , applsys.fnd_security_groups s
  43. , applsys.fnd_responsibility_tl t
  44. WHERE g.responsibility_id = r.responsibility_id
  45. AND g.security_group_id = s.security_group_id
  46. AND g.responsibility_application_id = r.application_id
  47. AND g.responsibility_application_id=t.application_id
  48. AND g.responsibility_id=t.responsibility_id
  49. AND r.application_id = a.application_id
  50. AND u.user_name = user_in
  51. AND g.user_id = u.user_id
  52. AND (g.end_date > SYSDATE or g.end_date is null);
  53. BEGIN
  54. IF upper(substr('&&create_user_pref',1,1)) = 'Y' THEN
  55. create_flag := TRUE;
  56. END IF; --create_user_pref=Y
  57.  
  58. --Create user if needed
  59. IF create_flag AND NOT (apps.fnd_user_pkg.userExists(targ_user))
  60. THEN
  61.  
  62. targ_userid := apps.fnd_user_pkg.createuserid (
  63. x_user_name => targ_user
  64. , x_owner => 'CUST'
  65. , x_unencrypted_password => 'chang3m3'
  66. , x_description => 'Autocreated by ebs_dupresps.sql'
  67. );
  68. --Probably won't ever get to this point, but just to be safe...
  69. IF targ_userid IS NULL THEN
  70. dbms_output.put_line('Failed to create ' || targ_user ||
  71. ', cannot continue'
  72. );
  73. RETURN;
  74. ELSE
  75. dbms_output.put_line('User ' || targ_user || ' created with id ' ||
  76. targ_userid);
  77. END IF; --targ_userid
  78. ELSIF create_flag AND (apps.fnd_user_pkg.userExists(targ_user))
  79. THEN
  80. dbms_output.put_line('User ' || targ_user || ' already exists.');
  81. ELSIF NOT create_flag AND NOT (apps.fnd_user_pkg.userExists(targ_user))
  82. THEN
  83. dbms_output.put_line('User ' || targ_user ||
  84. ' does not exist and create flag not specified.');
  85. RETURN;
  86. END IF; --create_flag
  87.  
  88. --Add responsibilities
  89.  
  90. FOR new_resp IN cGetResps(src_user)
  91. LOOP
  92. dbms_output.put_line('Adding responsibility ' || new_resp.respname);
  93. apps.fnd_user_pkg.AddResp( username => targ_user
  94. , resp_app => new_resp.app
  95. , resp_key => new_resp.key
  96. , security_group => new_resp.secgrp
  97. , description => 'Added by ebs_dupresps.sql'
  98. , start_date => SYSDATE
  99. , end_date => new_resp.end_date
  100. );
  101. END LOOP; --new_resp
  102. END; --ebs_dupresps
  103. /
Add Comment
Please, Sign In to add comment