Menu

Record Selector - how to?

2018-10-17
2018-10-18
  • Ranga Nathan

    Ranga Nathan - 2018-10-17

    I want to use the record selection feature to filter only the records I want to read. Also, I want to separately group the columns based on the record. I see some code example of Record Selector / setRecordSelection which shows how to set but I dont see an example of how to use it.

    Also, I have a complex record selection rule, like below. I would like to know how to define this and how to retrieve only the records I need. Thanks

    if RDT-REC-CODE-KEY "D" or reject the record

    if RDT-REC-TYPE-CONTROL = "", "A","B","E","F","N","S" then REPORT-TAPE-DETAIL-RECORD

    if RDT-REC-TYPE-CONTROL = "C","T","X" then RDT-RECORD-TYPE-DCX

    if RDT-REC-TYPE-CONTROL = "P" then RDT-RECORD-TYPE-DP

    if RDT-REC-TYPE-CONTROL = "R" then RDT-RECORD-TYPE-DR

    if RDT-REC-TYPE-CONTROL = "S" RDT-DS-RECORD-TYPE-MULTRAN

     
  • Bruce Martin

    Bruce Martin - 2018-10-18

    The way to get the record-type is via the getPreferredLayoutIdx (I should change it to get...RecordIndex ???). i.e

    int recordIndex = line.getPreferredLayoutIdx()
    

    There is 3 ways decide on the record Type:

    • Hard-Coded in the java code (see AmsPoDownload02.java ). JRecord you does not need to know the RecordType. You can decide what the record is after it has been read.
    • Using the RecordDecider interface - its a java interface for determining the RecordType
    • Using RecordSelection option, use IoBuilder.setRecordSelection(...). This Option has its origin in saving FileDescriptions as Xml. See .setRecordSelection in TstMultiCopybookDef.java

    I will try and write a Wiki entry


    Anyway AmsPoDownload01.java:

        String copyName = this.getClass().getResource(copybookFileName).getFile();
            String poFile   = this.getClass().getResource(dataFileName).getFile();
            AbstractLine l;
    
            IRecordDeciderX recordDecider = JRecordInterface1.RECORD_DECIDER_BUILDER
                             .singleFieldDeciderBuilder("Record-Type", true)
                                    .addRecord("H1", PO_RECORD)
                                    .addRecord("D1", PRODUCT_RECORD)
                                    .addRecord("S1", LOCATION_RECORD)
                             .build();
    
            ICobolIOBuilder ioBldr = JRecordInterface1.COBOL
                        .newIOBuilder(copyName)
                            .setDialect(ICopybookDialects.FMT_FUJITSU)
                            .setFileOrganization(Constants.IO_BIN_TEXT)
                            .setSplitCopybook(CopybookLoader.SPLIT_01_LEVEL)
                            .setRecordDecider(recordDecider);
    
            LayoutDetail layout  = ioBldr   .getLayout();
            AbstractLineReader r = ioBldr   .newReader(poFile);
    
            while ((l = r.read()) != null) {
                String recordName = layout.getRecord(l.getPreferredLayoutIdx()).getRecordName();
    
                switch (recordName) {
                case PO_RECORD: 
                    System.out.println("PO: " 
                            +         l.getFieldValue("PO").asString()
                            + " "   + l.getFieldValue("Vendor").asString()
                    );
                    break;
                case PRODUCT_RECORD:
                    System.out.println("\tProduct: " 
                            +       l.getFieldValue("Product").asString()
                            + "\t" + l.getFieldValue("Product-Name").asString()
                    );
                    break;
                case LOCATION_RECORD:
                    System.out.println("\t\tLocation: " 
                            +       l.getFieldValue("DC-Number (1)").asString()
                            + " " + l.getFieldValue("Pack-Quantity (1)").asString()
                            + "\t" + l.getFieldValue("DC-Number (2)").asString()
                            + " " + l.getFieldValue("Pack-Quantity (2)").asString()
                    );
                }
    
            }
            r.close();
    
     

    Last edit: Bruce Martin 2018-10-18
  • Bruce Martin

    Bruce Martin - 2018-10-18

    With regards RecordSelection, I do not have any good examples beyond the java do,. You can use And / Or classes to do multiple tests i.e.

         IOBldr.setRecordSelection(
              "Trailer-Record",
              ExternalGroupSelection.newAnd(
                   new ExternalFieldSelection("Record-Type-1", "D"),
                   ExternalGroupSelection.newOr(
                        new ExternalFieldSelection("Record-Type-2", "D"),
                        new ExternalFieldSelection("Record-Type-2", "E"),
                        new ExternalFieldSelection("Record-Type-2", "F")
                   )
              ));
    

    for

      if RDT-REC-TYPE-CONTROL = "C","T","X" then RDT-RECORD-TYPE-DCX
    

    you would code

         IOBldr.setRecordSelection(
              "RDT-RECORD-TYPE-DCX",
              ExternalGroupSelection.newOr(
                         new ExternalFieldSelection("RDT-REC-TYPE-CONTROL", "C"),
                        new ExternalFieldSelection("RDT-REC-TYPE-CONTROL", "T"),
                        new ExternalFieldSelection("RDT-REC-TYPE-CONTROL", "X")
              ));
    
     

Log in to post a comment.