Cadet 3rd Class
Cadet 3rd Class

Request: Visual Cobol Program w/ web API on a Visual Studio platform


Are there samples of Visual Cobol program that access web API? 

We don't have Eclipse and work on a Visual Studio platform.  

Labels (1)
1 Reply
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Not sure if this is exactly what you were looking for but here is an example of accessing a web service using our .NET COBOL syntax:

class-id ManagedCOBOL.LocalTimeHelper.

*>> <summary>
*>> This method returns the local time for a store
*>> </summary>
*>> <param name="latitude">I'll give you 1 guess as to what this needs...</param>
*>> <param name="longitude">Oh come on</param>
*>> <returns>The local time in a given latitude/longitude according to Google</returns>
method-id GetLocalTime static.

procedure division using by value latitude as float-long, by value longitude as float-long,
returning res as string.

declare client = new type RestSharp.RestClient("")
declare request = new RestSharp.RestRequest("timezoneJSON", type RestSharp.Method::GET)

invoke request::AddParameter("lat", latitude)
invoke request::AddParameter("lng", longitude)
invoke request::AddParameter("username", "microfocals")

declare response = client::Execute[type GeoNamesTimeZone](request)

set res to response::Data::time

end method.

end class.

class-id GeoNamesTimeZone.
working-storage section.
01 sunrise string property.
01 lng string property.
01 countryCode string property.
01 gmtOffset string property.
01 rawOffset string property.
01 sunset string property.
01 timezoneId string property.
01 dstOffset string property.
01 countryName string property.
01 time string property.
01 lat string property.
end class.

*Example JSON reply for the timezoneJSON API:
* "sunrise": "2019-05-17 05:41",
* "lng": 10.2,
* "countryCode": "AT",
* "gmtOffset": 1,
* "rawOffset": 1,
* "sunset": "2019-05-17 20:49",
* "timezoneId": "Europe/Vienna",
* "dstOffset": 2,
* "countryName": "Austria",
* "time": "2019-05-17 14:01",
* "lat": 47.01

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.