Question : .Net (cwbx) calling cl program on as400

I have an excel add-in I created in Visual studio for office that calls a CL program on our as400. The .Net side of things works fine. The problem is the if the CL program has a problem and errors my excel Add-in does not know about it because the as400 is in MSGW mode waiting for some one to enter C D I R so it can continue dumping itself. My .Net app just sits there waiting for the command on the as400 to finish running.

I am trying to figure out what I need to do to manage the as400 errors the user of the excel add-in knows something bad happened.

I am thinking that the CL program need to be rewritten or maybe converted to an RPG program that will return something to my program that lets it know if all went well or not.

Or is there a way to just runt the CL program in a way that it will not do the the MSGW thing and just go ahead and dump some errors that my app will get it in cwbx.Command.Errors.

I just need to know what needs to happen on the as400 to get around this so I can tell our as400 programmer what to do. He has never dealt with anything like this before so nether of use are sure what to do for the best solution.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
cwbx.AS400System as400 = new cwbx.AS400SystemClass();
            cwbx.ProgramParameters parameters = new ProgramParametersClass();
            cwbx.Program program = new cwbx.Program();
            cwbx.Command cmd = new Command();
            
            Debug.Print("before try");
            try
            {
                
               as400.Define("XX.XX.XX.XX");
                as400.UserID = "USERID";
                as400.Password = "PASSWORD";
                as400.PromptMode = cwbcoPromptModeEnum.cwbcoPromptNever;
                as400.Signon();
                cmd.system = as400;
                
                //this did not work
                //cmd.Run("SBMJOB CMD(CALL PGM(MIKE/TESTER) PARM('645')) JOB(EXTEST) USER(EXCELUSR) INQMSGRPY(*DFT) HOLD(*NO)");                                                   
 
                cmd.Run("CALL PGM(MIKE/TESTER) PARM('645')");
                
                Debug.Print("after call");
            }
            catch (Exception ex)
            {
                Debug.Print("Exception = "+ ex.Message + " trace " + ex.StackTrace);
                if (cmd.Errors.Count > 0)
                {
                    foreach (cwbx.Error error in cmd.Errors)
                    {
                        System.Diagnostics.Debug.Print("CMD Errors : " + error.Text);
                    }
 
                }
                if (as400.Errors.Count > 0)
                {
                    foreach (cwbx.Error error in as400.Errors)
                    {
                        System.Diagnostics.Debug.Print("AS400 Errors : " + error.Text);
                    }
                }
 
                if (program.Errors.Count > 0)
                {
                    foreach (cwbx.Error error in program.Errors)
                    {
                        System.Diagnostics.Debug.Print("Program Errors : " + error.Text);
                    }
                }
            }
            finally
            {
               // as400.Disconnect(cwbcoServiceEnum.cwbcoServiceAll);
            }
        }
Open in New Window Select All

Answer : .Net (cwbx) calling cl program on as400

You can use the MONMSG command in the CL program to specifically monitor for the errors your CL is getting which you can then deal with the error gracefully.  You can also monitor for error messages globally by having the MONMSG command as the first command in the CL program after PGM and declares.

A good simple explanation of how to use error handling in CL can be found at
http://www.400school.com/artmsg.htm    
Random Solutions  
 
programming4us programming4us