Highlighted
Partha1 Absent Member.
Absent Member.
3350 views

Code Page Conversion.

Is there any method in Visual COBOL to do Code Page converison for File CP1250
(windows code page) to CP852 (DOS code page).

Thanks,

Partha!

0 Likes
6 Replies
Micro Focus Expert
Micro Focus Expert

RE: Code Page Conversion.

Hi Partha,

Are you referring to programatically converting code pages within your application or doing a one time conversion of source code within Visual Studio?

If it is the latter of the two then you can open up the file in Visual Studio and then select File-->Advanced Save Options and then change the target code page to the one that you desire and then save the file.

If you wish to do this programmatically then you would look into using the .NET System.Text.Encoding class.

Please take a look here.

If you require a COBOL example then let me know exactly what it is that you are trying to do and I will work one up for you.

Thanks

0 Likes
Partha1 Absent Member.
Absent Member.

RE: Code Page Conversion.

Thanks Chris.

I want to do this by programatically..regarding few files we received in 1250 nd want to convert in 852. It would be great help if you can refer anu COBOL example.

0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Code Page Conversion.

The following might work for you:

      $set ilusing"System.Text" 
      $set ilusing"System.IO" 
       program-id. Program1 as "fileconvert.Program1".
       data division.
       working-storage section.
       01 fileName string value "myfile.txt".
       01 newfileName string value "newfile.txt".
       01 original string value type String::Empty.
       01 sr type StreamReader.
       01 sw type StreamWriter.
       procedure division.
           
           set sr to new StreamReader(filename, type Encoding::GetEncoding("windows-1250"))
           set original to sr::ReadToEnd 
           invoke sr::Close
           
           set sw to new StreamWriter(newFilename, false, type Encoding::GetEncoding("ibm852"))
           invoke sw::Write(original)
           invoke sw::Close
      
           goback.
           
       end program Program1.
0 Likes
Partha1 Absent Member.
Absent Member.

RE: Code Page Conversion.

Hi Chris,

Is this code snippet supports Visual COBOL?

0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Code Page Conversion.

Yes, it was written using Visual COBOL 2.2 update 1 for VS2012.

It is a managed code project and must be compiled as such.

0 Likes
Panos_Zotos Contributor.
Contributor.

RE: Code Page Conversion.

Hi Partha,

Since you need to convert between the ANSI and OEM codeset, the following two routines might work for you:

PC_WIN_CHAR_TO_OEM (which will convert CP1250 to 852) and PC_WIN_OEM_TO_CHAR that will do the opposite. They are fully described in the product documentation.

CP1250 should be the active codepage on you machine.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.