If you open this URL in browser, it shows up the different entity sets.
As you can see in the above image, the entitysets in this OData service are Products, Productdetails, Categories, Suppliers, Persons, PersonDetails, Advertisements. So it includes totally seven entitysets. The entityset ‘Category’ includes information about all categories.
URL is case sensitive. So the first letter ‘P’ in Products must be written in Capital. Otherwise it does not work.
It is much similar to the Transaction SE11 (ABAP Dictionary) where we give the Table name. The Data contents can be displayed for this table.
The URLs mentioned above executes the HTTP-Get methods, which in turn calls the Read-OData method. In the background, the data would be retrieved and the result is sent back.
Let us look into an example of retrieving data records with single primary key.
Specific line of record can also be retrieved by specifying the primary key value in the URL.
In the above case, both the primary key fields are of datatype string. So the value is mentioned in quotes. If the datatype is integer, then quotes should not be used.
Retrieving data records with WHERE clause.
All the products with a particular category ID can also be retrieved. To achieve this, it must be predefined in the services. We can also navigate from one entity set to another. For example, in the below URL, only the data from the product entity set are displayed.
OData services works through entity sets and entities. Data is represented in the form of Tables.
Tables are referred as Entity sets and the lines of record are referred as entities.
The Data is accessed through the following OData methods. These OData methods are referred as CRUD methods.
OData Method
Http Method
Description and its relation to sql command
Create
POST
It creates a new record. It is similar to INSERT command in SQL
Read
GET
It reads the records. It is similar to SELECT command in SQL. The Read method from OData can be further classified. For example, the Read method is used to read only one record. The Query method is used to read more lines of record.
Update
UPDATE
It updates the records. It is similar to UPDATE command in SQL
Delete
DELETE
It deletes the records. It is similar to DELETE command in SQL
It is used just as a display of checkbox. It mentions that the particular line of record is selected.
It can be used to trigger an event of type LINK_CLICK.
The value of the checkbox cannot be changed.
The value of checkbox can be changed.
It is not used to manipulate the values of the fields of ALV Table.
It can be used to manipulate the values of the fields of ALV Table. The ALV Table must be refreshed with the refresh method call {lr_alv_grid -> REFRESH ()}.
The various cell types can be used both in container mode and complete mode. The cell types are constructed based on the Attribute of the Interface ‘IF_SALV_C_CELL_TYPE’.
Type of cell
Attribute of IF_SALV_C_CELL_TYPE
Display mode container / complete
Event
Text
=> Text
Both
–
Checkbox
=> Checkbox
Both
–
Checkbox hotspot
=> checkbox_hotspot
Both
link_click
Button
=> Button
Both
link_click
Dropdown
=> dropdown
Container
Hotspot
=> Hotspot
Both
link_click
The method set_cell_type of the column object ( cl_salv_column_table ) can be used to set the cell type for the cells in the ALV Display.
DATA lr_all_columns TYPE REF TO cl_salv_columns_table.
DATA lr_single_column TYPE REF TO cl_salv_column_table.
The column position in the ALV Display can be controlled using the set_column_position method of the class CL_SALV_COLUMNS_TABLE. There are two parameter used in the method call. The column name identifies the column to be positioned. The position parameter mentions the position of the column in ALV Display.
Let us look at the following example:
DATA lr_salv_columns_table TYPE REF TO cl_salv_columns_table.
It can be dereferenced. The object or any value can be assigned to dereferenced reference variable. lr_ref->* = lr_object
Object references cannot be dereferenced. This notation ->* cannot be used.
CONVERSION OR CASTING
How to convert a value or an object in to a reference: it can be converted in the following two ways. lr_ref->* = value or object lr_ref = REF #(value/obj)
How to cast an object. lr_object2 = CAST zcl_object2( lr_object ).
USAGE
used to create data references
Used to create objects for classes.
ASSIGNMENT
An object or any value cannot be assigned to a data reference variable. It must be deferenced in order to assign a value. lr_ref->* = lr_object. lr_ref->* = ‘string_value’
Only objects can be assigned. It can be assigned directly without dereference. DATA lr_object TYPE REF TO object. DATA lr_object2 TYPE REF TO object. CREATE OBJECT lr_object TYPE (‘ZCL_CLASS’). lr_object2 = lr_object.
POSSIBLE SYNTAX ERROR
As mentioned before, values cannot be assigned directly without dereference. For example: lr_ref = ‘String_value’. This line of code will result in the below Error. “The type of ‘lr_interface1’ cannot be converted to the type of ‘lr_ref’
If the types of data objects are different, then it must be casted during the assignment. Otherwise you will get the below error. ‘The type of ‘lr_object’ cannot be converted to the type of ‘lr_object2’.