Question Dynamic Field Handle for array fields

davidvilla

Member
Hi
I am trying to set fields dynamically in a table with array fields. I am not sure, how to represent an element of the array field when setting the field handle. Here is my example.

define temp-table tt1
fields fld1 as int extent 3.

define variable bh-tt1 as handle no-undo.
define variable fh-tt1 as handle no-undo.

bh-tt1 = buffer tt1:handle.
fh-tt1 = bh-tt1:buffer-field("fld1"). --> how should I represent the elements of the array here.
I tried bh-tt1:buffer-field("fld1[1]") and bh-tt1:buffer-field("fld1")[1]. Both didn't work.

Any ideas?

Thanks in advance!
 

TomBascom

Curmudgeon
Code:
function exportData returns logical ( input bh as handle ): 

  define variable bf as handle  no-undo.  /* handle to the field  */
  define variable f  as integer  no-undo.  /* field number  */
  define variable i  as integer  no-undo.  /* array index  */

  do f = 1 to bh:num-fields:  /* for each field...  */

    bf = bh:buffer-field( f ).  /* get a pointer to the field  */

    if f > 1 then put stream expFile unformatted field_sep.  /* output field separator  */

    if bf:extent = 0 then  /* is it an array?  */
      put stream expFile unformatted  
        ( if bf:data-type = "character" then  /* character data needs to be quoted to */
          quoter( string( bf:buffer-value ))  /* handle (potential) embedded delimiters  */
       else  /* and quotes within quotes!  */
          string( bf:buffer-value )  /* other data types should not be quoted  */
        )
      .
    else  /* array fields need special handling  */
      do i = 1 to bf:extent:  /* each extent is exported individually  */
        if i > 1 then put stream expFile unformatted field_sep.  /* and a field separator  */
          put stream expFile unformatted
            ( if bf:data-type = "character" then  /* see above...  */
              quoter( string( bf:buffer-value( i )))
            else
              string( bf:buffer-value( i ))
            )
           field_sep
          .
     end.

  end.
 
Top