Menjalankan program AS/400 using ASP.NET

Sharing, walaupun di internet sudah banyak beredar cara-caranya.

Ada pekerjaan web application yang membutuhkan akses ke AS/400 dan menjalankan program yang telah ada pada AS/400.

Untuk dapat menjalankan program dalam AS/400 dibutuhkan cwbx.dll yang ada pada instalasi IBM Client-Server. Kebetulan saya menggunakan versi 5 release 3. Cukup mudah, add saja cwbx.dll tersebut ke dalam project web pada VS 2005 anda. VS akan mengubah DLL tersebut menjadi Interop component.

Shared Function Configure(ByRef AS400Library As String, ByRef ProgramName As String, ByRef TheSystem As cwbx.AS400System, ByRef TheProgram As cwbx.Program) As Boolean

TheSystem.Define(ConfigurationManager.AppSettings.Item(“AS400Server”)) 

TheSystem.UserID = ConfigurationManager.AppSettings.Item(

 

“AS400UserID”)TheSystem.Password = ConfigurationManager.AppSettings.Item(

 

“AS400Password”)TheProgram.system = TheSystem

 

 

 

 

With

TheProgram 

 

.LibraryName = AS400Library

.ProgramName = ProgramName

 

 

End With 

 

 

 

Return True 

End Function

Script diatas adalah script untuk melakukan konfigurasi terhadap koneksi ke AS/400, dimana kebetulan saya menggunakan APPSETTING yang ditulis di web.config. Selanjutnya adalah membuat suatu function yang berfungsi memanggil program di AS/400.

 

Shared Function CallProgram(ByRef TheSystem As cwbx.AS400System, ByRef TheProgram As cwbx.Program, ByRef parameters As cwbx.ProgramParameters) As Boolean  

 

 

 

 

 

 

Try

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

If (TheSystem.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) = 0)  ThenTheSystem.Disconnect(cwbx.cwbcoServiceEnum.cwbcoServiceAll)

TheSystem.Connect(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd)

 

 

If (TheSystem.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) = 0) Then  

 

Return False  

 

End If  

 

End IfTheProgram.Call(parameters)

 

 

Return True  

 

Catch ex As Exception  

 

Throw ex  

 

 

 

 

Finally

 

 

 

 

 

If

 

Not (TheSystem.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) = 0)

Then

 

TheSystem.Disconnect(cwbx.cwbcoServiceEnum.cwbcoServiceAll)

 

 

End

If

 

 

 

 

 

End Try  

 

End Function

 

Selesai, anda tinggal mengkombinasikan 2 function di atas dengan menyebutkan library dan nama program beserta parameter-parameter dari program tersebut (bila ada).

 

Iklan

