Sean
Sean

Reputation: 37

How to solve the below scenario using transformer loop or anything in datastage

My data is like below in one column coming from a file.
Source_data---(This is column name)
CUSTOMER 15
METER 8
METERStatement 1
READING 1
METER 56
Meterstatement 14
Reading 5
Reading 6
Reading 7
CUSTOMER 38
METER 24
METERStatement 1
READING 51
CUSTOMER 77
METER 38
READING 9

I want the output data to be like below in one column

CUSTOMER 15 METER 8 METERStatement 1 READING 1
CUSTOMER 15 METER 56 Meterstatement 14 Reading 5
CUSTOMER 15 METER 56 Meterstatement 14 Reading 6
CUSTOMER 15 METER 56 Meterstatement 14 Reading 7
CUSTOMER 38 METER 24 Meterstatement 1 Reading 51
CUSTOMER 77 METER 38 'pad 100 spaces' Reading 9

I am trying to solve by reading transformer looping documentation but could not figure out an actual solution. anything helps. thank you all.

Upvotes: 1

Views: 1904

Answers (1)

MichaelTiefenbacher
MichaelTiefenbacher

Reputation: 4005

Yes this could be solved within a transformer stage. Concatenation is done with ":".

So use a stage variable to concat the input until a new "Meter" or "Customer" row comes up. Save the "Customer" in a second stage variable in case it does not change.

Use a condition to only output thew rows where a "Reading" exists.

Reset the concatenated string when a "Reading" has been processed.

I guess you want the padding for missing fields in general - you could do these checks in separate stage variables. You have to store the previous item inorder to kow wat is missing - and maybe even more if two consecutive items could be missing.

Upvotes: 1

Related Questions