Application Development 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: 

Change of System variable sy-uname during the program execution

Former Member
0 Kudos

Hi,

I wanted some help, if it is possible to change value of sy-uname during the program execution.

I am mentioning the flow of the execution as follows.

Step 1. Intially sy-uname is having the value of the login user, for example say 'user1'.

Step 2. I want to set the sy-uname to 'user2' and after that i call a function or a method. The system should take the sy-uname as 'user2' for executing the function or method.

Step 3. Once the control comes back from the function or method call the sy-uname should be set to the logged in user.

Regards,

Om

13 REPLIES 13

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You can change it, but when the next statement is executed it will again be overwritten with the currently logged in user id. You must pass a variable to your function module holding the value for user2. This will not work for you because your function module is using SY-UNAME in the code, right? Is it a standard function module?

Regards,

Rich Heilman

0 Kudos

Hi,

I am unable to make changes to the function module as it is a standard function module used almost at the basis level. It is used in the ACO package.

Is there any work around possible which would help me to change the sy-uname before the call to the function module/method and reset it back after the call.

Regards,

Om

0 Kudos

Hi Savita!

When you have a remote function call to a different system, you can define a fixed user (+PW) in SM59 to the connection.

Probably it's not possible to make a RFC to same client <i>and</i> using the logon (it's like destination none), but you could try to call a second client and make a second RFC back to original system.

But this will bring you only one fixed user in your documents - I guess you want to have several 'user2' values.

Normally correct user is logged for actions - and if you have a batch or interface user, then this is the correct user. An user of an original document is not responsible for automatic creations later.

Check, if later displays (or reports) a search for original user could be enough -> no system (variable) changes would be needed.

Regards,

Christian

0 Kudos

Hi,

Changing the value of the system variable sy-uname needs to be done dynamically during execution of the report program. The value of the sy-uname needs to be set from an internal table. But after the call to the FM or method the sy-uname has to be reset back to the sy-uname of the user which is logged in to the system.

I found out that even if i execute the report program in the debug mode, the sy-uname value changes from the value it was set before the call to the FM/method.

Can we have some work around for doing this.

Going by the RFC user concept would lead to performance issues.

Regards,

Om

0 Kudos

Imagine the security risk if you could dynamically switch to any user you wanted without tracking. You could write a program that could act as anyone in your company.

The closest you can come to this is in the web environment. For a ITS/BSP application you can start with an anonymous user and then switch to a more specific one. Kind of like when you browse a catalog, but then when you go to order you must login. This is all done via the function module SUSR_INTERNET_USERSWITCH. However it is very restrictive in what it allows (only switching from a service user type). I doubt it would work for what you are looking for.

0 Kudos

Hi Savitha,

I worked on similar kind of requirement.

As per my requirement:

A transaction will have a popup screen where R/3 user id and password can be entered. Based on the user action, it should lock & update a Z table with the user, who logged-in in the popup screen.

I achieved this with the below steps:

1. I called a method 'lock' by passing popup screen user as import parameter.

2. Inside the method definition, I just used this parameter for locking the table.

So you can also send the user id as a import parameter to solve your issue.

Hope this help you.

Thanks,

Ramakrishna

0 Kudos

Any program that dynamically changes a userid will not pass through an internal/external audit. It violates Sarbanes-Oxley 404 intentions of protecting data.

Your external auditors, in particular, would mark this as a "red flag" item on an audit.

I would NOT do this.

Former Member
0 Kudos

Hi Savita,

1. It won't work in the Step 2.

2. If its ur own FM Y/Z

pass the username for further process.

3. Moreover, it is recommended / advisable

not to tamper with the system fields,

due to which unknown problems may arise.

regards,

amit m.

Former Member
0 Kudos

Hi,

I have a suggestion, which you might want to try out.

Create a RFC destination pointing to the same system. If you want to use a separate user all the time, give the user details in the SM59 itself. If you want to execute with different users at different time, then first execute the FM - RFC_MODIFY_R3_DESTINATION, to maintain the user details in the Destination with which you want to execute.

Then, execute your FM with the addition at the created destination. This will execute the FM with the separate user(however, this will be a separate login to the same system) and when it comes back the execution continues with the current user.

I have not verified this, but feels like it is worth a try.

Thanks,

Renjith

Former Member
0 Kudos

Hi,

Here is one more solution for your problem but a long process.

1) copy the standard program into your Z/Y Program.

2) change the user "SY_UNAME" to the required one in the function module.

3) again reset the uname in your main program.

But before copying the standard program make sure that the requirement is correct or else you are just trying to overcome the authorization check. If the execution of the function module is due to the authority check then there is another way to overcome this.

Regards,

Suman

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

What are you actually trying to acomplish with this second user? Do you just want different user defaults or is this a security/role issue?

I have been know to use a background job to get around security issues.


****Open the Job
    call function 'JOB_OPEN'
         exporting
              jobname          = jobname
         importing
              jobcount         = jobcount
         exceptions
              cant_create_job  = 1
              invalid_job_data = 2
              jobname_missing  = 3
              others           = 4.
    if sy-subrc <> 0.
      message e028(zes_job) with sy-subrc.
    endif.

****Place the program as a step in the Job
    submit zemc_mass_extend_mat_s_bac and return
           user 'USER2' via job jobname number jobcount
           with session = zem_mmh1-mass_session
           with werks1  = zem_mmh1-werks
           with back1   = back1
           with back2   = back2
           with back3   = back3
           with back4   = back4.

****Close the job and start Immediately
    call function 'JOB_CLOSE'
      exporting
        jobcount                          = jobcount
        jobname                           = jobname
        strtimmed                         = 'X'
*     IMPORTING
*       JOB_WAS_RELEASED                  =
     exceptions
       cant_start_immediate              = 1
       invalid_startdate                 = 2
       jobname_missing                   = 3
       job_close_failed                  = 4
       job_nosteps                       = 5
       job_notex                         = 6
       lock_failed                       = 7
       others                            = 8.
    if sy-subrc <> 0.
      message e029(zes_job) with sy-subrc.
    endif.

  endif.

0 Kudos

just checked 7.31.

sy-uname = 'TEST'.

call function 'RFC_PING' in background task.

commit work.

tried suppressing tRFC fire in debugger, got a record under user TEST in SM58

this wasn't possible in 4.6c. is it issue or new feature?

Former Member
0 Kudos

Hi Savitha/Rama Krisha,

I have a similiar requirement to update with the different user names. Can you pls help me with additional info.If possible pls forward the details to ferryanand@yahoo.com