ravi_mehta
30th March 2009, 09:05
HI All,

I am trying to get the all User Role by standard dll function get.user.role() My code is as follow:

#pragma used dll ottdllams_print

domain ttaad.user i.user
long ret
string roles(10,10) fixed

ret = switch.to.company(0)
i.user = "rkumar"
ret = get.user.roles(i.user, roles)
ret = switch.to.company(90)

In the Above code there is no compilation error, But at the time of run the script is getting hanged at the line where i m calling the function. Is my argument of the function is wrong. I tried this function with roles(,) but getting the compilation error.

george7a
30th March 2009, 11:47
Hi,

Here is the documentation in our LNfunction extern long get.user.roles(
domain ttaad.user i.user,
ref string roles(,) fixed )

Desc
This function return all roles defined for a specific user,
including sub-roles.
Input
i.user User
Output
Array of roles and subroles (contains no duplicates)
Pre
Switch to company 000 should be done before executing this
function.
Return
Number of roles linked to the user will be returned.
If unknown user, value -1 will be returned.

You should check:

1) If you have switched to company (http://www.baanboard.com/programmers_manual_baanerp_help_functions_company_operations_switch_to_company) 0 successfully by checking its return value. It should equal 1.
2) Where exactly does the code hang through debug.

I hope it helps,

- George

ravi_mehta
30th March 2009, 13:17
Hi George,

Thanks for the Documentation.

1) ret = switch.to.company(0) : I am getting the ret = 1 after this i am also checking the changed company by get.compnr() which is returning me value 0. so problem is not here.

2) When I am Running the script in debug mode the system is getting hang at ret = get.user.roles(i.user, roles) line.

regards
ravi

toolswizard
30th March 2009, 19:29
I have two suggestions.

First if you are using the debugger and using "step" sometimes you have to step several times on the function line before it will come back. Sometimes it will be many steps, so many that you really want to do a break on the line immediately following the function and then go until break.

Second, check the i.user field. In the past I have found where the user is left justified in one table and right justified in the other and you can not find the user role because of this.

NPRao
30th March 2009, 20:10
Ravi,
I tested this code and it works.
#pragma used dll ottdllams_print
string roles(1, 1) based
e = switch.to.company(0)
e = get.user.roles(logname$, roles)
e = get.user.roles("bsp200s", roles)
The issue is with your variable declaration - string roles(10,10) fixed
When I used that declaration in my program aborted and the bshell got disconnected.
Also, the length of the roles domain (ttams.crol) is 13.

ravi_mehta
31st March 2009, 07:52
Thanks all for the information.

As suggested by the NPRao I changed my Declaration of String from fixed to based. And Now Function is working fine.

I am still confuse why the function is not taking the fixed string according to the given manual.In help Doc of Ln also they suggest to use fixed variable instead of Based.Can anyone give me with example where to use based & fixed.

Marioth
2nd April 2009, 14:08
Hi Ravi,

This is what I found in the manual. Hopes it helps.

Regards,

Mario

Fixed and based variables
Fixed variables

A string variable can be declared as fixed so that its current length always equals the maximum length. For example:

STRING name(10) FIXED
name = "andrew" | the string is always filled up with
spaces
The keyword FIXED is applicable to one-dimensional strings only. Multi-dimensional string arrays are always fixed and do not need to be declared with the keyword FIXED.

Based variables

The BASED mechanism is applicable to strings or arrays of all possible types. It determines that a variable will be based on another variable. For based variables, no memory space is reserved when they are declared. At runtime they use the same memory space as the variable on which they are based. So by using this mechanism, the same section of memory can be accessed via different names.

You use the following construction to base one variable on another: BASE var_1 AT var_2

In the case of a string, the based variable is always fixed. You must ensure that the based variable always fits in the variable on which it is based. So it will be safe to declare the basic variable as FIXED.

Example

STRING a(10) FIXED
STRING b(5) BASED
BASE b AT a(3) | This indicates that the space
occupied
| by b is the same
as the space for a(3;5)
b(2;3) = "yes" | a(4;3) now also contains "yes"
a(1;8) = "12345678" | b now contains "34567"
Variable and fixed length strings

The following points summarize the rules for variable and fixed length strings:

Strings with variable length are 1-dimensional strings not declared as based or fixed. All other strings are fixed- that is, database table fields, string arrays, and variables declared as FIXED or BASED.
Normally, variable length strings are not filled up with spaces except when a start position is specified in the assignment.
Fixed length strings are always filled up with spaces, except when a length is specified. In the latter case, the remaining positions are not overwritten by spaces.
If a string (of variable or fixed length) is filled from a certain start position, the part of that string preceding the start position is filled up with spaces if it was not filled before.