2013 Jan 14 10:48 AM
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
2013 Jan 14 10:03 PM
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.
2013 Jan 15 8:57 AM
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
2013 Jan 15 9:41 AM
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
2013 Jan 23 7:58 AM