Chapter 10_ABAP Open SQL Extensions

Embed Size (px)

Citation preview

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    1/35

    IBM Global Business Services

    IBM Corporation 2013ABAP Open SQL !tensions " #ec$200%

    ABAP Open SQL Extensions

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    2/35

    IBM Global Business Services

    IBM Corporation 20132 #ec$200%ABAP Open SQL !tensions "

    Ob&ectives

    '(e participants )ill be able to* #escribe (o) to use t(e +ollo)in, in an ABAP Pro,ra-*

    SLC' #IS'I.C' State-ent

    #/na-ic Clause

    Concatenate State-ent

    oin 4Inner vs5 Le+t Outer6 Aliases

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    3/35

    IBM Global Business Services

    IBM Corporation 20133 #ec$200%ABAP Open SQL !tensions "

    REPORT YAP00007.

    DATA: CNTRY TYPE YTABNA-COUNTRY.

    SELECT DSTNCT COUNTRY

    !RO" Yt#$n# NTO %CNTRY&.

    'RTE: ( CNTRY.

    ENDSELECT.

    '(e SLC' #IS'I.C' State-ent

    Usin) SELECT

    DSTNCT* it

    is possi$+eto e+i,in#te p+i/#te

    o1s o, te

    es+t set.

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    4/35

    IBM Global Business Services

    IBM Corporation 20134 #ec$200%ABAP Open SQL !tensions "

    REPORT YAP00005.

    DATA: TOTAL TYPE *

    "A6SALES TYPE YTABNA-SALES*

    A89SALES TYPE YTABNA-SALES*

    "NSALES TYPE YTABNA-SALES.

    SELECT COUNT% DSTNCT COUNTRY &

    "A6% SALES &A89% SALES &

    "N% SALES &

    !RO" t#$n#

    NTO %TOTAL* "A6SALES* A89SALES* "NSALES&

    ';ERE COUNTRY

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    5/35

    IBM Global Business Services

    IBM Corporation 2013 #ec$200%ABAP Open SQL !tensions "

    '(e #/na-ic ClauseREPORT YAP0000.

    PARA"ETERS:

    ';ERECL%72& DE!AULT >COUNTRY >>USA?? ?*';ERECL2%3& DE!AULT >OR?*

    ';ERECL3%72& DE!AULT >COUNTRY >>9B?? ?.

    TYPE: BE9N O! TABRECORD*

    TE6T%72& TYPE C*

    END O! TABRECORD.

    DATA: ';ERETAB TYPE STANDARD TABLE O!

    TABRECORD NTAL SE 3*'A';ERETAB TYPE TABRECORD*

    'AYTABNA TYPE YTABNA.

    'A';ERETAB-TE6T ';ERECL.

    APPEND 'A';ERETAB TO ';ERETAB.

    CLEAR 'A';ERETAB.

    'A';ERETAB-TE6T ';ERECL2.

    APPEND 'A';ERETAB TO ';ERETAB.

    CLEAR 'A';ERETAB.'A';ERETAB-TE6T ';ERECL3.

    APPEND 'A';ERETAB TO ';ERETAB.

    SELECT F !RO" YTABNA NTO 'AYTABNA ';ERE

    %';ERETAB&.

    'RTE: ( 'ATABNA-COUNTRY* 'ATABNA-D.

    ENDSELECT.

    Te p##,etes

    entee ,#Ge p te

    /ontents o te

    ';ERE /+#se. Te

    se #s te option o

    /#n)in) te

    /onitions #n

    n#,i/#++ ee/tin)

    1i/ 1# tepo)#, 1i++ exe/te.

    An inten#+ t#$+e is /e#te

    1i/ o+s te ';ERE

    /+#se nti+ it is se in te

    SELECT st#te,ent.

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    6/35

    IBM Global Business Services

    IBM Corporation 2013H #ec$200%ABAP Open SQL !tensions "

    CO.CA'.A' State-entREPORT YAP0000.

    PARA"ETERS:

    ';ERECL%72& DE!AULT >COUNTRY > >USA? ? ?*';ERECL2%3& DE!AULT >OR?*

    ';ERECL3%72& DE!AULT >COUNTRY > >9B? ? ?.

    TYPE: BE9N O! TABRECORD*

    TE6T%72&*

    END O! TABRECORD.

    DATA: ';ERETAB TYPE STANDARD TABLE O! TABRECORD

    NTAL SE 3*

    'A';ERETAB TYPE TABRECORD*

    'AYTABNA TYPE YTABNA*

    TYTABNA TYPE STANDARD TABLE O! YTABNA.

    CONCATENATE ';ERECL ';ERECL2 ';ERECL3

    NTO 'A';ERETAB-TE6T SEPARATED BY SPACE.

    APPEND 'A';ERETAB TO ';ERETAB.SELECT F !RO" t#$n# NTO TABLE TYTABNA ';ERE

    %';ERETAB&.

    LOOP AT TYTABNA NTO 'AYTABNA.

    'RTE: ( 'AYTABNA-COUNTRY* 'AYTABNA-D

    ENDLOOP.

    CONCATENATE

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    7/35

    IBM Global Business Services

    IBM Corporation 20137 #ec$200%ABAP Open SQL !tensions "

    9ariations on t(e I.'O Clause

    REPORT YAP000.

    DATA: TAB TYPE STANDARD TABLE O!

    t#$n# NTAL SE *

    'ATAB TYPE t#$n#.

    SELECT F !RO" t#$n#

    NTO TABLE TAB

    PACIA9E SE .

    LOOP AT TAB NTO 'ATAB.

    'RTE: ( 'ATAB-COUNTRY* 'ATAB-D.

    ENDLOOP.ENDSELECT.

    SELECT F !RO"

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    8/35

    IBM Global Business Services

    IBM Corporation 20135 #ec$200%ABAP Open SQL !tensions "

    REPORT YAP0002.

    PARA"ETERS: TABNA"E%H& DE!AULT >TABNAJ.

    DATA: TABLELNE%240&.

    SELECT F !RO" %TABNA"E& NTO TABLELNE.

    'RTE: ( TABLELNE.

    ENDSELECT.

    Speci+/in, t(e 'able .a-e at unti-e

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    9/35

    IBM Global Business Services

    IBM Corporation 2013 #ec$200%ABAP Open SQL !tensions "

    #e-onstration

    7sin, a :/na-ic select state-ent in a custo- ABAP pro,ra-5

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    10/35

    IBM Global Business Services

    IBM Corporation 20130 #ec$200%ABAP Open SQL !tensions "

    Practice

    7sin, a :/na-ic select state-ent in a custo- ABAP pro,ra-5

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    11/35

    IBM Global Business Services

    IBM Corporation 2013 #ec$200%ABAP Open SQL !tensions "

    C7SO Processin,

    OPEN CURSOR K'T; ;OLD

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    12/35

    IBM Global Business Services

    IBM Corporation 20132 #ec$200%ABAP Open SQL !tensions "

    #eclarin, an: OP.in, a C7SO

    REPORT YAP0003.DATA: TABCUR TYPE CURSOR*

    BE9N O! YTABNA'A*

    NA"E TYPE YTABNA-NA"E*

    COUNTRY TYPE YTABNA-COUNTRY*

    END O! YTABNA'A.

    OPEN CURSOR TABCUR !ORSELECT NA"E COUNTRY !RO" t#$n#.

    DO.

    !ETC; NE6T CURSOR TABCUR NTO YTABNA'A.

    ! SY-SUBRC

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    13/35

    IBM Global Business Services

    IBM Corporation 20133 #ec$200%ABAP Open SQL !tensions "

    REPORT YAP0003.

    DATA: TABCUR TYPE CURSOR*BE9N O! YTABNA'A*

    NA"E TYPE YTABNA-NA"E*

    COUNTRY TYPE YTABNA-COUNTRY*

    END O! YTABNA'A.

    OPEN CURSOR TABCUR !ORSELECT NA"E COUNTRY !RO" t#$n#.

    DO.

    !ETC; NE6T CURSOR TABCUR NTO YTABNA'A.

    ! SY-SUBRC

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    14/35

    IBM Global Business Services

    IBM Corporation 20134 #ec$200%ABAP Open SQL !tensions "

    CLOSI.G t(e C7SO

    REPORT YAP0003.

    DATA: TABCUR TYPE CURSOR*BE9N O! YTABNA'A*

    NA"E TYPE YTABNA-NA"E*

    COUNTRY TYPE YTABNA-COUNTRY*

    END O! YTABNA'A.

    OPEN CURSOR TABCUR !ORSELECT NA"E COUNTRY !RO" t#$n#.

    DO.

    !ETC; NE6T CURSOR TABCUR NTO YTABNA'A.

    ! SY-SUBRC

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    15/35

    IBM Global Business Services

    IBM Corporation 2013 #ec$200%ABAP Open SQL !tensions "

    #e-onstration

    7sin, cursor in a pro,ra- to retrieve :ata +ro- a :atabase table 5

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    16/35

    IBM Global Business Services

    IBM Corporation 2013H #ec$200%ABAP Open SQL !tensions "

    Practice

    7sin, cursor in a pro,ra- to retrieve :ata +ro- a :atabase table 5

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    17/35

    IBM Global Business Services

    IBM Corporation 20137 #ec$200%ABAP Open SQL !tensions "

    oins #e ,oe ei/ient t#n +o)i/#+ #t#$#ses #n neste se+e/ts.

    Te #//ess ,+tip+e t#$+es 1it one se+e/t st#te,ent.

    oins* (/ )e s(oul: use t(e- ;

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    18/35

    IBM Global Business Services

    IBM Corporation 20135 #ec$200%ABAP Open SQL !tensions "

    Inner oins

    S!L9;TSCARR

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    19/35

    IBM Global Business Services

    IBM Corporation 2013 #ec$200%ABAP Open SQL !tensions "

    Inner oins S/nta!

    SELECT

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    20/35

    IBM Global Business Services

    IBM Corporation 201320 #ec$200%ABAP Open SQL !tensions "

    '(e #rivin, table

    SELECT s/#/#n#,e s+i)t/#i s+i)t/onni

    s+i)t+#te

    NTO %/#i* /onni* #te* /#n#,e&

    !RO" s/# NNER ON s+i)t

    ON s/#/#i s+i)t/#i.

    'RTE: ( /#i* /onni* #te* /#n#,e.

    ENDSELECT.

    IBM Gl b l B i S i

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    21/35

    IBM Global Business Services

    IBM Corporation 20132 #ec$200%ABAP Open SQL !tensions "

    Le+t Outer oins

    S!L9;TSCARR

    IBM Gl b l B i S i

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    22/35

    IBM Global Business Services

    IBM Corporation 201322 #ec$200%ABAP Open SQL !tensions "

    Le+t Outer oin S/nta!

    SELECT

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    23/35

    IBM Global Business Services

    IBM Corporation 201323 #ec$200%ABAP Open SQL !tensions "

    Open SQL S/nta! estrictions

    Te snt#x o oins #@e $een )i@en /et#in esti/tions inoe to ense t#t te po/e te s#,e es+ts o #++ SAPsppote #t#$#ses.

    IBM Global B siness Ser ices

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    24/35

    IBM Global Business Services

    IBM Corporation 201324 #ec$200%ABAP Open SQL !tensions "

    e:un:anc/

    L!A BSI

    IBM Global Business Services

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    25/35

    IBM Global Business Services

    IBM Corporation 20132 #ec$200%ABAP Open SQL !tensions "

    oins Accessin, More t(an ')o 'ables

    SELECT

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    26/35

    IBM Global Business Services

    IBM Corporation 20132H #ec$200%ABAP Open SQL !tensions "

    Aliases

    SELECT A/#n#,e

    B/#i

    B/onni

    B+#te NTO %/#i* /onni* #te* /#n#,e&

    !RO" s/# AS A NNER ON s+i)t AS B

    ON s/#/#i s+i)t/#i.

    'RTE: ( /#i* /onni* #te* /#n#,e.

    ENDSELECT.

    IBM Global Business Services

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    27/35

    IBM Global Business Services

    IBM Corporation 201327 #ec$200%ABAP Open SQL !tensions "

    Sub

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    28/35

    IBM Global Business Services

    IBM Corporation 201325 #ec$200%ABAP Open SQL !tensions "

    Sub

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    29/35

    IBM Global Business Services

    IBM Corporation 20132 #ec$200%ABAP Open SQL !tensions "

    avin, Clause

    List #++ Lt#ns# CONNDs 1ee te s, o

    LU99'E9;T is < 20*000.

    IBM Global Business Services

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    30/35

    IBM Global Business Services

    IBM Corporation 201330 #ec$200%ABAP Open SQL !tensions "

    avin, Clause S/nta!=!a-ple

    SELECT carrid connidCOUNT% F& SU"% luggweight &

    NTO %carrid, connid, count, sum_weight& !RO" sbook

    ';ERE carrid 'LH'9ROUP BY carrid connid

    ;A8N9 SU"% luggweight& = 25.

    'RTE:( carrid, connid, count, sum_weight.

    ENDSELECT.

    IBM Global Business Services

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    31/35

    IBM Global Business Services

    IBM Corporation 20133 #ec$200%ABAP Open SQL !tensions "

    #e-onstration

    7sin, >OI.? in select state-ent o+ a custo- ABAP pro,ra- retrieve :ata +ro-t)o or -ore relate: :atabase tables5

    IBM Global Business Services

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    32/35

    IBM Global Business Services

    IBM Corporation 201332 #ec$200%ABAP Open SQL !tensions "

    Practice

    7sin, >OI.? in select state-ent o+ a custo- ABAP pro,ra- retrieve :ata +ro-t)o or -ore relate: :atabase tables5

    IBM Global Business Services

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    33/35

    IBM Global Business Services

    IBM Corporation 201333 #ec$200%ABAP Open SQL !tensions "

    Su--ar/

    SLC' #IS'I.C' option is use: to return onl/ one recor: +or eac( uni

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    34/35

    IBM Global Business Services

    IBM Corporation 201334 #ec$200%ABAP Open SQL !tensions "

    Su--ar/ 4Cont:56

    '(e C7SO :ata t/pe is t(en associate: )it( a SLC' +ro- a :atabase tablein t(e OP. state-ent5

    In:ivi:ual ro)s o+ t(e result set are processe: usin, a 8'C state-ent

    se

  • 8/9/2019 Chapter 10_ABAP Open SQL Extensions

    35/35

    Questions

    (at are t(e a,,re,ate +unctions; An: )(/ t(ese are use: in t(e selectstate-ent;

    (at is t(e purpose o+ usin, >CO.CA'.A'? state-ent;

    (at are t(e :i++erent steps o+ cursor processin,;

    o) :ata can be retrieve: +ro- t)o or -ultiple relate: :atabase table in sin,le

    select;