SAP Knowledge Base Article - Public

3387883 - Unable to pass the Current CE User Name to a Command Object SQL Query in Crystal Reports

Symptom

  • Unable to use the special field: Current CE User Name, in a SQL Query.
  • How to pass the special field: Current CE User Name, to the SQL Query written in a Command Object, in Crystal Reports?

Environment

  • SAP Crystal Reports 2013
  • SAP Crystal Reports 2016
  • SAP Crystal Reports 2020 

Reproducing the Issue

Cause

  • Crystal Reports Special Fields, like: Current CE User Name, are only available on the report design, and cannot be used in a SQL Query.

Resolution

  • The workaround to pass the value of the Current CE User Name to a SQL Query, is to insert your report as a subreport,  then create a formula that returns the Current CE User Name, and finally, link the formula to a subreport Command Object parameter:

    1. In Crystal Reports, create a new report off any data source that returns at least one record.
      ( The report will be used as a container of your actual report, and it is very important it returns 1 record.)
        
    2. Insert 1 database field in the Details section.
        
    3. Suppress all the sections except the Page Header, Report Footer, and Page Footer.
         
    4. Create a formula to capture the name of the user logged in to the SAP BusinessObjects Repository.
      The code for the special field: Current CE User Name is:

           CurrentCEuserName
          
    5. Create subreport based on the Command Object you want to pass the Current CE User Name to.
      5.1  Under the menu "Insert", select "Subreport"
      5.2  In Insert Subreport, click on "Report Wizard"
      5.3  Connect to your data source.
      5.4  For your data source connection, click on "Add Command"
         
    6. In the Command Object of the subreport, add a parameter to your SQL Query, like: CurrentUser.
      6.1  In the Command Object, on the right side of "Parameter List", click on "Create..."
      6.2  In the Command Parameter window, enter the parameter name.
      6.3  Set the Value Type, to: String.
      6.4  Click "OK"
         
    7. Add the parameter to the WHERE clause of your SQL Query in the Command Object, and surround it by single quotes.
      7.1  Add the parameter to the WHERE clause.

              For example, if the parameter name is MyParameter,
              then add to the WHERE caluse: '{?MyParameter}', like:

              SELECT Field Name A, Field Name B, Field Name C
              FROM My Table A
              WHERE Field Name A = '{?MyParameter}'

      7.2 Then click "OK"
      7.3 Back to the Report Wizard, add the Command to the report, and click "Finish"
      7.4 Back to the window "Insert Subreport" click "OK"
        
    8. Insert the Subreport in the Report Footer section of the report.
        
    9. Link the main report formula created for the Current User User Name, to the subreport command object parameter
      9.1  Right click on the subreport, and select "Change Subreport links..."
      9.2  In the Subreport Lins window, in the upper left corner, select the formula created for the Current CE User Name, and click on arrow button ">"
      9.3  At the bottom left corner, for the Subreport parameter field to use, select the subreport parameter in the drop-down list.  ( If we keep the example provided earlier, select the parameter named "?MyParameter" )
      9.4  Click "OK"

See Also

Keywords

CR, SpecialFields, CurrentCEuserName , KBA , BI-RA-CR , Crystal Reports designer or Business View Manager , How To

Product

SAP Crystal Reports 2013 ; SAP Crystal Reports 2016 ; SAP Crystal Reports 2020