Snippets
Created by
SeanB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | Struct tIndexFinder
Integer iFile
Integer iField
Integer iIndex
String sColumn
End_Struct
Object oIndexID is a cObject
Property tIndexFinder[] pIndexFinderList
Property tIndexFinder pLastItem
Function DF_Database_ID_Index_detail Integer iFile Returns tIndexFinder
tIndexFinder idDetail
Integer iLastIndex
Integer iIndex
Integer iNumSegments
Integer iColumn
String sColumn
Move iFile to IdDetail.iFile
Move 0 to IdDetail.iIndex
Move 0 to IdDetail.iField
Get_Attribute DF_FILE_LAST_INDEX_NUMBER of iFile to iLastIndex
For iIndex from 1 to iLastIndex
Get_Attribute DF_INDEX_NUMBER_SEGMENTS of iFile iIndex to iNumSegments
If (iNumSegments = 1) Begin
Get_Attribute DF_INDEX_SEGMENT_FIELD of iFile iIndex 1 to iColumn
Get_Attribute DF_FIELD_NAME of iFile iIndex to sColumn
Move iIndex to IdDetail.iIndex
Move iColumn to IdDetail.iField
Move sColumn to IdDetail.sColumn
Function_Return idDetail
End
Loop
Function_Return idDetail
End_Function
Function ItemForFile Integer iFile Returns tIndexFinder
tIndexFinder IdDetail
tIndexFinder[] IndexFinderList
Integer iPos
Integer iMax
Get pLastItem to IdDetail
If (IdDetail.iFile = iFile) Function_Return IdDetail
Get pIndexFinderList to IndexFinderList
Move (SizeOfArray(IndexFinderList)) to iMax
For iPos from 0 to (iMax-1)
If ( IndexFinderList[iPos].iFile = iFile ) Begin
Set pLastItem to IndexFinderList[iPos]
Function_Return IndexFinderList[iPos]
End
Loop
//we have not found it, so we need to go to the FileList
Get DF_Database_ID_Index_detail iFile to IdDetail
Move (SizeOfArray(IndexFinderList)) to iMax
Move IDDetail to IndexFinderList[iMax]
//todo:sort this for faster finding....
Set pIndexFinderList to IndexFinderList
Set pLastItem to IDDetail
Function_Return IDDetail
End_Function
Function IndexForID Integer iFile Returns Integer
tIndexFinder IdDetail
Move (ItemForFile(Self,iFile)) to IdDetail
Function_Return IdDetail.iIndex
End_Function
Function FieldForID Integer iFile Returns Integer
tIndexFinder IdDetail
Move (ItemForFile(Self,iFile)) to IdDetail
Function_Return IdDetail.iField
End_Function
End_Object
Global_Variable Integer ghoIndexID
Get oIndexID to ghoIndexID
Procedure find_by_id for DataDictionary String sValue
Integer iFile
Integer iIndex
Integer iField
Get Main_File to iFile
Get IndexForID of ghoIndexID iFile to iIndex
Get FieldForID of ghoIndexID iFile to iField
Send Request_Clear
Clear iFile
Set_Field_Value iFile iField to sValue
Send Request_Find EQ iFile iIndex
End_Procedure
//Use oFindByID.pkg
//
//Examples use the Example Order Entry Data Dictionaries
//--
//Usage
//Send find_by_id to {dataDictionary} {sValue}
//The procedure assumes the first index with one segment is the ID Data-dictionary
//
//Send find_by_id to oVendor_DD 8
//Showln Vendor.Name
//
//Send find_by_id to oInvt_DD "UNIXGUIDE"
//Showln Invt.Description
//Showln Vendor.Name
//Showln "---"
//
//Send find_by_id to oInvt_DD "UPDATE"
//Showln Invt.Description
//Showln Vendor.Name
//Showln "---"
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.