PRIVATE conditn_flg,lctmp_wind,lcfilt_con
lcfilt_con = ''
lctmp_wind = SYS(2015)
conditn_flg = 'N'
do set_menu
conditn_flg = get_pnam('PENDING SPARES ORDER (Order No. Wise)',.T.)
IF conditn_flg = 'Y'
	SELECT order_no,order_dt,SPACE(1) as sele_flg ;
		FROM monthord ;
		ORDER BY order_dt,order_no ;
		INTO CURSOR query ;
		READWRITE 
	DEFINE WINDOW (lctmp_wind) FROM 5,5 TO 20,50
	BROWSE FIELDS order_dt :h= 'ORDER DT.' :W= .f.,order_no :h= 'ORDER NO.' :W= .f. , ;
		SELE_FLG :H= 'SELECT (Y/N)' :P= 'Y' ;
		title '*** PLEASE GIVE Y FOR SELECTING ORDER ***' ;
		NOAP NODEL 
	PRIVATE lcorder_list
	lcorder_list = ''
	SCAN FOR sele_flg = 'Y'
		lcorder_list = lcorder_list + IIF(EMPTY(lcorder_list),'',',') + "'" + order_no + "'"
	ENDSCAN 
	USE IN query 
	IF ! EMPTY(lcorder_list)
		lcfilt_con = ' and INLIST(monthord.order_no,' + lcorder_list + ')'
	ENDIF 
ENDIF 

Wait Wind '!!! WAIT !!! Gathering Data Using SQL ..' nowa
sele monthbod.order_no,monthbod.item_no,itemmast.item,monthbod.qty, ;
		 monthbod.received,qty - monthbod.received as pending, ;
		 (qty - monthbod.received) * monthbod.rate as pend_amt, ;
		 monthord.order_dt ;
	 from monthbod,itemmast,monthord ;
	 where monthord.order_no = monthbod.order_no ;
	 	and itemmast.item_no = monthbod.item_no ;
	 	and monthbod.qty - monthbod.received > 0 ;
	 	&lcfilt_con ;
	 order by monthbod.order_no ;
	 into curs query

wait wind '!!! WAIT !!! Generating Report ..' nowa
do prinrepo with 'WPEND_OR','PEND_ORD','','','' 
USE IN query
do cls_menu