-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPySAPUserCreate.py
More file actions
44 lines (35 loc) · 1.34 KB
/
PySAPUserCreate.py
File metadata and controls
44 lines (35 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import csv
from ConfigParser import ConfigParser
from sapnwrfc2 import *
def userAdd(sapconn,userName,initPass,userType,firstName,lastName):
try:
passwordStruct = {u'BAPIPWD':initPass}
impStruct = {u'FIRSTNAME':firstName,u'LASTNAME':lastName}
logonStruct = {u'USTYP':userType}
result = sapconn.call('BAPI_USER_CREATE1',
USERNAME=userName,
PASSWORD=passwordStruct,
LOGONDATA=logonStruct,
ADDRESS=impStruct)
print(result['RETURN'][0]['MESSAGE'])
except:
print('Error Occurred in ' + userAdd.__name__ )
raise
def getConnectionInfo():
try:
config = ConfigParser()
config.read("sapnwrfc.cfg")
return config._sections["connection"]
except:
print('Error Occurred in ' + getConnectionInfo.__name__)
raise
if __name__ == '__main__':
try:
connecitonInfo = getConnectionInfo()
csvReader = csv.reader(open('userinfo.csv'),delimiter=',')
sapconn = Connection(**connecitonInfo)
for username,initpass,usertype,firstname,lastname in csvReader:
userAdd(sapconn,username,initpass,usertype,firstname,lastname)
finally:
print('connection close')
sapconn.close()