# X-array

**URL:** <https://techcommunity.softwareag.com/t/x-array/291533>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes, Natural-on-Linux\
**Created:** [February 15, 2024, 8:08am UTC](https://techcommunity.softwareag.com/t/x-array/291533 "2024-02-15T08:08:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![arulvadivel](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@arulvadivel](https://techcommunity.softwareag.com/u/arulvadivel)\
**Post date:** [February 15, 2024, 8:08am UTC](https://techcommunity.softwareag.com/t/x-array/291533/1 "2024-02-15T08:08:18Z")

</div>

Shall we write work file into X-array variables? we have a variable declared in dynamic and expand those arrays in run time and write into work file but getting a nat error NAT6256 " X-arrays cannot specified in this context.  
sample code  
1 #name (A20/\*)

expand array #name to (1:5)

write into work file 1 #name(1:5)  
or  
for #i 1 to 5  
write into work file 1 variable #name(#i)  
end-for

---

<div class="post-metadata">

**Author:** ![Finn\_the\_Dane1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/finn_the_dane1/32/132_2.png) [@Finn\_the\_Dane1](https://techcommunity.softwareag.com/u/Finn_the_Dane1)\
**Post date:** [February 15, 2024, 1:17pm UTC](https://techcommunity.softwareag.com/t/x-array/291533/2 "2024-02-15T13:17:04Z")

</div>

Hi  
I’m not sure where you get the error, but tried to make an example based on yours  
It’s for windows, so you will probably have to change the Define Work File to fit your env.  
and with a few extra details it works - but not really related to X-arrays???  
Finn

define data local  
1 #name (A20/\*)  
1 #I (I4)  
end-define  
DEFINE WORK file 1 ‘c:\temp\x’ TYPE ‘ASCII’

expand array #name to (1:5)  
move ‘xyz’ to #name(1:5)  
write work file 1 variable #name(1:5)  
\*  
for #i 1 to 5  
write work file 1 variable #name(#i)  
end-for  
END

---

<div class="post-metadata">

**Author:** ![arulvadivel](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@arulvadivel](https://techcommunity.softwareag.com/u/arulvadivel)\
**Post date:** [February 16, 2024, 9:12am UTC](https://techcommunity.softwareag.com/t/x-array/291533/3 "2024-02-16T09:12:08Z")

</div>

Hi Finn,

Thanks for your response, we were using Natural windows, we have used Define work file type as ‘CSV’. we received the error at the run time NAT6256. After changing the type from CSV to ASCII its working fine. Thanks for your help, Finn. So, we cannot write into work file for type CSV for X arrays is it correct?

---

<div class="post-metadata">

**Author:** ![Dion\_Kejlberg](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/dion_kejlberg/32/525_2.png) [@Dion\_Kejlberg](https://techcommunity.softwareag.com/u/Dion_Kejlberg)\
**Post date:** [February 16, 2024, 10:10am UTC](https://techcommunity.softwareag.com/t/x-array/291533/4 "2024-02-16T10:10:08Z")

</div>

CSV is a format for what you put into your file. It is not a type.

For Windows it is a file-extension, that is used to determine which programs is suitable for using the file. You can still put all kind of data in a CSV file, but then Excel or other programs will not be very happy.

---

<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:** [February 19, 2024, 6:42am UTC](https://techcommunity.softwareag.com/t/x-array/291533/5 "2024-02-19T06:42:40Z")

</div>

Arul,

There are three things that you can do.

1. Submit a ticket to SAG to find out whether the NAT6256 is a run-time bug. If you can write X-array entries to an ASCII file, why not to CSV? By specifying a specific number of array entries, isn’t this logically the same as a standard array?

2. Replace the X-array with a standard array. If the number of entries is growing over time, test for 90% usage and send a warning to the programmers for the array to be increased. In my experience, programmers use X-arrays because they want the experience, not because they can justify the overhead incurred by EXPAND ARRAY.

3. If you truly can justify the use of an X-array, use the mainframe technique of writing a CSV-compatible file. Here is an example. (USR2011N is needed only for a program which reads the CSV.)

```auto
DEFINE DATA LOCAL
1 #X (A5/1:*)
1 #RECORD (A100)
1 #Q (A1) INIT <'"'>
1 #D (A1) INIT <','>
1 #C (I4)
1 #I (I4)
1 USR2011
  2 FUNCTION (A1) INIT <"S">
  2 WORK-NUM (I1) INIT <01>
  2 WORK-FILE (A253) INIT <'C:\Users\Ralph\rgz.csv'>
  2 WORK-TYPE (A1) INIT <"B">
  2 MAX-NUM (I1)
  2 RESPONSE (I4)
  2 EXTENDED-DATA (A1/1) INIT <H'00'>
  2 WORK-ATTRIBUTES (A1000) INIT <"KEEP">
  2 WORK-CODEPAGE (A64)
  2 WORK-PROPERTIES (A1000) INIT <"SEPARATOR-COMMA">
END-DEFINE
OPTIONS TQMARK=OFF
ASSIGN #Q = '"'
OPTIONS TQMARK=ON
DEFINE WORK FILE 01 USR2011.WORK-FILE TYPE "ASCII-COMPRESSED" /* ATTRIBUTES "KEEP"
EXPAND ARRAY #X TO (1:50)
MOVE ALL '1' TO #X (1) UNTIL 1
MOVE ALL '3' TO #X (3) UNTIL 3
MOVE ALL '5' TO #X (5) UNTIL 5
ASSIGN #C = 5 /* determine # used entries
*
FOR #I = 1 #C
  COMPRESS #RECORD
           #Q #X (#I) #Q #D
      INTO #RECORD LEAVING NO SPACE
END-FOR
WRITE WORK 01 VARIABLE #RECORD
PRINT '=' #RECORD
SKIP 1
CLOSE WORK FILE 01
*
RESET #X (*)
DEFINE WORK FILE 01 USR2011.WORK-FILE TYPE "CSV"
CALLNAT "USR2011N" USR2011
READ WORK 01 #X (1:#C)
  DISPLAY #X (1:#C)
END-WORK
END

```

---

<div class="post-metadata">

**Author:** ![arulvadivel](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@arulvadivel](https://techcommunity.softwareag.com/u/arulvadivel)\
**Post date:** [February 19, 2024, 9:32am UTC](https://techcommunity.softwareag.com/t/x-array/291533/6 "2024-02-19T09:32:48Z")

</div>

Thanks, Ralph, for providing the multiple options. we have used ASCII instead of CSV. I will try above logic as well. sure, I will a raise ticket to SAG for runtime NAT6256 error.

---

<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:** [August 17, 2024, 9:33am UTC](https://techcommunity.softwareag.com/t/x-array/291533/7 "2024-08-17T09:33:41Z")

</div>

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