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

BAPI_SALESORDER_CHANGE - Adding Partner Item

Former Member
0 Likes
1,815

Hi Gurus,

I'm having a problem when adding more than one item that have the same type of partner function.

I need to add to a sales order several items and each of them have the same type of partner function.

Each partner have a different address and after running the program, all partners have the address of the first partner added.

In debug mode in can see that the two structures (BAPIPARNR AND BAPIADDR1) have the correct data for each item.

Can anyone give me a clue off what can cause this behavior?

The code is this:

LOOP AT ti_dados INTO wa_dados.

MOVE: item TO t_itm-itm_number,

p_mat TO t_itm-material,

p_cen TO t_itm-plant,

p_dep TO t_itm-store_loc,

p_loc TO t_itm-ship_point.

MOVE: item TO t_itmx-itm_number,

'I' TO t_itmx-updateflag,

'X' TO t_itmx-material,

'X' TO t_itmx-plant,

'X' TO t_itmx-store_loc,

'X' TO t_itmx-ship_point.

APPEND: t_itm,

t_itmx.

MOVE: item TO t_schedule_l-itm_number,

'0001' TO t_schedule_l-sched_line,

quant TO t_schedule_l-req_qty.

MOVE: item TO t_schedule_lx-itm_number,

'I' TO t_schedule_lx-updateflag,

'0001' TO t_schedule_lx-sched_line,

'X' TO t_schedule_lx-req_qty.

APPEND: t_schedule_l,

t_schedule_lx.

"Trata de parceiros

t_partner-itm_number = item.

t_partner-partn_role = 'ZW'.

t_partner-PARTN_NUMB = 'A'.

t_partner-ADDR_LINK = 'ZW'.

t_partner-name = wa_dados-nome1.

t_partner-name_2 = wa_dados-nome2.

t_partner-street = wa_dados-rua1.

t_partner-postl_code = wa_dados-cod_postal.

t_partner-city = wa_dados-localidade.

t_partner-country = 'PT'.

t_partner-langu = 'P'.

APPEND t_partner.

t_partneradd-addr_no = 'ZW'.

t_partneradd-name = wa_dados-nome1.

t_partneradd-name_2 = wa_dados-nome2.

t_partneradd-street = wa_dados-rua1.

t_partneradd-str_suppl1 = wa_dados-rua2.

t_partneradd-house_no = wa_dados-nr.

t_partneradd-house_no2 = wa_dados-andar.

t_partneradd-postl_cod1 = wa_dados-cod_postal.

t_partneradd-city = wa_dados-localidade.

t_partneradd-adr_notes = wa_dados-cae.

t_partneradd-country = 'PT'.

t_partneradd-langu = 'P'.

APPEND t_partneradd.

ADD 10 TO item.

ENDLOOP.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

SALESDOCUMENT = p_ov

ORDER_HEADER_INX = t_order_header_inx

TABLES

RETURN = t_return

ORDER_ITEM_IN = t_itm

ORDER_ITEM_INX = t_itmx

PARTNERS = t_partner

PARTNERADDRESSES = t_partneradd

SCHEDULE_LINES = t_schedule_l

SCHEDULE_LINESX = t_schedule_lx.

READ TABLE t_return WITH KEY type = 'E'.

IF sy-subrc NE 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

ELSE.

LOOP AT t_return WHERE type EQ 'E'.

MESSAGE w000(zsd1) WITH t_return-message.

ENDLOOP.

EXIT.

ENDIF.

Thank you in advance!

Hi Gurus,

I'm having a problem when adding more than one item that have the same type of partner function.

I need to add to a sales order several items and each of them have the same type of partner function.

Each partner have a different address and after running the program, all partners have the address of the first partner added.

In debug mode in can see that the two structures (BAPIPARNR AND BAPIADDR1) have the correct data for each item.

Can anyone give me a clue off what can cause this behavior?

The code is this:

