文章目录
- 需求
- 整体流程
- 1. 检查角色是否存在
- 2. 复制角色
- 3. 批量生成参数文件
- 4. 如果角色用户还是出现未比较,可在PFCG界面选择批量比较
- 细节
- 上载模板
- 代码:
- 小结
需求
最近碰到一个需求,需要对大批量的PFCG角色进行复制并使其生效
整体流程
1. 检查角色是否存在
PRGN_CHECK_AGR_EXISTS
2. 复制角色
PRGN_COPY_AGR
3. 批量生成参数文件
批量复制新角色名,填入选择屏幕
点击在后台 等待生成即可
出现此消息代表成功
4. 如果角色用户还是出现未比较,可在PFCG界面选择批量比较
批量数据填入选择屏幕 出现以下消息代表比较成功
细节
上载模板
旧角色 | 新角色 |
---|---|
ZROLE1 | ZROLE_NEW1 |
ZROLE2 | ZROLE_NEW2 |
代码:
1. *&---------------------------------------------------------------------*
2. *& Report Z_CREATE_ROLE
3. *&---------------------------------------------------------------------*
4. *&
5. *&---------------------------------------------------------------------*
6. REPORT Z_CREATE_ROLE.
7.
8.
9. DATA: IT_DATA TYPE STANDARD TABLE OF ZZS_ALSMEX_TABLINE WITH HEADER LINE.
10. FIELD-SYMBOLS: <WA_DATA> TYPE ZZS_ALSMEX_TABLINE.
11.
12. * 导入的EXCEL格式
13. TYPES: BEGIN OF IT_FILE,
14. ROLE_NAME1(30) TYPE C, "复制来源
15. ROLE_NAME2(30) TYPE C, "创建内容
16. END OF IT_FILE.
17. DATA: WA_FILE TYPE IT_FILE.
18. DATA: LT_FILE TYPE STANDARD TABLE OF IT_FILE. "与EXCEL格式保持一致
19.
20. DATA: ACT_NAME TYPE XUPROFNAME.
21.
22. DATA: LT_AGR_USERS TYPE TABLE OF AGR_USERS,
23. LT_PT1016 TYPE TABLE OF PT1016,
24. LT_PT1250 TYPE TABLE OF PT1250,
25. LT_PT1251 TYPE TABLE OF PT1251,
26. WA_PT1016 LIKE LINE OF LT_PT1016.
27.
28.
29. * 画屏
30. SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
31. PARAMETERS: FNAME1 TYPE RLGRAP-FILENAME OBLIGATORY.
32. SELECTION-SCREEN END OF BLOCK BLK1.
33.
34. INITIALIZATION.
35. *获取本地文件
36. AT SELECTION-SCREEN ON VALUE-REQUEST FOR FNAME1." SEACH HELP
37.
38. CALL FUNCTION 'WS_FILENAME_GET'
39. EXPORTING
40. MASK = ',EXCEL FILE,*.XLS;*.XLSX;'
41. MODE = 'O' "S为保存,O为打开
42. IMPORTING
43. FILENAME = FNAME1
44. EXCEPTIONS
45. INV_WINSYS = 1
46. NO_BATCH = 2
47. SELECTION_CANCEL = 3
48. SELECTION_ERROR = 4
49. OTHERS = 5.
50.
51. START-OF-SELECTION.
52. PERFORM INTERNAL_TABLE.
53. PERFORM COPY_ROLE.
54.
55. END-OF-SELECTION.
56.
57.
58. *获取数据转化为内表
59. FORM INTERNAL_TABLE.
60. CALL FUNCTION 'Z_SSF_EXCEL_TO_INTERNAL_TABLE'
61. EXPORTING
62. FILENAME = FNAME1
63. I_BEGIN_COL = '1' "起始列
64. I_BEGIN_ROW = '2' "起始行
65. I_END_COL = '2' "终结列
66. I_END_ROW = '65535' "终结行
67. TABLES
68. INTERN = IT_DATA
69. EXCEPTIONS
70. INCONSISTENT_PARAMETERS = 1
71. UPLOAD_OLE = 2
72. OTHERS = 3.
73. IF IT_DATA[] IS INITIAL.
74. MESSAGE '清单中无数据' TYPE 'E'.
75. RETURN.
76. ENDIF.
77.
78. SORT IT_DATA BY ROW.
79. LOOP AT IT_DATA ASSIGNING <WA_DATA>.
80. CASE <WA_DATA>-COL.
81. WHEN '0001'.
82. WA_FILE-ROLE_NAME1 = <WA_DATA>-VALUE.
83. WHEN '0002'.
84. WA_FILE-ROLE_NAME2 = <WA_DATA>-VALUE.
85. ENDCASE.
86.
87. AT END OF ROW.
88. APPEND WA_FILE TO LT_FILE.
89. CLEAR WA_FILE.
90. ENDAT.
91. ENDLOOP.
92. ENDFORM.
93.
94.
95. FORM COPY_ROLE.
96.
97. LOOP AT LT_FILE INTO WA_FILE.
98. *检查角色是否存在
99. CALL FUNCTION 'PRGN_CHECK_AGR_EXISTS'
100. EXPORTING
101. ACTIVITY_GROUP = WA_FILE-ROLE_NAME1.
102. IF SY-SUBRC = 0.
103. *复制角色
104. CALL FUNCTION 'PRGN_COPY_AGR'
105. EXPORTING
106. SOURCE_AGR = WA_FILE-ROLE_NAME1
107. TARGET_AGR = WA_FILE-ROLE_NAME2
108. DISPLAY_MESSAGES = ''.
109.
110. ENDIF.
111. ENDLOOP.
112. ENDFORM.
小结
代码不多 操作方便快捷