Highlighted
Honored Contributor.
Honored Contributor.
1475 views

translate C# WriteLine to Visual COBOL

Jump to solution

The following C# console program, when translated to the following Visual COBOL equivalent, produces different results - apparently the tab (the \t escape sequence) is not recognized in the COBOL version of the program (???).

C# :

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace csConTest1

{

    class Program

         {

        static void Main(string[] args)

                 {

             Console.WriteLine("\t{0}\t{1}\t{2}",

                               "1", "2", "three");

                 }

         }

}

 

Visual COBOL:

        program-id. Program1 as "cblConTest1.Program1".

        data division.

        working-storage section.

        procedure division.

            Invoke type Console::WriteLine("\t{0}\t{1}\t{2}",

                                           "1", "2", "three");

            goback.

         end program Program1.

 

0 Likes
2 Solutions

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: translate C# WriteLine to Visual COBOL

Jump to solution

Strangely (and rather annoyingly) semicolon and comma have always been treated as white space by COBOL.  I believe this was already the case in ANS 74 COBOL, and remains the case now.  It would be nice if for instance the comma could be used to separate parameters in an invoke parameter list, but COBOL does not work like that...

View solution in original post

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: translate C# WriteLine to Visual COBOL

Jump to solution

As for the main point (support for /t etc.) it's true this is not supported by COBOL, and it would probably be difficult to introduce support at this stage because of compatibility issues.

You can do something like:

          Invoke type Console::WriteLine(x"09" & "{0}" & x"09" & "{1}" & x"09" &" {2}", "1", "2", "three");

..or maybe:

78 tab-char value x"09".

... and then:

          Invoke type Console::WriteLine(tab-char & "{0}" & tab-char & "{1}" & tab-char &" {2}", "1", "2", "three");

Not very elegant but should do the job...

View solution in original post

0 Likes
3 Replies
Highlighted
Honored Contributor.
Honored Contributor.

RE: translate C# WriteLine to Visual COBOL

Jump to solution

... also notice that Visual COBOL ignored / had no issue with the semicolon at the end of the statement...

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: translate C# WriteLine to Visual COBOL

Jump to solution

Strangely (and rather annoyingly) semicolon and comma have always been treated as white space by COBOL.  I believe this was already the case in ANS 74 COBOL, and remains the case now.  It would be nice if for instance the comma could be used to separate parameters in an invoke parameter list, but COBOL does not work like that...

View solution in original post

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: translate C# WriteLine to Visual COBOL

Jump to solution

As for the main point (support for /t etc.) it's true this is not supported by COBOL, and it would probably be difficult to introduce support at this stage because of compatibility issues.

You can do something like:

          Invoke type Console::WriteLine(x"09" & "{0}" & x"09" & "{1}" & x"09" &" {2}", "1", "2", "three");

..or maybe:

78 tab-char value x"09".

... and then:

          Invoke type Console::WriteLine(tab-char & "{0}" & tab-char & "{1}" & tab-char &" {2}", "1", "2", "three");

Not very elegant but should do the job...

View solution in original post

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.