Skip to Content

Hello every one
 ODATA service is used for build the services through URI in XML format.It is the back end development system for getting the data from SAP.It accesses through Restful API.We can access these services through UI5,other non-sap systems(Ex: Java,etc..)

Sales order(SO): The Sales Order is a  document confirmation sent to the customers before delivering the goods or services. Sales Order can be created once the quote is accepted by your prospective customer.

Coming to the creation of sales order based on RFC  we are using the function module ‘BAPI_SALESORDER_CREATEFROMDAT2‘.

Follow these below steps:

1.Go to T-code ‘SEGW’ and click on create an icon.Give the ‘Project name’ and ‘Description’.

 

2.Right click on Data model–>Import–>RFC

3.Give the Entity type name and Data sources.Give the name as  function module  ‘BAPI_SALESORDER_CREATEFROMDAT2‘.

4.Select the Header details as well as item and what we want to require choose those the fields and click on next button.

5.We can see all the selected fields as below.

6.Click on ‘Generate runtime objects‘ button and the message shows generated successfully as below..

Note: we can see the created entity type and entity set.

Get:

7.Now Goto  Service implementation and right click on ‘Get entity(Read).

Note:We can create order only after getting the data through set.

8.Click on methods–>inherited–>Redefine and write the logic.

METHOD salesorderset_get_entity.

*Data Declaration
DATA:lv_vbeln TYPE vbeln.
DATA : wa_keytab TYPE /iwbep/s_mgw_name_value_pair.
*Read the table
READ TABLE it_key_tab INTO wa_keytab INDEX 1.
IF it_key_tab IS NOT INITIAL.
SELECT SINGLE vbeln
FROM vbak
INTO lv_vbeln
WHERE vbeln EQ wa_keytab-value.
er_entity-salesdocument = lv_vbeln.
ENDIF.
ENDMETHOD.

 

CREATE:

9.Follow the same steps to Create entity.

10.Redefine the  function and write the Logic for Create entity.


METHOD salesorderset_create_entity.

* * Data declarations.
DATA: v_vbeln TYPE bapivbeln-vbeln.
DATA: wa_header TYPE bapisdhd1,
wa_headerx TYPE bapisdhd1x.
DATA: wa_item TYPE bapisditm,
it_item TYPE TABLE OF bapisditm.
DATA: wa_itemx TYPE bapisditmx,
it_itemx TYPE TABLE OF bapisditmx.
DATA: wa_partner TYPE bapiparnr,
it_partner TYPE TABLE OF bapiparnr.
DATA: wa_return TYPE bapiret2,
it_return TYPE TABLE OF bapiret2.
DATA:wa_text TYPE bapisdtext,
it_text TYPE TABLE OF bapisdtext.
DATA:wa_condition TYPE bapicond,
it_condition TYPE TABLE OF bapicond.
DATA:wa_conditionx TYPE bapicondx,
it_conditionx TYPE TABLE OF bapicondx.
DATA:wa_schedule TYPE bapischdl,
it_schedule TYPE TABLE OF bapischdl.
DATA:wa_schedulex TYPE bapischdlx,
it_schedulex TYPE TABLE OF bapischdlx.

DATA: es_table TYPE zcl_zcreate_so_bapi88_mpc=>ts_salesorder.

*Read the entry data
io_data_provider->read_entry_data( IMPORTING es_data = es_table ).

* Header data
wa_header-doc_type = es_table-doc_type.
wa_header-sales_org = es_table-sales_org.
wa_header-distr_chan = es_table-distr_chan.
wa_header-division = es_table-division.”’00’.
* APPEND wa_header .

wa_headerx-updateflag = ‘I’.
wa_headerx-doc_type = ‘X’.
wa_headerx-sales_org = ‘X’.
wa_headerx-distr_chan = ‘X’.
wa_headerx-division = ‘X’.

* Partner data
* Sold to
wa_partner-partn_role = es_table-partn_role.”‘AG’.
wa_partner-partn_numb = es_table-partn_numb.”‘0000023422’.
APPEND wa_partner TO it_partner.

* Item data
* Line item number.
wa_item-itm_number = es_table-itm_number.” ‘000013’.
wa_item-material = es_table-material.”‘CYD’.
wa_item-plant = es_table-plant.” ‘SL31’.
wa_item-target_qty = es_table-target_qty.”‘2’.
APPEND wa_item TO it_item.

wa_itemx-itm_number = ‘000013’.
wa_itemx-material = ‘X’.
wa_itemx-plant = ‘X’.
wa_itemx-target_qty = ‘X’.
wa_itemx-updateflag = ‘I’.
APPEND wa_itemx TO it_itemx.

