‎2011 Apr 29 10:22 AM
Hello Experts,
i wonder about the correct notation of a select statement.
I have an internal table it_zoll including two structures as defined below.
The select is a join on the two tables zollp and zolls. As coded below the select is syntactically correct, but the fields
in the nested structures are not filled ....
Any ideas how to write the select statement ? (The internal table it_zoll must have the nested structures for other reasons ..)
Declaration:
TYPES: BEGIN OF ty_zollp,
belnr TYPE zollp-belnr,
werks TYPE zollp-werks,
gebnr TYPE zollp-gebnr,
...
...
END OF ty_zollp.
TYPES: BEGIN OF ty_zolls,
grnum type zolls-grnum,
werks type zolls-werks,
name1 TYPE zolls-name1,
...
...
END OF ty_zolls.
DATA: BEGIN OF wa_zoll.
DATA: zollp type ty_zollp.
DATA: zolls type ty_zolls.
DATA: END OF wa_zoll.
DATA: it_zoll LIKE TABLE OF wa_zoll.
Select:
SELECT
zollp~belnr zollp~werks zollp~gebnr
zolls~grnum zolls~werks zolls~name1
FROM zollp
JOIN zolls ON zolls~werks = zollp~werks
AND zolls~grnum = zollp~grnum
INTO CORRESPONDING FIELDS OF TABLE it_zoll
WHERE zollp~werks = werks
AND zollp~gebnr IN s-gebnr
AND ...
.
Thank you !
‎2011 Apr 29 11:07 AM
‎2011 Apr 29 10:41 AM
have you tried it without TYPES?
and : i nclude structure...
grx
Andreas
‎2011 Apr 29 11:00 AM
DATA: BEGIN OF ty_zollp,
belnr TYPE zollp-belnr,
werks TYPE zollp-werks,
gebnr TYPE zollp-gebnr,
...
...
END OF ty_zollp.
DATA: BEGIN OF ty_zolls,
grnum type zolls-grnum,
werks type zolls-werks,
name1 TYPE zolls-name1,
...
...
END OF ty_zolls.
DATA: BEGIN OF wa_zoll.
Include structure ty_zollp.
Include structure ty_zolls.
DATA: END OF wa_zoll.
The above declaration had worked. Please try.
Regards,
Satish Kanteti
‎2011 Apr 29 11:07 AM
‎2011 Apr 29 12:13 PM
Thanks for your replies
the "include structure"-proposal won't work for me. I need to address the content of table it_zoll (respectivly structure wa_zoll) lateron by using e.g. following syntax "wa_zoll-zollp-werks" or "wa_zoll-zolls-werks" and not e.g. "wa_zoll-werks".
Any more ideas ?
! removal of "into corresponding fields of" works
Edited by: Andreas Milbredt on Apr 29, 2011 1:24 PM
‎2011 Apr 29 12:43 PM
My solution works if the list of fields selected map the structure definition, so don't forget to adapt the sequence of fields selected to any change of the structure definition to respect sequence and mapping rules. ([Work Areas in Open SQL Statements |http://help.sap.com/abapdocu_70/en/ABENOPEN_SQL_WA.htm])
Regards,
Raymond
‎2011 Apr 29 1:22 PM
Thanks Raymond,
it really is a bit unflexible, because when changing the underlying structures also the select statements have to be changed. And even the sequence of the selected fields has to match exactly the definition of the structures.
As an alternative i could define the structures like the (huge) database tables and use select *, that would be more flexible but not have the best performance effect.