0% found this document useful (0 votes)
143 views4 pages

Few ABAP New Features

The document describes new ABAP language features including inline declarations, constructor operators, conditional expressions, JSON processing, and messaging channels. It provides examples of using NEW to create objects, VALUE to create inline tables, EXACT for lossless operations, CAST for type conversions, COND and SWITCH for conditional expressions, and READ to access deep structures and JSON data. It also briefly mentions ABAP messaging channels.

Uploaded by

Raju Jajula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
143 views4 pages

Few ABAP New Features

The document describes new ABAP language features including inline declarations, constructor operators, conditional expressions, JSON processing, and messaging channels. It provides examples of using NEW to create objects, VALUE to create inline tables, EXACT for lossless operations, CAST for type conversions, COND and SWITCH for conditional expressions, and READ to access deep structures and JSON data. It also briefly mentions ABAP messaging channels.

Uploaded by

Raju Jajula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Inline Declarations

READ TABLE Lt_itab INTO DATA(lwa_itab).


LOOP AT lt_itab INTO DATA(lwa_itab).
ENDLOOP.
CALL TRANSFORMATION
RESULT XML DATA(xml).
DATA(ref) = class=>method().
LOOP AT lt_itab ASSIGNING FIELD-SYMBOL(<lwa_itab>).
ENDLOOP.

The new constructor operators


NEW creates objects
FIELD-SYMBOLS <lv_fS> TYPE data.
DATA ref_data TYPE REF TO data.
CREATE DATA ref_data TYPE i.
ASSIGN ref_data->* TO <lv_fs>.
<lv_fs> = 555.
DATA ref_data TYPE REF TO data.
Ref_data = NEW i( 555 ).

VALUE creates values


DATA lt_itab TYPE t_itab.
DATA lwa LIKE LINE OF lt_itab.
wa-col1 = 1. wa-col2 = 2.
APPEND lwa TO lt_itab.
wa-col1 = 3. wa-col2 = 4.
APPEND lwa_wa TO lt_itab.
method( lt_itab )
method( VALUE t_itab(
( col1 = 1 col2 = 2 )
( col1 = 3 col2 = 4 ) ) ).

REF gets references


DATA ref_data TYPE REF TO string.
GET REFERENCE OF para INTO ref_data.
DATA(lt_tab) =
VALUE abap_parmbind_tab(
( name = name
kind = cl_abap_objectdescr=>exporting
value = ref_data ) ).

CALL METHOD (class)=>(meth) PARAMETER-TABLE lt_tab.


DATA(lt_tab) =
VALUE abap_parmbind_tab(
( name = name
kind = cl_abap_objectdescr=>exporting
value = REF #( para ) ) ).
CALL METHOD (class)=>(meth) PARAMETER-TABLE lt_tab.

EXACT performs lossless calculations or assignments


TYPES numtext TYPE n LENGTH 255.
DATA number TYPE numtext.
TRY.
MOVE EXACT '4 Apples + 3 Oranges' TO number.
CATCH cx_sy_conversion_error INTO DATA(exc).
...
ENDTRY.
TYPES numtext TYPE n LENGTH 255.
TRY.
DATA(number) = EXACT numtext( '4 Apples + 3 Oranges' ).
CATCH cx_sy_conversion_error INTO DATA(exc).
ENDTRY.

CAST performs up or down casts


DATA structdescr TYPE REF TO cl_abap_structdescr.
structdescr ?= cl_abap_typedescr=>describe_by_name( 'T100' ).
DATA(components) = structdescr->components.
DATA(components) =
CAST cl_abap_structdescr(
cl_abap_typedescr=>describe_by_name( 'T100' )
)->components.

COND and SWITCH enable conditional expressions


DATA time TYPE string.
IF sy-timlo < '120000'.
time = |{ sy-timlo TIME = ISO } AM|.
ELSEIF sy-timlo > '120000'.
time = |{ CONV t( sy-timlo - 12 * 3600 )
TIME = ISO } PM|.
ELSEIF sy-timlo = '120000'.
time = |High Noon|.
ELSE.
RAISE EXCEPTION TYPE cx_cant_be.
ENDIF.
DATA(time) =
COND string(
WHEN sy-timlo < '120000' THEN
|{ sy-timlo TIME = ISO } AM|

WHEN sy-timlo > '120000' THEN


|{ CONV t( sy-timlo - 12 * 3600 )
TIME = ISO } PM|
WHEN sy-timlo = '120000' THEN
|High Noon|
ELSE
THROW cx_cant_be( ) ).

Switch
DATA number TYPE string.
CASE sy-index.
WHEN 1.
number = 'one'.
WHEN 2.
number = 'two'.
WHEN 3.
number = 'three'.
WHEN OTHERS.
RAISE EXCEPTION TYPE cx_overflow.
ENDCASE.

DATA(number) =
SWITCH string( sy-index
WHEN 1 THEN 'one'
WHEN 2 THEN 'two'
WHEN 3 THEN 'three'
ELSE THROW cx_overflow( ) ).

Read
READ TABLE itab INDEX idx INTO wa.
lwa = itab[ idx ].

READ TABLE flights WITH KEY


col1 = ... col2 = ... INTO wa.
lwa = itab[col1 = ... col2 = ... ].

Asuming the Document Structure is


Crdoc-x-items-crptr

READ TABLE lt_gcrdoc INTO DATA(lwa_crdoc) INDEX 2.


READ TABLE lwa_crdoc-items INTO DATA(lwa_Items) INDEX 1.
READ TABLE lwa_Items-crptr INTO DATA(lwa_crptr) INDEX 2.
DATA(num) = lwa_crptr-ktonr.
DATA(num) = lt_gcrdoc[ 2 ]-items[ 1 ]-crptr[ 2 ]-ktonr.

JSON
Readers and Writers
DATA(json) = cl_abap_codepage=>convert_to( `{"TEXT":"JSON"}` ).
DATA(json_reader) = cl_sxml_string_reader=>create( json ).
DATA(xml_writer) = cl_sxml_string_writer=>create( ).
json_reader->next_node( ).
json_reader->skip_node( xml_writer ).
cl_demo_output=>display_xml( xml_writer->get_output( ) ).

JSON
Transformation ID
DATA(xml) = `<object><str name="TEXT">JSON</str></object>`.
DATA(json_writer) = cl_sxml_string_writer=>create( type =
if_sxml=>co_xt_json ).
CALL TRANSFORMATION id SOURCE XML xml
RESULT XML json_writer.
cl_demo_output=>display_json( json_writer->get_output( ) ).

ABAP Messaging Channels (AMC) and ABAP Push Channels (APC)


Need to explore more

You might also like