# redefine for  arrays

**URL:** <https://techcommunity.softwareag.com/t/redefine-for-arrays/75933>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [January 2, 2008, 9:48am UTC](https://techcommunity.softwareag.com/t/redefine-for-arrays/75933 "2008-01-02T09:48:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rishi](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@rishi](https://techcommunity.softwareag.com/u/rishi)\
**Post date:** [January 2, 2008, 9:48am UTC](https://techcommunity.softwareag.com/t/redefine-for-arrays/75933/1 "2008-01-02T09:48:17Z")

</div>

I have something like this

01 #I-REC (A124)  
01 REDEFINE #I-REC  
02 I-F1 (N8)  
02 I-F2 (N8)  
.  
.  
.

01 #REC (A124/1:25)  
01 REDEFINE #REC  
02 #REC-GP (1:25)  
03 #F1 (N8)  
03 #F2 (N8)  
.  
.  
.  
.

I-REC record layout for a workfile. The thing is I’m moving records from the workfile(I-REC) to the #REC continuously.  
Each time want to check if the #F1 ( #INDEX) EQ #F1(#INDEX-1)  
I.E I want to check the previous record in the array with the current record and perform some processing.  
The problem now is since the record is defined as (a124),how do I access the array as a group of 25 occurences.  
When I use  
IF #REC-GP.#F1(#INDEX) EQ #REC-GP.#F2(#INDEX - 1)  
It throws me an error.

Is there any problem with my redefine ? Pls clarify.

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [January 2, 2008, 12:51pm UTC](https://techcommunity.softwareag.com/t/redefine-for-arrays/75933/2 "2008-01-02T12:51:13Z")

</div>

Your fields beyond #REC-GP got two dimensions.

So please check, if you really need two dimensions.  
If no, drop one dimension and everything should be OK.  
If yes, you have to address #REC-GP.#F1 like this

```auto
IF #REC-GP.#F1(#INDEX, #index2) EQ #REC-GP.#F2(#INDEX - 1, #index2) 
```

---

<div class="post-metadata">

**Author:** ![rishi](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@rishi](https://techcommunity.softwareag.com/u/rishi)\
**Post date:** [January 2, 2008, 1:48pm UTC](https://techcommunity.softwareag.com/t/redefine-for-arrays/75933/3 "2008-01-02T13:48:22Z")

</div>

> [@Matthias](#):
>
> Your fields beyond #REC-GP got two dimensions.
> 
> So please check, if you really need two dimensions.  
> If no, drop one dimension and everything should be OK.  
> If yes, you have to address #REC-GP.#F1 like this
> 
> ```auto
> IF #REC-GP.#F1(#INDEX, #index2) EQ #REC-GP.#F2(#INDEX - 1, #index2) 
> ```

I need only a single dimension. I need 25 occurences of (A124) structure .  
And I need to compare the first occurence(first record) #F1 to the second occurence(second record) #F1.How do I accomplish it?

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [January 2, 2008, 2:23pm UTC](https://techcommunity.softwareag.com/t/redefine-for-arrays/75933/4 "2008-01-02T14:23:50Z")

</div>

> [@](#):
>
> I need only a single dimension. I need 25 occurences of (A124) structure .

Then try the following definition:

```auto
01 #REC (A124/1:25) 
01 REDEFINE #REC 
02 #REC-GP /* <-- no Array-definition here 
03 #F1 (N8)
03 #F2 (N8)
```

---

<div class="post-metadata">

**Author:** ![rishi](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@rishi](https://techcommunity.softwareag.com/u/rishi)\
**Post date:** [January 2, 2008, 2:35pm UTC](https://techcommunity.softwareag.com/t/redefine-for-arrays/75933/5 "2008-01-02T14:35:17Z")

</div>

> [@Matthias](#):
>
> > [@](#):
> >
> > I need only a single dimension. I need 25 occurences of (A124) structure .
> 
> Then try the following definition:
> 
> ```auto
> 01 #REC (A124/1:25) 
> 01 REDEFINE #REC 
> 02 #REC-GP /* <-- no Array-definition here 
> 03 #F1 (N8)
> 03 #F2 (N8)
> ```

I’ve redefined as quoted .  
But when I try to check  
IF #REC(#INDEX).#F1 EQ #REC(#INDEX - 1).#F1

It says Invalid relational operator in a relational expression.

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [January 2, 2008, 3:33pm UTC](https://techcommunity.softwareag.com/t/redefine-for-arrays/75933/6 "2008-01-02T15:33:10Z")

</div>

> [@rishi](#):
>
> IF #REC(#INDEX).#F1 EQ #REC(#INDEX - 1).#F1

How about putting the index at the end of the field’s name?

```auto
IF #REC.#F1(#INDEX) EQ #REC.#F1(#INDEX - 1)
```

---

<div class="post-metadata">

**Author:** ![rishi](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@rishi](https://techcommunity.softwareag.com/u/rishi)\
**Post date:** [January 2, 2008, 4:07pm UTC](https://techcommunity.softwareag.com/t/redefine-for-arrays/75933/7 "2008-01-02T16:07:56Z")

</div>

> [@Matthias](#):
>
> > [@rishi](#):
> >
> > IF #REC(#INDEX).#F1 EQ #REC(#INDEX - 1).#F1
> 
> How about putting the index at the end of the field’s name?
> 
> ```auto
> IF #REC.#F1(#INDEX) EQ #REC.#F1(#INDEX - 1)
> ```

am getting the error  
Index entry incorrectly specified for field.  
As #f1 is not defined as an array.  
But when I change #F1 as an array of 25 occurences,the total necessity for a group of becomes meaningless.

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [January 2, 2008, 4:34pm UTC](https://techcommunity.softwareag.com/t/redefine-for-arrays/75933/8 "2008-01-02T16:34:33Z")

</div>

Oh Sorry, what I initially told you about “two dimensions” was completely false. :oops::oops:

What you need is a REDEFINITION like that:

```auto
define data local
01 #REC-GP (1:25) 
   02 #REC (A124)
   02 REDEFINE #REC 
     03 #F1 (N8) 
     03 #F2 (N8)
*
01 #index (I4)
end-define
#index := 2
#REC-GP.#F1(#index) := 1
#REC-GP.#F1(#index - 1) := 1
IF #REC-GP.#F1(#index) EQ #REC-GP.#F1(#index - 1)
  write #REC-GP.#F1(#index) 'EQ' #REC-GP.#F1(#index - 1)
end-if
end
```

The reason is:  
With a array beyond the redefine, you’ll split the A-Field into an array.

Sorry again for confusing you :oops: . I should read the posts more carefully…

---

<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:** [April 2, 2021, 2:49pm UTC](https://techcommunity.softwareag.com/t/redefine-for-arrays/75933/9 "2021-04-02T14:49:02Z")

</div>


