creating tables using preprocessor names

whwar9739

Member
Hopefully I can explain this well enough to get the answer I am looking for.

What I am trying to do is create an include file to be able to create a table dynamically.

I have a set of tables where they all have the same fields. The only difference from one table to the next is the data type of one field. Below is what i would like to see in the main program:

Code:
{cnv-ud.i
   &type = ""
   &int-field = "1"
   &dec-field = "123456"
   &ch-field = ""
   &int-field1 = "1"
   &udval = "xxxx"
}

In the above example type would tell me what type of field the udval is, whether it is an integer or a character or a decimal....etc.

The other fields are the key fields in the tables and are always the same type and same name. What I would like to see the cnv-ud.i file look like would be similar to the following:

Code:
FIND {&type} NO-LOCK
   WHERE {&type}.int-field = {&int-field}
       AND {&type}.dec-field = {&dec-field}
       AND {&type}.ch-field  = {&ch-field}
       AND {&type}.int-field1 = {&int-field1}
   NO-ERROR.

IF NOT AVAILABLE {&type}
THEN DO:
   CREATE {&type}.
   ASSIGN
      {&type}.int-field = {&int-field}
      {&type}.dec-field = {&dec-field}
      {&type}.ch-field = "{&ch-field}"
      {&type}.int-field1 = {&int-field1}
      {&type}.udval      = {&udval}

I hope this makes sense, feel free to ask questions if it does not, and i will try to provide as much information as I can.
 

jmac13

Member
first off what version of open edge are you using?

if I've understood what ur saying your saying you are trying to create a record for 3 different tables. All the fields are the same just the names are different. I'd use a query objects and buffer objects to do this. Example i did is a genric create procedure (see below)


Code:
chrAssignValues = "specNo," + string(intSpecNo).  
run CreateTable(input "specCert",chrAssignValues).
 
CreateTable:
 
 
/*Create a pointer to the choosen table e.g. SpecCert*/    
create buffer hanPointerToRealTable for table ipchrCreationTable no-error. 
 
 
if not valid-handle(hanPointerToRealTable) then    
  return.    
        
do transaction:    
   hanPointerToRealTable:buffer-create(). /*create a Record*/    
 
  /*Assign and Values to fields*/    
        do intCount = 2 to num-entries(ipchrAssignValues) by 2:    
            chrFieldName   = entry(intCount - 1,ipchrAssignValues,",").    
            chrAssignValue = entry(intCount,ipchrAssignValues,",").    
        
    hanPointerToRealTable:buffer-field(chrFieldName):buffervalue  = chrAssignValue.     
        end.  
end.

It creates a record for the table name you pass through and goes through the string chrAssignvalues and assign the values based on the field name (format fieldName,Value).

so you just need to added a query object check at the start to see if ur record is already there if not go ahead a create it
 
Top