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: 

BAPI_CONTRACT_CHANGE doesn't work

former_member780881
Participant
0 Kudos
2,308

Hi guys ;

I have a question about ME32K. When ı enter transaction via purchase document number to me32k. I see a lot of item.

Example; When i enter the program and i select just item_no "9810" and "9870" , program will delete flag just 9810 and 9870 in ME32K. The picture is like that;

First of ; ı use to BAPI_CONTRACT_GET_DETAIL bapi and ı get all of item_no and details for my Purchase document.

After ı use to BAPI_CONTRACT_CHANGE bapi . But nothing gonna be changed.

My code part like this basically ;

call function 'BAPI_CONTRACT_GETDETAIL'
exporting
purchasingdocument = ld_purchasingdocument
item_data = 'X'
condition_data = 'X'
importing
header = ld_header
tables
item = it_item
item_condition = t_item_condition_s
return = t_return
.
commit work and wait .
check sy-subrc eq 0.

read table t_item_condition_s index 1.
read table t_item_cond_validity index 1.

t_item_cond_validityx-serial_id = t_item_condition_s-serial_id.
t_item_cond_validityx-item_no = 9810.

append t_item_cond_validityx.

t_item_condition-item_no = 9810.
t_item_condition-deletion_ind = 'X'.
t_item_condition-serial_id = t_item_condition_s-serial_id.
t_item_condition-cond_count = t_item_condition_s-cond_count.
t_item_condition-change_id = 'U'.
append t_item_condition.
t_item_conditionx-item_no = 9810.
t_item_conditionx-serial_id = t_item_condition_s-serial_id.
t_item_conditionx-cond_count = t_item_condition_s-cond_count.
t_item_conditionx-cond_value = 'X'.
append t_item_conditionx.
call function 'BAPI_CONTRACT_CHANGE'
exporting
purchasingdocument = ld_purchasingdocument
tables
item = it_item
item_condition = t_item_condition
item_conditionx = t_item_conditionx
return = t_return.
.
commit work and wait.
check sy-subrc eq 0.
10 REPLIES 10

SimoneMilesi
Active Contributor
1,976

Hello,

did you check your return table?

former_member780881
Participant
0 Kudos
1,976

Actually, i didn' t check my return table. I check that items in ME32k and ME3M after when i run bapi_contract_change and i get sy-subrc eq 0. After my control in that transaction, i saw nothing change

SimoneMilesi
Active Contributor
1,976

Well, first step is to check return table: it contains all the messages (informative, warnings, errors and so on).

I'm not sure about this piece of code, because it looks to me you are adding flag/removing flag.

t_item_cond_validityx-serial_id = t_item_condition_s-serial_id.
t_item_cond_validityx-item_no = 9810.

append t_item_cond_validityx.

t_item_condition-item_no = 9810.
t_item_condition-deletion_ind = 'X'.
t_item_condition-serial_id = t_item_condition_s-serial_id.
t_item_condition-cond_count = t_item_condition_s-cond_count.
t_item_condition-change_id = 'U'.
append t_item_condition.
t_item_conditionx-item_no = 9810.
t_item_conditionx-serial_id = t_item_condition_s-serial_id.
t_item_conditionx-cond_count = t_item_condition_s-cond_count.
t_item_conditionx-cond_value = 'X'.
append t_item_conditionx.


Why are you passing t_item_conditionx-cond_value = 'X'. ?

former_member780881
Participant
0 Kudos
1,976

Hi Simone;

:Why are you passing t_item_conditionx-cond_value = 'X'. ?

Because when i search about this bapi , some developer use like this and he get success. So ı used to.

Actually ; I just want to put a deletion mark in the specific area I specified in the picture.

SimoneMilesi
Active Contributor
0 Kudos
1,976

Hello!
Before putting flags, it's better to understand what they do 🙂
The 'X' on ...X structures are usually used to tell the system which field you want to update: in your case, you are not trying to update the value, correct?

You are passing

 t_item_condition-deletion_ind = 'X'.

so you have to fill the corresponding

 t_item_conditionX-deletion_ind = 'X'.

Get rid of useless lines like

 t_item_cond_validityx-serial_id = t_item_condition_s-serial_id.
t_item_cond_validityx-item_no = 9810.

append t_item_cond_validityx.

because they mean nothing then try in the following way

  t_item_condition-item_no = 9810.
t_item_condition-deletion_ind = 'X'.
t_item_condition-serial_id = t_item_condition_s-serial_id.
t_item_condition-cond_count = t_item_condition_s-cond_count.
t_item_condition-change_id = 'U'.
append t_item_condition.
t_item_conditionx-item_no = 9810.
t_item_conditionx-serial_id = t_item_condition_s-serial_id.
t_item_conditionx-cond_count = t_item_condition_s-cond_count.
t_item_conditionx-deletion_ind = 'X'.
append t_item_conditionx.

And check the table returns to see if you have any error and rollback the work or commit if all ok.

former_member780881
Participant
0 Kudos
1,976

Thanks your comment and attention 🙂

What is your suggest code piece for solving problem ?

SimoneMilesi
Active Contributor
0 Kudos
1,976

With my last reply you should be able to delete 1 condition on item 9810.

If you want to delete the item you have to work with ITEM table instead of ITEM_CONDITION

former_member780881
Participant
0 Kudos
1,976

I tried item table in bapi but i guess , i didn't get result.

So ı guess ; according to your comment;

when i define to item_no = 9819 and put to delete_ind = 'X' in item table

i can get result; ????

 call function 'BAPI_CONTRACT_CHANGE'
exporting
purchasingdocument = ld_purchasingdocument
tables
item = it_item
return = t_return.
commit work and wait.
check sy-subrc eq 0.

thanks for your help 🙂

SimoneMilesi
Active Contributor
0 Kudos
1,976

Hello,

As thumb rule, BAPIs that change data (like this one) usually (there are exceptions!!!) rely on tables working in couples.

In your case, you have ITEM and ITEMX:

  • in table ITEM, you add rows you want to change with the values you want to update (in your case the deletion flag)
  • in table ITEMX, you add rows you are changing (the same in table rows, passing the key aka ITEM_NO) and for each row you fill the corresponding field you are updating with an 'X'

They have the same field list, if you check, but, as i explained in my previous replies, the...X table's fields are all flags, key fields apart, and they are used to tell the system which fields you are updating.

So, no, your example is not working because you are invoking the BAPI without ITEMX table.

former_member780881
Participant
0 Kudos
1,976

Thanks to your comment simone.milesi

(As thumb rule, BAPIs that change data (like this one) usually (there are exceptions!!!) rely on tables working in couples.

In your case, you have ITEM and ITEMX:

  • in table ITEM, you add rows you want to change with the values you want to update (in your case the deletion flag)
  • in table ITEMX, you add rows you are changing (the same in table rows, passing the key aka ITEM_NO) and for each row you fill the corresponding field you are updating with an 'X'

They have the same field list, if you check, but, as i explained in my previous replies, the...X table's fields are all flags, key fields apart, and they are used to tell the system which fields you are updating.

So, no, your example is not working because you are invoking the BAPI without ITEMX table.)

My Problem is solved thanks to you.