Copy tables changing the labels

mikelcid

New Member
Hi all!

First I will show you my code, build using OpenEdge 10.2B:

Code:
	METHOD PUBLIC VOID crearQuery(INPUT sentencia AS CHARACTER,	OUTPUT bindingSource1 AS Progress.Data.BindingSource):
    
   DEFINE VARIABLE hTable AS HANDLE      NO-UNDO.
   DEFINE VARIABLE iField AS INTEGER     NO-UNDO.
   DEFINE VARIABLE hBrowse AS HANDLE      NO-UNDO.
   DEFINE VARIABLE hQuery  AS HANDLE      NO-UNDO.
   DEFINE VARIABLE hBuffer AS HANDLE      NO-UNDO.
   DEFINE VARIABLE bufer AS HANDLE NO-UNDO.   
   
   CREATE QUERY hQuery.
   
    FOR EACH tt_lininf NO-LOCK BY tt_lininf.secuencial_lin:
        tt_bd = tt_lininf.tabla_lin.
        CREATE TEMP-TABLE tabla.
        tabla:CREATE-LIKE(tt_bd).
        tabla:TEMP-TABLE-PREPARE(tt_bd).
        DO iField = 1 TO tabla:DEFAULT-BUFFER-HANDLE:NUM-FIELDS:
           tabla:DEFAULT-BUFFER-HANDLE:BUFFER-FIELD(iField):COLUMN-LABEL = tt_bd + "." + tabla:DEFAULT-BUFFER-HANDLE:BUFFER-FIELD(iField):COLUMN-LABEL.
           tabla:DEFAULT-BUFFER-HANDLE:BUFFER-FIELD(iField):LABEL = tt_bd + "." + tabla:DEFAULT-BUFFER-HANDLE:BUFFER-FIELD(iField):LABEL.
        END.
        CREATE BUFFER hBuffer FOR TABLE tabla.
        hQuery:ADD-BUFFER(hBuffer).
    END.


    hQuery:QUERY-PREPARE(sentencia).


    bindingSource1 = NEW Progress.Data.BindingSource(hQuery).


	RETURN.


	END METHOD.

Well, what I am doing in it is taking a table from my db and modifying the labels because the sentence apply in the query-prepare statement joins the tables and then, after giving the query to the bindingsource, it is given to a DevExpress control that if finds two fields with the same label it only shows one of them.

My problem is that this code works fines, I take the data with "tablename.fieldname" format but it is totally empty, it only has the structure. I have tried to use BUFFER-COPY and COPY-TEMP-TABLE statements but it does not work. I also tried to do it not using the temp-tables, directly using buffers to db but the DevExpress control didn't get the changes in the labels.

Somebody can guess where is the problem that causes the query to be empty and how to fill it?

Thanks in advance!
 
CREATE-LIKE will not copy the contents, it will only copy the structure. So you must copy the contents, for which COPY-TEMP-TABLE works fine as the following example illustrates:

Code:
DEFINE TEMP-TABLE tt NO-UNDO
   FIELD cc AS CHAR
   .


CREATE tt.
tt.cc = "hello".


DEF VAR ht AS HANDLE.
DEF VAR hb AS HANDLE.
DEF VAR lcc AS LONGCHAR.


CREATE TEMP-TABLE ht.
ht:CREATE-LIKE( TEMP-TABLE tt:DEFAULT-BUFFER-HANDLE ).


ht:TEMP-TABLE-PREPARE( "newtt" ).
ht:DEFAULT-BUFFER-HANDLE:BUFFER-FIELD(1):LABEL = "mylabel".
ht:COPY-TEMP-TABLE( TEMP-TABLE tt:DEFAULT-BUFFER-HANDLE ).


ht:DEFAULT-BUFFER-HANDLE:WRITE-XML( "LONGCHAR", lcc, TRUE, ?, ?, TRUE ).


MESSAGE STRING( lcc ) VIEW-AS ALERT-BOX.
 
It is impossible to change temp-table structure after TEMP-TABLE-PREPARE statement.

Second, you have to query tt_bd table and fill tabla temp-tablle with buffer-create methods.
 
I think I have not explained myself well. I don't want to copy a temp-table to another one, I want to have the same data contained in a db table in a temp-table but with the labels changed.

Obviously it is impossible to copy data from a db table to a temp-table with COPY-TEMP-TABLE method so, which would be the correct code to copy data from a db table to a temp-table and then modify the labels?

Also, I have tried to modify the labels directly in a buffer to the db table, it would be very helpful in terms of execution time, but it did not work :(

Thanks a lot!
 
create temp-table TableData.


fieldcount = 0.
FOR EACH system._Field OF system._File NO-LOCK By system._Field._Order:
TableData:ADD-NEW-FIELD (system._Field._Field-name, system._Field._Data-Type, ?, ?, ?, "Your label here").
fieldcount = fieldcount + 1.
END.
TableData:TEMP-TABLE-PREPARE ("TableData").
 
@MaximMonin that code would create the temp-table but empty of data no? Where have I to put the name of the table I want to copy?

The label format I want to give to the fields in my temp-table would be db table name + the previous label name, how can I do that?

Thanks for your fast answer!
 
I used data in _field system.table.

find first system._File where system._File._File-Name = YourTableName NO-LOCK NO-ERROR.
if not available system._File then RETURN.

TableData:ADD-NEW-FIELD (system._Field._Field-name, system._Field._Data-Type, system._Field._Extent, system._field._Format, system._field._Initial, TableName + "." + system._field._Label).
 
@MaximMonin Any method to copy the data from the db to the created temp-table that would not take too much time?

Thanks again!
 
Back
Top