Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java calling cobol issue (Cobol program Not closing)

Status
Not open for further replies.

Wiezewazoel

Programmer
Apr 4, 2008
10
BE
Hello

I did not buy microfocus or something like it, so don't mention it!

i had to make java calling cobol, which works, but th real problem is:

I can't get it closed :s I'll explain with code...will be better:

Code:
import com.legacyj.api.Callable;

public class CobolPoort
{
	
	private Callable theCom;
	
	public CobolPoort (String naamBestand)
	{
		try
		{
			Class<Callable> prog;
			prog = (Class<Callable>) Class.forName(naamBestand);
			theCom = prog.newInstance();
		}
		catch (Throwable e)
		{
			e.printStackTrace();
		}
	}
		
	public Object uitvoeren (boolean[] booleans, Object[] objects)
	{
		try
		{
			return theCom.call(booleans, objects);
		} 
		catch (Throwable e)
		{
			e.printStackTrace();
			return null;
		}
	}
}

This is the code that calls the certain cobol program
The dutch:
Cobolpoort ==> "cobolport"
naambestand ==> filename

I do not have a single problem when i call this from a class where it is in the main Example:

Code:
package gui;

import cobolLink.CobolPoort;

public class NewTest 
{
	public static void main(String[] args)
	{
		int i = 0;
		CobolPoort poort = new CobolPoort("duurtijdproject");
		Object[] params = new Object[]{new Integer(1)};
		boolean[] booleans = new boolean[]{false};
		Object res = poort.uitvoeren(booleans, params);
		String alles = res.toString();
		double tijd = Double.parseDouble(alles.substring(0, 6));
		int teller = Integer.parseInt(alles.substring(6, 11));
		System.out.println("Duur: " + tijd);
		System.out.println("Teller: " + teller);
		if(teller!=0)
			do
			{
				String activiteit = alles.substring((11 + i) + (i*10), (22+i) + (i*10));
				int activiteitID = Integer.parseInt(activiteit.substring(0,5));
				double duur = Double.parseDouble(activiteit.substring(5,11));
				System.out.println("ActiviteitID: " + activiteitID + " heeft een duur van " + duur);
				i++;
			}while(i<teller);
	}
}

this works perfect!

but when i try calling it after i click a button in a jDialog:

Code:
private void btnToonActionPerformed(ActionEvent evt) 
	{
		int keuze = TijdsbestedingCobol.getID(cbbProjecten.getSelectedItem().toString());
		txtpUitvoer.setText(TijdsbestedingCobol.uitvoeren(this,keuze));
	}

this is the button action event! "keuze" is the choice the user made in a listbox "cbbProjecten".
then there is "TijdsbestedingCobol" which is a class that has similarities of a controller class:

Code:
package domein;

import javax.swing.JDialog;

import persistentie.Sql;
import cobolLink.CobolPoort;

public class TijdsbestedingCobol 
{
	
	private static Sql sql = new Sql();
	private static StringBuffer resultaat = new StringBuffer();
	
	public static String[] getProjecten()
	{
		return sql.getProjecten();
	}
	
	public static int getID(String project)
	{
		return sql.getID(project, 1);
	}
	
	public static String uitvoeren(JDialog cobol, int projectnr)
	{
[red]===============>[/red]cobol.setVisible(false);
		TijdsbestedingCobol tijds = new TijdsbestedingCobol();
		TijdsbestedingCobol.CobolThread c = tijds.new CobolThread(projectnr);
	    new Thread(c).start();
	    return resultaat.toString();
	}
	
	
    class CobolThread extends Thread {
        int projectnr;
        CobolThread(int projectnr)
        {
            this.projectnr = projectnr;
        }

        public void run() 
        {
    		int i = 0;
    		CobolPoort poort = new CobolPoort("duurtijdproject");
    		Object[] params = new Object[]{new Integer(1)};
    		boolean[] booleans = new boolean[]{false};
    		Object res = poort.uitvoeren(booleans, params);
    		String alles = res.toString();
    		double tijd = Double.parseDouble(alles.substring(0, 6));
    		int teller = Integer.parseInt(alles.substring(6, 11));
    		if(teller!=0)
    		{
    			do
    			{
    				String activiteit = alles.substring((11 + i) + (i*10), (22+i) + (i*10));
    				int activiteitID = Integer.parseInt(activiteit.substring(0,5));
    				double duur = Double.parseDouble(activiteit.substring(5,11));
    				resultaat.append("ActiviteitID: " + activiteitID + " heeft een duur van " + duur + "\n");
    				i++;
    			}while(i<teller);
    		}
    		else
    		{
    			resultaat.append("De totale duurtijd van dit project is: " + tijd);
    		}
        }
    }
}

I have tried to put this into a thread, though it worked out of it too, but the problem is...

At the arrow in this last piece of code, "===============>", there I have to put the dialog which calls this method, on invisible
ELSE i can NOT type in my cobol application!

my conclusion is, because its called after a dialog, or frame, it will keep doing weird.

In case you wondered how my cobol program finishes and begins:

Code:
PROCEDURE DIVISION USING projectnr GIVING Group-Data.
MAIN-PARAGRAPH.

...
/ ==> The user gets a question if he wants to give the values back to Java or not!
        If yes
                Exit program
        If no 
                Stop run


So my question is, anyone has an idea how to fix this?
- So i can push the button, java gives trough a parameter, my cobol program loads, asks things, etc, gives back something, displays it back in the dialog without seeing the cobol program ofcourse

things in blue work, things in red don't
 
I also have problems with this.
how do you get import com.legacyj.api.Callable working?
it does not work for me
Do i need to download the package?
if so ,where?

thanks in advance
 
You are probably at the same school as me so,
If you have Percobol installed, just go to

http://www.admins.be/viewtopic.php?p=21711#21711

since i saw your other post on cobol, you do speak dutch and thats also where i got convinced you are doing same project at the same school :p

just follow those slides like they said :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top