<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic tJava - records count in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/tJava-records-count/m-p/2328154#M97461</link>
    <description>I am trying to count number of records in t JAVA components. Reading one row at a time.
&lt;BR /&gt;If data value = 'POLICY' then policycount = policycount + 1&amp;nbsp; and then i just want the total at the end
&lt;BR /&gt;elseif data value = 'CUST' then custcount = custcount + 1..
&lt;BR /&gt;Please help.</description>
    <pubDate>Sun, 10 Apr 2016 23:50:23 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-04-10T23:50:23Z</dc:date>
    <item>
      <title>tJava - records count</title>
      <link>https://community.qlik.com/t5/Talend-Studio/tJava-records-count/m-p/2328154#M97461</link>
      <description>I am trying to count number of records in t JAVA components. Reading one row at a time.
&lt;BR /&gt;If data value = 'POLICY' then policycount = policycount + 1&amp;nbsp; and then i just want the total at the end
&lt;BR /&gt;elseif data value = 'CUST' then custcount = custcount + 1..
&lt;BR /&gt;Please help.</description>
      <pubDate>Sun, 10 Apr 2016 23:50:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/tJava-records-count/m-p/2328154#M97461</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-04-10T23:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: tJava - records count</title>
      <link>https://community.qlik.com/t5/Talend-Studio/tJava-records-count/m-p/2328155#M97462</link>
      <description>Hi&amp;nbsp; 
&lt;FONT size="1"&gt;&lt;FONT face="Verdana, Helvetica, Arial, sans-serif"&gt;Sangita&lt;/FONT&gt;&lt;/FONT&gt;, 
&lt;BR /&gt;Using tJavaRow will make it easier as it supports both/either of the input row and output row from/to other components. 
&lt;BR /&gt;For your example, we can make use of the tJavaRow with an input row only.&amp;nbsp; 
&lt;BR /&gt;Here in tJavaRow component you can write your own logic in Java to calculate, hold, and print values like tJava.&amp;nbsp; 
&lt;BR /&gt;There is another component named tJavaFlex can also be used for this purpose. In that case the input column names are referred as per the link name construct, like 
&lt;BR /&gt; 
&lt;PRE&gt;//Assigning a value from incoming row;&lt;BR /&gt;String tempvalue = row23.data_value;&lt;BR /&gt;//The rest of the logic remains the same&lt;/PRE&gt; 
&lt;BR /&gt;. 
&lt;BR /&gt;using tJavaRow component: 
&lt;BR /&gt; 
&lt;PRE&gt;//Initialize variables to hold the count&lt;BR /&gt;//Note:- if the count is anticipated to exceed the integer limit,&lt;BR /&gt;//then recommended to use long data type&lt;BR /&gt;int pol_count = 0;&lt;BR /&gt;int cust_count = 0;&lt;BR /&gt;//conditional statement to check the data_value&lt;BR /&gt;//the input row column is represented by input_row.column_name&lt;BR /&gt;if ( ("POLICY").equals(input_row.data_value) ) {&lt;BR /&gt;	//the policy count is being held using pol_count variable.&lt;BR /&gt;	pol_count++;&lt;BR /&gt;}&lt;BR /&gt;else {&lt;BR /&gt;	if ( ("CUST").equals(input_row.data_value) ) {&lt;BR /&gt;	cust_count++;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;//The held counts can be printed using the sysout&lt;BR /&gt;System.out.println("Policy_Count : "+ pol_count + "\nCust_Count : "+ cust_count);&lt;BR /&gt;&lt;/PRE&gt; 
&lt;BR /&gt; 
&lt;BR /&gt;Note: I am not a java person yet, so if there are any syntax errors, please correct them and let me know 
&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009MACn.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/154443iC5B8CACEF3D12C6A/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009MACn.png" alt="0683p000009MACn.png" /&gt;&lt;/span&gt;</description>
      <pubDate>Mon, 11 Apr 2016 04:54:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/tJava-records-count/m-p/2328155#M97462</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-04-11T04:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: tJava - records count</title>
      <link>https://community.qlik.com/t5/Talend-Studio/tJava-records-count/m-p/2328156#M97463</link>
      <description>thanks for the reply. 
