Java Plug-In User Guide For IBM SPSS Statistics
Java Plug-In User Guide For IBM SPSS Statistics
Statistics
Note
Before using this information and the product it supports, read the information in “Notices” on page 25.
Product Information
This edition applies to version 22, release 0, modification 0 of IBM SPSS Statistics and to all subsequent releases and
modifications until otherwise indicated in new editions.
Contents
Chapter 1. Getting started with the Appending new cases . . . . . . . . . . 12
Integration Plug-in for Java . . . . . . 1
Invoking IBM SPSS Statistics from an external Java Chapter 5. Retrieving output from
application . . . . . . . . . . . . . . . 1 syntax commands . . . . . . . . . . 15
Creating IBM SPSS Statistics extension commands in Retrieving output from syntax commands . . . . 15
Java . . . . . . . . . . . . . . . . . 2
Chapter 6. Creating custom output . . 19
Chapter 2. Running IBM SPSS Statistics Creating custom output . . . . . . . . . . 19
commands . . . . . . . . . . . . . 5 Creating pivot tables . . . . . . . . . . 19
Running IBM SPSS Statistics commands . . . . . 5 Creating text blocks . . . . . . . . . . 21
Creating output for extension commands . . . 21
Chapter 3. Retrieving dictionary
information . . . . . . . . . . . . . 7 Chapter 7. Deploying an external Java
Retrieving dictionary information . . . . . . . 7 application . . . . . . . . . . . . . 23
iii
iv Java Plug-in User Guide for IBM SPSS Statistics
Chapter 1. Getting started with the Integration Plug-in for Java
The IBM® SPSS® Statistics - Integration Plug-in for Java enables an application developer to create Java
applications that can invoke and control the IBM SPSS Statistics processor, or to implement extension
commands in Java that can then be run from within IBM SPSS Statistics. Extension commands are IBM
SPSS Statistics commands that are implemented in an external language (Python, R or Java) and allow
users who are proficient in that language to share external functions with users of standard IBM SPSS
Statistics command syntax.
With the IBM SPSS Statistics - Integration Plug-in for Java, you can do the following:
v Execute IBM SPSS Statistics command syntax.
v Read case data from the active dataset.
v Get information about data in the active dataset.
v Add new variables and append cases to the active dataset.
v Get output results from syntax commands.
v Create custom output in the form of pivot tables and text blocks.
The IBM SPSS Statistics - Integration Plug-in for Java is installed with IBM SPSS Statistics and IBM SPSS
Statistics Server and requires no separate installation or configuration. For version 22 of IBM SPSS
Statistics, the IBM SPSS Statistics - Integration Plug-in for Java supports Java version 6.
The IBM SPSS Statistics - Integration Plug-in for Java is designed to work with Unicode mode. Use of the
IBM SPSS Statistics - Integration Plug-in for Java with code page mode is not recommended.
Complete documentation for all of the classes and methods available with the IBM SPSS Statistics -
Integration Plug-in for Java is available in the Help system under the heading IBM SPSS Statistics -
Integration Plug-in for Java API Reference.
Important: Do not move [Link] from its installed location. The IBM SPSS Statistics - Integration
Plug-in for Java assumes that [Link] is in the installed location.
Note: For information on deploying your application on end user machines, please see Chapter 7,
“Deploying an external Java application,” on page 23.
When invoked from an external Java application, the IBM SPSS Statistics processor runs without an
associated instance of the IBM SPSS Statistics client. In this mode, output generated from IBM SPSS
The following is a simple example of using the IBM SPSS Statistics - Integration Plug-in for Java to create
a dataset in IBM SPSS Statistics, compute descriptive statistics and generate output. It illustrates the basic
features of invoking IBM SPSS Statistics from an external Java application.
import [Link].*;
try {
[Link]();
String[] command={"OMS",
"/DESTINATION FORMAT=HTML OUTFILE=’/output/[Link]’.",
"DATA LIST FREE /salary (F).",
"BEGIN DATA",
"21450",
"30000",
"57000",
"END DATA.",
"DESCRIPTIVES salary.",
"OMSEND."};
[Link](command);
[Link]();
} catch (StatsException e) {
[Link]();
}
}
}
v The statement import [Link].* imports all of the classes in the
[Link] package.
v The [Link] method starts the IBM SPSS Statistics processor.
v A string array specifies IBM SPSS Statistics command syntax that creates a dataset and runs the
DESCRIPTIVES procedure. The command syntax is submitted to IBM SPSS Statistics using the
[Link] method. Output from the DESCRIPTIVES procedure is routed to an HTML file using
the OMS command.
v The [Link] method stops the IBM SPSS Statistics processor and should be called to properly
end an IBM SPSS Statistics session.
v The StatsException class is a subclass of the native Java Exception class, and handles exceptions that
are specific to the IBM SPSS Statistics - Integration Plug-in for Java. It can be inherited to define
custom exception classes for your application.
Implementation code
The implementation code can consist of a JAR file or Java class files.
v When using a JAR file, the name of the JAR file must be the same as the name of the extension
command, and in upper case. For multi-word command names, spaces between words should be
replaced with underscores when constructing the name of the JAR file. The JAR file must contain a
class file with the same name as the JAR file and the class must not be part of a package.
v When using standalone Java class files, there must be one class file with the same name as that of the
extension command, and in upper case. For multi-word command names, spaces between words
should be replaced with underscores when constructing the name of the Java class file.
The following is an example of a Java class for an extension command named DEMO, which simply takes a
variable list as input and prints out the list. It demonstrates the basic structure of the implementation
code and the means by which values are passed from the command syntax (submitted by the user) to the
method that implements the command.
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
public DEMO() {
[Link]("This is the constructor method");
}
} catch (Exception e) {
[Link]();
}
}
Briefly, the functions of the Run, Template, Syntax and processcmd methods are as follows:
v IBM SPSS Statistics parses the command syntax entered by the user and passes the specified values to
the Run function in a single argument--args in this example.
v The Run function contains calls to the [Link], [Link], and
[Link] methods, which are designed to work together.
[Link] specifies the details needed to process a specified keyword in the syntax for an
extension command. In this example, the extension command contains the single keyword VARIABLES.
[Link] validates the values passed to the Run function according to the templates specified
for the keywords.
Values of specific keywords from the submitted syntax are mapped to variables in the method that
implements the command (printvars in this example) using a Java annotation. In this example, the
[Link] method specifies that the value of the VARIABLES keyword is associated with the
identifier "vars". The argument to the printvars method specifies that this identifier is mapped to the
local variable variables. This is accomplished with the @ParamName("vars") annotation. You include such
an annotation for each keyword in the syntax for the extension command.
The annotation mechanism also requires that arguments to the implementation method are defined as
object types, not primitive data types. In particular, you must use the object types Integer, Short, Long,
Float, Double, Byte, Character and Boolean instead of the primitive data types int, short, long, float,
double, byte, char and boolean. Note that in the above example, the value passed to the printvars
method is an array of strings and is defined as an ArrayList object.
To deploy an extension command, it is best to create an extension bundle for the command and add both
the implementation code (JAR file or Java class files) and the XML file specifying the command syntax to
the bundle. You can distribute the extension bundle (spe) file to other users who can then install it and
begin using your extension command. Information on extension bundles is available from Core
System>Utilities>Working with extension bundles, in the Help system.
You submit a single command to IBM SPSS Statistics by providing a string representation of the
command as shown in this example. When submitting a single command in this manner the period (.) at
the end of the command is optional.
[Link]("GET FILE=’/data/Employee [Link]’.");
[Link]("DESCRIPTIVES SALARY.");
v The submit method is called twice; first to submit a GET command and then to submit a DESCRIPTIVES
command.
You can submit multiple commands as an array of strings where each array element is a string
representation of a syntax command. The string for each command must be terminated with a period (.)
as shown in this example.
[Link]("GET FILE=’/data/Employee [Link]’.");
String[] cmdLines = {"DESCRIPTIVES SALARY SALBEGIN.","FREQUENCIES EDUC JOBCAT."};
[Link](cmdLines);
v The submit method is called with an array that specifies a DESCRIPTIVES and a FREQUENCIES command.
You can also use the elements of an array to represent parts of a command so that a single array specifies
one or more complete syntax commands. When submitting multiple commands in this manner, each
command must be terminated with a period (.) as shown in this example.
[Link]("GET FILE=’/data/Employee [Link]’.");
String[] cmdLines = {"OMS /SELECT TABLES ",
"/IF COMMANDS = [’Descriptives’ ’Frequencies’] ",
"/DESTINATION FORMAT = HTML ",
"IMAGES = NO OUTFILE = ’/output/[Link]’.",
"DESCRIPTIVES SALARY SALBEGIN.",
"FREQUENCIES EDUC JOBCAT.",
"OMSEND."};
[Link](cmdLines);
v The submit method is called with an array that specifies an OMS command followed by a DESCRIPTIVES
command, a FREQUENCIES command, and an OMSEND command. The first four elements of the array are
used to specify the OMS command.
For debugging purposes, it is convenient to see the completed syntax passed to IBM SPSS Statistics by
any calls to the submit method. This is enabled through command syntax with SET PRINTBACK ON MPRINT
ON.
The generated command syntax shows the completed FREQUENCIES command as well as the GET
command. In the present example the variable with index value 1 in the dataset has the name gender.
M> GET FILE=’c:/data/Employee [Link]’.
M> FREQUENCIES /VARIABLES=gender.
Example
Consider the common scenario of running a particular block of command syntax only if a specific
variable exists in the dataset. For example, you are processing many datasets containing employee
records and want to split them by gender--if a gender variable exists--to obtain separate statistics for the
two gender groups. We will assume that if a gender variable exists, it has the name gender, although it
may be spelled in upper case or mixed case. The following sample code illustrates the approach:
[Link]("GET FILE=’/data/Employee [Link]’.");
DataUtil datautil = new DataUtil();
String[] varnames = [Link]();
[Link]();
for(String name: varnames){
if([Link]().equals("gender")){
String[] command={"SORT CASES BY " + name + ".",
"SPLIT FILE LAYERED BY " + name + "."};
[Link](command);
}
}
7
8 Java Plug-in User Guide for IBM SPSS Statistics
Chapter 4. Working with case data in the active dataset
Working with case data in the active dataset
The IBM SPSS Statistics - Integration Plug-in for Java provides the ability to read case data from the
active dataset, create new variables in the active dataset, and append new cases to the active dataset. The
functionality for reading from and writing to the active dataset is provided in the Cursor class. An
instance of the Cursor class creates an open cursor, which provides access to the active dataset. The
following rules apply to the use of cursors:
v You cannot use the submit method from the StatsUtil class while a data cursor is open. You must
close the cursor first using the close method. In particular, if you need to save changes made to the
active dataset to an external file, then use the submit method to submit a SAVE command after closing
the cursor.
v Only one data cursor can be open at any point in an application. To define a new data cursor, you
must first close the previous one.
While the Cursor class provides the full set of methods for accessing the active dataset, the simpler
DataUtil class is a wrapper for the Cursor class and provides the ability to read cases, create new
variables and append new cases. The examples in this section use the DataUtil class. Because the
DataUtil class is a wrapper for the Cursor class, the above limitations on cursors also apply to DataUtil
objects. The following apply:
v You cannot use the submit method from the StatsUtil class while a DataUtil object exists. You must
release the resources associated with the object with the release method. As with cursors, if you need
to save changes made to the active dataset to an external file, then use the submit method to submit a
SAVE command after releasing the DataUtil object.
v Only one DataUtil object can exist at a time. To create a new DataUtil object, you must first release the
previous one.
Note: To create a new dataset, use the submit method in the StatsUtil class to submit a DATA LIST
command.
Example
[Link]("GET FILE=’/data/[Link]’.");
DataUtil datautil = new DataUtil();
[Link](true);
Case[] data = [Link](false, 0);
Double numvar;
String strvar;
Calendar datevar;
for(Case onecase: data){
for(int i = 0;i<[Link]();i++){
CellValueFormat format = [Link](i);
9
if(format == [Link]){
numvar = [Link](i);
}
else if(format == [Link]){
strvar = [Link](i);
}
else if(format == [Link]){
datevar = [Link](i);
}
}
}
[Link]();
v You first create an instance of the DataUtil class. In this example, the variable datautil is a DataUtil
object.
v The setConvertDateTypes method specifies that values read from IBM SPSS Statistics variables with
date or datetime formats will be converted to Java Calendar objects.
v The fetchCases method retrieves all cases from the active dataset. The first argument specifies that
user-missing values will be treated as missing and thus converted to the Java null value. The second
argument specifies that all cases, starting with case 0, will be retrieved from the active dataset. You can
retrieve cases starting from an arbitrary case number by specifying a different value for the second
argument. You can also retrieve a specified number of cases, using an overloaded form of fetchCases
with a third argument specifying the number of cases to retrieve.
v The fetchCases method returns a Case object, which represents an array of cases. The items in a given
element of the array correspond to the values of the variables in a particular case of data from the
active dataset, in file order. You can get the number of items in each case from the getCellNumber
method of the Case object.
v The type of value in each item of a case is available from the getCellValueFormat method of the Case
object. Values are retrieved from the Case object with methods specific to each type of value, as shown
here for numeric, string and date values.
You can specify a subset of variables for which data will be retrieved. You can specify the set of variables
by name or by their index position in the active dataset. Index positions start with 0 for the first variable
in file order.
[Link]("GET FILE=’/data/employee [Link]’.");
DataUtil datautil = new DataUtil();
String[] varNames = new String[]{"id","educ","salary"};
[Link](varNames);
Case[] data = [Link](false, 0);
The setVariableFilter method specifies the subset of variables for which data will be retrieved. In this
example, only data for the variables id, educ and salary will be retrieved.
Missing data
The first argument to the fetchCases method specifies whether user-missing values are converted to the
Java null value or treated as valid data. System-missing values are always converted to the Java null
value.
String[] command={"DATA LIST LIST (’,’) /numVar (f) stringVar (a4).",
"BEGIN DATA",
"1,a",
",b",
"3,,",
"9,d",
"END DATA.", _
"MISSING VALUES numVar (9) stringVar (’ ’)."}
[Link](command);
DataUtil datautil = new DataUtil();
Case[] data = [Link](false, 0);
[Link]();
Setting the first argument to fetchCases to false specifies that user-missing values are converted to the
Java null value. The values read from IBM SPSS Statistics and stored in the variable data are:
10 Java Plug-in User Guide for IBM SPSS Statistics
1 a
null b
3 null
null d
You can specify that user-missing values be treated as valid data by setting the first argument to the
fetchCases method to true. The values of data are now:
1 a
null b
3
9 d
The getSplitIndex method, from the DataUtil class, allows you to detect split changes when reading
from datasets that have splits.
String[] command={"DATA LIST FREE /salary (F) jobcat (F).",
"BEGIN DATA",
"21450 1",
"45000 1",
"30000 2",
"30750 2",
"103750 3",
"72500 3",
"57000 3",
"END DATA.",
"SPLIT FILE BY jobcat."};
[Link](command);
DataUtil datautil = new DataUtil();
int splitindex;
splitindex = [Link](0);
while(splitindex!=-1){
[Link]("A new split begins at case: " + splitindex);
splitindex = [Link](splitindex);
}
[Link]();
v [Link] gets the case number of the first case in the split following the specified case.
For the sample dataset used in this example, split boundaries are crossed when reading the 3rd and
5th cases. Case numbers start from 0.
v If there are no split boundaries following the specified case, then [Link] returns -1.
Example
In this example we create a new string variable, a new numeric variable and a new date variable, and
populate case values for them. A sample dataset is first created.
String[] command={"DATA LIST FREE /case (A5).",
"BEGIN DATA",
"case1",
"case2",
"case3",
"END DATA."};
[Link](command);
Variable numVar = new Variable("numvar",0);
Variable strVar = new Variable("strvar",1);
Variable dateVar = new Variable("datevar",0);
[Link]([Link]);
double[] numValues = new double[]{1.0,2.0,3.0};
String[] strValues = new String[]{"a","b","c"};
Calendar dateValue = [Link]();
[Link]([Link], 2012);
[Link]([Link], [Link]);
[Link](Calendar.DAY_OF_MONTH, 1);
Calendar[] dateValues = new Calendar[]{dateValue};
DataUtil datautil = new DataUtil();
[Link](numVar, numValues, 0);
[Link](strVar, strValues, 0);
[Link](dateVar, dateValues, 0);
[Link]();
Note: To save the modified active dataset to an external file, use the submit method (following the
release method) to submit a SAVE command, as in:
[Link]("SAVE OUTFILE=’/data/[Link]’.")
Sometimes more than one pass of the data is required, as in the following example involving two data
passes. The first data pass is used to read the data and compute a summary statistic. The second data
pass is used to add a summary variable to the active dataset.
String[] command={"DATA LIST FREE /var (F).",
"BEGIN DATA",
"40200",
"21450",
"21900",
"END DATA."};
[Link](command);
Double total = 0.0;
DataUtil datautil = new DataUtil();
Case[] data = [Link](false, 0);
for(Case onecase: data){
total = total + [Link](0);
}
Double meanval = total/[Link];
Variable mean = new Variable("mean",0);
double[] meanVals = new double[[Link]];
for (int i=0;i<[Link];i++){
meanVals[i]=meanval;
}
[Link](mean, meanVals, 0);
[Link]();
Example
Constructing the correct XPath expression (IBM SPSS Statistics currently supports XPath 1.0) requires an
understanding of the Output XML schema. The output schema [Link] is distributed with
IBM SPSS Statistics. Documentation is included in the IBM SPSS Statistics Help system.
Example
In this example, we'll retrieve the mean value of a variable calculated from the Descriptives procedure.
String[] command={"GET FILE=’/data/Employee [Link]’.",
"OMS SELECT TABLES ",
"/IF COMMANDS=[’Descriptives’] SUBTYPES=[’Descriptive Statistics’] ",
"/DESTINATION FORMAT=OXML XMLWORKSPACE=’desc_table’ ",
"/TAG=’desc_out’.",
"DESCRIPTIVES VARIABLES=salary, salbegin, jobtime, prevexp ",
"/STATISTICS=MEAN.",
"OMSEND TAG=’desc_out’."};
[Link](command);
String handle = "desc_table";
String context = "/outputTree";
String xpath = "//pivotTable[@subType=’Descriptive Statistics’]" +
"/dimension[@axis=’row’]" +
"/category[@varName=’salary’]" +
"/dimension[@axis=’column’]" +
"/category[@text=’Mean’]" +
"/cell/@text";
String result = [Link](handle, context, xpath);
[Link](handle);
v The OMS command is used to direct output from a syntax command to the XML workspace. The
XMLWORKSPACE keyword on the DESTINATION subcommand, along with FORMAT=OXML, specifies the XML
workspace as the output destination. It is a good practice to use the TAG subcommand, as done here, so
as not to interfere with any other OMS requests that may be operating. The identifiers used for the
COMMANDS and SUBTYPES keywords on the IF subcommand can be found in the OMS Identifiers dialog
box, available from the Utilities menu in IBM SPSS Statistics.
v The XMLWORKSPACE keyword is used to associate a name with this XPath DOM in the workspace. In the
current example, output from the DESCRIPTIVES command will be identified with the name desc_table.
You can have many XPath DOM's in the XML workspace, each with its own unique name.
v The OMSEND command terminates active OMS commands, causing the output to be written to the
specified destination--in this case, the XML workspace.
v You retrieve values from the XML workspace with the evaluateXPath method from the StatsUtil class.
The method takes an explicit XPath expression, evaluates it against a specified XPath DOM in the XML
workspace, and returns the result as an array of string values.
v The first argument to the evaluateXPath function specifies the XPath DOM to which an XPath
expression will be applied. This argument is referred to as the handle name for the XPath DOM and is
simply the name given on the XMLWORKSPACE keyword on the associated OMS command. In this case the
handle name is desc_table.
v The second argument to evaluateXPath defines the XPath context for the expression and should be set
to "/outputTree" for items routed to the XML workspace by the OMS command.
15
v The third argument to evaluateXPath specifies the remainder of the XPath expression (the context is
the first part). Since XPath expressions almost always contain quoted strings, you'll need to use a
different quote type from that used to enclose the expression. For users familiar with XSLT for OXML
and accustomed to including a namespace prefix, note that XPath expressions for the evaluateXPath
function should not contain the oms: namespace prefix.
v The XPath expression in this example is specified by the variable xpath. It is not the minimal expression
needed to select the mean value of interest but is used for illustration purposes and serves to highlight
the structure of the XML output.
//pivotTable[@subType=’Descriptive Statistics’] selects the Descriptives Statistics table.
/dimension[@axis=’row’]/category[@varName=’salary’] selects the row for the variable salary.
/dimension[@axis=’column’]/category[@text=’Mean’] selects the Mean column within this row, thus
specifying a single cell in the pivot table.
/cell/@text selects the textual representation of the cell contents.
v When you have finished with a particular output item, it is a good idea to delete it from the XML
workspace. This is done with the deleteXPathHandle method, whose single argument is the name of
the handle associated with the item.
If you're familiar with XPath, note that the mean value of salary can also be selected with the following
simpler XPath expression:
//category[@varName=’salary’]//category[@text=’Mean’]/cell/@text
Note: To the extent possible, construct your XPath expressions using language-independent attributes,
such as the variable name rather than the variable label. That will help reduce the translation effort if you
need to deploy your code in multiple languages. Also consider factoring out language-dependent
identifiers, such as the name of a statistic, into constants. You can obtain the current language used for
pivot table output with the syntax command SHOW OLANG.
You may also consider using text_eng attributes in place of text attributes in XPath expressions.
text_eng attributes are English versions of text attributes and have the same value regardless of the
output language. The OATTRS subcommand of the SET command specifies whether text_eng attributes are
included in OXML output.
When writing and debugging XPath expressions, it is often useful to have a sample file that shows the
XML structure. This can be obtained with the getXMLUTF16 method from the StatsUtil class, as well as by
an option on the OMS syntax command. The following code recreates the XML workspace for the
preceding example and writes the XML associated with the handle desc_table to an external file.
String[] command={"GET FILE=’/data/Employee [Link]’.",
"OMS SELECT TABLES ",
"/IF COMMANDS=[’Descriptives’] SUBTYPES=[’Descriptive Statistics’] ",
"/DESTINATION FORMAT=OXML XMLWORKSPACE=’desc_table’ ",
"/TAG=’desc_out’.",
"DESCRIPTIVES VARIABLES=salary, salbegin, jobtime, prevexp ",
"/STATISTICS=MEAN.",
"OMSEND TAG=’desc_out’."};
[Link](command);
String result = StatsUtil.getXMLUTF16("desc_table");
Writer out = new OutputStreamWriter(new FileOutputStream("/output/descriptives_table.xml"));
[Link](result);
[Link]();
[Link]("desc_table");
The section of the output file that specifies the Descriptive Statistics table, including the mean value of
salary, is as follows (the output is written in Unicode (UTF-16)):
<pivotTable subType="Descriptive Statistics" text="Descriptive Statistics">
<dimension axis="row" text="Variables">
<category label="Current Salary" text="Current Salary"
varName="salary" variable="true">
<dimension axis="column" text="Statistics">
You can retrieve images associated with output routed to the XML workspace. In this example, we'll
retrieve a bar chart associated with output from the Frequencies procedure.
String[] command={"GET FILE=’/data/Employee [Link]’.",
"OMS SELECT CHARTS ",
"/IF COMMANDS=[’Frequencies’] ",
"/DESTINATION FORMAT=OXML IMAGES=YES",
"CHARTFORMAT=IMAGE IMAGEROOT=’myimages’ IMAGEFORMAT=JPG XMLWORKSPACE=’demo’.",
"FREQUENCIES VARIABLES=jobcat",
" /BARCHART PERCENT",
" /ORDER=ANALYSIS.",
"OMSEND."};
[Link](command);
String handle = "demo";
String context = "/outputTree";
String xpath = "//command[@command=’Frequencies’]" +
"/chartTitle[@text=’Bar Chart’]" +
"/chart/@imageFile";
String[] result = [Link](handle, context, xpath);
String imageName = result[0];
BufferedImage imageObj = [Link](handle, imageName);
File outputFile = new File("/output/[Link]");
[Link](imageObj, "JPG", outputFile);
[Link](handle);
v The OMS command routes output from the FREQUENCIES command to an output XPath DOM with the
handle name of demo.
v To route images along with the OXML output, the IMAGES keyword on the DESTINATION subcommand
(of the OMS command) must be set to YES, and the CHARTFORMAT, MODELFORMAT, or TREEFORMAT keyword
must be set to IMAGE.
v The evaluateXPath function is used to retrieve the name of the image associated with the bar chart
output from the FREQUENCIES command. In the present example, the value returned by evaluateXPath
is a list with a single element, which is then stored to the variable imageName.
v The getImage method of the StatsUtil class retrieves the image, which is then written to an external
file.
The first argument to the getImage function specifies the particular XPath DOM and must be a valid
handle name defined by a previous IBM SPSS Statistics OMS command.
The second argument to getImage is the filename associated with the image in the OXML
output--specifically, the value of the imageFile attribute of the chart element associated with the
image.
Each cell in the table can be specified by a combination of category values. In the example shown here,
the indicated cell is specified by a category value of Male for the Gender dimension and Custodial for the
Employment Category dimension.
Pivot tables are created with the PivotTable class, as shown in the following example. This example
assumes that you are creating pivot table output for an external Java application that will invoke IBM
SPSS Statistics, so that the output is routed with OMS.
String[] command={
"OMS SELECT TABLES",
"/IF SUBTYPES=[’pivotTableDemo’]",
"/DESTINATION FORMAT=HTML OUTFILE=’/output/[Link]’."
};
[Link](command);
Object[] rowLabels = new Object[] {"row1", "row2"};
Object[] colLabels = new Object[] { "columnA", "columnB"};
Object[][] cells = new Object[][] {{"1A","1B"}, {"2A","2B"}};
String title = "Sample pivot table";
String templateName = "pivotTableDemo";
String outline = "";
String caption = "";
String rowDim = "Row dimension";
String columnDim = "Column dimension";
boolean hideRowDimTitle = false;
boolean hideRowDimLabel = false;
boolean hideColDimTitle = false;
boolean hideColDimLabel = false;
PivotTable table = new PivotTable(cells, rowLabels, colLabels,
title, templateName, outline, caption, rowDim,
19
columnDim, hideRowDimTitle, hideRowDimLabel,
hideColDimTitle, hideColDimLabel, [Link]);
[Link]();
[Link]("OMSEND.");
Result
v In this example, pivot table output is routed to an external HTML file using OMS (Output
Management System). The OMS command specifies that only tables with a table subtype of
pivotTableDemo (to be defined below) will be included in the output. It also specifies the path to the
output file and that the output will be rendered in HTML.
v The command syntax for the OMS command is submitted to IBM SPSS Statistics. This starts an OMS
session. The session is closed with the OMSEND command, which then writes the output to the
destination file.
Note: As an alternative to routing output with OMS, you can also specify output formats and
destinations using an overloaded form of the [Link] method that accepts a string with
output specifications. OMS offers greater flexibility but, for simple applications, specifying output on
the start method may be sufficient.
v To create a pivot table, you create an instance of the PivotTable class. The arguments are as follows:
cells. This argument specifies the values for the cells of the pivot table, and must be given as a
2-dimensional array, where each element of the array specifies the cells in a given row of the pivot
table. Only Double and String objects can be specified in this array.
rowLabels. A 1-dimensional array of categories for the row dimension. Only Double and String objects
can be specified in this array.
colLabels. A 1-dimensional array of categories for the column dimension. Only Double and String
objects can be specified in this array.
title. A string specifying the title of the table.
templateName A string that specifies the OMS (Output Management System) table subtype for this
table. This value must begin with a letter, and have a maximum of 64 bytes. The table subtype can be
used on the SUBTYPES keyword of the OMS command, as done here, to include this pivot table in the
output for a specified set of subtypes.
Note: By creating the pivot table instance within a startProcedure-endProcedure block, you can
associate the pivot table output with a command name, as for pivot table output produced by syntax
commands. The command name is the argument to the startProcedure function and can used on the
COMMANDS keyword of the OMS command to include the pivot table in the output for a specified set of
commands (along with optionally specifying a subtype as discussed above).
outline. A string that specifies an optional outline title for the table. When routing output to an SPV
file with OMS, or generating output in the Viewer for an extension command implemented in Java, the
pivot table will be nested under an item with the outline name. When output is routed to OMS in
OXML format, the outline title specifies a heading tag that will contain the output for the pivot table.
caption. A string that specifies a table caption.
rowDim. A string specifying the label for the row dimension.
columnDim. A string specifying the label for the column dimension.
hideRowDimTitle. A boolean specifying whether to hide the row dimension title.
hideRowDimLabels. A boolean specifying whether to hide the row labels.
As discussed in Chapter 1, “Getting started with the Integration Plug-in for Java,” on page 1, the JAR file
containing the Java package for the IBM SPSS Statistics - Integration Plug-in for Java is located in the IBM
SPSS Statistics installation directory, so your application must be able to locate this directory. A utility
distributed with the IBM SPSS Statistics - Programmability SDK is provided for this purpose. This
software development kit (SDK) is available from [Link]
The utility provides two means for obtaining the IBM SPSS Statistics installation directory. You can either
run a script which will write the location of the latest installed version of IBM SPSS Statistics to a .ini file,
or you can import a JAR file with methods that will allow you to obtain that location or the locations of
all installed versions of IBM SPSS Statistics (beginning with version 21). The components available with
the utility can be found in the StatisticsUtil folder under the location where you extract the ZIP file
containing the IBM SPSS Statistics - Programmability SDK.
To write the location of the latest installed version of IBM SPSS Statistics (beginning with version 21) to a
.ini file, run [Link] (for Windows platforms) or [Link] (for non-Windows platforms). The
script writes the location of IBM SPSS Statistics to the file [Link], located in the folder that contains
the script. Specifically, it creates a key-value pair with STATISTICS_PATH as the key and the location as
the value--for example, STATISTICS_PATH=C:\Program Files\IBM\SPSS\Statistics\21. If [Link]
already exists, the script updates the file. If [Link] does not exist, then the script will create it.
The file [Link] provides the following two methods in the Utility class:
v getStatisticsLocationLatest. This method returns a string with the path to the latest installed version of
IBM SPSS Statistics, starting with version 21.
v getStatisticsLocationAll. This method returns a string array with the paths to all installed versions of
IBM SPSS Statistics, starting with version 21.
Notes
v For instances of the client version of SPSS Statistics, the term 'latest' means the highest installed
version. For instances of the server version of SPSS Statistics on UNIX platforms, where multiple
instances with the same version number may exist on the same machine, the 'latest' version is the one
with the highest version number and the most recent time stamp.
v If there is both a client and a server version of SPSS Statistics installed as the latest version, then the
path to the server version is the one written to the .ini file or returned by the
getStatisticsLocationLatest method.
23
24 Java Plug-in User Guide for IBM SPSS Statistics
Notices
This information was developed for products and services offered in the U.S.A.
IBM may not offer the products, services, or features discussed in this document in other countries.
Consult your local IBM representative for information on the products and services currently available in
your area. Any reference to an IBM product, program, or service is not intended to state or imply that
only that IBM product, program, or service may be used. Any functionally equivalent product, program,
or service that does not infringe any IBM intellectual property right may be used instead. However, it is
the user's responsibility to evaluate and verify the operation of any non-IBM product, program, or
service.
IBM may have patents or pending patent applications covering subject matter described in this
document. The furnishing of this document does not grant you any license to these patents. You can send
license inquiries, in writing, to:
For license inquiries regarding double-byte (DBCS) information, contact the IBM Intellectual Property
Department in your country or send inquiries, in writing, to:
The following paragraph does not apply to the United Kingdom or any other country where such
provisions are inconsistent with local law: INTERNATIONAL BUSINESS MACHINES CORPORATION
PROVIDES THIS PUBLICATION "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR
IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some
states do not allow disclaimer of express or implied warranties in certain transactions, therefore, this
statement may not apply to you.
This information could include technical inaccuracies or typographical errors. Changes are periodically
made to the information herein; these changes will be incorporated in new editions of the publication.
IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this
publication at any time without notice.
Any references in this information to non-IBM Web sites are provided for convenience only and do not in
any manner serve as an endorsement of those Web sites. The materials at those Web sites are not part of
the materials for this IBM product and use of those Web sites is at your own risk.
IBM may use or distribute any of the information you supply in any way it believes appropriate without
incurring any obligation to you.
25
Licensees of this program who wish to have information about it for the purpose of enabling: (i) the
exchange of information between independently created programs and other programs (including this
one) and (ii) the mutual use of the information which has been exchanged, should contact:
Such information may be available, subject to appropriate terms and conditions, including in some cases,
payment of a fee.
The licensed program described in this document and all licensed material available for it are provided
by IBM under terms of the IBM Customer Agreement, IBM International Program License Agreement or
any equivalent agreement between us.
Any performance data contained herein was determined in a controlled environment. Therefore, the
results obtained in other operating environments may vary significantly. Some measurements may have
been made on development-level systems and there is no guarantee that these measurements will be the
same on generally available systems. Furthermore, some measurements may have been estimated through
extrapolation. Actual results may vary. Users of this document should verify the applicable data for their
specific environment.
Information concerning non-IBM products was obtained from the suppliers of those products, their
published announcements or other publicly available sources. IBM has not tested those products and
cannot confirm the accuracy of performance, compatibility or any other claims related to non-IBM
products. Questions on the capabilities of non-IBM products should be addressed to the suppliers of
those products.
All statements regarding IBM's future direction or intent are subject to change or withdrawal without
notice, and represent goals and objectives only.
This information contains examples of data and reports used in daily business operations. To illustrate
them as completely as possible, the examples include the names of individuals, companies, brands, and
products. All of these names are fictitious and any similarity to the names and addresses used by an
actual business enterprise is entirely coincidental.
COPYRIGHT LICENSE:
This information contains sample application programs in source language, which illustrate programming
techniques on various operating platforms. You may copy, modify, and distribute these sample programs
in any form without payment to IBM, for the purposes of developing, using, marketing or distributing
application programs conforming to the application programming interface for the operating platform for
which the sample programs are written. These examples have not been thoroughly tested under all
conditions. IBM, therefore, cannot guarantee or imply reliability, serviceability, or function of these
programs. The sample programs are provided "AS IS", without warranty of any kind. IBM shall not be
liable for any damages arising out of your use of the sample programs.
Each copy or any portion of these sample programs or any derivative work, must include a copyright
notice as follows:
© your company name) (year). Portions of this code are derived from IBM Corp. Sample Programs.
© Copyright IBM Corp. _enter the year or years_. All rights reserved.
Adobe, the Adobe logo, PostScript, and the PostScript logo are either registered trademarks or trademarks
of Adobe Systems Incorporated in the United States, and/or other countries.
Intel, Intel logo, Intel Inside, Intel Inside logo, Intel Centrino, Intel Centrino logo, Celeron, Intel Xeon,
Intel SpeedStep, Itanium, and Pentium are trademarks or registered trademarks of Intel Corporation or its
subsidiaries in the United States and other countries.
Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both.
Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the
United States, other countries, or both.
UNIX is a registered trademark of The Open Group in the United States and other countries.
Java and all Java-based trademarks and logos are trademarks or registered trademarks of Oracle and/or
its affiliates.
Notices 27
28 Java Plug-in User Guide for IBM SPSS Statistics
Index
D
data
appending cases 9, 12
creating new variables 9, 11
reading active dataset from Java 9
dictionary
reading dictionary information from
Java 7
J
Java
DataUtil class 9
evaluateXPath method 15
Submit method 5
O
output
reading output results from Java 15
OXML
reading output XML from Java 15
P
pivot tables 19
R
running command syntax from Java 5
X
XML workspace 15
XPath expressions 15
29
30 Java Plug-in User Guide for IBM SPSS Statistics
Printed in USA