You are on page 1of 5

*&---------------------------------------------------------------------*

*& Report zjul_first_abap


*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zjul_first_abap.

WRITE : / 'Hello World'.

CLASS zcl_jul_demo DEFINITION


PUBLIC
FINAL
CREATE PUBLIC .

PUBLIC SECTION.
METHODS : test_method.

PROTECTED SECTION.
PRIVATE SECTION.
METHODS add_two_numbers.
ENDCLASS.

CLASS zcl_jul_demo IMPLEMENTATION.


METHOD test_method.
"Coding
"Coding
add_two_numbers( ).

*
"Coding
"Coding
"Coding
ENDMETHOD.

METHOD add_two_numbers.

DATA: a TYPE i, b TYPE i, c TYPE i.


c = a + b.

ENDMETHOD.

ENDCLASS.

*&---------------------------------------------------------------------*
*& Report zjul_new_abap_syntax
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zjul_new_abap_syntax.
"""Feature 11: Case expression

select company_name, ceil( sum( gross_amount ) ) as gross_amount, amt~currency_code


as currency_code,
case when sum( gross_amount ) > 1000000 then 'High'
when sum( gross_amount ) > 500000 and ceil( sum( gross_amount ) ) <= 1000000
then 'Medium'
else 'Low' end as ord_type
from snwd_bpa as bpa inner join snwd_so as amt on bpa~node_key = amt~buyer_guid
GROUP BY company_name, amt~currency_code
into table @data(itab).

loop at itab into data(wa).


write: / wa-company_name, wa-gross_amount, wa-ord_type, wa-currency_code.
endloop.

select ord_type, sum( gross_amount ) as total_amount from @itab as mytab


group by ord_type into table @data(calc_table).

loop at calc_table into data(calc_line).


write: / calc_line-ord_type, calc_line-total_amount .
endloop.

"""Feature 10: Case expressions

*select company_name,
* case bp_role
* when '01' then 'Customer'
* when '02' then 'Supplier'
* else 'I dont know' end as bp_role
* from snwd_bpa into table @data(itab).
*
*loop at itab into data(wa).
*write: / wa-company_name, wa-bp_role.
*endloop.

""Feature 9 : new functions in SQL

*select company_name, ceil( sum( gross_amount ) ) as gross_amount,


amt~currency_code as currency_code
*from snwd_bpa as bpa inner join snwd_so as amt on bpa~node_key = amt~buyer_guid
*GROUP BY company_name, amt~currency_code
*having sum( gross_amount ) > 1000000
*into table @data(itab).
*
*loop at itab into data(wa).
*write: / wa-company_name, wa-gross_amount, wa-currency_code.
*endloop.

""Feature 8: use of string literals

*select 'M/S' && ' ' && company_name as company_name from snwd_bpa into table
@data(itab).
*
*loop at itab into data(wa).
*write: / wa-company_name.
*endloop.

