Question Passing datasets: should I pass as handle or dataset-handle?

progdev1

Member
Hi guys,
I am wondering if someone could advise me here on something regarding passing data-set between procedures.

If I use the following code snippet as an example .

Code:
DEFINE TEMP-TABLE tt-ch no-undo SERIALIZE-NAME "datarow"
    FIELD account-id    AS CHARACTER    SERIALIZE-NAME "ACCOUNT_NO"       
    FIELD account-name  AS CHARACTER    SERIALIZE-NAME "ACCOUNT_NAME"     
    FIELD phone        as character    SERIALIZE-NAME "PHONE".
 
DEFINE DATASET dsCustOrd SERIALIZE-NAME "datarow"
    FOR tt-ch.
 
DEFINE VARIABLE  lch  AS LONGCHAR  NO-UNDO.
DEFINE VARIABLE  lOK  AS LOGICAL  NO-UNDO.
DEFINE VARIABLE  vhdl AS HANDLE    NO-UNDO.
 
ASSIGN lch = '
<?xml version="1.0"?>
<data>
    <datarow><ACCOUNT_NAME>SP account BTC 1</ACCOUNT_NAME><ACCOUNT_NO>123456789</ACCOUNT_NO><PHONE>1234</PHONE></datarow>
    <datarow><ACCOUNT_NAME>SP account CAD 1</ACCOUNT_NAME><ACCOUNT_NO>1234567896</ACCOUNT_NO><PHONE>1234</PHONE></datarow>
    <datarow><ACCOUNT_NAME>SP account EUR 1</ACCOUNT_NAME><ACCOUNT_NO>1234567891</ACCOUNT_NO><PHONE>1234</PHONE></datarow>
    <datarow><ACCOUNT_NAME>SP account USD 1</ACCOUNT_NAME><ACCOUNT_NO>1234567891</ACCOUNT_NO><PHONE>1234</PHONE></datarow>
</data>'.
 
ASSIGN vhdl = DATASET dsCustOrd:HANDLE.
 
EMPTY TEMP-TABLE tt-ch.
 
RUN read-xml-procedure (INPUT  vhdl).
 
FOR EACH tt-ch NO-LOCK:
    DISP tt-ch.
END.
 
PROCEDURE read-xml-procedure:
    DEFINE INPUT  PARAMETER htt AS HANDLE NO-UNDO  .
 
    run read-xml-procedure2 (INPUT  htt).
END PROCEDURE.
 
PROCEDURE read-xml-procedure2:
    DEFINE INPUT  PARAMETER htt AS HANDLE NO-UNDO  .
 
    lOK = htt:READ-XML('LONGCHAR', lch, 'APPEND', ?, ?, ?, ?).
END PROCEDURE.

The code works but I'm wondering whether my input parameters should be dataset-handle as opposed to handles. E.g DEFINE INPUT PARAMETER DATASET-HANDLE htt instead of DEFINE INPUT PARAMETER htt AS HANDLE NO-UNDO.

Can someone please explain the difference between passing a parameter as a dataset handle as opposed to just a handle and which is more correct in this case. My big worry here is when I go to do this using handle insead of DATASET-HANDLE will crash or not work properly if the table data gets too big. But I'd just like to know what the difference is in this case.

As said in the comment in a real scenario read-xml-parameter2 would be in a separate super procedure program on the server, and obviously the variable names etc would be better.
 

Cringer

ProgressTalk.com Moderator
Staff member
If you put [code][/code] tags around your code it maintains the indentation and makes it easier to read.
 

progdev1

Member
Okay apologies, I hope this is easier to read.

Code:
DEFINE TEMP-TABLE tt-ch no-undo SERIALIZE-NAME "datarow"
    FIELD account-id    AS CHARACTER    SERIALIZE-NAME "ACCOUNT_NO"         
    FIELD account-name  AS CHARACTER    SERIALIZE-NAME "ACCOUNT_NAME"      
    FIELD phone         as character    SERIALIZE-NAME "PHONE".
 
DEFINE DATASET dsCustOrd SERIALIZE-NAME "datarow"
    FOR tt-ch.
 
DEFINE VARIABLE  lch  AS LONGCHAR  NO-UNDO.
DEFINE VARIABLE  lOK  AS LOGICAL   NO-UNDO.
DEFINE VARIABLE  vhdl AS HANDLE    NO-UNDO.
 
ASSIGN lch = '
<?xml version="1.0"?>
<data>
    <datarow><ACCOUNT_NAME>SP account BTC 1</ACCOUNT_NAME><ACCOUNT_NO>123456789</ACCOUNT_NO><PHONE>1234</PHONE></datarow>
    <datarow><ACCOUNT_NAME>SP account CAD 1</ACCOUNT_NAME><ACCOUNT_NO>1234567896</ACCOUNT_NO><PHONE>1234</PHONE></datarow>
    <datarow><ACCOUNT_NAME>SP account EUR 1</ACCOUNT_NAME><ACCOUNT_NO>1234567891</ACCOUNT_NO><PHONE>1234</PHONE></datarow>
    <datarow><ACCOUNT_NAME>SP account USD 1</ACCOUNT_NAME><ACCOUNT_NO>1234567891</ACCOUNT_NO><PHONE>1234</PHONE></datarow>
</data>'.
 
ASSIGN vhdl = DATASET dsCustOrd:HANDLE.
 
EMPTY TEMP-TABLE tt-ch.

RUN read-xml-procedure (INPUT  vhdl).
 
FOR EACH tt-ch NO-LOCK:
    DISP tt-ch.
END.
 
PROCEDURE read-xml-procedure:
    DEFINE INPUT  PARAMETER htt AS HANDLE NO-UNDO  .
 
    run read-xml-procedure2 (INPUT  htt).
END PROCEDURE.
 
PROCEDURE read-xml-procedure2:
    DEFINE INPUT  PARAMETER htt AS HANDLE NO-UNDO  .
 
    lOK = htt:READ-XML('LONGCHAR', lch, 'APPEND', ?, ?, ?, ?).
END PROCEDURE.
 

Stefan

Well-Known Member
If you are passing with the same session, there is no added value in passing a DATASET-HANDLE since you can pass the HANDLE. The DATASET-HANDLE allows you to pass the schema information over the wire (from client to AppServer) resulting in a complete dynamic restore of dataset on the other side.

Note that the DATASET-HANDLE is passed as a HANDLE if the caller and callee are in the same session.

If you are on the same side you may also want to read up on the BY REFERENCE and BIND options.

Also: when passing DATASET-HANDLEs - you need to clean these up yourself (just like when passing TABLE-HANDLEs), they implicitly create a dataset which you explicitly need to DELETE OBJECT.
 

progdev1

Member
Okay guys thanks a million for your help and and those tips. It cleared things up a lot and has given the answers I need.
 

tamhas

ProgressTalk.com Sponsor
If you are in the same session, then consider wrapping all the relevant logic around the dataset in a PP or object and don't pass anything except the handle to the object. Encapsulation is a wonderful principle.
 
Top