How to retrieve a cell value from a dataset

I am trying to use Visual COBOL for Visual Studio to call a SOAP webservices method to return multiple attribution of an item. The webservices method takes in a string value (item number), and returns a dataset (dsItemDetails). It is a very simple dataset, only one table in the dataset, and only one row in the return table, two columns in the return row, they are (item number), and (item description).

My questions is: how can I move the item description value in the return row to a string variable (strLableName) in Visual COBOL?

I knew the webservices call worked, I checked the row count in the returned dataset - datatable. It had a value of 1.

The other problem I had was I could not get the DataSet Visualizer to work in debug. Was it suppose to work in Visual COBOL for Visual Studio? It always work when I coded in Visual Basic with my Visual Studio settings.

Below are the codes from my test program:

01 wsinquiry type WSName.RXORDWS004 value new type WSName.RXORDWS004.
01 inItemNbr pic x(11).
01 any-key pic x.
01 intRowCount pic 999.
01 dsItemDetails type System.Data.DataSet.
01 strLableName type String.

procedure division.

set inItemNbr to "00002062402"

* returns a dataset
set dsItemDetails to wsinquiry::GetNDCAttributes(inItemNbr) as type System.Data.DataSet

* check for row count in the returned dataset - datatable
set intRowCount to dsItemDetails::Tables::Count

* This is how I coded in Visual Basic to get the ITEM_DESC value to a string variable

* strLableName = CStr(dsItemDetails.Tables(0).Rows(0).Item(1))

* OR strLableName = CStr(dsItemDetails.Tables(0).Rows(0).Item("ITEM_DESC"))

* How to code in Visual COBOL to perform the same function?

display " "
goback.

end program TestWSLink.

Many thanks from Stan

Parents
  • Verified Answer

    CStr is a VB function that converts an object to a string so you should be able to use something like the following in Visual COBOL:

    set strLableName = dsItemDetails::Tables[0]::Rows[0]::Item(1) as string

    * OR set strLableName = dsItemDetails::Tables[0]::Rows[0]::Item("ITEM_DESC") as string

  • Thank you Chris!
    I did not know that Visual COBOL use both curly brackets and square brackets for parameters. Now I do, and will learn when to apply which type.
    Stan
  • In managed code you can use the square brackets [] or the round brackets () when using indexing on an array. The difference is that when you use square brackets the subscript is 0 based (other .NET languages) and when you use round brackets (parenthesis) the subscript is 1 based (COBOL).

    This only applies to arrays though and the round brackets should really only be used when referencing COBOL data items that contain an OCCURS clause.

    The example that you use here is actually a case where you are specifying an index into a number of collections. These must be accessed via square brackets. The Item parameter is a special case and can actually be left out completely and you can just specify the occurrence number within a square bracket.

    set strLableName = dsItemDetails::Tables[0]::Rows[0][1] as string

    * OR set strLableName = dsItemDetails::Tables[0]::Rows[0]["ITEM_DESC"] as string

     

  • Thank you again Chris.
    Is there a Visual COBOL programming guide available for reference?
  • In the Reference section of the docs you can find the .NET COBOL Reference guide:

    You can also take a look at the Intro to OO COBOL Guide here:

    and the full-blown book on the subject, Developer's Guide to Modern COBOL here:

Reply Children