Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
sagarjagga
Creator
Creator

Load and Write in a variable from text file

Hi All,

I want to load a variable in a table from a .txt file and then after want to change the value of the variable and again want to store the new value of the variable in the text file.

1 Solution

Accepted Solutions
petter
Partner - Champion III
Partner - Champion III

Do you wish to do this in a load script?

View solution in original post

2 Replies
petter
Partner - Champion III
Partner - Champion III

Do you wish to do this in a load script?

felipedl
Partner - Specialist III
Partner - Specialist III

Use the following script to take a specific variable, change it and write it to the file.

Data:

Load * Inline

[

Name,Value

A,1

B,2

C,3

D,4

];

Variables:

LOAD [Variable Name],

     [Variable Value]

FROM

(txt, codepage is 1252, embedded labels, delimiter is ',', msq);

NoConcatenate

_tmpVariables:

Load

*

Resident Variables

where [Variable Name]='A';

let A.VariableName = peek('Variable Name',0,'_tmpVariables');

let A.VariableValue = peek('Variable Value',0,'_tmpVariables');

drop table _tmpVariables;

// Changing the variable content

NoConcatenate

_tmpData:

Load

Name, Value

Resident Data

where Name = '$(A.VariableName)';

// New value for variable A

let A.VariableNewValue = peek('Value',0,'_tmpData');

// Gets all the variables that weren't used

NoConcatenate

_tmpNewVariableFile:

LOAD

*

Resident Variables

where [Variable Name] <> '$(A.VariableName)';

Concatenate(_tmpNewVariableFile)

Load

'$(A.VariableName)' as [Variable Name],

'$(A.VariableNewValue)' as [Variable Value]

AutoGenerate(1);

store _tmpNewVariableFile into New_test.txt (txt);

It will get the variable A, check the A field from the data table and overwrite the variable A value with the value from the Data table.

Just used to files (test.txt and New_test.txt) for demonstrating that it changes the file.