1

I try to create simple function module but I have this error which says

the statement "function" is not allowed in the current environment. However, the similar statement "function-pool" is allowed

Thank you.

enter image description here

Suncatcher
  • 10,355
  • 10
  • 52
  • 90

1 Answers1

2

A function module always has to be part of a function pool ("Funktionsgruppe" in German). A function pool is a special kind of program that begins with the statement FUNCTION-POOL, consists of multiple includes and follows certain conventions. The development environment tries to hide this, but is not too successful with abstracting this away completely. Which is why you might get errors like that if you do something wrong with those includes.

The structure of a function pool called "ZMYGROUP" is like this:

SAPLZMYGROUP (the master include of the function pool)
  LZMYGROUPTOP (the "FUNCTION-POOL" declaration. Should also include any other global declaration)
  LZMYGROUPUXX (the include that includes the includes for each function module)
     LZMYGROUPU01 - first function module
     LZMYGROUPU02 - second function module
     LZMYGROUPU03 - third function module
     ...and so on...
  LZMYGROUPF00 - Local FORM subroutines used internally by the function modules
  LZMYGROUPP00 - Implementation of local classes used internally by the function modules
  LZMYGROUPT00 - ABAP Unit Tests
  LZMYGROUPI00 - Dynpro input modules 
  LZMYGROUPO00 - Dynpro output modules 

You usually don't need to build any of that structure yourself. It should all be generated automatically when you create and activate a new function pool and then add stuff to it. But you can build it manually, and you can also break it if you make manual changes to it. So that's something you might want to check on.

The usual workflow when creating a function module with a new function pool is:

  1. Create the function pool
  2. Activate the function pool
  3. Create the function module
  4. Activate the function module
  5. Implement the code of the function module

So when you can't find out what exactly is wrong with your function pool, then I recommend to just delete everything and start from scratch using this procedure.

Philipp
  • 67,764
  • 9
  • 118
  • 153