I am call BAPI BAPI_SALESORDER_CHANGE to update sales order and need to changed the edatu at item level, the return of the BAPI is that the sales order is changed but no changes are made.
i am committing after calling the BAPI BAPI BAPI_SALESORDER_CHANGE but changes are not impacting in the database.
ls_header_x-updateflag = 'U'.
assign ls_schdl to <schdl>.
assign ls_schdlx to <schdlx>.
assign ls_items to <items2>.
assign ls_itemsx to <items2x>.
<schdl>-itm_number = '000010'.
<schdlx>-itm_number = '000010'.
<schdl>-sched_line = '0001'.
<schdlx>-sched_line = '0001'.
<items2>-itm_number = '000010'.
<items2x>-itm_number = '000010'.
<schdlx>-itm_number = '000010'.
<schdl>-dlv_date = '20181111'.
append <schdl> to lt_schdl.
<schdlx>-dlv_date = 'U'.
<schdlx>-updateflag = 'U'.
append <schdlx> to lt_schdlx.
<items2x>-updateflag = 'U'.
append <items2> to lt_items.
append <items2x> to lt_itemsx.
*update the data
call function 'BAPI_SALESORDER_CHANGE'
exporting
salesdocument = p_vbeln
order_header_inx = ls_header_x
tables
order_item_in = lt_items
order_item_inx = lt_itemsx
return = lt_return
schedule_lines = lt_schdl
schedule_linesx = lt_schdlx.
read table lt_return assigning <return> with key type = 'E'.
if sy-subrc ne 0.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'
importing
return = ls_return.
endif.
You need to fill order_item_inx and schedule_linesx item fields with 'X'. Other values ignored.
Related
I have the following scenario:
I am using BAPI BAPI_BUPR_RELATIONSHIP_CHANGE to change validuntildate. (BUT050-DATE_TO / BUT051-DATE_TO).
But I also need to update field BUT051-PAFKT and a custom field in BUT050 (lets call it ZZFIELD).
I do this by updating BUT050 / BUT051 from internal tables.
At the end, if I write COMMIT WORK or call FM BAPI_TRANSACTION_COMMIT, only the fields from BAPI_BUPR_RELATIONSHIP_CHANGE will be updated. If I do not write anything at the end, only the field from UPDATE FROM TABLE will be updated.
How can I update all my fields?
Are there any BAPI that can allow me to modify BUT051-PAFKT and custom fields from BUT050 ?
Sample code for testing:
DATA: lt_return TYPE bapiret2_t,
lv_kunnr TYPE kunnr VALUE '111',
lv_partner TYPE bu_partner VALUE '222',
lv_rel_cat TYPE bu_reltyp VALUE 'BUR001',
lv_new_date TYPE sy-datum VALUE '20300101',
lt_but051 TYPE TABLE OF but051.
CALL FUNCTION 'BAPI_BUPR_RELATIONSHIP_CHANGE'
EXPORTING
businesspartner1 = lv_kunnr
businesspartner2 = lv_partner
relationshipcategory = lv_rel_cat
validfromdate = sy-datum
validuntildate = sy-datum
validuntildatenew = lv_new_date
datetox = abap_true
TABLES
RETURN = lt_return.
SELECT *
FROM but051
INTO TABLE lt_but051
WHERE partner1 = lv_kunnr
AND partner2 = lv_partner
AND reltyp = lv_rel_cat.
LOOP AT lt_but051 ASSIGNING FIELD-SYMBOL(<ls_but051>).
<ls_but051>-pafkt = '0003'.
ENDLOOP.
UPDATE but051 FROM TABLE lt_but051.
COMMIT WORK.
Try this (or its wrapper BAPI_BUPR_CONTP_CHANGE):
DATA: ls_person TYPE bapibus1006_central_person.
DATA: ls_person_x TYPE bapibus1006_central_person_x.
DATA: ls_central TYPE bapibus1006_central.
DATA: ls_central_x TYPE bapibus1006_central_x.
DATA: lt_return TYPE bapiret2_t.
is_data-function = '0001'. "<-- your PAFKT
is_data_x-function = abap_true.
* changes of the central data
CALL FUNCTION 'BUPR_CONTP_CHANGE'
EXPORTING
iv_partner = is_data-partner1
* IV_PARTNER_GUID =
iv_contactperson = is_data-partner2
* IV_CONTACTPERSON_GUID =
* IV_DATE_FROM =
* IV_DATE_TO =
* IV_DEFAULTRELATIONSHIP =
* IV_DEFAULTRELATIONSHIP_X =
is_data = is_data-data
is_data_x = is_data_x-central
* IV_TESTRUN = ' '
TABLES
et_return = lt_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = abap_true.
Also check my answer about updating relations and the corresponding note.
Regarding the custom field in BUT050, you can't just add a new field and update it, you need to change the BOL model.
I need to remove the batch number (LIPS-CHARG) on the delivery item and tried with BAPI_OUTB_DELIVERY_CHANGE without success.
I can change the delivery quantity (LIPS-LFIMG) correctly with this BAPI and change the picking number (LIPS-PKIMG) with WS_DELIVERY_UPDATE_2, but can't remove the batch number.
Does someone already remove the batch number? Don't need to use this BAPI, can be another one. I just need to remove the batch in any way.
The following code works to change the delivery quantity and picking quantity. At a certain moment, I change picking quantity to zero and at this moment I need to remove the batch number.
"&**** Begin structures BAPI_OUTB_DELIVERY_CHANGE *******
ls_header_data-deliv_numb = p_vbeln.
ls_header_control-deliv_numb = p_vbeln.
APPEND INITIAL LINE TO lt_item_data ASSIGNING FIELD-SYMBOL(<ls_item_data>).
<ls_item_data>-deliv_numb = p_vbeln.
<ls_item_data>-deliv_item = lv_posnn.
<ls_item_data>-material = <ls_alv>-matnr.
<ls_item_data>-batch = <ls_alv>-charg.
<ls_item_data>-hieraritem = <ls_lips>-posnr.
<ls_item_data>-usehieritm = '1'.
<ls_item_data>-dlv_qty = lv_delivery_qtd. "my delivery quantity
<ls_item_data>-dlv_qty_imunit = lv_delivery_qtd. "my delivery quantity
<ls_item_data>-fact_unit_nom = <ls_lips>-umvkz.
<ls_item_data>-fact_unit_denom = <ls_lips>-umvkn.
<ls_item_data>-sales_unit = <ls_lips>-vrkme.
APPEND INITIAL LINE TO lt_item_control ASSIGNING FIELD-SYMBOL(<ls_item_control>).
<ls_item_control>-deliv_numb = p_vbeln.
<ls_item_control>-deliv_item = lv_posnn.
<ls_item_control>-chg_delqty = 'X'.
"&**** End structures BAPI_OUTB_DELIVERY_CHANGE *******
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'
EXPORTING
header_data = ls_header_data
header_control = ls_header_control
delivery = p_vbeln
TABLES
item_data = lt_item_data
item_control = lt_item_control
return = lt_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
"&**** Begin structures WS_DELIVERY_UPDATE_2 *******
APPEND INITIAL LINE TO lt_vbpok ASSIGNING FIELD-SYMBOL(<ls_vbpok>).
<ls_vbpok>-vbeln_vl = <ls_lips>-vbeln.
<ls_vbpok>-posnr_vl = <ls_lips>-posnr.
<ls_vbpok>-vbeln = <ls_lips>-vgbel.
<ls_vbpok>-posnn = <ls_lips>-vgpos.
<ls_vbpok>-matnr = <ls_lips>-matnr.
<ls_vbpok>-werks = <ls_lips>-werks.
<ls_vbpok>-umvkz = <ls_lips>-umvkz.
<ls_vbpok>-umvkn = <ls_lips>-umvkn.
<ls_vbpok>-gewei = <ls_lips>-gewei.
<ls_vbpok>-charg = <ls_alv>-charg.
<ls_vbpok>-pikmg = lv_picking_qtd. "my picking quantity
ls_vbkok-vbeln_vl = <ls_lips>-vbeln.
ls_vbkok-vbtyp_vl = 'J'.
ls_vbkok-komue = 'X'.
ls_vbkok-gewei = <ls_lips>-gewei.
ls_vbkok-anzpk = lv_anzpk.
ls_vbkok-kzapk = 'X'.
"&**** End structures WS_DELIVERY_UPDATE_2 *******
CALL FUNCTION 'WS_DELIVERY_UPDATE_2'
EXPORTING
vbkok_wa = ls_vbkok
delivery = p_vbeln
synchron = abap_true
update_picking = abap_true
nicht_sperren_1 = abap_true
commit = abap_false
if_error_messages_send = abap_false
IMPORTING
ef_error_any = ls_error-any
ef_error_in_item_deletion = ls_error-in_item_deletion
ef_error_in_pod_update = ls_error-in_pod_update
ef_error_in_interface = ls_error-in_interface
ef_error_in_goods_issue = ls_error-in_goods_issue
ef_error_in_final_check = ls_error-in_final_check
ef_error_partner_update = ls_error-partner_update
ef_error_sernr_update = ls_error-sernr_update
TABLES
vbpok_tab = lt_vbpok.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
I found my error!
When we need to remove the batch number, we don't need to send value on ITEM_DATA-DELIV_ITEM.
In my code, I was sending '90000001' on ITEM_DATA-DELIV_ITEM and '00010' on ITEM_DATA-USEHIERITM, but to work I just send ITEM_DATA-USEHIERITM and the batch number was removed correctly.
Thanks all!
I am using the class CL_GUI_ALV_GRID and a dynpro screen to display an internal table via the ALV tool.
In my selection screen I have a dropdown list where the user can choose a layout variant for the displayed internal table. The layout variants are stored in the table LTDX.
Now, back to my question, how can I display the variants depending on the selection of the user?
You supply in the initial set_table_for_first_display method the is_variant parameter:
DATA: ls_variant TYPE disvariant.
CLEAR: ls_variant.
ls_variant-report = sy-repid.
ls_variant-variant = pa_varid. "<<< this is the name of the variant
CALL METHOD gro_alv100->set_table_for_first_display
EXPORTING
is_variant = ls_variant
...
EDIT: okay you did not accept the simple answer, so I will add the manual alternative:
FORM set_variant USING ps_variant TYPE disvariant.
DATA: lf_user_specific TYPE char1,
ls_stable TYPE lvc_s_stbl VALUE 'XX'.
CHECK ps_variant-variant IS NOT INITIAL.
lf_user_specific = boolc( ps_variant-variant(1) <> '/' ).
CALL FUNCTION 'LVC_VARIANT_SELECT'
EXPORTING
i_dialog = space
i_user_specific = lf_user_specific
i_default = space
it_default_fieldcat = gt_fcat
IMPORTING
et_fieldcat = gt_fcat
et_sort = gt_sort
et_filter = gt_filter
TABLES
it_data = gt_outtab
CHANGING
cs_variant = ps_variant
EXCEPTIONS
wrong_input = 1
fc_not_complete = 2
not_found = 3
program_error = 4
data_missing = 5
OTHERS = 6.
IF sy-subrc <> 0.
ENDIF.
gro_alv100->set_variant( EXPORTING is_variant = ps_variant ).
gro_alv100->set_frontend_fieldcatalog( EXPORTING it_fieldcatalog = gt_fcat ).
gro_alv100->set_sort_criteria( EXPORTING it_sort = gt_sort ).
gro_alv100->set_filter_criteria( EXPORTING it_filter = gt_filter ).
gro_alv100->refresh_table_display( EXPORTING is_stable = ls_stable i_soft_refresh = abap_false ).
ENDFORM.
I get an exception raised after posting gl account data to bapi_incominginvoice_create1.
This is my gl account data:
DATA : it_glacnt TYPE STANDARD TABLE OF bapi_incinv_create_gl_account,
wa_glacnt TYPE bapi_incinv_create_gl_account.
wa_glacnt-invoice_doc_item = '000002'.
wa_glacnt-gl_account = '0000400100'.
wa_glacnt-item_amount = '100.0000'.
wa_glacnt-db_cr_ind = 'H'.
wa_glacnt-comp_code = '010'.
wa_glacnt-item_text = 'Test TEXT'.
* wa_glacnt-sdoc_item = '0'.
wa_glacnt-bus_area = 'TMKK'.
wa_glacnt-alloc_nmbr = v_scanid.
APPEND wa_glacnt TO it_glacnt .
CLEAR wa_glacnt.
CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE1'
EXPORTING
headerdata = wa_miro_header
IMPORTING
invoicedocnumber = v_invno
fiscalyear = v_miroyr
TABLES
itemdata = it_miro_item
taxdata = it_miro_tax
glaccountdata = it_glacnt
withtaxdata = it_withtax
return = it_ret.
IF NOT v_invno IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
ENDIF.
I want to post this amount to gl account but when I execute, I get this exception:
It looks like records are not found in EKPO (purchasing document item) table. Generally, invoice posting needs PO records.
My requirement is change sales order item details.
For this i am using BAPI_SALESOPDER_CHANGE.
For one line item it is working fine.
Sales order which contains two line items, for line item 10 its updating quantity but for 20 line item it updates with random vale.
SO which contains three items it shows exception.
My code is here:
DATA: SALESDOCUMENT TYPE BAPIVBELN-VBELN.
DATA: LT_ORDER_HEADER_INX TYPE TABLE OF BAPISDH1X,
LS_ORDER_HEADER_INX TYPE BAPISDH1X.
DATA: LT_ORDER_ITEM_IN TYPE TABLE OF BAPISDITM,
LS_ORDER_ITEM_IN TYPE BAPISDITM.
DATA: LT_ORDER_ITEM_INX TYPE TABLE OF BAPISDITMX,
LS_ORDER_ITEM_INX TYPE BAPISDITMX.
DATA: LT_SCHEDULE_LINES TYPE TABLE OF BAPISCHDL,
LS_SCHEDULE_LINES TYPE BAPISCHDL.
DATA: LT_SCHEDULE_LINESX TYPE TABLE OF BAPISCHDLX,
LS_SCHEDULE_LINESX TYPE BAPISCHDLX.
DATA: LT_RETURN TYPE TABLE OF BAPIRET2,
LS_RETURN TYPE BAPIRET2.
PARAMETERS: p_sonum TYPE BAPIVBELN-VBELN.
LS_ORDER_HEADER_INX-UPDATEFLAG = 'U'.
LS_ORDER_ITEM_IN-ITM_NUMBER = 10.
LS_ORDER_ITEM_IN-TARGET_QTY = 22.
APPEND LS_ORDER_ITEM_IN TO LT_ORDER_ITEM_IN.
clear: LS_ORDER_ITEM_IN.
LS_ORDER_ITEM_IN-ITM_NUMBER = 20.
LS_ORDER_ITEM_IN-TARGET_QTY = 33.
APPEND LS_ORDER_ITEM_IN TO LT_ORDER_ITEM_IN.
clear: LS_ORDER_ITEM_IN.
LS_ORDER_ITEM_IN-ITM_NUMBER = 30.
LS_ORDER_ITEM_IN-TARGET_QTY = 44.
APPEND LS_ORDER_ITEM_IN TO LT_ORDER_ITEM_IN.
clear: LS_ORDER_ITEM_IN.
LS_ORDER_ITEM_INX-ITM_NUMBER = 10.
LS_ORDER_ITEM_INX-UPDATEFLAG = 'U'.
LS_ORDER_ITEM_INX-TARGET_QTY = 'X'.
APPEND LS_ORDER_ITEM_INX TO LT_ORDER_ITEM_INX.
clear:LS_ORDER_ITEM_INX.
LS_ORDER_ITEM_INX-ITM_NUMBER = 20.
LS_ORDER_ITEM_INX-UPDATEFLAG = 'U'.
LS_ORDER_ITEM_INX-TARGET_QTY = 'X'.
APPEND LS_ORDER_ITEM_INX TO LT_ORDER_ITEM_INX.
clear:LS_ORDER_ITEM_INX.
LS_ORDER_ITEM_INX-ITM_NUMBER = 30.
LS_ORDER_ITEM_INX-UPDATEFLAG = 'U'.
LS_ORDER_ITEM_INX-TARGET_QTY = 'X'.
APPEND LS_ORDER_ITEM_INX TO LT_ORDER_ITEM_INX.
clear:LS_ORDER_ITEM_INX.
LS_SCHEDULE_LINES-ITM_NUMBER = 10.
LS_SCHEDULE_LINES-SCHED_LINE = 1.
LS_SCHEDULE_LINES-REQ_QTY = 22.
APPEND LS_SCHEDULE_LINES TO LT_SCHEDULE_LINES.
clear:LS_SCHEDULE_LINES.
LS_SCHEDULE_LINES-ITM_NUMBER = 20.
LS_SCHEDULE_LINES-SCHED_LINE = 2.
LS_SCHEDULE_LINES-REQ_QTY = 33.
APPEND LS_SCHEDULE_LINES TO LT_SCHEDULE_LINES.
clear:LS_SCHEDULE_LINES.
LS_SCHEDULE_LINES-ITM_NUMBER = 30.
LS_SCHEDULE_LINES-SCHED_LINE = 3.
LS_SCHEDULE_LINES-REQ_QTY = 44.
APPEND LS_SCHEDULE_LINES TO LT_SCHEDULE_LINES.
clear:LS_SCHEDULE_LINES.
LS_SCHEDULE_LINESX-ITM_NUMBER = 10.
LS_SCHEDULE_LINESX-SCHED_LINE = 1.
LS_SCHEDULE_LINESX-UPDATEFLAG = 'U'.
LS_SCHEDULE_LINESX-REQ_QTY = 'X'.
APPEND LS_SCHEDULE_LINESX TO LT_SCHEDULE_LINESX.
CLEAR: LS_SCHEDULE_LINESX.
LS_SCHEDULE_LINESX-ITM_NUMBER = 20.
LS_SCHEDULE_LINESX-SCHED_LINE = 2.
LS_SCHEDULE_LINESX-UPDATEFLAG = 'U'.
LS_SCHEDULE_LINESX-REQ_QTY = 'X'.
APPEND LS_SCHEDULE_LINESX TO LT_SCHEDULE_LINESX.
CLEAR: LS_SCHEDULE_LINESX.
LS_SCHEDULE_LINESX-ITM_NUMBER = 30.
LS_SCHEDULE_LINESX-SCHED_LINE = 3.
LS_SCHEDULE_LINESX-UPDATEFLAG = 'U'.
LS_SCHEDULE_LINESX-REQ_QTY = 'X'.
APPEND LS_SCHEDULE_LINESX TO LT_SCHEDULE_LINESX.
CLEAR: LS_SCHEDULE_LINESX.
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = p_sonum
order_header_inx = LS_ORDER_HEADER_INX
TABLES
return = LT_RETURN
ORDER_ITEM_IN = LT_ORDER_ITEM_IN
ORDER_ITEM_INX = LT_ORDER_ITEM_INX
SCHEDULE_LINES = LT_SCHEDULE_LINES
SCHEDULE_LINESX = LT_SCHEDULE_LINESX .
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
Please make sure, that the line item numbers you are passing to the BAPI are with leading zeros.
In addition to adding leading zeros, I think the line item numbers are 1,2,3 not 10,20,30 try running the code with single number increments. And also post the result of lt_return if it does not work.
The schedule lines are tied to the order lines so they should start renumbering per order item.
So, in your example all lines like
LS_SCHEDULE_LINES-SCHED_LINE = ???.
and
LS_SCHEDULE_LINESX-SCHED_LINE = ???.
should be
LS_SCHEDULE_LINES-SCHED_LINE = 1.
and
LS_SCHEDULE_LINESX-SCHED_LINE = 1.