rem ' This sample introduces an Empty Mapping Source, and a FormatMappingAction
rem ' Mappings can be done with any type of recordset, they are done here
rem ' with MemoryRecordSets so the example stands on its own.
declare BBjRecordSet UserRS!
GOSUB SetupRecordSets
declare BBjMappingSource source!
declare BBjMappingAction action!
rem 'configure our source and fallback action
source! = UserRS!.createEmptyMappingSource()
action! = UserRS!.createFormatMappingAction("[LocationCode={0}].")
rem 'Add the recordset
UserRS!.addMapping("LOCATION","MAPPED_LOC",source!,action!)
UserRS!.first()
while(1)
gosub printRecord
UserRS!.next(err=*end)
wend
end
printRecord:
name$ = UserRS!.getCurrentRecordData().getFieldValue("NAME")
location$ = UserRS!.getCurrentRecordData().getFieldValue("MAPPED_LOC")
PRINT name$, " lives in ", location$
return
SetupRecordSets:
UserRS! = BBJAPI().createMemoryRecordSet("NAME:C(100*=10),LOCATION:C(1)")
Data! = UserRS!.getEmptyRecordData()
Data!.setFieldValue("NAME", "John Doe")
Data!.setFieldValue("LOCATION", "1")
UserRS!.insert(Data!)
Data! = UserRS!.getEmptyRecordData()
Data!.setFieldValue("NAME", "Jane Smith")
Data!.setFieldValue("LOCATION", "3")
UserRS!.insert(Data!)
Data! = UserRS!.getEmptyRecordData()
Data!.setFieldValue("NAME", "Jane Doe")
Data!.setFieldValue("LOCATION", "2")
UserRS!.insert(Data!)
Data! = UserRS!.getEmptyRecordData()
Data!.setFieldValue("NAME", "Dr Droopy")
Data!.setFieldValue("LOCATION", "0")
UserRS!.insert(Data!)
return
|