Code: Alles auswählen.
TYPES: BEGIN OF GY_WA,
kunnr type kunnr,
name1 type name1,
references type standard table of kunnr,
END OF GY_WA,
GY_ITAB TYPE STANDARD TABLE OF GY_WA WITH EMPTY KEY.
DATA: gs_wa type gy_wa,
gt_itab type gy_itab.
Code: Alles auswählen.
select kna1~kunnr, kna1~name1, knvp~kunnr as line of references
from kna1
inner join knvp on knvp~kunn2 = kna1~kunnr
knvp~parvw = 'V1'
into corresponding fields of table @gt_itab.
Code: Alles auswählen.
TYPES: BEGIN OF GY_WA,
KUNNR TYPE KUNNR,
NAME1 TYPE NAME1,
REFERENCES TYPE STANDARD TABLE OF KUNNR WITH EMPTY KEY,
END OF GY_WA,
GY_ITAB TYPE STANDARD TABLE OF GY_WA WITH EMPTY KEY.
DATA: GS_WA TYPE GY_WA,
GT_ITAB TYPE GY_ITAB.
SELECT KUNNR NAME1 FROM KNA1
INTO CORRESPONDING FIELDS OF TABLE GT_ITAB.
LOOP AT GT_ITAB INTO GS_WA.
SELECT KUNNR INTO TABLE GS_WA-REFERENCES FROM KNVP
WHERE KUNN2 = GS_WA-KUNNR
AND PARVW = 'V1'.
MODIFY GT_ITAB FROM GS_WA.
ENDLOOP.
Und dann per Loop at group zusammenfügen?nickname8 hat geschrieben:Oder man denkt über einen Join nach, wenn die Daten eh zusammenhängen. Wenn man möchte, kann man die Daten dann anschließend auseinanderpflücken und in die gewünschte tiefe Tabelle einfügen.
Klingt interessant. Kannst Du dazu nochmal den Code posten?zornbruder hat geschrieben:Ich arbeite mit einem CDS der den ganzen Join übernimmt. Bei dem gesamten Konstrukt handelt es sich um 9 zusammenhängenden Tabellen und etliche Felder.
Außerdem benötige ich auch noch weitere Referenzen (dementsprechend heißt die tabelle nicht referenced sondern ref_v1_tt, ref_we_tt, ref_*_tt etc. ).
Die besagten habe ich mir jetzt über eine Assoziation im CDS zur Verfügung gestellt und greife in einem SELECT. ENDSELECT. Konstrukt darauf zu, mal schauen, was die Laufzeit dazu so sagt...
Code: Alles auswählen.
define view z_customer_data as select from knvp as origin
left outer join knvk on knvk.kunnr = origin.kunn2
and knvk.pafkt = 'Z01'
inner join kna1 on kna1.kunnr = origin.kunn2
left outer join z_customer_adressdata as knvkAddr on knvkAddr.addrnumber = knvk.adrnd "entweder sind abweichende Daten vorhanden
left outer join z_customer_adressdata as kna1Addr on kna1Addr.addrnumber = kna1.adrnr "oder man nimmt die ursprungsdaten
association [0..*] to z_b2b_reference as _ref_we on _ref_we.parvw = 'WE'
and _ref_we.ag = origin.kunnr
association [0..*] to z_reference as _ref_re on _ref_re.parvw = 'RE'
and _ref_re.ag = origin.kunnr
association [0..*] to z_reference as _ref_v1_partner on _ref_v1_partner.parvw = 'V1'
and _ref_v1_partner.kunnr = origin.kunnr
association [0..*] to z_reference as _ref_v1_parent on _ref_v1_parent.parvw = 'V1'
and _ref_v1_parent.ag = origin.kunnr
{
key origin.kunnr,
key case when origin.parvw = 'WE' then LTRIM(origin.kunn2, '0') else '' end as kunwe,
key case when origin.parvw = 'RE' then LTRIM(origin.kunn2, '0') else '' end as kunre,
coalesce( knvk.anred, kna1.anred) as anred,
coalesce( knvk.name1, kna1.name1) as name1,
kna1.name2,
coalesce( knvk.adrnd, kna1.adrnr ) as adrnr,
coalesce( knvk.telf1, kna1.telf1) as telf1,
coalesce( knvkAddr.mob_number, kna1Addr.mob_number ) as mob_number,
coalesce( knvkAddr.telfx, kna1Addr.telfx ) as telfx,
coalesce( knvkAddr.smtp_addr, kna1Addr.smtp_addr ) as smtp_addr,
coalesce( knvkAddr.comm_type, kna1Addr.comm_type ) as comm_type,
coalesce( knvkAddr.street, kna1Addr.street ) as street,
coalesce( knvkAddr.house_num1, kna1Addr.house_num1 ) as house_num1,
coalesce( knvkAddr.city1, kna1Addr.city1 ) as city1,
coalesce( knvkAddr.post_code1, kna1Addr.post_code1 ) as post_code1,
coalesce( knvkAddr.region, kna1Addr.region ) as region,
coalesce( knvkAddr.country, kna1Addr.country ) as country,
coalesce( knvkAddr.langu, kna1Addr.langu ) as langu,
kna1.loevm,
_ref_we, _ref_re, _ref_v1_partner, _ref_v1_parent
}
where ( origin.parvw = 'WE' or origin.parvw = 'RE' or origin.parvw = 'AG' )
Code: Alles auswählen.
define view z_reference as select from knvp
inner join cabn on atnam = 'ISB2B'
inner join ausp on ausp.atinn = cabn.atinn
and ausp.atwrt = 'X' {
key knvp.kunnr as ag,
key knvp.kunn2 as kunnr,
knvp.parvw,
ausp.atinn,
ausp.atwrt
} where knvp.kunn2 <> knvp.kunnr
Code: Alles auswählen.
define view z_customer_adressdata as select from adrc
left outer join adr6 on adr6.addrnumber = adrc.addrnumber
and adr6.persnumber = ''
and adr6.home_flag = 'X'
left outer join adr2 on adr2.addrnumber = adrc.addrnumber
and adr2.r3_user = '3'
and adr2.persnumber = ''
left outer join adr12 on adr12.addrnumber = adrc.addrnumber
and adr12.uri_type = 'HPG'
and adr12.flgdefault = 'X'
and adr12.persnumber = ''
left outer join adr3 on adr3.addrnumber = adrc.addrnumber
and adr3.flgdefault = 'X'
and adr3.persnumber = ''
inner join t002 on t002.spras = adrc.langu {
adrc.addrnumber,
adrc.street,
adrc.city1,
adrc.post_code1,
adrc.country,
adrc.region,
adrc.house_num1,
t002.laiso as langu,
adr2.tel_number as mob_number,
adr3.faxnr_long as telfx,
adr6.smtp_addr,
adr12.uri_srch as comm_type
}
Code: Alles auswählen.
SELECT DISTINCT kunnr, kunwe, kunre, anred,name1,
name2, region, telf1, loevm, street,
city1,post_code1, country, house_num1,
langu, mob_number, telfx, smtp_addr, comm_type
FROM z_customer_data
WHERE ( kunnr IN @lt_b2b_rr
OR kunnr IN @lt_v1_rr )
AND country IN @so_land1
ORDER BY kunnr, street, house_num1, city1,
post_code1, country, telf1, telfx
INTO CORRESPONDING FIELDS OF @gs_kunden.
IF gs_kunden-kunre IS INITIAL AND gs_kunden-kunwe IS INITIAL.
SELECT DISTINCT ltrim( \_ref_re-kunnr, '0' ) AS kunnr ##ASSOC_TO_N_OK[_REF_RE]
FROM z_customer_data
WHERE kunnr = @gs_kunden-kunnr
INTO CORRESPONDING FIELDS OF TABLE @gs_kunden-ref_re.
SELECT DISTINCT ltrim( \_ref_we-kunnr, '0' ) AS kunnr ##ASSOC_TO_N_OK[_REF_WE]
FROM z_customer_data
WHERE kunnr = @gs_kunden-kunnr
INTO CORRESPONDING FIELDS OF TABLE @gs_kunden-ref_we.
SELECT DISTINCT ltrim( \_ref_v1_partner-ag, '0' ) AS kunnr ##ASSOC_TO_N_OK[_REF_v1_PARTNER]
FROM z_customer_data
WHERE kunnr = @gs_kunden-kunnr
INTO CORRESPONDING FIELDS OF TABLE @gs_kunden-v1_partner.
SELECT DISTINCT ltrim( \_ref_v1_parent-kunnr, '0' ) AS kunnr ##ASSOC_TO_N_OK[_REF_v1_PARENT]
FROM z_customer_data
WHERE kunnr = @gs_kunden-kunnr
INTO CORRESPONDING FIELDS OF TABLE @gs_kunden-v1_parent.
ENDIF.
APPEND gs_kunden TO gt_kunden.
FREE gs_kunden.
ENDSELECT.
Folgende Benutzer bedankten sich beim Autor zornbruder für den Beitrag:
Haubi