Using Varaibles in Script component

  • Hi All

    I'm sure that someone will have the answer and I'm sure it will be an easy answer as well.

    I've got a flat file which list a bunch of programs on the mainframe. When I list it, some of the first lines show which library it is in. When I get to the row data, it shows again the program name, type, cateloged etc.

    I want to get the library data from the input row, and then lateron use it again when I find the program name, Example

    DATA TVD,TVD001

    DATA TVD001

    1Logon accepted to library [highlight=#ffff11]TVD[/highlight].

    1NEXT L * *

    1 13:03:18 ***** NATURAL LIST COMMAND ***** 2010-05-05

    User TVD001 - List * * - Library TVD

    + TVD001 - List * * - TVD

    + TVD001 - List * * - TVD

    0 Name Type S/C SM Version User-ID Date Time Code Page

    -------- ----------- --- -- ------- -------- ---------- -------- --------------------------------

    [highlight=#ffff11]AA [/highlight]Program S S 2.2.07 FCZ064 1996-09-04 15:45:10

    [highlight=#ffff11]ABPAY [/highlight]Subprogram S/C S 2.2.08 CAD026 1998-06-19 14:33:04

    [highlight=#ffff11]ABSACRE [/highlight]Program S S 2.3.03 FCZ090 2000-03-25 15:12:13

    The first highlight is the library and the seconds are the programs. I need to populate them into 3 rows, each with the library and program name in the row details.

    I need to assign a global variable to the library when I read it in and then use it later on in the processing to assing again to a output row, but the variable is not avaiable to use only later on in the postexcute.

    Hope this makes sense

  • you talk about using the variable as the output row so I assume you are talking about using a script transform in a data flow is that correct?

    Dan

    If only I could snap my figures and have all the correct indexes apear and the buffer clean and.... Start day dream here.

  • You can assign values to variables within a Script Component if you use the VariableDispenser class.

    See more here.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Hi Dan, Yes that correct. I need to read in a value in row 10 for example and then use that 1 value later on when I get to the rest of the data and then populating the DB with the row data as well as the 1 value read in.

    Sorry about the posting layout as well, I had to rush out urgently yesterday when I posted the message.

  • Phil Parkin (5/5/2010)


    You can assign values to variables within a Script Component if you use the VariableDispenser class.

    See more here.

    Hi

    I saw that someone mentioned the VariableDispenser class but could not find any examples on, thanks for the link and I'll let you know what I figure out there. Many thanks

  • Well the answer was easy. The problem was that I didnt think!

    In the script component in the data flow, I wanted to get a value out of a row being read and then use that value in the following line. If you look at the script the Input0_ProcessInputRow cant access a variable and set, (I did try the variable dispenser as well, but could not get any luck with it), but what you can do is to create a variable outside of the sub routine, that simple!

    Example:

    [font="Verdana"]

    Public Class ScriptMain

    Inherits UserComponent

    Public sLibrary As String = ""

    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

    Dim sString As String

    '** going to check against it so make sure that there is no values in it

    Row.ObjectName = ""

    If Mid(Row.AllData, 1, 27) = "1Logon accepted to library " Then

    sLibrary = Replace(Mid(Row.AllData, 28, 8), ".", "")

    End If

    If Mid(Row.AllData, 26, 3) = "S/C" _

    And Mid(Row.AllData, 1, 16) <> "0 Name Type" Then

    Row.Library = sLibrary

    [/font]

  • I'm afraid you threw me off the track when you called it a global variable.

    VariableDispenser gives you access to package- or task-scoped variables - not locally declared variables within your script modules, which are scoped within only the script.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Hi Phil, sorry about that, but yesterday was mad and I really needed a solution thats why the post.

    But if I just used the correct terms......Something I've always struggled with 😀

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply