Sap

Writing SAP HCM ABAP Fiori oData service.

I’m going to transaction code SE80 and creating a package. After typing a package name, press Enter.

Then I’m taking a workbench request.

I also created a function group.

Then I’m creating a new service project using transaction code SEGW.

Then I click on “Import DDIC Structure.”

Here, we select the desired table.

Here, we select our parameters. I have chosen PERNR, VORNA, NACHN, and GBORT.

Since we will be using PERNR as the key, I entered PERNR as the key.

I am editing the properties of the entity to be creatable, updatable, and sortable. The “Key” property cannot be nullable.

Then, in SE11, we create the structure that we will use for exporting. I suggest adding “St” at the end for a smart coding convention.

I provide the relevant ABAP fields, save them, and activate them.

I am creating a new function in SE37 using my function group.

I acknowledge the warning and proceed by clicking on the checkbox.

I enter “Remote Enabled” mode in the Attributes section.

In the Import section, after providing the abbreviated form of the input value “Pernr” as “P_PERNR” and assigning the appropriate data type, I check the “Pass by value” checkbox.

Then, in the Export section, I define a parameter named “ES_DATA” since we will use a structure for exporting. I set the type of this parameter to the structure we created earlier. I also check the “Pass by value” checkbox.

In the source code section, since it is a “Get Entity” operation, I select “Single Select” and write the fields we want to fetch. After that, I use “FROM” and retrieve the data from the PA0002 table, where information related to individuals (Info Type 0002) is stored. I assign the retrieved data to the “ES_DATA” in the Export section, matching it with the “Pernr” from the Import parameter. Finally, I activate the function.

SELECT SINGLE  PERNR,
NACHN,
VORNA,
GBORT FROM PA0002 INTO @ES_DATA
WHERE PERNR EQ @IV_PERNR.

Then, I right-click on the Get Entity (Read) under Service Implementation and select “Map To Data Source.”

After selecting “Local” here, I choose “Remote Function Call” in the Type field and enter the name of our function.

On the right side, since we have an Input parameter, we click on “Add Row” to add it here.

After dragging and dropping the parameters, we save the changes and generate the implementation.

We click on the checkbox and proceed.

Now we need to create a structure for the “get_entityset” operation. Since we will be using a table, we will use a table type. We create a new data element in SE11.

Here, we select the “Table Type” option.

In the “Line Type” section, we enter the table we will be using, which is PA0002, the info type table for individual data. We save the changes and activate the data element.

Then, in SE37, we create a different function for the “Get_EntitySet” operation.

We leave the Import section empty since it is a “Set” operation.

In the Attributes section, we check the “Remote Enabled Module” checkbox.

Since this is a “Set” function and there will be multiple data entries, we don’t use “SELECT SINGLE”. After specifying our fields, we write “FROM PA0002 INTO” and select “Corresponding fields of table” for “ET_DATA”. (If we don’t specify “Corresponding fields of table” and use PA0002 table as a structure, the order of the data might get disrupted.) I wanted to limit the retrieved data to 20 rows. We activate the function.

SELECT  PERNR,
NACHN,
VORNA,
GBORT
from Pa0002 Into CORRESPONDING FIELDS OF table @et_data up to 20 rows.
ENDFUNCTION.

Again, under Service Implementation, we right-click on Get EntitySet and select “Map to Data Source.”

We map the table fields that we will use from the PA0002 table. (Since we are using PA0002 itself as a structure, all the fields from the table are retrieved.) Then, we generate the implementation.

Then we click on “Generate” and go to transaction code /n/IWFND/MAINT_SERVICE. Here, we select “Add Service.”

Here, after selecting “Local” for the System Alias, we search by Name and check the checkbox next to the selected service(s). Then, we click on “Add Selected Services” to add them.

We select our package and click on the checkbox.

Then we press the back button and filter by the technical service name.

From here, we go to SAP Gateway.

We click on “EntitySets” and select our entity set.

When we press the Execute button, as you can see, the personnel data is displayed.

Here, if we enter the PERNR that we provided as an Import value in the Get Entity with quotation marks and parentheses at the end of the HRSet, the Get Entity function will be triggered. As you can see, the data for the employee with PERNR 6 has been retrieved.

About Author

I have a Bachelor's degree in Management Information Systems from Sakarya University, where I learned the fundamentals of information technology, business analysis, and project management. I have also worked as an Oracle HR Cloud Technical Consultant at Athena Information Solutions. Currently working as a SAP ABAP and Fiori Consultant

No Comments

    Leave a Reply