Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

select into substructure

Former Member
0 Likes
1,656

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,368

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

10 REPLIES 10
Read only

ferry_lianto
Active Contributor
0 Likes
1,368

Hi,

Yes, you can ...

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
1,368

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á

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,368

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

Read only

Former Member
0 Likes
1,369

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

Read only

0 Likes
1,368

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.

Read only

0 Likes
1,368

This doesn't work?



SELECT * FROM /xyz/jut_wbz_hdl
INTO CORRESPONDING FIELDS OF TABLE git_jut_wbz_hdl-wbz_hdl.

Regards,

Rich Heilman

Read only

0 Likes
1,368

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

Read only

0 Likes
1,368

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

Read only

0 Likes
1,368

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

Read only

0 Likes
1,368

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.