Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Specify field mapping when changing table location

I want to change the tables in a report to refer to database tables with a different schema, and specify the mapping of fields in code.

I already have code that changes table locations successfully when the schema does not differ, using the RAS API. As far as I can tell, the RAS API doesn't have a way of handling schema differences. Is that true?

OTOH, the higher-level CR API does appear to have a mechanism to do field mapping, using the FieldMapping event in the ReportDocument class. I've been trying to use this API for the job, but I don't seem to be able to change the location of a table in the report.

Here's an example scenario:

  • The report was created using an ODBC data source Source1 that contains a table Table1
  • I have an ODBC data source Source2 that contains Table1 as well as a table Table2 that is identical to Table1 except that the field names are all slightly different
  • I want to change the report so that it uses Table2 in Source2

I've managed to get the report switched to Source2 with code like this:

report.DataSourceConnections[0].SetConnection("Source2", "", id, pwd);

Here's the code I'm using to try to change the report table to refer to Table2:

            Table table = report.Database.Tables[0]; // only one table in the report

            TableLogOnInfo logOnInfo = table.LogOnInfo;

            logOnInfo.TableName = "Table2";

            table.ApplyLogOnInfo(logOnInfo);

            report.VerifyDatabase();


I've also tried the simpler


table.Location = "Table2";


Neither approach changes the table location. I know this because when I preview the report I see data. Since the field names are all different, changing the location should have removed all the fields from the report. (Also, the event handler I have hooked up to the FieldMapping event is not called. Yes, I did enable the event in the ReportDocument.)


So:


  1. How do you change the location of a table using the high-level API?
  2. If you change the location using the RAS API, is the FieldMapping event fired? (Haven't tried this, but somehow I doubt it.)
  3. Is there a way to do field mapping with the RAS API?


Thanks!


- rick cameron

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question