Just for a change let’s begin where we left in last article!!! If you want the whole story, please pause, go to our last article and return here.
Additionally for Database there is a provision to add few technical settings.
Double Click on the spanner icon which opens a new window for checking the technical details of ZEMP_DTLS table which we created.
As in traditional ABAP, we can set the Log Changes, add the data class, size category, storage type, buffering et cetera.
Buffering:
This is a very improved version compared to conventional ABAP, since we know exactly the type of operation is being performed.
Announcement
We are starting a new Instructor-Led Paid Training on Advanced ABAP CDS with SAP Fiori Elements. This will be 1 hour daily on working days from 7:30 AM to 8:30 AM IST starting 15th of June 2020. Please register using this link and we will share more details soon.
How to populate the entries into the DB? By ABAP Class?
Step 1:
Right click on the your ABAP Cloud Project and choose ‘Other ABAP Repository Object’.
Expand ‘Source Code Library’ and select ‘ABAP Class’. Click ‘Next’.
Step 2:
Provide name and description and Click on ‘Next’. Select the default TR. Finish.
Step 3:
Observe the tabs Global Class section, Class-relevant Local Types.
Global Class
Section as most know is to include all the required information like class definition, methods, parameters (importing, exporting, changing, returning) etc.
Section 1: Static Methods
As per SAP documentation, following are the variants of the statement CLASS-METHODS distinguish different types of method declaration:
- General static methods
The most general form of the statement CLASS-METHODS allows static methods in classes and interfaces to be declared with any number of input and output parameters. - Functional Static Methods
Functional methods of classes and interfaces have exactly one return value and any number of formal parameters. - Static constructors
Static constructors of classes are methods with the predefined name class_constructor that are called automatically before their class is first used. Static constructors do not have a parameter interface and cannot be declared in interfaces. - Static event handlers
Static event handlers are static methods of classes and interfaces that are called by an event of a class or an interface. The only possible formal parameters of an event handler are input parameters that were defined as the output parameters of the event. - Static AMDP methods
In general, the same rules apply to declarations of static AMDP methods for AMDP procedure implementations and AMDP function implementations that do not implement CDS table functions as to all static methods. There is, however, one special optional addition, AMDP OPTIONS, and no non-class-based exceptions can be declared using EXCEPTIONS. - AMDP function implementations
AMDP function implementations declared using the addition FOR TABLE FUNCTION implement a CDS table function in an AMDP class. The formal parameters are determined using the CDS table function. An AMDP function implementation cannot be declared in an interface.
Section 2: Dynamic Methods
Following (as seen in ABAP documentation) are the different variants for instance methods.
- General instance methods
The general form of the METHODS statement allows instance methods to be defined with any input and output parameters. - Functional instance methods
Functional methods have exactly one return value and any number of formal parameters. - Instance constructors
Instance constructors are methods with the given name constructor, which are called automatically when their class is instantiated. Constructors have any number of input parameters and no output parameters. They cannot be declared in interfaces. - Event handlers
Event handlers are methods that can be called directly using statements (or in statements), but are mainly called when an event of a class or an interface is raised. The only possible formal parameters of an event handler are input parameters, which have been defined as the output parameters of the event. - Redefinition of Instance Methods
A method declared in a superclass can be redefined in a subclass as long as it is not flagged as final in the superclass. In a redefinition, the interface of the method is not changed. - AMDP Methods
In general, the same rules apply when declaring AMDP methods as in all instance methods. There is, however, one special optional addition, AMDP OPTIONS, and no non-class-based exceptions can be declared using EXCEPTIONS. - Definition of a test method
Test methods can be declared in test classes. They have no interface parameters and are called during ABAP Unit tests by the ABAP runtime environment. They cannot be declared in interfaces.
Also Read: CDS Part 16. Usage of Built-In Functions in CDS – IV
Step 4:
Define interface and then implement a method.
For us to insert new records and also to view the status we need to use a very important interface named “if_oo_adt_classrun”.
Step 5:
Add the required code to insert records.
Step 6:
Run and see the results in Console.
Shortcut to Run the method: Just Press F9.
Few points here:
As against traditional ABAP, we don’t have any selection screen or GUI for us to run and see the results.
Here, we have something called as CONSOLE which captures the required output.
In our code, simple internal table is declared.
New values appended.
Here, there is a one important thing. We are making use of
zempid = cl_system_uuid=>create_uuid_c32_static( ).
This is not a new concept for those who know. If you don’t know, let us know. 🙂
Insert statement written.
Finally, out->write(‘Success’), gives us the success message in the console.
So, this is one of the MOST IMPORTANT sample code which can be used everywhere in ABAP Cloud wherever data manipulation needs to be done using CODE ONLY.
Whether inserting new records, changing or deleting, this is just the right thing to do until a Fiori App is ready.
Step 7:
Validate the insertion of records into the DB Table.
Shortcut to Run the data preview of DB Table: Just Press F8.
Perfect!!! Record is Created.
Step 8:
Validate if the same record appears in the CDS Root View which we had created LOOOOONG Time ago.
Don’t remember??!!! Click here.
Again you see we have done wonderful job so far!!!
Step 9:
Now let’s recap once what we have done so far with the reference of the following diagram. Click here to revisit the content where this was first introduced.
- Database Table Created – Yes. Done. Here.
- Root View Created – Yes. Done. Here.
- Data Access Control – No. For time being let’s skip this. We can handle this topic along with authorizations topic.
- Metadata Extension – No. Next Topic !!!
- Behavior Definition – No. Next Article 🙂
- Behavior Implementation – No. Next Article.
As you can recall Metadata Extension was discussed here.
The purpose was of it was to handle the UI element through code written(read annotations) in the file exclusively, known as Metadata Extension file.
Remember, we can also add the same code(read annotations), in the same root view also. But, to differentiate the UI components from data definition language, we create a new artifact. The second approach shall be taken in the some other example when we create new table and CDS.
If you observe the root view we have written this:
So, let’s do some justice. Let us do some metadata extensions which will add super power to the view.
Right Click on ‘Core Data Services’ -> New -> Metadata Extension.
OR
Right Click on package -> New -> Other ABAP Repository Object -> ‘Core Data Services’ -> New -> Metadata Extension.
In either following screen appears. Add the required details. Next -> Next -> Finish.
Step 10:
Add the code as below:
@Metadata.layer: #CUSTOMER @UI.headerInfo: { typeName: 'Employee Detail', typeNamePlural: 'Employee Details', title.value: 'zempid', title.criticality: 'zempdesg' } annotate view Z_I_EMP_DTLS with
{ @UI.facet: [{ id : 'zempid', type: #IDENTIFICATION_REFERENCE, label: 'Employee Details'}] @UI.lineItem: [{position: 10, label: 'Employee ID'}] @UI.identification: [{ position: 10, label: 'Employee ID' }] zempid; @UI.lineItem: [{position: 20, label: 'Employee Name'}] @UI.identification: [{ position: 20, label: 'Employee Name' }] zempname; @UI.lineItem: [{position: 30, label: 'Employee Designation'}] @UI.identification: [{ position: 10, label: 'Employee Designation' }] zempdesg; @UI.lineItem: [{position: 40, label: 'Employee Gender'}] @UI.identification: [{ position: 10, label: 'Employee Gender' }] zgender; @UI.lineItem: [{position: 50, label: 'Employee Salary'}] @UI.identification: [{ position: 10, label: 'Employee Salary' }] zsalary; @UI.lineItem: [{position: 60, label: 'Salary Currency'}] @UI.identification: [{ position: 10, label: 'Salary Currency' }] zcurrency_key; }
Activate. By using Ctrl + F3.
Did the article come to a logical end? Did we miss something?
Surely, we need to address the annotations and the code written in the metadata extension. These are very important since they enable ABAP to transform into a UI (proxy) Expert. 🙂
Happy Coding and keep the questions coming!!! Remember there are many open points in this article itself to be addressed.
We hope very keen observations can draw few points and make sure to put them in comment section.
Comment Please!!
Please follow our LinkedIn Page, LinkedIn Group, Facebook Page, Twitter and Instagram.
Save our number +1-646-727-9273 and send us a Whatsapp message ‘LEARN’ to be part of our Learning Community.
All ABAP on Cloud Tutorials
- ABAP on Cloud – 1 – Introduction
- ABAP on Cloud – 2 – ABAP Trial Instance on Cloud
- ABAP on Cloud – 3 – Eclipse Set-up for ABAP Cloud
- ABAP on Cloud – 4 – Your First ABAP Cloud Project
- ABAP on Cloud – 5 – Introduction to RESTFul ABAP Programming
- ABAP on Cloud – 6 – DB Creation and Root View in ABAP Cloud
- ABAP on Cloud – 7 – Insert Records through Class and Create Metadata Extension
- ABAP on Cloud – 8 – Behavior Definition and Service Definition and Binding & Output
- ABAP on Cloud – 9 – Experimenting with Metadata Extension and CRUD Operations
- ABAP on Cloud – 10 – First Fiori Project on Cloud – 1
- ABAP on Cloud – 11 – First Fiori Project on Cloud – 2
- ABAP on Cloud – 12 – First Fiori Project on Cloud – 3
- ABAP on Cloud – 13 – First Fiori Project on Cloud – 4
- ABAP on Cloud – 14 – Advanced Topics – 1 – On Screen Validation for Managed Scenario
- ABAP on Cloud – 15 – Advanced Topics – 2 – On Screen Validation for Managed Scenario
- ABAP on Cloud – 17 – ABAP Service & ABAP Instance in Trial SAP Cloud Platform
- ABAP on Cloud – 18 – Business Application Studio – 1
- ABAP on Cloud – 19 – Business Application Studio – 2
- How to Create SM30 Like Table Maintenance T-Code in SAP RAP – Part 1
- SAP BTP. Part 9. Handling the Business Logic in RAP – Part 1
- How to Create SM30 Like Table Maintenance T-Code in SAP RAP – Part 2 – Validations and Action via RAP
- Table Maintenance Generator from SAP RAP – Part 3 – FIORI UI App
Also, Check ABAP Programming for SAP Fiori Tutorials
- ABAP Programming Model for SAP Fiori – 1 – Overview
- ABAP Programming Model for SAP Fiori – 2 – CDS – Introduction
- ABAP Programming Model for SAP Fiori – 4 – OData Service Creation
- ABAP Programming Model for SAP Fiori – 5 – OData Service Generation
- ABAP Programming Model for SAP Fiori – 3 – CDS Views Creation
- ABAP Programming Model for SAP Fiori – 6 – Generating Read-Only Application in Fiori using Fiori Elements
- ABAP Programming Model for SAP Fiori – 7 – BOPF – Introduction
- ABAP Programming Model for SAP Fiori – 8 – Developing Transactional Application – CRUD Operations using BOPF
- ABAP Programming Model for SAP Fiori – 9 – Use of Determinations in BOPF
- ABAP Programming Model for SAP Fiori – 10 – Use of Actions in BOPF
- ABAP Programming Model for SAP Fiori – 11 – Enabling Draft Functionality for Transactional Apps
- ABAP Programming Model for SAP Fiori – 12 – Scenario of Transactional App with Draft Enabled Functionality
- ABAP Programming Model for SAP Fiori – 13 – How to Preview and Download PDF in Fiori Apps
- ABAP Programming Model for SAP Fiori – 14 : Dynamic handling of CUD Operations & Fields in the Transaction App
- ABAP Programming Model for SAP Fiori – 15 : Automatic Popup Confirmation for Custom Actions using ABAP Programming Model in S/4HANA
- ABAP Programming Model for SAP Fiori – 16 : Automatic Dialogue with Parameters for Custom Actions using ABAP Programming Model in S/4HANA
- Single Popup Instead Multiple Popup for BAPI Return and Custom Messages
- How to Create SM30 Like Table Maintenance T-Code in SAP RAP – Part 1
- How to Create SM30 Like Table Maintenance T-Code in SAP RAP – Part 2 – Validations and Action via RAP
- Table Maintenance Generator from SAP RAP – Part 3 – FIORI UI App
Awesome Team!! Great efforts.
Keep up the good work. Many wishes!!!