Developer Documentation Library > Data Model > Accessing the UNICOM Intelligence Data Model > Working with the Metadata Model > Working with the Metadata Model: Tutorial > Introduction to versions
 
Introduction to versions
MDM Documents support multiple versions. This means you can incorporate several versions of a Document in an .mdd file. The precise method used to do this depends on which UNICOM Intelligence product the file is used with.
In the case of UNICOM Intelligence Interviewer - Paper, you might have to add another question at the last minute, that is, just before publishing your carefully-formatted questionnaire. UNICOM Intelligence Interviewer - Paper stores information in the metadata about which Looks are to be used for different questions, and if you overwrite the .mdd file, you will lose this information. If you create a new version, the changes are added to the file while preserving the original information about each question's Look. So if you are simply adding a question, you only need to format, or apply a Look to, the newly-added question.
To understand versioning in MDM, first generate version one of the MDM Document using the following mrScriptBasic code.
Dim MyDocument, MyRouting, MyVariable, MyVersion

Set MyDocument = CreateObject("MDM.Document")

' Include some properties
With MyDocument
.Languages.Add("ENU")
.Languages.Base = "ENU"
.IncludeSystemVariables = True
.Contexts.Add("Question")
.Contexts.Base = "Question"
.RoutingContexts.Add("PAPER")
.RoutingContexts.Base = "PAPER"
.url = "C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Output\Versioning.mdd"
' url sets location of file
End With

MyDocument.Versions.AddNew() ' Creates the first version
Set MyVersion = MyDocument.Versions[MyDocument.Versions.Count - 1]

Set MyVariable = MyDocument.CreateVariable("Name")
MyVariable.Labels["Label"].Text["Question"]["ENU"] = "What is your name?"
MyVariable.DataType = mr.Text
MyDocument.Fields.Add(MyVariable)

Set MyRouting = CreateObject("MDM.RoutingItem")
Set MyRouting.Item = MyDocument.Fields["Name"]

MyDocument.Routing.Add(MyRouting, "Paper")

MyVersion.Lock() ' Locks the current version and saves the file

MyDocument.Close()
A similar example in VB.NET is:
Private Sub Generate_Version_One()
Dim MyDocument As MDMLib.Document
Dim MyRouting As MDMLib.RoutingItem
Dim MyVariable As MDMLib.IVariable2
Dim MyVersion As MDMLib.Version

MyDocument = New MDMLib.Document

' Include some properties
With MyDocument
.Languages.Add("ENU")
.Languages.Base = "ENU"
.IncludeSystemVariables = True
.Contexts.Add("Question")
.Contexts.Base = "Question"
.RoutingContexts.Add("PAPER")
.RoutingContexts.Base = "PAPER"
.url = " [INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\DDL\Output\Versioning.mdd"
' url sets location of file
End With

MyDocument.Versions.AddNew() ' Creates the first version
MyVersion = MyDocument.Versions(MyDocument.Versions.Count - 1)

MyVariable = MyDocument.CreateVariable("Name")
MyVariable.Labels("Label").Text("Question", "ENU") = "What is your name?"
MyVariable.DataType = MDMLib.DataTypeConstants.mtText
MyDocument.Fields.Add(MyVariable)

MyRouting = New MDMLib.RoutingItem
MyRouting.Item = MyDocument.Fields("Name")

MyDocument.Routing.Add(MyRouting, "Paper")

MyVersion.Lock() ' Locks the current version and saves the file

MyDocument.Close()
End Sub
This example creates a text question and adds it to an UNICOM Intelligence Interviewer - Paper routing. The With MyDocument .. End With block adds system variables, base context, base routing context, and sets the URL property for the Document. (The URL is simply the path to where the file will be stored.)
The line MyDocument.Versions.AddNew() adds a version to the Document. At this point the Document contains one version.
The line MyVersion.Lock() locks the current working version, and saves the Document to the file specified in the URL property. When adding a version to a Document, the Lock method can be used instead of Save.
The following mrScriptBasic example adds a new version containing an additional variable to the .mdd file.
Dim MyDocument, MyVariable, MyRouting, MyVersion, fso

Const TARGETDOC = "C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Output\versioning2.mdd"

' Work on a copy of the versioning.mdd file so that
' we do not update the original file
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile("C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Output\versioning.mdd", _
TARGETDOC, True)

Set MyDocument = CreateObject("MDM.Document")

MyDocument.Open(TARGETDOC, , MDMLib.openConstants.oREADWRITE)

' Add a new version to the Document
MyDocument.Versions.AddNew()

' Create a new variable in the second version of the Document
Set MyVariable = MyDocument.CreateVariable("Spend")
MyVariable.DataType = mr.Long
MyVariable.Labels["Label"].Text["Question"]["ENU"] = _
"How much do you spend on our products?"
MyDocument.Fields.Add(MyVariable)

Set MyRouting = CreateObject("MDM.RoutingItem")
Set MyRouting.Item = MyDocument.Fields["Spend"]
MyDocument.Routing.Add(MyRouting, "Paper")

Set MyVersion = MyDocument.Versions[MyDocument.Versions.Count - 1]
MyVersion.Lock()

MyDocument.Close()
A similar example in VB.NET is:
Private Sub Generate_Version_Two()
Dim MyDocument As MDMLib.Document
Dim MyVariable As MDMLib.IVariable2
Dim MyRouting As MDMLib.RoutingItem
Dim MyVersion As MDMLib.Version

MyDocument = New MDMLib.Document

MyDocument.Open(" [INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\DDL\Output\Versioning.mdd")

' Add a new version to the Document
MyDocument.Versions.AddNew()

' Create a new variable in the second version of the Document
MyVariable = MyDocument.CreateVariable("Spend")
MyVariable.DataType = MDMLib.DataTypeConstants.mtLong
MyVariable.Labels("Label").Text("Question", "ENU") = _
"How much do you spend on our products?"
MyDocument.Fields.Add(MyVariable)

MyRouting = New MDMLib.RoutingItem
MyRouting.Item = MyDocument.Fields("Spend")
MyDocument.Routing.Add(MyRouting, "Paper")

MyVersion = MyDocument.Versions(MyDocument.Versions.Count - 1)
MyVersion.Lock()

MyDocument.Close()
End Sub
This example loads the .mdd file and calls the MyDocument.Versions.AddNew method to create the second version of the Document. Then a numeric variable is created and added to the UNICOM Intelligence Interviewer - Paper routing, and finally, the Document is locked.
It is then possible to open the .mdd file in UNICOM Intelligence Interviewer - Paper. The UNICOM Intelligence Interviewer - Paper Open Questionnaire dialog allows you to select which version of a Document you want to open. If the first version is loaded, only the first text question is displayed. If the second version is loaded, both questions are displayed.
It does not matter what changes you perform on a Document from one version to another. You might choose to add questions, alter a label, or perhaps remove an entire routing collection.
Requirements
See Requirements.
Optional: Microsoft Visual Basic .NET 2003
Next topic
Document Information
See also
Working with the Metadata Model: Tutorial
Creating and saving a variable