Global variables

Validate, clean, transform and transfer data.

Global variables

Postby andy.moss » Mon Mar 01, 2010 10:03 am

Just when I thought I'd got the hang of Global Variables it looks like they're not as Global as I thought !

I'm creating a script that picks up a job number from an external Excel sheet and uses that job number in the InputDataSource string. I've managed to open and pick up the job number fine in the OnBeforeJobStart section and tried to attach it to a Global variable to use in the connection string, but it looks like Global variables don't work until you get to the OnJobStart event (although that's too late to do what I want to do as it has to have a valid connection string by then).

There is some stuff in the DDL about CreateObject that I have to admit I don't fully (or really at all) understand :oops: . Can anyone suggest how I can get those seven tiny digits into a variable that can be used in the connection string. I thought I might be able to use something like DEFINE or CONST but I haven't been having much luck so far !

Thanks,
Andy
andy.moss
 
Posts: 23
Joined: Mon Jan 14, 2008 12:04 pm
Location: London, UK

Re: Global variables

Postby James Corriveau » Mon Mar 01, 2010 10:28 am

Unfortunately, I believe global variables only work in Event sections. So I don't think it'll work in Input, Output, or Metadata sections.
James Corriveau
 
Posts: 108
Joined: Tue Sep 05, 2006 12:07 pm
Location: Cincinnati, OH

Re: Global variables

Postby klaus » Mon Mar 01, 2010 11:04 am

Hi Andy,
I think Jamey is right. You could provide the Job number as a constant at the beginning of your DMS script. However this would need to be done before the job is starting by hand. This is probably not what you want to do.

So you could write a MRS script which reads the Excel file, extracts all needed details from there (i.e. the Job number) and places the according "#define" into a prepared DMS script. Afterwards this MRS script could simply start the DMS job. I've posted an according example from DDL a few days before, but here is the copy of this code snippet:
Code: Select all
    Dim DMOMJob

    Set DMOMJob = CreateObject("DMOM.Job")
    DMOMJob.Load("C:\Program Files\SPSS Dimensions\DDL\Scripts\Data Management\DMS\MyFirstTransfer.dms", null)
    DMOMJob.Run()

You would have to insert a portion of code before the "DMOMJob.Load" that creates the DMS script, i.e. modifes a prepared script by adding some global defines to this script. And of course you need to insert the name of your DMS script! 8)

The thing behind the global variables is that they are bound to the "Job" object. In a DMS job this object only exists in the period from "OnJobStart" until "OnJobEnd". Outside this part the job object does not exist and so you cannot access the global variables for the object.

I hope this helps.
Klaus
Klaus Danker
datab GmbH, Frankfurt, Germany
klaus
 
Posts: 105
Joined: Tue Jan 29, 2008 7:02 am
Location: datab GmbH, Frankfurt, Germany

Re: Global variables

Postby andy.moss » Mon Mar 01, 2010 11:43 am

Thanks for the replies. I was thinking about something along the lines you mentioned Klaus, so I think that seems the way to go.

Playing around I have discovered that you can define a DEFINE subsitution within the onbefore ... event but it takes the actual text rather than the value (e.g. DEFINE job_ no my_name make job_no equal "my_name" rather than the value that is in my_name).
andy.moss
 
Posts: 23
Joined: Mon Jan 14, 2008 12:04 pm
Location: London, UK

Re: Global variables

Postby andy.moss » Mon Mar 01, 2010 12:19 pm

Agggg. One last question (promise). Has anyone had any luck passing defined text into a DMOM job. I couldn't get it to work but then found a post from SPSS's knowledgebase that suggests maybe you can't do it (at least prior to v5.6). Which won't be good news. :cry:

http://support.spss.com/tech/troublesho ... t=mrStudio
andy.moss
 
Posts: 23
Joined: Mon Jan 14, 2008 12:04 pm
Location: London, UK

Re: Global variables

Postby klaus » Tue Mar 02, 2010 12:28 pm

Hi Andy,
I'm not sure if I got your query right. As far as I know the "dmsrun" command is able to take some arguments. Amongst those the is the flag "/d which should take the values for values that otherwise would have been defined in the script using "#define". So if you want to provide such a constant like "PROJECT" you shoud be able to start your script writing something like
Code: Select all
dmsrun yourscript.dms /d"PROJECT \"pr12345\""

This at least does work for me. It is a bit tricky to get the thing with the escape'd '"' for the string that is used as substitution for the constant "FILE". Things appear to get even worse when you want to set a path name through such an argument. I encountered some problems I haven't figured out yet. But so far this worked for me (at version 5.5.005). I know that I've tried this with earlier versions as well but not yet at 5.6.

Regards,
Klaus
Klaus Danker
datab GmbH, Frankfurt, Germany
klaus
 
Posts: 105
Joined: Tue Jan 29, 2008 7:02 am
Location: datab GmbH, Frankfurt, Germany


Return to Data Management

Who is online

Users browsing this forum: No registered users and 1 guest