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,964

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

Prass
Explorer

TuncayKaraca
Active Contributor
2,807

Task 1 Completed! 

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

    TuncayKaraca_2-1723146465657.png

     

Alpesa1990
Participant

azaharescu
Explorer
2,865

CDS Data Preview:

azaharescu_1-1723152232927.png

 

Code of the generator class:

azaharescu_0-1723152149502.png

 

kedarT
Active Contributor
3,320

CDS Data Preview

kedarT_0-1723152550352.png

Data generation class;

kedarT_1-1723152601491.png

 

fredymb
Discoverer
3,313

Hi,

CDS View:

fredymb_0-1723154161249.png

Generator Class:

fredymb_1-1723154222652.png

 

Jorge_Cervantes
Participant
3,313
  1. Data preview of the CDS View Entity (no X found)

Jorge_Cervantes_0-1723154160630.png

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

Jorge_Cervantes_1-1723154276059.png

 

MinhNguyenABVN
Explorer
3,301

Interesting! Ready for next week!

  1. Data preview of the CDS View Entity
  • MinhNguyenABVN_0-1723167253023.png
  1. Logic in the ABAP class. In specific, the field ‘Status’ should only have values ( O, A or X ).
  • MinhNguyenABVN_1-1723167459000.png

Steffi1
Discoverer
3,288

Data preview of CDS view:

Steffi1_0-1723173515918.png

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

Steffi1_1-1723173577304.png

 

 

 

ayyappa_koneti90
Discoverer
3,270

Data preview of the CDS View Entity:
ayyappa_koneti90_0-1723177015894.png

Logic in the ABAP class:

ayyappa_koneti90_1-1723177089618.png

 

 

 

PrakharAlok1
Explorer
3,254

My solution:

CDS view entity data preview - 

PrakharAlok1_0-1723185172458.png

And the Data generation Class - 

PrakharAlok1_1-1723185224786.png

 

Valentin_BVA001
Discoverer

adrianng
Explorer
3,253
  1. Data preview of the CDS View Entity

adrianng_0-1723193401760.png

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

adrianng_1-1723193455781.png

 

localConstantin
Explorer
3,254

Hello there,

my submission to the challenge:

CDS View output:

localConstantin_0-1723193613202.png

My ABAP class:

localConstantin_1-1723193701403.png

 

vslakshmi
Explorer
3,238

Data preview of the CDS View Entity

vslakshmi_1-1723195833362.png

Logic in the ABAP class

vslakshmi_2-1723196011473.png

Task 1 Completed...

 

spassaro
Participant
3,232

Hi!

Data Preview of the CDS View 

spassaro_0-1723196213053.png

ABAP Class

CLASS zcl_spassaro_travel_generator DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

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



CLASS zcl_spassaro_travel_generator IMPLEMENTATION.
    METHOD if_oo_adt_classrun~main.
    DELETE FROM ZSPASSARO_TRAVEL.
    INSERT ZSPASSARO_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.

 

 

SachinSinghg
Explorer
3,191

Week 1 challenge completed....😀😀😀

Data Preview.

Week 1 - 1 - Data Preview.jpg

ABAP Class Logic for loading data.

Week 1 - 1 - Class to Load Data.jpg

 

shotokka
Explorer

Yuvaraj_S88
Explorer

Saikumar_Vendoti
Discoverer

SebSchlegel
Explorer
3,163

My solution for the Week 1 challenge 😊

The data preview of my own Travel database table:

SebSchlegel_0-1723203786662.png

The transformation class logic:

SebSchlegel_1-1723203851779.png

 

Henning_T
Explorer
3,142

My Solution for Week 1 Challenge:

Data Preview of the CDS View:

Henning_T_0-1723216960707.png

My Method:

Henning_T_1-1723217021607.png

 

 

rathnabalaji_rg
Discoverer
3,140

Interesting. Done with Task 1.

CDS entity and data preview.

 CDS view entity.jpgData preview.jpg

 Class and table 

Class.jpgTable.jpg

 

 

soni_opal
Explorer
3,099

TASK 1 : Solution :

data Preview: 

soni_opal_0-1723231308063.png

ABAP Class:

soni_opal_1-1723231387495.png

 

 

Bharath369
Explorer
3,088

Hi, please find the below screenshots.

Bharath369_0-1723238377158.pngBharath369_1-1723238455058.png

 

Latifa
Explorer
3,052

CDS View Preview: 

Latifa_0-1723241980764.png

The code:

CLASS zcl_travel_lha DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    TYPES: ty_tab_flight TYPE TABLE OF zttravels_lha.
    INTERFACES : if_oo_adt_classrun.
    METHODS: main,
      collect_flights
        EXPORTING e_flights TYPE ty_tab_flight,
      map_flights
        IMPORTING i_flights        TYPE ty_tab_flight
        EXPORTING e_flights_mapped TYPE abap_boolean,
      display_flights
      .
  PROTECTED SECTION.
  PRIVATE SECTION.
    DATA : out TYPE REF TO if_oo_adt_classrun_out.
ENDCLASS.



