PDA

View Full Version : new auto-increment



David Martinko
29-Mar-2006, 12:12 AM
If you don't want to use a system file to store the next/last number for a
field to auto-increment, here is another solution. It is a generic class
that can be plugged right into your datadictionary subclass and used as-is.
Customize it if you want to auto-increment date or ascii field types. You
can also customize it to auto-increment fields that are body records to a
header file. This should just give you an idea of what can be done.



Class oWSDataDictionary is a DataDictionary
Procedure Construct_Object
Forward Send Construct_Object
Property Integer piIncrementField 0
Property Boolean pbAutoIncrement FALSE
End_Procedure // Construct_Object

// Call this to setup the field to auto-increment
Procedure DefineAutoIncrement Handle hFile handle hField
If (hFile <> Main_File(Self)) Error 999 "Auto-increment field cannot
be from a different file."
Else Begin
Set piIncrementField to hField
Set pbAutoIncrement to TRUE
End
End_Procedure // DefineAutoIncrement

// Creating:
Procedure Creating
Handle hFile
Integer iMemberid iAutoField iField iFields iType iSize iIndex
iDefaultValue
String[] sFieldValue
String sVal sMaxValue

Forward Send Creating
// Check if we are auto-incrementing this file
If (pbAutoIncrement(Self)) Begin
Get Main_File to hFile
// Make sure we have the field to increment
If (piIncrementField(Self)=0) Error 999 "No auto-increment field
defined."
Get piIncrementField to iAutoField
Get_Attribute DF_FIELD_TYPE of hFile iAutoField to iType
Get_Attribute DF_FIELD_LENGTH of hFile iAutoField to iSize
Get_Attribute DF_FIELD_INDEX of hFile iAutoField to iIndex
// Make sure field is indexed
If (iIndex = 0) Error 999 "Indexed must have an index."
// Determine max field value
If (iType = DF_BCD) Move (Repeat("9", iSize)) to sMaxValue
Else Error 999 ("Invalid field type. Cannot auto-increment a
"+(If(iType=DF_DATE, " date field.", ""))+(If(iType=DF_OVERLAP, " overlap
field.", ""))+(If(iType=DF_TEXT, " text field.", ""))+(If(iType=DF_BINARY, "
binary field.", "")))
// Store new field values
Get_Attribute DF_FILE_NUMBER_FIELDS of hFile to iFields
For iField from 1 to iFields
GET_FIELD_VALUE hFile iField to sVal
Move sVal to sFieldValue[iField]
Loop
// Find last record in file
Clear hFile
SET_FIELD_VALUE hFile iAutoField to sMaxValue
vFind hFile iIndex lt
GET_FIELD_VALUE hFile iAutoField to iDefaultValue
Clear hFile
// Restore field values
For iField from 1 to iFields
Move sFieldValue[iField] to sVal
SET_FIELD_VALUE hFile iField to sVal
Loop
// Set auto-increment value
SET_FIELD_VALUE hFile iAutoField to (iDefaultValue+1)
End
End_Procedure // Creating
End_Class


// EXAMPLE USAGE
Object Member_DD is a cWSDataDictionary
Send DefineAutoIncrement FILE_FIELD Member.Memberid
End_Object

--
David Martinko
248-535-7495
Tracker Systems, Inc.
Redeemed Software
Redeemed Hosting
www.trackersys.com
www.redeemedsoftware.com
www.redeemedhosting.com
Proud member of the Northeast DataFlex Consortium: (NEDC)
www.NEDataFlex.com

David Martinko
29-Mar-2006, 12:33 AM
Here is a better place for this setting.

Class Member_DataDictionary is a cWSDataDictionary

Procedure Field_Defaults
Forward Send Field_Defaults
Send DefineAutoIncrement FILE_FIELD Member.Memberid
End_Procedure // Field_Defaults

End_Class

This way, all the code is in the DD's and it will compile under the webapp
or VDF. If you don't have VDF11.1, change the native array to an object
array and it'll still work...

--
David Martinko
248-535-7495
Tracker Systems, Inc.
Redeemed Software
Redeemed Hosting
www.trackersys.com
www.redeemedsoftware.com
www.redeemedhosting.com
Proud member of the Northeast DataFlex Consortium: (NEDC)
www.NEDataFlex.com

Mark Rutherford
29-Mar-2006, 12:56 PM
Cool....... I will have to try it.

David Martinko wrote:
> Here is a better place for this setting.
>
> Class Member_DataDictionary is a cWSDataDictionary
>
> Procedure Field_Defaults
> Forward Send Field_Defaults
> Send DefineAutoIncrement FILE_FIELD Member.Memberid
> End_Procedure // Field_Defaults
>
> End_Class
>
> This way, all the code is in the DD's and it will compile under the webapp
> or VDF. If you don't have VDF11.1, change the native array to an object
> array and it'll still work...
>


--
Thanks!

Mark Rutherford
Maunz Electronics, Inc.
803-791-5860

Eric Vaughen
29-Mar-2006, 04:31 PM
What keeps TWO different users from claiming the same number if they
happen to make the request at the same time...

David Martinko wrote:
> If you don't want to use a system file to store the next/last number for a
> field to auto-increment, here is another solution. It is a generic class
> that can be plugged right into your datadictionary subclass and used as-is.
> Customize it if you want to auto-increment date or ascii field types. You
> can also customize it to auto-increment fields that are body records to a
> header file. This should just give you an idea of what can be done.
>
>
>
> Class oWSDataDictionary is a DataDictionary
> Procedure Construct_Object
> Forward Send Construct_Object
> Property Integer piIncrementField 0
> Property Boolean pbAutoIncrement FALSE
> End_Procedure // Construct_Object
>
> // Call this to setup the field to auto-increment
> Procedure DefineAutoIncrement Handle hFile handle hField
> If (hFile <> Main_File(Self)) Error 999 "Auto-increment field cannot
> be from a different file."
> Else Begin
> Set piIncrementField to hField
> Set pbAutoIncrement to TRUE
> End
> End_Procedure // DefineAutoIncrement
>
> // Creating:
> Procedure Creating
> Handle hFile
> Integer iMemberid iAutoField iField iFields iType iSize iIndex
> iDefaultValue
> String[] sFieldValue
> String sVal sMaxValue
>
> Forward Send Creating
> // Check if we are auto-incrementing this file
> If (pbAutoIncrement(Self)) Begin
> Get Main_File to hFile
> // Make sure we have the field to increment
> If (piIncrementField(Self)=0) Error 999 "No auto-increment field
> defined."
> Get piIncrementField to iAutoField
> Get_Attribute DF_FIELD_TYPE of hFile iAutoField to iType
> Get_Attribute DF_FIELD_LENGTH of hFile iAutoField to iSize
> Get_Attribute DF_FIELD_INDEX of hFile iAutoField to iIndex
> // Make sure field is indexed
> If (iIndex = 0) Error 999 "Indexed must have an index."
> // Determine max field value
> If (iType = DF_BCD) Move (Repeat("9", iSize)) to sMaxValue
> Else Error 999 ("Invalid field type. Cannot auto-increment a
> "+(If(iType=DF_DATE, " date field.", ""))+(If(iType=DF_OVERLAP, " overlap
> field.", ""))+(If(iType=DF_TEXT, " text field.", ""))+(If(iType=DF_BINARY, "
> binary field.", "")))
> // Store new field values
> Get_Attribute DF_FILE_NUMBER_FIELDS of hFile to iFields
> For iField from 1 to iFields
> GET_FIELD_VALUE hFile iField to sVal
> Move sVal to sFieldValue[iField]
> Loop
> // Find last record in file
> Clear hFile
> SET_FIELD_VALUE hFile iAutoField to sMaxValue
> vFind hFile iIndex lt
> GET_FIELD_VALUE hFile iAutoField to iDefaultValue
> Clear hFile
> // Restore field values
> For iField from 1 to iFields
> Move sFieldValue[iField] to sVal
> SET_FIELD_VALUE hFile iField to sVal
> Loop
> // Set auto-increment value
> SET_FIELD_VALUE hFile iAutoField to (iDefaultValue+1)
> End
> End_Procedure // Creating
> End_Class
>
>
> // EXAMPLE USAGE
> Object Member_DD is a cWSDataDictionary
> Send DefineAutoIncrement FILE_FIELD Member.Memberid
> End_Object
>

David Martinko
29-Mar-2006, 04:35 PM
Because CREATING is in a Locked state.

=Dave

--
David Martinko
248-535-7495
Tracker Systems, Inc.
Redeemed Software
Redeemed Hosting
www.trackersys.com
www.redeemedsoftware.com
www.redeemedhosting.com
Proud member of the Northeast DataFlex Consortium: (NEDC)
www.NEDataFlex.com

"Eric Vaughen" <evaughen@gmail.com> wrote in message
news:khrwug3UGHA.1280@dacmail.dataaccess.com...
What keeps TWO different users from claiming the same number if they
happen to make the request at the same time...

David Martinko wrote:
> If you don't want to use a system file to store the next/last number for a
> field to auto-increment, here is another solution. It is a generic class
> that can be plugged right into your datadictionary subclass and used
> as-is.
> Customize it if you want to auto-increment date or ascii field types. You
> can also customize it to auto-increment fields that are body records to a
> header file. This should just give you an idea of what can be done.
>
>
>
> Class oWSDataDictionary is a DataDictionary
> Procedure Construct_Object
> Forward Send Construct_Object
> Property Integer piIncrementField 0
> Property Boolean pbAutoIncrement FALSE
> End_Procedure // Construct_Object
>
> // Call this to setup the field to auto-increment
> Procedure DefineAutoIncrement Handle hFile handle hField
> If (hFile <> Main_File(Self)) Error 999 "Auto-increment field
> cannot
> be from a different file."
> Else Begin
> Set piIncrementField to hField
> Set pbAutoIncrement to TRUE
> End
> End_Procedure // DefineAutoIncrement
>
> // Creating:
> Procedure Creating
> Handle hFile
> Integer iMemberid iAutoField iField iFields iType iSize iIndex
> iDefaultValue
> String[] sFieldValue
> String sVal sMaxValue
>
> Forward Send Creating
> // Check if we are auto-incrementing this file
> If (pbAutoIncrement(Self)) Begin
> Get Main_File to hFile
> // Make sure we have the field to increment
> If (piIncrementField(Self)=0) Error 999 "No auto-increment
> field
> defined."
> Get piIncrementField to iAutoField
> Get_Attribute DF_FIELD_TYPE of hFile iAutoField to iType
> Get_Attribute DF_FIELD_LENGTH of hFile iAutoField to iSize
> Get_Attribute DF_FIELD_INDEX of hFile iAutoField to iIndex
> // Make sure field is indexed
> If (iIndex = 0) Error 999 "Indexed must have an index."
> // Determine max field value
> If (iType = DF_BCD) Move (Repeat("9", iSize)) to sMaxValue
> Else Error 999 ("Invalid field type. Cannot auto-increment a
> "+(If(iType=DF_DATE, " date field.", ""))+(If(iType=DF_OVERLAP, " overlap
> field.", ""))+(If(iType=DF_TEXT, " text field.", ""))+(If(iType=DF_BINARY,
> "
> binary field.", "")))
> // Store new field values
> Get_Attribute DF_FILE_NUMBER_FIELDS of hFile to iFields
> For iField from 1 to iFields
> GET_FIELD_VALUE hFile iField to sVal
> Move sVal to sFieldValue[iField]
> Loop
> // Find last record in file
> Clear hFile
> SET_FIELD_VALUE hFile iAutoField to sMaxValue
> vFind hFile iIndex lt
> GET_FIELD_VALUE hFile iAutoField to iDefaultValue
> Clear hFile
> // Restore field values
> For iField from 1 to iFields
> Move sFieldValue[iField] to sVal
> SET_FIELD_VALUE hFile iField to sVal
> Loop
> // Set auto-increment value
> SET_FIELD_VALUE hFile iAutoField to (iDefaultValue+1)
> End
> End_Procedure // Creating
> End_Class
>
>
> // EXAMPLE USAGE
> Object Member_DD is a cWSDataDictionary
> Send DefineAutoIncrement FILE_FIELD Member.Memberid
> End_Object
>

Larry Heiges
30-Mar-2006, 02:47 PM
Dave,

>Because CREATING is in a Locked state.
>
The way I'm reading the docs, this may not be true with all database
backends. For example, DB2, exclusive locks are made only on rows
that are inserted, updated, or deleted. The only way to get an update
lock to do what you think is happening is to issue a reread or find by
recnum after the vfind LT. I don't think I would want to do a reread
inside of a DDO transaction because there are so many things going on
that I don't control, so find by recnum is the only alternative. The
examples all use "by recnum" so I guess it's up to us to figure out
how to do this on a database that doesn't have recnums.

The really big problem is that an error of this type would be
intermittent and almost impossible to debug.

This has been the whole thrust of the VDF topic "help: transactions"
that Ben has been trying to help me through. Us old timers my need to
learn some new tricks<g>... I'm just upset I almost missed this
potential problem.

Larry Heiges
App-2-Win Systems, Inc.
LookFeel for Windows
http://app-2-win.com
LFW7sp3
LFW11

Peter Bragg
31-Mar-2006, 05:53 AM
David,

Where you have the lines

> // Find last record in file
> Clear hFile
> SET_FIELD_VALUE hFile iAutoField to sMaxValue
> vFind hFile iIndex lt
> GET_FIELD_VALUE hFile iAutoField to iDefaultValue

what happens if this is the very first entry in the file?

I am going to guess that the find will fail and the line "Get_Field_Value
hFile .... " will return a "iDefaultValue" that is the value of sMaxValue.
It may be that you need to tweak this to return a zero value if the find
fails, or do something like

Get_Attribute DF_FILE_RECORDS_USED of hFile to iRecs

and then don't execute the find if (iRecs=0)


Peter Bragg


"David Martinko" <RedeemedSoftware@Hotmail.com> wrote in message
news:RPUIy9uUGHA.3232@dacmail.dataaccess.com...
> If you don't want to use a system file to store the next/last number for a
> field to auto-increment, here is another solution. It is a generic class
> that can be plugged right into your datadictionary subclass and used
as-is.
> Customize it if you want to auto-increment date or ascii field types. You
> can also customize it to auto-increment fields that are body records to a
> header file. This should just give you an idea of what can be done.
>
>
>
> Class oWSDataDictionary is a DataDictionary
> Procedure Construct_Object
> Forward Send Construct_Object
> Property Integer piIncrementField 0
> Property Boolean pbAutoIncrement FALSE
> End_Procedure // Construct_Object
>
> // Call this to setup the field to auto-increment
> Procedure DefineAutoIncrement Handle hFile handle hField
> If (hFile <> Main_File(Self)) Error 999 "Auto-increment field
cannot
> be from a different file."
> Else Begin
> Set piIncrementField to hField
> Set pbAutoIncrement to TRUE
> End
> End_Procedure // DefineAutoIncrement
>
> // Creating:
> Procedure Creating
> Handle hFile
> Integer iMemberid iAutoField iField iFields iType iSize iIndex
> iDefaultValue
> String[] sFieldValue
> String sVal sMaxValue
>
> Forward Send Creating
> // Check if we are auto-incrementing this file
> If (pbAutoIncrement(Self)) Begin
> Get Main_File to hFile
> // Make sure we have the field to increment
> If (piIncrementField(Self)=0) Error 999 "No auto-increment
field
> defined."
> Get piIncrementField to iAutoField
> Get_Attribute DF_FIELD_TYPE of hFile iAutoField to iType
> Get_Attribute DF_FIELD_LENGTH of hFile iAutoField to iSize
> Get_Attribute DF_FIELD_INDEX of hFile iAutoField to iIndex
> // Make sure field is indexed
> If (iIndex = 0) Error 999 "Indexed must have an index."
> // Determine max field value
> If (iType = DF_BCD) Move (Repeat("9", iSize)) to sMaxValue
> Else Error 999 ("Invalid field type. Cannot auto-increment a
> "+(If(iType=DF_DATE, " date field.", ""))+(If(iType=DF_OVERLAP, " overlap
> field.", ""))+(If(iType=DF_TEXT, " text field.", ""))+(If(iType=DF_BINARY,
"
> binary field.", "")))
> // Store new field values
> Get_Attribute DF_FILE_NUMBER_FIELDS of hFile to iFields
> For iField from 1 to iFields
> GET_FIELD_VALUE hFile iField to sVal
> Move sVal to sFieldValue[iField]
> Loop
> // Find last record in file
> Clear hFile
> SET_FIELD_VALUE hFile iAutoField to sMaxValue
> vFind hFile iIndex lt
> GET_FIELD_VALUE hFile iAutoField to iDefaultValue
> Clear hFile
> // Restore field values
> For iField from 1 to iFields
> Move sFieldValue[iField] to sVal
> SET_FIELD_VALUE hFile iField to sVal
> Loop
> // Set auto-increment value
> SET_FIELD_VALUE hFile iAutoField to (iDefaultValue+1)
> End
> End_Procedure // Creating
> End_Class
>
>
> // EXAMPLE USAGE
> Object Member_DD is a cWSDataDictionary
> Send DefineAutoIncrement FILE_FIELD Member.Memberid
> End_Object
>
> --
> David Martinko
> 248-535-7495
> Tracker Systems, Inc.
> Redeemed Software
> Redeemed Hosting
> www.trackersys.com
> www.redeemedsoftware.com
> www.redeemedhosting.com
> Proud member of the Northeast DataFlex Consortium: (NEDC)
> www.NEDataFlex.com
>
>

David Martinko
31-Mar-2006, 07:53 AM
Peter,

Good thought. I was designing a new system and thought I would try some
new code. The tables only had 2 records in them... but your right, I needed
to test an empty file. I always forget that. I guess I do need a FOUND
indicator there.

As for different backends, I guess you would have to understand how your
database locks. Another think I didn't consider. Perhaps I could add an
error message if the locking is something other than File locking.

--
David Martinko
248-535-7495
Tracker Systems, Inc.
Redeemed Software
Redeemed Hosting
www.trackersys.com
www.redeemedsoftware.com
www.redeemedhosting.com
Proud member of the Northeast DataFlex Consortium: (NEDC)
www.NEDataFlex.com

"Peter Bragg" <tech@care-data.co.uk> wrote in message
news:3z99fFLVGHA.1280@dacmail.dataaccess.com...
David,

Where you have the lines

> // Find last record in file
> Clear hFile
> SET_FIELD_VALUE hFile iAutoField to sMaxValue
> vFind hFile iIndex lt
> GET_FIELD_VALUE hFile iAutoField to iDefaultValue

what happens if this is the very first entry in the file?

I am going to guess that the find will fail and the line "Get_Field_Value
hFile .... " will return a "iDefaultValue" that is the value of sMaxValue.
It may be that you need to tweak this to return a zero value if the find
fails, or do something like

Get_Attribute DF_FILE_RECORDS_USED of hFile to iRecs

and then don't execute the find if (iRecs=0)


Peter Bragg


"David Martinko" <RedeemedSoftware@Hotmail.com> wrote in message
news:RPUIy9uUGHA.3232@dacmail.dataaccess.com...
> If you don't want to use a system file to store the next/last number for a
> field to auto-increment, here is another solution. It is a generic class
> that can be plugged right into your datadictionary subclass and used
as-is.
> Customize it if you want to auto-increment date or ascii field types. You
> can also customize it to auto-increment fields that are body records to a
> header file. This should just give you an idea of what can be done.
>
>
>
> Class oWSDataDictionary is a DataDictionary
> Procedure Construct_Object
> Forward Send Construct_Object
> Property Integer piIncrementField 0
> Property Boolean pbAutoIncrement FALSE
> End_Procedure // Construct_Object
>
> // Call this to setup the field to auto-increment
> Procedure DefineAutoIncrement Handle hFile handle hField
> If (hFile <> Main_File(Self)) Error 999 "Auto-increment field
cannot
> be from a different file."
> Else Begin
> Set piIncrementField to hField
> Set pbAutoIncrement to TRUE
> End
> End_Procedure // DefineAutoIncrement
>
> // Creating:
> Procedure Creating
> Handle hFile
> Integer iMemberid iAutoField iField iFields iType iSize iIndex
> iDefaultValue
> String[] sFieldValue
> String sVal sMaxValue
>
> Forward Send Creating
> // Check if we are auto-incrementing this file
> If (pbAutoIncrement(Self)) Begin
> Get Main_File to hFile
> // Make sure we have the field to increment
> If (piIncrementField(Self)=0) Error 999 "No auto-increment
field
> defined."
> Get piIncrementField to iAutoField
> Get_Attribute DF_FIELD_TYPE of hFile iAutoField to iType
> Get_Attribute DF_FIELD_LENGTH of hFile iAutoField to iSize
> Get_Attribute DF_FIELD_INDEX of hFile iAutoField to iIndex
> // Make sure field is indexed
> If (iIndex = 0) Error 999 "Indexed must have an index."
> // Determine max field value
> If (iType = DF_BCD) Move (Repeat("9", iSize)) to sMaxValue
> Else Error 999 ("Invalid field type. Cannot auto-increment a
> "+(If(iType=DF_DATE, " date field.", ""))+(If(iType=DF_OVERLAP, " overlap
> field.", ""))+(If(iType=DF_TEXT, " text field.", ""))+(If(iType=DF_BINARY,
"
> binary field.", "")))
> // Store new field values
> Get_Attribute DF_FILE_NUMBER_FIELDS of hFile to iFields
> For iField from 1 to iFields
> GET_FIELD_VALUE hFile iField to sVal
> Move sVal to sFieldValue[iField]
> Loop
> // Find last record in file
> Clear hFile
> SET_FIELD_VALUE hFile iAutoField to sMaxValue
> vFind hFile iIndex lt
> GET_FIELD_VALUE hFile iAutoField to iDefaultValue
> Clear hFile
> // Restore field values
> For iField from 1 to iFields
> Move sFieldValue[iField] to sVal
> SET_FIELD_VALUE hFile iField to sVal
> Loop
> // Set auto-increment value
> SET_FIELD_VALUE hFile iAutoField to (iDefaultValue+1)
> End
> End_Procedure // Creating
> End_Class
>
>
> // EXAMPLE USAGE
> Object Member_DD is a cWSDataDictionary
> Send DefineAutoIncrement FILE_FIELD Member.Memberid
> End_Object
>
> --
> David Martinko
> 248-535-7495
> Tracker Systems, Inc.
> Redeemed Software
> Redeemed Hosting
> www.trackersys.com
> www.redeemedsoftware.com
> www.redeemedhosting.com
> Proud member of the Northeast DataFlex Consortium: (NEDC)
> www.NEDataFlex.com
>
>

Evertjan Dondergoor
31-Mar-2006, 09:37 AM
David,

A risk with this is that you can give out the same number twice. This only happens when the last record gets deleted, so it might
never be a problem, but stil I dont like it.

Nowadays I always get the Autoincrement value from a table designed for that purpose. It is faster and more flexible then
system-files. It also does not have the above mentioned problem.

Regards,
Evertjan



"David Martinko" <RedeemedSoftware@Hotmail.com> wrote in message news:IUpkBJMVGHA.1276@dacmail.dataaccess.com...
> Peter,
>
> Good thought. I was designing a new system and thought I would try some
> new code. The tables only had 2 records in them... but your right, I needed
> to test an empty file. I always forget that. I guess I do need a FOUND
> indicator there.
>
> As for different backends, I guess you would have to understand how your
> database locks. Another think I didn't consider. Perhaps I could add an
> error message if the locking is something other than File locking.
>
> --
> David Martinko
> 248-535-7495
> Tracker Systems, Inc.
> Redeemed Software
> Redeemed Hosting
> www.trackersys.com
> www.redeemedsoftware.com
> www.redeemedhosting.com
> Proud member of the Northeast DataFlex Consortium: (NEDC)
> www.NEDataFlex.com
>
> "Peter Bragg" <tech@care-data.co.uk> wrote in message
> news:3z99fFLVGHA.1280@dacmail.dataaccess.com...
> David,
>
> Where you have the lines
>
>> // Find last record in file
>> Clear hFile
>> SET_FIELD_VALUE hFile iAutoField to sMaxValue
>> vFind hFile iIndex lt
>> GET_FIELD_VALUE hFile iAutoField to iDefaultValue
>
> what happens if this is the very first entry in the file?
>
> I am going to guess that the find will fail and the line "Get_Field_Value
> hFile .... " will return a "iDefaultValue" that is the value of sMaxValue.
> It may be that you need to tweak this to return a zero value if the find
> fails, or do something like
>
> Get_Attribute DF_FILE_RECORDS_USED of hFile to iRecs
>
> and then don't execute the find if (iRecs=0)
>
>
> Peter Bragg
>
>
> "David Martinko" <RedeemedSoftware@Hotmail.com> wrote in message
> news:RPUIy9uUGHA.3232@dacmail.dataaccess.com...
>> If you don't want to use a system file to store the next/last number for a
>> field to auto-increment, here is another solution. It is a generic class
>> that can be plugged right into your datadictionary subclass and used
> as-is.
>> Customize it if you want to auto-increment date or ascii field types. You
>> can also customize it to auto-increment fields that are body records to a
>> header file. This should just give you an idea of what can be done.
>>
>>
>>
>> Class oWSDataDictionary is a DataDictionary
>> Procedure Construct_Object
>> Forward Send Construct_Object
>> Property Integer piIncrementField 0
>> Property Boolean pbAutoIncrement FALSE
>> End_Procedure // Construct_Object
>>
>> // Call this to setup the field to auto-increment
>> Procedure DefineAutoIncrement Handle hFile handle hField
>> If (hFile <> Main_File(Self)) Error 999 "Auto-increment field
> cannot
>> be from a different file."
>> Else Begin
>> Set piIncrementField to hField
>> Set pbAutoIncrement to TRUE
>> End
>> End_Procedure // DefineAutoIncrement
>>
>> // Creating:
>> Procedure Creating
>> Handle hFile
>> Integer iMemberid iAutoField iField iFields iType iSize iIndex
>> iDefaultValue
>> String[] sFieldValue
>> String sVal sMaxValue
>>
>> Forward Send Creating
>> // Check if we are auto-incrementing this file
>> If (pbAutoIncrement(Self)) Begin
>> Get Main_File to hFile
>> // Make sure we have the field to increment
>> If (piIncrementField(Self)=0) Error 999 "No auto-increment
> field
>> defined."
>> Get piIncrementField to iAutoField
>> Get_Attribute DF_FIELD_TYPE of hFile iAutoField to iType
>> Get_Attribute DF_FIELD_LENGTH of hFile iAutoField to iSize
>> Get_Attribute DF_FIELD_INDEX of hFile iAutoField to iIndex
>> // Make sure field is indexed
>> If (iIndex = 0) Error 999 "Indexed must have an index."
>> // Determine max field value
>> If (iType = DF_BCD) Move (Repeat("9", iSize)) to sMaxValue
>> Else Error 999 ("Invalid field type. Cannot auto-increment a
>> "+(If(iType=DF_DATE, " date field.", ""))+(If(iType=DF_OVERLAP, " overlap
>> field.", ""))+(If(iType=DF_TEXT, " text field.", ""))+(If(iType=DF_BINARY,
> "
>> binary field.", "")))
>> // Store new field values
>> Get_Attribute DF_FILE_NUMBER_FIELDS of hFile to iFields
>> For iField from 1 to iFields
>> GET_FIELD_VALUE hFile iField to sVal
>> Move sVal to sFieldValue[iField]
>> Loop
>> // Find last record in file
>> Clear hFile
>> SET_FIELD_VALUE hFile iAutoField to sMaxValue
>> vFind hFile iIndex lt
>> GET_FIELD_VALUE hFile iAutoField to iDefaultValue
>> Clear hFile
>> // Restore field values
>> For iField from 1 to iFields
>> Move sFieldValue[iField] to sVal
>> SET_FIELD_VALUE hFile iField to sVal
>> Loop
>> // Set auto-increment value
>> SET_FIELD_VALUE hFile iAutoField to (iDefaultValue+1)
>> End
>> End_Procedure // Creating
>> End_Class
>>
>>
>> // EXAMPLE USAGE
>> Object Member_DD is a cWSDataDictionary
>> Send DefineAutoIncrement FILE_FIELD Member.Memberid
>> End_Object
>>
>> --
>> David Martinko
>> 248-535-7495
>> Tracker Systems, Inc.
>> Redeemed Software
>> Redeemed Hosting
>> www.trackersys.com
>> www.redeemedsoftware.com
>> www.redeemedhosting.com
>> Proud member of the Northeast DataFlex Consortium: (NEDC)
>> www.NEDataFlex.com
>>
>>
>
>
>

Larry Heiges
31-Mar-2006, 01:49 PM
Evertjan,

I think I would agree.

Another reason for using a system file would be that you may be in a
better position to avoid deadlocks in some processing situations
because of a common file with one record getting a lock at the initial
reread. This would act as a semaphore.

Larry Heiges
App-2-Win Systems, Inc.
LookFeel for Windows
http://app-2-win.com
LFW7sp3
LFW11

IAN VAGG
3-Apr-2006, 11:59 PM
I can see where this could be useful using the DF database. In my case I do most of my work in Pervasive. This and the vast majority of SQL backends
suppors autocrement fields which I am using more and more. In some applications data is being updated via SQL as well as Dataflex. In such an
environment even DF System files can hand out the same counter value to more than one user. Like Evertjan, I really believe Autoincrement fields are
the way to go.

Autoincrement fields in Pervasive can only be created via SQL commands and then only in new tables. This I have done but it is tedious. More
recently, I take advantage of DF's own Record number field. I first create a new table as Dataflex. I then convert it to Pervasive with Recnum
support. Then I edit the .INT file to remove the "Recnum Support 1" line. Now DBBuilder shows the first field as RECID which I rename to Code or
whatever.

Another approach I have used which is more SQL & Developer friendly than system files is to create a Sysfield table. Each record is a different
system counter and I have a global function which returns the current value of any particular record or increments it and returns the new value. This
is SQL friendly because it lends itself to record level locking and developer friendly because you can easily add new counters without changing system
file structures and recompiling programs which are otherwise unafected.

Ian


On Wed, 29 Mar 2006 00:12:07 -0500, "David Martinko" <RedeemedSoftware@Hotmail.com> wrote:

>If you don't want to use a system file to store the next/last number for a
>field to auto-increment, here is another solution. It is a generic class
>that can be plugged right into your datadictionary subclass and used as-is.
>Customize it if you want to auto-increment date or ascii field types. You
>can also customize it to auto-increment fields that are body records to a
>header file. This should just give you an idea of what can be done.
>
>
>
>Class oWSDataDictionary is a DataDictionary
> Procedure Construct_Object
> Forward Send Construct_Object
> Property Integer piIncrementField 0
> Property Boolean pbAutoIncrement FALSE
> End_Procedure // Construct_Object
>
> // Call this to setup the field to auto-increment
> Procedure DefineAutoIncrement Handle hFile handle hField
> If (hFile <> Main_File(Self)) Error 999 "Auto-increment field cannot
>be from a different file."
> Else Begin
> Set piIncrementField to hField
> Set pbAutoIncrement to TRUE
> End
> End_Procedure // DefineAutoIncrement
>
> // Creating:
> Procedure Creating
> Handle hFile
> Integer iMemberid iAutoField iField iFields iType iSize iIndex
>iDefaultValue
> String[] sFieldValue
> String sVal sMaxValue
>
> Forward Send Creating
> // Check if we are auto-incrementing this file
> If (pbAutoIncrement(Self)) Begin
> Get Main_File to hFile
> // Make sure we have the field to increment
> If (piIncrementField(Self)=0) Error 999 "No auto-increment field
>defined."
> Get piIncrementField to iAutoField
> Get_Attribute DF_FIELD_TYPE of hFile iAutoField to iType
> Get_Attribute DF_FIELD_LENGTH of hFile iAutoField to iSize
> Get_Attribute DF_FIELD_INDEX of hFile iAutoField to iIndex
> // Make sure field is indexed
> If (iIndex = 0) Error 999 "Indexed must have an index."
> // Determine max field value
> If (iType = DF_BCD) Move (Repeat("9", iSize)) to sMaxValue
> Else Error 999 ("Invalid field type. Cannot auto-increment a
>"+(If(iType=DF_DATE, " date field.", ""))+(If(iType=DF_OVERLAP, " overlap
>field.", ""))+(If(iType=DF_TEXT, " text field.", ""))+(If(iType=DF_BINARY, "
>binary field.", "")))
> // Store new field values
> Get_Attribute DF_FILE_NUMBER_FIELDS of hFile to iFields
> For iField from 1 to iFields
> GET_FIELD_VALUE hFile iField to sVal
> Move sVal to sFieldValue[iField]
> Loop
> // Find last record in file
> Clear hFile
> SET_FIELD_VALUE hFile iAutoField to sMaxValue
> vFind hFile iIndex lt
> GET_FIELD_VALUE hFile iAutoField to iDefaultValue
> Clear hFile
> // Restore field values
> For iField from 1 to iFields
> Move sFieldValue[iField] to sVal
> SET_FIELD_VALUE hFile iField to sVal
> Loop
> // Set auto-increment value
> SET_FIELD_VALUE hFile iAutoField to (iDefaultValue+1)
> End
> End_Procedure // Creating
>End_Class
>
>
>// EXAMPLE USAGE
>Object Member_DD is a cWSDataDictionary
> Send DefineAutoIncrement FILE_FIELD Member.Memberid
>End_Object

David Martinko
4-Apr-2006, 01:19 AM
Ok, so this code is not recommended. It does not port well to other
backends, so even if you are using DF tables now... some day you may convert
then you will have to change your logic. So don't use this.

I hate coding myself into a corner. Apparently when I wrote this I wasn't
thinking about other backends... Thanks for the input. I'll just stick with
recnum and other auto-increment fields using system tables and parent
tables.

--
David Martinko
248-535-7495
Tracker Systems, Inc.
Redeemed Software
Redeemed Hosting
www.trackersys.com
www.redeemedsoftware.com
www.redeemedhosting.com
Proud member of the Northeast DataFlex Consortium: (NEDC)
www.NEDataFlex.com

"David Martinko" <RedeemedSoftware@Hotmail.com> wrote in message
news:RPUIy9uUGHA.3232@dacmail.dataaccess.com...
If you don't want to use a system file to store the next/last number for a
field to auto-increment, here is another solution. It is a generic class
that can be plugged right into your datadictionary subclass and used as-is.
Customize it if you want to auto-increment date or ascii field types. You
can also customize it to auto-increment fields that are body records to a
header file. This should just give you an idea of what can be done.



Class oWSDataDictionary is a DataDictionary
Procedure Construct_Object
Forward Send Construct_Object
Property Integer piIncrementField 0
Property Boolean pbAutoIncrement FALSE
End_Procedure // Construct_Object

// Call this to setup the field to auto-increment
Procedure DefineAutoIncrement Handle hFile handle hField
If (hFile <> Main_File(Self)) Error 999 "Auto-increment field cannot
be from a different file."
Else Begin
Set piIncrementField to hField
Set pbAutoIncrement to TRUE
End
End_Procedure // DefineAutoIncrement

// Creating:
Procedure Creating
Handle hFile
Integer iMemberid iAutoField iField iFields iType iSize iIndex
iDefaultValue
String[] sFieldValue
String sVal sMaxValue

Forward Send Creating
// Check if we are auto-incrementing this file
If (pbAutoIncrement(Self)) Begin
Get Main_File to hFile
// Make sure we have the field to increment
If (piIncrementField(Self)=0) Error 999 "No auto-increment field
defined."
Get piIncrementField to iAutoField
Get_Attribute DF_FIELD_TYPE of hFile iAutoField to iType
Get_Attribute DF_FIELD_LENGTH of hFile iAutoField to iSize
Get_Attribute DF_FIELD_INDEX of hFile iAutoField to iIndex
// Make sure field is indexed
If (iIndex = 0) Error 999 "Indexed must have an index."
// Determine max field value
If (iType = DF_BCD) Move (Repeat("9", iSize)) to sMaxValue
Else Error 999 ("Invalid field type. Cannot auto-increment a
"+(If(iType=DF_DATE, " date field.", ""))+(If(iType=DF_OVERLAP, " overlap
field.", ""))+(If(iType=DF_TEXT, " text field.", ""))+(If(iType=DF_BINARY, "
binary field.", "")))
// Store new field values
Get_Attribute DF_FILE_NUMBER_FIELDS of hFile to iFields
For iField from 1 to iFields
GET_FIELD_VALUE hFile iField to sVal
Move sVal to sFieldValue[iField]
Loop
// Find last record in file
Clear hFile
SET_FIELD_VALUE hFile iAutoField to sMaxValue
vFind hFile iIndex lt
GET_FIELD_VALUE hFile iAutoField to iDefaultValue
Clear hFile
// Restore field values
For iField from 1 to iFields
Move sFieldValue[iField] to sVal
SET_FIELD_VALUE hFile iField to sVal
Loop
// Set auto-increment value
SET_FIELD_VALUE hFile iAutoField to (iDefaultValue+1)
End
End_Procedure // Creating
End_Class


// EXAMPLE USAGE
Object Member_DD is a cWSDataDictionary
Send DefineAutoIncrement FILE_FIELD Member.Memberid
End_Object

--
David Martinko
248-535-7495
Tracker Systems, Inc.
Redeemed Software
Redeemed Hosting
www.trackersys.com
www.redeemedsoftware.com
www.redeemedhosting.com
Proud member of the Northeast DataFlex Consortium: (NEDC)
www.NEDataFlex.com

Bob Worsley
4-Apr-2006, 06:51 AM
What works well for me and I think I saw one other similar reference in this
thread is a small table that contains only two fields, ID# and Key where the
key is the particular function the ID number is used for. It requires one
extra find over a system table but has the distinct advantage that you don't
have to do a restructure to add a new ID# sequence for a different purpose.
Then simply write a function that finds the appropriate record before
incrementing the ID.
Bob

"David Martinko" <RedeemedSoftware@Hotmail.com> wrote in message
news:Mw0Ic$6VGHA.540@dacmail.dataaccess.com...
> Ok, so this code is not recommended. It does not port well to other
> backends, so even if you are using DF tables now... some day you may
> convert
> then you will have to change your logic. So don't use this.
>
> I hate coding myself into a corner. Apparently when I wrote this I wasn't
> thinking about other backends... Thanks for the input. I'll just stick
> with
> recnum and other auto-increment fields using system tables and parent
> tables.
>
> --
> David Martinko
> 248-535-7495
> Tracker Systems, Inc.
> Redeemed Software
> Redeemed Hosting
> www.trackersys.com
> www.redeemedsoftware.com
> www.redeemedhosting.com
> Proud member of the Northeast DataFlex Consortium: (NEDC)
> www.NEDataFlex.com
>
> "David Martinko" <RedeemedSoftware@Hotmail.com> wrote in message
> news:RPUIy9uUGHA.3232@dacmail.dataaccess.com...
> If you don't want to use a system file to store the next/last number for a
> field to auto-increment, here is another solution. It is a generic class
> that can be plugged right into your datadictionary subclass and used
> as-is.
> Customize it if you want to auto-increment date or ascii field types. You
> can also customize it to auto-increment fields that are body records to a
> header file. This should just give you an idea of what can be done.
>
>
>
> Class oWSDataDictionary is a DataDictionary
> Procedure Construct_Object
> Forward Send Construct_Object
> Property Integer piIncrementField 0
> Property Boolean pbAutoIncrement FALSE
> End_Procedure // Construct_Object
>
> // Call this to setup the field to auto-increment
> Procedure DefineAutoIncrement Handle hFile handle hField
> If (hFile <> Main_File(Self)) Error 999 "Auto-increment field
> cannot
> be from a different file."
> Else Begin
> Set piIncrementField to hField
> Set pbAutoIncrement to TRUE
> End
> End_Procedure // DefineAutoIncrement
>
> // Creating:
> Procedure Creating
> Handle hFile
> Integer iMemberid iAutoField iField iFields iType iSize iIndex
> iDefaultValue
> String[] sFieldValue
> String sVal sMaxValue
>
> Forward Send Creating
> // Check if we are auto-incrementing this file
> If (pbAutoIncrement(Self)) Begin
> Get Main_File to hFile
> // Make sure we have the field to increment
> If (piIncrementField(Self)=0) Error 999 "No auto-increment
> field
> defined."
> Get piIncrementField to iAutoField
> Get_Attribute DF_FIELD_TYPE of hFile iAutoField to iType
> Get_Attribute DF_FIELD_LENGTH of hFile iAutoField to iSize
> Get_Attribute DF_FIELD_INDEX of hFile iAutoField to iIndex
> // Make sure field is indexed
> If (iIndex = 0) Error 999 "Indexed must have an index."
> // Determine max field value
> If (iType = DF_BCD) Move (Repeat("9", iSize)) to sMaxValue
> Else Error 999 ("Invalid field type. Cannot auto-increment a
> "+(If(iType=DF_DATE, " date field.", ""))+(If(iType=DF_OVERLAP, " overlap
> field.", ""))+(If(iType=DF_TEXT, " text field.", ""))+(If(iType=DF_BINARY,
> "
> binary field.", "")))
> // Store new field values
> Get_Attribute DF_FILE_NUMBER_FIELDS of hFile to iFields
> For iField from 1 to iFields
> GET_FIELD_VALUE hFile iField to sVal
> Move sVal to sFieldValue[iField]
> Loop
> // Find last record in file
> Clear hFile
> SET_FIELD_VALUE hFile iAutoField to sMaxValue
> vFind hFile iIndex lt
> GET_FIELD_VALUE hFile iAutoField to iDefaultValue
> Clear hFile
> // Restore field values
> For iField from 1 to iFields
> Move sFieldValue[iField] to sVal
> SET_FIELD_VALUE hFile iField to sVal
> Loop
> // Set auto-increment value
> SET_FIELD_VALUE hFile iAutoField to (iDefaultValue+1)
> End
> End_Procedure // Creating
> End_Class
>
>
> // EXAMPLE USAGE
> Object Member_DD is a cWSDataDictionary
> Send DefineAutoIncrement FILE_FIELD Member.Memberid
> End_Object
>
> --
> David Martinko
> 248-535-7495
> Tracker Systems, Inc.
> Redeemed Software
> Redeemed Hosting
> www.trackersys.com
> www.redeemedsoftware.com
> www.redeemedhosting.com
> Proud member of the Northeast DataFlex Consortium: (NEDC)
> www.NEDataFlex.com
>
>
>

Larry Heiges
4-Apr-2006, 12:34 PM
Bob,

I use a single system increment field for all files. It doesn't give
a "next one" number on a particular file, but it does give a
chronological "next one" as records are added to a system. This has
come in handy in the past, especially for files that are not date
stamped.

I figure if I make the field big enough, I won't be the one having to
deal with rollover<g> All of my increment fields are N10.

Larry Heiges
App-2-Win Systems, Inc.
LookFeel for Windows
http://app-2-win.com
LFW7sp3
LFW11

Pieter van Dieren
5-Apr-2006, 04:01 AM
David,

I don't like system tables either and use code below a lot.
It's not something I've implemented in my subclass (yet), but that shouldn't
be too hard.

Seems to me it does the same, but with a lot less code:

// Creating
Procedure Creating
Forward Send Creating

Integer iNextNumber
Integer iFile iField

Move TableName.File_number To iFile
Field_Map iFile "Number" To iField

Clear TableName
Fill_Field iFile iField With DF_HIGH
Find Le TableName.Number
If (Found) Move (TableName.Number + 1) To iNextNumber
Else Move 1 To iNextNumber

Clear TableName
Send Request_entry_update TableName.File_Number 3
Move iNextNumber To TableName.Number

End_Procedure // Creating

Clive Richmond
10-Apr-2006, 11:20 AM
David & Pieter,

We also having something similar see code below. However instead of
Field_Map and Request_Entry_Update we use Get_Fieldnumber and
Entry_Update respectively.

We opted for Get_Fieldnumber since I understand Field_Map relies on the
table's tag file being present and correct which has been a problem for
us in the past.

We’ve also assumed that by the time you reach creating all local record
buffers should be insync with their DEOs and all that is required is to
copy the local record buffer back to the physical buffer hence why we
opted for Entry_Update.

And likewise we haven't implemented as a subclass (yet) . . .

// Creating:
// Allocate the next available transaction number
//
Procedure Creating
Integer iField iLstTransNo

Forward Send Creating

Clear TCTALL
Get_Fieldnumber TCTALL.TCTALL# To iField
Fill_Field TCTALL.File_Number iField With DF_HIGH
Find GE TCTALL By C_TCTALL_IDX_TCTALL
If (FOUND) Move TCTALL.TCTALL# To iLstTransNo
Else Move 0 To iLstTransNo

Clear TCTALL
Send Entry_Update Of (Record_Buffer(Self)) (Main_File(Self)) True
Move (iLstTransNo + 1) To TCTALL.TCTALL#
End_Procedure // Creating


--
Clive Richmond
Triumph Business Systems Pty Ltd
http://www.triumph-accounting.com

Pieter van Dieren wrote:
> David,
>
> I don't like system tables either and use code below a lot.
> It's not something I've implemented in my subclass (yet), but that shouldn't
> be too hard.
>
> Seems to me it does the same, but with a lot less code:
>
> // Creating
> Procedure Creating
> Forward Send Creating
>
> Integer iNextNumber
> Integer iFile iField
>
> Move TableName.File_number To iFile
> Field_Map iFile "Number" To iField
>
> Clear TableName
> Fill_Field iFile iField With DF_HIGH
> Find Le TableName.Number
> If (Found) Move (TableName.Number + 1) To iNextNumber
> Else Move 1 To iNextNumber
>
> Clear TableName
> Send Request_entry_update TableName.File_Number 3
> Move iNextNumber To TableName.Number
>
> End_Procedure // Creating
>
>

Pieter van Dieren
25-Apr-2006, 04:54 AM
Clive,

I didn't know Get_Fieldnumber.
Looks like a better solution than Field_Map in this case.
Thanks. <g>

--

Pieter

"Clive Richmond" <"clive at triumph dash accounting dot com"> schreef in
bericht news:Viya0qLXGHA.2932@dacmail.dataaccess.com...
> David & Pieter,
>
> We also having something similar see code below. However instead of
> Field_Map and Request_Entry_Update we use Get_Fieldnumber and Entry_Update
> respectively.
>
> We opted for Get_Fieldnumber since I understand Field_Map relies on the
> table's tag file being present and correct which has been a problem for us
> in the past.
>
> We’ve also assumed that by the time you reach creating all local record
> buffers should be insync with their DEOs and all that is required is to
> copy the local record buffer back to the physical buffer hence why we
> opted for Entry_Update.
>
> And likewise we haven't implemented as a subclass (yet) . . .
>
> // Creating:
> // Allocate the next available transaction number
> //
> Procedure Creating
> Integer iField iLstTransNo
>
> Forward Send Creating
>
> Clear TCTALL
> Get_Fieldnumber TCTALL.TCTALL# To iField
> Fill_Field TCTALL.File_Number iField With DF_HIGH
> Find GE TCTALL By C_TCTALL_IDX_TCTALL
> If (FOUND) Move TCTALL.TCTALL# To iLstTransNo
> Else Move 0 To iLstTransNo
>
> Clear TCTALL
> Send Entry_Update Of (Record_Buffer(Self)) (Main_File(Self)) True
> Move (iLstTransNo + 1) To TCTALL.TCTALL#
> End_Procedure // Creating
>
>
> --
> Clive Richmond
> Triumph Business Systems Pty Ltd
> http://www.triumph-accounting.com
>
> Pieter van Dieren wrote:
>> David,
>>
>> I don't like system tables either and use code below a lot.
>> It's not something I've implemented in my subclass (yet), but that
>> shouldn't be too hard.
>>
>> Seems to me it does the same, but with a lot less code:
>>
>> // Creating
>> Procedure Creating
>> Forward Send Creating
>>
>> Integer iNextNumber
>> Integer iFile iField
>>
>> Move TableName.File_number To iFile
>> Field_Map iFile "Number" To iField
>>
>> Clear TableName
>> Fill_Field iFile iField With DF_HIGH
>> Find Le TableName.Number
>> If (Found) Move (TableName.Number + 1) To iNextNumber
>> Else Move 1 To iNextNumber
>>
>> Clear TableName
>> Send Request_entry_update TableName.File_Number 3
>> Move iNextNumber To TableName.Number
>>
>> End_Procedure // Creating
>>

Allan Greis Eriksen
26-Apr-2006, 01:33 AM
Get_Fieldnumber is also used behind the scenes when using the FILE_FIELD
attribute.

ie.

Procedure FillMaxValue integer iFile integer iField
Fill_Field iFile iField With DF_HIGH
End_Procedure

Send FillMaxValue File_Field TCTALL.TCTALL#


--
Regards,
Allan Kim Eriksen
Programmer/systemconsolent

Nordteam Gruppen Aps
Denmark

Clive Richmond
1-May-2006, 01:11 AM
Yes. It would be nice if DAW extended to FILE_FIELD/FIELD construct to
all commands that require file/field or field arguments. It would save
the extra coding or implementing your own functions as you have done. E.g.

Fill_Field FILE_FIELD TCTALL.TCTALL# With DF_HIGH

Some of the commands I'd like covered by the FILE_FIELD/FIELD construct
include:

Fill_Field
Set_Field_Value
Get_Field_Value
Get/Set_Attribute

I'm sure their are several more to add to this list.

--
Clive Richmond
Triumph Business Systems Pty Ltd
http://www.triumph-accounting.com


Allan Kim Eriksen wrote:
> Get_Fieldnumber is also used behind the scenes when using the FILE_FIELD
> attribute.
>
> ie.
>
> Procedure FillMaxValue integer iFile integer iField
> Fill_Field iFile iField With DF_HIGH
> End_Procedure
>
> Send FillMaxValue File_Field TCTALL.TCTALL#
>
>

David Martinko
1-May-2006, 06:43 AM
Clive,

You can use FILE_FIELD and FIELD with any procedure. They are built into the
Compiler. Any time you want the file and field number or the field number,
you just use it.

Set Fill_Field FILE_FIELD Cust.Name With DF_HIGH

Set_Field_Value FILE_FIELD Cust.Name to "ACME"
or
Set_Field_Value Cust.File_Number FIELD Cust.Name to "ACME"

Cust.File_Number // use to get the file number
File_Field // translates into 2 variables, the file number and field number
Field // translates into 1 variable, the field number

--
David Martinko
248-535-7495
Tracker Systems, Inc.
Redeemed Software
Redeemed Hosting
www.trackersys.com
www.redeemedsoftware.com
www.redeemedhosting.com
Proud member of the Northeast DataFlex Consortium: (NEDC)
www.NEDataFlex.com

"Clive Richmond" <"clive at triumph dash accounting dot com"> wrote in
message news:UQsyIYObGHA.3852@dacmail.dataaccess.com...
Yes. It would be nice if DAW extended to FILE_FIELD/FIELD construct to
all commands that require file/field or field arguments. It would save
the extra coding or implementing your own functions as you have done. E.g.

Fill_Field FILE_FIELD TCTALL.TCTALL# With DF_HIGH

Some of the commands I'd like covered by the FILE_FIELD/FIELD construct
include:

Fill_Field
Set_Field_Value
Get_Field_Value
Get/Set_Attribute

I'm sure their are several more to add to this list.

--
Clive Richmond
Triumph Business Systems Pty Ltd
http://www.triumph-accounting.com


Allan Kim Eriksen wrote:
> Get_Fieldnumber is also used behind the scenes when using the FILE_FIELD
> attribute.
>
> ie.
>
> Procedure FillMaxValue integer iFile integer iField
> Fill_Field iFile iField With DF_HIGH
> End_Procedure
>
> Send FillMaxValue File_Field TCTALL.TCTALL#
>
>

Larry Heiges
1-May-2006, 10:21 AM
>
>You can use FILE_FIELD and FIELD with any procedure. They are built into the

Almost any<g> I've had some situations where it would work as a
"Set" procedure but not as a "send" procedure.

Larry Heiges
App-2-Win Systems, Inc.
LookFeel for Windows
http://app-2-win.com
LFW7sp3
LFW11

Clive Richmond
1-May-2006, 12:05 PM
Hi David,

Yes I understand how FILE_FIELD and FIELD work with procedures and
functions. However the Fill_Field and Set_Field_Value are macro commands.

> Set Fill_Field FILE_FIELD Customer.Name With DF_HIGH

and

> Set_Field_Value Customer.File_Number FIELD Customer.Name to "ACME"

will generate compiler errors. Well they did for me :-(

What I'd like to see DAW implement are 'helper' commands, similar to
GET$SET$HELP, to the existing macros which require File_Field/Field
arguments. E.g.

#COMMAND FILL$FIELD$HELP RLUG# RLUG# "WITH" RLUG# .
!A [] $51D !1
!A [] $51E !2 !4
#ENDCOMMAND

#COMMAND FILL_FIELD
#IFSAME !1 FILE_FIELD
#IFCLASS !2 F // test for file element
#PUSH !h
#PUSH !g
#SET H$ %!2 // get the fieldnumber of parameter
#SET G$ !2 // get the filenumber of parameter
FILL$FIELD$HELP |CI!g |CI!h !3 !4 !5 !6 !7 !8 !9
#POP G$
#POP H$
#ELSE
#ERROR DFERR_COMP_UNDEFINED_SYMBOL_IN_ARGUMENT UNKNOWN FILE_FIELD: !2
#ENDIF
#ELSE
FILL$FIELD$HELP !1 !2 !3 !4 !5 !6 !7 !8 !9
#ENDIF
#ENDCOMMAND

--
Clive Richmond
Triumph Business Systems Pty Ltd
http://www.triumph-accounting.com

David Martinko wrote:
> Clive,
>
> You can use FILE_FIELD and FIELD with any procedure. They are built into the
> Compiler. Any time you want the file and field number or the field number,
> you just use it.
>
>
> Set_Field_Value FILE_FIELD Cust.Name to "ACME"
> or
> Set_Field_Value Cust.File_Number FIELD Cust.Name to "ACME"
>
> Cust.File_Number // use to get the file number
> File_Field // translates into 2 variables, the file number and field number
> Field // translates into 1 variable, the field number
>

David Martinko
1-May-2006, 12:39 PM
I C

or you could create them as

Procedure MyFillField Integer iFile Integer iField String sVal
Fill_Field iFile iField with sVal
End_Procedure

Send MuFillField File_Field Cust.Name DF_HIGH

If you want a change, be sure and goto DAW website and fill out a request.

--
David Martinko
248-535-7495
Tracker Systems, Inc.
Redeemed Software
Redeemed Hosting
www.trackersys.com
www.redeemedsoftware.com
www.redeemedhosting.com
Proud member of the Northeast DataFlex Consortium: (NEDC)
www.NEDataFlex.com

"Clive Richmond" <"clive at triumph dash accounting dot com"> wrote in
message news:ZpkqrFUbGHA.4804@dacmail.dataaccess.com...
Hi David,

Yes I understand how FILE_FIELD and FIELD work with procedures and
functions. However the Fill_Field and Set_Field_Value are macro commands.

> Set Fill_Field FILE_FIELD Customer.Name With DF_HIGH

and

> Set_Field_Value Customer.File_Number FIELD Customer.Name to "ACME"

will generate compiler errors. Well they did for me :-(

What I'd like to see DAW implement are 'helper' commands, similar to
GET$SET$HELP, to the existing macros which require File_Field/Field
arguments. E.g.

#COMMAND FILL$FIELD$HELP RLUG# RLUG# "WITH" RLUG# .
!A [] $51D !1
!A [] $51E !2 !4
#ENDCOMMAND

#COMMAND FILL_FIELD
#IFSAME !1 FILE_FIELD
#IFCLASS !2 F // test for file element
#PUSH !h
#PUSH !g
#SET H$ %!2 // get the fieldnumber of parameter
#SET G$ !2 // get the filenumber of parameter
FILL$FIELD$HELP |CI!g |CI!h !3 !4 !5 !6 !7 !8 !9
#POP G$
#POP H$
#ELSE
#ERROR DFERR_COMP_UNDEFINED_SYMBOL_IN_ARGUMENT UNKNOWN FILE_FIELD: !2
#ENDIF
#ELSE
FILL$FIELD$HELP !1 !2 !3 !4 !5 !6 !7 !8 !9
#ENDIF
#ENDCOMMAND

--
Clive Richmond
Triumph Business Systems Pty Ltd
http://www.triumph-accounting.com

David Martinko wrote:
> Clive,
>
> You can use FILE_FIELD and FIELD with any procedure. They are built into
> the
> Compiler. Any time you want the file and field number or the field number,
> you just use it.
>
>
> Set_Field_Value FILE_FIELD Cust.Name to "ACME"
> or
> Set_Field_Value Cust.File_Number FIELD Cust.Name to "ACME"
>
> Cust.File_Number // use to get the file number
> File_Field // translates into 2 variables, the file number and field
> number
> Field // translates into 1 variable, the field number
>

Vincent Oorsprong
2-May-2006, 03:03 AM
Clive,

Logged your suggestion.
--
Regards,
Vincent Oorsprong
Data Access Europe B.V.
http://www.dataaccess.nl