Monday 9 March 2020

Using Standard BOPF Object for CRUD Operations – Single/Multiple

What you will learn in this blog?


In this blog, you will learn to use SAP delivered standard BOPF object for CRUD operations in Custom Application.

My scenario / Example to Understand


For my use case, I have to create an excel upload utility to update/create multiple Service Entry Sheets in one go – Header & Item. There is a Standard Fiori Application that exists for creating Service Entry Sheet one by one. This application uses a BOPF object to perform CRUD operation along with draft functionality. For my use case I need to upload multiple Service Entry Sheet in one go-to standard tables so that they are visible to Standard Application and for this, I have few options:

◉ Use Standard BAPI provided so that few validations can be performed automatically
     ◉ Downside – BAPI should be there and not all validations, determinations, etc. will be there.
◉ Write custom code for Validations, save, etc.
     ◉ Time-consuming and sometimes as a custom development you don’t get time to figure out each validation
◉ Use the BOPF object used to create an actual application that handles all the validations, determinations, actions, etc.

I found that using the 3rd approach I almost save 80% of my time. Let me share your steps that how I used existing BOPF to simply perform CRUD operations.

Steps:


1. For Upload of Excel, I have used standard API and classes which I will share in another blog, however for I have store data in two internal tables Header and Item after upload. Till this time I have only validated the format of data for ex. Date column should have a valid date, number column should have a number, etc. NO BUSINESS VALIDATIONS.

2. Now I have to use standard BOPF to perform CRUD operations with my data. To show an example I am performing Create as of now

3. Standard BO used – I_SERVICEENTRYSHEETTP (How to find Standard BO ?) – Usually, if a BOPF is a CDS based BOPF then the name of CDS views and BOPF will be same otherwise you can find it in Gateway project.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Certifications Exam Prep

4. Now let’s see the actual coding part wherein we will use this standard BOPF object to update records. But before this to give a heads-up when BOPF framework is used then records are saved with three basic keys – Node Key, Parent Key and Root Key ( this you can understand in BOPF concepts ).

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Certifications Exam Prep

5. BOPF has two parts Transactional Buffer and Save Sequence. First lets fill transactional buffer using BOPF service manager MODIFY method. In above screenshot mo_svc_mngr is initiated for Service Entry Sheet BOPF object using Keys present in constant class of BO object

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Certifications Exam Prep

6. Constant class IF_I_SERVICEENTRYSHEETTP_C gets created when BOPF object was created.

7. Now at step 2 (screenshot) LT_MOD is an internal table passed to IT_MODIFICATION, Now let’s see how LT_MOD is being prepared.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Certifications Exam Prep

In above screenshot modification data needs few mandatory details:

1. Node – Constant node key for Service Entry sheet header/item
2. Change_mode – in above screenshot create is mentioned
3. Key – generated key for Header record (random key)
4. Root_key – since this is a header and the root, it is same (at item we will put root key as Header key)
5. Data – here data reference is there.

8. Now fill LT_MOD with all the data reference in LOOP for multiple records and then execute MODIFY method. Once method is called data will be stored in buffer and all the validations and determinations will be executed and if there are any issues the messages will be raised in eo_message.

9. To map messages with input records, in output messages key will be there for records which has issues

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Certifications Exam Prep

In above screenshot to get the messages use method get( ) and then to map the record key use ms_origin_location-key

10. Now let’s do the same process for items. In this particular BO object once modify for Header is executed then it automatically create Item record with pre-determined fields.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Certifications Exam Prep

Use method retrieve_by_association to fetch item records created by Header modify and then fill rest of the columns imported by Excel

11. Now use modify method for Items but before that we need to prepare modification table for Items

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Certifications Exam Prep

In items we need to mention 3 things differently from what we mentioned at header

1. Change mode – update
2. Association – association constant from header to item
3. Changed fields – whatever fields we updated, their node key need to be mentioned here (constant need to be mentioned)

12. Again if there are any messages then eo_messages will be updated.

13. Once modify is executed successfully it means all the validations (business validations) are already executed.

14. Now use SAVE method of Transaction Manager object.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Certifications Exam Prep

15. For above mentioned BO data is saved in Draft table, now we need to save data in Service Entry Sheet Standard Tables. For this we will use ACTIVATION action of this BOPF object.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Certifications Exam Prep

With above mentioned action we will be able to save data in actual tables. In IT_KEY input parameter we just need to pass Service Entry Sheet Header Keys which we used in MODIFY method of Header.

16. Once this is executed successfully data will be save to Standard Service Entry Sheet tables.

No comments:

Post a Comment