Skip to Content
0

Inline declaration with function module.

Jul 18, 2017 at 08:45 AM

1.8k

avatar image
Former Member

Try as I might, I just don't seem to be able to get an inline decaration to work for what seems like a fairly simple function module. Here's the code:

 CALL FUNCTION 'MATERIAL_READ_PLANTS'
 EXPORTING
 MATNR = ls_matnr-matnr
 TABLES
 PLANTS = DATA(lt_plants).

I get the message The inline declaration "DATA(LT_PLANTS)" is not possible in this position.

Can anyone be of help as to the correct format, if at all possible.

I have also tried using "@DATA(lt_plants)" as well. But did not really expect that to work.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Horst Keller
Jul 18, 2017 at 09:09 AM
3

Since a call of a function module is always "dynamic", the compiler doesn't know the parameter type and an inline declaration is not possible.

Show 5 Share
10 |10000 characters needed characters left characters exceeded

Thanks for the explanation, I always wondered why FMs were 'left out' of some of the newer features. But then I must wonder: if something as lowly as an editor can figure out the parameter's type, why can't the compiler?

0

For the compiler,

CALL FUNCTION 'FUNC' ...

is the same as

DATA func TYPE string VALUE `FUNC`.
CALL FUNCTION func ...

It doesn't look into the data object that denotes the function module. Only tools like SLIN or "where use list" (that's what you mean with editor) look into literals.

In the recent ABAP Docu, this is clearly pointed out at that and similar operand positions.

It is different for a static method call, where you do not use literals.

0

By editor I meant Eclipse, pressing F2 on any parameter shows the type, and quick fix can declare it for you.

I understand the dynamic nature, but it just seems like a bit of a relic. I can't think of any reason why it shouldn't look into the function module name. If the function name is a quoted literal, deal with it the same way as

call method foo.

If it's a data element, treat it the same as

call method (foo).

0

And rise syntax errors if the function module doesn't exist or parameters do not match?

No, it's too late for that.

One of the reasons, one should use methods if possible.

0

Exactly! I guess warnings would be more appropriate so as not to break the existing code base (although...).

But it should still not prevent things like inline declaration for quoted literal function modules. It's just a strange gap from a developer's perspective.

0
Mike Pokraka Jul 18, 2017 at 09:08 AM
2

The syntax is correct, but is not supported for some of the older constructs, including function modules.

https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abendeclaration_positions.htm

If you are using Eclipse, just write a variable name and do a quick fix to automatically add the declaration before the call.

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jul 25, 2017 at 11:56 AM
0

I have not checked this again to confirm, but from memory I'm sure this worked when using the FM's export/import parmeters, just not with table. But I'll confirm this.

Share
10 |10000 characters needed characters left characters exceeded