&lt;BR /&gt;when I try to print&amp;nbsp; 
&lt;FONT size="2"&gt;&lt;FONT face="consolas, monaco, 'bitstream vera sans mono', 'courier new', courier, monospace"&gt;pol_count , I get 0 value, instead of 15(since total pol_count records are 15).&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;BR /&gt; 
&lt;FONT size="2"&gt;&lt;FONT face="consolas, monaco, 'bitstream vera sans mono', 'courier new', courier, monospace"&gt;pol_counts get reset once I am out of if else statement.&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;BR /&gt; 
&lt;FONT size="2"&gt;&lt;FONT face="consolas, monaco, 'bitstream vera sans mono', 'courier new', courier, monospace"&gt;once I find pol_count, I want to use this total and print when data value = "TRA" in the next if else statements.&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;BR /&gt; 
&lt;FONT size="2"&gt;&lt;FONT face="consolas, monaco, 'bitstream vera sans mono', 'courier new', courier, monospace"&gt;Ex: &lt;/FONT&gt;&lt;/FONT&gt; 
&lt;FONT size="2"&gt;&lt;FONT face="consolas, monaco, 'bitstream vera sans mono', 'courier new', courier, monospace"&gt;if ( ("POLICY").equals(input_row.data_value) ) {&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;BR /&gt; 
&lt;FONT size="2"&gt;&lt;FONT face="consolas, monaco, 'bitstream vera sans mono', 'courier new', courier, monospace"&gt;//the policy count is being held using pol_count variable.&lt;BR /&gt; pol_count++;&lt;BR /&gt;}&lt;BR /&gt;else {&lt;BR /&gt; if ( ("CUST").equals(input_row.data_value) ) {&lt;BR /&gt; cust_count++;&lt;BR /&gt; } &lt;BR /&gt; }&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;BR /&gt; 
&lt;BR /&gt; 
&lt;FONT face="consolas, monaco, bitstream vera sans mono, courier new, courier, monospace"&gt;&lt;FONT size="2"&gt;if &lt;/FONT&gt;&lt;/FONT&gt; 
&lt;FONT size="2"&gt;&lt;FONT face="consolas, monaco, 'bitstream vera sans mono', 'courier new', courier, monospace"&gt;("TRA").equals(input_row.data_value) )&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;BR /&gt; 
&lt;FONT face="consolas, monaco, bitstream vera sans mono, courier new, courier, monospace"&gt;&lt;FONT size="2"&gt;output_row.line = "policy_total"+pol_count+"cust total"+cust_count;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;BR /&gt; 
&lt;BR /&gt; 
&lt;BR /&gt; 
&lt;FONT face="consolas, monaco, bitstream vera sans mono, courier new, courier, monospace"&gt;&lt;FONT size="2"&gt;then I will wite output_row.line to flat file&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;BR /&gt; 
&lt;BR /&gt; 
&lt;FONT face="consolas, monaco, bitstream vera sans mono, courier new, courier, monospace"&gt;&lt;FONT size="2"&gt;Thanks again.&lt;BR /&gt;&lt;/FONT&gt;&lt;/FONT&gt;</description>
      <pubDate>Mon, 11 Apr 2016 17:21:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/tJava-records-count/m-p/2328156#M97463</guid>
      <dc:creator>_AnonymousUser</dc:creator>
      <dc:date>2016-04-11T17:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: tJava - records count</title>
      <link>https://community.qlik.com/t5/Talend-Studio/tJava-records-count/m-p/2328157#M97464</link>
      <description>You can use gnan.ram's&amp;nbsp;solution, but you should use the tJavaFlex instead of the tJavaRow. The reason for this is that you can instantiate your variables for counting in the "Start Code" section. This code is run at the start of the subjob, then the "Main Code" section is run for every row. With the tJavaRow, all of the code you use is run on every row which means variables are instantiated for every row.</description>
      <pubDate>Mon, 11 Apr 2016 20:01:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/tJava-records-count/m-p/2328157#M97464</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-04-11T20:01:22Z</dc:date>
    </item>
  </channel>
</rss>

