# Working with Binary Fields

**URL:** <https://techcommunity.softwareag.com/t/working-with-binary-fields/92367>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [December 15, 2009, 12:50pm UTC](https://techcommunity.softwareag.com/t/working-with-binary-fields/92367 "2009-12-15T12:50:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hezi](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@Hezi](https://techcommunity.softwareag.com/u/Hezi)\
**Post date:** [December 15, 2009, 12:50pm UTC](https://techcommunity.softwareag.com/t/working-with-binary-fields/92367/1 "2009-12-15T12:50:26Z")

</div>

Hi,

I work with Cobol routine that return a Binary return code.  
How can I convert to decimal?  
Is there a sample code that shows converting B/D/A?  
How to use INIt/CONST with Binary fileds?

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [December 15, 2009, 5:22pm UTC](https://techcommunity.softwareag.com/t/working-with-binary-fields/92367/2 "2009-12-15T17:22:10Z")

</div>

Binary fields in Natural are basically numeric for lengths one to four. Hence:

DEFINE DATA LOCAL  
1 #B (B4) INIT \<123\>  
1 #N (N8)  
END-DEFINE  
MOVE #B TO #N  
WRITE #B #N  
END

Note, if you try to have #B (B5) you will get an error message re the INIT. This is because B5 and above are basically alpha fields, and the INIT would have to be in apostrophes. (of course MOVE #B TO #N will then get an error message)

steve

---

<div class="post-metadata">

**Author:** ![Hezi](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@Hezi](https://techcommunity.softwareag.com/u/Hezi)\
**Post date:** [December 15, 2009, 5:30pm UTC](https://techcommunity.softwareag.com/t/working-with-binary-fields/92367/3 "2009-12-15T17:30:48Z")

</div>

1. But when using : call ‘cobol’ #rc (b02), I need to convert #rc to decimal.
2. Using Init/Const : I mean to init variable with bin/hex value/

Hezi

---

<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:** [December 15, 2009, 7:49pm UTC](https://techcommunity.softwareag.com/t/working-with-binary-fields/92367/4 "2009-12-15T19:49:02Z")

</div>

Conversion is simply a matter of moving the source field to a target field of the correct type, e.g.:

```auto
DEFINE DATA LOCAL        
1 #RC (B02) INIT<H>
1 #RC_PACKED (P05)       
END-DEFINE               
*                        
* CALL 'COBOL' #RC       
*                        
MOVE #RC TO #RC_PACKED   
*                        
WRITE #RC #RC_PACKED     
*                        
END
```

Which will give you

```auto
MORE       
Page 1
           
0004 4
```

---

<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:57pm UTC](https://techcommunity.softwareag.com/t/working-with-binary-fields/92367/5 "2021-04-02T14:57:51Z")

</div>


