Getting information out of an AS/400 data area from Visual Basic
| Date: | Archived |
|---|---|
| Product/Release: | LANSA/Server |
| Abstract: | You can get information out of an AS/400 data area very easily from Visual Basic using LANSA/Server. |
| Submitted By: | N/A |
It is easy using LANSA to get information out of an AS/400 data area from Visual Basic.
You can use a LANSA/Server function Lce3GLCall to call a CL program on the AS/400 that retrieves the contents of the data area and returns them to a PC program written in Visual Basic.
There are a number of benefits using this technique such as:
- If there is an error on the AS/400 (eg the data area doesn't exist) the CL program can automatically create it for you.
- If the user is not authorised to the data area then the CL program could also handle this in a "very friendly" manner
- In the example below a "generic" data area handling program (ie for any data area) was created. With a little more work you could also update the data area contents too.
Here is the CL source for the AS/400 CL program:
*************** Beginning of data******************************
/* Program Name: DATAAREA *
/* Program Description: GETS CONTENTS OF PASSED DATAAREA NAME */
/* Author Name: DOUG Date Written: 25/10/96 */
/**************************************************************/
DATAAREA: PGM PARM(&NAME &CONTENT)
/* Declarations:
*/ DCL VAR(&NAME) TYPE(*CHAR) LEN(10)
DCL VAR(&CONTENT) TYPE(*CHAR) LEN(256)
/* Mainline: */
RTVDTAARA DTAARA(&NAME) RTNVAR(&CONTENT)
END: ENDPGM
****************** End of data*********************************
Here is the code fragment from Visual Basic that uses the CL program:
Sub Get_DataArea_Click ()
Prog$ = "DATAAREA"
Value$ = text2.Text 'DATAAREA NAME
Rem Define the parameters to pass and receive
Ret% = Lce3GLDefineParameter(SessId%, 0, 0, "P", "A", 10, 0, Value$)
Value$ = String(256, 0)
Ret% = Lce3GLDefineParameter(SessId%, 1, 0, "R", "A", 256, 0, Value$)
Rem Call the 3GL program
Ret% = Lce3GLCall(SessId%, Prog$, "*LIBL", 1)
Rem Retrieve the parameter returned from the 3GL program
Value$ = String(256, 0)
Ret% = Lce3GLGetValue(SessId%, 1, 0, Value$)
Label2.Caption = Value$
End Sub