Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Task 1 - Create CDS View Entity ( August Developer Challenge )

sheenamk
Developer Advocate
Developer Advocate
31,185

First of all, thanks for the overwhelming response to the ABAP Developer Challenge. Kudos to everyone who took time out of their busy schedule and finished the pre-requisite – Task 0 last week.

Now let us dive right into the challenge.

Task 1 - In this challenge, we will create a custom table and explore the creation of CDS view entity from it. This also includes writing a simple logic to generate data into this table and to replace the existing values in a specific field.

Follow the instructions carefully and share with us the screenshots of the items mentioned in the ‘Validation’ section of this discussion.

Note: As suggested in Task 0 , please ensure that you give a unique ID ( something that can relate to your SAP Community ID ) to all your development objects.

Please use this separate thread to ask your questions and discuss issues.

So, let’s get started:

  1. Create a database table with the following fields:
    1. Client as Key
    2. Travel Id as Key
    3. Description
    4. Total Price
    5. Currency Code
    6. Status
  2. Create an ABAP class which will generate data from the table /dmo/travel  to the newly created database table.
  3. Write a logic in the ABAP class to map the below values to replace the existing value in the ‘Status’ column.
    1. N --> O
    2. P --> O
    3. B --> A
    4. For all other values update --> X
  4. Check the Data Preview of the table. The ‘Status’ column should have the distinct values specified in  Step 3
  5. Create a CDS view entity using ADT with reference to the above created table.
    1. Help Document for CDS View Entitiy
  6. Once the CDS View entity is created, check the fields created. Add the 'Currency Code’ annotation for ‘Total Price’ field. Save, Activate and check the Data Preview.

Validation : Share a screenshot of the following items as a reply to this thread to gain credits:

  1. Data preview of the CDS View Entity
  2. Logic in the ABAP class. In specific, the field ‘Status’ should only have values ( O, A or X ).

Enjoy!!!!

211 REPLIES 211

kirankumar_angar
Explorer
2,700

Hello,

Here is my solution for the task1 
1) CDS View and Entity contents

 

kirankumar_angar_1-1723690002188.png
2) Program to copy entries to new custom z table

kirankumar_angar_2-1723690073061.png

Thanks & Regards,
Kiran Angar

 

darseidel
Discoverer
3,040

Here is my submission:

Preview of the CDS View Entity:

darseidel_0-1723704855720.png

Logic in the ABAP class:

darseidel_1-1723704875982.png

 

Ziynatullo
Explorer

diveshkalra
Explorer
3,196

Thank you for initiating these challenge series.

Task1:

  1. Data preview of the CDS View Entity
  2. Logic in the ABAP class. In specific, the field ‘Status’ should only have values ( O, A or X ).

diveshkalra_0-1723719797927.pngdiveshkalra_1-1723719943106.png

diveshkalra_2-1723719972867.png

 

Ajay19
Explorer
3,191

My validation

Ajay19_0-1723722836078.png

Logic of ABAP Class

CLASS zcl_a19_travel DEFINITION

PUBLIC

FINAL

CREATE PUBLIC .

 

PUBLIC SECTION.

DATA: lt_data TYPE STANDARD TABLE OF YDAJ19_travel.

INTERFACES if_oo_adt_classrun .

PROTECTED SECTION.

PRIVATE SECTION.

METHODS: delete_data.

METHODS: Get_data.

METHODS: update_data.

ENDCLASS.

 

CLASS zcl_a19_travel IMPLEMENTATION.

 

METHOD if_oo_adt_classrun~main.

DATA: lt_zcl_YADj19_travel TYPE STANDARD TABLE OF YDAJ19_travel WITH EMPTY KEY.

FIELD-SYMBOLS <fs_travel> TYPE YDAJ19_travel.

 

me->delete_data( ).

me->get_data( ).

LOOP AT me->lt_data ASSIGNING <fs_travel>.

CASE <fs_travel>-status.

 

WHEN 'N'.

<fs_travel>-status = 'O'.

WHEN 'P'.

<fs_travel>-status = 'O'.

WHEN 'B'.

<fs_travel>-status = 'A'.

WHEN OTHERS.

<fs_travel>-status = 'X'.

ENDCASE.

 

ENDLOOP.

me->update_data( ).

ENDMETHOD.

METHOD update_data.

INSERT YDAJ19_travel from TABLE @me->lt_data.

ENDMETHOD.

METHOD delete_data.

* delete existing entries in the database table

DELETE FROM YDAJ19_travel.

ENDMETHOD.

 

METHOD get_data.

CLEAR me->lt_data.

SELECT client, travel_id, description, total_price, currency_code, status

FROM /dmo/travel

INTO TABLE @me->lt_data.

 

ENDMETHOD.

 

ENDCLASS.

 

***************

Status values available in the filter selection

 

Ajay19_1-1723723077807.png

 

 

 

Dani_
Explorer
3,178

Hi,

Please find the screenshot 
Class logic

Dani__0-1723727354665.png

Data preview 

Dani__2-1723727896084.png

 

 

 

 

RafkeMagic
Active Contributor
3,160

1. data preview of CDS Entity

RafkeMagic_0-1723731899566.png

2 ABAP Class - logic status part:

RafkeMagic_1-1723731932259.png

distinct values for status:

RafkeMagic_2-1723732217166.png

 

kunalchanda
Explorer
3,160

My solution:

1. Data preview of CDS view entity:

kunalchanda_1-1723735085837.png

2. Logic in the ABAP class. In specific, the field ‘Status’ should only have values ( O, A or X ).

kunalchanda_2-1723735125838.png

 

 

 

 

