Application Development and Automation 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: 
Read only

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

sheenamk
Developer Advocate
Developer Advocate
83,311

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!!!!

212 REPLIES 212
Read only

Prass
Explorer
Read only

TuncayKaraca
Active Contributor
9,450

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

     

Read only

Alpesa1990
Participant
Read only

azaharescu70
Explorer
9,508

CDS Data Preview:

azaharescu_1-1723152232927.png

 

Code of the generator class:

azaharescu_0-1723152149502.png

 

Read only

kedarT
Active Contributor
9,963

CDS Data Preview

kedarT_0-1723152550352.png

Data generation class;

kedarT_1-1723152601491.png

 

Read only

fredymb
Discoverer
Read only

Jorge_Cervantes1
Participant
9,956
  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

 

Read only

MinhNguyenABVN
Explorer
9,944

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
Read only

Steffi1
Explorer
9,931

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

 

 

 

Read only

ayyappa_koneti90
Discoverer
9,913

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

Logic in the ABAP class:

ayyappa_koneti90_1-1723177089618.png

 

 

 

Read only

PrakharAlok1
Explorer
9,897

My solution:

CDS view entity data preview - 

PrakharAlok1_0-1723185172458.png

And the Data generation Class - 

PrakharAlok1_1-1723185224786.png

 

Read only

Valentin_BVA001
Discoverer
Read only

adrianng
Explorer
9,897
  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

 

Read only

localConstantin
Explorer
9,895

Hello there,

my submission to the challenge:

CDS View output:

localConstantin_0-1723193613202.png

My ABAP class:

localConstantin_1-1723193701403.png

 

Read only

vslakshmi
Product and Topic Expert
Product and Topic Expert
9,879

Data preview of the CDS View Entity

vslakshmi_1-1723195833362.png

Logic in the ABAP class

vslakshmi_2-1723196011473.png

Task 1 Completed...

 

Read only

spassaro
Participant
9,873

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.

 

 

Read only

SachinSinghg
Explorer
9,831

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

 

Read only

shotokka
Explorer
Read only

Yuvaraj_S88
Explorer
Read only

Saikumar_Vendoti
Discoverer
Read only

SebSchlegel
Explorer
9,803

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

 

Read only

Henning_T
Explorer
9,782

My Solution for Week 1 Challenge:

Data Preview of the CDS View:

Henning_T_0-1723216960707.png

My Method:

Henning_T_1-1723217021607.png

 

 

Read only

rathnabalaji_rg
Discoverer
9,780

Interesting. Done with Task 1.

CDS entity and data preview.

 CDS view entity.jpgData preview.jpg

 Class and table 

Class.jpgTable.jpg

 

 

Read only

soni_opal
Explorer
9,739

TASK 1 : Solution :

data Preview: 

soni_opal_0-1723231308063.png

ABAP Class:

soni_opal_1-1723231387495.png

 

 

Read only

Bharath369
Explorer
9,728

Hi, please find the below screenshots.

Bharath369_0-1723238377158.pngBharath369_1-1723238455058.png

 

Read only

Latifa
Explorer
9,692

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 💙 

Read only

Eyis
Explorer
9,633

Data Preview of CDS View

Eyis_0-1723263361320.png

Class Logic

Eyis_1-1723263392708.png

 

Read only

Vara_reddy
Explorer
9,620

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

Read only

Srimathi
Explorer
9,606

Hi,
Task 1 Completed waiting for next task.

CDS Preview:

Srimathi_0-1723274490209.png

Class Logic:

Srimathi_1-1723274498850.png

 

Read only

9,611

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.

Read only

sandeep-panwar
Discoverer
9,568

Task 1 Completed.

1. DATA Preview:

sandeeppanwar_0-1723278384041.png

2. Class logic:

sandeeppanwar_1-1723278457051.png

 

Read only

dla3076
Explorer
Read only

KenHsu97
Discoverer
9,511

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

 

Read only

angelluis_sanz
Discoverer
Read only

Nkrish
Contributor
9,427

Hi,

 

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

 

 

 

   2. Class Code : 

Nkrish_0-1723293049037.png

 

Read only

ganeshprasadj34
Explorer
9,435

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

 

Read only

Rambabu_Botsa
Explorer
9,421

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

 

 

Read only

Ayush-Rawat
Explorer
9,266

Data Preview of CDS - ZAR_TRAVEL_CDS

AyushRawat_0-1723329885089.png

Data Generating Class - ZCL_AR_GEN_DATA

AyushRawat_1-1723329919630.png