FUNCTION nextino

parameter alias_nam,tag_nam,fld_nam,field_nam,pcSeries,pad_zero

private cur_rec,malias,lcfilt_con,lcField_value

lcField_value = 0
if para() = 4
	pcSeries = '0'
	pad_zero = .T.
endif	
if para() = 5
	pad_zero = .T.
endif	
malias = alia(alias_nam)
if eof(alias_nam) or bof(alias_nam)
	cur_rec = 0
else
	cur_rec = recn(alias_nam)
endif	
sele (alias_nam)
lcfilt_con = FILTER()
SET FILTER TO 
set orde to (tag_nam) desc
if empt(pcSeries) OR pcSeries == '0'
	LOCATE FOR &fld_nam > 0
	lcField_value = &fld_nam
else
	IF ! seek (pcSeries)
		IF EMPTY(pcSeries)
			field_nam = '1'
		ELSE
			field_nam = pcSeries + '1'
		endif		
	ENDIF
endif		
set orde to (tag_nam) asce
if pad_zero
	IF pcSeries <> '0'
		field_nam = pcSeries + padl(ltrim(str(val(subs(&fld_nam,len(pcSeries) + 1)) + 1)),len(&fld_nam) - len(pcSeries),'0')
	ELSE 
		field_nam = padl(ltrim(str(&fld_nam + 1)),len(&fld_nam),'0')
	ENDIF 
ELSE 
	field_nam = pcSeries + ltrim(str(val(subs(&fld_nam,len(pcSeries))) + 1))
endif		
if seek(field_nam)
	do alert with '!!! ERROR !!!;Duplicate No. was found while Generating NO;Run Reindex;Still Problem Exists Contect;WIPRA WORLDWIDE HELP DESK -(079) 26638556' + CHR(13) + CHR(13) + 'TABLE : ' + ALIAS() + '   ' + 'RECORD NO : ' + STR(RECNO()) + ' FIELD : ' + fld_nam + CHR(13) + 'VALUE : ' + lcField_value
	sele (malias)
	if cur_rec <> 0
		go (cur_rec) in (malias)
	endif	
	IF ! EMPTY(lcfilt_con)
		SET FILTER TO (lcfilt_con)
	ENDIF 
	retu .F.
else
	IF ! EMPTY(lcfilt_con)
		SET FILTER TO &lcfilt_con
	ENDIF 
	sele (malias)
	if cur_rec <> 0
		go (cur_rec) in (malias)
	endif	
	RETURN
ENDIF