Mon Nov 29, 2021 9:39 pm
Login Register Lost Password? Contact Us

Split data from one logical file to many logical files.

Comments and questions related to the Enterprise Control Language

Mon Aug 07, 2017 11:47 am Change Time Zone


I have logical file on THOR of the following layout:

LayoutOne := RECORD
Unsigned2 ID;
STRING Field1;
STRING Field2;
STRING Field3;
STRING Field4;
STRING Field5;
STRING RecordDifferentiater;

The field RecordDifferentiater differentiates the data in the logical file in terms of the source from where the data has been gathered. Depending upon the value of RecordDifferentiater,
I wish to split the data from the logical file into different logical files at runtime. So every logical file that gets created will have a data from the same RecordDifferentiater.

For example:
If the base logical file has 10 records with 10 different RecordDifferentiater, I want to create 10 logical files at runtime.

Request your help in doing this. I tried using LOOP, but was not able to implemente the logic.

Thanks and regards,
Akhilesh Badhri.
Posts: 23
Joined: Thu Sep 22, 2016 12:15 pm

Mon Aug 07, 2017 1:17 pm Change Time Zone


You can try something like this:
Code: Select all
ds := DATASET(...);

SetDiffs := SET(TABLE(ds,{RecDiff},RecDiff),RecDiff);
CntDiffs := COUNT(SetDiffs);

LOOP(ds,CntDiffs, <loopbody> )
This is obviously pseudo code but the point is to split them out within the <loopbody> function by simple filtering like this:
Code: Select all
ThisDS := ds(RecDiff = SetDiffs[COUNTER]);


Community Advisory Board Member
Community Advisory Board Member
Posts: 1605
Joined: Wed Oct 26, 2011 7:40 pm

Tue Aug 08, 2017 12:45 pm Change Time Zone

Thanks a lot Richard.

Following is the code I am trying to execute:

namesRec := RECORD
STRING20 lname;
STRING10 fname;
UNSIGNED2 age := 25;
UNSIGNED2 ctr := 0;
namesTable2 := DATASET([{'Flintstone','Fred',35},
{'Mr. T','Z-man'},
{'Flintstone','Wilma',33}], namesRec);

SetDiffs := SET(TABLE(namesTable2,{lname},lname),lname);
CntDiffs := COUNT(SetDiffs);

loopBody(DATASET(namesRec) ds, unsigned4 c) := FUNCTION
ThisDs := PROJECT(namesTable2(lname = SetDiffs[c]),TRANSFORM(namesRec,SELF.ctr := c; SELF:=LEFT;));


The output I get is always the last of all the iterations. I tried using OUTPUT within the function (commented line). The output file also has the record of the last iteration.

Is there a way I can output records of all the iterations into different logical files.
Posts: 23
Joined: Thu Sep 22, 2016 12:15 pm

Return to ECL

Who is online

Users browsing this forum: rtaylor and 1 guest