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 - write - internal table

Former Member
0 Likes
1,045

Hi

I dont know if I can use the forum for this ...

Can you help me with this code:

Data: t_SUB_HEADER type BAPI1077RH occurs 0 with header line.

SELECT RECN INTO (t_SUB_HEADER-RECORD_NO)

FROM ESTRH

FOR ALL ENTRIES IN t_estmj

WHERE RECN = t_ESTMJ-RECNROOT.

WRITE:/ t_SUB_HEADER-RECORD_NO.

ENDSELECT.

I want the t_SUB_HEADER to get fill but I cant get to insert the values into the table, I dont know if Im doing things right.

Thanks in advance

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
994

Either


SELECT RECN INTO corresponding field of table t_SUB_HEADER....
loop at y_sub_header.
 WRITE:/ t_SUB_HEADER-RECORD_NO.
endloop.

Or


SELECT RECN INTO (t_SUB_HEADER-RECORD_NO) "here you are addressing header of the table
FROM ESTRH
FOR ALL ENTRIES IN t_estmj
WHERE RECN = t_ESTMJ-RECNROOT.
WRITE:/ t_SUB_HEADER-RECORD_NO.
append t_sub_header. "here you are addressing table content
ENDSELECT.

Regards

Marcin

9 REPLIES 9
Read only

Former Member
0 Likes
994

Hi jean

You must append the structure in the select statemen, otherwise the record

is not insert in the tablem but only in the header line..


append t_sub_header.

regards

Marco

Read only

MarcinPciak
Active Contributor
0 Likes
995

Either


SELECT RECN INTO corresponding field of table t_SUB_HEADER....
loop at y_sub_header.
 WRITE:/ t_SUB_HEADER-RECORD_NO.
endloop.

Or


SELECT RECN INTO (t_SUB_HEADER-RECORD_NO) "here you are addressing header of the table
FROM ESTRH
FOR ALL ENTRIES IN t_estmj
WHERE RECN = t_ESTMJ-RECNROOT.
WRITE:/ t_SUB_HEADER-RECORD_NO.
append t_sub_header. "here you are addressing table content
ENDSELECT.

Regards

Marcin

Read only

Former Member
0 Likes
994

Hi,

If you want to fill the table .. write as

SELECT RECN INTO table t_SUB_HEADER

FROM ESTRH

FOR ALL ENTRIES IN t_estmj

WHERE RECN = t_ESTMJ-RECNROOT.

Regards,

Srini.

Read only

former_member194669
Active Contributor
0 Likes
994

Change this way


data: begin of it_SUB_HEADER occurs 0.
data : RECN like BAPI1077RH-RECORD_NO.
data : end of it_SUB_HEADER.

SELECT RECN INTO TABLE it_SUB_HEADER
FROM ESTRH
FOR ALL ENTRIES IN t_estmj
WHERE RECN = t_ESTMJ-RECNROOT.
ENDSELECT.

a®

Read only

Former Member
0 Likes
994

Ithink that "corresponding field of table" doesnt apply because the column names are different, neither the select RECN into table.

Im I right?

Read only

0 Likes
994

Hi

yes you're right...

you must use append like my previous post...in the select..

regards

Marco

Read only

Former Member
0 Likes
994

the "append t_sub_header." did it.

Thanks a lot

Read only

Former Member
0 Likes
994

Are you sure the internal table t_estmj is not initial before the select query?

Better to put the check when you use FOR ALL ENTRIES


Data: t_SUB_HEADER type BAPI1077RH occurs 0 with header line.

IF NOT t_estmj[] is intial.

SELECT RECN INTO (t_SUB_HEADER-RECORD_NO)
FROM ESTRH
FOR ALL ENTRIES IN t_estmj
WHERE RECN = t_ESTMJ-RECNROOT.
WRITE:/ t_SUB_HEADER-RECORD_NO.
ENDSELECT.

ENDIF.

Read only

Former Member
0 Likes
994

Hi Jean Carlo,

You are saying that you Iwant the t_SUB_HEADER to get fill but you cant get to insert the values into the table.

Here in this code your are not appending the table. see below:

Data: t_SUB_HEADER type BAPI1077RH occurs 0 with header line.

SELECT RECN INTO (t_SUB_HEADER-RECORD_NO)

FROM ESTRH

FOR ALL ENTRIES IN t_estmj

WHERE RECN = t_ESTMJ-RECNROOT.

APPEND t_SUB_HEADER.

WRITE:/ t_SUB_HEADER-RECORD_NO.

ENDSELECT.

Better if you write the code written below for good performance.

SELECT RECN INTO TABLE t_SUB_HEADER

FROM ESTRH

FOR ALL ENTRIES IN t_estmj

WHERE RECN = t_ESTMJ-RECNROOT.

IF SY-SUBRC EQ 0.

LOOP AT t_SUB_HEADER.

WRITE:/ t_SUB_HEADER-RECORD_NO.

ENDLOOP.

Hope this is the solution of your question.

Regards,

Md Ziauddin.