Wed Mar 20, 2019 5:28 pm
Login Register Lost Password? Contact Us


Loading a DATASET with a Record Structure

Share ideas, code, best practices and techniques with other community members

Thu Dec 20, 2018 10:02 am Change Time Zone

Hi,
I was having to flatten a complex data structure and realised a structure in a DATASET would be easy to use. I reproduce below as it may be of general use. (I just used it for my specific task, Richard Taylor has generalised by wrapping it inside a FUNCTIONMACRO)
Code: Select all
//************************************************************************
RecordStructureAsDATASET(RecStruct) := FUNCTIONMACRO
      #DECLARE(xmlOfRecordStructure)
      #EXPORT(xmlOfRecordStructure,RecStruct)

      RRec := RECORD
          STRING ecltype    := XMLTEXT('@ecltype');
          BOOLEAN isRecord  := (BOOLEAN) XMLTEXT('@isRecord');
          STRING label      := XMLTEXT('@label');
          STRING name       := XMLTEXT('@name');
          STRING position   := XMLTEXT('@position');
          STRING rawtype    := XMLTEXT('@rawtype');
          STRING size       := XMLTEXT('@size');
          STRING ttype      := XMLTEXT('@type');
          BOOLEAN isEnd     := (BOOLEAN) XMLTEXT('@isEnd');
      END;

      OnRec := {STRING FldEntry};
      RETURN PARSE(DATASET([{%'xmlOfRecordStructure'%}],OnRec),FldEntry,RRec,XML('Data/Field'));
ENDMACRO;
//************************************************************************

R1abc := RECORD
   UNSIGNED1 u1;
   STRING2   s2;
   SET OF STRING3 ss3;
END;

R2def := RECORD
   REAL4 r4;
   UDECIMAL3_2 ud32;
   R1abc;
   R1abc InnerR1;
END;

R := RECORD
   BOOLEAN b;
   QSTRING5 qs5;
   DATASET(R1abc) dsr1;
   SET OF DATASET(R2def) sdsr2;
END;

OUTPUT(RecordStructureAsDATASET(R),NAMED('RecordStructureAsDATASET'));

Running the above gives:
Image
Allan
 
Posts: 351
Joined: Sat Oct 01, 2011 7:26 pm

Return to Tips & Tricks

Who is online

Users browsing this forum: No registered users and 0 guests