cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI_SALESORDER_CHANGE - Add forwarding agent

Former Member
0 Kudos

Hi,

I am using the bapi BAPI_SALESORDER_CHANGE to change the partner details from a Webdynpro application.

I am passing the following values. I have hardcoded the values here, but actually they come from the table "Li_Current_Partners_new"

Z_Change_Sales_Order_Input input = new Z_Change_Sales_Order_Input();

wdContext.nodeZ_Change_Sales_Order_Input().bind(input);

// Update the Document number

input.setL_Salesdocument("10000000632");

Bapisdh1X input_headerx = new Bapisdh1X();

input_headerx.setUpdateflag("U");

input.setL_Order_Header_Inx(input_headerx);

// Update the Partner details

// Get the final size of the partner table

new_partner_size = wdContext.nodeLi_Current_Partners_new().size();

for (int i = new_partner_size-1 ; i>=0; i--)

{

Bapiparnr input_partner = new Bapiparnr();

input_partner.setPartn_Numb("00000300018");

input_partner.setPartn_Role("CR");

input_partner.setItm_Number("000000"); // Only header partners are required

input.addLi_Partners(input_partner);

Bapiparnrc input_partner_changes = new Bapiparnrc();

input_partner_changes.setP_Numb_New("00000300018");

input_partner_changes.setItm_Number("000000"); // Only header partners are required

input_partner_changes.setUpdateflag("I");

input_partner_changes.setPartn_Role("CR");

input_partner_changes.setDocument("10000000632");

input.addLi_Partnerchanges(input_partner_changes);

}

try

{

wdContext.currentZ_Change_Sales_Order_InputElement().modelObject().execute();

wdContext.nodeOutput().invalidate();

}

catch (Exception ex)

{

ex.printStackTrace();

}

<b>When I run the bapi from R/3 for the same value, it works. But when I try from the WD application I get the return message:</b>

"Partner Function CR not created" (msg no. 0004)

"Sales Document 1000000632 was not changed" (msg no 555)

Can anyone help me fix this?

Thanks and Regards

Reena

Accepted Solutions (1)

Accepted Solutions (1)

abhijeet_mukkawar
Active Contributor
0 Kudos

Reena,

run application taking help of external debugging, check there if you are getting correct values in right parameter. the error may be because values are being passed to some other paramter or some parameter is not being passed

for ext debug:

SE37->enter your FM name->Utilities->Settings->Debugging tab->check the Act checkbox and then run your application from WD.

let me know if you face any problem

regards

Former Member
0 Kudos

I couldnt find the "Act" checkbox

There is "External Debugging -> Users" which displays my user id and an "IP matching checkbox".

"ABAP debugger -> New Debugger" radio button is selected

and a "Session breakpoint active immed." checkbox. Is this what you are referring to?

abhijeet_mukkawar
Active Contributor
0 Kudos

yeah, so just above your userid have you found 'Actv' checkbox?

check that,

and here we want HTTP break point and not session, so choose HTTP breakpoint

regards

Former Member
0 Kudos

Now we are dicussing ABAP in WD forum

There is no "HTTP breakpoint" checkbox only "Session breakpoint" checkbox in my SAP GUI

Anyhow, I printed the values that I am passing to the bapi from my WD application, and everything seems to be same as the ones Im using for testing the bapi directly!

abhijeet_mukkawar
Active Contributor
0 Kudos

Reena,

do you mean you have debuged the application externally? where have you printed them? We should check out the values BAPI is recieving from WD, so for that we want to do 'External Debugging'.

In 'External Debugging'. have you checked the checkbox?

If so then when you apply breakpoint in codning, has not it asked you for HTTP breakpoint, Session breakpoint, Setting and Cancel in dialog box?

and if you have done ext debugging, can you tell me if you are using any tables parameter while passing data and let me know the values it is recieving in ABAP.

and yeah please check out under which circumstances it throws the message you got while executing the appplicaion(CR not created etc)

regards

Former Member
0 Kudos

Hi Abhijeet,

Thanks for your help.

I figured out the problem.

I was passing "CR" as the value for forwarding agents to the parvw field, while the correct value for forwarding agents is "SP".

Once I changed the value from "CR" to "SP" it started working. Im still wondering how the same data worked without any error from the BAPI while it gave an error from WD.

Anyhow, thanks for the help!

An additional question - The adress details are not getting updated, though I am passing the values to the table PARTNERS.

Do we need to pass the address details to table PARTNERADDRESSES?

Regards,

Reena

Former Member
0 Kudos

Again, when I pass the address details from the BAPI it works, but from WD it fails.

Any inputs..anyone?

Thanks and Regards,

Reena

