Skip to Content
Author's profile photo Gianluca Calloni

Crystal Report – Data filtered by logged in user

A little and short Blog post to explain what i done to filter data in a Crystal Report depending the user logged in SAP.

Here the link of the discussion where many people help me to solve this “issue”: Crystal Report – Sales order filtered by current logged in user


Create some reports for:

  • Sales Quotation (OQUT / /QUT1)
  • Sales Order (ORDR / RDR1)
  • Sales Delivery (ODLN / DLN1)
  • Sales Invioce (OINV/INV1)

The report show the itemcode, price, discount grouped by BP Code.

In sap we have 3 user (USER_A, USER_B, USER_C) which can see all the data.

Every other user can see only the BP data for which he is sales agent.

So.. We suppose to use sales order tables, but is the same with all other sales documents…


In Crystal Report load the following tables:

  • ORDR
  • RDR1
  • OSLP
  • OHEM
  • OUSR

Then create a join through:

  • ORDR.slpcode and OSLP.slpcode
  • OSLP.slpcode and OHEM.salesprson
  • OHEM.userid and OUSR.userid


Create a parameter PrintByUserName@ which return the user name of the user logged in SAP B1 (from OUSR.U_NAME).


Create a function (i use the name CHEK_USER…) to check which user is logged in.

The code could be:

StringVar Array MasterUser;
StringVar User;
Redim MasterUser [3];
MasterUser[1] := "USER_A";
MasterUser[2] := "USER_B";
MasterUSer[3] :="USER_C";
if ({?PrintByUserName@} in MasterUser) then
     User := "*";
     User := {?PrintByUserName}

So the function give back the “*” (if the user is USER_A or USER_B or USER_C) or the name of the logged in user if the user is someone else…


In Crystal Report, in the WHERE clause, just put the code


And this is..

If you are USER_A or USER_B or USER_C you can see all the data..

If you are someone else.. You can see only the data for which you are set as Sales Agent.

I hope this could help someone other..

Sorry for my english

Have a nice day


Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Nagarajan K
      Nagarajan K


      Thanks for sharing.

      Best regards,


      Author's profile photo Gianluca Calloni
      Gianluca Calloni
      Blog Post Author


      Author's profile photo Former Member
      Former Member

      Error in your function code --> Fields cannot be used within a custom function !