‎2007 Jul 17 3:26 PM
Hello,
I have a database-table, I want to select into an internal table. The internal table has a few fields and the structure of the database table as substructure. Is there a way to do a SELECT on the database-table and move the values of the fields via 'INTO CORRESPONDING FIELDS OF TABLE' into the substructure?
thx
‎2007 Jul 17 3:35 PM
Hi Mike,
try this:
TABLES: MARA.
*
TYPES: IMARA TYPE TABLE OF MARA.
DATA: WA_MARA TYPE MARA.
*
DATA: BEGIN OF ITAB OCCURS 0,
AUFNR LIKE AUFK-AUFNR,
VBELN LIKE VBAK-VBELN,
ITMARA TYPE IMARA,
END OF ITAB.
*
ITAB-AUFNR = '0000000001'. ITAB-VBELN = '0000000001'.
SELECT * FROM MARA UP TO 5 ROWS INTO TABLE ITAB-ITMARA.
APPEND ITAB.
ITAB-AUFNR = '0000000002'. ITAB-VBELN = '0000000001'.
SELECT * FROM MARA UP TO 5 ROWS INTO TABLE ITAB-ITMARA where matkl = '02'.
APPEND ITAB.
*
*
LOOP AT ITAB.
WRITE: / ITAB-AUFNR, ITAB-VBELN.
LOOP AT ITAB-ITMARA INTO WA_MARA.
WRITE: /50 WA_MARA-MATNR, WA_MARA-MATKL.
ENDLOOP.
ENDLOOP.
Regards, Dieter
‎2007 Jul 17 3:30 PM
‎2007 Jul 17 3:31 PM
Hi!
You might try out this:
SELECT matnr AS substructure-matnr
werks AS substructure-werks
FROM marc
INTO CORRESPONDING FIELDS OF TABLE gt_marc
WHERE ...
gt_marc has the substructure
Regards
Tamá
‎2007 Jul 17 3:34 PM
Sure you can do it like this.
report zrich_0001 .
data : begin of itab,
fld1(10) type c,
it001 type table of t001,
fld2(10) type c,
end of itab .
data: xt001 like line of itab-it001.
select * into table itab-it001
from t001.
loop at itab-it001 into xt001.
write:/ xt001-bukrs, xt001-butxt.
endloop.
Regards
Rich Heilman
‎2007 Jul 17 3:35 PM
Hi Mike,
try this:
TABLES: MARA.
*
TYPES: IMARA TYPE TABLE OF MARA.
DATA: WA_MARA TYPE MARA.
*
DATA: BEGIN OF ITAB OCCURS 0,
AUFNR LIKE AUFK-AUFNR,
VBELN LIKE VBAK-VBELN,
ITMARA TYPE IMARA,
END OF ITAB.
*
ITAB-AUFNR = '0000000001'. ITAB-VBELN = '0000000001'.
SELECT * FROM MARA UP TO 5 ROWS INTO TABLE ITAB-ITMARA.
APPEND ITAB.
ITAB-AUFNR = '0000000002'. ITAB-VBELN = '0000000001'.
SELECT * FROM MARA UP TO 5 ROWS INTO TABLE ITAB-ITMARA where matkl = '02'.
APPEND ITAB.
*
*
LOOP AT ITAB.
WRITE: / ITAB-AUFNR, ITAB-VBELN.
LOOP AT ITAB-ITMARA INTO WA_MARA.
WRITE: /50 WA_MARA-MATNR, WA_MARA-MATKL.
ENDLOOP.
ENDLOOP.
Regards, Dieter
‎2007 Jul 17 3:53 PM
structure with field1 & field2 and structure wbz_hdl
TYPES: BEGIN OF wbz_hdl_show,
field1(1) TYPE c,
field2(1) TYPE c,
wbz_hdl TYPE /xyz/jut_wbz_hdl,
END OF wbz_hdl_show.
internal table with new defined structure
DATA: git_jut_wbz_hdl TYPE STANDARD TABLE OF wbz_hdl_show.
select on dbtab into internal table git_jut_wbz_hdl (but this doesn't work)
SELECT * FROM /xyz/jut_wbz_hdl
INTO CORRESPONDING FIELDS OF TABLE git_jut_wbz_hdl.
ok I can solve the problem, do the SELECT into internal table and loop through the internal table and MOVE-CORRESPONDING into workarea defined with new structure and at last append it to internal table, also defined with the new structure.
‎2007 Jul 17 3:56 PM
‎2007 Jul 17 4:05 PM
no, this doesn't work, I also thought it would work, but it doesn't.
I think the reason is because 'INTO CORRESPONDING FIELDS' works on the first level and not at the substructure, and so there are no comparisons found
I also thought it would work like this:
SELECT * FROM /xyz/jut_wbz_hdl
INTO CORRESPONDING FIELDS OF TABLE git_jut_wbz_hdl-wbz_hdl-*
but I think this would only work, if git_jut_wbz_hdl is defined with HEADER LINE
‎2007 Jul 17 4:07 PM
Hi Mike,
here a short example with own types:
ABLES: MARA.
*
TYPES: BEGIN OF XMARA,
MATNR LIKE MARA-MATNR,
MATKL LIKE MARA-MATKL,
GROES LIKE MARA-GROES,
END OF XMARA.
*
TYPES: IMARA TYPE TABLE OF XMARA.
DATA: WA_MARA TYPE XMARA.
*
DATA: BEGIN OF ITAB OCCURS 0,
AUFNR LIKE AUFK-AUFNR,
VBELN LIKE VBAK-VBELN,
ITMARA TYPE IMARA,
END OF ITAB.
*
ITAB-AUFNR = '0000000001'. ITAB-VBELN = '0000000001'.
SELECT * FROM MARA UP TO 5 ROWS INTO CORRESPONDING FIELDS OF TABLE ITAB-ITMARA.
APPEND ITAB.
ITAB-AUFNR = '0000000002'. ITAB-VBELN = '0000000001'.
SELECT * FROM MARA UP TO 5 ROWS INTO CORRESPONDING FIELDS OF TABLE ITAB-ITMARA WHERE MATKL = '02'.
APPEND ITAB.
*
*
LOOP AT ITAB.
WRITE: / ITAB-AUFNR, ITAB-VBELN.
LOOP AT ITAB-ITMARA INTO WA_MARA.
WRITE: /50 WA_MARA-MATNR, WA_MARA-MATKL.
ENDLOOP.
ENDLOOP.
Regards, Dieter
‎2007 Jul 17 4:11 PM
Since the structure is the same for the DB table and the substructure, there is no reason why you need to have the CORRESPONDING FIELDS. Simply try this.
SELECT * FROM /xyz/jut_wbz_hdl
INTO TABLE git_jut_wbz_hdl-wbz_hdl. "<-- Make sure to specifiy the name of the substructure internal table here
Regards,
RIch Heilman
‎2007 Jul 17 4:20 PM
or alternatively you can change your type definition as follows and then the CORRESPONDING FIELDS OF TABLE should work
TYPES: BEGIN OF wbz_hdl_show,
field1(1) TYPE c,
field2(1) TYPE c.
INCLUDE STRUCTURE /xyz/jut_wbz_hdl.
TYPES: END OF wbz_hdl_show.
internal table with new defined structure
DATA: git_jut_wbz_hdl TYPE STANDARD TABLE OF wbz_hdl_show.