LOOP AT ti_dados INTO wa_dados.

MOVE: item TO t_itm-itm_number,

p_mat TO t_itm-material,

p_cen TO t_itm-plant,

p_dep TO t_itm-store_loc,

p_loc TO t_itm-ship_point.

MOVE: item TO t_itmx-itm_number,

'I' TO t_itmx-updateflag,

'X' TO t_itmx-material,

'X' TO t_itmx-plant,

'X' TO t_itmx-store_loc,

'X' TO t_itmx-ship_point.

APPEND: t_itm,

t_itmx.

MOVE: item TO t_schedule_l-itm_number,

'0001' TO t_schedule_l-sched_line,

quant TO t_schedule_l-req_qty.

MOVE: item TO t_schedule_lx-itm_number,

'I' TO t_schedule_lx-updateflag,

'0001' TO t_schedule_lx-sched_line,

'X' TO t_schedule_lx-req_qty.

APPEND: t_schedule_l,

t_schedule_lx.

"Trata de parceiros

t_partner-itm_number = item.

t_partner-partn_role = 'ZW'.

t_partner-PARTN_NUMB = 'A'.

t_partner-ADDR_LINK = 'ZW'.

t_partner-name = wa_dados-nome1.

t_partner-name_2 = wa_dados-nome2.

t_partner-street = wa_dados-rua1.

t_partner-postl_code = wa_dados-cod_postal.

t_partner-city = wa_dados-localidade.

t_partner-country = 'PT'.

t_partner-langu = 'P'.

APPEND t_partner.

t_partneradd-addr_no = 'ZW'.

t_partneradd-name = wa_dados-nome1.

t_partneradd-name_2 = wa_dados-nome2.

t_partneradd-street = wa_dados-rua1.

t_partneradd-str_suppl1 = wa_dados-rua2.

t_partneradd-house_no = wa_dados-nr.

t_partneradd-house_no2 = wa_dados-andar.

t_partneradd-postl_cod1 = wa_dados-cod_postal.

t_partneradd-city = wa_dados-localidade.

t_partneradd-adr_notes = wa_dados-cae.

t_partneradd-country = 'PT'.

t_partneradd-langu = 'P'.

APPEND t_partneradd.

ADD 10 TO item.

ENDLOOP.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

SALESDOCUMENT = p_ov

ORDER_HEADER_INX = t_order_header_inx

TABLES

RETURN = t_return

ORDER_ITEM_IN = t_itm

ORDER_ITEM_INX = t_itmx

PARTNERS = t_partner

PARTNERADDRESSES = t_partneradd

SCHEDULE_LINES = t_schedule_l

SCHEDULE_LINESX = t_schedule_lx.

READ TABLE t_return WITH KEY type = 'E'.

IF sy-subrc NE 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

ELSE.

LOOP AT t_return WHERE type EQ 'E'.

MESSAGE w000(zsd1) WITH t_return-message.

ENDLOOP.

EXIT.

ENDIF.

Thank you in advance!

6 REPLIES 6
Read only

Former Member
0 Likes
1,295

Hello

MOVE: item TO t_schedule_l-itm_number,

'0001' TO t_schedule_l-sched_line,

quant TO t_schedule_l-req_qty.

MOVE: item TO t_schedule_lx-itm_number,

'I' TO t_schedule_lx-updateflag,

'0001' TO t_schedule_lx-sched_line,

'X' TO t_schedule_lx-req_qty.

try counting the number of items added....and on sched_line and add 1 on each loop iteration

Hope this helps!!

gabriel P-.

Read only

Former Member
0 Likes
1,295
"Trata de parceiros
t_partner-itm_number = item.
t_partner-partn_role = 'ZW'.
t_partner-PARTN_NUMB = 'A'.
t_partner-ADDR_LINK = 'ZW'. 
t_partner-name = wa_dados-nome1.
t_partner-name_2 = wa_dados-nome2.
t_partner-street = wa_dados-rua1.
t_partner-postl_code = wa_dados-cod_postal.
t_partner-city = wa_dados-localidade.
t_partner-country = 'PT'.
t_partner-langu = 'P'.
APPEND t_partner.

