Click here to Skip to main content
11,495,049 members (52,183 online)
Click here to Skip to main content

Accessing AS400 Business Logic From .NET Applications

, 21 Oct 2003 204.8K 455 34
Rate this:
Please Sign up or sign in to vote.
This article describes how to call a COBOL program residing on an AS400 machine from a .NET application.

Sample Image - Accessing_AS400.jpg

Introduction

A company's data might exist scattered in legacy systems, in custom-built business applications and in databases in different parts of the organization. The ability to integrate and leverage all this data and applications helps us in reducing the reuse of existing applications, development time and the risk.

I also encountered a similar scenario where I had to reuse the data and business logic (which is implemented in COBOL) developed on AS/400, from a .NET application. This article is a modest approach which describes the above, using an example..

About the application

The application explained here has three buttons. The Add button sends the input data to a COBOL program, which is available on an AS/400 machine. This COBOL program validates the entered user information. If its a valid data, it updates the physical file (USERS) which is residing on AS/400. The Remove button deletes a row from the same physical file based on the user ID provided .The Quit button closes the application.

The .NET application, which I’ve developed, reads the user input and calls the COBOL program. The COBOL program passes the data entered by the user and receives the values returned by the COBOL program. The three textboxes provide the input parameters for the program. They contain the data to be updated.

Sample screenshot

The AS/400 machine name (connection string) and the library in which the COBOL program is available are configured in the app.config file. This allows us to change these values without the need to recompile the program.

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

 <appSettings>

  <add key="ProgramName" value="pgm1" />

  <add key="Library" value="lib1" />

  <add key="ConnectionString" value="conn1"/>

</appSettings>

</configuration>

where

  • pgm1 = Name of the COBOL program
  • lib1 = Library on AS/400 in which COBOL program is available
  • conn1 = connection string for AS/400
"Provider=IBMDA400.DataSource.1;User ID=XXXX;Password=YYYYY;Data 
Source=123.123.123.123;Connect Timeout=_ 
30;SSL=DEFAULT;Transport Product=Client Access"

This application uses ADODB as an interface to connect to the database. It has three primary objects- the connection object, the command object and the recordset. The command object is used to execute the command text from the connection object. The parameters are stored in the command parameters and the values are read during runtime. When the command type in the command object is text, we must specify a placeholder for the number of parameters. IBM Client Express’s IBMDA400 OLEDB provider is used for connecting to AS/400.

The following code shows how we have used the command object for passing the three parameters:

command = New ADODB.Command

OpenConnection()

command.ActiveConnection = conn

command.CommandType = ADODB.CommandTypeEnum.adCmdText

command.Parameters.Append(command.CreateParameter("P1",_ 
ADODB.DataTypeEnum.adChar, _ 
  ADODB.ParameterDirectionEnum.adParamInputOutput,5))

command.Parameters.Append(command.CreateParameter("P2",_ 
ADODB.DataTypeEnum.adChar, _
   ADODB.ParameterDirectionEnum.adParamInputOutput,10))

command.Parameters.Append(command.CreateParameter("P3", _
ADODB.DataTypeEnum.adChar, _ 
    ADODB.ParameterDirectionEnum.adParamInputOutput, 10))

The following code calls the COBOL program:

command.CommandText = "{{CALL /QSYS.LIB/" & _ 
        lib_str & ".LIB/" & program_str & ".PGM(?,?,?)}}"

command.Prepared = True

Dim Rcds As Object = New Object

command.Execute(Rcds, a, command.CommandType.adCmdText)

We can also execute the SQL queries directly on AS/400 physical files. This is a right solution when we need to change the data without any prior processing. For implementing delete functionality I am using this procedure.

command.CommandType = ADODB.CommandTypeEnum.adCmdText

command.CommandText = "DELETE FROM " & _
    libr_str & ".USERS1 WHERE USERID =" & txtUserId.Text

command.Execute()

Conclusion

