2015年6月12日 星期五

Call AS400 RPG program using asp.net

The first thing you will need to do is make sure you have the latest version of IBM Client Access (V5R3 or later) installed an make sure that you install the optional programmers toolkit.
Next, you will need to add a reference to the CWBX library from your application. This library provides the means by which we are going to be calling RPG from VB.net or C#. You can add a reference to this file from the project menu and selecting "Add Reference". You need to browse to "C:\Program Files\IBM Client\AccessShared\cwbx.dll". This will give you access to the IBM API's within the cwbx namespace. You can add cwbx to you using statements if you wish.



Imports cwbx

Private Sub GetAS400CycleDt()
        'try user the packed converter or string converter to conver the bytes array, it is cwvx api
        Dim str As New PackedConverter
        str.Digits = 8
        Dim strCover As New StringConverter

        Dim system As New AS400System
        system.Define("AS400")
        system.UserID = "userid"
        system.Password = "pass"
        system.IPAddress = "100.17.38.40"
        system.Connect(cwbcoServiceEnum.cwbcoServiceRemoteCmd)
        If system.IsConnected(cwbcoServiceEnum.cwbcoServiceRemoteCmd) Then
            Dim program As New cwbx.Program

            program.LibraryName = "DPLIB"
            program.ProgramName = "SU027"
            program.system = system

            Dim parameters As ProgramParameters = New ProgramParameters()
            parameters.Append("Input", cwbrcParameterTypeEnum.cwbrcInout, 80)
            parameters.Append("CycleDt", cwbrcParameterTypeEnum.cwbrcOutput, 80)
            parameters.Append("LastCycleDt", cwbrcParameterTypeEnum.cwbrcOutput, 80)
            parameters.Append("NextCycleDt", cwbrcParameterTypeEnum.cwbrcOutput, 80)
            parameters.Append("4", cwbrcParameterTypeEnum.cwbrcOutput, 80)
            parameters.Append("5", cwbrcParameterTypeEnum.cwbrcOutput, 80)
            parameters.Append("6", cwbrcParameterTypeEnum.cwbrcOutput, 10)
            parameters.Append("7", cwbrcParameterTypeEnum.cwbrcOutput, 20)
            parameters.Append("8", cwbrcParameterTypeEnum.cwbrcOutput, 20)
            parameters.Append("9", cwbrcParameterTypeEnum.cwbrcOutput, 64)
            parameters["Input"].Value = stringConverter.ToBytes("20120111")
            Try

                program.Call(parameters)
                'get the return values
                cycle_dt_YYYYMMDD_char = str.FromBytes(parameters("CycleDt").Value)
                cycle_dt = DateTime.ParseExact(cycle_dt_YYYYMMDD_char, "yyyyMMdd", Nothing)


            Catch ex As Exception
                WriteErrorLock(ex.Message)
            End Try


        End If
        system.Disconnect(cwbcoServiceEnum.cwbcoServiceAll)



    End Sub

沒有留言:

張貼留言