t_partneradd-addr_no = 'ZW'.
t_partneradd-name = wa_dados-nome1.
t_partneradd-name_2 = wa_dados-nome2.
t_partneradd-street = wa_dados-rua1.
t_partneradd-str_suppl1 = wa_dados-rua2.
t_partneradd-house_no = wa_dados-nr.
t_partneradd-house_no2 = wa_dados-andar.
t_partneradd-postl_cod1 = wa_dados-cod_postal.
t_partneradd-city = wa_dados-localidade.
t_partneradd-adr_notes = wa_dados-cae.
t_partneradd-country = 'PT'.
t_partneradd-langu = 'P'.
APPEND t_partneradd.

LOOP AT ti_dados INTO wa_dados.

MOVE: item TO t_itm-itm_number,
p_mat TO t_itm-material,
p_cen TO t_itm-plant,
p_dep TO t_itm-store_loc,
p_loc TO t_itm-ship_point.

MOVE: item TO t_itmx-itm_number,
'I' TO t_itmx-updateflag,
'X' TO t_itmx-material,
'X' TO t_itmx-plant,
'X' TO t_itmx-store_loc,
'X' TO t_itmx-ship_point.

APPEND: t_itm,
t_itmx.

MOVE: item TO t_schedule_l-itm_number,
'0001' TO t_schedule_l-sched_line,
quant TO t_schedule_l-req_qty.

MOVE: item TO t_schedule_lx-itm_number,
'I' TO t_schedule_lx-updateflag,
'0001' TO t_schedule_lx-sched_line,
'X' TO t_schedule_lx-req_qty.

APPEND: t_schedule_l,
t_schedule_lx.

ADD 10 TO item.
ENDLOOP.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
SALESDOCUMENT = p_ov
ORDER_HEADER_INX = t_order_header_inx
TABLES
RETURN = t_return
ORDER_ITEM_IN = t_itm
ORDER_ITEM_INX = t_itmx
PARTNERS = t_partner
PARTNERADDRESSES = t_partneradd
SCHEDULE_LINES = t_schedule_l
SCHEDULE_LINESX = t_schedule_lx.

READ TABLE t_return WITH KEY type = 'E'.
IF sy-subrc NE 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ELSE.
LOOP AT t_return WHERE type EQ 'E'.
MESSAGE w000(zsd1) WITH t_return-message.
ENDLOOP.
EXIT.
ENDIF.

what i have done in the above code is written the logic to populate the partner structure above the loop since it remains the same.

inside the loop only populating item and the header details of the sales order.

Hope this was your query

Regards,

Lalit Mohan Gupta.

Read only

Former Member
0 Likes
1,295

Hi again,

My question is diferente, I don't want the same partner for all items added. In fact, each item has a diferent partner. The problem, I think is that they are all of the same type of function partner.

And when I insert the partner, the BAPI doesn't know what address from the structure BAPIADDR1 should use because the only key is the field addr_no, which is the same for all entries since its the function partner.

I hope I was more explicit.

Thank you.

Read only

Former Member
0 Likes
1,295

so you mean to say for different partner you have same address (addr_no).

Regards,

Lalit Mohan Gupta.

Read only

0 Likes
1,295

Hello,

No, the field addr_no isn't the address it self is the function partner of the partner that is being inserted.

The address is define in the other fields of the structure BAPIADDR1.

Regards,

Sandra Marques

Edited by: Sandra Maria Marques on Apr 15, 2009 10:24 AM

Read only

0 Likes
1,295

Increment the value "$1" in the addr_no field for each new address you want to create.

Item 10 - addr_no = $1

Item 20 - addr_no = $2

Item 30 - addr_no = $3