Highlighted
Super Contributor.
Super Contributor.
1768 views

GridView

Jump to solution

Does anyone have an example of GridView (Web aspx) without using the database?
I'm using Cobol native files, is to populate a GridView that way?

Thank you

Alguém tem um exemplo de GridView (Web aspx) sem usar banco de dados ?
Só estou utilizando arquivos nativos Cobol, tem como popular um GridView dessa forma?

Obrigado

0 Likes
2 Solutions

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

I would recommend that you use the same method to populate the grid with records from a COBOL data file that you would when you get the data from a database, create a List or Collection object containing the data and bind this to the grid.

The example code below shows you one way that you can do this by calling a COBOL program that reads the file and places each record into a CustData object which is then added to a List. The List is then returned to the main form and it is bound to the gridview control.

  method-id Button1_Click protected.
       01 mylist list[type CustData].
       procedure division using by value sender as object e as type System.EventArgs.
           declare myrununit as type RunUnit = new RunUnit
           
           try 
              set mylist to myrununit::CallObject("getrecords") as List[type CustData]
           catch 
              set errormsg::Text to exception-object::Message
           finally
              invoke myrununit::StopRun
           end-try
           set GridView1::DataSource to mylist  
           invoke GridView1::DataBind 
           goback.
       end method.

called program:


       program-id. getrecords as "WebGridview.getrecords".
           select cust-file assign to "C:\WebGridview\WebGridview\WebGridview\App_Data\custfile.txt"
                            organization is line sequential
                            file status is file-status.
       data division.
       fd cust-file.
       01 cust-record.
          05 cust-name   pic x(20).
          05 cust-company pic x(20).
          05 cust-phone  pic x(15).
       working-storage section.
       01 file-status    pic x(2) value spaces.
       01 mydata type CustData.
       01 mylist list[type CustData] value new List[type CustData].
       procedure division returning mylist.

           open input cust-file
           if file-status = "00"
              perform until exit
                 read cust-file
                    at end
                       exit perform
                    not at end
                       set mydata to new CustData
                       set mydata::CustName to cust-name
                       set mydata::Company to cust-company
                       set mydata::Phone to cust-phone
                       invoke mylist::Add(mydata)
                 end-read
              end-perform
           end-if
           close cust-file
           goback.
           
       end program getrecords.

Class:


class-id WebGridview.CustData public.

       working-storage section.
       01 CustName  string property.
       01 Company   string property.
       01 Phone     string property.
       end class.

View solution in original post

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Right-click on the Project References folder and select Add Reference and then select the assembly MicroFocus Runtime (Interop RuntimeServices) 4.0 which is listed under the Extensions section.

This will add MicroFocus.COBOL.RuntimeServices.dll to your project. This contains the RunUnit class.

Then add the following directive to the top of Default.aspx.cbl

$set ilusing"MicroFocus.COBOL.RuntimeServices"

Your project will then compile successfully.

In a multi-threaded environment like ASP.NET where each user request is handled by a separate thread, you must protect the resources that the COBOL programs use to make them thread safe. This is what the RunUnit class does. By creating an instance of the RunUnit class for each user request and then adding your top level COBOL program to the RunUnit and calling it, you will be protecting all resources of that program and any other program that it may call. This includes resources source as open files, database connections and working-storage data. If you did not use a RunUnit and just executed a CALL statement directly from your .aspx program then only one instance of the program would be created and shared by all threads. These threads would quickly be stomping all over each other.

Documentation for RunUnits and multiuser programming can be found in the docs here:

The actual documentation for the RunUnit class is in a separate help file which is documented here:

View solution in original post

0 Likes
6 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

I would recommend that you use the same method to populate the grid with records from a COBOL data file that you would when you get the data from a database, create a List or Collection object containing the data and bind this to the grid.

The example code below shows you one way that you can do this by calling a COBOL program that reads the file and places each record into a CustData object which is then added to a List. The List is then returned to the main form and it is bound to the gridview control.

  method-id Button1_Click protected.
       01 mylist list[type CustData].
       procedure division using by value sender as object e as type System.EventArgs.
           declare myrununit as type RunUnit = new RunUnit
           
           try 
              set mylist to myrununit::CallObject("getrecords") as List[type CustData]
           catch 
              set errormsg::Text to exception-object::Message
           finally
              invoke myrununit::StopRun
           end-try
           set GridView1::DataSource to mylist  
           invoke GridView1::DataBind 
           goback.
       end method.

called program:


       program-id. getrecords as "WebGridview.getrecords".
           select cust-file assign to "C:\WebGridview\WebGridview\WebGridview\App_Data\custfile.txt"
                            organization is line sequential
                            file status is file-status.
       data division.
       fd cust-file.
       01 cust-record.
          05 cust-name   pic x(20).
          05 cust-company pic x(20).
          05 cust-phone  pic x(15).
       working-storage section.
       01 file-status    pic x(2) value spaces.
       01 mydata type CustData.
       01 mylist list[type CustData] value new List[type CustData].
       procedure division returning mylist.

           open input cust-file
           if file-status = "00"
              perform until exit
                 read cust-file
                    at end
                       exit perform
                    not at end
                       set mydata to new CustData
                       set mydata::CustName to cust-name
                       set mydata::Company to cust-company
                       set mydata::Phone to cust-phone
                       invoke mylist::Add(mydata)
                 end-read
              end-perform
           end-if
           close cust-file
           goback.
           
       end program getrecords.

Class:


class-id WebGridview.CustData public.

       working-storage section.
       01 CustName  string property.
       01 Company   string property.
       01 Phone     string property.
       end class.

View solution in original post

0 Likes
Highlighted
Super Contributor.
Super Contributor.

Chris, thanks for the help but I could not understand where to put it in my project. Confused

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

If you tell me how your project is currently organized perhaps I can make some suggestions. You can update the individual columns of the gridview itself with data but binding to a collection object is really a better way to accomplish this,

Is there a specific question that I can help you with regarding this example?

0 Likes
Highlighted
Super Contributor.
Super Contributor.

Thank you Chris, see this example I did, but there's something wrong do not understand RunUnit

Obrigado Chris, veja este exemplo que fiz, mas tem alguma coisa errada não entendo o RunUnit.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Right-click on the Project References folder and select Add Reference and then select the assembly MicroFocus Runtime (Interop RuntimeServices) 4.0 which is listed under the Extensions section.

This will add MicroFocus.COBOL.RuntimeServices.dll to your project. This contains the RunUnit class.

Then add the following directive to the top of Default.aspx.cbl

$set ilusing"MicroFocus.COBOL.RuntimeServices"

Your project will then compile successfully.

In a multi-threaded environment like ASP.NET where each user request is handled by a separate thread, you must protect the resources that the COBOL programs use to make them thread safe. This is what the RunUnit class does. By creating an instance of the RunUnit class for each user request and then adding your top level COBOL program to the RunUnit and calling it, you will be protecting all resources of that program and any other program that it may call. This includes resources source as open files, database connections and working-storage data. If you did not use a RunUnit and just executed a CALL statement directly from your .aspx program then only one instance of the program would be created and shared by all threads. These threads would quickly be stomping all over each other.

Documentation for RunUnits and multiuser programming can be found in the docs here:

The actual documentation for the RunUnit class is in a separate help file which is documented here:

View solution in original post

0 Likes
Highlighted
Super Contributor.
Super Contributor.

Chris, thank you!

I will read this documentation, it worked!

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.