# Function to get a variable value by name

**URL:** <https://techcommunity.softwareag.com/t/function-to-get-a-variable-value-by-name/79365>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [October 27, 2008, 6:10pm UTC](https://techcommunity.softwareag.com/t/function-to-get-a-variable-value-by-name/79365 "2008-10-27T18:10:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![samueldc](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@samueldc](https://techcommunity.softwareag.com/u/samueldc)\
**Post date:** [October 27, 2008, 6:10pm UTC](https://techcommunity.softwareag.com/t/function-to-get-a-variable-value-by-name/79365/1 "2008-10-27T18:10:56Z")

</div>

Hi Everybody,

Is there any function to get a variable value by its name?

Something like this:

color=“red”

IF GETVAL(“CLIENT-NUMBER”) EQ 0  
WRITE ‘REQUIRED…’  
END-IF

(…)[/color]

---

<div class="post-metadata">

**Author:** ![Daniel\_Wilson](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@Daniel\_Wilson](https://techcommunity.softwareag.com/u/Daniel_Wilson)\
**Post date:** [October 27, 2008, 9:37pm UTC](https://techcommunity.softwareag.com/t/function-to-get-a-variable-value-by-name/79365/2 "2008-10-27T21:37:13Z")

</div>

You can test an alphanumeric field for a numeric value by using the conditional IS clause and you can move the numeric value from an alphanumeric field using the VAL function:

```auto
IF CLIENT-NUMBER IS (N7)
  MOVE VAL(CLIENT-NUMBER) TO #NUMERIC-FIELD
  IF #NUMERIC-FIELD = 0
    WRITE 'REQUIRED'
  END-IF
ELSE
  WRITE 'CLIENT-NUMBER IS NOT NUMERIC'
END-IF
```

You should always test the field with the IS before attempting to move the value with the VAL.

If that is what you are asking…

---

<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:** [November 3, 2008, 8:41pm UTC](https://techcommunity.softwareag.com/t/function-to-get-a-variable-value-by-name/79365/3 "2008-11-03T20:41:23Z")

</div>

> [@Daniel Wilson](#):
>
> If that is what you are asking…

I think this is, what samueldc is asking:

```auto
define data local
1 #varname (A10)
1 CLIENT-NUMBER (N8)
end-define
#varname := "CLIENT-NUMBER"
if getval(#varname) eq 0 /* get the content of CLIENT-NUMBER
  write 'REQUIRED...'
end-if
end
```

… and the answer is: No! There’s no such statement. The only thing you can do is to write the whole code dynamically … but this is ugly.

```auto
define printer (2) output 'SOURCE'
write (2) 'define data local'
write (2) ...
```

---

<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:51pm UTC](https://techcommunity.softwareag.com/t/function-to-get-a-variable-value-by-name/79365/4 "2021-04-02T14:51:05Z")

</div>


