How to Call a LANSA Function from a 3GL

Date: 29 November 2004
Product/Release: LANSA for iSeries
Abstract: Calling a LANSA Function from a 3GL
Submitted By: LANSA Technical Support
Last Review: November 2010


How to call a LANSA function from a C program (3GL) in LANSA for Windows and LANSA for iSeries.


Depending on the platform of execution, there are 2 ways of calling a LANSA function from a 3GL:

Calling a LANSA function from a 3GL on iSeries

  1. There is a document available on request from LANSA regarding calling LANSA processes and functions from CL or RPG. It is titled 'Direct Calling of LANSA Functions' and has sample source codes in RPG that can achieve what you want. You can still use the RPG program, however, as stated below, you will need to call the RPG program via your C program.

    Also note that the basic information in the sample source code applies equally to calling from C programs.
  2. Using the sample program [email protected] as a basis, create an RPG program (say MYCALL) that calls the required LANSA function. There are many variations on this (see following details headed 'Variations').
  3. Call MYCALL from the C program. To do this you need to use the normal C compiler options that indicate that you want to call an RPG program.

For example:

You need standard C pragmas:

#pragma map(MyProgramCall, "MYCALL")
#pragma linkage(MyProgramCall, OS, nowiden)

You need a prototype:

void MyProgramCall (void);

You need to make the call in you code:


Note: See the documentation for what to change in order to call a particular function and also how to pass parameters.


  1. If you have many different functions to call then change MYCALL to receive the name of the LANSA function to be called as a parameter from the C program as a char 7 value:

    You need a different C prototype:

    void MyProgramCall (char *);

    You need to make the call passing the 7 character function name (actually 8 in length with the terminator):

    MyProgramCall("F001 ");
  2. If you need to make lots of calls back and forwards change MYCALL to be reentrant (i.e.: do not set on LR) and avoid repeating the relatively expensive calls [email protected] and [email protected] every time MYCALL is invoked. You would only need to make these calls the first time MYCALL is invoked.
  3. Passing data structures, lists and using the exchange list are all possible. Refer to the documentation in the OSU guide for the exact details.

Calling a LANSA function from a 3GL on Windows

You need to use the system() api or CreateProcess() api to call X_RUN with appropriate parameters as documented in LANSA documentation.

User parameters can be passed in a file (TRANSFORM_FILE BIF) or through registry (GET_REGISTRY_VALUE BIF).

For information purposes: Version 11.0 has a new parameter – UDEF - so it can be passed on the command line. This can be queried from RDML using GET_SESSION_VALUE.