Changing an SSIS dts variables - sql-server-2005

In an SSIS package I have a For..Each container that enumerates all (.) the files in a folder.
In that For..Each container I have a component-level variable 'fileComments' of DataType 'String'.
In that For..Each container I have a script task. With a ReadWrite entry for 'filecomments' (amongst others)
In that script task, I have some code :-
Dim Comments As String = Dts.Variables("User::fileComments").ToString
which allows me to read the value of that variable, but if I try to allocate a value back to that variable, I get a Property 'Item' is 'ReadOnly' blue squiggly underline.
How do I change the vlaue of that variable (or get the value out of the script task so I can use it later in the flow) ?
Thanks in advance.

your problem is a common trap check this article out:
http://www.programmersedge.com/?p=1350
you basically need to use the Dts.VariableDispenser object to lock or declare the variable as read / write in the script task.

Related

ASSIGN fails with variable from debugger path

I am trying to assign the value of this stucture path to a fieldsymbol, but this path does not work because it has a table in it's path.
But with in the debugger this value of this path is shown correctly.
Is there a way to dynamically assign a component of a table line to a fieldsymbol, by passing one path?
If not then I will just read the table line and then use the path to get the wanted value.
ls_struct (Struct)
- SUPPLYCHAINTRADETRANSACTION (Struct)
- INCL_SUPP_CHAIN_ITEM (Table)
- ASSOCIATEDDOCUMENTLINEDOCUMENT (Element)
i_component_path = |IG_DDIC-SUPPLYCHAINTRADETRANSACTION-INCL_SUPP_CHAIN_ITEM[1]-ASSOCIATEDDOCUMENTLINEDOCUMENT|.
ASSIGN (i_component_path) TO FIELD-SYMBOL(<lg_value>).
IF <lg_value> IS NOT ASSIGNED.
return.
ENDIF.
<lg_value> won't be assigned
Solution by Sandra Rossi
The debugger has its own syntax and own logic, it doesn't apply the ASSIGN algorithm at all. With ABAP source code, you have to use ASSIGN twice, the first one to reach the internal table, then you select the first line, and the second one to reach the component of the line.
The debugger works completely differently, the debugger code works only in debug mode, you can't call the code from the debugger (i.e. if you call it, the kernel code used by the debugger will fail). No, there's no "abappath". There are the XSL transformation objects (xpath), but it's slow for what you ask.
Thank you very much
This seems to be a rather unexpected limitation of the ASSIGN statement. Probably worth a ticket to SAP's ABAP language group to clarify whether it's even a bug.
While this works:
ASSIGN data-some_table[ 1 ]-some_field TO FIELD-SYMBOL(<lv_source>).
the same expressed as a string doesn't:
ASSIGN (`data-some_table[ 1 ]-some_field`) TO FIELD-SYMBOL(<lv_source>).
Alternative 1 for (name) of the ABAP keyword documentation for the ASSIGN statement says that "[t]he name in name is structured in the same way as if specified directly".
However, this declaration is immediately followed by "the content of name must be the name of a data object which may contain offsets and lengths, structure component selectors, and component selectors for assigning structured data objects and attributes in classes or objects", a list that does not include the table expressions we would need here.

Pentaho variables at JVM level

Using set variables step in pentaho, I have defined a variable and the scope is set to "valid in the Java virtual machine", but it is not replacing in one of the sql's used in the table input step.
Table input step is checked with option "replace variables in script". But the same variable when I placed in kettle.properties file, it is working. Pentaho job available in the repository and running from Linux box
Could anyone please share your thoughts?
You can-not set the parameter and use it in the same transformation, because it executes all the steps parallelly.
Logic-wise correct approach is first set the variable and get the variable in next transformation and further use or replace in respected steps.
As Working Hard.. says, you can not use a parameter in the same transformation, you have to use another transformation after setting the variables.

dynamically generate file with last day of previous month in ssis