7 pemikiran pada “Menjalankan program AS/400 using ASP.NET

  1. Saya ubah program anda ke VB.Net

    Private Function Configure(ByRef AS400Library As String, ByRef ProgramName As String, ByRef TheSystem As cwbx.AS400System, ByRef TheProgram As cwbx.Program) As Boolean
    TheSystem.Define(“150.114.30.01”)
    TheSystem.UserID = “User”
    TheSystem.Password = “User”

    TheProgram.system = TheSystem
    With TheProgram
    .LibraryName = AS400Library
    .ProgramName = ProgramName
    End With
    Return True
    End Function

    Function CallProgram(ByRef TheSystem As cwbx.AS400System, ByRef TheProgram As cwbx.Program, ByRef parameters As cwbx.ProgramParameters) As Boolean
    Try
    If TheSystem.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) = 0 Then
    TheSystem.Disconnect(cwbx.cwbcoServiceEnum.cwbcoServiceAll)
    TheSystem.Connect(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd)

    If (TheSystem.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) = 0) Then
    Return False
    End If
    End If

    ‘ TheProgram.Call(parameters)
    Return True
    Catch ex As Exception
    Throw ex
    Finally
    If Not TheSystem.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) = 0 Then
    TheSystem.Disconnect(cwbx.cwbcoServiceEnum.cwbcoServiceAll)
    End If
    End Try
    End Function

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim TheSystem As New cwbx.SystemNames
    Dim as400 As New cwbx.AS400System
    Dim cmdAS400 As New cwbx.Command
    Dim ProgramName As New cwbx.Program
    Dim dQueue As New cwbx.DataQueue
    Dim strCvtr As New cwbx.StringConverter
    Dim lngCvtr As New cwbx.PackedConverter

    Configure(“MyLib”, “MyPrg”, TheSystem, ProgramName)
    CallProgram(TheSystem, ProgramName, Nothing)
    End Sub

    Muncul error seperti ini :
    Unable to cast COM object of type ‘cwbx.SystemNamesClass’ to interface type ‘cwbx.AS400System’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{86F9DB11-15D5-11D2-849C-0004AC94E175}’ failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

    Line 796: Dim lngCvtr As New cwbx.PackedConverter
    Line 797:
    Line 798: Configure(“MyLib”, “MyPrg”, TheSystem, ProgramName)
    Line 799: CallProgram(TheSystem, ProgramName, Nothing)
    Line 800: End Sub

    Source File: D:\Project\BM\Transactions\Payment\JournalEntry.aspx.vb Line: 798

  2. Salam pak Thedee,

    Di kantor saya menggunakan AS/400 untuk main systemnya dan RPG programming untuk back-end system.
    Ada program yang dibuat oleh vendor, sebut aja PrgSend yg ada di library MyLib.
    Program itu cuma baca dari sebuah Physical file yg dikirim lewat FTP untuk kemudian mengirim data ke real table
    dan dijalankan menlalui Client Access-nya AS/400.

    Saya ingin memanggil PrgSend tersebut dari ASP.Net dengan ide melakukan looping sebanyak jumlah transaksi yg ada di table SQL Server saya.

    Code:

    Dim AS400Name As String = “110.114.30.02”
    Dim AS400User As String = “User”
    Dim AS400Password As String = “User”
    Dim AS400Pgm = “PrgSend”
    Dim AS400Lib = “MyLib”

    Dim AS400 As New cwbx.AS400System
    Dim program As New cwbx.Program

    AS400.Define(AS400Name)

    program.system = AS400
    program.system.UserID = AS400User
    program.system.Password = AS400Password

    program.LibraryName = AS400Lib
    program.ProgramName = AS400Pgm

    AS400.Signon()
    AS400.Connect(cwbcoServiceEnum.cwbcoServiceRemoteC md)
    program.Call()

    Ngak jalan, malah nyakut di bagian ini : AS400.Define(AS400Name)

    cara lain saya coba panggil dgn ODBC connection

    Dim connectionString As String = “Dsn=MyDSN;uid=User;pwd=User;Force Translate=0;”
    Dim conn As Odbc.OdbcConnection = New Odbc.OdbcConnection(connectionString)
    Dim command As New Odbc.OdbcCommand(“call qsys.qcmdexc (‘MyLib/MyPrg’),0000000011.00000)”, conn)
    command.CommandType = CommandType.Text
    conn.Open()
    command.ExecuteNonQuery()
    conn.Close()

    Error :
    Code:

    ERROR [42000] [IBM][Client Access Express ODBC Driver (32-bit)][DB2/400 SQL]SQL0104 – Token , was not valid. Valid tokens: .

    Bisa bantu ngak untuk mennyelesaikan problem saya ?
    Apa ada yang perlu disetting di mesin AS/400 untuk jalanin atau kasih akses terhadap .Net ?
    Padahal, untuk jalanin perintah built-innya AS/400 aja bisa

    call qsys.qcmdexc (‘clrpfm file(MyLib/TmpTable)’)

    Terima kasih,

    Kusno.

  3. Eh…sorry

    Configure(”MyLib”, “MyPrg”, TheSystem, ProgramName)
    CallProgram(TheSystem, ProgramName, Nothing)

    Ganti TheSystem pakai as400 atau
    ganti deklarasi TheSystem di buttonclick dengan menggunakan cwbx.as400system

    –Cheers–

  4. Kalo yang ini…

    AS400.Signon()
    AS400.Connect(cwbcoServiceEnum.cwbcoServiceRemoteC md)
    program.Call()

    Ngak jalan, malah nyakut di bagian ini : AS400.Define(AS400Name)

    ==> Nyangkut tapi nggak error kan? ada kemungkinan itu nggak bisa resolve ip-nya AS/400. Asumsi emulator bisa jalan, coba line AS400.Signon dihapus deh….

  5. Saya sudah ubah programmnya jadi :

    Dim AS400Name As String = “110.114.30.2”
    Dim AS400User As String = “User”
    Dim AS400Password As String = “User”
    Dim AS400Pgm = “MyPrg”
    Dim AS400Lib = “MyLib”

    Dim AS400 As New cwbx.AS400System
    Dim program As New cwbx.Program

    AS400.Define(AS400Name)

    program.system = AS400
    program.system.UserID = AS400User
    program.system.Password = AS400Password

    program.LibraryName = AS400Lib
    program.ProgramName = AS400Pgm

    program.Call()

    Tetap sama saja, diem ngak ada response….

  6. Eh…sorry

    Configure(”MyLib”, “MyPrg”, TheSystem, ProgramName)
    CallProgram(TheSystem, ProgramName, Nothing)

    Ganti TheSystem pakai as400 atau
    ganti deklarasi TheSystem di buttonclick dengan menggunakan cwbx.as400system

    –Cheers–
    ==========================================
    Tetap aja ngak ada response mas….
    bingung dech…segala cara udah dicoba….

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s