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

Calling Function Module RV_ORDER_FLOW_INFORMATION in a Loop!

Former Member
0 Likes
2,090

Hi Guys,

I need to fetch SD document Flow data into Bw for which I have created an Extractor using function modules. I am using a Standard FM "RV_ORDER_FLOW_INFORMATION" which is called in the LOOP as below.

LOOP AT VIT_VBRK INTO VFL_VBRK.

    CLEAR VBCO6.
    VBCO6-MANDT = SY-MANDT.
    VBCO6-VBELN = VFL_VBRK-VBELN.
    REFRESH TVBFA_TAB[].
    CLEAR TVBFA_TAB.

CALL FUNCTION 'RV_ORDER_FLOW_INFORMATION'
  EXPORTING
   AUFBEREITUNG        = '2'
   BELEGTYP            = VFL_VBRK-VBTYP
    COMWA               = VBCO6
   NACHFOLGER          = 'X'
   N_STUFEN            = '50'
   VORGAENGER          = 'X'
   V_STUFEN            = '50'
 IMPORTING
   BELEGTYP_BACK       = BELEG_TYP
  TABLES
    VBFA_TAB            = TVBFA_TAB
 EXCEPTIONS
   NO_VBFA             = 1
   NO_VBUK_FOUND       = 2
   OTHERS              = 3
          .
IF SY-SUBRC <> 0.
ENDIF.

*OTHER CODE LOGIC*

ENDLOOP.

Now the problem is if I run this only once, i.e VIT_VBRK having only 1 document, the result I get is correct. However, if this same code is run in a LOOP with many different values in VIT_VBRK, the first Loop gives correct values and all subsequent values (value of TVBFA_TAB- RFMNG to be precise) are incorrect.

I am guessing this is b'coz of some internal tables and work areas specific to the function module are not refreshed and the values of earlier iterations are adding up in the subsequent runs. can any one tell me if theres any specific 'REFRESH' statement or FM to be called before calling this FM.

Thanks in Advance,

Parth Shah.

5 REPLIES 5
Read only

Former Member
0 Likes
1,389

Hi,

Variables / Internal tables defined inside the FM is local to the FM and they get clear automatically once the FM execution is over

ie, once the variable become out of scope it is cllected by the garbage collector.

Coming to your case you can try wait upto 2 seconds statment after the FM execution is over, I also do not know the exact logic why it works but in my experiance I have solved some of the similar issue using this .

Cheers

Bikas

Read only

matt
Active Contributor
0 Likes
1,389

>

> Hi,

>

> Variables / Internal tables defined inside the FM is local to the FM and they get clear automatically once the FM execution is over

> ie, once the variable become out of scope it is cllected by the garbage collector.

This is only true if the variable is declared locally. Function groups may well have globally defined variables. Function modules can have globally defined parameters. Some function modules might rely on values EXPORTED to memory or written to a table.

Go to the function module. Use menu goto->global data. Then you'll see what's perhaps not being reset between calls.

You could run your program in two sessions - debug the function module in one session in the first call, and in the second in the second call. Then see what the differences are. If you find that a variable is not being reset, you could do a whereused on the variable, and perhaps find a function module, parameter or subroutine (callable externally) which resets the variable.

However, it may be that the function module simply isn't designed to be run more than once.

You might consider then launching it in its own session (IN NEW TASK). Maybe wrapping it in your own function module.

matt

Read only

0 Likes
1,389

Hi Matt,

I debugged the Function module like u said in 2 different Session, what I found was that there is a yet another function module called with in the FM RV_ORDER_FLOW_INFORMATION, i.e "GET_HANDLE_SD_DOCUMENTFLOW_SP" heres what the code in this FM looks like.

FUNCTION GET_HANDLE_SD_DOCUMENTFLOW_SP.
*"----------------------------------------------------------------------
*"Lokale Schnittstelle:
*"  EXPORTING
*"     REFERENCE(HANDLE) TYPE REF TO  IF_EX_BADI_SD_DOCUMENTFLOW
*"     VALUE(ACTIVE) TYPE  XFELD
*"----------------------------------------------------------------------

IF L_HANDLE_SD_DOCUMENTFLOW IS INITIAL.
    CALL METHOD CL_EXITHANDLER=>GET_INSTANCE
      IMPORTING
        ACT_IMP_EXISTING = BADI_SD_DOCUMENTFLOW_ACTIVE
      CHANGING
        INSTANCE         = L_HANDLE_SD_DOCUMENTFLOW
        EXCEPTIONS
        OTHERS           = 1.
    IF NOT SY-SUBRC = 0.
      CLEAR BADI_SD_DOCUMENTFLOW_ACTIVE.
    ENDIF.
  ENDIF.
  HANDLE = L_HANDLE_SD_DOCUMENTFLOW.
  ACTIVE = BADI_SD_DOCUMENTFLOW_ACTIVE.

ENDFUNCTION.

the only difference I found in the two sessions was that L_HANDLE_SD_DOCUMENTFLOW is initial in the first run and then in all subsequent run its value remains the same, while in fact it should reset. Sadly there is no REFRESH procedure / Subroutine for it.

Any idea how i can refresh it, or may be by-pass this check (IF L_HANDLE_SD_DOCUMENTFLOW IS INITIAL) ?

Edited by: shahparth on Feb 17, 2011 8:39 AM

Read only

matt
Active Contributor
0 Likes
1,389

This function module only gets a reference to implementation of the BADI BADI_SD_DOCUMENTFLOW. It's unlikely to be causing your problem.

However, the BADI might possibly be. Check for implementations of the BADI - see if they're persisting any data.

matt

Read only

Former Member
0 Likes
1,389

Hi,

I am not sure whether this will help or not can you please check the where used list of the Function Module I guess you will see the program RKEPCR00 where this function module is called inside the LOOP statment. May be you can call in the way they did and proceed with your logic.

Regards,

SRinivas