# s (subindex) processing code

The s (Subindex) processing code is
used to update an index that uses a file translation if the value
in the translate file changes. This processing code is set from Attribute
8 of the File Definition Item for the data section of a translate
file.

| System Processors | N/A |
| --- | --- |
| Code Type | File Defining |
| Dictionary Attributes | Correlative |

## Syntax

```
s<File1>;<AMC>;a<n>(t<File2>;<c>;;<AMC>)
```

## Parameter(s)

| | A file having the index: ```
a<n>(t<File2>;<c>;;<AMC>
``` |
| --- | --- |
| | The attribute in the translate item containing the translated data. |
| | The primary attribute number for the index. |
| | The translate file. |
| | Translate subcode. |

 Warning: Items in the translate file must exist before
 they are referenced in the main file. If they do not, the index in the main file will
 become corrupted when they are created.

## Example(s)

```
CREATE-FILE MYMAIN 1 1
CREATE-FILE MYTRANS 1 1
CREATE-INDEX MYMAIN A1(TMYTRANS;X;;1)
```
Put the subindex processing code on attribute 8 of DICT
MYTRANS MYTRANS.

```
sMYMAIN;1;A1(TMYTRANS;X;;1)
```
To see it used, create two items in the MYTRANS file:

```
 1
001 same
 2
001 diff
```
... then create several items in the MYMAIN file:

```
 a
001 1
 b
001 2
 c
001 1
 d
001 2
```
... then create the following program and compile it:

```
 bp subidx
001 root "mymain", "A1(TMYTRANS;X;;1)" to rX else stop
002 sKey=&#39;&#39;
003 sId=&#39;&#39;
004 loop
005 key(&#39;n&#39;,rX,sKey,sId) else stop
006 print sId
007 repeat
```
Traversing the index at this point, using the above program,
the item-id order should be "b,d,a,c" since "diff" sorts before "same".
Here is the output of the program at this point:

```
:run bp subidx
b
d
a
c
```
Change item 2 in MYTRANS from "diff" to "update", and
the change should be reflected in the index.

```
:ed mytrans 2
top
.
001 diff
eoi 001
.r
001 update
eoi 001
.fi
[221] &#39;2&#39; filed.
```
Now, traversing the index from the start should return
the item-ids in the order, "a,c,b,d", since "same" sorts before "update".
Here is the output of the program now:

```
:run bp subidx
a
c
b
d
:
```

## See also

- [Processing codes](https://d3codex.com/processingcodes/processing-codes/)

---
Source: https://d3codex.com/processingcodes/s-subindex-processing-code/ - part of the D3Codex reference.