**Conditions
wa_condition-itm_number = es_table-itm_number.”‘000013’.
wa_condition-cond_type = es_table-cond_type.”‘ZN00’.
wa_condition-cond_value = es_table-cond_value.”‘9000’.
APPEND wa_condition TO it_condition.

wa_conditionx-itm_number = ‘000013’.
wa_conditionx-itm_number = ‘X’.
wa_conditionx-cond_type = ‘X’.
wa_conditionx-cond_value = ‘X’.
wa_conditionx-updateflag = ‘X’.
APPEND wa_conditionx TO it_conditionx.

wa_text-text_line = es_table-text_line.”‘Please give the text’.
APPEND wa_text TO it_text.

wa_schedule-itm_number = es_table-itm_number.”‘000013’.
wa_schedule-req_qty = es_table-req_qty.”‘2’.
APPEND wa_schedule TO it_schedule.

wa_schedulex-itm_number = ‘000013’.
wa_schedulex-req_qty = ‘X’.
wa_schedulex-updateflag = ‘I’.
APPEND wa_schedulex TO it_schedulex.

CALL FUNCTION ‘BAPI_SALESORDER_CREATEFROMDAT2
EXPORTING
order_header_in = wa_header
order_header_inx = wa_headerx
IMPORTING
salesdocument = v_vbeln
TABLES
return = it_return
order_items_in = it_item
order_items_inx = it_itemx
order_partners = it_partner
order_text = it_text
order_conditions_in = it_condition
order_conditions_inx = it_conditionx
order_schedules_in = it_schedule
order_schedules_inx = it_schedulex
.

er_entity = es_table.
* Check the return table.
LOOP AT it_return INTO wa_return WHERE type = ‘E’ OR type = ‘A’.
EXIT.
ENDLOOP.

IF sy-subrc EQ 0.
WRITE: / ‘Error in creating document’.
ELSE.
* Commit the work.
COMMIT WORK AND WAIT.
WRITE: / ‘Document ‘, v_vbeln, ‘ created’.
ENDIF.

ENDMETHOD.

Save and Activate the entity sets.

 

11.Add and Maintain the service:

Go for the t-code  ‘ /IWFND/MAINT_SERVICE‘ to add  the service.

Click on ‘Add service‘ to add service.

12.Give system name and click on ‘Get service‘ and the project will be found and select project click on  ‘Add selected service‘.It will automatically maintained the service.

13.After it will shows technical service with some details and Click on yes button.

14.Go back to maintain services and  select the project and Click on ‘Sap Gateway Client‘.

15.It will shows the HTTP Request with Request URI and selct the entity set name as below.

16.Give the sales order number for get the details by clicking on ‘Get‘ radiobutton in the request.

Execute the Request URI.

We will get the success message (status code:200) the order details will be displayed.

Click on ‘Use as Request‘ and change the data.

17. After change the data  click on ‘post‘ radiobutton for create.

Execute the Request by removing order number.The new salesorder is number is ‘20305‘ created with success message (Status code: ‘201‘) as below.

18.We can check the salesorder by going T-code va03.

Note: Created the Document.

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

  1. Mantri Shekar

    Hi Sreeram,

    Am able to follow the document and created an odata service .

    But while posting am getting 400 bad request error.

    Could you please help me to resolve the issue.

    (0) 
    1. Mantri Shekar

      Hi Sreeram,

      The issue i posted i  now solved.

      Now i need passed inputs and it created a sales order for below inputs

      <atom:content type=”application/atom+xml”>
      <m:properties>
      <d:DocType>OR</d:DocType>
      <d:SalesOrg>1000</d:SalesOrg>
      <d:DistrChan>10</d:DistrChan>
      <d:Division>00</d:Division>
      <d:PoItmNo>000010</d:PoItmNo>
      <d:Material>P-109</d:Material>
      <d:TargetQty>0000000000010</d:TargetQty>
      <d:ReqQty>0000000000005</d:ReqQty>
      <d:PartnRole>SP</d:PartnRole>
      <d:PartnNumb>0000001390</d:PartnNumb>
      </m:properties>
      </atom:content>
      </atom:entry>

      What if i want to insert multiple items.

      Could you please tell me how to pass request for multiple items

       

      Regards,

      Shekar

      (0) 
  2. Vijay Dudla

    Sreeram, is this the way you use the ODATA for creating the order? how you handle multiple items i don’t think the approach you are following is right with the ODATA for handling the deep structures.

    (0) 

Leave a Reply