# How force specific charset in write work file

**URL:** <https://techcommunity.softwareag.com/t/how-force-specific-charset-in-write-work-file/182614>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-Code-Samples\
**Created:** [July 2, 2015, 4:22pm UTC](https://techcommunity.softwareag.com/t/how-force-specific-charset-in-write-work-file/182614 "2015-07-02T16:22:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juliano\_Jose\_da\_Silva](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@Juliano\_Jose\_da\_Silva](https://techcommunity.softwareag.com/u/Juliano_Jose_da_Silva)\
**Post date:** [July 2, 2015, 4:22pm UTC](https://techcommunity.softwareag.com/t/how-force-specific-charset-in-write-work-file/182614/1 "2015-07-02T16:22:27Z")

</div>

Hi, first, sorry for poor english.

How force specific charset in write work file in a subprogram? I need force ISO-8859-1 for a string in the moment of write work file, it’s possible? If not, it’s possible encode accents and special characters for HTML?

---

<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:** [July 3, 2015, 8:19am UTC](https://techcommunity.softwareag.com/t/how-force-specific-charset-in-write-work-file/182614/2 "2015-07-03T08:19:39Z")

</div>

ISO-8859-1 is a SBCS codepage, so why would you need to translate something to it, assuming your Natural session already runs with the correct locale ?

When you “force” something into a specific codepage from another there is always a potential risk that you end up with some characters that didn’t translate correctly.

Do you know what CP the data you need to "force to 8859-1 is in ?

---

<div class="post-metadata">

**Author:** ![Weihnachtsbar](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/weihnachtsbar/32/146_2.png) [@Weihnachtsbar](https://techcommunity.softwareag.com/u/Weihnachtsbar)\
**Post date:** [July 3, 2015, 9:24am UTC](https://techcommunity.softwareag.com/t/how-force-specific-charset-in-write-work-file/182614/3 "2015-07-03T09:24:04Z")

</div>

General Question: Is your Natural running on MF (with or without ICU) or LUW?

In general you can use the MOVE ENCODED statement for code-page/charset translation.

Best practice, in my opinion, is that the receiving variable is a binary dynamic.

Then you can DEFINE WORK with “UNFORMATTED” and the binary variable will be written unchanged to the work file.

If you want to generate e.g. an HTML/XML page, have a look at the variable \*CODEPAGE which returns the current settings of the Natural System (on LUW, on MF this variable is by be empty!)

For HTML translation you can use examine replace with two arrays - the one defines as A1 with the character you want to translate and the other one as A8 with your HTML entity names.

Consider using a function e.g. named XML then you can add a translation for anywhere.

```auto
MOVE ENCODED #XML_A TO #XML_B CODEPAGE 'utf-8'
```

```auto
DEFINE WORK FILE 12 #FILE_PATH TYPE "UNFORMATTED"
WORK FILE 12 VARIABLE #XML_B
CLOSE WORK 12
```

```auto
COMPRESS '<!DOCTYPE html><html><head>'
  '<meta charset="' *CODEPAGE '">'
 INTO #HTML_A LEAVING NO
```

```auto
COMPRESS '<?xml version="1.0" encoding="' *CODEPAGE '"?>'
  INTO #XML_A LEAVING NO
```

```auto
DEFINE PROTOTYPE XML RETURNS (A) DYNAMIC
DEFINE DATA PARAMETER
1 P00H (A) DYNAMIC BY VALUE
END-DEFINE
END-PROTOTYPE
*
DEFINE FUNCTION XML RETURNS (A) DYNAMIC
DEFINE DATA PARAMETER
1 P00H (A) DYNAMIC BY VALUE
LOCAL
1 ##ASCII_XML (1:3)
  2 ASCII (A1)
  2 XM (A8) /* XML is reserved by the function name
END-DEFINE
*
* ---- Ampersand
##ASCII_XML.ASCII(001) := "&" ##ASCII_XML.XM(001) := '&'
* ---- Greater than
##ASCII_XML.ASCII(002) := ">" ##ASCII_XML.XM(002) := '>'
* ---- Less than
##ASCII_XML.ASCII(003) := "<" ##ASCII_XML.XM(003) := '<'

* ------ MAIN PROGRAM --------------------------------------------
XML := P00H
*
EXAMINE XML FOR ##ASCII_XML.ASCII(*) REPLACE WITH ##ASCII_XML.XM(*)
*
END-FUNCTION
END
```

```auto
COMPRESS #HTML '<p>' XML(< #MYDATABASEFIELD >) '</p>' H'0D0A'
INTO #HTML LEAVING NO
```

---

<div class="post-metadata">

**Author:** ![Juliano\_Jose\_da\_Silva](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@Juliano\_Jose\_da\_Silva](https://techcommunity.softwareag.com/u/Juliano_Jose_da_Silva)\
**Post date:** [July 3, 2015, 1:01pm UTC](https://techcommunity.softwareag.com/t/how-force-specific-charset-in-write-work-file/182614/4 "2015-07-03T13:01:24Z")

</div>

> [@Wolfgang Winter](#):
>
> ISO-8859-1 is a SBCS codepage, so why would you need to translate something to it, assuming your Natural session already runs with the correct locale ?
> 
> When you “force” something into a specific codepage from another there is always a potential risk that you end up with some characters that didn’t translate correctly.
> 
> Do you know what CP the data you need to "force to 8859-1 is in ?

The generated file is read by a Java application. The generated file is a .txt.

The subprogram is written “ÁÉÍÓÚÇªº” , but int the file was written “Ý?²ä§CÞÑ??”. I’ve tried to read in all possible charsets in the Java application(CP037, CP1252, UTF-8, ISO-8859-1, UTF16…) but without success. So force a charset was the alternative.

---

<div class="post-metadata">

**Author:** ![Juliano\_Jose\_da\_Silva](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@Juliano\_Jose\_da\_Silva](https://techcommunity.softwareag.com/u/Juliano_Jose_da_Silva)\
**Post date:** [July 3, 2015, 1:06pm UTC](https://techcommunity.softwareag.com/t/how-force-specific-charset-in-write-work-file/182614/5 "2015-07-03T13:06:22Z")

</div>

> [@Weihnachtsbär](#):
>
> General Question: Is your Natural running on MF (with or without ICU) or LUW?
> 
> In general you can use the MOVE ENCODED statement for code-page/charset translation.
> 
> Best practice, in my opinion, is that the receiving variable is a binary dynamic.
> 
> Then you can DEFINE WORK with “UNFORMATTED” and the binary variable will be written unchanged to the work file.
> 
> If you want to generate e.g. an HTML/XML page, have a look at the variable \*CODEPAGE which returns the current settings of the Natural System (on LUW, on MF this variable is by be empty!)
> 
> For HTML translation you can use examine replace with two arrays - the one defines as A1 with the character you want to translate and the other one as A8 with your HTML entity names.
> 
> Consider using a function e.g. named XML then you can add a translation for anywhere.
> 
> ```auto
> MOVE ENCODED #XML_A TO #XML_B CODEPAGE 'utf-8'
> ```
> 
> ```auto
> DEFINE WORK FILE 12 #FILE_PATH TYPE "UNFORMATTED"
> WORK FILE 12 VARIABLE #XML_B
> CLOSE WORK 12
> ```
> 
> ```auto
> COMPRESS '<!DOCTYPE html><html><head>'
> '<meta charset="' *CODEPAGE '">'
> INTO #HTML_A LEAVING NO
> ```
> 
> ```auto
> COMPRESS '<?xml version="1.0" encoding="' *CODEPAGE '"?>'
> INTO #XML_A LEAVING NO
> ```
> 
> ```auto
> DEFINE PROTOTYPE XML RETURNS (A) DYNAMIC
> DEFINE DATA PARAMETER
> 1 P00H (A) DYNAMIC BY VALUE
> END-DEFINE
> END-PROTOTYPE
> *
> DEFINE FUNCTION XML RETURNS (A) DYNAMIC
> DEFINE DATA PARAMETER
> 1 P00H (A) DYNAMIC BY VALUE
> LOCAL
> 1 ##ASCII_XML (1:3)
> 2 ASCII (A1)
> 2 XM (A8) /* XML is reserved by the function name
> END-DEFINE
> *
> * ---- Ampersand
> ##ASCII_XML.ASCII(001) := "&" ##ASCII_XML.XM(001) := '&'
> * ---- Greater than
> ##ASCII_XML.ASCII(002) := ">" ##ASCII_XML.XM(002) := '>'
> * ---- Less than
> ##ASCII_XML.ASCII(003) := "<" ##ASCII_XML.XM(003) := '<'
> 
> * ------ MAIN PROGRAM --------------------------------------------
> XML := P00H
> *
> EXAMINE XML FOR ##ASCII_XML.ASCII(*) REPLACE WITH ##ASCII_XML.XM(*)
> *
> END-FUNCTION
> END
> ```
> 
> ```auto
> COMPRESS #HTML '<p>' XML(< #MYDATABASEFIELD >) '</p>' H'0D0A'
> INTO #HTML LEAVING NO
> ```

It’s perfect, thank you!

---

<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, 3:33pm UTC](https://techcommunity.softwareag.com/t/how-force-specific-charset-in-write-work-file/182614/6 "2021-04-02T15:33:43Z")

</div>


