Logical To String Conversion With Format Using Buffer-field

Posted by davidvilla on 19-Feb-2017 02:58

Hi, I am trying to dynamically convert a logical value to string with a specific format. It works fine, but the TRUE value is not getting displayed properly. See example below. 
define variable httOutData      as handle    no-undo.
define variable bhttOutData     as handle    no-undo.
 
create temp-table httOutData.
httOutData:add-new-field("mylogfield","character",0,"ACTIVE/INACTIVE",?,"","ACTIVE-FLAG").
httOutData:temp-table-prepare("httOutData").
bhttOutData = httOutData:default-buffer-handle.
 
for each tablename no-lock:
bhttOutData:buffer-create().
bhttOutData:buffer-field(1):buffer-value =  string(tablename.logfield,bhttOutData:buffer-field(1):format).
 
disp bhttOutData:buffer-field(1):buffer-value tablename.logfield .
 
end.


In this code, the value for yes is displayed as "A" (instead of "ACTIVE"). This is my problem. I tried replacing "ACTIVE" in the format with some other text and got weird results. 

Why does this happen? How do I fix this?

I am using OE11.5 with HP-UX environment.

Posted by tpavlovic on 19-Feb-2017 06:30

Are you two serious? Take a look at character display formats.

documentation.progress.com/.../index.html

Change this
    httOutData:add-new-field("mylogfield","character",0,"ACTIVE/INACTIVE",?,"","ACTIVE-FLAG").
into this
    httOutData:add-new-field("mylogfield","character",0,"x(8)",?,"","ACTIVE-FLAG").

and this
    bhttOutData:buffer-field(1):buffer-value =  string(tablename.logfield,bhttOutData:buffer-field(1):format).
into this
    bhttOutData:buffer-field(1):buffer-value =  string(tablename.logfield,"ACTIVE/INACTIVE").

OR this
    httOutData:add-new-field("mylogfield","character",0,"ACTIVE/INACTIVE",?,"","ACTIVE-FLAG").
into this
    httOutData:add-new-field("mylogfield","LOGICAL",0,"ACTIVE/INACTIVE",?,"","ACTIVE-FLAG").

and this
    bhttOutData:buffer-field(1):buffer-value =  string(tablename.logfield,bhttOutData:buffer-field(1):format).
into this
    bhttOutData:buffer-field(1):buffer-value = tablename.logfield.

    disp string(bhttOutData:buffer-field(1):buffer-value, bhttOutData:buffer-field(1):FORMAT) tablename.logfield .

All Replies

Posted by goo on 19-Feb-2017 06:06

I tested it on 11.6.2, same result...strange, since if you put in a false value, Works. only true value will give wrong result.

DEF VAR b AS LOG FORMAT "Acitve/Inactive" NO-UNDO.

DEF VAR c AS CHAR FORMAT "Active/Inactive" NO-UNDO.

DEF VAR h AS HANDLE NO-UNDO.

DEF VAR bh AS HANDLE NO-UNDO.

CREATE TEMP-TABLE h.

h:ADD-NEW-FIELD("myLogField","character",0,"Active/Inactive",?,"","Active-flag").

h:TEMP-TABLE-PREPARE("tt").

bh = h:DEFAULT-BUFFER-HANDLE.

ASSIGN

 b = FALSE

 c = STRING(b,"Active/Inactive")

 .

bh:BUFFER-CREATE().

bh::myLogField = STRING(b,bh:BUFFER-FIELD(1):FORMAT).

MESSAGE  b SKIP

        c  SKIP

        bh::myLogField SKIP

        bh:BUFFER-FIELD(1):FORMAT

   VIEW-AS ALERT-BOX INFO BUTTONS OK.

Posted by goo on 19-Feb-2017 06:09

If you use "ON/OFF" the result With a true value will be "N".... strange

Posted by tpavlovic on 19-Feb-2017 06:30

Are you two serious? Take a look at character display formats.

documentation.progress.com/.../index.html

Change this
    httOutData:add-new-field("mylogfield","character",0,"ACTIVE/INACTIVE",?,"","ACTIVE-FLAG").
into this
    httOutData:add-new-field("mylogfield","character",0,"x(8)",?,"","ACTIVE-FLAG").

and this
    bhttOutData:buffer-field(1):buffer-value =  string(tablename.logfield,bhttOutData:buffer-field(1):format).
into this
    bhttOutData:buffer-field(1):buffer-value =  string(tablename.logfield,"ACTIVE/INACTIVE").

OR this
    httOutData:add-new-field("mylogfield","character",0,"ACTIVE/INACTIVE",?,"","ACTIVE-FLAG").
into this
    httOutData:add-new-field("mylogfield","LOGICAL",0,"ACTIVE/INACTIVE",?,"","ACTIVE-FLAG").

and this
    bhttOutData:buffer-field(1):buffer-value =  string(tablename.logfield,bhttOutData:buffer-field(1):format).
into this
    bhttOutData:buffer-field(1):buffer-value = tablename.logfield.

    disp string(bhttOutData:buffer-field(1):buffer-value, bhttOutData:buffer-field(1):FORMAT) tablename.logfield .

Posted by goo on 19-Feb-2017 06:38

I first thought about giving a logical format to a character seemed a bit strange, but when I tried it, I was supprised to see that it worked, or at least pretty near working :-)

But I understand that the display format for character should not be mix with the format of a logical field :-) Thanks for the info...

Posted by davidvilla on 20-Feb-2017 02:00

Thank you for the information. It was helpful.

This thread is closed