abhijeet_mukkawar
Active Contributor
0 Kudos

Hi,

Is the parameter PARTNER a table in R3?

for that you may need to create list and then can pass values,

you may refer sample code,


Bapiparnr.Bapiparnr_List PartnerList = new Bapiparnr.Bapiparnr_List(); 
Bapiparnr Partner = new Bapiparnr();
Partner.setPartn_Numb(PartnerNumber);
Partner.setPartn_Role("AG");
PartnerList.addBapiparnr(Partner);
SO.setOrder_Partners(PartnerList);

//SO is the instance of models input class
//Order_Partners is the model class name of structure Bapiparnr
//Bapiparnr is a model node with table structure in r3

and Reena, in any case, if you are doubtful then you can use external debugging(hope it has worked last time)

regards

Former Member
0 Kudos

Hi Abhijeet,

Yes, PARTNER is a table in R/3.

The code that I have used to pass the address details is as follows. I have done an external debugging and checked the values. They are being passed correctly. The code is slighly different to what you have given. But the values are getting passed correctly. I suppose thats the whole idea.

for (int i = new_partner_size-1 ; i>=0; i--)

{

int addr_no = i;

addr_no = addr_no+1;

Bapiparnr input_partner = new Bapiparnr();

input_partner.setPartn_Numb(wdContext.nodeLi_Current_Partners_new().getLi_Current_Partners_newElementAt(i).getKunnr());

input_partner.setPartn_Role(wdContext.nodeLi_Current_Partners_new().getLi_Current_Partners_newElementAt(i).getParvw()); // Only forwarding agents currently - 'SP'

input_partner.setItm_Number("000000"); // Only header partners are required

input.addLi_Partners(input_partner);

Bapiparnrc input_partner_changes = new Bapiparnrc();

input_partner_changes.setP_Numb_New(wdContext.nodeLi_Current_Partners_new().getLi_Current_Partners_newElementAt(i).getKunnr());

input_partner_changes.setItm_Number("000000"); // Only header partners are required

input_partner_changes.setUpdateflag("I");

input_partner_changes.setPartn_Role(wdContext.nodeLi_Current_Partners_new().getLi_Current_Partners_newElementAt(i).getParvw());

input_partner_changes.setAddress(wdContext.nodeLi_Current_Partners_new().getLi_Current_Partners_newElementAt(i).getAdrnr());

input_partner_changes.setAddr_Link(addr_no+"");

input_partner_changes.setDocument(wdContext.currentContextElement().getDocument());

input.addLi_Partnerchanges(input_partner_changes);

<b>// <b>When testing with the BAPI (R/3) directly, the address (Name, City, Street, Postal code) gets updated updated even if I dontt pass the values</b> to the PARTNERADDRESSES(Bapiaddr1) table</b>

Bapiaddr1 input_partner_addr = new Bapiaddr1();

input_partner_addr.setName(wdContext.nodeLi_Current_Partners_new().getLi_Current_Partners_newElementAt(i).getName1());

input_partner_addr.setCity(wdContext.nodeLi_Current_Partners_new().getLi_Current_Partners_newElementAt(i).getCity1());

input_partner_addr.setStreet(wdContext.nodeLi_Current_Partners_new().getLi_Current_Partners_newElementAt(i).getStreet());

input_partner_addr.setPostl_Cod1(wdContext.nodeLi_Current_Partners_new().getLi_Current_Partners_newElementAt(i).getPost_Code1());

input_partner_addr.setAddr_No(addr_no+"");

input_partner_addr.setCountryiso("FI");

input.addLi_Partneraddresses(input_partner_addr);

}

Thanks and Regards,

Reena

abhijeet_mukkawar
Active Contributor
0 Kudos

Reena,

If it is working fine when you execute from r3 and doesnt work from WD, have you checked that all required parameters have been sent?

or if it is even coming into tables in r3 , so check it should also come into the header of internal table when you pass this table to SD_SALESDOCUMENT_CHANGE in BAPI_SALESORDER_CHANGE. i.e. check out it should not left behind in the body of internal table.

if it is happening then use "Read...from <addr table>" in r3 just before you call other FM. Just make sure ADRNR no you pass is valid and satisfy all the criteria.

regards

Former Member
0 Kudos

Hi Abhijeet,

> Just make sure ADRNR no you pass is valid and satisfy all the criteria.

Could you tell me what exactly you mean by this?

Currently I am passing VBPA-ADRNR to the bapi.

Thanks and Regards,

Reena

abhijeet_mukkawar
Active Contributor
0 Kudos

Reena,

Somedays back, even i faced same problem, and the error was i was not passing one parameter with valid values.

So just wanted to check that.

