# How access array in copybook from cobol to local in natural?

**URL:** <https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [April 11, 2022, 11:49am UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611 "2022-04-11T11:49:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![alysson.oliveira](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@alysson.oliveira](https://techcommunity.softwareag.com/u/alysson.oliveira)\
**Post date:** [April 11, 2022, 11:49am UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/1 "2022-04-11T11:49:43Z")

</div>

Hello my friends.  
i have a natural program that call a cobol program using a copybook that fill a array in that copybook. and i created a array in the local , so i can access the results in the local. The problem is that the values are not right.  
copybook in cobol are pic s9(04) comp-5 and in the local in the natural i’m using (I4).  
Thanks for the help.

#### Are you using a free trial or a product with a customer license?

#### What are trying to achieve? Please describe in detail.

#### Do you get any error messages? Please provide a **full error** message screenshot and log file.

#### Have you installed latest fixes for the products

---

<div class="post-metadata">

**Author:** ![Eli\_Cohen1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/eli_cohen1/32/39733_2.png) [@Eli\_Cohen1](https://techcommunity.softwareag.com/u/Eli_Cohen1)\
**Post date:** [April 11, 2022, 1:14pm UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/2 "2022-04-11T13:14:14Z")

</div>

Hello Oliveira,

Could you please share what is wrong with the data?  
Is it part of redefine ?  
Is it part of a group ?

Eli

---

<div class="post-metadata">

**Author:** ![alysson.oliveira](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@alysson.oliveira](https://techcommunity.softwareag.com/u/alysson.oliveira)\
**Post date:** [April 11, 2022, 1:46pm UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/3 "2022-04-11T13:46:23Z")

</div>

the natural program call a cobol, that make a select in a db2 and fill a array in the copybook

results in the display on cobol:  
x1 = 00163 - PIC S9(04) COMP-5  
x2 = 00002 - PIC S9(04) COMP-5  
x3 = 09909 - PIC S9(04) COMP-5  
x4 = X322098 - PIC X(06)  
x5 = 00011 - PIC S9(04) COMP-5

results in the local on Natural  
#x1 = 163 - (I02)  
#x2 = 16338 - (I02)  
#x3 = 16338 - (I02)  
#x4 = - (A06)  
#x5 = 16338 - (I02)

in the local on the natural, the values are completely off from the cobol.

---

<div class="post-metadata">

**Author:** ![Eli\_Cohen1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/eli_cohen1/32/39733_2.png) [@Eli\_Cohen1](https://techcommunity.softwareag.com/u/Eli_Cohen1)\
**Post date:** [April 11, 2022, 2:13pm UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/4 "2022-04-11T14:13:00Z")

</div>

Hello,

You first mentioned that you used I4 and in the sample it is I2.  
What is the correct one?  
We assume it should be I2.

Eli

---

<div class="post-metadata">

**Author:** ![alysson.oliveira](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@alysson.oliveira](https://techcommunity.softwareag.com/u/alysson.oliveira)\
**Post date:** [April 11, 2022, 4:24pm UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/5 "2022-04-11T16:24:31Z")

</div>

it’s I02 in the natural for all the PIC S9(04) Comp-5 in the copybook.

---

<div class="post-metadata">

**Author:** ![George\_Cooper](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/george_cooper/32/7831_2.png) [@George\_Cooper](https://techcommunity.softwareag.com/u/George_Cooper)\
**Post date:** [April 11, 2022, 10:23pm UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/6 "2022-04-11T22:23:15Z")

</div>

I02 and S9(04) Comp-5 should both allocate 2 bytes of memory, so the individual fields should align correctly. How are the arrays defined in the Cobol copybook versus your Natural array definition? Maybe the array definitions don’t match up correctly? You might try redefining the Natural array as a single large (A) field and display that field to see how the data is mapped into it when returned from the Cobol program. You would have to display as hex output since most of the fields are binary.

Hope that helps.  
George

---

<div class="post-metadata">

**Author:** ![alysson.oliveira](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@alysson.oliveira](https://techcommunity.softwareag.com/u/alysson.oliveira)\
**Post date:** [April 12, 2022, 11:33am UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/7 "2022-04-12T11:33:45Z")

</div>

in the copybook all pic S9(04) Comp-5 are defined in the natural as I02 and the pic x in the copybook are defined in the natural as A()… the definition in the both arrays are matching correctly. how a display the hex output in natural?  
thanks George for the help.

---

<div class="post-metadata">

**Author:** ![wolfgang.winter](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/wolfgang.winter/32/17954_2.png) [@wolfgang.winter](https://techcommunity.softwareag.com/u/wolfgang.winter)\
**Post date:** [April 12, 2022, 11:45am UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/8 "2022-04-12T11:45:32Z")

</div>

Put an edit mask on the fields to be displayed as hex like this

`WRITE #X1 (EM=HH) #X4(EM=H(6))`

---

<div class="post-metadata">

**Author:** ![andreysonsouzapt](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@andreysonsouzapt](https://techcommunity.softwareag.com/u/andreysonsouzapt)\
**Post date:** [April 12, 2022, 11:52am UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/9 "2022-04-12T11:52:09Z")

</div>

Isn’t the problem in the cobol declaration? because S9(04) there is a positive or negative sign, and in Natural I2 it does not accept a sign, in Natural it has to be an alphanumeric (A05)

Alysson Oliveira via Software AG Tech Community & Forums \<[techcommunity@discoursemail.com](mailto:techcommunity@discoursemail.com)\> escreveu no dia terça, 12/04/2022 à(s) 12:44:

---

<div class="post-metadata">

**Author:** ![wolfgang.winter](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/wolfgang.winter/32/17954_2.png) [@wolfgang.winter](https://techcommunity.softwareag.com/u/wolfgang.winter)\
**Post date:** [April 12, 2022, 11:59am UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/11 "2022-04-12T11:59:22Z")

</div>

Format I fields in Natural are _ALWAYS_ signed, so the value range for an I2 is +32767 to -32768

---

<div class="post-metadata">

**Author:** ![alysson.oliveira](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@alysson.oliveira](https://techcommunity.softwareag.com/u/alysson.oliveira)\
**Post date:** [April 12, 2022, 12:01pm UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/12 "2022-04-12T12:01:38Z")

</div>

i tried thoses and i got “4040404040”

---

<div class="post-metadata">

**Author:** ![wolfgang.winter](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/wolfgang.winter/32/17954_2.png) [@wolfgang.winter](https://techcommunity.softwareag.com/u/wolfgang.winter)\
**Post date:** [April 12, 2022, 12:18pm UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/13 "2022-04-12T12:18:27Z")

</div>

Then your (A5) field is “empty” aka contains “all blanks”

---

<div class="post-metadata">

**Author:** ![alysson.oliveira](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@alysson.oliveira](https://techcommunity.softwareag.com/u/alysson.oliveira)\
**Post date:** [April 12, 2022, 12:32pm UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/14 "2022-04-12T12:32:07Z")

</div>

i reset all those fields before call cobol. and even thou i got this “garbage” values except the first value, that came right.

---

<div class="post-metadata">

**Author:** ![wolfgang.winter](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/wolfgang.winter/32/17954_2.png) [@wolfgang.winter](https://techcommunity.softwareag.com/u/wolfgang.winter)\
**Post date:** [April 12, 2022, 12:39pm UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/15 "2022-04-12T12:39:06Z")

</div>

H’404040404040’ is a perfect initial value for an (A6) field after a RESET.

---

<div class="post-metadata">

**Author:** ![alysson.oliveira](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@alysson.oliveira](https://techcommunity.softwareag.com/u/alysson.oliveira)\
**Post date:** [April 12, 2022, 12:41pm UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/16 "2022-04-12T12:41:43Z")

</div>

i should get “garbage” for all the fields? why the first field get right, but the others still get wrong?

---

<div class="post-metadata">

**Author:** ![wolfgang.winter](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/wolfgang.winter/32/17954_2.png) [@wolfgang.winter](https://techcommunity.softwareag.com/u/wolfgang.winter)\
**Post date:** [April 12, 2022, 2:19pm UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/17 "2022-04-12T14:19:09Z")

</div>

We would need to see the CALL in your NATURAL Program plus the COBOL PROCEDURE DIVISION + LINKAGE SECTION.

`x4 = X322098 - PIC X(06)`

X322098 is only 3 bytes and x3220 are not valid printable EBCDIC characters, btw.

---

<div class="post-metadata">

**Author:** ![alysson.oliveira](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@alysson.oliveira](https://techcommunity.softwareag.com/u/alysson.oliveira)\
**Post date:** [April 12, 2022, 2:34pm UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/18 "2022-04-12T14:34:18Z")

</div>

in the natural the call of cobol are:  
SET CONTROL ‘P=C’  
CALL ‘PGM-Name’ USING #LOCAL

in the cobol:

LINKAGE SECTION  
01 DFHCOMMAREA.

PROCEDURE DIVISION USING DFHCOMMAREA.

---

<div class="post-metadata">

**Author:** ![wolfgang.winter](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/wolfgang.winter/32/17954_2.png) [@wolfgang.winter](https://techcommunity.softwareag.com/u/wolfgang.winter)\
**Post date:** [April 12, 2022, 2:40pm UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/19 "2022-04-12T14:40:36Z")

</div>

We would need to see the structure within the COMMAREA, but please consider the following from the documentation

> If a group name is used, the group is converted to individual fields; that is, if a user wishes to specify the beginning address of a group, the first field of the group must be specified.

---

<div class="post-metadata">

**Author:** ![alysson.oliveira](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@alysson.oliveira](https://techcommunity.softwareag.com/u/alysson.oliveira)\
**Post date:** [April 12, 2022, 3:18pm UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/20 "2022-04-12T15:18:49Z")

</div>

well, i don’t get it. but in the local at natural, the array’s definition is the same order in the copybook at cobol.

---

<div class="post-metadata">

**Author:** ![wolfgang.winter](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/wolfgang.winter/32/17954_2.png) [@wolfgang.winter](https://techcommunity.softwareag.com/u/wolfgang.winter)\
**Post date:** [April 12, 2022, 3:29pm UTC](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611/21 "2022-04-12T15:29:53Z")

</div>

What the documentation says here is that if you have

```auto
1 #LOCAL
  2 #X1 (I2)
  2 #X2 (I2)
..

```

then try to specify #X1 on the CALL statement instead of #LOCAL

[Next page](https://techcommunity.softwareag.com/t/how-access-array-in-copybook-from-cobol-to-local-in-natural/256611.md?page=2)
