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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

start program on as400 iseries server

Status
Not open for further replies.

VBmim

Programmer
Jun 25, 2001
361
BE
Hello

I have to start an as400 program from a vb6 program and I am having some problems...

Code:
Function testfunction()
On Error GoTo handler
Dim as400Connection As New ADODB.Connection
as400Connection.ConnectionString = strconnAs400
as400Connection.Open
    
Dim cmdtest As New ADODB.Command
Set cmdtest.ActiveConnection = as400Connection

'1    
cmdtest.CommandText = "CALL QSYS.QCMDEXC('CALL PGM (MYLIB/MYPROGRAM)', 0000000026.00000)"

'2
Str = "MYPROGRAM"
cmdtest.CommandText = "{{call qcmdexc ('" & Str & "', " & Format$(Len(Str), "0000000000.00000") & ")}}"

'3
cmdtest.CommandText = "{{call /QSYS.LIB/MYLIB.LIB/MYPROGRAM.PGM}}"

cmdtest.Execute
     
Set cmdtest = Nothing
    
as400Connection.Close
Set as400Connection = Nothing
Exit Function
handler:
If as400Connection.State = 1 Then
    as400Connection.Close
End If
Set as400Connection = Nothing
Set cmdtest = Nothing
End Function

1) gives me the following error = CPF0006: Errors occurred in command.
Cause . . . . . : If the wrong length was passed on one part of the command, other messages are issued because the wrong part of the command is being analyzed. Recovery . . . : See the previously listed messages in the job log. Correct the errors and then try the command again.

2) gives me the following error CPF0006 - Errors occurred in command.

3) My vb program hangs on the cmdtest.Execute line and I have to close it with task manager

Can anyone help me finding what I am doing wrong?

Greetz

VBMim
 
this is hardly a vb problem.

I will test this and come back to you.
One option you can use is to create a stored procedure on the 400 and execute that one instead.
the SP can be any type of programs, including CL and COBOL, and they then can do all you wish as per normal AS400 programs.

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Hello frederico

Thanks for your response.
I don't have many experiance in making stored procedures on an as400 system, and I don't know if it is possible for us because we bought the software from another company. Of course, we could ask our software vendor to make the stored procedure, but then they will obviously send a bill and I obviously want to avoid that :).

Greetz

VBMim
 
as long as you have one of the available compilers you can do a Stored Procedure. nothing to it.

If you don't then you do need to ask someone to do it for you, not necessaraly your software vendor.

But regarding your problem.
remove the qcmdexc as that may be the cause of your problem.


either of the following works

cmdtest.CommandText = "{{CALL /QSYS.LIB/FFONSECA.LIB/ATST1.PGM}}"
cmdtest.CommandText = "{{SBMJOB CMD(CALL PGM(FFONSECA/ATST1)) JOB(FREDTST) USER(FREDERICO) LOG(4 0 *MSG) LOGCLPGM(*YES) HOLD(*YES)}}"
cmdtest.CommandText = "{{call ffonseca/atst1}}"

cmdtest.Execute , , adExecuteNoRecords


I would also advise you to install the latest iSeries Access Express client, and install the VB ADO wizard, and then use it on a project to see how it executes and accesses all types of objects, including the use of paramters on commands.




Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Hello Frederico

Your tip on this not being a vb problem got me searching on my as400 client access.
I found out that the line

Code:
cmdtest.CommandText = "{{CALL /QSYS.LIB/FFONSECA.LIB/ATST1.PGM}}"

WAS starting the right procedure, but it gave a system error on the as400 waiting for an answer. That's why my program seemed to hang...

Together with our software vendor we figured out the problem. Because the program was run from a pc environment (and not directly in as400 client access), the procedure had some libraries missing. Within 5 minutes, our software vendor wrote anoter program that (I think) calls all right libraries before launching the initial program.

I'm glad it is solved, It almost took me all day...

Thanks for your help anyway

Greetz and good week-end!

VBMim

 
you did not had to create a new library. you can do that directly with the VB code. as follows.

as400Connection.Execute "{{ADDLIBLE lib1}}"
as400Connection.Execute "{{ADDLIBLE lib2}}"

This is done after opening the connection, and before the execution of the program call.

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Aha!

This is something I have to remember, thanks!

My software vendor not being a vb programmer probably didn't know this either.

Greetz

VBMim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top