fyzhou / beanio

Automatically exported from code.google.com/p/beanio
Apache License 2.0
0 stars 0 forks source link

Add support for overlapping fixed length fields #54

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have two cases I need to handle with a fixed length file.

Case 1: The two fields use overlapping information.

The field is of the format 'AAAABBBCCCCCCCCC'. Section 'AAAABBB' is used to 
identify the record. Section 'BBBCCCCCCCCC' is used as a key in a database.

Case 2: A substring in one field is used in another field.

The field is of the format 'BBBCCCCCCCCC'. The entire string is used to 
identify the record but substring 'CCCCCCCCC' needs to be stored in a separate 
field.

Original issue reported on code.google.com by jgriffin...@gmail.com on 31 Jan 2013 at 1:57

GoogleCodeExporter commented 9 years ago
Hello,

You can define multiple record identifying fields.  Have you tried the 
following?

Case 1:

<field name="field1" rid="true" literal="AAAA" ignore="true" />
<field name="field2" rid="true" regex="BBB.*" />

Case 2:

<field name="field1" rid="true" literal="BBB" ignore="true" />
<field name="field2" rid="true" literal="CCCCCCCCC" />

Thanks,
Kevin

Original comment by kevin.s...@gmail.com on 31 Jan 2013 at 7:59

GoogleCodeExporter commented 9 years ago
Hi Kevin,

The rid is actually a different field. In case 2 an example would be as follows:

3000011934646724232800BBBCCCCCCCCC 20   2013-01-29XXXXXXXXXXXX                  
              00000000000413+2
3000012034646724435100BBBCCCCCCCCC 20   2013-01-29XXXXXXXXXXXX                  
               00000000071842+2

The two characters at the beginning of the line are the rid. The value 
'BBBCCCCCCCCC' is the key used between systems. The value 'CCCCCCCCC' is the 
value needed within one of the systems.

Would it be possible to specify an absolute starting position for the field?

<field name="field1" rid="true" start="22" length="12" />
<field name="field2" rid="true" start="25" length="9" />

Where the end of the last field tag (i.e. field2) defines where the next field 
tag starts (field3?).

I realize this is an enhancement not a bug. I do not, however, see a means for 
changing the designation.

Original comment by jgriffin...@gmail.com on 31 Jan 2013 at 8:14

GoogleCodeExporter commented 9 years ago
Overlapping fields would cause all kinds of problems I'd rather not have to 
deal with if there are simple workarounds.  In case #2, couldn't you just have 
extra getter/setter methods on the bean object that splits the field into two 
fields?  For example:

class Bean {
    private String key1;
    private String key2;

    public String getField2() {
        return key1;
    }

    public void setField2(String s) {
        this.key1 = s;
        this.key2 = s.substring(3);
    }
}

Thanks,
Kevin

Original comment by kevin.s...@gmail.com on 1 Feb 2013 at 2:40

GoogleCodeExporter commented 9 years ago
Hi Kevin,

The bean is a generic one, used by more than one output format. I have 
work-arounds but was hoping to keep things generic by pushing the format 
specific logic into beanio XML file. If you need to push this off for a while 
no worries, I will use my work-arounds.

Original comment by jgriffin...@gmail.com on 1 Feb 2013 at 2:48

GoogleCodeExporter commented 9 years ago
Hi again,

I think I misspoke before- very sorry.  This is already supported, but you must 
specify the starting position for ALL fields or for none of them.  The 
attribute you seek is called 'position', not 'start'.  For example:

<field name="field1" rid="true" position="22" length="12" />
<field name="field2" rid="true" position="25" length="9" />

Thanks,
Kevin

Original comment by kevin.s...@gmail.com on 23 Feb 2013 at 10:36

GoogleCodeExporter commented 9 years ago
Fantastic! Thank-you!

Original comment by jgriffin...@gmail.com on 24 Feb 2013 at 12:26