CLASS zcl_travel_lha IMPLEMENTATION.
  METHOD : if_oo_adt_classrun~main.
    me->out = out.
    main( ).
  ENDMETHOD.
  METHOD main.
    me->collect_flights( IMPORTING e_flights = DATA(i_flights) ).
    me->map_flights( EXPORTING i_flights = i_flights IMPORTING e_flights_mapped = DATA(flights_are_mapped) ).
    IF flights_are_mapped EQ abap_true.
      me->display_flights( ).
    ELSE.
      out->write( 'An error has occured' ).
    ENDIF.
  ENDMETHOD.
  METHOD collect_flights.
    SELECT FROM /dmo/travel
    FIELDS client, travel_id, description, total_price, currency_code, status
    INTO CORRESPONDING FIELDS OF TABLE @e_flights.
    IF Sy-subrc NE 0.
    ENDIF.
  ENDMETHOD.

  METHOD map_flights.
    IF lines( i_flights ) GT 0.
      DATA: lt_flights TYPE ty_tab_flight.
      LOOP AT i_flights INTO DATA(ls_flight).
        CASE ls_flight-status.
          WHEN 'N' OR 'P'.
            lt_flights = VALUE #( BASE lt_flights ( client = ls_flight-client
                                                    travel_id = ls_flight-travel_id
                                                    description = ls_flight-description
                                                    status = 'O'
                                                    total_price = ls_flight-total_price
                                                    currency_code = ls_flight-currency_code
                                                     ) ).
          WHEN 'B'.
            lt_flights = VALUE #( BASE lt_flights ( client = ls_flight-client
                                                    travel_id = ls_flight-travel_id
                                                    description = ls_flight-description
                                                    status = 'A'
                                                    total_price = ls_flight-total_price
                                                    currency_code = ls_flight-currency_code
                                                     ) ).
          WHEN OTHERS.
            lt_flights = VALUE #( BASE lt_flights ( client = ls_flight-client
                                                      travel_id = ls_flight-travel_id
                                                      description = ls_flight-description
                                                      status = 'X'
                                                      total_price = ls_flight-total_price
                                                      currency_code = ls_flight-currency_code
                                                       ) ).
        ENDCASE.
      ENDLOOP.
      MODIFY zttravels_lha FROM TABLE @LT_flights.
      IF sy-subrc EQ 0.
        e_flights_mapped = abap_true.
      ENDIF.
    ENDIF.
  ENDMETHOD.

  METHOD display_flights.
    SELECT FROM zttravels_lha
        FIELDS *
        INTO TABLE @DATA(lt_flights).
    IF sy-subrc EQ 0.
      out->write( lt_flights ).
    ENDIF.
  ENDMETHOD.

ENDCLASS.

Any remarks on how I make the code better are welcomed 💙 

Eyis
Explorer
2,993

Data Preview of CDS View

Eyis_0-1723263361320.png

Class Logic

Eyis_1-1723263392708.png

 

Vara_reddy
Explorer
2,980

1. Data Preview of my CDS Entity 

Vara_reddy_0-1723269239238.png

2. Logic of my ABAP Class

Vara_reddy_1-1723269287873.png

Task - 1 is Done

Srimathi
Explorer
2,966

Hi,
Task 1 Completed waiting for next task.

CDS Preview:

Srimathi_0-1723274490209.png

Class Logic:

Srimathi_1-1723274498850.png

 

2,971

Hi,

Task 1 completed and waiting for the next task :).

CDS Preview:

Nandhini_Thanikachalam_0-1723274521936.png

ABAP Class:

Nandhini_Thanikachalam_1-1723274680061.png

Thanks,

Nandhini Thanikachalam.

sandeep-panwar
Discoverer
2,928

Task 1 Completed.

1. DATA Preview:

sandeeppanwar_0-1723278384041.png

2. Class logic:

sandeeppanwar_1-1723278457051.png

 

dla3076
Explorer

KenHsu97
Discoverer
2,871

Task 1 Screen shot

Data preview of the CDS View Entity

截圖 2024-08-10 下午6.12.00.pngLogic in the ABAP class. In specific, the field ‘Status’ should only have values ( O, A or X ).

截圖 2024-08-10 下午6.12.16.png

 

Nkrish
Contributor
2,787

Hi,

 

  1. Data Preview - CDS Entity
    Screenshot 2024-08-10 at 10.14.18 pm.png

 

 

 

   2. Class Code : 

Nkrish_0-1723293049037.png

 

ganeshprasadj34
Explorer
2,795

Data preview of the CDS View Entity

ganeshprasadj34_2-1723293743814.png

ganeshprasadj34_1-1723293713401.png

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

ganeshprasadj34_3-1723293829532.png

 

Rambabu_Botsa
Explorer
2,781

Task 1 - Completed!!

Data View:

rambabu_botsa_0-1723294876429.png

Method Implementation:

rambabu_botsa_1-1723294941352.png

DISTINCT values of status:

rambabu_botsa_2-1723295329952.png

 

 

Ayush-Rawat
Explorer
2,626

Data Preview of CDS - ZAR_TRAVEL_CDS

AyushRawat_0-1723329885089.png

Data Generating Class - ZCL_AR_GEN_DATA

AyushRawat_1-1723329919630.png