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 Statement

Former Member
0 Likes
1,007

Hello Friends,

I am facing a problem in select statement.

DATA : t_caufv LIKE caufv OCCURS 0 WITH HEADER LINE,

t_ihpa LIKE ihpa OCCURS 0 WITH HEADER LINE,

t_lfa1 LIKE lfa1 OCCURS 0 WITH HEADER LINE.

SELECT *

FROM ihpa

INTO TABLE t_ihpa

FOR ALL ENTRIES IN t_caufv

WHERE objnr = t_caufv-objnr

AND parvw = 'VN'.

IF NOT t_ihpa IS INITIAL.

SELECT *

FROM lfa1

INTO TABLE t_lfa1

FOR ALL ENTRIES IN t_ihpa

WHERE lifnr = t_ihpa-parnr.

ENDIF.

But my second select statement gives a Syntax error.

I looked into LFA1-LIFNR and IHPA-Parnr in se11. They both have same data type but have different length.

ANy suggestions.

Ster.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
962

DATA : t_caufv LIKE caufv OCCURS 0 WITH HEADER LINE,

t_ihpa LIKE ihpa OCCURS 0 WITH HEADER LINE,

t_lfa1 LIKE lfa1 OCCURS 0 WITH HEADER LINE.

data : begin of itab occurs 0,

lifnr type lfa1-lifnr,

end of itab.

SELECT *

FROM ihpa

INTO TABLE t_ihpa

FOR ALL ENTRIES IN t_caufv

WHERE objnr = t_caufv-objnr

AND parvw = 'VN'.

IF NOT t_ihpa IS INITIAL.

loop at t_ihpa.

move t_ihpa-para+2(12) to itab-lifnr.

append lifnr.

endloop.

SELECT *

FROM lfa1

INTO TABLE t_lfa1

FOR ALL ENTRIES IN t_ihpa

WHERE lifnr = itab-lifnr.

ENDIF.

10 REPLIES 10
Read only

Former Member
0 Likes
962

LIFNR is of length 10 and PARNr is of length 12 , try this

Read only

0 Likes
962

Thanks, Thats the problem Chandrashekhar.

LIFNR has length 10 and PARNR has length 12.

So the problem.

Whats an alternative for this?

Ster

Read only

Former Member
0 Likes
962

Hi,

use ADRC instead of LFA1 table

define

t_adrc LIKE adrc OCCURS 0 WITH HEADER LINE.

IF NOT t_caufv IS INITIAL.

SELECT *

FROM ihpa

INTO TABLE t_ihpa

FOR ALL ENTRIES IN t_caufv

WHERE objnr = t_caufv-objnr

AND parvw = 'VN'.

endif.

IF NOT t_ihpa IS INITIAL.

SELECT *

FROM adrc INTO TABLE t_adrc

FOR ALL ENTRIES IN t_ihpa

WHERE adrnr = t_ihpa-adrnr.

ENDIF.

ADRC will also have the same data a s LFA1.

reward points if useful

regards,

ANJI

Read only

0 Likes
962

To quote from an F1 on FOR ALL ENTRIES..

"Each component of the internal table that occurs in a replacement symbol in the WHERE condition must have exactly the same type and length as the corresponding component in the database table. "

Which is not the case in your second SELECT. Pl change your itab definition to match the type & length of LIFNR

~Suresh

Read only

Former Member
0 Likes
962

Use the below code in bold

DATA : t_caufv LIKE caufv OCCURS 0 WITH HEADER LINE,

t_ihpa LIKE ihpa OCCURS 0 WITH HEADER LINE,

t_lfa1 LIKE lfa1 OCCURS 0 WITH HEADER LINE.

<b>

data : begin of itab occurs 0,

lifnr type lfa1-lifnr,

end of itab.</b>

SELECT *

FROM ihpa

INTO TABLE t_ihpa

FOR ALL ENTRIES IN t_caufv

WHERE objnr = t_caufv-objnr

AND parvw = 'VN'.

IF NOT t_ihpa IS INITIAL.

<b>loop at t_ihpa.

move t_ihpa-para to itab-lifnr.

append lifnr.

endloop.</b>

SELECT *

FROM lfa1

INTO TABLE t_lfa1

FOR ALL ENTRIES IN t_ihpa

WHERE lifnr =<b> itab-lifnr</b>.

ENDIF.

Read only

Former Member
0 Likes
962

Hi Ster,

Check this code.

IF NOT t_ihpa IS INITIAL.

SELECT *

FROM lfa1

INTO TABLE t_lfa1

FOR ALL ENTRIES IN t_ihpa

WHERE<b> lifnr = t_ihpa-parnr+0(10).</b>

ENDIF.

Thanks,

Vinay

Read only

Former Member
0 Likes
962

Hi,

The fields in the select statement should be of same data type and same length.

Regards,

RS

Read only

Former Member
0 Likes
962
DATA : t_caufv LIKE caufv OCCURS 0 WITH HEADER LINE,
t_ihpa LIKE ihpa OCCURS 0 WITH HEADER LINE,
t_lfa1 LIKE lfa1 OCCURS 0 WITH HEADER LINE.

data : it_ranges for ihpa-parnr.

SELECT *
FROM ihpa
INTO TABLE t_ihpa
FOR ALL ENTRIES IN t_caufv
WHERE objnr = t_caufv-objnr
AND parvw = 'VN'.

loop at i_ihpa.
 it_ranges-sign = 'I'.
 it_ranges-option = 'CP'.
 concatenate i_ihpa-parnr '*' into it_ranges-low.
 append it_ranges.
clear it_ranges.
endloop.

delete adjacent duplicates from it_ranges.

IF NOT t_ihpa IS INITIAL.

SELECT *
FROM lfa1
INTO TABLE t_lfa1
WHERE lifnr in  it_ranges.

ENDIF.
Read only

Former Member
0 Likes
963

DATA : t_caufv LIKE caufv OCCURS 0 WITH HEADER LINE,

t_ihpa LIKE ihpa OCCURS 0 WITH HEADER LINE,

t_lfa1 LIKE lfa1 OCCURS 0 WITH HEADER LINE.

data : begin of itab occurs 0,

lifnr type lfa1-lifnr,

end of itab.

SELECT *

FROM ihpa

INTO TABLE t_ihpa

FOR ALL ENTRIES IN t_caufv

WHERE objnr = t_caufv-objnr

AND parvw = 'VN'.

IF NOT t_ihpa IS INITIAL.

loop at t_ihpa.

move t_ihpa-para+2(12) to itab-lifnr.

append lifnr.

endloop.

SELECT *

FROM lfa1

INTO TABLE t_lfa1

FOR ALL ENTRIES IN t_ihpa

WHERE lifnr = itab-lifnr.

ENDIF.

Read only

0 Likes
962

Thanks everyone for your suggestions.

I will try as suggested.

Ster.