on 12-12-2007 3:33 PM
Good Day
Experts:
I would like to create Indexes on User-Defined fields at the time I create the table.
However, I do not want to click on the CreateIndex checkbox once inside a specific field. I want to do it programatically like when you hit the Keys button after highlighting a table from the list.
Any ideas how I can achieve this?
Thanks,
Ed
Hi Ed
Try something like this function
Private Sub addUserTableKeys(ByVal strTableName As String, ByVal strKeyFieldName As String, ByVal strKeyName As String, Optional ByVal bolUnique As Boolean = True)
Try
Dim bFlagFirst As Boolean = True
Dim oUserKeysMD As SAPbobsCOM.UserKeysMD
oUserKeysMD = msboCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserKeys) ' Set table name and key name
oUserKeysMD.TableName = strTableName
oUserKeysMD.KeyName = strKeyName
If bFlagFirst = True Then
bFlagFirst = False ' Add method not used for first element
Else
oUserKeysMD.Elements.Add() ' Add item to Elements collection
End If
oUserKeysMD.Elements.ColumnAlias = strKeyFieldName ' Set column's alias
oUserKeysMD.Unique = IIf(bolUnique, SAPbobsCOM.BoYesNoEnum.tYES, SAPbobsCOM.BoYesNoEnum.tNO) ' whether key is unique or not
oUserKeysMD.Add() ' Add the key
Catch ex As Exception
msboApplication.StatusBar.SetText("Fail to create data!" & vbCrLf & ex.Message)
End Try
End Sub
now, all you need to pass is a couple of parameters to the function like this ..
Call addUserTableKeys("TAB1", "PP_Field1", "KEY1")
hope it helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Neftali:
That clears up a few items that were unclear to me in the bit of info I found on the object. I am just curios about the flag checking. Is that if there already is an index on the table and you are adding another one? If so, how do I check if there is one present for the next time I call the subroutine to add another one?
Thanks,
EJD
Hmm
I can understand your curiosity. Looking at this code again (which probably found on the SAP SDK documentation) , the flag should be pass as a parameter! And maybe you'll end up with something like this ...
Call addUserTableKeys("TAB1", "PP_Field1", "KEY1", True)
Call addUserTableKeys("TAB1", "PP_Field2", "KEY2")
Call addUserTableKeys("TAB1", "PP_Field2", "KEY3")
in the case of adding multiple keys.
Although my code seems to be working so far I believe this could be a bug on my part.
Hmm
I can understand your curiosity. Looking at this code again (which probably found on the SAP SDK documentation) , the flag should be pass as a parameter! And maybe you'll end up with something like this ...
Call addUserTableKeys("TAB1", "PP_Field1", "KEY1", True)
Call addUserTableKeys("TAB1", "PP_Field2", "KEY2")
Call addUserTableKeys("TAB1", "PP_Field2", "KEY3")
in the case of adding multiple keys.
Although my code seems to be working so far I believe this could be a bug on my part.
Ok I understand...just thought I might have been missing something. So, you might be calling this routine from a loop and sending over whether it is the first time through the loop or the second or third. It is the first time adding a group at a time not to use the Add and not the first one ever created ?
Thanks,
EJD
Right
I thought about it myself also! I use it in a more simple manner thought. In the beginning I was trying though to establish database constraints instead, like sql relationships, foreign and parent keys. I found out though that SAP don't let set these in a more easy-straight forward manner. Is a pain, really!
I can't for instance set a master-child relationship between the Employees Master Table and a User table!
User | Count |
---|---|
91 | |
8 | |
7 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.