Desktop User Guides > Professional > Data management scripting > Data Management Script (DMS) file > Sections in the DMS file > Event section > Using objects in the Event section > Objects in the OnBeforeJobStart Event section
 
Objects in the OnBeforeJobStart Event section
The OnBeforeJobStart Event section defines procedural code that is to be executed before any of the data sources are opened. For example, code that uses the Metadata Model to Quantum component to set up card, column, and punch specifications for use when exporting case data to a Quantum .dat file, or that sets up custom properties to customize an export to a .sav file. For more information, see Transferring data to IBM SPSS Statistics.
In this section you do not have access to any variables you are creating in the Metadata section. However, you can access the new variables in the OnAfterMetaDataTransformation Event section, and if necessary you can set up card, column, and punch definitions and other custom properties for them there.
When exporting proprietary data, you can set up an .mdd file in the OnBeforeJobStart Event section and then specify the .mdd file as the input metadata source in the InputDataSource section. For more information, see Creating an .mdd file from proprietary metadata.
The Job object, and the other objects to which it gives access, are not available in the OnBeforeJobStart Event sections. You need to use the CreateObject function to access any object in this section.
Example
The following example shows a DMS file that contains an OnBeforeJobStart Event section that uses the Metadata Model to Quantum component to set up card, column, and punch definitions in the input metadata so that the case data can be exported to a Quantum .dat file using the Quantum DSC. It also uses the new MDSC capability of Quantum DSC to create a basic Quantum specification based on the card, column, and punch definitions. For more information, see The Quantum specification.
#define COPY_OF_MUSEUM_MDD "C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Output\museum.mdd"

Event(OnBeforeJobStart, "Set up the card and column definitions")
Dim M2Q, MDM, MyDataSource, fso, f

' Create a copy of museum.mdd
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile("C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Data\Data Collection File\museum.mdd", _
COPY_OF_MUSEUM_MDD, True)

' Make sure that the read-only attribute is not set
Set f = fso.GetFile(COPY_OF_MUSEUM_MDD)
If f.Attributes.BitAnd(1) Then
f.Attributes = f.Attributes - 1
End If

' Create the MDM object and open the Museum .mdd file in read-write mode
Set MDM = CreateObject("MDM.Document")
MDM.Open(COPY_OF_MUSEUM_MDD)

' Check whether a Quantum DSC DataSource object already exists
On Error Resume Next
Set MyDataSource = MDM.DataSources.Find("mrpunchdsc")
If MyDataSource Is Null Then
' Create a Quantum DSC DataSource object if one doesn't already exist
Set MyDataSource = MDM.DataSources.AddNew("mrPunchDsc", "mrPunchDsc", "MDM2Quantum.dat")
End If
Set MDM.DataSources.Current = MyDataSource
Err.Clear()
' Disable error handling...
On Error Goto 0

' Create the MDM2Quantum object
Set M2Q = CreateObject("MDM2QuantumLib.MDM2Quantum")

' Set the MDM Document into the MDM2Quantum object
Set M2Q.MDMDocument = MDM

' Set the MDM2Quantum properties to use the standard Quantum
' setting of multiple cards with 80 columns. Delete these lines
' if you want to use one card of unlimited length

M2Q.SerialFullName = "Respondent.Serial"
M2Q.SerialColCount = 5
M2Q.CardNumColCount = 2
M2Q.CardNumColStart = 6
M2Q.CardSize = 80

' Run the allocation
M2Q.AllocateCardColPunch(True)

' Write the data map to a .csv file using the
' Now function to create a unique filename
M2Q.WriteToCommaSeparatedFile("C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Output\MDM2Quantum." + CText(CDouble(Now())) +
".csv")

' Save the Museum .mdd file
MDM.Save()

' Use the DSC Registration component to find Quantum DSC
Dim DMComp, dscQuantum
Set DMComp = CreateObject("MRDSCReg.Components")
Set dscQuantum = DMComp.Item["mrPunchDsc"]

' Write out the specs
dscQuantum.Metadata.Save(MDM, "C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Output\Museum\Museum", Null)

MDM.Close()

End Event

InputDataSource(myInputDataSource)
ConnectionString = "Provider=mrOleDB.Provider.2; _
Data Source=mrDataFileDsc; _
Location=C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Data\Data Collection File\museum.ddf; _
Initial Catalog=" + COPY_OF_MUSEUM_MDD
End InputDataSource

#define Target "MDM2Quantum"
#Include "C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Scripts\Data Management\DMS\Include\QuantumOutput.dms"
This example is provided as a sample DMS file (called MDM2Quantum.dms) that is installed with the UNICOM Intelligence Developer Documentation Library. For more information, see Sample DMS files.
See
Event section