1

I was able to write the code to get the details from SAP thru BAPI_USER_GET_DETAIL, here is attached code to get the email from SAP backend:

import pyrfc
from pyrfc import Connection
setup= pyrfc.Connection(user=X , passwd=Y , mshost=Z , sysid=A , client=B , msserv= C , group=D )
result=setup.call(BAPI_USER_GET_DETAIL, USERNAME=abc)
print (result['ADDRESS']['E_MAIL'])

Expected Result: abc@xyz.com

I am in need to update email address for particular user in SAP, after researching found that by using BAPI_USER_CHANGE we can update new mail address but tried many times with no luck!

Can anyone please help in getting the correct syntax to run BAPI_USER_CHANGE in Python?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Sapta619
  • 9
  • 7

2 Answers2

0

For any "Update BAPI" you need to call BAPI_TRANSACTION_COMMIT right after your BAPI call in order to actually commit the changes to the database.

Make sure the BAPI_TRANSACTION_COMMIT is executed on the same "connection", because it needs to run in the same backend user session.

Lanzelot
  • 15,976
  • 4
  • 18
  • 14
0

First of all, your get BAPI is also a bit of incorrect, maybe on old versions of PyRFC it worked but now pyrfc module has Connection object, not connection and your code throws compilation error. It should be as follows:

import pyrfc
from pyrfc import Connection
RIS=pyrfc.Connection(user='USER', passwd='pw', ashost='hostey.com', sysid='KEK', sysnr='00', client='200', lang='EN', trace='3')
result=RIS.call("BAPI_USER_GET_DETAIL", USERNAME='MUELLER')
print(result['ADDRESS']['FULLNAME'])

Secondly, change BAPI is called the same as get BAPI, for me this code worked

ADDR = { "E_MAIL": 'wazawaza@mail.com'}
ADDX = { "E_MAIL": 'X'}
changed=RIS.call("BAPI_USER_CHANGE", USERNAME='MUELLER', ADDRESS=ADDR, ADDRESSX=ADDX)
print(changed["RETURN"])

it should show you smth like this output if executed correctly

[{'TYPE': 'S', 'ID': '01', 'NUMBER': '039', 'MESSAGE': 'User MUELLER has changed', 'LOG_NO': '', 'LOG_MSG_NO': '000000', 'MESSAGE_V1': 'MUELLER', 'MESSAGE_V2': '', 'MESSAGE_V3': '', 'MESSAGE_V4': '', 'PARAMETER': '', 'ROW': 0, 'FIELD': 'BNAME', 'SYSTEM': 'T90CLNT090'}]

Weirdly new email does not showed neither with BAPI call nor in SE37, but perfectly showed in SU01.

enter image description here

I thinks this is because of the long char field in BAPI structure which prevents it from showing correctly. Maybe this was the reason why you considered your call unsuccessful?

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
  • Thanks @Suncatcher for your update, I was somehow able to get my code work like the way you said but getting this error in return: "You are not authorized to change users in group" although I am passing only one user in my code. Any thoughts regarding this ? – Sapta619 Apr 02 '20 at 15:51
  • Simple authorization issue, it has nothing to do with mass changes. You have no rights to group in which user resides. You need authorization S_USER_GRP with ACTVT = 02. – Suncatcher Apr 02 '20 at 17:01