# Variable length records

**URL:** <https://forum.cloverdx.com/t/variable-length-records/430>\
**Category:** CloverDX Platform\
**Created:** [October 29, 2008, 12:00am UTC](https://forum.cloverdx.com/t/variable-length-records/430 "2008-10-29T00:00:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eontech](https://avatars.discourse-cdn.com/v4/letter/e/bc79bd/32.png) [@eontech](https://forum.cloverdx.com/u/eontech)\
**Post date:** [October 29, 2008, 12:00am UTC](https://forum.cloverdx.com/t/variable-length-records/430/1 "2008-10-29T00:00:00Z")

</div>

Hi,

I need to extract and validate data from file with fix-length .It has multiple records of different structure.Value of a field RECID identifies the record as header,detail or trailer record.RECID with value H1234 will be header,RECID with value D1234 will be detail and RECID with value T1234 will be trailer. File will have data in following format

H1234 12345 12345678901234567890 abcde  
D1234 12345 12345678901234567890 abcde abcde abc123 90  
D1234 12345 12345678901234567890 abcde abcde abc123 70  
T1234 12345 12345678901234567890

Please advice how above requirement can be acheived by CloverETL.

---

<div class="post-metadata">

**Author:** ![avackova](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@avackova](https://forum.cloverdx.com/u/avackova)\
**Post date:** [October 30, 2008, 8:18am UTC](https://forum.cloverdx.com/t/variable-length-records/430/2 "2008-10-30T08:18:30Z")

</div>

It is not possible to do it in one step. You have to read all data (one field with eol delimiter or mixed metadata) and then partition them. After partitioning you can write them to different files (and they are prepared for reading now) or validate in Reformat or Filter node.

---

<div class="post-metadata">

**Author:** ![avackova](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@avackova](https://forum.cloverdx.com/u/avackova)\
**Post date:** [January 19, 2009, 12:38pm UTC](https://forum.cloverdx.com/t/variable-length-records/430/3 "2009-01-19T12:38:49Z")

</div>

Hello,  
since 2.5 ver. you can use Reformat component with following transform function:

```auto
function transform() {
	string f4 = null;
	string f5 = null;
	string f6 = null;
	string f7 = null;
	int recType;
	list tmp = split($field3,' ');
	if (char_at($Field1,0).eq.'H') recType = 0; 
	else if (char_at($Field1,0).eq.'D') recType=1;
	else recType = 2;
	if (length(tmp) > 1) f4 = tmp[1];
	if (length(tmp) > 2) f5 = tmp[2];
	if (length(tmp) > 3) f6 = tmp[3];
	if (length(tmp) > 4) f7 = tmp[4];
	$0.field1 := $0.Field1;
	$1.field1 := $0.Field1;
	$2.field1 := $0.Field1;
	$0.field2 := $0.field2;
	$1.field2 := $0.field2;
	$2.field2 := $0.field2;
	$0.field3 := tmp[0];
	$1.field3 := tmp[0];
	$2.field3 := tmp[0];
	$0.field4 := f4;
	$1.field4 := f4;
	$1.field5 := f5;
	$1.field6 := f6;
	$1.field7 := f7;
	return recType
}

```
