Posted: Sat Apr 12, 2008 12:10 am Post subject: Импорт данных пользователей
Code:
REPORT ZZUSER_IMPORT_NEW MESSAGE-ID CJ LINE-SIZE 120 LINE-COUNT 38(3)
NO STANDARD PAGE HEADING.
* DDIC Tables
TABLES: ZIDESUSER, USR02, USR10, USGRP, TPARA, TSP03, T002C.
* Local dataset (as dictionary structure)
DATA: BEGIN OF XZIDESUSER OCCURS 100.
INCLUDE STRUCTURE ZIDESUSER.
DATA: END OF XZIDESUSER.
* User & Password as imported
DATA: BEGIN OF TUSER OCCURS 100,
USERNAME LIKE USR02-BNAME,
PASSWORD LIKE USR02-BCODE,
TRDAT LIKE USR02-TRDAT,
END OF TUSER.
* User & Password after cleansing
DATA: BEGIN OF TUSER1 OCCURS 100,
USERNAME LIKE USR02-BNAME,
PASSWORD LIKE USR02-BCODE,
TRDAT LIKE USR02-TRDAT,
END OF TUSER1.
* Log-on data
DATA: BEGIN OF TLOGONDATA OCCURS 100,
USERNAME LIKE USR02-BNAME,
LOGONDATA LIKE BAPILOGOND,
END OF TLOGONDATA.
* User defaults
DATA: BEGIN OF TDEFAULTS OCCURS 100,
USERNAME LIKE USR02-BNAME,
DEFAULTS LIKE BAPIDEFAUL,
END OF TDEFAULTS.
* Address data
DATA: BEGIN OF TADDRESS OCCURS 100,
USERNAME LIKE USR02-BNAME,
ADDRESS LIKE BAPIADDR3,
END OF TADDRESS.
* Company data
DATA: BEGIN OF TCOMPANY OCCURS 100,
USERNAME LIKE USR02-BNAME,
COMPANY LIKE BAPIUSCOMP,
END OF TCOMPANY.
* Parameters
DATA: BEGIN OF TPARAMETER OCCURS 100,
USERNAME LIKE USR02-BNAME,
PARID LIKE BAPIPARAM-PARID,
PARVA LIKE BAPIPARAM-PARVA,
PARTXT LIKE BAPIPARAM-PARTXT,
END OF TPARAMETER.
* Profiles
DATA: BEGIN OF TPROFILES OCCURS 100,
USERNAME LIKE USR02-BNAME,
BAPIPROF LIKE BAPIPROF-BAPIPROF,
BAPIPTEXT LIKE BAPIPROF-BAPIPTEXT,
BAPITYPE LIKE BAPIPROF-BAPITYPE,
BAPIAKTPS LIKE BAPIPROF-BAPIAKTPS,
END OF TPROFILES.
* Activity groups
DATA: BEGIN OF TACTIVITYGROUPS OCCURS 100,
USERNAME LIKE USR02-BNAME,
AGR_NAME LIKE BAPIAGR-AGR_NAME,
FROM_DAT LIKE BAPIAGR-FROM_DAT,
TO_DAT LIKE BAPIAGR-TO_DAT,
AGR_TEXT LIKE BAPIAGR-AGR_TEXT,
ORG_FLAG LIKE BAPIAGR-ORG_FLAG,
END OF TACTIVITYGROUPS.
* Table for recording already existent users
DATA: BEGIN OF USER_ALREADY_EXISTENT OCCURS 100,
ZUSER LIKE USR02-BNAME,
ZCLASS LIKE USR02-CLASS,
ZFIRSTNAME LIKE BAPIADDR3-FIRSTNAME,
ZLASTNAME LIKE BAPIADDR3-LASTNAME,
FLAG_LOCK TYPE C,
FLAG_PROF TYPE C,
FLAG_VALID TYPE C,
END OF USER_ALREADY_EXISTENT.
* Table for recording users from master system
DATA: BEGIN OF USER_MASTER_SYSTEM OCCURS 100,
USER LIKE USR02-BNAME,
CLASS LIKE USR02-CLASS,
FIRSTNAME LIKE BAPIADDR3-FIRSTNAME,
LASTNAME LIKE BAPIADDR3-LASTNAME,
FLAG_LOCK TYPE C,
FLAG_PROF TYPE C,
FLAG_VALID TYPE C,
END OF USER_MASTER_SYSTEM.
* Table for recording users created
DATA: BEGIN OF USER_CREATED OCCURS 100,
ZUSER LIKE USR02-BNAME,
MESSAGE LIKE BAPIRET2-MESSAGE,
END OF USER_CREATED.
* Table for setting old password
DATA: BEGIN OF USER_MOD OCCURS 100,
BNAME LIKE USR02-BNAME,
BCODE LIKE USR02-BCODE,
LTIME LIKE USR02-LTIME,
TRDAT LIKE USR02-TRDAT,
END OF USER_MOD.
DATA: USER_FIRSTNAME LIKE BAPIADDR3-FIRSTNAME,
USER_LASTNAME LIKE BAPIADDR3-LASTNAME.
* Table for recording users which could not be created
DATA: BEGIN OF USER_NOT_CREATED OCCURS 100,
ZUSER LIKE USR02-BNAME,
MESSAGE LIKE BAPIRET2-MESSAGE,
END OF USER_NOT_CREATED.
* Table for recording access to data source
DATA: BEGIN OF ACCESS_TAB OCCURS 100,
ZNUM(2) TYPE C,
ZDATA_SOURCE(50) TYPE C,
ZSTATUS(70) TYPE C,
END OF ACCESS_TAB.
data: z_type like bapiret2-type,
z_id like bapiret2-id,
z_number like bapiret2-number.
* Auxiliary fields
DATA: TABKEY LIKE INDX-SRTFD,
ZFILENAM LIKE LTRAN-PATH01.
DATA: START_WEEK LIKE SCAL-WEEK,
T_WEEK(7) TYPE C,
XYEAR_PAST TYPE I,
XYEAR_FUTU TYPE I,
WEEK_DAY TYPE C.
DATA: NOT_CREATED TYPE C,
NO_MASTER_USERS TYPE C,
FETCH TYPE C,
ZCLASS TYPE C.
DATA: TAB_LOG(60) TYPE C,
FILE_LOG(60) TYPE C.
DATA: STATUS_TAB TYPE C,
STATUS_FILE TYPE C,
STATUS_SEARCH TYPE C,
TOP_PAGE TYPE C.
DATA: XADDRESS LIKE BAPIADDR3,
USR03_ADDRESS LIKE USR03,
PARAMETER LIKE BAPIPARAM OCCURS 0 WITH HEADER LINE,
PROFILES LIKE BAPIPROF OCCURS 0 WITH HEADER LINE,
ACTIVITYGROUPS LIKE BAPIAGR OCCURS 0 WITH HEADER LINE,
RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE,
XUSR02 LIKE USR02 OCCURS 0 WITH HEADER LINE,
ZXIDES_USR02 LIKE USR02 OCCURS 0 WITH HEADER LINE.
DATA: ZCOUNT TYPE I,
ZCOUNT_LOCK TYPE I,
ZCOUNT_VALID TYPE I,
ZCOUNT_PROFILE TYPE I,
ZCOUNT_USER_CREATED TYPE I,
ZCOUNT_USER_NOT_CREATED TYPE I,
ZCOUNT_USER_ALREADY_EXISTANT TYPE I,
ZCOUNT_USER_FROM_MASTER_SYSTEM TYPE I,
ZCOUNT_TOTAL TYPE I,
Z_ACCESS_COUNTER TYPE I.
DATA: NO_SYSTEM TYPE C,
NO_AUTH TYPE C.
INCLUDE <LIST>.
* Screen properties
* Block 1
SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME TITLE TEXT-010.
PARAMETERS: XSYST LIKE SY-SYSID MODIF ID INT,
XMANDT LIKE T000-MANDT MODIF ID INT,
XWEEK(7) TYPE C MODIF ID INT,
OVERRULE AS CHECKBOX DEFAULT ' ',
XACCESS TYPE N DEFAULT '1' NO-DISPLAY.
SELECTION-SCREEN END OF BLOCK 1.
* Block 2
SELECTION-SCREEN BEGIN OF BLOCK 2 WITH FRAME TITLE TEXT-011.
PARAMETERS: XUSERTAB LIKE DD02L-TABNAME MODIF ID INT.
SELECTION-SCREEN SKIP 1.
PARAMETERS: XFILE01(25) TYPE C LOWER CASE NO-DISPLAY,
XZUSATZ(2) TYPE C NO-DISPLAY,
XFILENAM LIKE LTRAN-PATH01 MODIF ID INT NO-DISPLAY.
SELECTION-SCREEN END OF BLOCK 2.
* Block 3
SELECTION-SCREEN BEGIN OF BLOCK 3 WITH FRAME TITLE TEXT-020.
PARAMETERS: CLASS1 LIKE USGRP-USERGROUP NO-DISPLAY.
SELECT-OPTIONS: PROFN1 FOR USR10-PROFN NO INTERVALS NO-DISPLAY.
SELECTION-SCREEN SKIP 1.
PARAMETERS: CLASS2 LIKE USGRP-USERGROUP NO-DISPLAY.
SELECT-OPTIONS: PROFN2 FOR USR10-PROFN NO INTERVALS NO-DISPLAY.
SELECTION-SCREEN END OF BLOCK 3.
* Block 4
SELECTION-SCREEN BEGIN OF BLOCK 4 WITH FRAME TITLE TEXT-021.
PARAMETERS: XLOCK DEFAULT ' ' NO-DISPLAY,
XVALID DEFAULT ' ' NO-DISPLAY.
* Force release of local memory
CALL FUNCTION 'ADDR_MEMORY_CLEAR'
EXPORTING
FORCE = 'X'.
* Assign profiles to users
CHECK NOT_CREATED IS INITIAL.
PERFORM DETERMINE_PROFILES.
CALL FUNCTION 'BAPI_USER_PROFILES_ASSIGN'
EXPORTING
USERNAME = TUSER1(12)
TABLES
PROFILES = PROFILES
RETURN = RETURN.
IF RETURN-TYPE NE 'S'.
PERFORM APPEND_USER_CREATED.
ENDIF.
* Assign activity groups to users
PERFORM DETERMINE_ACTIVITYGROUPS.
CALL FUNCTION 'BAPI_USER_ACTGROUPS_ASSIGN'
EXPORTING
USERNAME = TUSER1(12)
TABLES
ACTIVITYGROUPS = ACTIVITYGROUPS
RETURN = RETURN.
IF RETURN-TYPE NE 'S'.
PERFORM APPEND_USER_CREATED.
ENDIF.
ENDLOOP.
* Change initial password to user password
LOOP AT USER_MOD.
SELECT SINGLE * FROM USR02 WHERE BNAME EQ USER_MOD-BNAME.
IF SY-SUBRC EQ 0.
USR02-BCODE = USER_MOD-BCODE.
USR02-LTIME = USER_MOD-LTIME.
USR02-TRDAT = USER_MOD-TRDAT.
MODIFY USR02.
ENDIF.
ENDLOOP.
ENDIF.
* Treatment users from master system
IF NO_MASTER_USERS IS INITIAL.
* Assign profiles to users from master system
ZCOUNT_PROFILE = 0.
IF NOT CLASS1 IS INITIAL.
ZCLASS = 1.
REFRESH PROFILES.
LOOP AT PROFN1.
PROFILES-BAPIPROF = PROFN1-LOW.
APPEND PROFILES.
ENDLOOP.
PERFORM ASSIGN_PROFILES.
ENDIF.
IF NOT CLASS2 IS INITIAL.
ZCLASS = 2.
REFRESH PROFILES.
LOOP AT PROFN2.
PROFILES-BAPIPROF = PROFN2-LOW.
APPEND PROFILES.
ENDLOOP.
PERFORM ASSIGN_PROFILES.
ENDIF.
* Unlock users from master system
IF XLOCK EQ 'X'.
ZCOUNT_LOCK = 0.
LOOP AT USER_MASTER_SYSTEM WHERE FLAG_LOCK EQ '1'.
CHECK: USER_MASTER_SYSTEM-USER NE 'SAP*',
USER_MASTER_SYSTEM-USER NE 'DEMO',
USER_MASTER_SYSTEM-USER NE 'TRAINING'.
IF ( SY-SYSID EQ 'IDT' OR
SY-SYSID EQ 'DI0' ).
CHECK USER_MASTER_SYSTEM-USER NE 'MUSTER'.
ENDIF.
SELECT SINGLE * FROM USR02 WHERE BNAME
EQ USER_MASTER_SYSTEM-USER.
USR02-UFLAG = '0'.
MODIFY USR02.
IF SY-SUBRC = 0.
USER_MASTER_SYSTEM-FLAG_LOCK = '0'.
MODIFY USER_MASTER_SYSTEM.
ZCOUNT_LOCK = ZCOUNT_LOCK + 1.
ENDIF.
ENDLOOP.
ENDIF.
* Delete validity period for users from master system
IF XVALID EQ 'X'.
ZCOUNT_VALID = 0.
LOOP AT USER_MASTER_SYSTEM WHERE FLAG_VALID EQ '1'.
SELECT SINGLE * FROM USR02 WHERE BNAME
EQ USER_MASTER_SYSTEM-USER.
USR02-GLTGV = '00000000'.
USR02-GLTGB = '00000000'.
MODIFY USR02.
IF SY-SUBRC = 0.
USER_MASTER_SYSTEM-FLAG_VALID = '0'.
MODIFY USER_MASTER_SYSTEM.
ZCOUNT_VALID = ZCOUNT_VALID + 1.
ENDIF.
ENDLOOP.
ENDIF.
ELSE.
MESSAGE I001 WITH TEXT-114.
ENDIF.
TOP-OF-PAGE.
IF TOP_PAGE EQ 1.
ULINE AT /7(75).
WRITE: /2 ICON_GREEN_LIGHT AS ICON,
7 TEXT-600 COLOR COL_HEADING INTENSIFIED OFF,
84(6) ZCOUNT_USER_CREATED COLOR COL_BACKGROUND,
92 TEXT-104 COLOR COL_BACKGROUND.
ULINE AT /7(75).
ENDIF.
IF TOP_PAGE EQ 2.
ULINE AT /7(75).
WRITE: /2 ICON_RED_LIGHT AS ICON,
7 TEXT-600 COLOR COL_HEADING INTENSIFIED OFF,
84(6) ZCOUNT_USER_NOT_CREATED COLOR COL_BACKGROUND,
92 TEXT-106 COLOR COL_BACKGROUND.
ULINE AT /7(75).
ENDIF.
IF TOP_PAGE EQ 3.
ULINE AT /7(75).
WRITE: /2 ICON_YELLOW_LIGHT AS ICON,
7 TEXT-600 COLOR COL_HEADING INTENSIFIED OFF,
84(6) ZCOUNT_USER_ALREADY_EXISTANT COLOR COL_BACKGROUND,
92 TEXT-103 COLOR COL_BACKGROUND.
ULINE AT /7(75).
ENDIF.
IF TOP_PAGE EQ 4.
ULINE AT /7(75).
WRITE: /2 ICON_GREEN_LIGHT AS ICON,
7 TEXT-610 COLOR COL_HEADING INTENSIFIED OFF,
84(6) ZCOUNT_USER_FROM_MASTER_SYSTEM COLOR COL_BACKGROUND,
92 TEXT-107 COLOR COL_BACKGROUND.
ULINE AT /7(75).
ENDIF.
*---------------------------------------------------------------------*
* FORM GET_DATA
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM GET_DATA.
Z_ACCESS_COUNTER = 0.
STATUS_SEARCH = 4.
DO.
IF Z_ACCESS_COUNTER GE XACCESS OR
STATUS_SEARCH = 0.
EXIT.
ENDIF.
IF Z_ACCESS_COUNTER GE '2'.
XFILENAM+29(2) = XFILENAM+29(2) - 1.
ENDIF.
PERFORM CONCATENATE_NAMES.
SELECT SINGLE * FROM ZIDESUSER WHERE
RELID EQ '10' AND
SRTFD EQ XFILENAM+29.
Z_ACCESS_COUNTER = Z_ACCESS_COUNTER + 1.
IF SY-SUBRC = 0.
* Cluster table contains searched key
TABKEY = XFILENAM+29.
PERFORM IMPORT_TABLES.
IF SY-SUBRC = 4.
* User tables could not be imported from cluster table
ACCESS_TAB-ZNUM = Z_ACCESS_COUNTER.
ACCESS_TAB-ZDATA_SOURCE = TAB_LOG.
ACCESS_TAB-ZSTATUS = TEXT-813.
APPEND ACCESS_TAB.
PERFORM GET_DATA_FROM_DATASET.
ELSE.
* User tables were imported
ACCESS_TAB-ZNUM = Z_ACCESS_COUNTER.
ACCESS_TAB-ZDATA_SOURCE = TAB_LOG.
ACCESS_TAB-ZSTATUS = TEXT-810.
APPEND ACCESS_TAB.
STATUS_SEARCH = '0'.
ENDIF.
ELSE.
* Cluster table does not contain searched key
ACCESS_TAB-ZNUM = Z_ACCESS_COUNTER.
ACCESS_TAB-ZDATA_SOURCE = TAB_LOG.
ACCESS_TAB-ZSTATUS = TEXT-812.
APPEND ACCESS_TAB.
PERFORM GET_DATA_FROM_DATASET.
ENDIF.
ENDDO.
ENDFORM.
*---------------------------------------------------------------------*
* FORM GET_DATA_FROM_DATASET *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM GET_DATA_FROM_DATASET.
* Get file
CHECK Z_ACCESS_COUNTER LT XACCESS.
OPEN DATASET XFILENAM.
Z_ACCESS_COUNTER = Z_ACCESS_COUNTER + 1.
IF SY-SUBRC <> 0.
ACCESS_TAB-ZNUM = Z_ACCESS_COUNTER.
ACCESS_TAB-ZDATA_SOURCE = FILE_LOG.
ACCESS_TAB-ZSTATUS = TEXT-812.
append access_tab.
* message i001 with text-601 xfilenam text-101.
* exit.
ELSE.
DO.
READ DATASET XFILENAM INTO XZIDESUSER.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
APPEND XZIDESUSER.
ENDDO.
* Fill ZIDESUSER
LOOP AT XZIDESUSER.
ZIDESUSER = XZIDESUSER.
MODIFY ZIDESUSER.
ENDLOOP.
COMMIT WORK.
TABKEY = XFILENAM+29.
PERFORM IMPORT_TABLES.
IF SY-SUBRC = 4.
* User tables could not be imported from cluster table
ACCESS_TAB-ZNUM = Z_ACCESS_COUNTER.
ACCESS_TAB-ZDATA_SOURCE = FILE_LOG.
ACCESS_TAB-ZSTATUS = TEXT-813.
APPEND ACCESS_TAB.
EXIT.
ELSE.
* User tables could be imported from cluster table
access_tab-znum = z_access_counter.
ACCESS_TAB-ZDATA_SOURCE = FILE_LOG.
access_tab-zstatus = text-810.
APPEND ACCESS_TAB.
STATUS_SEARCH = '0'.
ENDIF.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM IMPORT_TABLES *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM IMPORT_TABLES.
IMPORT
TUSER TLOGONDATA TDEFAULTS TADDRESS TCOMPANY
TPARAMETER TPROFILES TACTIVITYGROUPS
FROM DATABASE ZIDESUSER(10) ID TABKEY.
ENDFORM.
*---------------------------------------------------------------------*
* FORM ASSIGN_PROFILES *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM ASSIGN_PROFILES.
CASE ZCLASS.
WHEN '1'.
LOOP AT USER_MASTER_SYSTEM WHERE CLASS EQ CLASS1.
IF SY-SUBRC EQ 0.
PERFORM BAPI_USER_PROFILES_ASSIGN.
ENDIF.
ENDLOOP.
WHEN '2'.
LOOP AT USER_MASTER_SYSTEM WHERE CLASS EQ CLASS2.
IF SY-SUBRC EQ 0.
PERFORM BAPI_USER_PROFILES_ASSIGN.
ENDIF.
ENDLOOP.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form WRITE_HEADING
*&---------------------------------------------------------------------*
FORM WRITE_HEADING.
ULINE AT /5(110).
WRITE: /5 TEXT-800 COLOR COL_HEADING INVERSE.
ULINE AT /5(110).
SKIP 2.
* Log access
WRITE: /5 ICON_INFORMATION AS ICON,
14 TEXT-801 COLOR COL_HEADING INVERSE.
SKIP.
WRITE: /14 TEXT-802 COLOR COL_BACKGROUND.
ULINE AT /14(95).
LOOP AT ACCESS_TAB.
WRITE: /14 ACCESS_TAB-ZNUM COLOR COL_BACKGROUND INTENSIFIED OFF,
20 ACCESS_TAB-ZDATA_SOURCE COLOR
COL_BACKGROUND INTENSIFIED OFF,
70 ACCESS_TAB-ZSTATUS COLOR
COL_BACKGROUND INTENSIFIED OFF.
ENDLOOP.
SKIP 4.
* Log Users
WRITE: /5 ICON_INFORMATION AS ICON,
14 TEXT-803 COLOR COL_HEADING INVERSE.
SKIP.
WRITE: /14 TEXT-804 COLOR COL_BACKGROUND.
ULINE AT /14(95).
WRITE: /14 '1' COLOR COL_BACKGROUND INTENSIFIED OFF,
20 TEXT-605 COLOR COL_BACKGROUND INTENSIFIED OFF,
65 ZCOUNT_USER_CREATED COLOR COL_BACKGROUND INTENSIFIED OFF,
/14 '2' COLOR COL_BACKGROUND INTENSIFIED OFF,
20 TEXT-606 COLOR COL_BACKGROUND INTENSIFIED OFF,
65 ZCOUNT_USER_NOT_CREATED COLOR
COL_BACKGROUND INTENSIFIED OFF,
/14 '3' COLOR COL_BACKGROUND INTENSIFIED OFF,
20 TEXT-607 COLOR COL_BACKGROUND INTENSIFIED OFF,
65 ZCOUNT_USER_ALREADY_EXISTANT COLOR
COL_BACKGROUND INTENSIFIED OFF,
/14 '4' COLOR COL_BACKGROUND INTENSIFIED OFF,
20 TEXT-608 COLOR COL_BACKGROUND INTENSIFIED OFF,
65 ZCOUNT_USER_FROM_MASTER_SYSTEM COLOR
COL_BACKGROUND INTENSIFIED OFF.
WRITE: /20 TEXT-815 COLOR COL_NORMAL INVERSE,
38 TEXT-816 COLOR COL_NORMAL INVERSE,
65 ZCOUNT_LOCK COLOR COL_NORMAL INVERSE,
/38 TEXT-817 COLOR COL_NORMAL INVERSE,
65 ZCOUNT_PROFILE COLOR COL_NORMAL INVERSE,
/38 TEXT-818 COLOR COL_NORMAL INVERSE,
65 ZCOUNT_VALID COLOR COL_NORMAL INVERSE.
ULINE AT /68(8).
WRITE: /20 TEXT-609 COLOR COL_BACKGROUND,
65 ZCOUNT_TOTAL COLOR COL_BACKGROUND.
SKIP 5.
*---------------------------------------------------------------------*
* FORM WRITE_USER_ALREADY_EXISTENT *
*---------------------------------------------------------------------*
FORM WRITE_USER_ALREADY_EXISTENT.
READ TABLE USER_ALREADY_EXISTENT INDEX 1.
CHECK SY-SUBRC = 0.
TOP_PAGE = 3.
NEW-PAGE.
DELETE USER_ALREADY_EXISTENT WHERE ZUSER IS INITIAL.
SORT USER_ALREADY_EXISTENT ASCENDING.
LOOP AT USER_ALREADY_EXISTENT.
DETAIL.
WRITE: /7(6) SY-TABIX,
15(12) USER_ALREADY_EXISTENT-ZUSER,
29(11) USER_ALREADY_EXISTENT-ZFIRSTNAME,
42(25) USER_ALREADY_EXISTENT-ZLASTNAME.
ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
* FORM WRITE_USERS_FROM_MASTER_SYSTEM *
*---------------------------------------------------------------------*
FORM WRITE_USERS_MASTER_SYSTEM.
READ TABLE USER_MASTER_SYSTEM INDEX 1.
CHECK SY-SUBRC = 0.
TOP_PAGE = 4.
NEW-PAGE.
DELETE USER_MASTER_SYSTEM WHERE USER IS INITIAL.
SORT USER_MASTER_SYSTEM ASCENDING.
LOOP AT USER_MASTER_SYSTEM.
DETAIL.
WRITE: /7(6) SY-TABIX,
15(12) USER_MASTER_SYSTEM-USER,
29(11) USER_MASTER_SYSTEM-FIRSTNAME,
42(25) USER_MASTER_SYSTEM-LASTNAME.
CASE USER_MASTER_SYSTEM-FLAG_LOCK.
WHEN '0'.
WRITE: 69 ICON_UNLOCKED AS ICON.
WHEN '1'.
WRITE: 69 ICON_LOCKED AS ICON.
ENDCASE.
IF USER_MASTER_SYSTEM-FLAG_PROF EQ 'X'.
WRITE: 74 ICON_BOOKING_OK AS ICON.
ENDIF.
IF USER_MASTER_SYSTEM-FLAG_VALID EQ '0'.
WRITE: 79 ICON_DATE AS ICON.
ENDIF.
ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
* FORM CHECK_USER_EXISTANCE *
*---------------------------------------------------------------------*
FORM CHECK_USER_EXISTANCE.
CHECK STATUS_SEARCH = '0'.
ZCOUNT_USER_ALREADY_EXISTANT = 0.
LOOP AT TUSER.
* User exists already
SELECT SINGLE * FROM USR02
WHERE BNAME = TUSER-USERNAME.
* If so, check if user comes from master system
IF SY-SUBRC EQ 0.
READ TABLE USER_MASTER_SYSTEM WITH KEY USER = TUSER-USERNAME.
* Note if user DOES NOT come from master system
IF SY-SUBRC <> 0.
PERFORM FILL_USER_ALREADY_EXISTENT.
ENDIF.
ELSE.
PERFORM PREPARE_LIST_USERS_CREATE.
ENDIF.
ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
* FORM APPEND_USER_NOT_CREATED *
*---------------------------------------------------------------------*
FORM APPEND_USER_NOT_CREATED.
clear: z_type,
z_id,
z_number.
LOOP AT RETURN.
CHECK ( RETURN-TYPE NE Z_TYPE AND
RETURN-ID NE Z_ID AND
RETURN-NUMBER NE Z_NUMBER ).
USER_NOT_CREATED-ZUSER = TUSER1(12).
MOVE-CORRESPONDING RETURN TO USER_NOT_CREATED.
APPEND USER_NOT_CREATED.
Z_TYPE = RETURN-TYPE.
Z_ID = RETURN-ID.
Z_NUMBER = RETURN-NUMBER.
endloop.
ENDFORM.
*---------------------------------------------------------------------*
* FORM APPEND_USER_CREATED *
*---------------------------------------------------------------------*
FORM APPEND_USER_CREATED.
clear: z_type,
z_id,
z_number.
LOOP AT RETURN.
CHECK ( RETURN-TYPE NE Z_TYPE AND
RETURN-ID NE Z_ID AND
RETURN-NUMBER NE Z_NUMBER ).
USER_CREATED-ZUSER = TUSER1(12).
IF RETURN-TYPE NE 'S'.
MOVE-CORRESPONDING RETURN TO USER_CREATED.
ENDIF.
APPEND USER_CREATED.
Z_TYPE = RETURN-TYPE.
Z_ID = RETURN-ID.
Z_NUMBER = RETURN-NUMBER.
ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
* FORM APPEND_USER_MOD *
*---------------------------------------------------------------------*
FORM APPEND_USER_MOD.
USER_MOD-BNAME = TUSER1(12).
USER_MOD-BCODE = TUSER1-PASSWORD.
USER_MOD-LTIME = TLOGONDATA+59(6).
USER_MOD-TRDAT = TUSER1-TRDAT.
APPEND USER_MOD.
ENDFORM.
*---------------------------------------------------------------------*
* FORM DETERMINE_PARAMETER *
*---------------------------------------------------------------------*
FORM DETERMINE_PARAMETER.
REFRESH PARAMETER.
LOOP AT TPARAMETER WHERE USERNAME EQ TUSER1-USERNAME.
SELECT SINGLE * FROM TPARA WHERE PARAMID EQ TPARAMETER-PARID.
IF SY-SUBRC = 0.
MOVE-CORRESPONDING TPARAMETER TO PARAMETER.
APPEND PARAMETER.
ENDIF.
ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
* FORM DETERMINE_PROFILES *
*---------------------------------------------------------------------*
FORM DETERMINE_PROFILES.
REFRESH PROFILES.
LOOP AT TPROFILES WHERE USERNAME EQ TUSER1-USERNAME.
MOVE-CORRESPONDING TPROFILES TO PROFILES.
APPEND PROFILES.
ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
* FORM DETERMINE_ACTIVITYGROUPS *
*---------------------------------------------------------------------*
FORM DETERMINE_ACTIVITYGROUPS.
REFRESH ACTIVITYGROUPS.
LOOP AT TACTIVITYGROUPS WHERE USERNAME EQ TUSER1-USERNAME.
MOVE-CORRESPONDING TACTIVITYGROUPS TO ACTIVITYGROUPS.
APPEND ACTIVITYGROUPS.
ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
* FORM FILL_USER_ALREADY_EXISTENT *
*---------------------------------------------------------------------*
FORM FILL_USER_ALREADY_EXISTENT.
*---------------------------------------------------------------------*
* FORM PREPARE_LIST_USERS_CREATE *
*---------------------------------------------------------------------*
FORM PREPARE_LIST_USERS_CREATE.
MOVE-CORRESPONDING TUSER TO TUSER1.
APPEND TUSER1.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FETCH_NAME
*&---------------------------------------------------------------------*
FORM FETCH_NAME.
CASE FETCH.
WHEN '+'.
READ TABLE TADDRESS WITH KEY USERNAME = USER_CREATED-ZUSER.
WHEN '-'.
READ TABLE TADDRESS WITH KEY USERNAME = USER_NOT_CREATED-ZUSER.
ENDCASE.
IF TADDRESS+62(40) IS INITIAL.
USER_FIRSTNAME = TEXT-500.
ELSE.
USER_FIRSTNAME = TADDRESS+62.
ENDIF.
USER_LASTNAME = TADDRESS+102.
ENDFORM.
*----------------------------------------------------------------------*
* Form CREATE_FILE_NAME
*----------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM CONCATENATE_FILE_NAME.
IF NOT XFILE01 IS INITIAL.
CONCATENATE XFILE01 ZFILENAM INTO XFILENAM.
IF XZUSATZ NE ' '.
CONCATENATE XFILENAM '-' XZUSATZ INTO XFILENAM.
ENDIF.
ELSE.
XFILENAM = ' '.
ENDIF.
ENDFORM.
*----------------------------------------------------------------------*
* Form CHECK_WEEK
*----------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM CHECK_WEEK.
XYEAR_PAST = START_WEEK(4).
XYEAR_PAST = XYEAR_PAST - 1.
XYEAR_FUTU = XYEAR_PAST + 2.
IF XWEEK IS INITIAL.
PERFORM GET_WEEK.
ELSE.
IF XWEEK(2) CN '0123456789' OR XWEEK(2) GT '52' OR XWEEK(2) EQ '00'.
MESSAGE E001 WITH TEXT-113.
ENDIF.
IF XWEEK+2(1) NE '.'.
MESSAGE E001 WITH TEXT-112.
ENDIF.
IF XWEEK+3(4) CN '0123456789' OR XWEEK+3(4) LT XYEAR_PAST OR
XWEEK+3(4) GT XYEAR_FUTU.
MESSAGE E001 WITH TEXT-113.
ENDIF.
ENDIF.
ENDFORM.
*----------------------------------------------------------------------*
* Form GET_WEEK_INFO
*----------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Form CHECK_BLOCK_2
*---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM CHECK_BLOCK_2.
IF XFILE01 IS INITIAL.
XFILE01 = 'D:\usr\sap\trans\bin\'.
MODIFY SCREEN.
ENDIF.
PERFORM CONCATENATE_FILE_SUFFIX.
PERFORM CONCATENATE_FILE_NAME.
ENDFORM.
*----------------------------------------------------------------------*
* Form CHECK_BLOCK_3
*----------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM CHECK_BLOCK_3.
IF NOT CLASS1 IS INITIAL.
SELECT SINGLE * FROM USGRP WHERE USERGROUP EQ CLASS1.
IF SY-SUBRC <> 0.
MESSAGE E001 WITH TEXT-110.
ENDIF.
ENDIF.
* Check profiles for group 1
IF NOT PROFN1-LOW IS INITIAL.
SELECT SINGLE * FROM USR10 WHERE PROFN EQ PROFN1-LOW.
IF SY-SUBRC <> 0.
MESSAGE E001 WITH TEXT-111.
ENDIF.
ENDIF.
* Check group 2
IF NOT CLASS2 IS INITIAL.
SELECT SINGLE * FROM USGRP WHERE USERGROUP EQ CLASS2.
IF SY-SUBRC <> 0.
MESSAGE E001 WITH TEXT-110.
ENDIF.
ENDIF.
* Check profiles for group 2
IF NOT PROFN2-LOW IS INITIAL.
SELECT SINGLE * FROM USR10 WHERE PROFN EQ PROFN2-LOW.
IF SY-SUBRC <> 0.
MESSAGE E001 WITH TEXT-111.
ENDIF.
ENDIF.
* Check groups are not the same
IF NOT ( CLASS1 IS INITIAL OR CLASS2 IS INITIAL ).
IF CLASS1 EQ CLASS2.
MESSAGE E001 WITH TEXT-120.
ENDIF.
ENDIF.
* Check group/profile consistency
IF ( NOT CLASS1 IS INITIAL AND PROFN1-LOW IS INITIAL ).
MESSAGE E001 WITH TEXT-121 CLASS1.
ENDIF.
IF ( NOT CLASS2 IS INITIAL AND PROFN2-LOW IS INITIAL ).
MESSAGE E001 WITH TEXT-121 CLASS2.
ENDIF.
IF ( NOT PROFN1-LOW IS INITIAL AND CLASS1 IS INITIAL ).
MESSAGE E001 WITH TEXT-122 PROFN1-LOW.
ENDIF.
IF ( NOT PROFN2-LOW IS INITIAL AND CLASS2 IS INITIAL ).
MESSAGE E001 WITH TEXT-122 PROFN1-LOW.
ENDIF.
ENDFORM.
*----------------------------------------------------------------------*
* Form GET_WEEK
*----------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GET_WEEK.
*--- Determine current week
call function 'DATE_GET_WEEK'
exporting
DATE = SY-DATUM
importing
WEEK = START_WEEK
exceptions
date_invalid = 01.
*--- Determine current day
CALL FUNCTION 'DATE_COMPUTE_DAY'
EXPORTING
DATE = SY-DATUM
IMPORTING
DAY = WEEK_DAY.
*---- Check if day is working day and overwrite week if necessary
* if ( week_day ne 6 and
* week_day ne 7 ).
* xweek(2) = ( start_week+4(2) - 1 ).
*
* endif.
ENDFORM.
*
*----------------------------------------------------------------------*
* Form GET_USERS_MASTER_SYSTEM
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM GET_USERS_MASTER_SYSTEM.
ZCOUNT_USER_FROM_MASTER_SYSTEM = 0.
* Determine master users
SELECT * FROM ZIDES_USR02 INTO TABLE ZXIDES_USR02.
IF SY-SUBRC = 0.
* Prepare master users for treatment
SELECT * FROM USR02 INTO TABLE XUSR02
FOR ALL ENTRIES IN ZXIDES_USR02
WHERE BNAME EQ ZXIDES_USR02-BNAME.
IF SY-SUBRC EQ 0.
LOOP AT XUSR02.
CLEAR USER_MASTER_SYSTEM.
PERFORM FETCH_ADDRESS_DATA.
USER_MASTER_SYSTEM-USER = XUSR02-BNAME.
USER_MASTER_SYSTEM-CLASS = XUSR02-CLASS.
IF USR03_ADDRESS-NAME1 IS INITIAL.
USER_MASTER_SYSTEM-FIRSTNAME = TEXT-500.
ELSE.
USER_MASTER_SYSTEM-FIRSTNAME = USR03_ADDRESS-NAME1.
ENDIF.
USER_MASTER_SYSTEM-LASTNAME = USR03_ADDRESS-NAME2.
IF XUSR02-UFLAG = '64'.
USER_MASTER_SYSTEM-FLAG_LOCK = '1'.
ENDIF.
IF NOT XUSR02-GLTGB IS INITIAL AND ( XUSR02-CLASS NE 'DEMO' AND
XUSR02-CLASS NE 'ESSUSER' ).
USER_MASTER_SYSTEM-FLAG_VALID = '1'.
ENDIF.
APPEND USER_MASTER_SYSTEM.
ZCOUNT_USER_FROM_MASTER_SYSTEM = ZCOUNT_USER_FROM_MASTER_SYSTEM + 1.
ENDLOOP.
ELSE.
NO_MASTER_USERS = 'X'.
ENDIF.
ELSE.
NO_MASTER_USERS = 'X'.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FETCH_ADDRESS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM FETCH_ADDRESS_DATA.
*---------------------------------------------------------------------*
* FORM CONCATENATE_NAMES *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM CONCATENATE_NAMES.
CONCATENATE TEXT-603 XUSERTAB '(' '10' '/' XFILENAM+29 ')'
INTO TAB_LOG SEPARATED BY SPACE.
CONCATENATE TEXT-601 XFILENAM
INTO FILE_LOG SEPARATED BY SPACE.
ENDFORM.
*----------------------------------------------------------------------*
* Form CHECK_SYSTEM
*----------------------------------------------------------------------*
FORM CHECK_SYSTEM.
* --- Check if system is target system, and if so, continue.
*
IF ( SY-SYSID NE 'IDT' AND
SY-SYSID NE 'DIP' AND
SY-SYSID NE 'DII' AND
SY-SYSID NE 'DI0' ).
MESSAGE I001 WITH TEXT-001.
NO_SYSTEM = 'X'.
EXIT.
ENDIF.
ENDFORM.
*----------------------------------------------------------------------*
* Form CHECK_AUTHORITY
*----------------------------------------------------------------------*
FORM CHECK_AUTHORITY.
AUTHORITY-CHECK OBJECT 'S_USER_AUT'
ID 'OBJECT' FIELD '*'
ID 'AUTH ' FIELD '*'
ID 'ACTVT ' FIELD '*'.
IF SY-SUBRC NE 0.
MESSAGE I001(CJ) WITH TEXT-100.
NO_AUTH = 'X'.
EXIT.
ENDIF.
ENDFORM.
*----------------------------------------------------------------------*
* Form CLEAN_UP_BEFORE_CREATE
*----------------------------------------------------------------------*
FORM CLEAN_UP_BEFORE_CREATE.
* User group does not exist in target system
IF NOT TLOGONDATA+29(12) IS INITIAL.
SELECT SINGLE * FROM USGRP WHERE USERGROUP EQ TLOGONDATA+29(12).
IF SY-SUBRC <> 0.
TLOGONDATA+29(12) = ' '.
ENDIF.
ENDIF.
* User printer does not exist in target system
IF NOT TDEFAULTS+32(4) IS INITIAL.
SELECT SINGLE * FROM TSP03 WHERE PADEST EQ TDEFAULTS+32(4).
IF SY-SUBRC <> 0.
TDEFAULTS+32(4) = ' '.
ENDIF.
ENDIF.
* User default language does not exist in target system
IF NOT TDEFAULTS+41(1) IS INITIAL.
SELECT SINGLE * FROM T002C WHERE SPRAS EQ TDEFAULTS+41(1).
IF SY-SUBRC <> 0.
TDEFAULTS+41(1) = 'E'.
ENDIF.
ENDIF.
ENDFORM.
*Text elements
*----------------------------------------------------------
* 001 Программу нельзя выполнить в этой системе!
* 010 Общие параметры
* 011 Источник данных
* 020 Доп. полномочия пользоват. из основной системы
* 021 Изменения пользоват. из осн. системы
* 100 Вы не имеете полномочий на эту программу!
* 101 не существует
* 103 <- уже существует
* 104 <- создано
* 105 Данные не удалось импортировать
* 106 <- не создано
* 107 <- из основной системы
* 109 Данные отсутствуют:
* 110 Группа пользователей отсутствует!
* 111 Профиль полномочий отсутствует!
* 112 Проверить формат!
* 113 Проверьте введенные данные!
* 114 Пользователи из основной системы отсутствуют
* 115 Постобработка пользоват. из основной системы
* 120 Группы пользователей должны быть разными!
* 121 Ввести профиль полномочий ->
* 122 Ввести группу пользоват. ->
* 500 Нет
* 600 Ткщ№ Пользоват. Имя Фамилия
* 601 Файл
* 602 <- Всего пользов.
* 603 Таблица
* 604 Польз. выкл.
* 605 Создано заново
* 606 Не создано
* 607 Уже имеется
* 608 Из осн. системы
* 609 Общий
* 610 Ткщ№ Пользов. Имя Фамилия Блк Прф Дат
* 800 Ж У Р Н А Л
* 801 Доступы
* 802 № ИсточнДанн Статус
* 803 Пользов.
* 804 № Тип Число
* 810 Данные успешно импортированы
* 812 Данные не найдены.
* 813 Данные не импортированы
* 814 Не выполнено
* 815 из них
* 816 Блокировка отменена
* 817 Профили расширены
* 818 Срок действия продлен
*Selection texts
*----------------------------------------------------------
* CLASS1 Группа пользователей 1
* CLASS2 Группа пользователей 2
* OVERRULE Станд. значения при конфликте
* PROFN1 Профиль полномочий - группа 1
* PROFN2 Профиль полномочий - группа 1
* XFILE01 Каталог
* XFILENAM Имя файла
* XLOCK Разблокировать блокир. польз.
* XMANDT Мандант
* XSYST ИД системы
* XUSERTAB Таблица
* XVALID Отменить дату "Действит. по"
* XWEEK Пользоват. из календ. недели
* XZUSATZ Дополнительный ид.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.