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
29,118

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

abaprules
Explorer

AndreaUS
Product and Topic Expert
Product and Topic Expert
9,088

Data preview CDS view entity:

AndreaUS_0-1723103085663.png

data generator class: 

AndreaUS_1-1723103100010.png

 

ArunaShibane
Explorer
6,337

Can anyone explain why client field is not added as part of select statement while moving the data to custom table?

3,523

The ABAP open SQL statements are designed to handle the client number automatically. This can be overwritten by using some special syntax, but its use is discouraged because it can lead to security issues.

tobiasz_h
Active Participant

babu4abap
Explorer
3,304

1. CDS view preview

babu4abap_0-1723104020091.png

2. Logic in the class to update the data and status field

babu4abap_1-1723104061489.png

 

 

symega2021_92
Discoverer
3,279

Hi ,

I completed Task 1,Please find the below screen shots.

symega2021_92_1-1723104073636.png

 

symega2021_92_0-1723104038591.png

Kind Regards,

Guru

 

 

Tharun_Kumar_M
Explorer
3,177

Task 1 Completed!

CDS View output :

Tharun_Kumar_M_0-1723104516609.png


Class to update data in database table :

Tharun_Kumar_M_1-1723104544435.png


Waiting for Task 02.

OanaVladescu
Explorer
3,177

Hello 😁,

Here is my submission for Task 1:

  1. Data preview of the CDS View EntityOanaVladescu_0-1723104431830.png
  2. Logic in the ABAP classOanaVladescu_1-1723104511524.png

Kind regards,                                                                                                                                                          Oana

pankajgupta1992
Explorer
3,179

My Solution:

Data Preview:

pankajgupta1992_0-1723104676590.png

Logic in ABAP Class:

pankajgupta1992_1-1723104780993.png

 

 

 

sarahf
Discoverer

BerkayZdmr
Explorer

EzgiKarabay
Explorer
3,189

💪 👍

My class logic :

EzgiKarabay_0-1723105106399.png

My CDS view:

EzgiKarabay_1-1723105262175.png

 

DineshkumarR1
Explorer
3,189

Attaching the screen shots.

DineshkumarR1_0-1723105419890.pngDineshkumarR1_1-1723105449504.png

 

mtunc
Explorer
3,177

Done 💪

Class logic;

ssforchallenge.png

Data preview;

ssforchallenge2.png

abhijitzope
Active Participant
3,086
  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 ).

abhijitzope_0-1723108149468.png

abhijitzope_1-1723108165591.png

 

3,091

Table

MallareddyBuchammagari_0-1723108245998.png

Class to generate data:

MallareddyBuchammagari_1-1723108269345.png

CDS view entity

MallareddyBuchammagari_2-1723108287074.png

Output of CDS view:

MallareddyBuchammagari_3-1723108305065.png

 

 

 

vgirish22
Discoverer
3,092

CDS view preview

vgirish22_0-1723108306296.png

ABAP Class

 

CLASS zcl_gv_travel_data_copy DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.

    INTERFACES if_oo_adt_classrun .
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

CLASS zcl_gv_travel_data_copy IMPLEMENTATION.
  METHOD if_oo_adt_classrun~main.

    DATA lt_traveldt TYPE TABLE OF ztl_travel_data.

    DELETE FROM ztl_travel_data.

    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 lt_traveldt.

    IF lt_traveldt IS NOT INITIAL.
      INSERT ztl_travel_data FROM TABLE lt_traveldt.
      IF sy-subrc = 0.
        out->write( 'Travel data inserted' ).
      ELSE.
        out->write( 'No data inserted' ).
      ENDIF.
    ENDIF.

  ENDMETHOD.
ENDCLASS.

 

 

 

Praveengopal
Associate
Associate
3,055

Solution: ABAP Class and Preview

Praveengopal_0-1723110216670.png

 

StevenNguyen
Discoverer

SushmitaG
Product and Topic Expert
Product and Topic Expert
3,023

Hi @sheenamk,

Please find below my submission of week 1

CDS View data PreviewScreenshot 2024-08-08 at 3.29.03 PM.png

Data preview of database table

 Screenshot 2024-08-08 at 3.30.14 PM.png

Class to update the table

Screenshot 2024-08-08 at 3.30.40 PM.png

Regards,

Sushmita

barisguler
Participant
3,025

Hello all,

CDS data preview

barisguler_1-1723116247566.png

Class

barisguler_0-1723116114326.png

 

geek
Participant
3,029

Borrowed heavily from:

Create Database Table and Generate UI Service | SAP Tutorials

Also followed @thomas_jung idea of mapping the domain to its description. Is there a technically elegant way of doing that?

geek_0-1723116459143.png

geek_1-1723116939724.png

thomas_jung
Developer Advocate
Developer Advocate
3,020

I've already completed all four weeks of the challenge during testing.  So, my screenshot contains a few fields that will be part of future week challenges as well. The extended description field is part of next week I believe. 

jormancacua
Explorer
3,028

Hello SAP abapers community!

Here is my Solution: 

CDS view entity:

jormancacua_0-1723117796417.png

Data preview CDS entity:

jormancacua_1-1723117860762.png

Data class generator:

jormancacua_2-1723117895876.png

Custom table:

jormancacua_3-1723117949711.png

Best regards.

Jorman 

Föß
Active Participant

jochenlittleq
Explorer
2,921

My solution.

CDS View:

jochenlittleq_0-1723125452272.png

Class:

jochenlittleq_1-1723125573845.png

 

2,913

Task 1 - Completed!

Class

govendan_annadurai_0-1723126373894.png

Data Preview of CDS View

govendan_annadurai_1-1723126395197.png

 

 

NKA1
Explorer

vazhz
Explorer
2,864

Task 1 Completed,

1. Class Logic

Screenshot 2024-08-08 205005.png

 

 

 

 

 

2. Data Preview.

Screenshot 2024-08-08 205111.png

 

 

 

 

 

 

 

Done with the task 1 and waiting for the next task..... 😊

 

kngupta141
Participant

halfknight
Explorer

arunnaik
Explorer
2,796
  1. Data preview of the CDS View Entity:
    arunnaik_0-1723137709791.png
  2. Logic in the ABAP Class:
    arunnaik_1-1723137759339.png

     

Neethu_Lohi
Explorer
2,791

Data preview of the CDS View Entity

Neethu_Lohi_2-1723140216489.png

ABAP Class

Neethu_Lohi_1-1723140114366.png

 

 

 

this_yash
Participant

miguelandher
Discoverer
2,766

Buen día, 

Comparto mi solución:

miguelandher_1-1723144105305.png

 

miguelandher_0-1723144088488.png

Saludos