Okay have you checked the record is coming in table header and not staying in body? If you dont pass anything in address table from WD, does it gets automatically created like what happens in the case when it is given in backend?

regards

abhijeet_mukkawar
Active Contributor
0 Kudos

Reena,

Somedays back, even i faced same problem, and the error was i was not passing one parameter with valid values.

So just wanted to check that.

Okay have you checked the record is coming in table header and not staying in body? If you dont pass anything in address table from WD, does it gets automatically created like what happens in the case when it is given in backend?

regards

SORRY posted twice

Message was edited by:

Abhijeet

Former Member
0 Kudos

Yes, the record is moving to the table header.

If I dont pass anything to the address table from WD, it does not create it automatically like in the backend

I have a feeling that I might be going wrong while passing the ADDR_LINK, ADDR_NO, ADDRESS values. I cannot check this from the backend since, its working in the backend even if I dont pass anything to these fields.

Could you tell me what are the required fields to be passed, and the relation between the ADDR_LINK, ADDR_NO, and ADDRESS fields of the three tables?

Or should I even pass values to these fields or not?

Thanks and Regards,

Reena

abhijeet_mukkawar
Active Contributor
0 Kudos

Reena,

This is getting worst!!!

I have never worked on SALES FM, but in case of vendor creation ADRNR is the adress no(in ADRC table) and gets generated automatically when we give values for vendor,

I have tried all possibilites , one thing you can do is , debug application in R3 and keep the values with you , notice the flow of FM, then pass values from WD and then check the flow and you can compare the processing. You have to do through external debugging. This is monotonous but you gotta do. I am sure there gotta be some difference in the flow.

let me know if you stuck somewhere.

regards

Former Member
0 Kudos

Hi Abhijeet,

I found a work around for this. Not sure how good a solution this is, but the adress is getting updated now.

I am calling the BAPI twice, once with an "I" update flag and second time with a "U".

First time Im not passing any address details, rather just adding a partner with blank values in the Name1, City, Street etc fields.

When I call the Bapi the second time, I am passing the address details and updating the newly added partner. The address is now getting updated.

Anyway, thanks a lot for your continous help! I really appreciate your concern.

Regards,

Reena

abhijeet_mukkawar
Active Contributor
0 Kudos

Congrats Reena !!!

well you have done it, but approach is odd, i would suggest to check why does it need to be called twice to update the address(may be the difference between flag).

anyway if you face any problem , let me know.

regards

Former Member
0 Kudos

Hello Geeks,

i am using this bapi for updating my item quantity no....

but the bapi return msg say tat its not changing....

i think i may did some mistake pls anyone can rectify it....

i hv attached my code below......

*For line item

TYPES :BEGIN OF y_t_vbap,

vbeln TYPE vbeln_va, "sales Document

posnr TYPE posnr_va, "Item no of SD document

matnr TYPE matnr, "Material No

zmeng TYPE dzmeng , "Target qty in Sales unit

spart TYPE spart, "division

message TYPE BAPI_MSG,

  • kwmeng type kwmeng, "cummulative order qty

END OF y_t_vbap.

TYPES : y_t_itemin TYPE bapisditm,

y_t_return TYPE bapiret2,

y_t_headerx TYPE bapisdh1x.

TYPES: BEGIN OF y_t_logdata,

lno TYPE lineno, "Lineno

field TYPE fieldname, "Field Name

value TYPE lmon_fvalue, "Field Value

message TYPE bapi_msg, "Messages

END OF y_t_logdata.

*********************************************************************

  • Internal table declaration

*********************************************************************

DATA: "y_i_vbak TYPE STANDARD TABLE OF y_t_vbak,

y_i_vbap TYPE STANDARD TABLE OF y_t_vbap,

y_i_headerx TYPE STANDARD TABLE OF bapisdh1x,

y_i_itemin TYPE STANDARD TABLE OF bapisditm ,

y_i_iteminx TYPE STANDARD TABLE OF bapisditmx,

y_i_return TYPE STANDARD TABLE OF y_t_return,

y_i_logdata TYPE STANDARD TABLE OF y_t_logdata,

y_i_bapiret TYPE STANDARD TABLE OF bapiret2.

*********************************************************************

  • Table type declaration

*********************************************************************

TYPES: y_tt_vbap TYPE STANDARD TABLE OF y_t_vbap ,

y_tt_logdata TYPE STANDARD TABLE OF y_t_logdata.

*********************************************************************

  • Work Area declaration.

*********************************************************************

DATA: y_wa_vbap TYPE y_t_vbap,

y_wa_itemin TYPE bapisditm ,

y_wa_iteminx TYPE bapisditmx,

y_wa_headerx TYPE bapisdh1x,

