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

Getting data in one internal table based on another one

Former Member
0 Likes
1,161

Hi experts,

I have a req. in which I get data from one DB table into an internal table lt_hrp.

Now based on the data in it1, I need to fetch data in lt_hrt.

Below is the piece of code:

DATA: lt_zhrp TYPE STANDARD TABLE OF zhrp,

lt_zhrt TYPE STANDARD TABLE OF zhrt.

SELECT tabnr

FROM zhrp

INTO CORRESPONDING FIELDS OF TABLE lt_zhrp

WHERE objid = lv_posid.

SELECT low

from zhrt

INTO CORRESPONDING FIELDS OF TABLE lt_zhrt

where tabnr = lt_zhrp-tabnr

AND attrib = 'NET_VALUE'.

This is giving a syntax error at the line: where tabnr = lt_zhrp-tabnr

""LT_HRP1222" is a table without a header line and therefore has no component called "TABNR".

Since I am coding inside a method, I can't use WITH HEADER LINE, as it has become obsolete.

Can you please help me out with this problem?

Thanks,

Ajay.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,115

Hi,

You need to use the FOR ALL ENTRIES in the second query.

SELECT tabnr

FROM zhrp

INTO CORRESPONDING FIELDS OF TABLE lt_zhrp

WHERE objid = lv_posid.

SELECT low

from zhrt

INTO CORRESPONDING FIELDS OF TABLE lt_zhrt

FOR ALL ENTRIES IN lt_zhrp

where tabnr = lt_zhrp-tabnr

AND attrib = 'NET_VALUE'.

Hope this helps

Regards

Shiva

8 REPLIES 8
Read only

PedroGuarita
Active Contributor
0 Likes
1,115

You are missing the "FOR ALL ENTRIES" instruction in the second select.

SELECT low

from zhrt

INTO CORRESPONDING FIELDS OF TABLE lt_zhrt

FOR ALL ENTRIES IN LT_ZHRP

where tabnr = lt_zhrp-tabnr

AND attrib = 'NET_VALUE'.

Read only

Former Member
0 Likes
1,116

Hi,

You need to use the FOR ALL ENTRIES in the second query.

SELECT tabnr

FROM zhrp

INTO CORRESPONDING FIELDS OF TABLE lt_zhrp

WHERE objid = lv_posid.

SELECT low

from zhrt

INTO CORRESPONDING FIELDS OF TABLE lt_zhrt

FOR ALL ENTRIES IN lt_zhrp

where tabnr = lt_zhrp-tabnr

AND attrib = 'NET_VALUE'.

Hope this helps

Regards

Shiva

Read only

Former Member
0 Likes
1,115

hi,

i think your problem is need of a work area...

Using "FOR ALL ENTRIES IN lt_zhrp" You must use " check lt_zhrp is not initial "


DATA: lt_zhrp TYPE STANDARD TABLE OF zhrp,
      lt_zhrt TYPE STANDARD TABLE OF zhrt.

*new
data: wa_zhrp type lt_zhrp.

SELECT tabnr
FROM zhrp
INTO CORRESPONDING FIELDS OF TABLE lt_zhrp
WHERE objid = lv_posid.

LOOP AT lt_zhrp INTO wa_zhrp.


  SELECT low
  FROM zhrt
  INTO CORRESPONDING FIELDS OF TABLE lt_zhrt
  WHERE tabnr =  wa_zhrp-tabnr  " lt_zhrp-tabnr
  AND attrib = 'NET_VALUE'.

ENDLOOP.

Edited by: Miguel Antunes on Apr 28, 2010 4:22 PM

Read only

Former Member
0 Likes
1,115

Further related issues.

Read only

0 Likes
1,115

Hi experts,

When I user FOR ALL ENTRIES, there is one problem.

The field ATTRIB is from the table zhrt, but in using for all entries, the system treats it as the field of zhrp,

and therefore sy-subrc = 4 i.e. the query fails.

Could you please let me know a possible solution?

Thanks,

Ajay.

Read only

0 Likes
1,115

Can you paste the relevant part of your code...

Read only

0 Likes
1,115

Hi Manas,

Below is the piece of code:

DATA: lt_zhrp TYPE STANDARD TABLE OF zhrp,

lt_zhrt TYPE STANDARD TABLE OF zhrt.

SELECT tabnr

FROM zhrp

INTO CORRESPONDING FIELDS OF TABLE lt_zhrp

WHERE objid = lv_posid.

SELECT low

from zhrt

INTO CORRESPONDING FIELDS OF TABLE lt_zhrt

where tabnr = lt_zhrp-tabnr

AND attrib = 'NET_VALUE'.

Thanks,

Ajay.

Read only

Former Member
0 Likes
1,115

Solved