# PE-group with counter

**URL:** <https://techcommunity.softwareag.com/t/pe-group-with-counter/243308>\
**Category:** Forum\
**Tags:** Adabas-Natural, Adabas, Adabas-on-Linux\
**Created:** [August 2, 2021, 6:12am UTC](https://techcommunity.softwareag.com/t/pe-group-with-counter/243308 "2021-08-02T06:12:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Derick](https://avatars.discourse-cdn.com/v4/letter/d/df788c/32.png) [@Derick](https://techcommunity.softwareag.com/u/Derick)\
**Post date:** [August 2, 2021, 6:12am UTC](https://techcommunity.softwareag.com/t/pe-group-with-counter/243308/1 "2021-08-02T06:12:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Marbod\_Mueller1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/marbod_mueller1/32/97_2.png) [@Marbod\_Mueller1](https://techcommunity.softwareag.com/u/Marbod_Mueller1)\
**Post date:** [August 3, 2021, 10:41am UTC](https://techcommunity.softwareag.com/t/pe-group-with-counter/243308/2 "2021-08-03T10:41:22Z")

</div>

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](https://documentation.softwareag.com/adabas/ada853mfr/util/adacmp-input.htm#adacmp-input_PE) 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.

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [August 3, 2021, 10:56pm UTC](https://techcommunity.softwareag.com/t/pe-group-with-counter/243308/3 "2021-08-03T22:56:31Z")

</div>

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:

```auto
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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Derick](https://avatars.discourse-cdn.com/v4/letter/d/df788c/32.png) [@Derick](https://techcommunity.softwareag.com/u/Derick)\
**Post date:** [August 4, 2021, 2:28am UTC](https://techcommunity.softwareag.com/t/pe-group-with-counter/243308/4 "2021-08-04T02:28:28Z")

</div>

Thank you very much.

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

And help alot.

Regards

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [November 2, 2021, 2:29am UTC](https://techcommunity.softwareag.com/t/pe-group-with-counter/243308/5 "2021-11-02T02:29:30Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