y_wa_return TYPE y_t_return,

y_wa_logdata TYPE y_t_logdata,

y_wa_event TYPE slis_alv_event,

y_wa_event1 TYPE slis_t_event,

y_wa_bapiret TYPE bapiret2.

*********************************************************************

  • Variables declaration.

*********************************************************************

DATA: y_i_event TYPE slis_t_event,

y_v_success TYPE i , "For Success

y_v_error TYPE i , "For Error

y_v_sno TYPE char30 ,

y_v_eno TYPE char30 ,

y_v_msg TYPE char100 . "error msg

**********************************************************************

  • Constants declaration.

***********************************************************************

constants : y_k_x type char1 value 'X',

y_k_u type char1 value 'U',

y_k_e type char1 value 'E'.

************************************************************************

  • SELECTION SCREEN LAYOUT

************************************************************************

SELECTION-SCREEN:BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECTION-SCREEN: BEGIN OF LINE.

SELECTION-SCREEN: COMMENT 3(18) text-003.

PARAMETERS : y_p_vbln TYPE vbak-vbeln OBLIGATORY.

SELECTION-SCREEN: END OF LINE.

SELECTION-SCREEN : END OF BLOCK b1.

************************************************************************

  • START-OF-SELECTION.

************************************************************************

START-OF-SELECTION.

  • WRITE: text-002.

************************************************************************

  • END-OF-SELECTION.

************************************************************************

END-OF-SELECTION.

SELECT vbeln

posnr

matnr

zmeng

spart

FROM vbap

INTO TABLE y_i_vbap

WHERE vbeln = y_p_vbln.

LOOP AT y_i_vbap INTO y_wa_vbap.

y_wa_vbap-zmeng = 2 + y_wa_vbap-zmeng.

MODIFY y_i_vbap FROM y_wa_vbap INDEX sy-tabix.

ENDLOOP.

PERFORM y_f_update USING y_i_vbap.

&----


*& Form y_f_update

&----


  • POPULATE BAPI DATA AND RUN BAPI

----


FORM y_f_update USING y_p_vbap TYPE y_tt_vbap.

CLEAR: y_i_headerx, y_i_itemin, y_i_iteminx,

y_i_return, y_i_bapiret.

REFRESH: y_i_itemin, y_i_iteminx, y_i_return, y_i_bapiret.

LOOP AT y_i_vbap INTO y_wa_vbap.

MOVE y_wa_vbap-zmeng TO y_wa_itemin-target_qty.

MOVE y_wa_vbap-posnr TO y_wa_itemin-itm_number.

APPEND y_wa_itemin TO y_i_itemin.

ENDLOOP.

*Update the Bapi Itnernal tables

y_wa_headerx-updateflag = y_k_u .

APPEND y_wa_headerx TO y_i_headerx.

LOOP AT y_i_vbap INTO y_wa_vbap.

y_wa_iteminx-itm_number = y_wa_vbap-posnr.

y_wa_iteminx-target_qty = y_k_x .

y_wa_iteminx-updateflag = y_k_u .

APPEND y_wa_iteminx TO y_i_iteminx .

ENDLOOP .

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

salesdocument = y_wa_vbap-vbeln

order_header_inx = y_wa_headerx

TABLES

return = y_i_return

order_item_in = y_i_itemin

order_item_inx = y_i_iteminx.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

CLEAR y_i_vbap.

IF y_i_return is not initial.

LOOP AT y_i_return INTO y_wa_return where TYPE = y_k_e .

MOVE y_wa_return-message TO y_wa_vbap-message .

Append y_wa_vbap to y_i_vbap.

y_v_success = y_v_success + 1.

ENDLOOP.

ENDIF.

y_wa_event-name = 'TOP_OF_PAGE'.

y_wa_event-form = 'Y_FD_TOP_OF_LIST'.

APPEND y_wa_event TO y_i_event.

CLEAR y_wa_event.

CALL FUNCTION 'ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = sy-repid

i_tabtypename1 = 'Y_T_VBAP'

it_events1 = y_i_event[]

TABLES

t_outtab1 = y_i_vbap[]

EXCEPTIONS

program_error = 1

maximum_of_appends_reached = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " y_f_vbap

&----


*& Form Y_FD_TOP_OF_LIST

&----


----


FORM y_fd_top_of_list.

MOVE: y_v_success TO y_v_sno,

y_v_error TO y_v_eno.

CONCATENATE text-002 y_v_sno '/' y_v_eno INTO y_v_msg SEPARATED BY

space.

CONDENSE y_v_msg.

WRITE / y_v_msg .

SKIP 1.

ENDFORM. "Y_FD_TOP_OF_LIST

Answers (0)