prodataset brain cramps

Posted by jmls on 01-Sep-2011 04:35

As always, when it comes to datasets, my brain seems to get into cramp mode.

All I want to do is to export a query as json. However, write-json does not (for some reason) work on database buffers , only temp-table buffers.

So, given a query on a database buffer, what is the simplest way to create a dataset and fill it with data from the query ?

All Replies

Posted by Admin on 01-Sep-2011 04:40

As the title of your post suggests: use a ProDataset and attach your Query to the DATA-SOURCE of a ProDataset buffer.

Pretty simple and I guess the docs are full of sample code.

Posted by jmls on 01-Sep-2011 04:45

yup, already tried that. got 11884

Dataset buffer must be for a temp-table. (11884)

You may not add normal database tables to a dataset.

So, now I need to create a temp-table, populate said temp-table and

add temp-table to prodataset.

I was wanting to know if there is a simple way of taking this query,

and using it to populate the temp-table.

Julian

On 1 September 2011 10:40, Mike Fechner

Posted by maximmonin on 01-Sep-2011 04:53

define input parameter FileName as character.

define temp-table t_accplan  NO-UNDO LIKE-SEQUENTIAL acc-plan.

define temp-table t_accounts NO-UNDO LIKE-SEQUENTIAL accounts.

define temp-table t_antype   NO-UNDO LIKE-SEQUENTIAL AnType.

define temp-table t_accobj   NO-UNDO LIKE-SEQUENTIAL Apnd-count-obj.

define temp-table t_currency NO-UNDO LIKE-SEQUENTIAL currency.

DEFINE DATASET accdata for t_accplan, t_accounts, t_antype, t_accobj, t_currency.

define variable hDS as handle.

DEFINE DATA-SOURCE ds_accplan  FOR acc-plan.

DEFINE DATA-SOURCE ds_accounts FOR accounts.

DEFINE DATA-SOURCE ds_antype   FOR AnType.

DEFINE DATA-SOURCE ds_accobj   FOR Apnd-count-obj.

DEFINE DATA-SOURCE ds_currency FOR currency.

BUFFER t_accplan:ATTACH-DATA-SOURCE (DATA-SOURCE ds_accplan:HANDLE ).

BUFFER t_accounts:ATTACH-DATA-SOURCE(DATA-SOURCE ds_accounts:HANDLE).

BUFFER t_antype:ATTACH-DATA-SOURCE  (DATA-SOURCE ds_antype:HANDLE  ).

BUFFER t_accobj:ATTACH-DATA-SOURCE  (DATA-SOURCE ds_accobj:HANDLE  ).

BUFFER t_currency:ATTACH-DATA-SOURCE(DATA-SOURCE ds_currency:HANDLE  ).

hDS = DATASET accdata:HANDLE.

hDS:FILL ().

run src/transfer/XmlWriteDataset.p (FileName, DATASET-HANDLE hDS).

Posted by Admin on 01-Sep-2011 05:50

I was wanting to know if there is a simple way of taking this query,

and using it to populate the temp-table.

We may have different opinions about simple then

Posted by jmls on 01-Sep-2011 05:50

thanks to all, this is what I needed for my simple requirements

  method public longchar ExportJson(p_buffer as handle,p_Query as handle):

    def var TempTable1  as handle no-undo.

    def var DataSet1    as handle no-undo.

    def var DataSource1 as handle no-undo.

    def var lv_Data as longchar no-undo.

    create temp-table TempTable1.

    TempTable1:CREATE-LIKE(p_Buffer).

    TempTable1:TEMP-TABLE-PREPARE("TTCustomer").

    TempTable1:serialize-name = "Customer".

    create dataset DataSet1.

    DataSet1:add-buffer(TempTable1:default-buffer-handle).

    create data-source DataSource1.

    DataSource1:query = p_Query.

    TempTable1:default-buffer-handle:ATTACH-DATA-SOURCE(DataSource1:handle).

    DataSet1:fill().

    TempTable1:write-json("longchar",lv_Data).

    return lv_Data.

  end method.

thanks again.

Posted by jmls on 01-Sep-2011 05:55

I *still* want to know why you can't :write-xml from a query handle . Or from a buffer. Or from an object ....

Posted by Admin on 01-Sep-2011 06:05

I still want to know why you can't :write-xml from a query handle . Or from a buffer. Or from an object ....

Because it's not yet implemented for those other potential sources.... As simple as that.

So everybody with similar requests, register for www.pugchallenge.eu and attend the ABL and tools info exchange session with Shelley Chase, Sunil Belgoankar and Ken Wilner from PSC. The best occasion to discuss your feature wish list!

This thread is closed