Saturday, October 18, 2008

How to fetch record with undefine key(s)

Often you wanted to fetch records from table with combination of key(s) that you know is unique (yes you use this ONLY when you know exactly what you want), then you find the key(s) that you are trying to map is not define either in Primary Key(PK) /Composite Keys(CK) or the Alternate Key(s) (AK).

Then what you can do?
1. Yes you might want to add another alternate key into this, but you'll have to regenerate your indexes, what if it's a standard table?
2. You try to use FetchNext, but there's no such key combination there to select.

Example Scenario:
Say you try to fetch field "F0101.AN8" of FIRST ROW of record from F0101 (Address Book Master) where URCD=[szCriteria_URCD].

In this case, instead of trying the F0101.Fetch Single function, try following ...

F0101.Open
F0101.Select
[VA frm_szCriteria_URCD] = [BF szUserReservedCode]
If [SV File_Status] equal to [CO_SUCCESS]
F0101.Fetch Next
[VA evt_mnF0101_AN8] <- [BF mnAddressNum
ber]
End If
F0101.Close

Then you notice I used F0101.Open and F0101.Close, these advance Table I/O operation might not be significant in here, but I like to keep this kind of practice so I know when my table operation start and stop it's session, so it won't interrupt with other similar I/O operation in a same event scope.

Reference(s):
- F0101 standard key(s)



By Avatar Ng
2008/10/19