Transforming the string value into a table field

Posted by savoine on 15-Dec-2015 11:15

temp-table tt-param
     field c-from as char
     field c-to as char.

create tt-param.
assign tt-param.c-from = "#name#"
            tt-param.c-to = "customer.name".

def var c-string as char no-undo. assign c-string = "my company #name#". find first customer no-lock no-error.

How to convert the string value "tt-param.c-to"  to table field.

Sorry for bad English.

All Replies

Posted by Tim Kuehn on 15-Dec-2015 11:21

The following code'll create a dynamic buffer for the table, then reference the field for that buffer that you want. Because you're creating a dynamic object, you'll also need to delete it from memory when you're done.



DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO. DEFINE VARIABLE hField AS HANDLE NO-UNDO. CREATE BUFFER hBuffer FOR TABLE ENTRY(1, tt-param.c-to, ".") . hField = hBuffer:BUFFER-FIELD(ENTRY(2, tt-param.c-to, ".")). MESSAGE hField:BUFFER-VALUE VIEW-AS ALERT-BOX INFO BUTTON OK.

DELETE OBJECT hBuffer.

Posted by savoine on 15-Dec-2015 11:33

DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hField  AS HANDLE NO-UNDO.
def var c-string as char no-undo.


DEFINE TEMP-TABLE tt-param
    field c-from as char
    field c-to as char.
 
create tt-param.
assign tt-param.c-from = "#name#"
            tt-param.c-to = "estabelec.nome".
 
assign c-string  = "my company #name#".
 
find first estabelec no-lock no-error.


MESSAGE estabelec.nome SKIP
    ENTRY(1, tt-param.c-to, ".") 
    VIEW-AS ALERT-BOX INFO BUTTONS OK.

/* Message: NAME = OK (show) , entry = estabelec */

CREATE BUFFER hBuffer
    FOR TABLE ENTRY(1, tt-param.c-to, ".").
    
ASSIGN hField = hBuffer:BUFFER-FIELD(ENTRY(2, tt-param.c-to, ".")).

/* Message ERROR: **RECORD NOT AVAILABLE */

MESSAGE hField:BUFFER-VALUE
    VIEW-AS ALERT-BOX info BUTTON OK.

Posted by Tim Kuehn on 15-Dec-2015 11:40

Forgot to add that you'll need to do something like this after the CREATE BUFFER.

  hBuffer:FIND-FIRST("estabelec WHERE estabelec.CustNum = 123").

That'll get you a start on using dynamic buffers. Consult the reference docs for more information on how to proceed.

Posted by savoine on 15-Dec-2015 11:53

OK, thanks...

but if so, would somehow too?

tt-param.c-to = "IF estabelec.state = 1 THEN 'xxxx' ELSE 'aaaa'".

Sorry ;)

Posted by Tim Kuehn on 15-Dec-2015 11:58

You can put that in the WHERE phrase of a dynamic lookup, there's no way to execute that at run-time though.

Posted by savoine on 15-Dec-2015 12:15

Thank you for the tip... but.... rsrsrs

/* He has caught the table above information without having to run the statement again. */

hBuffer = BUFFER estabelec:HANDLE.
hField = hBuffer:BUFFER-FIELD(ENTRY(2, tt-param.c-to, ".")).

/*
how to change this:  estabelec:HANDLE
for this: ENTRY(1, tt-param.c-to, ".")
*/

MESSAGE hField:BUFFER-VALUE
    VIEW-AS ALERT-BOX info BUTTON OK.

Posted by Tim Kuehn on 15-Dec-2015 12:19

If you don't need a dynamic buffer, then you can chain these:

hField = BUFFER estabelec:HANDLE:BUFFER-FIELD(ENTRY(2, tt-param.c-to, ".")):BUFFER-VALUE

Posted by savoine on 15-Dec-2015 12:24

Tim,
I have this temp table with several more in different fields and tables also wanted to automate it.

table estabelec has can not be fixed.

||

hField = BUFFER estabelec:HANDLE:BUFFER-FIELD(ENTRY(2, tt-param.c-to, ".")):BUFFER-VALUE 

Posted by Tim Kuehn on 15-Dec-2015 12:29

Then you have to use the CREATE BUFFER technique. You can put that code into a procedure and then call it as needed for each TT record / configuration you're using.

Posted by savoine on 15-Dec-2015 12:44

Excuse my ignorance but you could show me an example?

Posted by Tim Kuehn on 15-Dec-2015 13:21

Look in the Reference docs for "PROCEDURE", you'll find examples of how to write a procedure, pass parameters, etc.

Posted by savoine on 16-Dec-2015 07:08

Sorry, I tried using includes and procedures and can not replace 'estabelec:HANDLE' for '{1}:HANDLE'

He does not use the value of the field only the name of his declaration "ENTRY(1, tt-param.c-to, ".")"

This thread is closed