Menu

#20 More than one field returned with getGroupField

v1.0_(example)
pending
None
1
2017-12-12
2017-06-14
Anonymous
No

When trying to fetch a field with record.getGroupField("A", "B-LINE-CNT") it returns both

A.B-LINE-CNT and A.D.B-LINE-CNT.

      01  A.                                             
           05 B-LINE-CNT          PIC S999   COMP-3.               
           05 C.                            
           05 D REDEFINES C.                          
               10 B-LINE-CNT      PIC S999   COMP-3. 

How can I just fetch the 1 field?

Thanks for your time

Discussion

  • Bruce Martin

    Bruce Martin - 2017-06-15
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -3,11 +3,13 @@
     A.B-LINE-CNT and A.D.B-LINE-CNT. 
    
    
    +~~~Cobol
     01  A.                                             
                05 B-LINE-CNT          PIC S999   COMP-3.               
                05 C.                            
                05 D REDEFINES C.                          
                    10 B-LINE-CNT      PIC S999   COMP-3. 
    +~~~
    
     How can I just fetch the 1 field?
    
     
  • Bruce Martin

    Bruce Martin - 2017-06-15
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -4,7 +4,7 @@
    
    
     ~~~Cobol
    -01  A.                                             
    
    +      01  A.                                             
                05 B-LINE-CNT          PIC S999   COMP-3.               
                05 C.                            
                05 D REDEFINES C.                          
    
    • assigned_to: Bruce Martin
     
  • Bruce Martin

    Bruce Martin - 2017-06-15

    Try the followin (see attached program for test program):

        static IFieldDetail getFld(RecordDetail r, String... fieldNames) {
            List<IFieldDetail> groupFields = r.getGroupFields(fieldNames);
    
            switch (groupFields.size()) {
            case 0: throw new RuntimeException("No field found");
            case 1: return groupFields.get(0);
            }
    
            if (fieldNames.length > 1) {
                String lastGroup = "." + fieldNames[fieldNames.length - 2].toLowerCase() + ".";
                IFieldDetail fld = null;
                int cmpSize = 1;
                boolean multi = false;
                for (int i = fieldNames.length - 2; i>= 0; i-- ) {
                    cmpSize += fieldNames[i].length() + 1;
                }
                for (IFieldDetail f : groupFields) {
                    String gn = ((FieldDetail) f).getGroupName().toLowerCase();
                    if (gn.endsWith(lastGroup)) {
                        if (cmpSize == gn.length()) {
                            return f;
                        }
                        multi = fld != null;
                        fld = f;
                    }
                }
    
                if (! multi) {
                    return fld;
                }
            }
    
            throw new RuntimeException("multiple fields found");
        }
    

    I will add this to JRecord, but I wont release it until I have more changes.

     
  • Anonymous

    Anonymous - 2017-06-15

    Thanks Bruce, you're awesome! Any plans to eventually push such functionality into the JRecord codebase?

    And thanks again.

     
  • Bruce Martin

    Bruce Martin - 2017-06-16

    I will include it in JRecord (probably in record.getGroupField(..) method. It should be in the next release when ever that comes out.

    Note: I suggest getting Sourceforge user id as

    • I do not have to approve comments from approved users (saves mee work)
    • You can follow questions and be notified when answers appear.
     
  • Bruce Martin

    Bruce Martin - 2017-12-12

    The functionality should be in Version 0.90

     
  • Bruce Martin

    Bruce Martin - 2017-12-12
    • status: open --> pending
     

Anonymous
Anonymous

Add attachments
Cancel