ABAP - Novos Comandos

download ABAP - Novos Comandos

of 51

Transcript of ABAP - Novos Comandos

  • 7/25/2019 ABAP - Novos Comandos

    1/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 3Public

    Agenda

    Inline Declarations

    Constructor Expressions

    Table Expressions: Selection, Table Comprehension, and Reduction

    Grouping

    Further News

  • 7/25/2019 ABAP - Novos Comandos

    2/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 4Public

    Simplification is the Goal

    7.40 ABAP extensions address programming in the small . Not prescribing some new paradigm or design methodology. But you will find them useful every 2 nd line. You can write ABAP code more similar to state-of-the-art languages.

    Simplification is the overall goal. Features allow you to: Avoid redundancies

    Inline declarationsType inference

    Express pure value computations concisely w/o state manipulationConstructor expressionsTable comprehensions

    Leverage powerful operations on data collectionsGrouping

  • 7/25/2019 ABAP - Novos Comandos

    3/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 5Public

    Previously on ABAP NewsExpressions (ABAP 7.02 and up)

    Computation in Operands

    Method Call Chains

    Expressions for String Operations

    String Templates! # $ %&''()*+ $ ,

    $-(./0 1! 2 !03./-45 ./-& # 1!( 6 *+$ , $+(7 1! 2 !0348&1- -15& # 1!( 6$9

    ! # -(:4;;&(+.&+!&= !-< ? ? ,,>(+>/-:'1+&!:(@= !-

  • 7/25/2019 ABAP - Novos Comandos

    4/51

    Inline Declarations

  • 7/25/2019 ABAP - Novos Comandos

    5/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 7Public

    Expressions Inline Declarations

    Inline Declaration999 JKLK=M/

  • 7/25/2019 ABAP - Novos Comandos

    6/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 8Public

    Expressions Inline Declarations DATA( )

    OTTV KL -/A BWLT JKLK='1+& ? 9

    NWJOTTV9(+- ? RKL[% TCCPNL JKLK=(@@? 9

    [KOO LYKWPCTYRKLBTW YNP^OL _RO JKLK=`5' ? 9

    JKLK=+&7? # ('. H 1+>9

    YNKJ LKSON tab INTO JKLK='1+& ? 9

  • 7/25/2019 ABAP - Novos Comandos

    7/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 9Public

    Expressions Inline Declarations DATA( )

    JKLK 1`5' LQVN YNC LT 1@:1`5'9JKLK .(>45&+- LQVN YNC LT 1@:1`5':.(>45&+-9JKLK !-- LQVN YNC LT 1@:1`5':!--(':1`5'#D>45&+- # 1`5'3D>45&+-= ?9

    !-- # 1`5'3D>

  • 7/25/2019 ABAP - Novos Comandos

    8/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 10Public

    Expressions Inline Declarations FIELD-SYMBOL( )

    CBNOJ3PQRSTOPa U'1+&ED OBbN OBWN TC -/A) U'1+&D OBbN OBWN TC -/A) U>(5;D LQVN -9

    YNKJ LKSON tab ASSIGNING .

    OTTV KL -/A KPPBZWBWZ U'1+&D9

    ASSIGN COMPONENT OF TO .

    NWJOTTV9YNKJ LKSON tab ASSIGNING CBNOJ3PQRSTO= U'1+&ED ? 9

    OTTV KL -/A KPPBZWBWZ CBNOJ3PQRSTO= U'1+&D ? 9

    KPPBZW [TRVTWNWL TC U'1+&D LT CBNOJ3PQRSTO= U>(5;D ? 9

    NWJOTTV9

  • 7/25/2019 ABAP - Novos Comandos

    9/51

    Constructor Expressions

  • 7/25/2019 ABAP - Novos Comandos

    10/51

  • 7/25/2019 ABAP - Novos Comandos

    11/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 13Public

    ExpressionsConstructor Expressions Operator NEW( )

    JKLK .

  • 7/25/2019 ABAP - Novos Comandos

    12/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 14Public

    ExpressionsConstructor Expressions Operator VALUE( )

    JKLK -/A LQVN -:-/A9JKLK '1+& OBbN OBWN TC -/A9'1+&3>('E # Ef9'1+&3>('G # g/g9

    KVVNWJ '1+& LT -/A9'1+&3>('G # gAg9

    KVVNWJ '1+& LT -/A9 KVVNWJ OBWNP TC (-X&('E # Ef >('G # g/g ?= >('E # Ef >('G # gAg ?= OBWNP TC (-X&('E # Ef

    = >('G # g/g ?= >('G # gAg ?

    = OBWNP TC (-X&

  • 7/25/2019 ABAP - Novos Comandos

    13/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 15Public

    ExpressionsConstructor Expressions Operator REF( )

    JKLK .-.&!>

  • 7/25/2019 ABAP - Novos Comandos

    14/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 16Public

    ExpressionsConstructor Expressions Operator CONV( )

    JKLK X&';&< LQVN !-

  • 7/25/2019 ABAP - Novos Comandos

    15/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 17Public

    ExpressionsConstructor Expressions Local Variable Bindings

    JKLK=!n!18&? # [TW\ 1= ONL ! # I&-:!18& ( ) BW ! e ! ?9

    Several constructor operators allow the binding of intermediate results to expression-local variables.

    ('/!!= ONL !f # I&-:!18& ( ?! # [TWJ c= d%NW !18&:(]= !f ? L%NW !f NOPN E ?

    BW ;:!18&:` # ! ;:!18&:0 # ! ?9

  • 7/25/2019 ABAP - Novos Comandos

    16/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 18Public

    ExpressionsConstructor Expressions Operator CAST( )

    JKLK !--.&!>< LQVN YNC LT >':/A/;:!--.&!>< o# >':/A/;:-0;&.&!>(5;(+&+-!? # !--.&!>(5;(+&+-!9

    JKLK=>(5;(+&+-!? # [KPL >':/A/;:!--.&!>< = >':/A/;:-0;&.&!>(5;(+&+-!9

  • 7/25/2019 ABAP - Novos Comandos

    17/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 19Public

    ExpressionsConstructor Expressions Operator EXACT( )

    LQVNP +45-&`- LQVN + ONWZL% Gpp9JKLK +45A&< LQVN +45-&`-9LYQ9

    RT\N N_K[L gl K;;'&! H m T(+M&?9

    999NWJLYQ9

    LQVNP +45-&`- LQVN + ONWZL% Gpp9LYQ9

    JKLK=+45A&

  • 7/25/2019 ABAP - Novos Comandos

    18/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 20Public

    ExpressionsConstructor Expressions Operator COND( )

    JKLK -15& LQVN !-`:>/+-:A&= ? ? 9

  • 7/25/2019 ABAP - Novos Comandos

    19/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 21Public

    ExpressionsConstructor Expressions Operator SWITCH( )

    JKLK +45A&< LQVN !-

  • 7/25/2019 ABAP - Novos Comandos

    20/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 22Public

    ExpressionsConstructor Expressions Operator CORRESPONDING( )

    OTTV KL 1-/AE KPPBZWBWZ U'1+&ED9 RT\N3[TYYNPVTWJBWZ U'1+&ED LT '1+&G9

    '1+&G3@(( # U'1+&ED3A/

  • 7/25/2019 ABAP - Novos Comandos

    21/51

    Exercise

  • 7/25/2019 ABAP - Novos Comandos

    22/51

    Table Expressions

  • 7/25/2019 ABAP - Novos Comandos

    23/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 25Public

    ExpressionsTable Expressions

    Syntax: -/A r s

    Read access to internal tables at all expression-enabled operand positions. Also enabled in write positions. Table expressions are LHS-expressions.

  • 7/25/2019 ABAP - Novos Comandos

    24/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 26Public

    ExpressionsTable Selection Specification of Table Line

    YNKJ LKSON -/A BWJN_ 1.` BWLT 7/9 7/ # -/A r 1.` s 9

    YNKJ LKSON -/A BWJN_ 1.`^PBWZ bNQ ]&0 BWLT 7/9

    7/ # -/A r bNQ ]&0 BWJN_ 1.` s 9

    YNKJ LKSON -/A dBL% bNQ >('E # >('G # INTO 7/9

    7/ # -/A r >('E # >('G # s 9

    YNKJ LKSON -/A dBL% LKSON bNQ ]&0[TRVTWNWLP >('E # >('G # BWLT 7/9

    7/ # -/A r bNQ ]&0 >('E # >('G # s 9

  • 7/25/2019 ABAP - Novos Comandos

    25/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 27Public

    ExpressionsTable Selection Retrieval Method

    -/A r s 3>(' # Ef9READ TABLE tab KPPBZWBWZ U'1+&D9

    U'1+&D3>(' # Ef9

    5&-X= \KO^N c = -/A r s JNCK^OL '1+&f ? ?9

    READ TABLE tab BWLT '1+&9

    BC !03!4A UD f9'1+& # '1+&f9NWJBC9

    5&-X= '1+& ?9

    5&-X= YNC c = -/A r s ? ?9READ TABLE tab YNCNYNW[N BWLT '1+&

  • 7/25/2019 ABAP - Novos Comandos

    26/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 28Public

    ExpressionsTable Selection Chaining

    2 3

    4 5

    6 7

    8 9

    1

    11 12

    13 14

    15 16

    17 18

    10

    YNKJ LKSON -/A BWLT JKLK=7/E? BWJN_ G9YNKJ LKSON 7/E3>('G BWLT JKLK=7/G? BWJN_ E9YNKJ LKSON 7/G BWLT JKLK=7/m? BWJN_ G9JKLK=+45? # 7/m3>('E9

    JKLK=+45? # -/A r G s 3>('G r E sr G s 3>('E9

  • 7/25/2019 ABAP - Novos Comandos

    27/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 29Public

    ExpressionsTable Selection Built-in Functions

    YNKJ LKSON -/A LYKWPVTYLBWZ WT CBNOJP9JKLK=1.`? # !03-/A1` 9 JKLK=1.`? # '1+&:1+.&`= -/A r s ? 9

    YNKJ LKSON -/A LYKWPVTYLBWZ WT CBNOJP9BC !03!4A # f 9

    NWJBC9

    BC '1+&:&`1!-!= -/A r s ? 9

    NWJBC9

  • 7/25/2019 ABAP - Novos Comandos

    28/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 30Public

    ExpressionsTable Comprehensions Building Tables Functionally

    Table-driven: \KO^N '&*+$'(#$ = CTY '1+& BW -/A d%NYN ( ) ( line 3 line 3 )

    ?For each selected line in the source table(s), construct a line in the result table.Generalization of value constructor from static to dynamic number of lines

    Condition-driven: \KO^N '&*+$'(#$ = CTY 1 # E d%BON 1 U +CTY i # Ef L%NW i 3 E ^WLBO i # f

    = 1 i ) ?

    Construct lines in the result table until the condition on the loop variable is false.

    !"#

  • 7/25/2019 ABAP - Novos Comandos

    29/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 31Public

    ExpressionsTable Comprehensions - Example

    OTTV KL -/AE BWLT '1+&E d%NYN M/' # E9OTTV KL -/AG KPPBZWBWZ U'1+&GD9

    '1+&m3> # @= '1+&E3/ ?9

    '1+&m3. # U'1+&GD3A9 KVVNWJ '1+&m LT -/AE:`:-/AG9NWJOTTV9

    NWJOTTV9

    -/AE:`:-/AG # \KO^N c= CTY '1+&E BW -/AE d%NYN = M/' # E ?

    CTY U'1+&GD BW -/AG= > # @= '1+&E3/ ? . # U'1+&GD3A ? ? 9

    Build cross product of two tables.

  • 7/25/2019 ABAP - Novos Comandos

    30/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 32Public

    ExpressionsReductions Computing Aggregate Values Functionally

    Syntax: YNJ^[N '(#$ = BWBL res = X'; =

    CTY var1 WN_L X'; = X'; var1 res )

    In each iteration (table-driven or condition-driven), re-compute the result value (and helper variables).

    Generalization of table comprehension from table to arbitrary result type

    !"#

  • 7/25/2019 ABAP - Novos Comandos

    31/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 33Public

    ExpressionsReductions - Example

    JKLK X-5'-/A LQVN !-

  • 7/25/2019 ABAP - Novos Comandos

    32/51

    Grouping!"#

  • 7/25/2019 ABAP - Novos Comandos

    33/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 35Public

    GroupingProcessing Table Lines in Groups Statement Variant

    OTTV KL -/A *,-. =`? d%NYN

    ZYT^V SQ /%"0#1$( =`?*,-. =I?9

    OTTV KL ZYT^V I *,-. =5?9

    NWJOTTV9

    NWJOTTV9

    The ZYT^V SQ loop iterates through the computed group key values in I , if *,-. =I? is given representative group members in ` , if *,-. =I? is missing

    The OTTV KL ZYT^V iterates through all members of the current group I (in 5 ).

    *,-. =`? is a binding ( BWLT / KPPBZWBWZ) of a variable ` for theoriginal lines in the table being grouped*,-. =I? is a binding of a variable I for the group key values/%"0#1$( =`? is either

    an expression over ` or a tuple = -&2$ E # $3#% E -&2$ G # $3#% G ) over `

  • 7/25/2019 ABAP - Novos Comandos

    34/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 36Public

    GroupingProcessing Table Lines in Groups Expression Variant

    Table Comprehension

    \KO^N c= CTY ZYT^VP I TC ` BW -/A ZYT^V SQ /%"0#1$( =`?( CTY 5 BW ZYT^V g ( ) )

    ?

    Reduction

    YNJ^[N c= BWBL r = CTY ZYT^VP I TC ` BW -/A ZYT^V SQ /%"0#1$( =`?

    WN_L < # CTY 5 BW ZYT^V g ( ) ?

  • 7/25/2019 ABAP - Novos Comandos

    35/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 37Public

    GroupingProcessing Table Lines in Groups - Example

    OTTV KL @'1IX-! KPPBZWBWZ CBNOJ3PQRSTO=U@'ID?ZYT^V SQ [TWJ c= d%NW U@'ID3@'-15& U EGf L%NW f

    d%NW U@'ID3@'-15& D qff L%NW ttNOPN -= U@'ID3@'-15& k gqfg ? ?

    KP[NWJBWZ

    KPPBZWBWZ [email protected]?9 dYBLN k $J41-0-( 6a 2 U@'ID3@'-15& 6$9

    NWJOTTV9NWJOTTV9

    Group flights by duration.

  • 7/25/2019 ABAP - Novos Comandos

    36/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 38Public

    ABAP 7.31 ABAP 7.40JKLKa 1-E LQVN --E)

    7/E OBbN OBWN TC 1-E9

    7/E3/ # u9 7/E3A # t9BWPNYL 7/E BWLT LKSON 1-E9

    7/E3/ # m9 7/E3A # p9BWPNYL 7/E BWLT LKSON 1-E9

    CBNOJ3PQRSTOP U7/ED OBbN OBWN TC 1-E9JKLK 7/G OBbN OBWN TC 1-G9OTTV KL 1-E KPPBZWBWZ U7/ED9

    7/G # -E:-(:-G= U7/ED ?9BWPNYL 7/G BWLT LKSON 1-G9

    NWJOTTV9

    JKLKa '/!!E)-5; LQVN !-(+M&

    WNd >'/!!E= ?3D.(:!(5&-X1+I=[TW\ c= 1-E r / # m s 3A ? ?9

    Simplified ABAP Code Through Expressions

  • 7/25/2019 ABAP - Novos Comandos

    37/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 39Public

    Expressions ABAP is Extensively Expression Enabled Pitfalls

    Obfuscation

    '>'#D>5:11='>'#D@/>-(-(5:11= G ee 1 ? 3 m H

    1-/Ar G s3!3`-/Ar ` # g/A>g s?3D5:11=

    '>'#D@/>-('#D>5:11= p ? ?3D15:11= q ?

    ??9

    Performance1-/AEr E s3/ # 1-/AGr E s3`91-/AEr E s3A # 1-/AGr E s3091-/AEr E s3> # 1-/AGr E s389

  • 7/25/2019 ABAP - Novos Comandos

    38/51

    Exercise

  • 7/25/2019 ABAP - Novos Comandos

    39/51

    Further News

  • 7/25/2019 ABAP - Novos Comandos

    40/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 42Public

    JSON ABAP and JSON

    JSON Support in sXML-Library

    JSON - JavaScript Object Notation, data format in text form for data exchange.

    JSON-XML - SAP-specific representation of JSON data in XML format

    asJSON - ABAP Serialization JSON,

    Canonical JSON representation for serialization/deserialization of ABAP data by transformation ID

    Backported to7.02!

  • 7/25/2019 ABAP - Novos Comandos

    41/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 43Public

    JSONReaders and Writers

    JSON to JSON-XML and Vice Versa

    JKLK=i!(+? # >':/A/;:>(.&;/ID>(+M&

  • 7/25/2019 ABAP - Novos Comandos

    42/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 44Public

    JSONTransformation ID

    JSON to JSON-XML and Vice Versa

    JKLK=i!(+? # j 2vLN_LvavhPTWv6 j9[KOO LYKWPCTYRKLBTW1. PT^Y[N _RO i!(+

    YNP^OL _RO JKLK=`5'?9>':.&5(:(4-;4-#D.1!;'/0:`5'= `5' ?9

    JKLK=`5'? # j U(Ai&>-DU!-< +/5vLN_LvDhPTWUk!--D j9JKLK=i!(+:7

  • 7/25/2019 ABAP - Novos Comandos

    43/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 45Public

    JSONasJSON

    ABAP to JSON and Vice Versa

    JKLK=-&`-? # jhPTWj9JKLK=i!(+:7

  • 7/25/2019 ABAP - Novos Comandos

    44/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 46Public

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

    AS ABAP Session Application Server 1 AS ABAP Session Application Server 2 AMC

    APC

    APC

    WebSocket Protocol

  • 7/25/2019 ABAP - Novos Comandos

    45/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 47Public

    ABAP ChannelsCharacteristcs

    ABAP Push Channel (APC)Integration of WebSocket (RFC 6455) into ABAPOutlook : SAPGUI Push Channel

    ABAP Messaging Channel (AMC)Inter-Session Messaging (Pub/Sub) in ABAP

    Binding AMC channels to ABAP sessions

    Collaboration (AMC & APC)Binding AMC channels to APC (WebSocket) Connections

    Goal: Replace polling by event-driven approach whenever possible

  • 7/25/2019 ABAP - Novos Comandos

    46/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 48Public

    ABAP Channels ABAP Messaging Channels

    Enable message based communications between ABAP programs across the boundaries of application servers.

    [KPL 1@:/5>:5&!!/I&:;&':/5>:>X/++&':5/+/I&':/5>:>X/++&':5/+/I&(+!45&< =1:/;;'1>/-1(+:1. # gJNRT:KR[g1:>X/++&':1. # gk.&5(:-&`-g

    ?3D !-/

  • 7/25/2019 ABAP - Novos Comandos

    47/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 49Public

    ABAP Channels ABAP Push Channels ABAP side

    Enable bidirectional communications between ABAP programs and theinternet using the WebSocket protocol. APCs can be connected to AMCs.

    RNL%TJ 1@:/;>:7!:&`-&+!1(+F (+:5&!!/I& 9999

    BC /5>:@'/I # /A/;:-:5&!!/I&:;&':/5>:>X/++&':5/+/I&

  • 7/25/2019 ABAP - Novos Comandos

    48/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 50Public

    ABAP Channels ABAP Push Channels Internet side

  • 7/25/2019 ABAP - Novos Comandos

    49/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 51Public

    Further NewsSecurity Checks

    SLIN_SEC JKLK +/5& LQVN !-4!-(5&4!-(5 dBL% NRVLQ bNQ9

    >':.&5(:1+;4-#D

    >':.&5(:(4-;4-#D.1!;'/0= gd

  • 7/25/2019 ABAP - Novos Comandos

    50/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 52Public

    Further News ABAP Doc for ABAP in Eclipse

    Inline Documentation of Source Code based Development Objects

    F2

  • 7/25/2019 ABAP - Novos Comandos

    51/51

    2014 SAP SE or an SAP affiliate company. All rights reserved. 53Public

    DocumentationSee ABAP Keyword Documentation

    Classic ADT