How to use `export` with buffer handle?

AXMIM

Exporting the data of a table before deleting it work like a charm.
Example :

OUTPUT TO VALUE("C:\mytable.d") APPEND.
EXPORT mybd.mytable.
OUTPUT CLOSE. 
DELETE mybd.mytable.

However, I've yet to make it work when using a buffer handle instead. The following exports an integer instead of the data deleted.

DEF INPUT PARAM hlTableToDelete AS HANDLE NO-UNDO.
...
OUTPUT TO VALUE("C:\" + hiTableToDelete:NAME + ".d") APPEND.
EXPORT hlTableToDelete:HANDLE.
OUTPUT CLOSE. 
hlTableToDelete:BUFFER-DELETE().

Which syntax is needed for command export to work and actually export the data of the buffer handle?

Tom Bascom

EXPORT only works with static buffers. There is no EXPORT method on buffer handles.

To get equivalent functionality you will need to write some code that loops through the field list.

Something along these lines should get you started:

/* export data like EXPORT does
 *
 * makes no attempt to handle LOB data types
 *
 */

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.

  put stream expFile skip.                                                      /* don't forget the newline! ;-)                */

  return true.

end.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related