"""Feature 7 : Table loop as object

*TYPES: BEGIN OF ty_sports,


* team TYPE c LENGTH 10,
* player TYPE c LENGTH 20,
* score TYPE i,
* END OF ty_sports,
* tt_sports type standard table of ty_sports WITH DEFAULT KEY.
*
*
*data(itab) = value tt_sports( ( player = 'Chistiano' team = 'Manchester' score =
60 )
* ( player = 'Messy' team = 'FCB' score = 45 )
* ( player = 'Nymar' team = 'Liverpool' score = 40 ) ).
*
*
*loop at itab REFERENCE INTO data(lo_line).
*
* WRITE : / lo_line->player, lo_line->score, lo_line->team.
*
*ENDLOOP.

""Feature 6 : Constructor Expression

*data: lo_obj type ref to cl_e2eie_ic_tc_dpc_ext.


*create OBJECT lo_obj.

*data(lo_obj) = new cl_e2eie_ic_tc_dpc_ext( ).

""Feature 5: Table expression

*TYPES: BEGIN OF ty_sports,


* team TYPE c LENGTH 10,
* player TYPE c LENGTH 20,
* score TYPE i,
* END OF ty_sports,
* tt_sports type standard table of ty_sports WITH DEFAULT KEY.
*
*
*data(itab) = value tt_sports( ( player = 'Chistiano' team = 'Manchester' score =
60 )
* ( player = 'Messy' team = 'FCB' score = 45 )
* ( player = 'Nymar' team = 'Liverpool' score = 40 ) ).
*
**READ table itab into data(wa) with key team = 'FCB'.
**
**WRITE : / wa-player, wa-team, wa-score.
*
*if ( line_exists( itab[ team = 'DCR' ] ) ).
* data(wa) = itab[ team = 'DCR' ].
* WRITE : / wa-player, wa-team, wa-score.
*ENDIF.
""Feature 4 : String Expression

*data : lv_country type c LENGTH 20 VALUE 'India',


* lv_string type string.
*
**CONCATENATE 'I Love ' '''' lv_country '''' into lv_string RESPECTING BLANKS.
*lv_string = |I Love '{ lv_country }'|.
*
*WRITE : lv_string.

""Feature 2 : Value Expression

*TYPES: BEGIN OF ty_sports,


* team TYPE c LENGTH 10,
* player TYPE c LENGTH 20,
* score TYPE i,
* END OF ty_sports,
* BEGIN OF ty_rugby,
* scrum TYPE c LENGTH 10,
* smaster TYPE c LENGTH 20,
* goal TYPE i,
* champion type c,
* END OF ty_rugby,
* tt_sports type standard table of ty_sports WITH DEFAULT KEY,
* tt_rugby type standard table of ty_rugby with default key.
*
*data : jtab type tt_rugby.
*
*""""Option 1 with value expression with #
**DATA : itab TYPE TABLE OF ty_sports,
** wa type ty_sports.
**itab = value #( ( player = 'Chistiano' team = 'Manchester' score = 60 )
** ( player = 'Messy' team = 'FCB' score = 45 )
** ( player = 'Nymar' team = 'Liverpool' score = 40 ) ).
*""""End::: Option 1 with value expression with #
*
*""""Option 2 with value expression without hash #
*data(itab) = value tt_sports( ( player = 'Chistiano' team = 'Manchester' score =
60 )
* ( player = 'Messy' team = 'FCB' score = 45 )
* ( player = 'Nymar' team = 'Liverpool' score = 40 ) ).
*""""END ::: Option 2 with value expression without hash #
*
*""Feature 3: Moving data from one table to another
*
**jtab = CORRESPONDING #( itab MAPPING scrum = team
** smaster = player
** goal = score
** ).
*
*jtab = value #( for line in itab ( scrum = line-team
* smaster = line-player
* goal = line-score
* champion = cond #( let ref_score = 50 in
* when line-score > ref_score and 1 = 1
* then 'X'
* else ''
* ) ) ).
*
*
*
*"Ctrl+7 to comment and uncomment code blocks
**wa-player = 'Chistiano'.
**wa-team = 'Manchester'.
**wa-score = 60.
**APPEND wa TO itab.
**
**wa-player = 'Messy'.
**wa-team = 'FCB'.
**wa-score = 45.
**APPEND wa TO itab.
**
**wa-player = 'Nymer'.
**wa-team = 'Liverpool'.
**wa-score = 40.
**APPEND wa TO itab.
*
*LOOP AT itab INTO data(wa).
* WRITE: / wa-player, wa-team, wa-score.
*ENDLOOP.
*uline.
*LOOP AT jtab INTO data(wa2).
* WRITE: / wa2-scrum, wa2-smaster, wa2-goal, wa2-champion.
*ENDLOOP.
*uline.

""Feature 1: Inline data declaration


*
*select matnr, matkl, meins from mara into table @data(itab).
*
*loop at itab ASSIGNING field-symbol(<fs>).
*write: / <fs>-matnr, <fs>-matkl, <fs>-meins.
*endloop.

*loop at itab into data(wa).


*write: / wa-matnr, wa-matkl, wa-meins.
*endloop.

You might also like