A Code for Part Structure Comparison
since 9 April, 1999 last modified 9 April, 1999


Description

This program compares two part structures(two tree structures). Each structure consists of parts and their relationship (VPM PART_LIST and $EXT tables are used for the part and relationship, respectivly.). It compares two part lists(old and new) for each layer of the trees, and drill down to the sub parts, if it finds two parts from each list that have version relationship(replaced). If there is no version related parts in the lists, the program just denotes "same", "add" and "delete" tags for each case.

Known Problems

<@ Language=VBScript >

' ==============================
'  comparison.asp
'------------------------------
' indentation
'------------------------------
SUB Indent(level)
	FOR i = 0 TO level-1
		response.write("-")
	NEXT
    response.write("+")
END SUB
'-------------------------------
' Delete an element from a list
'-------------------------------
SUB Delete_Elm(new_list, index, new_count01)
FOR i= index TO new_count01-1
	new_list(i)=new_list(i+1)
NEXT
END SUB

'------------------------------
' Print a list
'------------------------------
SUB Print_List(list, count)
Response.Write("
") FOR i=1 TO count Response.Write(" "+list(i)) NEXT END SUB '------------------------------- ' Query child of a part '------------------------------- SUB Query_Child(part_no, part_ver, part_list, ver_list, i, db) i=0 query1 = "SELECT b.s_part_no, b.c_part_version FROM parts.part_list a, parts.part_list b, parts.""$EXT"" c " query2 = "where a.""$COID""= c.""$COID"" and c.""$COID_REF""=b.""$COID"" and c.""$TYPE""='CATASS' and " query3 = "not(a.""$COID"" = b.""$COID"") and a.c_part_version ='"+part_ver+"' and " query4 = "a.s_part_no = '" + part_no +"' " query = query1+query2+query3+query4 Set rs = db.execute(query) Do Until (rs.EOF) i=i+1 part_list(i) = rs(0) ver_list(i) = rs(1) rs.MoveNext loop rs.close Set rs = Nothing END SUB '---------------------------------- ' Tree Comparison Program '---------------------------------- SUB Tree_Comp(old_part, old_ver, new_part, new_ver, db,level) DIM old_list(100) DIM old_list_ver(100) DIM new_list(100) DIM new_list_ver(100) old_count= 0 new_count01 =0 new_count02 =0 CALL Query_Child(old_part,old_ver,old_list,old_list_ver,old_count,db) CALL Query_Child(new_part,new_ver,new_list,new_list_ver,new_count01,db) new_count02=new_count01 FOR i=1 TO old_count FOR j=1 TO new_count01 IF old_list(i)=new_list(j) and old_list_ver(i)=new_list_ver(j) THEN Response.Write(""+CStr(level)+"") Response.Write(""+old_list(i)+old_list_ver(i)+"") Response.Write(""+new_list(j)+new_list_ver(j)+"SAME") new_count02= new_count01-1 CALL Delete_Elm(new_list,j,new_count01) CALL Delete_Elm(new_list_ver,j,new_count01) EXIT FOR END IF NEXT ' if there is no matching part between old & new, check version IF new_count02=new_count01 THEN FOR j=1 TO new_count01 IF old_list(i) = new_list(j) THEN 'check same part nbr version Response.Write(""+CStr(level)+"") Response.Write(""+old_list(i)+old_list_ver(i)+"") Response.Write(""+new_list(j)+new_list_ver(j)+"REPLACED") new_count02=new_count01-1 CALL Tree_Comp(old_list(i),old_list_ver(i), new_list(j), new_list_ver(j), db, level+1) CALL Delete_Elm(new_list, j, new_count01) CALL Delete_Elm(new_list_ver,j,new_count01) END IF NEXT ' Nither matching part or version exists IF new_count02=new_count01 THEN Response.Write(""+CStr(level)+"") Response.Write(""+old_list(i)+old_list_ver(i)+"") Response.Write("DELETED") ELSE new_count01=new_count02 END IF ELSE ' same part°¡ ÀÖ´Â °æ¿ì new_count01=new_count02 END IF NEXT 'There are unmatching parts in new list IF new_count01 > 0 THEN FOR i=1 TO new_count01 Response.Write(""+CStr(level)+"") Response.Write("") Response.Write(""+new_list(i)+new_list_ver(i)+"ADDED") list_length=new_count01+1-i CALL Delete_Elm(new_list, i, list_length) CALL Delete_Elm(new_list_ver,i,list_length) NEXT END IF END SUB %> <HTML> <HEAD> </HEAD> <BODY> <% '=========================================== ' part structure comparison program main part '=========================================== ' user input from HTML 'FORM tag' old_part=Request("part_nbr01") new_part=Request("part_nbr02") v01=Request("v01") v02=Request("v02") ' Database conection is established Set sedb = Server.CreateObject("ADODB.Connection") sedb.ConnectionTimeout = Application("vpmdb_ConnectionTimeout") sedb.CommandTimeout = Application("vpmdb_CommandTimeout") sedb.Open Application("vpmdb_ConnectionString"), Application("vpmdb_RuntimeUserName"), Application("vpmdb_RuntimePassword") ' Prepare TABLE tag for output Response.Write("<BLOCKQUOTE><TABLE border=1 cellpading=2 cellspace=1 width= 85% >") Response.Write("<TR bgcolor=#C0C0C0 align=center><TD>level</TD><TD>old</TD><TD>new</TD><TD>ºñ°í</TD>") ' Call a function for part structure comparision CALL Tree_Comp(old_part,v01,new_part,v02,sedb,1) Response.Write("</TABLE>") %> </BODY> </HTML>



Korean Engineering Databases © copyright Namchul Do, 1999