mz86
Discoverer
3,158

Hallo,

Datapreview

mz86_1-1723743667491.png

 

ABAP Class

mz86_0-1723743609168.png

 

 

Shky
Product and Topic Expert
Product and Topic Expert

ManojKumarVarma
Explorer
3,126

Hi, I have completed the week-1 challenge. Please find the attached screenshots.

ManojKumarVarma_1-1723792703108.png

ManojKumarVarma_2-1723792706558.png

Regards,

Manoj Kumar Potharaju.

jakub_plocki
Explorer
3,096

Hello,
please find preview of data from my CSD view:

jakub_plocki_0-1723803699511.png

logic from uploader class:

jakub_plocki_1-1723803738950.png

 

3,095

My Solution for Task 1

Class Logic:

SRIVIDYA_AVADHANI_16_0-1723804880981.png

SRIVIDYA_AVADHANI_16_1-1723804908481.png


CDS Data Preview:

SRIVIDYA_AVADHANI_16_2-1723804930686.png

 

RonyPhilip
Discoverer
3,047

Hi,

Screenshots of the Solutions:

Data preview of the CDS View Entity:

pic1.png

Logic in the ABAP class:

RonyPhilip_7-1723816592938.png

 

bugsanderrrors
Participant
3,004

My Solution:

1. CDS Preview

bugsanderrrors_1-1723834231533.png

2. ABAP Class

bugsanderrrors_0-1723834175873.png

Always great to brush up the basics. 😉

Rajini88
Discoverer

Aditya1231
Discoverer

PedroARomero
Explorer
2,873

Task 1 Completed!

PedroARomero_2-1724033520754.png

 

The class

PedroARomero_3-1724033520928.png

 

 

 

 

AdilBasha1SAP
Explorer

namshagiri_s1
Discoverer
2,836

CDS View Entity

CDS View Entity dataCDS View Entity data

Class

Class.PNG

kyo_choi2
Participant

kyo_choi2
Participant

0 Kudos
2,776

Task-1 :
Class:

 

 

CDS Preview:

 

 

2,776

Task-1 :
Class:

Chandana_Pamarthi_0-1724091867073.png

CDS View Preview:

Chandana_Pamarthi_1-1724091895993.png

 

 

mohit_dev
Contributor
2,764

My solution:

mohit_dev_1-1724097238515.png

 

 

 

 

CLASS zms_cl_travel_copy DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    INTERFACES if_oo_adt_classrun.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.



CLASS zms_cl_travel_copy IMPLEMENTATION.
  METHOD if_oo_adt_classrun~main.
  
    DATA: lt_travel TYPE STANDARD TABLE OF zms_db_travel.

    SELECT client, travel_id, description, total_price, currency_code,
    CASE
      WHEN status = 'N' THEN 'O'
      WHEN status = 'P' THEN 'O'
      WHEN status = 'B' THEN 'A'
      ELSE 'X'
      END AS status
    FROM /dmo/travel
    INTO TABLE @LT_travel.
    IF lt_travel IS NOT INITIAL.
      "Refresh the existing data if any.
      DELETE zms_db_travel FROM TABLE @LT_travel.
      "Populate the new data.
      INSERT zms_db_travel FROM TABLE @LT_travel.
      IF sy-subrc IS INITIAL.
        DATA(lv_message) = |'Data inserted successfully!'- { sy-dbcnt }|.
        out->write( lv_message ).
      ENDIF.
    ENDIF.
  ENDMETHOD.

ENDCLASS.

 

 

 

 

Shay90
Discoverer

Mohammed_Nabeel
Explorer
2,670

1. Data preview of the CDS View Entity

Mohammed_Nabeel_2-1724148637965.png

2. Logic in the ABAP class.

Mohammed_Nabeel_1-1724148447768.png

 

ankitasharma
Newcomer
2,639

My solution -

  • Data preview of the CDS View Entity

ankitasharma_0-1724159506421.png

  • Logic in the ABAP class. 

ankitasharma_1-1724159558100.png

 

Joy_Ragavie
Explorer

Vik
Discoverer

Raju212
Explorer
2,511

Task 1.

Class

Raju212_0-1724246606243.png

CDS 

Raju212_1-1724246740711.png

CDS Data Preview

Raju212_2-1724246838087.png

 

 

Madhuchandanmc
Discoverer

LF98
Discoverer
2,399

Hello!
My Solution:

The data preview of my database table:

LF98_0-1724326768455.png

The transformation class logic:

LF98_1-1724326821345.png

 



Sayontan_Das
Participant
2,375

Hi @sheenamk  & @Shilpa4 

Task 1 Details -

CDS View Entity Data Preview

Sayontan_Das_0-1724338962290.pngSayontan_Das_1-1724338989881.png

Logic in the ABAP class. In specific, the field ‘Status’ should only have values ( O, A or X ).

Sayontan_Das_2-1724339053080.png

Please let me know your feedback.

CameronWilson
Explorer

SubaR
Explorer
2,173

Hi Team,

Here are the screenshots for the task

SubaR_0-1724506036950.png

SubaR_2-1724506132841.png

 

 

 

Arpan13Pradhan
Newcomer
2,024

Here is my solution:

1. Creation of my database table:

Arpan13Pradhan_2-1724679430531.png

2. Defining class and writing logic:

Arpan13Pradhan_1-1724679403938.png

3. Final output in the database table:

Arpan13Pradhan_0-1724679380260.png

 

Bharath369
Explorer
1,989

Hi, Task 1: I am unable to login to cloud project. So created a new project with new instance.

Bharath369_0-1724689077410.png

Bharath369_1-1724689098429.png