ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Initializing data structure subfields using pointers

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Initializing data structure subfields using pointers

    In my program I have a data structure with 99 elements, DL1, DL2..................DL99. All the even numbered elemets DL2, etc. are the same length (2A). The odd #ones are not. I want to initialize the even numbered ones with ~! (delimiter). Without having 49 assignment statements is there a way I can initialize these with pointers and a for loop or (or another method requiring less coding)

  • #2
    Re: Initializing data structure subfields using pointers

    OK... Sort of thinking out loud here...

    Don't think you need to use pointers. Use a second data structure which contains only the 'even' elements of the first, but with elements named the same. Use QUALIFIED on both structures. You can now initialise the second array by doing a DSsecond= *ALL'~!', (or an overlaid array - its up to you) then you can do a EVAL-CORR to get the contents across to the original array. I think

    Comment


    • #3
      Re: Initializing data structure subfields using pointers

      I can't think of any good way to use a loop because each element is a discrete variable and has a different size.

      The suggestion to use a second DS and EVAL-CORR seems reasonable. The second DS only needs the even-numbered elements since those are the only ones you want EVAL-CORR to affect.

      But it's not clear why you don't have INZ( '~!' ) for those elements. Then you might simply run
      Code:
      RESET myDS ;
      when you want to re-initialize. Also, is there a reason you need those elements initialized more than once?
      Tom

      There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

      Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

      Comment


      • #4
        Re: Initializing data structure subfields using pointers

        Hmmm...

        I understand that the "odd" fields are all different lengths. Is there any algorithm that you can use to figure out what these lengths are in your program? Are they stored in an array or file or something else that you could loop through in order to calculate the positions? If not, then I can't see how you can do this aside from typing EVAL or INZ for each element.

        Are you sure that a data structure is the best approach here? I know nothing about your application, but, when I've created delimited files (where there's a character sequence delimiting each field, etc) I've always found that data structures are a poor fit. It's better to write a routine that calculates the record layout before writing (or passing, or whatever) the delimiting string (and call a routine that strips the delimiters out when loading, etc) Could that be the case here?

        Comment

        Working...
        X