I need to generate a file with last day of month using SSIS. I am getting it using SQL.
DECLARE #mydate DATETIME
SELECT #mydate = '03/21/2013'
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(#mydate)),#mydate),112)
--20130228
I dont know how to put it in SSIS expression in connection manager.
The file name will be like 'ABC_20130228.txt'
I would assign the date to a variable in SSIS, then pass that variable to a script task that builds the file name and puts that in an output variable. Then you can assign the output variable in the ConnectionString property under the Expressions property group in the properties for the Connection Manager for that output file to use the variable's value as your file name.
to Summarize:
Use a script task and pass the date to use in the file name to it as a read only variable as type string to make it easier to manipulate.
Assign a read/write variable to the script task to store your file name.
Create the file name in the script task.
Variables named: User::DataFile, User::MaxDate
ie String DataFileName;
String DateToUse;
DateToUse= (String) Dts.Variables["MaxDate"].value;
DataFileName="ABC_"+Convert.ToString((Convert.ToDateTime(DateToUse)).Year)+Convert.ToString((Convert.ToDateTime(DateToUse)).Month)+Convert.ToString((Convert.ToDateTime(DateToUse)).Day)+".txt";
Dts.Variables["DataFile"].value=DataFileName;
Assign the variable in the Expression sections of the properties for the Connection Manager to the CONNECTIONSTRING property.
That should do it. If you need a particular path, then that would be concatenated onto the property and variable in step 4.
Why use a script task? Why not use the expression described here:
Add datestamp to a .txt file in an SSIS Package?

how to store sql query result in a variable and messegeBox

I have a simple sql query in my Execute sql task in ssis package,
SELECT MAX(binindex)
FROM dbo.myTable
I need to store this maximum index into a variable and then pass it to Script Task and display it,
I already declared a package variable, the package compiles, however it shows -1 every time, I don't know what I'm doing wrong, any help will be appreciated!
public void Main(){
//TODO: Add your code here
Dts.TaskResult = (int)ScriptResults.Success;
MessageBox.Show(Dts.Variables["User::BININDEX"].Value.ToString());
}
The good news, is that you are doing everything correctly as far as I can see. I recreated your package and I get the expected value from my query.
I can also induce your situation - the correct value is returned from my query but my package produces an "incorrect result."
The problem, I hope, is that you have two BININDEX variables defined at different scopes. My original assumption was the Package scoped one contained a value of -1 and you had a variable scoped to the "Execute SQL Task" with the same name. The default behaviour is a variable is created scoped to the object that currently has focus. This changes in the 2012 release of SQL Server by the way.
As your picture shows a design-time value of 123 for the package scoped variable, the possibility also exists that you have a variable defined on the Script Task with the same name of BININDEX. The local variable would override the globally scoped variable
Click on your Script Task and hopefully you'll see a BININDEX defined there like the above. Otherwise, I think the problem is somewhere in your package, you have conflicting BININDEX variables. You can try slogging through the Package Explorer looking for an instance where you have two variables with the same name listed.
I need to leave but if none of that is the case, add a PostExecute breakpoint on the Execute SQL Task and look at your Locals window (not Variables as that only reflects Design-time values). Expand Variables and you should be able to see the value of BININDEX. Is it correct there?

SSIS set variable at runtime

Anyone know how I can change a SSIS variable at runtime?
I have a variable User:SkipStuff
I want to set this based on a condition during a for loop container
Use Expression Task instead. In the "Expressions" pane, put the variable to set on left, then equates it to the intended value.
#[User::VariableToSet] = some expressions...
You can add a Script task. Add your SSIS variable(s) to the ReadWriteVariables property in the Script Task Editor.
You can reference the variable(s) in your script using the following format: Dts.Variables["MyCaseSensitiveVariableName"].Value
Lots of ways really, but the one I use most frequently is to use an execute SQL task and set the result set to single row and then put the results set into the variable.