cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
bzanos
Level III

Code to Check If No Row Created in a of Data Table, Close the Data Table

I am creating a list data table subset from a main data table. Then, I manipulate the data through Tabulate() and make into the table for processing. Then, check each of the data table N Rows, if N Rows = 0, close the data table. Finally, append the data table into the report. Below is my script. 

 

The problem is after I add in below codes, to check the N Rows, it no longer work. No error show up.

If(N Rows(mDT)==0, Close(mDT, no save));

 

I believe might be some error on the code. The overall code might not be well written 

Need guideline and help here.

 

saveFolder = "$TEMP/";

listDT = {};
listtab = {};
mDT = {};

col = Column(dt1Sub, ":PART");

colLevs = Associative Array(col) << Get Keys;

hb = V List Box( );

For (i=1, i<=NItems(colLevs), i++,

     r2get = dt1 << Get Rows Where(:PART == colLevs[i]);

     listDT[i] = dt1 << Subset(Rows(r2get));

     listDT[i] << Set Name(Char(colLevs[i]));
 
     listDT[i] << Save( saveFolder || Word( 1, listDT[i] << get name, "-" )||".csv");
     
     listtab = listDT[i] << Tabulate(
	               Show Control Panel( 0 ),
	               Add Table(
		               Column Table( Grouping Columns( :ORDER ) ),
		               Column Table( Statistics( Sum ), Analysis Columns( :Qty ) ),
		               Row Table(
			               Grouping Columns(
				              ::PART,
				              ::PART DESC,
				              :LOW PART #,
				              :LOW PART DESC,
				              :FAILURE MODE
			               )
		               )
	               )
                ); 
                
     mDT= listtab << Make Into Data Table;   
     
     Close(listDT[i], no save);
    
     mDT << New Column ("Criteria", Character, "Nominal",
     	      Formula(
     	      	If(As Column(6)>= 3, "Failure")
     	      )
     );
     mDT:Criteria << Delete Formula;
     mDT << Sort(By(Column(6)),Order(Descending), Replace Table);
     mDT << Select Where (:As Column(6) == 0);
     mDT << Delete Rows;
     
     If(N Rows(mDT)==0, Close(mDT, no save));   
          
     mDT << Set Window Size (2400, 800);
     
     mDT << Get As Report;
     
     hb << Append( ( mDT << Get As Report ) );
          
);

New Window( "Report", hb );

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Code to Check If No Row Created in a of Data Table, Close the Data Table

It could be that you continue the loop execution after closing the datatable. You could try moving the rows in for loop after if-statement to else statement:

If(N Rows(mDT) == 0,
	Close(mDT, no save)
,//else
	mDT << Set Window Size(2400, 800);
	mDT << Get As Report;
	hb << Append((mDT << Get As Report));
);

or useContinue() after closing mDT:

If(N Rows(mDT) == 0,
	Close(mDT, no save)
	Continue();
);
-Jarmo

View solution in original post

txnelson
Super User

Re: Code to Check If No Row Created in a of Data Table, Close the Data Table

You are attempting to pass messages to your mDT object even when the table has been closed.  See if the JSL below works for you

saveFolder = "$TEMP/";

listDT = {};
listtab = {};
mDT = {};

col = Column( dt1Sub, ":PART" );

colLevs = Associative Array( col ) << Get Keys;

hb = V List Box();

For( i = 1, i <= N Items( colLevs ), i++,
	r2get = dt1 << Get Rows Where( :PART == colLevs[i] );
	listDT[i] = dt1 << Subset( Rows( r2get ) );
	listDT[i] << Set Name( Char( colLevs[i] ) );
	listDT[i] << Save( saveFolder || Word( 1, listDT[i] << get name, "-" ) || ".csv" );
	listtab = listDT[i] << Tabulate(
		Show Control Panel( 0 ),
		Add Table(
			Column Table( Grouping Columns( :ORDER ) ),
			Column Table( Statistics( Sum ), Analysis Columns( :Qty ) ),
			Row Table(
				Grouping Columns(
					::PART, ::PART DESC, :LOW PART #, :LOW PART DESC, :FAILURE MODE
				)
			)
		)
	); 
                
	mDT = listtab << Make Into Data Table;   
     
	Close( listDT[i], no save );
    
	mDT << New Column( "Criteria",
		Character,
		"Nominal",
		Formula( If( As Column( 6 ) >= 3, "Failure" ) )
	);
	mDT:Criteria << Delete Formula;
	mDT << Sort( By( Column( 6 ) ), Order( Descending ), Replace Table );
	mDT << Select Where( :As Column( 6 ) == 0 );
	mDT << Delete Rows;
     
	If( N Rows( mDT ) == 0,
		Close( mDT, no save )
		, 	           
		mDT << Set Window Size( 2400, 800 );
		mDT << Get As Report;
		hb << Append( (mDT << Get As Report) );
	);
);

New Window( "Report", hb );
Jim

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Code to Check If No Row Created in a of Data Table, Close the Data Table

It could be that you continue the loop execution after closing the datatable. You could try moving the rows in for loop after if-statement to else statement:

If(N Rows(mDT) == 0,
	Close(mDT, no save)
,//else
	mDT << Set Window Size(2400, 800);
	mDT << Get As Report;
	hb << Append((mDT << Get As Report));
);

or useContinue() after closing mDT:

If(N Rows(mDT) == 0,
	Close(mDT, no save)
	Continue();
);
-Jarmo
txnelson
Super User

Re: Code to Check If No Row Created in a of Data Table, Close the Data Table

You are attempting to pass messages to your mDT object even when the table has been closed.  See if the JSL below works for you

saveFolder = "$TEMP/";

listDT = {};
listtab = {};
mDT = {};

col = Column( dt1Sub, ":PART" );

colLevs = Associative Array( col ) << Get Keys;

hb = V List Box();

For( i = 1, i <= N Items( colLevs ), i++,
	r2get = dt1 << Get Rows Where( :PART == colLevs[i] );
	listDT[i] = dt1 << Subset( Rows( r2get ) );
	listDT[i] << Set Name( Char( colLevs[i] ) );
	listDT[i] << Save( saveFolder || Word( 1, listDT[i] << get name, "-" ) || ".csv" );
	listtab = listDT[i] << Tabulate(
		Show Control Panel( 0 ),
		Add Table(
			Column Table( Grouping Columns( :ORDER ) ),
			Column Table( Statistics( Sum ), Analysis Columns( :Qty ) ),
			Row Table(
				Grouping Columns(
					::PART, ::PART DESC, :LOW PART #, :LOW PART DESC, :FAILURE MODE
				)
			)
		)
	); 
                
	mDT = listtab << Make Into Data Table;   
     
	Close( listDT[i], no save );
    
	mDT << New Column( "Criteria",
		Character,
		"Nominal",
		Formula( If( As Column( 6 ) >= 3, "Failure" ) )
	);
	mDT:Criteria << Delete Formula;
	mDT << Sort( By( Column( 6 ) ), Order( Descending ), Replace Table );
	mDT << Select Where( :As Column( 6 ) == 0 );
	mDT << Delete Rows;
     
	If( N Rows( mDT ) == 0,
		Close( mDT, no save )
		, 	           
		mDT << Set Window Size( 2400, 800 );
		mDT << Get As Report;
		hb << Append( (mDT << Get As Report) );
	);
);

New Window( "Report", hb );
Jim
bzanos
Level III

Re: Code to Check If No Row Created in a of Data Table, Close the Data Table

it work perfectly. Thanks Jim and Jarmo