You can check abap changes that comes with 7.40 release from Horst Keller 's blog ABAP Language News for Release 7.40
And below you can find example code compilation for your own try.
***********************************
REPORT zabap740.
***************
* Expressions *
***************
************************************
* Expressions->Inline Declarations *
************************************
**Data declaration
**Before 7.40
*DATA text TYPE string.
*text = 'Example Text'.
*cl_demo_output=>display( text ).
*
**With 7.40
*DATA(text740) = 'Example Text 740'.
*cl_demo_output=>display( text740 ).
**Declaration of table
*TYPES: BEGIN OF t_struct1,
* col1 TYPE i,
* col2 TYPE string,
* END OF t_struct1,
* t_itab TYPE TABLE OF t_struct1 WITH EMPTY KEY.
*
**Before 7.40
*DATA: itab TYPE t_itab,
* wa LIKE LINE OF itab.
*wa-col1 = 1. wa-col2 = 'B1'.
*APPEND wa TO itab.
*wa-col1 = 2. wa-col2 = 'B2'.
*APPEND wa TO itab.
*cl_demo_output=>display( itab ).
*
**With 7.40
*DATA(itab740) =
* NEW t_itab( ( col1 = 1 col2 = 'B1' )
* ( col1 = 2 col2 = 'B2' ) ).
*cl_demo_output=>display( itab ).
*
*TYPES typ_itab TYPE TABLE OF i WITH EMPTY KEY.
*DATA(itabt) = VALUE typ_itab( ( 1 ) ( 2 ) ( 3 ) ).
*cl_demo_output=>display( itabt ).
**Declaration of table work areas
*DATA: itab TYPE TABLE OF mara.
*SELECT *
*UP TO 1 ROWS
*INTO TABLE itab
*FROM mara.
*
**Before 7.40
*DATA wa LIKE LINE OF itab.
*LOOP AT itab INTO wa.
* cl_demo_output=>display( wa ).
*ENDLOOP.
*
**With 7.40
*LOOP AT itab INTO DATA(wa740).
* cl_demo_output=>display( wa740-matnr ).
*ENDLOOP.
**Declaration of a helper variable
**Before 7.40
*DATA cnt TYPE i.
*FIND 'O' IN 'OZGUR' MATCH COUNT cnt.
*cl_demo_output=>display( cnt ).
*
**With 7.40
*FIND 'O' IN 'OZGUR' MATCH COUNT DATA(cnt740).
*cl_demo_output=>display( cnt740 ).
**Declaration of a result
**Before 7.40
*DATA res TYPE numc4.
*CALL METHOD cl_lib_string_tab=>version
* RECEIVING
* rv_version = res.
*cl_demo_output=>display( res ).
*
**With 7.40
*CALL METHOD cl_lib_string_tab=>version
* RECEIVING
* rv_version = DATA(res740).
*cl_demo_output=>display( res740 ).
**Declaration of actual parameters
**Before 7.40
*DATA vers TYPE numc4.
*cl_lib_string_tab=>version( RECEIVING rv_version = vers ).
*cl_demo_output=>display( vers ).
*
**With 7.40
*cl_lib_string_tab=>version( RECEIVING rv_version = DATA(vers740) ).
*cl_demo_output=>display( vers740 ).
**Declaration of reference variables for factory methods
**Before 7.40
*DATA ixml TYPE REF TO if_ixml.
*DATA stream_factory TYPE REF TO if_ixml_stream_factory.
*DATA document TYPE REF TO if_ixml_document.
*ixml = cl_ixml=>create( ).
*stream_factory = ixml->create_stream_factory( ).
*document = ixml->create_document( ).
*cl_demo_output=>display( document ).
*
**With 7.40
*DATA(ixml740) = cl_ixml=>create( ).
*DATA(stream_factory740) = ixml740->create_stream_factory( ).
*DATA(document740) = ixml740->create_document( ).
*cl_demo_output=>display( document740 ).
**Field Symbols
*DATA: lv_value TYPE string VALUE 'TEST VALUE'.
*ASSIGN lv_value TO FIELD-SYMBOL(<fs>).
*cl_demo_output=>display( <fs> ).
*
*
*SELECT matnr, mtart
*UP TO 1 ROWS
*INTO TABLE @DATA(itab)
*FROM mara.
*LOOP AT itab ASSIGNING FIELD-SYMBOL(<line>).
* cl_demo_output=>display( <line> ).
*ENDLOOP.
*
*READ TABLE itab ASSIGNING FIELD-SYMBOL(<wa>) INDEX 1.
*cl_demo_output=>display( <wa> ).
****************************************
* Expressions->Constructor Expressions *
****************************************
*************************
* Instance operator NEW *
*************************
**Example for data objects
**Before Release 7.40
*FIELD-SYMBOLS <fs> TYPE data.
*DATA dref TYPE REF TO data.
*CREATE DATA dref TYPE i.
*ASSIGN dref->* TO <fs>.
*<fs> = 555.
*cl_demo_output=>display( <fs> ).
*
**With Release 7.40
*DATA dref740 TYPE REF TO data.
*dref740 = NEW i( 740 ).
*ASSIGN dref740->* TO FIELD-SYMBOL(<fs740>).
*cl_demo_output=>display( <fs740> ).
**Example for instances of classes
**Before Release 7.40
*DATA: cstr TYPE REF TO cl_bcs_string,
* lv_str TYPE string.
*CREATE OBJECT cstr.
*CALL METHOD cstr->add_text
* EXPORTING
* iv_string = 'ABAP 7.40'.
*CALL METHOD cstr->get_string
* RECEIVING
* rv_result = lv_str.
*cl_demo_output=>display( lv_str ).
*
**With Release 7.40
**Either
*DATA cstr740 TYPE REF TO cl_bcs_string.
*cstr740 = NEW #( ).
**or with an inline declaration
*DATA(cstr7402) = NEW cl_bcs_string( ).
**cstr740->get_string(RECEIVING rv_result = data(lv_str)).
*cl_demo_output=>display( cstr7402 ).
** Internal table
*TYPES: BEGIN OF t_struct1,
* col1 TYPE i,
* col2 TYPE i,
* END OF t_struct1,
* BEGIN OF t_struct2,
* col1 TYPE i,
* col2 TYPE t_struct1,
* col3 TYPE TABLE OF t_struct1 WITH EMPTY KEY,
* END OF t_struct2,
* t_itab TYPE TABLE OF t_struct2 WITH EMPTY KEY.
*
*DATA(dref) =
* NEW t_itab( ( col1 = 1
* col2-col1 = 1
* col2-col2 = 2
* col3 = VALUE #( ( col1 = 1 col2 = 2 )
* ( col1 = 3 col2 = 4 ) ) )
* ( col1 = 2
* col2-col1 = 2
* col2-col2 = 4
* col3 = VALUE #( ( col1 = 2 col2 = 4 )
* ( col1 = 6 col2 = 8 ) ) ) ).
*cl_demo_output=>display( dref ).
************************
* Value Operator VALUE *
************************
**Example for initial values
*CLASS c1 DEFINITION.
* PUBLIC SECTION.
* TYPES: BEGIN OF t_struct,
* col1 TYPE i,
* col2 TYPE i,
* END OF t_struct.
* CLASS-DATA: wa TYPE t_struct.
* CLASS-METHODS m1 IMPORTING p TYPE t_struct.
*ENDCLASS.
*CLASS c1 IMPLEMENTATION.
* METHOD m1.
* wa = p.
* ENDMETHOD.
*ENDCLASS.
*
*START-OF-SELECTION.
*
* c1=>m1( VALUE #( col1 = 1 col2 = 2 ) ).
* cl_demo_output=>display( c1=>wa ).
**Example for structures
*TYPES: BEGIN OF t_col2,
* col1 TYPE i,
* col2 TYPE i,
* END OF t_col2.
*
*TYPES: BEGIN OF t_struct,
* col1 TYPE i,
* col2 TYPE t_col2,
* END OF t_struct.
*
*DATA: struct TYPE t_struct,
* col2 TYPE t_col2.
*"1
*struct = VALUE t_struct( col1 = 1
* col2-col1 = 1
* col2-col2 = 2 ).
*cl_demo_output=>display( struct ).
*"2
*col2 = VALUE t_col2( col1 = 1
* col2 = 2 ).
*struct = VALUE t_struct( col1 = 1
* col2 = col2 ).
*cl_demo_output=>display( struct ).
*"3
*struct = VALUE t_struct( col1 = 1
* col2 = VALUE #( col1 = 1
* col2 = 2 ) ).
*cl_demo_output=>display( struct ).
**Examples for internal tables
*TYPES t_itab TYPE TABLE OF i WITH EMPTY KEY.
*DATA itab TYPE t_itab.
*
*itab = VALUE #( ( ) ( 1 ) ( 2 ) ).
*cl_demo_output=>display( itab ).
*
**Structured line type (RANGES table):
*DATA itab2 TYPE RANGE OF i.
*
*itab2 = VALUE #( sign = 'I' option = 'BT' ( low = 1 high = 10 )
* ( low = 21 high = 30 )
* ( low = 41 high = 50 )
* option = 'GE' ( low = 61 ) ).
*cl_demo_output=>display( itab2 ).
**Other expressions in VALUE operator
*TYPES t_date_tab TYPE TABLE OF string WITH EMPTY KEY.
*
*DATA(date_tab) = VALUE t_date_tab(
* ( |{ CONV d( sy-datlo - 1 ) DATE = ENVIRONMENT }| )
* ( |{ sy-datlo DATE = ENVIRONMENT }| )
* ( |{ CONV d( sy-datlo + 1 ) DATE = ENVIRONMENT }| )
* ( |{ 'CMA' && ' DANISMANLIK' }| ) ).
*cl_demo_output=>display( date_tab ).
**************************
* Reference Operator REF *
**************************
**Example for dynamic method call
*CLASS class DEFINITION.
* PUBLIC SECTION.
* METHODS meth
* IMPORTING p1 TYPE string
* p2 TYPE i.
*ENDCLASS.
*CLASS class IMPLEMENTATION.
* METHOD meth.
* cl_demo_output=>display( p1 ).
* ENDMETHOD.
*ENDCLASS.
*
*START-OF-SELECTION.
*
* DATA(arg1) = `blah`.
* DATA(arg2) = 111.
*
* DATA(ptab) = VALUE abap_parmbind_tab(
* ( name = 'P1' kind = cl_abap_objectdescr=>exporting value = REF #( arg1 ) )
* ( name = 'P2' kind = cl_abap_objectdescr=>exporting value = REF #( arg2 ) ) ).
*
* DATA(oref) = NEW class( ).
* CALL METHOD oref->('METH')
* PARAMETER-TABLE ptab.
**Example for ADBC
*DATA(key) = '000000000000017036'.
*data(lv_spras) = sy-langu.
*
*DATA(sql) = NEW cl_sql_statement( ).
*sql->set_param( REF #( sy-mandt ) ).
**sql->set_param( REF #( key ) ).
*sql->set_param( REF #( lv_spras ) ).
*
*DATA(result) = sql->execute_query(
* `SELECT maktx ` &&
* `FROM makt ` &&
** `WHERE mandt = ? AND matnr = ?` ).
* `WHERE mandt = ? AND spras = ?` ).
*
*DATA maktx TYPE makt-maktx.
*result->set_param( REF #( maktx ) ).
*cl_demo_output=>display( result->next( ) ).
*****************************
* Conversion Operator CONV *
*****************************
**Example for parameter passing
**Method cl_abap_codepage=>convert_to expects a string but you want to convert a text field.
**Before release 7.40
*DATA text TYPE c LENGTH 255 value 'TEXT 255 CHAR'.
*
*DATA helper TYPE string.
*DATA xstr TYPE xstring.
*helper = text.
*xstr = cl_abap_codepage=>convert_to( source = helper ).
*cl_demo_output=>display( xstr ).
*
**With release 7.40
*DATA text740 TYPE c LENGTH 255 value 'TEXT 255 CHAR 740'.
*DATA(xstr740) = cl_abap_codepage=>convert_to( source = CONV string( text740 ) ).
*cl_demo_output=>display( xstr740 ).
*
**In such cases it is even simpler to write
*DATA text7402 TYPE c LENGTH 255 value 'TEXT 255 CHAR 7402'.
*DATA(xstr7402) = cl_abap_codepage=>convert_to( source = CONV #( text7402 ) ).
*cl_demo_output=>display( xstr7402 ).
**Example for influencing a calculation
*IF 1 / 3 > 0.
* cl_demo_output=>display( 'true' ).
*ELSE.
* cl_demo_output=>display( 'false' ).
*ENDIF.
*
*
*IF CONV decfloat34( 1 / 3 ) > 0.
* cl_demo_output=>display( 'true' ).
*ELSE.
* cl_demo_output=>display( 'false' ).
*ENDIF.
*
**Example for influencing a comparison
*IF ' ' = ` `.
* cl_demo_output=>display( 'true' ).
*ELSE.
* cl_demo_output=>display( 'false' ).
*ENDIF.
*
*IF ' ' = CONV char1( ` ` ).
* cl_demo_output=>display( 'true' ).
*ELSE.
* cl_demo_output=>display( 'false' ).
*ENDIF.
*************************
* Casting Operator CAST *
*************************
**Example from RTTI
**Common example where a down cast is needed.
**Before release 7.40
*DATA structdescr TYPE REF TO cl_abap_structdescr.
*structdescr ?= cl_abap_typedescr=>describe_by_name( 'VBAK' ).
*
*DATA components TYPE abap_compdescr_tab.
*components = structdescr->components.
*cl_demo_output=>display( components ).
*
**With release 7.40
*DATA(components740) = CAST cl_abap_structdescr(
* cl_abap_typedescr=>describe_by_name( 'VBAP' ) )->components.
*cl_demo_output=>display( components740 ).
**Example with up cast
**The static type of the reference variable iref declared inline should be the interface not the class.
*INTERFACE if.
*
*ENDINTERFACE.
*CLASS cl DEFINITION CREATE PRIVATE.
* PUBLIC SECTION.
* INTERFACES if.
* CLASS-METHODS factory RETURNING VALUE(ref) TYPE REF TO cl.
*ENDCLASS.
*CLASS cl IMPLEMENTATION.
* METHOD factory.
* ref = NEW #( ).
* ENDMETHOD.
*ENDCLASS.
*
*START-OF-SELECTION.
* DATA(iref) = CAST if( cl=>factory( ) ).
* DATA(iref_cl) = CAST if( cl=>factory( ) ).
* BREAK-POINT.
***Example with data objects
**A constructor expression with CAST followed by -> is an LHS-expression,
**you can assign values to it.
*TYPES: BEGIN OF t_struc,
* col1 TYPE i,
* col2 TYPE i,
* END OF t_struc.
*
*DATA dref TYPE REF TO data.
*DATA struc TYPE t_struc.
*
*dref = NEW t_struc( ).
*CAST t_struc( dref )->col1 = struc-col1.
*ASSIGN dref->* TO FIELD-SYMBOL(<fs>).
*cl_demo_output=>display( <fs> ).
***************************
* Lossless operator EXACT *
***************************
**Lossless calculations
**A lossless calculation must not perform any roundings. If it does, an exception occurrs.
*TRY.
* DATA(r1) = EXACT decfloat34( 3 / 2 ).
* cl_demo_output=>write( |Exact: { r1 }| ).
* CATCH cx_sy_conversion_rounding INTO DATA(e1).
* cl_demo_output=>write( |Not exact: { e1->value }| ).
*ENDTRY.
*
*TRY.
* DATA(r2) = EXACT decfloat34( 3 / 7 ).
* cl_demo_output=>write( |Exact: { r2 }| ).
* CATCH cx_sy_conversion_rounding INTO DATA(e2).
* cl_demo_output=>write( |Not exact: { e2->value }| ).
*ENDTRY.
*
*cl_demo_output=>display( ).
*Lossless assignments
**A lossless assignment is an assignment where
**the value of the source is valid for its type
**there are no data losses during the assignment
**the converted value of the target is valid for its type
*TYPES numtext TYPE n LENGTH 10.
*
*cl_demo_output=>write( CONV numtext( '4 Apples + 2 Oranges' ) ).
*
*TRY.
* DATA(number) = EXACT numtext( '4 Apples + 2 Oranges' ).
* CATCH cx_sy_conversion_error INTO DATA(exc).
* cl_demo_output=>write( exc->get_text( ) ).
*ENDTRY.
*cl_demo_output=>display( ).
*****************************************
* Conditional operators COND and SWITCH *
*****************************************
**Example for COND
*CLASS cx_cant_be DEFINITION INHERITING FROM cx_static_check.
*ENDCLASS.
*DATA(settedtime) = sy-timlo.
*settedtime = '110000'.
*DATA(time) =
* COND string(
* WHEN settedtime < '120000' THEN
* |{ settedtime TIME = ISO } AM|
* WHEN settedtime > '120000' THEN
* |{ CONV t( settedtime - 12 * 3600 )
* TIME = ISO } PM|
* WHEN settedtime = '120000' THEN
* |High Noon|
* ELSE
* THROW cx_cant_be( )
* ).
*cl_demo_output=>display( time ).
**Example for SWITCH
*CLASS cx_langu_not_supported DEFINITION INHERITING FROM cx_static_check.
*ENDCLASS.
*CLASS class DEFINITION.
* PUBLIC SECTION.
* METHODS meth IMPORTING iso_langu TYPE string
* RETURNING VALUE(text) TYPE string.
*ENDCLASS.
*CLASS class IMPLEMENTATION.
* METHOD meth.
* text = 'Returning text from class' && iso_langu.
* ENDMETHOD.
*ENDCLASS.
*
*START-OF-SELECTION.
* DATA(text) =
* NEW class(
* )->meth(
* SWITCH #( sy-langu
* WHEN 'D' THEN `DE`
* WHEN 'E' THEN `EN`
* WHEN 'T' THEN `TR`
* ELSE THROW cx_langu_not_supported( ) ) ).
* cl_demo_output=>display( text ).
****************
* ABAP Objects *
****************
**Before Release 7.40 a functional method could have only importing parameters besides its returning parameter.
**A functional method can now have exporting and changing parameters besides its returning parameter.
**In functional method calls you can use the additions EXPORTING, IMPORTING, and CHANGING to pass parameters.
*CLASS class DEFINITION.
* PUBLIC SECTION.
* CLASS-METHODS do_something IMPORTING p1 TYPE i
* p2 TYPE i
* EXPORTING p3 TYPE i
* p4 TYPE i
* RETURNING VALUE(r) TYPE i.
*ENDCLASS.
*CLASS class IMPLEMENTATION.
* METHOD do_something.
* r = p2 - p1 - 111.
* p3 = 3.
* p4 = 4.
* ENDMETHOD.
*ENDCLASS.
*
*START-OF-SELECTION.
* DATA: a1 TYPE i,
* a2 TYPE i.
* IF class=>do_something( EXPORTING p1 = 333
* p2 = 444
* IMPORTING p3 = a1
* p4 = a2 ) = 0.
* cl_demo_output=>display( 'Result = 0' ).
* ELSE.
* cl_demo_output=>display( 'Result <> 0' ).
* ENDIF.
**Interfaces in Test Classes
**Before Release 7.40
*CLASS mock_request DEFINITION FOR TESTING FINAL.
* PUBLIC SECTION.
* INTERFACES if_http_request.
*ENDCLASS.
*CLASS mock_request IMPLEMENTATION.
* METHOD if_http_request~get_form_field.
* value = SWITCH spfli-carrid( name WHEN 'carrid' THEN 'LH'
* ELSE space ).
* ENDMETHOD.
*
* METHOD if_http_entity~set_cdata. ENDMETHOD. "##needed
* METHOD if_http_entity~set_data. ENDMETHOD. "##needed
* METHOD if_http_entity~add_multipart. ENDMETHOD. "##needed
* METHOD if_http_entity~append_cdate. ENDMETHOD. "##needed
*ENDCLASS.
*
**Release 7.40
*CLASS mock_request740 DEFINITION FOR TESTING FINAL.
* PUBLIC SECTION.
* INTERFACES if_http_request PARTIALLY IMPLEMENTED.
*ENDCLASS.
*CLASS mock_request740 IMPLEMENTATION.
* METHOD if_http_request~get_form_field.
* value = SWITCH spfli-carrid( name WHEN 'carrid' THEN 'LH'
* ELSE space ).
* ENDMETHOD.
*ENDCLASS.
*******************
* Internal Tables *
*******************
***************************************
* Internal Tables->Table expressions *
***************************************
**Index access using the primary index
*SELECT *
*UP TO 10 ROWS
*INTO TABLE @DATA(itab)
*FROM mara.
*
*READ TABLE itab INDEX 3 INTO DATA(wa).
*cl_demo_output=>display( wa-matnr ).
*
*READ TABLE itab WITH KEY matnr = '00582AA' INTO wa.
*DATA output TYPE string.
*CONCATENATE 'Matnr:' wa-matnr 'Mtart:' wa-mtart INTO output SEPARATED BY space.
*cl_demo_output=>display( output ).
*
*DATA(wa740) = itab[ 3 ].
*cl_demo_output=>display( wa740-matnr ).
*
*READ TABLE itab WITH KEY matnr = '00582AA' INTO DATA(wa7402).
*cl_demo_output=>display( |Matnr: { wa7402-matnr } Mtart: { wa7402-mtart }| ).
*
*cl_demo_output=>display( |Mtart: { itab[ matnr = '00582AA' ]-mtart }| ).
**Access using a free key
*SELECT *
*UP TO 10 ROWS
*INTO TABLE @DATA(itab)
*FROM mara.
*
*DATA: wa TYPE mara.
*READ TABLE itab WITH KEY matnr = '' mtart = '' INTO wa.
*cl_demo_output=>display( wa-matnr ).
*
*DATA(wa740) = itab[ matnr = '' mtart = '' ].
*cl_demo_output=>display( wa740-matnr ).
**Fun example
*TYPES:
* BEGIN OF struc1,
* col1 TYPE i,
* col2 TYPE i,
* END OF struc1,
* itab1 TYPE TABLE OF struc1 WITH EMPTY KEY,
* itab2 TYPE TABLE OF itab1 WITH EMPTY KEY,
* BEGIN OF struc2,
* col1 TYPE i,
* col2 TYPE itab2,
* END OF struc2,
* itab3 TYPE TABLE OF struc2 WITH EMPTY KEY.
*
*DATA(itab) = VALUE itab3(
* ( col1 = 1 col2 = VALUE itab2(
* ( VALUE itab1(
* ( col1 = 2 col2 = 3 )
* ( col1 = 4 col2 = 5 ) ) )
* ( VALUE itab1(
* ( col1 = 6 col2 = 7 )
* ( col1 = 8 col2 = 9 ) ) ) ) )
* ( col1 = 10 col2 = VALUE itab2(
* ( VALUE itab1(
* ( col1 = 11 col2 = 12 )
* ( col1 = 13 col2 = 14 ) ) )
* ( VALUE itab1(
* ( col1 = 15 col2 = 16 )
* ( col1 = 17 col2 = 18 ) ) ) ) ) ).
*
** Reading the column with value 13 with READ TABLE statements
*READ TABLE itab INTO DATA(wa1) INDEX 2.
*READ TABLE wa1-col2 INTO DATA(wa2) INDEX 1.
*READ TABLE wa2 INTO DATA(wa3) INDEX 2.
*DATA(num1) = wa3-col1.
*
** Reading the column with value 13 with chained table expressions
*DATA(num2) = itab[ 2 ]-col2[ 1 ][ 2 ]-col1.
**cl_demo_output=>write( wa1 ).
*cl_demo_output=>write( wa2 ).
*cl_demo_output=>write( wa3 ).
*cl_demo_output=>write( num1 ).
*cl_demo_output=>write( num2 ).
*cl_demo_output=>display( ).
*********************************************
* Internal Tables->Internal table functions *
*********************************************
**Line existence
**Note that we have already some other predicate functions in ABAP: matches
**and the contains-variants in the context of string processing
*SELECT *
*UP TO 10 ROWS
*INTO TABLE @DATA(itab)
*FROM mara.
*IF line_exists( itab[ matnr = '00582AA' ] ).
* cl_demo_output=>display( 'true' ).
*ELSE.
* cl_demo_output=>display( 'false' ).
*ENDIF.
**Line index
*SELECT *
*UP TO 10 ROWS
*INTO TABLE @DATA(itab)
*FROM mara.
*DATA(idx) = line_index( itab[ matnr = '00582AA' ] ).
*cl_demo_output=>display( idx ).
***************************************************
* Internal Tables->Internal tables with empty key *
***************************************************
*http://scn.sap.com/community/abap/blog/2013/06/27/abap-news-for-release-740--internal-tables-with-empty-key
*DATA: BEGIN OF struct,
* col1 TYPE i,
* col2 TYPE i,
* END OF struct.
*
*DATA itab LIKE TABLE OF struct.
*
*struct-col1 = 3. struct-col2 = 1.
*APPEND struct TO itab.
*struct-col1 = 2. struct-col2 = 2.
*APPEND struct TO itab.
*struct-col1 = 1. struct-col2 = 1.
*APPEND struct TO itab.
*
*DATA jtab LIKE itab.
*jtab = itab.
*
*SORT jtab."not working
*
*IF jtab = itab.
* MESSAGE 'nop!' TYPE 'I'.
*ENDIF.
*TYPES: BEGIN OF struct,
* col1 TYPE i,
* col2 TYPE i,
* END OF struct.
*
*TYPES itab TYPE STANDARD TABLE OF struct.
*FIELD-SYMBOLS <itab> TYPE itab.
*DATA jtab like <itab>.
*TYPES itab TYPE STANDARD TABLE OF string WITH EMPTY KEY.
*
*DATA(itab) = VALUE itab(
* ( `I'm going slightly mad` )
* ( `I'm going slightly mad` )
* ( `It finally happened - happened` )
* ( `It finally happened - ooh woh` ) ).
*
*cl_demo_output=>display( itab ).
*********************************************
* ABAP Language News for Release 7.40, SP05 *
*********************************************
**Internal Tables
*SELECT *
*UP TO 10 ROWS
*INTO TABLE @DATA(itab)
*FROM mara.
*data: itab2 type TABLE OF marc.
*
*MOVE-CORRESPONDING itab TO itab2.
*cl_demo_output=>display( itab2 ).
*
*MOVE-CORRESPONDING itab TO itab2 EXPANDING NESTED TABLES.
*cl_demo_output=>display( itab2 ).
*
*MOVE-CORRESPONDING itab TO itab2 KEEPING TARGET LINES."Append
*cl_demo_output=>display( itab2 ).
**LET Expressions in Constructor Expressions
*defines variables var1, var2, ... or field symbols <fs1>, <fs2>, ...
*as local auxiliary fields in an expression
*TYPES:
* BEGIN OF struc,
* col1 TYPE i,
* col2 TYPE i,
* END OF struc.
*
*DATA(rnd) = cl_abap_random_int=>create(
* seed = CONV i( sy-uzeit ) min = 1 max = 10 ).
*
*DO 5 TIMES.
* DATA(struc) = VALUE struc(
* LET x = rnd->get_next( )
* y = x * x
* z = sy-index * 1000 IN col1 = x + z
* col2 = y + z ).
* cl_demo_output=>write( struc ).
*ENDDO.
*cl_demo_output=>display( ).
**CORRESPONDING Operator
**allows to execute a "MOVE-CORRESPONDING" for structures or internal tables at operand positions
*SELECT *
*UP TO 10 ROWS
*INTO TABLE @DATA(itab)
*FROM mara.
*DATA: itab2 TYPE TABLE OF marc.
*itab2 = CORRESPONDING #( itab ).
*cl_demo_output=>display( itab2 ).
**Table Comprehensions
*CLASS demo DEFINITION.
* PUBLIC SECTION.
* CLASS-METHODS main.
* TYPES:
* BEGIN OF line1,
* col1 TYPE i,
* col2 TYPE i,
* col3 TYPE i,
* col4 TYPE i,
* END OF line1,
* itab1 TYPE TABLE OF line1 WITH EMPTY KEY
* WITH UNIQUE SORTED KEY
* key COMPONENTS col1,
* BEGIN OF line2,
* col1 TYPE i,
* col2 TYPE i,
* END OF line2,
* itab2 TYPE TABLE OF line1 WITH EMPTY KEY,
* itab3 TYPE TABLE OF line1 WITH EMPTY KEY,
* itab4 TYPE TABLE OF line2 WITH EMPTY KEY,
* itab5 TYPE TABLE OF i WITH EMPTY KEY.
*ENDCLASS.
*
*CLASS demo IMPLEMENTATION.
* METHOD main.
*
* DATA(out) = cl_demo_output=>new( ).
*
* DATA(itab1) = VALUE itab1(
* FOR j = 41 THEN j - 10 UNTIL j < 10
* ( col1 = j col2 = j + 1 col3 = j + 2 col4 = j + 3 ) ).
* out->write( itab1 ).
*
* DATA(itab2) = VALUE itab2(
* FOR wa IN itab1 WHERE ( col1 < 30 )
* ( wa ) ).
* out->write( itab2 ).
*
* DATA(itab3) = VALUE itab3(
* FOR wa IN itab1 INDEX INTO idx WHERE ( col1 = 21 ) ##PRIMKEY[key]
* ( LINES OF itab1 from idx ) ).
* out->write( itab3 ).
*
* DATA(itab4) = VALUE itab4(
* FOR wa IN itab1 FROM 2 TO 3
* ( col1 = wa-col2 col2 = wa-col3 ) ).
* out->write( itab4 ).
*
* DATA(base) = VALUE itab5( ( 1 ) ( 2 ) ( 3 ) ).
* DATA(itab5) = VALUE itab5(
* BASE base
* FOR wa IN itab1 USING KEY key
* ( wa-col1 ) ).
* out->write( itab5 ).
*
* out->display( ).
* ENDMETHOD.
*ENDCLASS.
*START-OF-SELECTION.
* demo=>main( ).
************
* Open SQL *
************
**Lists in Open SQL statements can and should be separated by a comma.
**Host variables in Open SQL statements can and should be escaped by a @.
*DATA: lv_matnr TYPE makt-matnr,
* lv_langu TYPE sy-langu.
*lv_matnr = '0004001A'.
*lv_langu = sy-langu.
*SELECT matnr, maktx
*UP TO 10 ROWS
*FROM makt
*INTO TABLE @DATA(itab)
*WHERE matnr = @lv_matnr AND
* spras = @lv_langu
*ORDER BY matnr, maktx.
*cl_demo_output=>display( itab ).
**SQL Expressions
**elementary values
**arithmetic expressions
**arithmetic functions abs, ceil, floor, div, mod
**castings with cast
**string concatenations with &&
**coalesce
**case
*DATA: lv_else TYPE makt-maktx VALUE 'DEFAULT MAKTX'.
*SELECT matnr, CASE maktx
* WHEN 'AMBALAJ SETİ' THEN ( 'when 1-' && spras && '-' && maktx )
* WHEN 'CMS 040 MAMUL JANT' THEN ( 'when 2-' && maktx && '-' && spras )
* "else maktx
* ELSE @lv_else
* END AS text
*UP TO 10 ROWS
*FROM makt
*INTO TABLE @DATA(itab).
*cl_demo_output=>display( itab ).
*ABAP Managed Database Procedures
*http://scn.sap.com/community/abap/blog/2014/02/06/abap-news-for-release-740-sp05
*********************************************
* ABAP Language News for Release 7.40, SP08 *
*********************************************
**Predicative Method Calls
*IF cl_abap_demo_services=>is_production_system( ).
* cl_demo_output=>display(
* 'This demo cannot be executed in a production system' ).
* LEAVE PROGRAM.
*ELSE.
* cl_demo_output=>display('false' ).
*ENDIF.
**New Boolean Function
*IF boolc( 1 = 2 ) = abap_false."returns string so wrong
* cl_demo_output=>display_text( 'yes' ).
*ELSE.
* cl_demo_output=>display_text( 'no' ).
*ENDIF.
*
*IF xsdbool( 1 = 2 ) = abap_false.
* cl_demo_output=>display_text( 'yes' ).
*ELSE.
* cl_demo_output=>display_text( 'no' ).
*ENDIF.
** REDUCE in FOR Expressions
* Cast result
*DATA(result) =
* REDUCE string( INIT text = `Count up:`
* FOR n = 1 UNTIL n > 10
* NEXT text = text && | { n }| ).
*cl_demo_output=>display_text( result ).
*
*TYPES outref TYPE REF TO if_demo_output.
*DATA(output) =
* REDUCE outref( INIT out = cl_demo_output=>new( )
* text = `Count up:`
* FOR n = 1 UNTIL n > 11
* NEXT out = out->write( text )
* text = |{ n }| ).
*output->display( ).
**BASE for start values of constructor expressions
**Appending lines
*DATA itab TYPE TABLE OF i.
*itab = VALUE #( ( 1 ) ( 2 ) ( 3 ) ).
*itab = VALUE #( ( 4 ) ( 5 ) ( 6 ) ).
*cl_demo_output=>display( itab ).
*
*itab = VALUE #( ( 1 ) ( 2 ) ( 3 ) ).
*itab = VALUE #( BASE itab ( 4 ) ( 5 ) ( 6 ) ).
*cl_demo_output=>display( itab ).
*******************
* Internal Tables *
*******************
** GROUP BY for Internal Tables
*DATA flights TYPE TABLE OF spfli WITH EMPTY KEY.
*SELECT *
*UP TO 10 ROWS
*INTO TABLE @flights
*FROM spfli.
*
*DATA members LIKE flights.
*LOOP AT flights INTO DATA(flight)
* GROUP BY ( carrier = flight-carrid
* cityfr = flight-cityfrom )
* ASCENDING
* ASSIGNING FIELD-SYMBOL(<group>).
* CLEAR members.
* LOOP AT GROUP <group> ASSIGNING FIELD-SYMBOL(<flight>).
* members = VALUE #( BASE members ( <flight> ) ).
* ENDLOOP.
* cl_demo_output=>write( members ).
*ENDLOOP.
*cl_demo_output=>display( ).
*
*TYPES t_flights LIKE flights.
*DATA out TYPE REF TO if_demo_output.
*out = REDUCE #( INIT o = cl_demo_output=>new( )
* FOR GROUPS <group2> OF wa_flight IN flights
* GROUP BY ( carrier = wa_flight-carrid cityfr = wa_flight-cityfrom )
* ASCENDING
* LET members2 = VALUE t_flights( FOR m IN GROUP <group2> ( m ) ) IN
* NEXT o = o->write( members2 ) ).
*out->display( ).
**FILTER expressions
*CLASS demo DEFINITION.
* PUBLIC SECTION.
* CLASS-METHODS main.
*ENDCLASS.
*CLASS demo IMPLEMENTATION.
* METHOD main.
* DATA carrid TYPE spfli-carrid VALUE 'LH'.
* cl_demo_input=>add_field( CHANGING field = carrid ).
* DATA cityfrom TYPE spfli-cityfrom VALUE 'Frankfurt'.
* cl_demo_input=>request( CHANGING field = cityfrom ).
*
* DATA spfli_tab TYPE STANDARD TABLE OF spfli
* WITH EMPTY KEY
* WITH NON-UNIQUE SORTED KEY carr_city
* COMPONENTS carrid cityfrom.
*
* SELECT *
* FROM spfli
* INTO TABLE @spfli_tab.
*
* DATA(extract) =
* FILTER #( spfli_tab USING KEY carr_city
* WHERE carrid = CONV #( to_upper( carrid ) ) AND
* cityfrom = CONV #( to_upper( cityfrom ) ) ).
*
* cl_demo_output=>display( extract ).
*
* DATA(rest) =
* FILTER #( spfli_tab EXCEPT USING KEY carr_city
* WHERE carrid = CONV #( to_upper( carrid ) ) AND
* cityfrom = CONV #( to_upper( cityfrom ) ) ).
*
* ASSERT lines( extract ) + lines( rest ) = lines( spfli_tab ).
* ENDMETHOD.
*ENDCLASS.
*
*START-OF-SELECTION.
* demo=>main( ).
************
* Open SQL *
************
* Inline Declarations behind INTO
*DATA id TYPE scarr-carrid VALUE 'LH'.
*cl_demo_input=>request( CHANGING field = id ).
*SELECT SINGLE carrname AS name, carrid AS id
*INTO @DATA(result)
*FROM scarr
*WHERE carrid = @id.
*cl_demo_output=>display( result ).
*
*SELECT carrname AS name, carrid AS id
*FROM scarr
*INTO TABLE @DATA(result2).
*cl_demo_output=>display( result2 ).
** Column Specification
*SELECT scarr~carrname, spfli~*, scarr~url
*FROM scarr
*INNER JOIN spfli
* ON scarr~carrid = spfli~carrid
*INTO TABLE @DATA(result).
*cl_demo_output=>display( result ).