0% found this document useful (0 votes)
50 views

ABAP On HANA - Query

The document discusses different techniques for using select statements in ABAP including passing select options to AMDP classes, handling all entries scenarios, using nested selects, case statements, converting internal tables to select options, and excluding values by comparing tables.

Uploaded by

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

ABAP On HANA - Query

The document discusses different techniques for using select statements in ABAP including passing select options to AMDP classes, handling all entries scenarios, using nested selects, case statements, converting internal tables to select options, and excluding values by comparing tables.

Uploaded by

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

Contents

Pass Select Option to AMDP Class......................................................................................................................................................................................................... 1


For All Entries Scenario in AMDP........................................................................................................................................................................................................... 2
Nested Select......................................................................................................................................................................................................................................... 3
Using Case in Select Statement............................................................................................................................................................................................................. 3
Convert Internal Table to Select Option................................................................................................................................................................................................ 4
Exclude Set of Values Comparing Table................................................................................................................................................................................................. 4

Pass Select Option to AMDP Class


Step 1:
*
TRY.
CALL METHOD cl_shdb_seltab=>combine_seltabs
EXPORTING
it_named_seltabs = VALUE #( ( name = 'BUKRS'
dref = REF #( s_bukrs[] ) )
( name = 'GKONT'
dref = REF #( s_lifnr[] ) )
( name = 'ZUORD'
dref = REF #( s_zuord[] ) )
( name = 'BLART'
dref = REF #( s_blart[] ) ) )
RECEIVING
rv_where = DATA(i_where).
CATCH cx_shdb_exception INTO oref_cx_shdb_exception.
sy-msgty = sy-abcde+18(1).
MESSAGE oref_cx_shdb_exception->get_text( ) TYPE sy-msgty.
RETURN.
ENDTRY.
*

Step 2:
CALL METHOD zcbs_cl_amdp_ers_report=>get_esr ( AMDP Class )
EXPORTING
i_langu = sy-langu
i_mandt = sy-mandt
i_where = i_where
CHANGING
e_esr = it_es1.
*

Step 3:
e_esr = apply_filter( :et_esr, :i_where );

For All Entries Scenario in AMDP


e_int_memo = SELECT vbkpf.mandt,
VBKPF.bukrs,
VBKPF.belnr,
VBKPF.gjahr,
VBKPF.blart,
VBKPF.budat,
vbsegs.shkzg,
vbsegs.saknr as hkont,
SUM ( vbsegs.dmbtr ) as dmbtr,
vbsegs.SWAER,
skb1.hbkid,
skb1.hktid,
t012k.bankn,
t012t.text1
from vbkpf as vbkpf inner join
vbsegs as vbsegs on (vbsegs.bukrs = vbkpf.bukrs and
vbsegs.belnr = vbkpf.belnr and
vbsegs.gjahr = vbkpf.gjahr)
inner join skb1 as skb1 on (skb1.saknr = vbsegs.saknr AND
skb1.bukrs = :i_bukrs AND
skb1.mandt = :i_client)
LEFT OUTER JOIN t012k as t012k on (t012k.hbkid = skb1.hbkid and
t012k.hktid = skb1.hktid and
t012k.bukrs = vbkpf.bukrs AND
t012k.mandt = :i_client )
LEFT OUTER JOIN t012t as t012t on (t012t.hbkid = t012k.hbkid and
t012t.hktid = skb1.hktid and
t012t.bukrs = vbkpf.bukrs and
t012t.spras = :i_langu)
where vbkpf.bukrs = :i_bukrs
and vbkpf.gjahr = :i_gjahr
and vbkpf.belnr = :i_belnr
GROUP BY vbkpf.mandt, VBKPF.bukrs, VBKPF.belnr, VBKPF.gjahr, VBKPF.blart,
VBKPF.budat, vbsegs.shkzg, vbsegs.saknr,vbsegs.SWAER,
skb1.hbkid,skb1.hktid,t012k.bankn,t012t.text1
ORDER BY VBKPF.belnr,vbsegs.shkzg;

e_t012 = SELECT t012.BUKRS,


t012.HBKID,
t012.BANKS,
t012.BANKL,
tiban.bankn,
tiban.IBAN
FROM t012 AS t012
LEFT OUTER JOIN tiban as tiban on (tiban.bankl = t012.bankl and
tiban.bankn IN (select bankn FROM :e_int_memo) AND
tiban.BANKS = t012.banks AND
tiban.mandt = i_client)
WHERE t012.BUKRS = :i_bukrs
AND t012.mandt = :i_client
AND t012.HBKID IN (select hbkid FROM :e_int_memo)
GROUP BY t012.BUKRS,
t012.HBKID,
t012.BANKS,
t012.BANKL,
tiban.bankn,
tiban.IBAN;

Nested Select

lt_lfa1 = SELECT lifnr,


name1
FROM lfa1
WHERE lifnr IN ( SELECT lifnr
FROM payr
WHERE mandt = :l_mandt
AND zbukr = :l_zbukr
AND vblnr = :l_vblnr
AND gjahr = :l_gjahr );

Using Case in Select Statement


lt_log = select distinct
t1.pernr as pernr,
t1.lg_date as lg_date,
t1.time_e as entry,
t1.term_id as term_id,
t2.terid as term_id1,
( CASE WHEN t1.pernr = t2.pernr
AND t1.lg_date = t2.ldate
AND t1.lg_time = t2.ltime
AND t1.time_e = t2.satza
AND t1.day_ass = t2.dallf
THEN 'Success - The data has been uploaded'
ELSE 'Failure - The data has some error'
END ) as status
from :it_rec as t1
INNER JOIN teven as t2 on t1.pernr = t2.pernr and t1.lg_date = t2.ldate and t1.lg_time = t2.ltime;

Convert Internal Table to Select Option


*/ ---> Get GL data.
class-methods fetch_gl_data
importing
value(iv_mandt) type eqkt-mandt
EXporting
Value(it_all_gl) type IT_TY_GL_NUM
Value(E_it_gl_slop) TYPE RSELOPTION.

* / -> converting the internal table to select option in DB level.


E_it_gl_slop = Select DISTINCT
'I' AS sign,
'NE' AS Option,
KTNAFG AS low ,
' ' AS High
FROM :it_all_gl AS it ;

Exclude Set of Values Comparing Table


Step 1: Convert the internal table to Select Option then use apply filter to ignore the value.

You might also like