Application Development 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: 

BAPI returns old values

Former Member
0 Kudos

Hi,

I'm using FM HU_PER_DOCUMENT_READ to read all handling units

from outbound delivery.

I run this FM several times in my ABAP code (without exiting from

the program) and I get wrong values - even if I modify delivery and HUs

in a separate session.

The FM returns "updated" values only after I exit the program and run the

program again.

I have noticed that this FM also returns "not updated" values when tested

in SE37. I can run it several times - but it always returns old values if

I change outbound delivery in the meantime.

It returns updated and correct values when I exit SE37 and run it again.

This is for me very strange since this FM does not modifies any object so

I think I should not use COMMIT or something like this. Instead - I think

I should clear some buffors but after several hours of searching - I still

haven't found a solution.

Here's my code. As you see I try to clear all variables, tables before

calling FM. Yet, FM returns old values.

DATA: it_objects   TYPE hum_object_t.
DATA: wa_objects   LIKE LINE OF it_objects.

DATA: et_highest   TYPE hum_venum_t.
DATA: et_headerTYPE hum_hu_header_t.
DATA: wa_headerTYPE vekpvb.

DATA: et_item  TYPE hum_hu_item_t.
DATA: et_history   TYPE hum_history_t.
DATA: et_messages  TYPE huitem_messages_t.

DATA: wa_item  TYPE VEPOVB.

DATA: et_item_temp  TYPE hum_hu_item_t.
DATA: wa_item_temp  TYPE VEPOVB.

CLEAR it_objects[].
CLEAR it_objects.
CLEAR wa_objects.

CLEAR et_highest.
CLEAR et_header.
CLEAR et_item.
CLEAR et_history.
CLEAR et_messages.

CLEAR et_highest[].
CLEAR et_header[].
CLEAR et_item[].
CLEAR et_history[].
CLEAR et_messages[].

wa_objects-object = '01'.
wa_objects-objkey =  <fs>-sd_vbeln.
APPEND wa_objects TO it_objects.


CALL FUNCTION 'HU_PER_DOCUMENT_READ'
   EXPORTING
     it_objects = it_objects
   IMPORTING
     it_objects  = it_objects
     et_highest  = et_highest
     et_header   = et_header
     et_item = et_item
     et_history  = et_history
     et_messages = et_messages
   EXCEPTIONS
     error  = 01
     others = 99.

Best regards,

Kordian

1 ACCEPTED SOLUTION

Former Member
0 Kudos

The problem is connected with two global tables GT_XVEKP and GT_XVEPO

initialized by the function module and not cleared after FM is executed.

They get cleared when you exit your program but once you use this FM

they exists and are not cleared. And because they are not being cleared -

this FM always returns the same results - even if HU are added / deleted

in outbound delivery.

These tables should be cleared before or after executing this function module.

However, this tables does not exists if the FM has not been executed therefore

I clear them just after calling FM. Clearing these tables "after" ensures that these

tables exists and there is no error with field symbol assigning.

CALL FUNCTION 'HU_PER_DOCUMENT_READ'
EXPORTING
it_objects = it_objects
IMPORTING
it_objects  = it_objects
et_highest  = et_highest
et_header   = et_header
et_item= et_item
et_history  = et_history
et_messages = et_messages
EXCEPTIONS
error = 01
others= 99.

*clear GT_XVEKP and GT_XVEPO so when next time HU_PER_DOCUMENT_READ
*executed it will return updated results
FIELD-SYMBOLS: <fs_gt_xvekp> TYPE ANY.
FIELD-SYMBOLS: <fs_gt_xvepo> TYPE ANY.

ASSIGN ('(SAPLV51P)GT_XVEKP[]') TO <fs_gt_xvekp>.
ASSIGN ('(SAPLV51P)GT_XVEPO[]') TO <fs_gt_xvepo>.

CLEAR <fs_gt_xvekp>.
CLEAR <fs_gt_xvepo>.

Please note, that there is no problem if you use this FM in your code only once.

However - if you use it several times (for example after refreshing ALV) and you

change HUs - the FM will return old values.

This problem is also described very well here but with different solution

http://zevolving.com/2012/12/think-sap-is-bug-free-not-really/

In my opinion this problem applies to FMs in function group V51E

(at least HU_PER_DOCUMENT_READ and HU_GET_HUS)

Keywords: HU_PER_DOCUMENT_READ, HU_GET_HUS, NOT UPDATED VALUES,

ET_ITEM, ET_HEADER, ET_HIGHEST, ET_HISTORY, ET_MESSAGES

Best regards,

Kordian

1 REPLY 1

Former Member
0 Kudos

The problem is connected with two global tables GT_XVEKP and GT_XVEPO

initialized by the function module and not cleared after FM is executed.

They get cleared when you exit your program but once you use this FM

they exists and are not cleared. And because they are not being cleared -

this FM always returns the same results - even if HU are added / deleted

in outbound delivery.

These tables should be cleared before or after executing this function module.

However, this tables does not exists if the FM has not been executed therefore

I clear them just after calling FM. Clearing these tables "after" ensures that these

tables exists and there is no error with field symbol assigning.

CALL FUNCTION 'HU_PER_DOCUMENT_READ'
EXPORTING
it_objects = it_objects
IMPORTING
it_objects  = it_objects
et_highest  = et_highest
et_header   = et_header
et_item= et_item
et_history  = et_history
et_messages = et_messages
EXCEPTIONS
error = 01
others= 99.

*clear GT_XVEKP and GT_XVEPO so when next time HU_PER_DOCUMENT_READ
*executed it will return updated results
FIELD-SYMBOLS: <fs_gt_xvekp> TYPE ANY.
FIELD-SYMBOLS: <fs_gt_xvepo> TYPE ANY.

ASSIGN ('(SAPLV51P)GT_XVEKP[]') TO <fs_gt_xvekp>.
ASSIGN ('(SAPLV51P)GT_XVEPO[]') TO <fs_gt_xvepo>.

CLEAR <fs_gt_xvekp>.
CLEAR <fs_gt_xvepo>.

Please note, that there is no problem if you use this FM in your code only once.

However - if you use it several times (for example after refreshing ALV) and you

change HUs - the FM will return old values.

This problem is also described very well here but with different solution

http://zevolving.com/2012/12/think-sap-is-bug-free-not-really/

In my opinion this problem applies to FMs in function group V51E

(at least HU_PER_DOCUMENT_READ and HU_GET_HUS)

Keywords: HU_PER_DOCUMENT_READ, HU_GET_HUS, NOT UPDATED VALUES,

ET_ITEM, ET_HEADER, ET_HIGHEST, ET_HISTORY, ET_MESSAGES

Best regards,

Kordian