How to handle "Segments" -- 01 definitions that apply WITHIN a record

2014-05-24
2014-05-24
  • Steven F. Lott
    Steven F. Lott
    2014-05-24

    I understand how to parse a workbook using one schema or another, but I'm not sure how to use multiple schemas on 1 workbook, especially when the schema parsing itself doesn't provide the necessary "REDEFINES" location....

    I know that the different segments define the data that may be found within the RDT-ADDL-DATA, but there is nothing in the copybook to inform Stingray of that....

    Also, using Stingray is it possible to access schema_dict['RDT-ADDL-SEG-KEY'].value since RDT-ADDL-SEG-KEY isn't actually a PICTURE itself?

    Would it be inappropriate to define the value of a group to be the concat values of the elements making up the group?

     
  • Steven F. Lott
    Steven F. Lott
    2014-05-24

    "the different segments define the data that may be found within RDT-ADDL-DATA"

    Aha.

    That clarifies many things. And that provides a strategic direction to me.

    In COBOL, they probably do a simple move from RDT-ADDL-DATA to the appropriate 01 level storage.

    A similar effect is available in Python if we pick the source record's bytes apart to create a secondary bunch of bytes for this sub-record or segment as they're calling it.

    At first blush is seems that something like

    segment = ODO_LazyRow(
        sheet,
        data= row[ schema_dict['RDT-ADDL-DATA'].offset: schema_dict['RDT-ADDL-DATA'].offset+size ],
        )
    

    should build a row-like object bound to the sheet's schema.

    But that's not quite it; we also need to build a new kind of Sheet with the right schema based on DDE that applies to that segment. Once we have this segment-specific Sheet, we can build LazyRow objects and the rest of the machinery should work correctly.

    segment = ODO_LazyRow(
         ExternalSchemaSheet( workbook, "segment_name", segment_schema['segment_name'] ),
         data = ... 
         )
    

    That might be closer to what's required.

     
    Last edit: Steven F. Lott 2014-05-24
  • Steven F. Lott
    Steven F. Lott
    2014-05-24

    Release 4.4.4 may solve this via "subrecord" processing.

    See :py:class:stingray.test.cobol_2.Test_Copybook_13( DDE_Test ).

    The idea is that we can do

    subrow= data.subrow( self.segment_abc, row.cell(schema_header_dict['GENERIC-FIELD'])  )
    

    This can map a field, GENERIC-FIELD, to an 01-level schema, self.segment_abc.
    We can then pick fields out of subrow using fields defined in self.segment_abc.