Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to call a C function?

Former Member
0 Likes
1,202

Hello,

I'd like to call a C function in my ABAP code. The fuction is located in a DLL file. Is that possible?

Thanks,

Aline

3 REPLIES 3
Read only

jayakummar
Active Participant
0 Likes
767

hai,

plz give some clear details to reply...

jai.m

Read only

Former Member
0 Likes
767

Hi,

Check this and if found Useful dont forget to assign points.

CALL - Calling a Method in OLE2 Automation

CALL METHOD OF obj m.

Extras:

1. ... = f

2. ... EXPORTING p1 = f1 ... pn = fn

3. ... NO FLUSH

4. ... QUEUE-ONLY

Effect

Calls the method m of object obj. m can be a literal or a variable.

Normally, all consecutive OLE statements are buffered by the ABAP processor and sent to the presentation server in bundled form. This means that it is possible for a statement to refer to the results of preceding statements.

In debugging, however, you should remember that the values of the return parameters cannot be displayed until directly before execution of the first ABAP statement external to OLE.

Even a command which refers to an object not yet generated by any OLE statement terminates the bundling.

The return code value of SY-SUBRC indicates whether all the bundled commands have been successfully executed.

The Return Code is set as follows:

SY-SUBRC = 0:

All commands were successfully executed.

SY-SUBRC = 1:

When communicating with the presentation

server, a system error occurred. The system

field SY-MSGLI contains a short

description of the error.

SY-SUBRC = 2:

A method call resulted in an error.

SY-SUBRC = 3:

Setting a property resulted in an error.

SY-SUBRC = 4:

Reading a property resulted in an error.

In the last 3 cases, a dialog box containing an error note is displayed on the presentation server.

CALL METHOD belongs to a group of key words that allows you to process external objects with ABAP/4. At present, only the object model OLE2 is supported, i.e. all objects must be of type OLE2_OBJECT. This type and other necessary data are defined in the include program OLE2INCL.

Addition 1

... = f

Effect

The return value of the method is placed in the variable f. It may itself have the type OLE2_OBJECT. This addition must always occur before the other additions.

Addition 2

... EXPORTING p1 = f1 ... pn = fn

Effect

Passes values from fields to the parameters of the method. p1, p2... are either keyword parameters or position parameters.

If the parameter assignment is by position, p1, p2, ... must begin with '#', followed by the position number of the parameter. Currently, only position parameters are supported.

The export parameters must always occur at the end of the statement.

Addition 3

... NO FLUSH

The addition NO FLUSH continues the collection process, even if the next command is not an OLE statement. This means that you can set a series of properties in a loop and download them to the presentation server in a single transport operation.

If you do not use NO FLUSH, you must ensure that you do not rely on the contents of return parameters not yet filled.

Also, all objects must be initialized in a bundle, i.e. they must be generated by an OLE call that has already been executed.

Every FREE statement always causes a download of the buffer.

Addition 4

... QUEUE-ONLY

Effect

If the CALL METHOD call has return values, they can be used by subsequent automation commands within the queue. However, thy will not be written back into the corresponding ABAP variables under the following conditions:

1.) If the queue only contains CREATE OBJECT, CALL METHOD, and GET PROPERTY calls with return values and the addition QUEUE-ONLY.

2.) If the flush mode is deactivated in the Debugger.

Using this addition does not mean that you do not have to call FREE OBJECT to destroy front end objects returned with CALL METHOD. If you do not, you may encounter memory shortages or terminations of the application.

Example

Openning an EXCEL file using the 'Open' method.

TYPE-POOLS OLE2.

DATA EXCEL TYPE OLE2_OBJECT.

DATA WORKBOOK TYPE OLE2_OBJECT.

CREATE OBJECT EXCEL 'Excel.Application'.

CALL METHOD OF EXCEL 'Workbooks' = WORKBOOK.

CALL METHOD OF WORKBOOK 'Open' EXPORTING #1 = 'C:\EX1.XLS'.

Read only

Former Member
0 Likes
767

Jaya,

I have a DLL file called CardShellU.dll. Inside that file is a function that reads some data from our card readers at our computers. I need that data in the User Exit SUSR0001.

Bhupal,

thanks for your tip, but I don't know how I can integrate my DLL into that code. Could you explain it a bit further please?