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
28,770

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

thomas_jung
Developer Advocate
Developer Advocate

mwn
Participant
15,716

CDS view preview:

mwn_0-1723040860732.png

Class file to copy data after using the code cleaner:

CLASS zcl_mwn_travel_copy IMPLEMENTATION.


  METHOD if_oo_adt_classrun~main.
  insert zmwn_travel from
  ( select 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
  from
   /dmo/travel ).
  ENDMETHOD.
ENDCLASS.

Distinct values for status (looks like there are no unexpected statuses)

mwn_1-1723041029003.png

 

 

0 Kudos
5,683

Task 1 Completed!

PedroARomero_0-1724033406705.png

The class

PedroARomero_1-1724033440058.png

 

 

 

 

RichHeilman
Developer Advocate
Developer Advocate

szubair
Newcomer
15,592

Hi, 

Please find the screenshots below:

szubair_0-1723042809363.png

szubair_0-1723044641765.png

0 Kudos
15,555

I don't think you want to just copy the top 100 rows to your new table

8,734

Hello!
Below is my Solution 
Data Preview:

Ananth27_0-1723470203895.png
Source Code:

Ananth27_1-1723470279031.png

Thanks!!

 

 

gphadnis2000
Participant
15,561

Hi,

 

Please find below screenshot.

gphadnis2000_0-1723043398547.png

 

gphadnis2000_1-1723043440111.png

 

 

Thanks and Regards,

Gaurav Phadnis

0 Kudos
12,664

Please attach the screenshot of the new value mapping logic.

0 Kudos
3,099

here is the mapping.

gphadnis2000_0-1725000868712.png

 

Silvi_
Explorer
15,549

CDS Data Preview:

Silvi__0-1723043374902.png

Class logic (still needs improvement 🙃)

Silvi__1-1723043432848.png

 

rajesh_munusamy
Explorer
15,464

 

CDS view entity

rajesh_munusamy_1-1723045035602.png

rajesh_munusamy_4-1723045357953.png

 

ABAP CLASS

rajesh_munusamy_2-1723045162436.pngrajesh_munusamy_3-1723045218361.png

 

YogSSohanee
Participant
15,230

Hello,

Interesting way to start the challenge, had fun!

Logic in the ABAP class:

YogSSohanee_0-1723048006924.png

Data preview of the CDS view entity : ZYSS_I_TRAVEL

YogSSohanee_2-1723048107698.png

Looking forward to the next challenge.

 

BH2408
Active Contributor
15,204

Hi Team,

Here is the Data Preview of CDS Entity:

P561888_0-1723048521062.png

ABAP Class:

P561888_1-1723048618190.png

Thank you!!!

Best Regards,

Bharani

SachinArtani
Active Participant
15,089

My Solution - 
Data Preview -

SachinArtani_0-1723050523668.png

There is no other value in travel table, hence in the custom table, there is no entry for status = 'X'.

Logic:
SachinArtani_1-1723050547519.png

 

UsamaKhan
Explorer
14,769

CB9980002351

CDS View Preview:

UsamaKhan_0-1723056910133.png

 Class Logic:

UsamaKhan_1-1723057049806.png

 

M-K
Active Participant
14,716

My submission for this task.

ABAP Class:

MK_0-1723057790929.png

CDS-View Preview:

MK_1-1723057934363.png

 

thomasks
Participant
14,644

Data Preview:

Screenshot 2024-08-07 at 3.38.29 PM.png

Logic to fill db table:

Screenshot 2024-08-07 at 3.40.25 PM.png

Anu_Nair
Explorer
14,583

CDS data preview

Anu_Nair_0-1723061421669.png

Class-method

Anu_Nair_1-1723061458292.png

 

14,510

CDS view Data Preview :

Sivaiah_Bhiragani_0-1723063108452.png

Data Generating Class:

Sivaiah_Bhiragani_1-1723063194140.png

 

aaruljothi
Participant
14,511

Hello,

Thank you for the week 1 challenge. Below are my screenshots:

Data Preview of CDS view entity

aaruljothi_0-1723063133842.png

Class Logic:

aaruljothi_1-1723063171954.png

 

 

kasch-code
Participant
14,476

Hi all,

Here is my solution for the task!

Data Preview of the CDS View Entity:

kaschcode_1-1723064118495.png

Code of the generator class:

CLASS zcl_p350812_generate_data DEFINITION PUBLIC FINAL CREATE PUBLIC.
  PUBLIC SECTION.
    INTERFACES if_oo_adt_classrun.

  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

CLASS zcl_p350812_generate_data IMPLEMENTATION.
  METHOD if_oo_adt_classrun~main.
    DATA travels TYPE STANDARD TABLE OF zp350812_travel.

    " Delete existing data in travel table
    DELETE FROM zp350812_travel.

    " Select data from demo table and apply mapping for status
    SELECT travel_id,
           description,
           total_price,
           currency_code,
           CASE status
               WHEN 'N' THEN 'O'
               WHEN 'P' THEN 'O'
               WHEN 'B' THEN 'A'
               ELSE 'X' END      AS status
      FROM /dmo/travel
      INTO CORRESPONDING FIELDS OF TABLE @travels.

    " Insert modified data into travel table
    INSERT zp350812_travel FROM TABLE @travels.
    out->write( |{ sy-dbcnt } records inserted into travel table.| ).
  ENDMETHOD.
ENDCLASS.

Ruthiel
Product and Topic Expert
Product and Topic Expert
14,381

Here is my submission:

CDS Preview:Ruthiel_0-1723068195943.png

ABAP Logic:

Ruthiel_2-1723068296789.png

 

 

Sandra_Solis
Participant

tim_matsypura
Product and Topic Expert
Product and Topic Expert

FreddieOliva
Newcomer

ajay_110125
Explorer
13,515

CDS View

ajay_110125_0-1723093333022.png

And It's data

ajay_110125_1-1723093383945.png

Copy Class

ajay_110125_2-1723093427631.png

And Table

ajay_110125_3-1723093459872.png

 

Ajay

Sarath_Kumar
Explorer
13,409

Hi @sheenamk , 

Task 1 is completed.

Screenshot:

     1. Data preview of the CDS View Entity.

Sarath_Kumar_0-1723096551928.png

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

Sarath_Kumar_1-1723096633652.png

 

ShivamChadha
Explorer
13,361

Data preview of the CDS view entity: 

ShivamChadha_0-1723097334833.png

Logic in the ABAP class:

ShivamChadha_1-1723097436121.png

 

Aslam2
Explorer
13,238

Hi,

CDS View Entity:

Aslam2_0-1723099298941.png

Data preview of CDS View

Aslam2_4-1723099682738.png

Table 

Aslam2_1-1723099360819.png

Class and logic 

Aslam2_2-1723099466820.png

Distinct entries logic

Aslam2_3-1723099541489.png

 

AAncos
Participant
13,113

Task 1, OK.

 

YasinKoseoglu
Participant
13,095

Ok 🙂

CDS View;

YasinKoseoglu_0-1723102473726.png

Class Logic;

YasinKoseoglu_1-1723102506793.png

 

 



0 Kudos
12,893

Looking good !! 

0 Kudos
12,245

thanks you 🙂

ojeswinisanaka
Explorer
13,094

Hi @sheenamk ,

I completed this week's task.
Screenshots:

1.Data preview of the CDS View Entity

ojeswinisanaka_0-1723102778308.png

2.Logic in the ABAP class. The field ‘Status’ allows only ( O, A and X ).

ojeswinisanaka_1-1723102481972.png