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 module Global variables not cleared from memory?

former_member194669
Active Contributor
0 Likes
4,661

Hi,

This is may be simple & stupid question ( after posting 4242 posts ):)


" Declaration in TOP
data : begin of i_y1yatt occurs 0.
        include structure y1yatt.
data : end of i_y1yatt.

types: begin of t_yatt71.
       include structure yatt71.
types: tcode like sy-tcode.
types: dflag type c.
types: end of t_yatt71.

data : i_yatt71 type standard table of t_yatt71
               with default key  with header line  initial size 0.

This is code in the function module.


  loop at i_y1yatt.
    move-corresponding o_y1yatt to i_yatt71.
    ....
    ....
    if i_y1yatt-werks eq 'N501'.
       move space to i_yatt71-werks.
    endif. 
    append i_yatt71.  
    " Here this internal contains the previous entry
    clear i_yatt71.

  endloop.

This function module is called 25 times in a minute.

My problem is this

For example : 1st tranmission is called this fm with 50 records,

and 2nd tranmission is called fm with 10 records.

My results are showing

last record in the 1st transmission is still on the memory while calling 2nd transmission. ( Here in int table I_YATT71 still contains the 1st transmission's last records during the 2nd tranmission call)

As per my knowledge if each time calls comes in to fm all gloabl variables get cleared. but some how this not happening.

Anybody come across this scenario.

PS. I know i need to use clear statement within the loop as first statement.

a®

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
2,239

You must understand that when calling a FM, you load the entire function group into memory. IF there are global variables, then they are "alive" for the entire duration of the program execution. Meaning if you call the function numerious times, or even if you call another function within the same function group, the functions still have access to that same global variable space, so it must always be cleared manually by the developer at the required points. You can not rely on the runtime to clear the global variables at the end of the function call. So you should clear all you globals as the first operation in your function module call, if that is what is required.

Is this clear?

Regards,

Rich Heilman

6 REPLIES 6
Read only

Former Member
0 Likes
2,239

>Anybody come across this scenario.

>PS. I know i need to use clear statement within the loop as first statement.

I too faced the similar problem. I just used the Clear statement in the beginning of the Function call.

If you see the IDOC function they will first initialize all the global vairables and proceed.

I will tell you the function name..

Read only

0 Likes
2,239

Vijay,

Thanks for your reply.

It will be strange that we need to clear the int tables (declared in global area) I know the if a variable declared in global area, can be available to other function modules in same function group.

but here the transmission are coming 2 different intervals of time difference of 3 to 6 micro seconds.

if the 2nd tranmission comes whether the global variables will not get cleared?

a®

Read only

0 Likes
2,239

>

> if the 2nd tranmission comes whether the global variables will not get cleared?

>

you have to clear them in the beginning. other wise you will see wrong results in case where you don't find the data for the selection, but still it show the data in the internal tables or variables.

so it is always advisable to clear in the beginning itself.

Read only

Former Member
0 Likes
2,239

Function

IDOC_INPUT_ORDERS

and the form you see in the beginning

* SET/GET Parameter und interne Tabellen neu initialisieren
* initialize SET/GET Parameter and internal tables
    PERFORM initialize_organizational_data.

Read only

RichHeilman
Developer Advocate
Developer Advocate
2,240

You must understand that when calling a FM, you load the entire function group into memory. IF there are global variables, then they are "alive" for the entire duration of the program execution. Meaning if you call the function numerious times, or even if you call another function within the same function group, the functions still have access to that same global variable space, so it must always be cleared manually by the developer at the required points. You can not rely on the runtime to clear the global variables at the end of the function call. So you should clear all you globals as the first operation in your function module call, if that is what is required.

Is this clear?

Regards,

Rich Heilman

Read only

0 Likes
2,239

Rich/Vijay,

Thanks for reply.

a®