sponsored links

Collapse

Announcement

Collapse
No announcement yet.

Redefining display file fields as an array

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

  • Redefining display file fields as an array

    I have a display file that has 8 character fields, length(char 1). They are called SEL1, SEL2................SEL8). "X" or blank is the only valid value. I want to redefine the fields as an array in the D specs and then loop through the array to see how many array elements contain an "X". If the count is 0 or >1, an error occurs.

    I am getting syntax errors re-defining these as an array. So, the question is "how to redefine SEL1, SEL2.........SEL8 as an array

  • #2
    I am assuming you're using free format.

    Code:
       DCL-DS SCREENDS;
         Sel1;
         Sel2;
         Sel3;
         Sel4;
         Sel5;
         Sel6;
         Sel7;
         Sel8;
         Sel9;
         Sel      Char(1) DIM(9) Pos(1);
       End-Ds ScreenDS;
    The array Sel will contain the values for Sel1 through Sel9.

    Comment


    • #3
      Would this work:
      Code:
      D sel             DS
      D  sel1
      D  sel2
      ...
      D  sel8
      D  sela                               dim(8) like(sel1) overlay(sel)

      Comment


      • #4
        Originally posted by Brian Rusch View Post
        Would this work:
        Code:
        D sel DS
        D sel1
        D sel2
        ...
        D sel8
        D sela dim(8) like(sel1) overlay(sel)
        It will but as Rocky's example shows you'd have to use POS not Overlay in free-form declarations.

        Comment


        • #5
          Originally posted by JonBoy View Post

          It will but as Rocky's example shows you'd have to use POS not Overlay in free-form declarations.
          Before I posted the question, I tried using OVERLAY as demonstrated in Brian's post and I got syntax errors. I was a little surprised, I thought OVERLAY would work. Using POS does work.

          Comment


          • gregwga50
            gregwga50 commented
            Editing a comment
            I meant, I tried Brian's version only converting it too free format and got syntax errors. The fixed format version works fine, not sure why one does and the other doesn't.

        • #6
          Thanks everyone

          Comment


          • #7
            The reason overlay doesn't work in free-form declares is that IBM decided that they should never have allowed Overlay to work against the DS name in the first place - it has caused a lot of errors and confusion.

            So overlay now works the way it was intended i.e. to break down a _field_ (like a part number) into its component pieces. To overlay against the DS itself you have to specify POS(1) to reposition it back to the start of the DS.

            Overlay can also be used against a group field. Using the original DS as an example it would work like this:
            Code:
            dcl-ds  myDS;
              field1;
              field2;
              group;
                sel1  overlay(group);
                sel2  overlay(group: *next); 
                ...
                sel8  overlay(group: *next);
                selArray  like(sel1) dim(8)  overlay(group);
            end-ds;
            You would do this if you needed the DS to contain fields other than the array of seln fields.

            Comment


            • Rocky
              Rocky commented
              Editing a comment
              Now my day is complete... my day is not complete until I learned something new! Thanks!

          • #8
            I knew that you could use OVERLAY that way - what I didn't know was the grouping capability - I've always thought you had to define the field - ie:

            Code:
             
             dcl-ds  myDS;   field1;   field2;   group char(8);     sel1  overlay(group);     sel2  overlay(group: *next);      ...     sel8  overlay(group: *next);     selArray  like(sel1) dim(8)  overlay(group); end-ds;
            Pretty cool that it's smart enough to define that from the overlayed fields.

            Comment


            • #9
              Code:
              dcl-ds myDS;
                field1;
                field2;
                group char(8);
                  sel1 overlay(group);
                  sel2 overlay(group: *next); 
                 ...
                  sel8 overlay(group: *next);
                  selArray like(sel1) dim(8) overlay(group);
              end-ds;
              Not sure why it didn't display the above properly n previous post... I wish there was a way to edit posts....

              Comment

              sponsored links

              Collapse

              Working...
              X