Skip to Content

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

Tables will not get added.

Hi All,

now in my web application I am facing the problem of

Table cannot get added by using following script.

any one told me please.

<%@ page contentType="text/html; charset=utf-8"%>

<%@ page import="com.crystaldecisions.sdk.occa.report.application.DatabaseController" %>

<%@ page import="com.crystaldecisions.sdk.occa.report.application.ReportClientDocument" %>

<%@ page import="com.crystaldecisions.sdk.occa.report.data.Field" %>

<%@ page import="com.crystaldecisions.sdk.occa.report.data.Table" %>

<%@ page import="com.crystaldecisions.sdk.occa.report.data.TableLink" %>

<%@ page import="com.crystaldecisions.sdk.occa.report.data.TableLinks" %>

<%@ page import="com.crystaldecisions.sdk.occa.report.lib.ReportSDKException" %>

<%@ include file = "Utilities.jsp" %>

<%

/*

  • This page creates a new report based on the tables, linking fields, and name provided by the

  • user on previous pages.

*/

%>

<%!

/*

  • This function adds the two given tables to the report and then links them

  • using the two given field names.

  • Parameters:

  • reportClientDocument

  • The ReportClientDocument object to which the new tables will be added.

  • It is assumed that the report does not have any tables.

  • sourceTable

  • The Table object representing the source table used for the linking.

  • targetTable

  • The Table object representing the target table used for the linking.

  • sourceFieldName

  • A name of a field from the source table. This field will be used for linking.

  • targetFieldName

  • A name of a field from the source table. This field will be used for linking.

  • Returns: void

*/

void addAndLinkTables( ReportClientDocument reportClientDocument,

Table sourceTable, Table targetTable,

String sourceFieldName, String targetFieldName )

throws TutorialException

{

/*

  • Only the database controller can be used to modify a report's table structure.

  • Here it is used add the two tables to the report.

*/

DatabaseController databaseController;

try

{

databaseController = reportClientDocument.getDatabaseController();

databaseController.addTable(sourceTable, new TableLinks());

databaseController.addTable(targetTable, new TableLinks());

}

catch(ReportSDKException e)

{

throw new TutorialException("Error while adding tables.");

}

// Create the new link that will connect the two tables.

TableLink tableLink = new TableLink();

/*

  • Add the source field name and the target field name to the SourceFieldNames

  • and TargetFieldNames collection of the TableLink object.

*/

tableLink.getSourceFieldNames().add(sourceFieldName);

tableLink.getTargetFieldNames().add(targetFieldName);

/*

  • Specify which tables are to be linked by setting table aliases

  • for the TableLink object.

*/

tableLink.setSourceTableAlias(sourceTable.getAlias());

tableLink.setTargetTableAlias(targetTable.getAlias());

// Add the link to the report. Doing so effectively links the two tables.

try

{

databaseController.addTableLink(tableLink);

}

catch(ReportSDKException e)

{

throw new TutorialException("Error while linking tables.");

}

}

%>

<%

// Get the previously opened report from the session.

ReportClientDocument sourceReportClientDocument =

(ReportClientDocument)session.getAttribute("ReportClientDocument");

// Create a new report.

ReportClientDocument newReportClientDocument = createNewReport(session);

// Retrieve the names of the tables from the session.

Table sourceTable = (Table)session.getAttribute("SourceTable");

Table targetTable = (Table)session.getAttribute("TargetTable");

// Retrieve the names of the linking fields from the session.

String sourceFieldName = (String)session.getAttribute("SourceFieldName");

String targetFieldName = (String)session.getAttribute("TargetFieldName");

// Retrieve the name of the new report.

String newReportName = request.getParameter("NewReportName");

// Add and link the tables, and then save the report.

try

{

addAndLinkTables( newReportClientDocument, sourceTable, targetTable,

sourceFieldName, targetFieldName );

saveReportAs(newReportClientDocument, newReportName, session);

}

catch (TutorialException e)

{

redirectWithError("Error.jsp", e.getMessage(), response);

return;

}

// Close both the source report and the new report.

closeReport(sourceReportClientDocument, session);

closeReport(newReportClientDocument, session);

%>

<html>

<head>

<link rel='stylesheet' type='text/css' name='stylelink' href='../tutss.css'>

</head>

<body>

<hr>

<p>The new report <i><%= newReportName %></i> has been saved.</p>

<hr>

</body>

</html>

Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question