We can manipulate the data that is stored on AS/400 from our .NET applications. We can integrate applications or use the business logic already implemented on AS/400 in our .NET solutions using this approach.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Kodanda Pani
Web Developer
India India
Working on .NET for last 6 years. Currently working for TCS.

Comments and Discussions

 
GeneralExemple d'utilisation de I5_Dotnet pour AS400 Pin
Armand Pierre16-Dec-10 0:13
memberArmand Pierre16-Dec-10 0:13 
General.NET data provider Pin
Polymorpher18-Dec-09 9:29
memberPolymorpher18-Dec-09 9:29 
GeneralRe: .NET data provider Pin
Armand Pierre22-Oct-10 3:41
memberArmand Pierre22-Oct-10 3:41 
Generalcommand text Pin
Kishar_200227-Jan-06 18:13
memberKishar_200227-Jan-06 18:13 
GeneralRe: command text Pin
Kodanda Pani29-Jan-06 20:12
memberKodanda Pani29-Jan-06 20:12 
GeneralIBM Client Express Pin
Jefferson Muñoz25-Jul-05 7:57
memberJefferson Muñoz25-Jul-05 7:57 
GeneralRe: IBM Client Express Pin
Anonymous13-Sep-05 9:49
sussAnonymous13-Sep-05 9:49 
GeneralPassing Numeric parameters between AS/400 and .NET Pin
derekadk24-Feb-05 23:20
memberderekadk24-Feb-05 23:20 
GeneralRe: Passing Numeric parameters between AS/400 and .NET Pin
Kodanda Pani7-Mar-05 19:33
memberKodanda Pani7-Mar-05 19:33 
GeneralRe: Passing Numeric parameters between AS/400 and .NET Pin
derekadk10-Jun-05 0:40
memberderekadk10-Jun-05 0:40 
GeneralRe: Passing Numeric parameters between AS/400 and .NET Pin
shrir12-Oct-06 19:31
membershrir12-Oct-06 19:31 
QuestionAnyone know how to go the other direction? Pin
ANORTON24-Feb-05 11:55
memberANORTON24-Feb-05 11:55 
GeneralConnecting to AS400 from .net Pin
joshiRohit_2115-Dec-04 1:07
sussjoshiRohit_2115-Dec-04 1:07 
GeneralRe: Connecting to AS400 from .net Pin
SGandhiS14-Feb-05 21:13
memberSGandhiS14-Feb-05 21:13 
GeneralRe: Connecting to AS400 from .net Pin
joshiRohit_2115-Feb-05 2:09
memberjoshiRohit_2115-Feb-05 2:09 
Generalcalling RPGLE PGM, Module and service program Pin
dsnvsnmdb15-Apr-04 5:15
memberdsnvsnmdb15-Apr-04 5:15 
GeneralRe: calling RPGLE PGM, Module and service program Pin
Sheeba Gandhi21-Apr-04 1:32
memberSheeba Gandhi21-Apr-04 1:32 
GeneralMaintenance program in .NET Pin
Effy15-Jan-04 23:40
memberEffy15-Jan-04 23:40 
GeneralRe: Maintenance program in .NET Pin
kodandapani17-Mar-04 23:53
memberkodandapani17-Mar-04 23:53 
GeneralAs400 invoking a .Net Pin
dfitzge217-Dec-03 7:19
memberdfitzge217-Dec-03 7:19 
GeneralRe: As400 invoking a .Net Pin
dfitzge218-Dec-03 4:29
memberdfitzge218-Dec-03 4:29 
GeneralADODB vs OLEDB connecting the AS/400 Pros &amp; Cons Pin
Effy27-Oct-03 0:11
memberEffy27-Oct-03 0:11 
GeneralReturn params from an AS400 PGM Pin
Effy24-Oct-03 3:29
memberEffy24-Oct-03 3:29 
GeneralRe: Return params from an AS400 PGM Pin
sheeba Gandhi24-Oct-03 18:32
membersheeba Gandhi24-Oct-03 18:32 
GeneralRe: Return params from an AS400 PGM Pin
Effy25-Oct-03 20:47
memberEffy25-Oct-03 20:47 
GeneralRe: Return params from an AS400 PGM Pin
sheeba Gandhi27-Oct-03 1:18
membersheeba Gandhi27-Oct-03 1:18 
GeneralRe: Return params from an AS400 PGM Pin
shrir12-Oct-06 19:29
membershrir12-Oct-06 19:29 
GeneralRe: Return params from an AS400 PGM Pin
Anonymous15-Nov-03 22:44
sussAnonymous15-Nov-03 22:44 
GeneralFunction Vs raw SQL Pin
codeJuice22-Oct-03 3:06
susscodeJuice22-Oct-03 3:06 
GeneralRe: Function Vs raw SQL Pin
sheeba Gandhi24-Oct-03 18:39
membersheeba Gandhi24-Oct-03 18:39 
GeneralAVR.NET Pin
Dean Bathke21-Oct-03 13:45
memberDean Bathke21-Oct-03 13:45 
GeneralRe: AVR.NET Pin
sheeba Gandhi21-Oct-03 18:49
membersheeba Gandhi21-Oct-03 18:49 
GeneralRe: AVR.NET Pin
Dean Bathke22-Oct-03 2:32
memberDean Bathke22-Oct-03 2:32 
GeneralArticle improvement Pin
Michael P Butler19-Oct-03 23:40
memberMichael P Butler19-Oct-03 23:40 
GeneralRe: Article improvement Pin
sheeba Gandhi21-Oct-03 21:28
membersheeba Gandhi21-Oct-03 21:28 
GeneralADODB Pin
cathy.A19-Oct-03 21:24
membercathy.A19-Oct-03 21:24 
GeneralRe: ADODB Pin
sheeba Gandhi19-Oct-03 21:36
membersheeba Gandhi19-Oct-03 21:36 
GeneralRe: ADODB Pin
cathy.A19-Oct-03 21:43
membercathy.A19-Oct-03 21:43 
GeneralRe: ADODB Pin
sheeba Gandhi21-Oct-03 18:57
membersheeba Gandhi21-Oct-03 18:57 
GeneralRe: ADODB Pin
Effy15-Nov-03 22:57
memberEffy15-Nov-03 22:57 
GeneralRe: ADODB Pin
tfoster22-Oct-03 4:33
membertfoster22-Oct-03 4:33 
GeneralRe: ADODB Pin
sheeba Gandhi24-Oct-03 18:56
membersheeba Gandhi24-Oct-03 18:56 
GeneralRPG program Pin
dragonwell17-Oct-03 6:53
memberdragonwell17-Oct-03 6:53 
GeneralRe: RPG program Pin
sheeba Gandhi19-Oct-03 19:48
membersheeba Gandhi19-Oct-03 19:48 
GeneralA pedantic observation regarding the case you have used to spell .NET Pin
Nishant S17-Oct-03 3:45
staffNishant S17-Oct-03 3:45 
GeneralRe: A pedantic observation regarding the case you have used to spell .NET Pin
dog_spawn17-Oct-03 5:44
memberdog_spawn17-Oct-03 5:44 
GeneralRe: A pedantic observation regarding the case you have used to spell .NET Pin
Nishant S17-Oct-03 5:46
staffNishant S17-Oct-03 5:46 
GeneralRe: A pedantic observation regarding the case you have used to spell .NET Pin
dog_spawn17-Oct-03 5:49
memberdog_spawn17-Oct-03 5:49 
GeneralRe: A pedantic observation regarding the case you have used to spell .NET Pin
Nishant S17-Oct-03 5:57
staffNishant S17-Oct-03 5:57 
GeneralRe: A pedantic observation regarding the case you have used to spell .NET Pin
dog_spawn17-Oct-03 5:59
memberdog_spawn17-Oct-03 5:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 22 Oct 2003
Article Copyright 2003 by Kodanda Pani
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid