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_CONTRACT_CHANGE fails to update validity in A016

Former Member
0 Kudos

Dear All,

i implemented the source as follows. However, though my return parameters declares the bapi steps to be successful, there is no update in a016-datbi, as it is intended to be.

Can you tell me, what i do wrong?

>>>>

report z_b_upm002.

tables: a016.

data: wa_a016 type a016,

t_016 type standard table of a016,

item_cond_validity like bapimeoutvalidity occurs 0 with header line,

item_cond_validityx like bapimeoutvalidityx occurs 0 with header line,

h_return like bapiret2 occurs 0 with header line.

selection-screen begin of block sel with frame title text-sel.

select-options: s_evrtn for a016-evrtn default '4600001066' obligatory,

s_evrtp for a016-evrtp.

parameters: p_bis type datum default sy-datum.

parameters: p_commit as checkbox default 'X'.

selection-screen end of block sel.

start-of-selection.

select * from a016 into table t_016 where evrtn in s_evrtn and evrtp in s_evrtp.

loop at t_016 into wa_a016.

write: / wa_a016-evrtn, at 20 wa_a016-evrtp, at 55 wa_a016-datbi, '=>', p_bis, ' -> '.

item_cond_validity-item_no = wa_a016-evrtp.

item_cond_validity-serial_id = wa_a016-knumh.

item_cond_validity-valid_to = p_bis.

item_cond_validity-valid_from = wa_a016-DATAB.

append item_cond_validity.

move-corresponding item_cond_validity to item_cond_validityx.

item_cond_validityx-valid_to = 'X'.

item_cond_validityx-valid_from = 'X'.

append item_cond_validityx.

call function 'BAPI_CONTRACT_CHANGE'

exporting

purchasingdocument = wa_a016-evrtn

  • HEADER =

  • HEADERX =

  • VENDOR_ADDRESS =

  • TESTRUN =

  • TECHNICAL_DATA =

  • IMPORTING

  • EXP_HEADER =

tables

  • ITEM =

  • ITEMX =

  • ACCOUNT =

  • ACCOUNTPROFITSEGMENT =

  • ACCOUNTX =

  • DELIVERY_ADDRESS =

item_cond_validity = item_cond_validity

item_cond_validityx = item_cond_validityx

  • ITEM_CONDITIONX =

  • ITEM_COND_SCALE_VALUE =

  • ITEM_COND_SCALE_QUAN =

  • ITEM_TEXT =

  • HEADER_TEXT =

  • HEAD_COND_VALIDITY =

  • HEAD_COND_VALIDITYX =

  • HEAD_CONDITION =

  • HEAD_CONDITIONX =

  • HEAD_COND_SCALE_VAL =

  • HEAD_COND_SCALE_QUAN =

  • PARTNER =

  • PARTNERX =

  • RELEASE_DOCU =

  • EXTENSIONIN =

  • EXTENSIONOUT =

return = h_return

.

write: /.

loop at h_return.

case: h_return-type.

when 'S'. write: 'Success'.

when 'E'. write: 'Error'.

when 'W'. write: 'Warning'.

when 'I'. write: 'Info'.

when 'A'. write: 'Abort'.

endcase.

write: h_return-message.

endloop.

clear: item_cond_validity, item_cond_validityx, h_return.

refresh: item_cond_validity, item_cond_validityx, h_return.

if p_commit = 'X'.

call function 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'

importing

return = h_return.

.

skip.

if sy-subrc = 0. write 'Commit OK'. else. write: 'Fehlerim Commit'. endif.

loop at h_return.

case: h_return-type.

when 'S'. write: 'Success'.

when 'E'. write: 'Error'.

when 'W'. write: 'Warning'.

when 'I'. write: 'Info'.

when 'A'. write: 'Abort'.

endcase.

write: h_return-message.

endloop.

clear: h_return. refresh: h_return.

endif.

skip 2.

endloop.

Regards Ralf

5 REPLIES 5

Former Member
0 Kudos

hi

did you get the answer?

if yes please share with me.

I am also having similar problem.

Actually I want to add/delete/change some conditions from the existing item and want to add conditions for newly added items in the contracts/scheduling agreement. The bapi BAPI_CONTRACT_CHANGE is not giving any error, error is coming at the time of commit_bapi as "Update was terminated as user........" like this.

waiting for your reply.

bye

0 Kudos

Hi,

You can go to SM13 Transaction Code and see all the

update termination and find out the reasons for the

particular one by double clicking it and find out the

error from there and change accordingly

thanks

karthik

Former Member
0 Kudos

Hi Ralf,

in the BAPI 'BAPI_TRANSACTION_COMMIT', wait is optional parameter, if you want to pass the value, it shoud be space or

X. if it set to X then it will we equal to COMMIT WORK AND WAIT command

it takes some time to update the data in DB. try to put wait to space.

try the below code.

if p_commit = 'X'.

call function 'BAPI_TRANSACTION_COMMIT'

endif.

Regards,

Boobalan Suburaj

Former Member
0 Kudos

Hello Together,

the following source implements BAPI_CONTRACT_CHANGE correctly. You must fill the following parameters:

call function 'BAPI_CONTRACT_CHANGE'

exporting

purchasingdocument = h_evrtn

tables

item = item

itemx = itemx

item_cond_validity = item_cond_validity

item_cond_validityx = item_cond_validityx

item_condition = item_condition

item_conditionx = item_conditionx

return = h_return.

You must especially consider:

item_condition-change_id = 'U'.

Here is the full coding:

>>>>>>>>>>>>>>>>>>

report z_b_upm002.

*Dieses Programm updatet die Gültigkeitszeiträume der Kontrakte (ME32K) entsprechend der parametrisierten Einkaufsbelegnummer A068 gibt die werksabhängige Vertragspositionen an, A016 ohne Werksbezug.

*Bei badenova gibt's keine werksabhängigen Vertragspositionen.

*Das Programm passt Gültigkeitszeiträume von Einkaufskontrakten entsprechend des SAP-BAPIs 'BAPI_CONTRACT_CHANGE' entsprechend der Benutzereingaben an.

*Im Eingabebildschirm wird hierzu das Range von Einkaufsbelegen mit Positionen abgefragt. Das mit dem Tagesdatum bevorschlagte Bezugsdatum, greift für die selektierten Kontrakte die betreffende Gültigkeitszeitscheibe heraus.

*Das 'Gültig-Bis'-Datum der betreffenden Zeitscheiben sämtlicher ermittelten Kontrakte, werden mit dem im Eingabebildschirm mitgegebenen gewünschten Datum überschrieben. Durch das Customizing ist ausgesteuert, das damit auch das Preisdatum auf das

*gewünschte datum aktualisiert wird.

*Beim Ändern der Zeitdaten werden neue Positionssätze in der Tabelle A016 geschrieben.

*Das Programm ersetzt die manuelle Tätigkeit in der Transaktion ME32K und kann mit dieser Transaktion auch nachvollzogen werden.

*

tables: a016.

data:

wa_a016 type a016, "Kontraktposition

wa_konp type konp, "Konditionen (Position)

t_016 type table of a016,

item_cond_validity like bapimeoutvalidity occurs 0 with header line,

item_cond_validityx like bapimeoutvalidityx occurs 0 with header line,

item like bapimeoutitem occurs 0 with header line,

itemx like bapimeoutitemx occurs 0 with header line,

item_condition like bapimeoutcondition occurs 0 with header line,

item_conditionx like bapimeoutconditionx occurs 0 with header line,

h_return like bapiret2 occurs 0 with header line.

data: h_evrtn_old type ebeln,

h_evertp_old type ebelp.

selection-screen begin of block sel with frame title text-sel.

select-options: s_evrtn for a016-evrtn default '4600000680' obligatory,

s_evrtp for a016-evrtp default '0020'.

parameters: p_bis type datum obligatory,

p_akt type datum default sy-datum.

parameters: p_commit as checkbox default 'X'.

selection-screen end of block sel.

start-of-selection.

select * from a016 into table t_016 where evrtn in s_evrtn and evrtp in s_evrtp

and datbi >= p_akt and datab <= p_akt.

sort t_016 by evrtn ascending evrtp ascending knumh descending.

loop at t_016 into wa_a016.

if h_evrtn_old <> wa_a016-evrtn and not h_evrtn_old is initial.

write: ' -> Bapi aufgerufen'.

perform bapi_gueltigkeit using h_evrtn_old.

perform bapi_refresh.

endif.

h_evrtn_old = wa_a016-evrtn.

  • in die BAPI Parameter nur die Werte für den jüngsten Konditionssatz mitaufnehmen

if wa_a016-evrtp <> h_evertp_old.

write: / wa_a016-kschl, at 10 wa_a016-evrtn, at 30 wa_a016-evrtp, at 75 wa_a016-datbi, '=>', p_bis, at 110 wa_a016-datab, at 130 wa_a016-knumh, 'in BAPIparam. aufgenommen'.

  • ITEM_COND_VALIDITY

  • Der Parameter ITEM_COND_VALIDITY enthält die Gültigkeitszeiträume für

  • Konditionen zu Rahmenvertragspositionen; dies entspricht den Tabellen

  • A016 und A068. Das Feld ITEM_NO enthält die Positionsnummer (EBELP) der

  • zugehörigen Position des Rahmenvertrags. Das Feld SERIAL_ID dient als

  • eindeutiger Schlüssel, um mehrere Konditionszeiträume abbilden zu

  • können.

  • Wenn es sich um werksabhängige Konditionen handelt, ist das Feld PLANT

  • gefüllt (entspricht Tabelle A068); ansonsten ist es leer (entspricht

  • Tabelle A016).

  • Zu einem Eintrag in ITEM_COND_VALIDITY können mehrere Einträge in der

  • Tabelle ITEM_CONDITION gehören; letztere werden über die Felder ITEM_NO

  • und SERIAL_ID an den Eintrag in Tabelle ITEM_COND_VALIDITY verknüpft.

  • Das Feld COND_COUNT dient zur eindeutigen Identifizierung von

  • Konditionspositionen.

  • ITEM_NOX BAPIUPDATE CHAR 1 0 Änderungsinformation zum zugehörigen Nutzdatenfeld muss mit 'X' versehen werden,

  • ausserdem muss ITEM_CONDITION(X) befüllt werden, hier ist wichtig dass ITEM_CONDITION-CHANGE_ID = 'U' befüllt wird, weil beim Ändern von Konditionen neue Konditionssätze geschrieben werden

item_cond_validity-item_no = wa_a016-evrtp.

item_cond_validity-serial_id = wa_a016-knumh.

item_cond_validity-valid_to = p_bis.

item_cond_validity-valid_from = wa_a016-datab.

append item_cond_validity.

move-corresponding item_cond_validity to item_cond_validityx.

clear: item_cond_validityx-valid_from.

item_cond_validityx-valid_to = 'X'.

item_cond_validityx-item_nox = 'X'.

item_cond_validityx-serial_idx = 'X'.

append item_cond_validityx.

move-corresponding item_cond_validity to item.

append item.

move-corresponding item_cond_validity to itemx.

itemx-item_nox = 'X'.

append itemx.

move-corresponding item_cond_validity to item_condition.

select * from konp into corresponding fields of wa_konp

where knumh = wa_a016-knumh.

add 1 to item_condition-cond_count.

item_condition-cond_type = wa_konp-kschl.

item_condition-cond_value = wa_konp-kbetr.

item_condition-currency = wa_konp-konwa.

item_condition-change_id = 'U'.

append item_condition.

endselect.

move-corresponding item_cond_validity to item_conditionx.

move-corresponding item_condition to item_conditionx.

item_conditionx-item_nox = 'X'.

item_conditionx-serial_idx = 'X'.

item_conditionx-cond_countx = 'X'.

item_conditionx-cond_type = 'X'.

item_conditionx-cond_value = 'X'.

item_conditionx-currency = 'X'.

append item_conditionx.

endif. "wa_a016-evrtp <> h_evertp_old.

h_evertp_old = wa_a016-evrtp.

endloop.

if not h_evrtn_old is initial.

write: ' -> Bapi aufgerufen'.

perform bapi_gueltigkeit using wa_a016-evrtn.

perform bapi_refresh.

endif.

end-of-selection.

*&----


*

*& Form BAPI_GUELTIGKEIT

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

form bapi_gueltigkeit using h_evrtn.

call function 'BAPI_CONTRACT_CHANGE'

exporting

purchasingdocument = h_evrtn

tables

item = item

itemx = itemx

item_cond_validity = item_cond_validity

item_cond_validityx = item_cond_validityx

item_condition = item_condition

item_conditionx = item_conditionx

return = h_return.

write: /.

loop at h_return.

case: h_return-type.

when 'S'. write: 'Success'.

when 'E'. write: 'Error'.

when 'W'. write: 'Warning'.

when 'I'. write: 'Info'.

when 'A'. write: 'Abort'.

endcase.

write: h_return-message.

endloop.

clear: item_cond_validity, item_cond_validityx, h_return.

refresh: item_cond_validity, item_cond_validityx, h_return.

if p_commit = 'X'.

call function 'BAPI_TRANSACTION_COMMIT'

  • EXPORTING

  • WAIT = 'X'

importing

return = h_return.

.

skip.

if sy-subrc = 0. write 'Commit OK'. else. write: 'Fehlerim Commit'. endif.

loop at h_return.

case: h_return-type.

when 'S'. write: 'Success'.

when 'E'. write: 'Error'.

when 'W'. write: 'Warning'.

when 'I'. write: 'Info'.

when 'A'. write: 'Abort'.

endcase.

write: h_return-message.

endloop.

clear: h_return. refresh: h_return.

endif.

skip 2.

endform. " BAPI_GUELTIGKEIT

*&----


*

*& Form BAPI_REFRESH

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

form bapi_refresh .

clear: item, itemx, item_cond_validity, item_cond_validityx, item_condition, item_conditionx.

refresh: item, itemx, item_cond_validity, item_cond_validityx, item_condition, item_conditionx.

clear: h_evertp_old.

write: 'BAPI Parameters refreshed'. skip 2.

endform. " BAPI_REFRESH

周建华
Participant
0 Kudos

BAPI_CONTRACT_CHANGE fails to update validity in A016