PE-group with counter

Good day

I try to find info in PE-group with counter

What I try to do is when a PE field1 is empty field2 shift up to field1

Please Advice

Hi Frederick,
the fields in a PE group do not shift from higher to lower occurrences when lower occurrences become empty.
Please see: Input Data Requirements Example 2, Input record 2, first occurrence is all blanks and occurrence count is 2

In order to achieve this you could update all occurrences starting from the occurrence that is to become empty in all fields in the PE group.

If you know which PE entry is empty (perhaps you just emptied it), then here is a program to ripple up all the following entries:

DEFINE DATA LOCAL
1 #M (I4)     CONST <10>
1 EMP    VIEW EMPLOYEES
  2 PERSONNEL-ID
  2 LEAVE-BOOKED
    3 LEAVE-START (#M)
    3 LEAVE-END   (#M)
1 #I (I4)
1 #J (I4)
END-DEFINE
READ (1) EMP BY PERSONNEL-ID
  ASSIGN EMP.LEAVE-START (1) = EMP.LEAVE-END (1) = 20210801
  ASSIGN EMP.LEAVE-START (2) = EMP.LEAVE-END (2) = 20210802
  ASSIGN EMP.LEAVE-START (3) = EMP.LEAVE-END (3) = 0
  ASSIGN EMP.LEAVE-START (4) = EMP.LEAVE-END (4) = 20210804
  ASSIGN EMP.LEAVE-START (5) = EMP.LEAVE-END (5) = 20210805
  /*
  WRITE 'before:'
  DISPLAY EMP.PERSONNEL-ID
          EMP.LEAVE-START (*)
          EMP.LEAVE-END   (*)
  NEWPAGE
  ASSIGN #I = 3 /* #I determined to be empty entry
  IF  #I < #M
    THEN
      ASSIGN EMP.LEAVE-START (#I:#M - 1) = EMP.LEAVE-START (#I + 1:#M)
      ASSIGN EMP.LEAVE-END   (#I:#M - 1) = EMP.LEAVE-END   (#I + 1:#M)
      RESET  EMP.LEAVE-START (#M)
             EMP.LEAVE-END   (#M)
  END-IF
  WRITE '  after:'
  DISPLAY EMP.PERSONNEL-ID
          EMP.LEAVE-START (*)
          EMP.LEAVE-END   (*)
END-READ
END

If empty entries are scattered in your PE, this program will consolidate the non-empty entries at the top:

DEFINE DATA LOCAL
1 #M (I4)     CONST <10>
1 EMP    VIEW EMPLOYEES
  2 PERSONNEL-ID
  2 LEAVE-BOOKED
    3 LEAVE-START (#M)
    3 LEAVE-END   (#M)
1 #TOP (I4)
1 #NEXT (I4)
1 #I (I4)
1 #J (I4)
END-DEFINE
READ (1) EMP BY PERSONNEL-ID
  ASSIGN EMP.LEAVE-START (1) = EMP.LEAVE-END (1) = 20210801
  ASSIGN EMP.LEAVE-START (2) = EMP.LEAVE-END (2) = 0
  ASSIGN EMP.LEAVE-START (3) = EMP.LEAVE-END (3) = 20210803
  ASSIGN EMP.LEAVE-START (4) = EMP.LEAVE-END (4) = 0
  ASSIGN EMP.LEAVE-START (5) = EMP.LEAVE-END (5) = 20210805
  WRITE 'before:'
  DISPLAY EMP.PERSONNEL-ID
          EMP.LEAVE-START (*)
          EMP.LEAVE-END   (*)
  NEWPAGE
  /*
  ASSIGN #TOP = #M - 1
  FOR #I = 1 #TOP
    IF   EMP.LEAVE-START (#I) = 0      /* empty PE entry
     AND EMP.LEAVE-END   (#I) = 0
      THEN
        ASSIGN #NEXT = #I + 1
        FOR #J = #NEXT #TOP
          IF  EMP.LEAVE-START (#J) <> 0
           OR EMP.LEAVE-END   (#J) <> 0
            THEN
              ASSIGN EMP.LEAVE-START (#I) = EMP.LEAVE-START (#J)
              ASSIGN EMP.LEAVE-END   (#I) = EMP.LEAVE-END   (#J)
              RESET  EMP.LEAVE-START (#J)
                     EMP.LEAVE-END   (#J)
              ESCAPE BOTTOM
          END-IF
        END-FOR
    END-IF
   END-FOR
   WRITE '  after:'
   DISPLAY EMP.PERSONNEL-ID
           EMP.LEAVE-START (*)
           EMP.LEAVE-END   (*)
END-READ
END

NOTE: These programs have not been coded for efficiency.

Thank you very much.

This help to clarify it alot for me because I was not a 100% sure

And help alot.

Regards