Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

JCO adding role to user with BAPI_USER_ACTGROUPS_ASSIGN

Former Member
0 Likes
1,131

I'm using JCo to create a user and then add a role to that new user.

I'm guessing I can use BAPI_USER_ACTGROUPS_ASSIGN to do the role assignment part. But I'm not sure how this works.

I have something like this:

JCoFunction roleAssign = connect.getFunction("BAPI_USER_ACTGROUPS_ASSIGN");

JCoParameterList user_info = roleAssign.getImportParameterList();

roleAssign.getImportParameterList().setValue( "USERNAME", "user1");

I can see that PARAMETERS 'INPUT' only takes 1 value for USERNAME, so how do I pass in the ACTIVITYGROUPS table like the documentation seem to suggest?

thanks

I'm using JCo to create a user and then add a role to that new user.

I'm guessing I can use BAPI_USER_ACTGROUPS_ASSIGN to do the role assignment part. But I'm not sure how this works.

I have something like this:

JCoFunction roleAssign = connect.getFunction("BAPI_USER_ACTGROUPS_ASSIGN");

JCoParameterList user_info = roleAssign.getImportParameterList();

roleAssign.getImportParameterList().setValue( "USERNAME", "user1");

I can see that PARAMETERS 'INPUT' only takes 1 value for USERNAME, so how do I pass in the ACTIVITYGROUPS table like the documentation seem to suggest?

thanks

6 REPLIES 6
Read only

Former Member
0 Likes
1,000

anyone?

Read only

0 Likes
1,000

Hi,

-Read tables with RFC_READ_TABLE----


Dim i, j As Integer

'-Get repository instance----


Dim repos As JCoRepository

Set repos = dest.getRepository()

'-Define function----


Dim func As JCoFunction

Set func = repos.getFunction("RFC_READ_TABLE")

'-Set arguments for function----


func.getImportParameterList().setValue("QUERY_TABLE", "SFLIGHT")

func.getImportParameterList().setValue("DELIMITER", "~")

'-Execute function----


com#sap#conn#jco#JCoContext.begin(dest)

func.execute(dest)

com#sap#conn#jco#JCoContext.end(dest)

'-Get field names----


Dim fields As JCoTable

Set fields = func.getTableParameterList().getTable("FIELDS")

Dim fcnt As Integer

fcnt = fields.getNumRows() - 1

'-Set field names as header in the grid----


For i = 0 To fcnt

fields.setRow(i)

Form1.Grid.Header(i) = fields.getString("FIELDNAME")

Form1.Grid.Refresh

Next

'-Get table content----


Dim table As JCoTable

Set table = func.getTableParameterList().getTable("DATA")

Dim cnt As Integer

cnt = table.getNumRows()

Dim felder(0 To fcnt) As String

'-Set table in the grid----


For i = 0 To cnt - 1

table.setRow(i)

felder = table.getString("WA").split("~")

For j = 0 To fcnt - 1

Form1.Grid.TextMatrix(i, j) = felder(j)

Next

Next

http://www.vogella.de/articles/SAPJCo/article.html

Check there are some links available.

Regards,

Madhu.

Read only

0 Likes
1,000

Sorry but I'm not sure why reading in some fileds in the SFLIGHT table would help me solve my problem? I'm asking about how to use JCo to add a role to my user.

The link you provided is what got me started. It doesn't contain the answer to my question either.

Read only

0 Likes
1,000

>

> Sorry but I'm not sure why reading in some fileds in the SFLIGHT table would help me solve my problem? I'm asking about how to use JCo to add a role to my user.

>

> The link you provided is what got me started. It doesn't contain the answer to my question either.

He has provided a sample code for another RFC call RFC_READ_TABLE which has got a table parameter 'FIELDS' just like your BAPI BAPI_USER_ACTGROUPS_ASSIGN has got a table parameter ACTIVITYGROUPS.. I presume, He has shown how it must be filled for a sample RFC and you can probably use that as a basis... I assume that you are familiar with jco tables and know how to fill those tables.. If not check out the links below,

ACTIVITY groups table has following fields AGR_NAME , FROM_DAT and TO_DAT which must be filled.

Also you can google and see if there are sample code for filling in the JCO table and calling a BAPI (i saw a example for BAPI_MATERIAL_GETLIST)

http://www.google.com/search?q=jcotableexample&hl=en&source=hp&aq=f&aqi=&aql=&oq=

SAP help,

http://help.sap.com/saphelp_nw04/helpdata/en/d2/561106b8b3bc449f890cddfdc8d3e2/frameset.htm

Read only

0 Likes
1,000

thanks Kris, the explanation you gave helped me understand it more.

The problem was that after using:

getImportParameterList().setValue( "USERNAME", myUser)

to set the user name, I have to use:

getTableParameterList().getTable("ACTIVITYGROUPS").appendRow() 
getTableParameterList().getTable("ACTIVITYGROUPS").setValue("AGR_NAME", myRole)

to set the user role.

I was trying to do something like:

getImportParameterList().getStructure("ACTIVITYGROUPS")

and that obviously did not work.

Read only

0 Likes
1,000

You are welcome...