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

FUNCTION_CREATE

Former Member
0 Likes
684

Hi,

I have to create code dynamically at runtime. So I'm going to use the function 'FUNCTION_CREATE' .

Assume the FUNCTION-POOL Z_FYN_FUNC_TEST exists, but the pool is empty - no functions, no types ....

My code looks like:

DATA: include TYPE RS38L-INCLUDE,

          code     TYPE STANDARD TABLE OF char255.

"

" First time

"

CALL FUNCTION 'FUNCTION_CREATE'

  EXPORTING

    funcname = 'Z_FUNC1'

    function_pool = 'Z_FYN_FUNC_TEST'

    short_text = 'Lalala'

  IMPORTING

    function_include = include

  TABLES

    "

    " it doesn't matter, since the function does not receive any data or

    " create any data ...

    "

  .

  "

  "  Create code, so it looks like

  "

  "  FUNCTION Z_FUNC1.

  "  *"--

  "  *"--

  "    any_syntax_error_free_code

  "  ENDFUNCTION.

INSERT REPORT include FROM code.

"

" the call processes successfully

"

CALL FUNCTION 'Z_FUNC1'.

CLEAR code[].

"

" Second time

"

CALL FUNCTION 'FUNCTION_CREATE'

  EXPORTING

    funcname = 'Z_FUNC2'

    function_pool = 'Z_FYN_FUNC_TEST'

    short_text = 'Lalala'

  IMPORTING

    function_include = include

  TABLES

    "

    " it doesn't matter, since the function does not receive any data or

    " create any data ...

    "

  .

  "

  "  Create code, so it looks like

  "

  "  FUNCTION Z_FUNC2.

  "  *"--

  "  *"--

  "    any_syntax_error_free_code

  "  ENDFUNCTION.

INSERT REPORT include FROM code.

"

" Runtime error like The Function 'Z_FUNC2' could not be found "

CALL FUNCTION 'Z_FUNC2'.

Any idea ?

  Kind regards

  Ralf

4 REPLIES 4
Read only

Jelena_Perfiljeva
Active Contributor
0 Likes
594

At minimum you need to check for exceptions (sy-subrc). When I can't figure out how an FM should be called, I usually use 'where-used' and see how it's done in other programs.

Read only

Former Member
0 Likes
594

OK - I forgot to post in the code above the sy-subrc-check (this code is a reduced fragment). In both cases the function returns sy-subrc = 0, so the code should be inserted in the includes.

The behaviour is always the same. The first dynamically function runs successfully and the next created function-call fails  :-(((

  Kind regards

Read only

0 Likes
594

Hi,

The first function runs successfully, could you try to insert a WAIT UNTIL 2 SECONDS and then call the second function call. However how the second function returns SY-SUBRC = 0 and does not insert the code. Also include exceptions when you call the function 'FUNCTION_CREATE'.

Let me know if any info is required.

Thanks,

Tooshar Bendale

Read only

0 Likes
594

Hi,

this works fine - thank you !

  Kind regards

  Ralf