Saturday, June 24, 2023

Sales order creation using odata (SAP ABAP)

 About OData: This 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,

wa_header TYPE bapisdhd1,

wa_headerx TYPE bapisdhd1x,

wa_item TYPE bapisditm,

it_item TYPE TABLE OF bapisditm,

wa_itemx TYPE bapisditmx,

it_itemx TYPE TABLE OF bapisditmx,

wa_partner TYPE bapiparnr,

it_partner TYPE TABLE OF bapiparnr,

wa_return TYPE bapiret2,

it_return TYPE TABLE OF bapiret2,

wa_text TYPE bapisdtext,

it_text TYPE TABLE OF bapisdtext,

wa_condition TYPE bapicond,

it_condition TYPE TABLE OF bapicond,

wa_conditionx TYPE bapicondx,

it_conditionx TYPE TABLE OF bapicondx,

wa_schedule TYPE bapischdl,

it_schedule TYPE TABLE OF bapischdl,

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 see above.


 


Note:My next blog will be about how we get filter,inlinecount,orderby operations in Odata services.


 


 


Thank you,

Rohit Kumar Gupta 


Thursday, June 22, 2023

LearnSAP

What Is SAP and why it is beneficial for IT professional 


SAP stands for Systems, Applications, and Products in Data Processing. It is a leading enterprise resource planning (ERP) software solution used by organizations worldwide.




SAP offers a comprehensive suite of modules and applications that integrate and streamline various business processes, including finance, human resources, logistics, supply chain management, and customer relationship management.

Acquiring SAP skills can greatly benefit IT professionals due to the widespread use and demand for SAP expertise in the industry.

SAP knowledge enhances an IT professional's job prospects and opens up opportunities to work with diverse organizations across different industries.

SAP skills enable IT professionals to contribute to the implementation, customization, and maintenance of SAP systems within organizations.

SAP proficiency can lead to career advancement and higher earning potential as SAP professionals are in high demand and often receive competitive salaries.

SAP certification validates an IT professional's expertise and demonstrates their commitment to ongoing professional development.




SAP provides a platform for continuous learning and growth, as new modules and functionalities are regularly introduced, requiring IT professionals to stay updated with the latest advancements.

SAP offers a vast ecosystem of support and resources, including documentation, online communities, and training programs, allowing IT professionals to enhance their skills and expand their knowledge base.

Overall, SAP offers a robust and widely adopted ERP solution, and acquiring SAP skills can significantly benefit IT professionals by enhancing their career prospects, job opportunities, and earning potential, while providing them with a platform for continuous learning and growth