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

report-query

Former Member
0 Likes
850

types: begin of ty_lfa1,

lifnr type lfa1-lifnr,

name1 type lfa1-name1,

land1 type lfa1-land1,

pstlz type lfa1-pstlz,

end of ty_lfa1.

data: w_lfa1 type ty_lfa1,

t_lfa1 type ty_lfa1 occurs 0.

Parameters : P_cnty type lfa1-land1.

select * from lfa1 into table t_lfa1 where land1 = p_cnty.

loop at t_lfa1 into w_lfa1.

write:/ 05 w_lfa1-lifnr,

30 w_lfa1-name1,

50 w_lfa1-land1,

75 w_lfa1-pstlz.

endloop.

8 REPLIES 8
Read only

Former Member
0 Likes
819

i think you are getting the sql error for this select query because select * will fetch all the fields from lfa1 but your internal table contains only few fields of lfa1 so after fetching the fields it can not store in the int table.

for that you have to write the select qery with the fields...

select lifnr name1 land1 pstlz into table t_lfa1 where land1 = p_cnty.

and one more thing since p_cnty is parameter so you must have to enter value other wise it will not fetch any rows..

regards

shiba dutta

Read only

Former Member
0 Likes
819

Hi,,

From your code its clear that you need to give corresponding fields of table ty_lfa1 as the query would fetch records from all fields of the database table lfa1.

try using the querry

select * from lfa1 into corresponding fields of table t_lfa1 where land1 = p_cnty.

regards

Dinesh

Read only

Former Member
0 Likes
819

Hi,

ur internal table cannt hold all the fields as u declared that with specific fields,thats the error.so either declare internal table with header line r use into corresponding option.

Read only

Former Member
0 Likes
819

Hi Venkat,

Use "<b>in to corresponing fields of table</b> " clause in to ur select query.

u r fetching all records from LFA1 which may be in different sequence as u have given in ur structure.so type mismatch will be there.

therefore use this statement :

select * from lfa1 <b>into corresponding fields of table t_lfa1</b> where land1 = p_cnty.

Reward points if helpful.

Regards,

Hemant.

Read only

Former Member
0 Likes
819

Hai Venkat,

U would have used 'DATA' instead of 'TYPES'. b'coz, pre-defined structures can be declared with 'types'. In query, ' into corresponding fields of table' is a must.

Now, this script can be executed.

data: begin of ty_lfa1,

lifnr type lfa1-lifnr,

name1 type lfa1-name1,

land1 type lfa1-land1,

pstlz type lfa1-pstlz,

end of ty_lfa1.

data: w_lfa1 like ty_lfa1,

t_lfa1 like ty_lfa1 occurs 0.

Parameters : P_cnty type lfa1-land1.

select * from lfa1 into corresponding fields of table t_lfa1 where land1

= p_cnty.

loop at t_lfa1 into w_lfa1.

write: /05 w_lfa1-lifnr,

30 w_lfa1-name1,

50 w_lfa1-land1,

75 w_lfa1-pstlz.

endloop.

Read only

Former Member
0 Likes
819

hi,

U have given * where its going to select all the fields n u have taken only few of them so u have to either give it as corresponding fields or take it as an internal table.this will solve ur problem.

if useful reward with points,

with regards,

madhuri.

Read only

Former Member
0 Likes
819

hi venkat,

u declared internal table without header line so u have to declare a work area and populate data through workarea into internal table.

second one is the select statement should have the same order in which u declared all fileds in types. otherwise u would get the error.

instead of that u can use select statement with 'into corresponding fields of' can be used but it reduces the performance as it has to check every filed while inserting data into the internal table

if it is useful reward some point.,

with regards ,

suresh babu.

Read only

Former Member
0 Likes
819

hi,

try this.

data : begin of itab_lfa1,

lifnr like lfa1-lifnr,

name1 like lfa1-name1,

land1 like lfa1-land1,

pstlz like lfa1-pstlz,

end of itab_lfa1.

data: w_lfa1 like itab_lfa1,

t_lfa1 like itab_lfa1 .

Parameters : P_cnty like lfa1-land1.

select * from lfa1 into table itab_lfa1 where land1 = p_cnty.

loop at itab_lfa1 into w_lfa1.

write:/ 05 w_lfa1-lifnr,

30 w_lfa1-name1,

50 w_lfa1-land1,

75 w_lfa1-pstlz.

endloop.

reward with points if helpful.