Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Occurs depending on mappings #151

Closed
tr11 opened this issue Aug 2, 2019 · 6 comments
Closed

Occurs depending on mappings #151

tr11 opened this issue Aug 2, 2019 · 6 comments
Labels
accepted Accepted for implementation enhancement New feature or request

Comments

@tr11
Copy link
Collaborator

tr11 commented Aug 2, 2019

I have a few copybooks that have groups occurring depending on a flag on some field as follows:

   02 FIELD_TYPE                  PIC X.
   02 RECORD_TYPE_A OCCURS 0 TO 1 TIMES DEPENDING ON FIELD_TYPE.
       ....
   02 RECORD_TYPE_B OCCURS 0 TO 1 TIMES DEPENDING ON FIELD_TYPE.
       ....

In this example, if FIELD_TYPE is A, then only RECORD_TYPE_A is defined. Same for B.

Maybe we could support something like this by allowing OCCURS clauses to point to non-integer fields together with some sort of mapping.
If this sounds good, I can come up with a PR that does this.

@yruslan yruslan added the enhancement New feature or request label Aug 5, 2019
@yruslan
Copy link
Collaborator

yruslan commented Aug 5, 2019

Yes, this makes sense overall. But how a mapping can be defined? Is it a part of the copybook or need to be specified via .option(...)?

@tr11
Copy link
Collaborator Author

tr11 commented Aug 5, 2019

It would have to be done through an option. I'm not sure if this is standard at all, but the files I have are structured this way.

@yruslan
Copy link
Collaborator

yruslan commented Aug 5, 2019

Makes sense. Could you please give an example of such a mapping? Can it be several mappings for different OCCURs?

How urgent is this? The current plan is to

  • release 0.5.5 with what we have,
  • merge changes prepared for 1.0.0 and work on other issues.

Have pressure from other projects, was planning to work on releasing 1.0.0 sometime next week.

@tr11
Copy link
Collaborator Author

tr11 commented Aug 5, 2019

No hurries at all.

The idea would be to specify for each field that depends on something else a mapping. With the example I had before:

   02 FIELD_TYPE                  PIC X.
   02 RECORD_TYPE_A OCCURS 0 TO 1 TIMES DEPENDING ON FIELD_TYPE.
       ....
   02 RECORD_TYPE_B OCCURS 0 TO 1 TIMES DEPENDING ON FIELD_TYPE.
       ....

A possible OCCURS mapping (json) would be

{
  "RECORD_TYPE_A": {
    "A": 1
  },
  "RECORD_TYPE_B": {
    "B": 1
  }
}

@tr11
Copy link
Collaborator Author

tr11 commented Aug 6, 2019

Actually, a better example would be

   02 FIELD_TYPE                  PIC X.
   02 RECORD_TYPE_A OCCURS 0 TO 2 TIMES DEPENDING ON FIELD_TYPE.
       ....
   02 RECORD_TYPE_B OCCURS 0 TO 2 TIMES DEPENDING ON FIELD_TYPE.
       ....

and the JSON mapping

{
  "RECORD_TYPE_A": {
    "A": 1,
    "X": 1,
    "Y": 2
  },
  "RECORD_TYPE_B": {
    "B": 1
    "X": 1,
    "Z": 2
  }
}

@yruslan
Copy link
Collaborator

yruslan commented Aug 6, 2019

Yes, this makes sense. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Accepted for implementation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants