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

Update the forwarding agents using bapi_salesorder_change

0 Likes
739

Hi all,

Inside a report, I am using a FM bapi_salesorder_change to update the partner details at header level, here it is adding the forwarding agent,

there are no errors returned in return table, however there are no entry of forwarding there in SO..

Any suggestion for this case on how to update the forwarding agent in SO?

Here is the sample code:

LOOP AT i_sale WHERE purch_no_c = it_ref-ebeln AND shipto = it_ref-kunnr
AND mseg = space.

READ TABLE i_vbpa WITH KEY vbeln = vbeln.
IF sy-subrc = 0.
lwa_part-document = vbeln.
* part-ITM_NUMBER = i_sale-po_itm_no.
lwa_part-updateflag = 'U'.
lwa_part-partn_role = 'SP'.
lwa_part-p_numb_old = i_vbpa-lifnr.
lwa_part-p_numb_new = i_sale-fright.
"APPEND part.
APPEND lwa_part TO lt_part.

ENDIF.
ENDLOOP.
order_header_inx-updateflag = 'U'.
salesdocument = vbeln.

.
SORT lt_part BY document updateflag partn_role p_numb_old p_numb_new.

DELETE ADJACENT DUPLICATES FROM lt_part.

DESCRIBE TABLE lt_part LINES lv_lines.

IF lv_lines > 1.
CLEAR lwa_part.
CLEAR lt_part.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = i_sale-shipto
IMPORTING
output = l_kunnr.
*Fecth forwarding agent from CMD
SELECT lifnr
FROM knvp
UP TO 1 ROWS
INTO lwa_part-p_numb_old
WHERE kunnr = l_kunnr
AND vkorg = i_sale-sales_org
AND vtweg = i_sale-distr_chan
AND spart = i_sale-division
AND parvw = k_sp.
ENDSELECT.

IF sy-subrc = 0.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = lwa_part-p_numb_old
IMPORTING
output = lwa_part-p_numb_new.

lwa_part-updateflag = 'U'.
lwa_part-partn_role = 'SP'.

APPEND lwa_part TO lt_part.
ELSE.
CLEAR lwa_part.
CLEAR lt_part.

ENDIF.

ENDIF.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = salesdocument
order_header_inx = order_header_inx
TABLES
return = return
partnerchanges = lt_part.

Hi all,

Inside a report, I am using a FM bapi_salesorder_change to update the partner details at header level, here it is adding the forwarding agent,

there are no errors returned in return table, however there are no entry of forwarding there in SO..

Any suggestion for this case on how to update the forwarding agent in SO?

Here is the sample code:

LOOP AT i_sale WHERE purch_no_c = it_ref-ebeln AND shipto = it_ref-kunnr
AND mseg = space.

READ TABLE i_vbpa WITH KEY vbeln = vbeln.
IF sy-subrc = 0.
lwa_part-document = vbeln.
* part-ITM_NUMBER = i_sale-po_itm_no.
lwa_part-updateflag = 'U'.
lwa_part-partn_role = 'SP'.
lwa_part-p_numb_old = i_vbpa-lifnr.
lwa_part-p_numb_new = i_sale-fright.
"APPEND part.
APPEND lwa_part TO lt_part.

ENDIF.
ENDLOOP.
order_header_inx-updateflag = 'U'.
salesdocument = vbeln.

.
SORT lt_part BY document updateflag partn_role p_numb_old p_numb_new.

DELETE ADJACENT DUPLICATES FROM lt_part.

DESCRIBE TABLE lt_part LINES lv_lines.

IF lv_lines > 1.
CLEAR lwa_part.
CLEAR lt_part.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = i_sale-shipto
IMPORTING
output = l_kunnr.
*Fecth forwarding agent from CMD
SELECT lifnr
FROM knvp
UP TO 1 ROWS
INTO lwa_part-p_numb_old
WHERE kunnr = l_kunnr
AND vkorg = i_sale-sales_org
AND vtweg = i_sale-distr_chan
AND spart = i_sale-division
AND parvw = k_sp.
ENDSELECT.

IF sy-subrc = 0.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = lwa_part-p_numb_old
IMPORTING
output = lwa_part-p_numb_new.

lwa_part-updateflag = 'U'.
lwa_part-partn_role = 'SP'.

APPEND lwa_part TO lt_part.
ELSE.
CLEAR lwa_part.
CLEAR lt_part.

ENDIF.

ENDIF.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = salesdocument
order_header_inx = order_header_inx
TABLES
return = return
partnerchanges = lt_part.

1 REPLY 1
Read only

VXLozano
Active Contributor
0 Likes
656

First of all, the CODE tag is your friend (and ours). Please, try to edit your message and put your code within a code tag.

Are you sure your update flag must be U if you are creating a new partner?