This website is not affiliated with, sponsored by, or approved by SAP AG.

MS Excel VBA Code for BAP_USER_CHANGE

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

MS Excel VBA Code for BAP_USER_CHANGE

Postby seancoles » Tue Jan 31, 2017 7:00 pm

Hi Fans,

I am trying to call BAPI_USER_LOCK & BAPI_USER_CHANGE in EXCEL VBA.

the purpose is to
1) Lock the User
2) Deactivate password
3) Change user group
4) Change Validity Date

BAPI_USER_LOCK works fine but BAPI_USER_CHANGE is getting stuck:

please review and suggest change:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sub User_Change()
'Created for changing User Lock, Validity Date, User Group

Dim sap As Object
Set sap = CreateObject("SAP.Functions")

Dim ws_MAIN As Worksheet
Set ws_MAIN = Worksheets("Logon")

'Define Logon
sap.Connection.user = ws_MAIN.Cells(2, 2)
sap.Connection.Password = ws_MAIN.Cells(3, 2)
sap.Connection.client = ws_MAIN.Cells(4, 2)
sap.Connection.applicationserver = ws_MAIN.Cells(5, 2)
sap.Connection.systemnumber = ws_MAIN.Cells(6, 2)
sap.Connection.Language = ws_MAIN.Cells(7, 2)
sap.Connection.saprouter = ""

If sap.Connection.logon(0, True) <> True Then
MsgBox ("Logon not successful")
Exit Sub
Else
' MsgBox ("Logon successful")
End If

'---------------------------------------------------------
'Define the user
UserId = ws_MAIN.Cells(2, 3)
'MsgBox ("" & UserId & "")
'---------------------------------------------------------
'Call Function Module - Lock User
Set rfc = sap.Add("BAPI_USER_LOCK")
rfc.Exports("USERNAME") = "" & UserId & ""
'---------------------------------------------------------
'Call Function Module
Set rfc = sap.Add("BAPI_USER_CHANGE")
rfc.Exports("USERNAME") = "" & UserId & ""
rfc.Exports("LOGONDATA-CLASS") = "''TERMINATED'" >>>>>ERROR = TYPE MISMATCH <<<<<<<<<<
rfc.Exports("LOGONDATAX-CLASS") = "X"

If rfc.Call() = True Then
MsgBox ("RFC Call Successful")
Else
MsgBox ("Error")
End If

End Sub
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------


If I try a different code for LOGONDATA
'---------------------------------------------------------
'Call Function Module
Set rfc = sap.Add("BAPI_USER_CHANGE")
rfc.Exports("USERNAME") = "" & UserId & ""
rfc.Exports("LOGONDATA") = "''TERMINATED'" >>>>>ERROR = Structure member not found "TERMINATED" <<<<<<<<<<
rfc.Exports("LOGONDATAX") = "X"

I have tried different values for LOGONDATA but error stays the same
rfc.Exports("LOGONDATA") = "''00/00/0000 00/00/0000 TERMINATED'" >>>>>ERROR = Structure member not found <<<<<<<<<<
----------------------------------------
seancoles
 
Posts: 1
Joined: Tue Jan 31, 2017 6:35 pm

Return to ABAP

Who is online

Users browsing this forum: Google [Bot] and 11 guests





loading...


This website is not affiliated with, sponsored by, or approved by SAP AG.