"Personally I’d suggest using CDS in first instance and go for AMDP if you need features such as scripting or to extract that last little squeak in performance.
In your scenario, you can do the JOINs in one or more CDS view(s) and then do a SELECT with FOR ALL ENTRIES or a temporary table. A great reason for CDS is you can build up complex joins in layers of multiple views, which is easier to build and test than a single complex SELECT with a bunch of JOINs.
Have a look at some of the SAP CDS views for this area, you might even find one that already supplies most of what you need and you can then either extend it or build your own view on top of it."
METHOD get_so_co_detail BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING vbak vbap
vbkd vbep tvagt
vbpa kna1.
tmp1 = apply_filter( vbap, :iv_where);
et_log = select
a.MANDT,
a.VBELN ,
b.POSNR,
b.matnr,
case
when b.gbsta = 'A'
then 'Open'
when b.gbsta= 'B'
then 'Open'
when b.gbsta = 'C'
then 'Closed'
end as stat,
c.bezei as rej,
concat( b.werks, concat( '/', b.lgort ) ) as werk_sloc,
b.ERDAT,
a.VKORG,
b.ERNAM,
vbep.EDATU,
b.KWMENG,
b.VRKME,
vbkd.BSTKD,
ship.kunnr as shipto,
kna1.name1 as shipto_name,
kna1.ORT01 as city,
kna1.regio as region,
merch.kunnr as merch,
z2_kna1.name1 as merch_name,
a.kunnr as soldto,
soldto.name1 as soldto_name
from
:tmp1 as b
inner join vbak as a on a.mandt = b.mandt and
a.vbeln = b.vbeln
left outer join tvagt as c
on a.mandt = c.mandt and
b.abgru = c.abgru and
c.spras = 'E'
left outer join vbep as vbep
on a.mandt = vbep.mandt and
b.vbeln = vbep.vbeln and
b.posnr = vbep.posnr and
vbep.bmeng > 0
left outer join vbkd as vbkd
on a.mandt = vbkd.mandt and
b.vbeln = vbkd.vbeln and
vbkd.posnr = '000000'
left outer join vbpa as ship
on a.mandt = ship.mandt and
a.vbeln = ship.vbeln and
ship.posnr = '000000' and
ship.parvw = 'WE'
left outer join kna1 as kna1
on a.mandt = kna1.mandt and
ship.kunnr = kna1.kunnr
left outer join vbpa as merch
on a.mandt = merch.mandt and
a.vbeln = merch.vbeln and
b.posnr = merch.posnr and
merch.parvw = 'Z2'
left outer join kna1 as z2_kna1
on a.mandt = z2_kna1.mandt and
merch.mandt = z2_kna1.mandt and
merch.kunnr = z2_kna1.kunnr
left outer join kna1 as soldto
on a.mandt = soldto.mandt and
a.kunnr = soldto.kunnr
method fill_dates.
data: lv_from type dats,
lv_to type dats,
lv_one(10),
lv_between(30).
lv_from = im_from.
lv_to = im_to.
* Explode BOM
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
auskz = abap_true
brems = abap_true
capid = 'PP01'
datuv = sy-datlo " Valid-From Date
mktls = abap_true
mehrs = abap_true
mtnrv = ls_stko-matnr
stlal = ls_stko-stlal
stlan = ls_stko-stlan
werks = ls_stko-werks
TABLES
stb = lt_stb
* CONVERT the SELECTION to where clause
DATA(lv_where) = cl_shdb_seltab=>combine_seltabs(
it_named_seltabs = VALUE #(
( name = 'VBELN' dref = REF #( s_vbeln[] ) )
( name = 'POSNR' dref = REF #( s_item[] ) )
)
iv_client_field = 'MANDT'
).
* Get contract details
TRY.
zcl_get_ingred_log=>get_so_co_detail(
EXPORTING
iv_where = lv_where
iv_client = sy-mandt
IMPORTING
et_log = DATA(lt_result) ).
CATCH cx_amdp_error INTO DATA(amdp_error).
cl_demo_output=>display( amdp_error->get_text( ) ).
RETURN.
ENDTRY.
gs_variant-report = sy-repid.
DATA: it_fieldcat TYPE lvc_t_fcat,
x_fieldcat TYPE lvc_s_fcat.
x_fieldcat-col_pos = 1.
x_fieldcat-seltext = 'APPLIED'.
x_fieldcat-fieldname = 'APPLIED'.
x_fieldcat-edit = abap_true.
x_fieldcat-checkbox = abap_true.
x_fieldcat-tabname = 'GT_SALES_DETAIL'.
APPEND x_fieldcat TO it_fieldcat.
CALL METHOD grid1->set_table_for_first_display
EXPORTING
i_bypassing_buffer = abap_true
i_structure_name = 'ZINGRD_CONTRACT'
is_print = gs_print
is_layout = gs_layout
it_toolbar_excluding = lt_exc
i_save = gv_save
is_variant = gs_variant
CHANGING
it_fieldcatalog = it_fieldcat
it_outtab = gt_sales_detail.
gv_check = abap_true.
CALL METHOD cl_gui_control=>set_focus EXPORTING control = grid1.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
5 | |
4 | |
4 | |
4 | |
3 | |
2 | |
2 | |
2 | |
2 |