UPDATE! The community will be go into read-only on April 19, 8am Pacific in preparation for migration on April 21. Read more.
UPDATE! The community will be go into read-only on April 19, 8am Pacific in preparation for migration on April 21.Read more.
Admiral
Admiral
296 views

Convert a command from C# to Cobol

Hi,

I am trying to convert a C # program to Cobol but there is an instruction that, despite not giving a compilation error, is not being executed.

The original statement is:

Manager.Http.SendRequestAsync(HttpMethodType.POST, this.ActionUri, body);

and the conversion will be:

invoke type Manager::Http::SendRequestAsync(type HttpMethodType::POST, self::ActionUri, body)

 

What is happening is that SendRequestAsync is not being executed.

Is there a different way to convert the statement to C #?

 

Thanks

Alberto Ferraz

0 Likes
5 Replies
Micro Focus Expert
Micro Focus Expert

The code appears to be converted to COBOL properly but I am not sure what you mean by it is never executed. Does it cause an exception to occur, does it never return from the call or does it just fall thru to the next statement?

You might try wrapping a TRY/CATCH block around it to see if an exception can be trapped?

Do you have a small cutdown example that we could test with?

0 Likes
Micro Focus Expert
Micro Focus Expert

This statement should execute exactly the same way C# would execute it. Keep in mind though, that this is an asynchronous method. It probably returns a Task<T> object which is used to track when the operation completes as it will be executed in the background.

You can find more information about asynchronous programming on Microsoft's documentation:
Asynchronous programming in C# | Microsoft Docs

It is likely though that you probably want to use the `await` syntax to block the current method until the operation completes successfully. Note that the await keyword is only supported in Visual COBOL 6.0 and above.

Example:

declare response = await type Manager::Http::SendRequestAsync(type HttpMethodType::POST, self::ActionUri, body)
declare content = await response::Content::ReadAsStringAsync()

 Relevant MF documentation is here:
Async - in COBOL and C# (microfocus.com)

Admiral
Admiral

Good afternoon:
When I say that the instruction is not executed, it is because it skips to the next instruction.

My question is that I cannot understand if the parameters are all correct and if that is why it is failing.

I already tried to put the instruction in a TRY-CATCH but it also doesn't "go out" through the cath, it moves on to the next instruction.

I will try to isolate a part of the application to be able to send.

 

Thanks

Alberto Ferraz

0 Likes
Micro Focus Expert
Micro Focus Expert

Please refer to the previous post by Ted John above for more details that you should look into...

Thanks.

0 Likes
Admiral
Admiral

Hi,

Thank you for your answers. I was able to execute the command and send the data to the machine.

Now I see how I get the answer, to know when the process is finished. If necessary,

I will send a new request for help.

Regarding the solution that Ted John presented, I was unable to incorporate it because it gives the error COBCH1927 in the "await" instruction and I still haven't figured out how to remove the error.

Thanks again.

 

Best regards

Alberto Ferraz

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.