Renaming Fields

7 posts / 0 new
Last post
aveenm293
Offline
Joined: 10/23/2012 - 16:02
Renaming Fields

Hi Brian
I have imported multiple SAP outputs. I am finding that the column headings are in German, but I know what each if them mean. I was wondering is there a script of a way to rename each of the fields, if field manipulation prevents change of column names.
Thank you
Regards
Aveen
 
 
 

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Aveen, I am not sure what you mean by the field manipulation preventing you changing the column names, you should be able to do it via the field manipulation but you can also change column names by a script.  I don't have access to IDEA right now but I will post the code on how to change a field name tonight.

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Aveen, below is an example piece of code that will rename fields.  You would need a new db.TableDef.NewField section for each field you want to change.  The script below will change three fields, one a date, one numerica and one is character.  I have justed added 1 to the end of the field name.  Hopefully this will help you out.

Sub Main
    Call ModifyField()    'General Ledger-GL.IMD
End Sub


' Modify Field
Function ModifyField
    Set db = Client.OpenDatabase("General Ledger-GL.IMD")
    Set task = db.TableManagement
    
    Set field = db.TableDef.NewField
    field.Name = "PERIOD1" 'new field name
    field.Description = ""
    field.Type = WI_NUM_FIELD 'numeric field
    field.Equation = ""
    field.Decimals = 0
    task.ReplaceField "PERIOD", field 'old field name
    task.PerformTask
    
    Set field = db.TableDef.NewField
    field.Name = "DATE1" 'new field name
    field.Description = ""
    field.Type = WI_DATE_FIELD 'date field
    field.Equation = "YYYYMMDD"
    task.ReplaceField "DATE", field 'old field name
    task.PerformTask
    
    Set field = db.TableDef.NewField
    field.Name = "SOURCE1" 'new field name
    field.Description = ""
    field.Type = WI_CHAR_FIELD 'character field
    field.Equation = ""
    field.Length = 2
    task.ReplaceField "SOURCE", field 'old field name
    task.PerformTask

    Set task = Nothing
    Set db = Nothing
    Set field = Nothing
End Function

VITOPIEPOLI
Offline
Joined: 10/29/2019 - 11:28

Hi Brian,
is there any funtion that gives me the possibility to modify all the 54 field headers, with an incremental progression of year weeks (from 1 to 54) without repeating the code all the times?
I am working with Version 10.
 
Many thanks for your help.
Vito

egonzaleze
Offline
Joined: 08/26/2016 - 15:28

Hi, there. How can I do something similar with databases?? How can I rename an Idea database from ideascript?

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Elías,

There is a function in the Progract Management object that will allow you to do this.  Here is some example code.  Your database should be closed when doing this or else IDEA will probably give you an error.

Brian

Sub Main
	Set task = Client.ProjectManagement
		task.RenameDatabase "Old Name.IMD", "New Name.IMD"
	Set task = Nothing
End Sub

 

TMC
Offline
Joined: 10/20/2016 - 09:43

looks interesting. the other day I was thinking of a method that would rename databases to a standard name so that generic scrips can be run with these renamed databases. In terms of SAP databases for different years appear to have different prefixes like A_TXW_TABLE1, B_TXW_TABLE2 which could be clensed so that standard scripts will work...