# Pass variable as Reformat Port Output

**URL:** <https://forum.cloverdx.com/t/pass-variable-as-reformat-port-output/1411>\
**Category:** CloverDX Platform\
**Created:** [May 20, 2014, 12:00am UTC](https://forum.cloverdx.com/t/pass-variable-as-reformat-port-output/1411 "2014-05-20T00:00:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul.field](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@paul.field](https://forum.cloverdx.com/u/paul.field)\
**Post date:** [May 20, 2014, 12:00am UTC](https://forum.cloverdx.com/t/pass-variable-as-reformat-port-output/1411/1 "2014-05-20T00:00:00Z")

</div>

Is it possible to dynamically populate port numbers with variables?  
For example:

```auto
for (integer i = 0; i<=3; i++) {
		$out.i.Row = i;
	}

```

The above code would populate the port number in the field ‘Row’ for the first 4 (0-3) ports.

To put this in context, i’m looking for a solution to output to the “next available” port as way of handling nested rows that vary dependent on the input record.

Thanks,  
Paul

---

<div class="post-metadata">

**Author:** ![David\_Hlidek](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@David\_Hlidek](https://forum.cloverdx.com/u/David_Hlidek)\
**Post date:** [May 22, 2014, 1:51pm UTC](https://forum.cloverdx.com/t/pass-variable-as-reformat-port-output/1411/2 "2014-05-22T13:51:43Z")

</div>

Hi Paul,

you can achieve this by simple Java transformation like:

```auto

import com.opensys.cloveretl.ctl.CTLUtils;
import static com.opensys.cloveretl.ctl.CTLUtils.DECIMAL_MAX_PRECISION;

/**Top level class*/
public final class CTL_REFORMAT_22052014_15_47_15_278_0 extends org.jetel.component.CTLRecordTransform {

    /**Code from CTL function globalScopeInit()*/
    public final void globalScopeInit() throws org.jetel.exception.ComponentNotReadyException {
    }

    /**Code from CTL function transform()*/
    protected final java.lang.Integer transformDelegate() throws org.jetel.exception.ComponentNotReadyException, org.jetel.exception.TransformException {
	for (int i=0;i<3;++i) {
	    getOutputRecord(i).getField("field1").setValue(i);
	}

        return 2147483647;
    }
}

```

Sample graph attached.

- [test\_dynamic\_output.grf](https://cdn.cloverdx.com/forum/15157%5Fec5265b6d7a04f1d813b3eec0e5a05d8/test%5Fdynamic%5Foutput.grf)

---

<div class="post-metadata">

**Author:** ![paul.field](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@paul.field](https://forum.cloverdx.com/u/paul.field)\
**Post date:** [May 22, 2014, 6:48pm UTC](https://forum.cloverdx.com/t/pass-variable-as-reformat-port-output/1411/3 "2014-05-22T18:48:42Z")

</div>

This is great - thanks for the response.  
Is it possible to achieve this using CTL2? Or is this functionality only possible using Java? If the latter, would i be able to embed Java in my existing code (which is CTL2).

Thanks,  
Paul

---

<div class="post-metadata">

**Author:** ![David\_Hlidek](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@David\_Hlidek](https://forum.cloverdx.com/u/David_Hlidek)\
**Post date:** [May 23, 2014, 8:54am UTC](https://forum.cloverdx.com/t/pass-variable-as-reformat-port-output/1411/4 "2014-05-23T08:54:02Z")

</div>

Hi Paul,

Unfortunately this cannot be achieved by CTL2. You can either split your code into CTL2 and Java part and have 2 Reformats or convert your CTL2 code to Java. CTL2 can be converted into Java automatically - please see “Convert to Java” on [http://doc.cloveretl.com/documentation/ … ditor.html](http://doc.cloveretl.com/documentation/UserGuide/index.jsp?topic=/com.cloveretl.gui.docs/docs/transform-editor.html) for details.
