Application Development 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: 

Select Statement Error

Former Member
0 Kudos

Friends,

I am trying to read values from MARC table.

This is the code i wrote:

data zstruct type marc.

select strgr into zstruct from marc.

endselect.

When the program is run, the values of strgr are not getting populated in zstruct.

Please let me know what is missing.

Thanks and Regards.

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor
0 Kudos

You can use like this:


data: zstruct type marc.

select strgr into corresponding fields of zstruct from marc.

endselect.

But this it is not performance efficient.

You should take the values in the internal table and than process it.


data: zstruct type standard table of marc.

select * from marc into table zstruct where .....

Regards,

Naimesh Patel

20 REPLIES 20

naimesh_patel
Active Contributor
0 Kudos

You can use like this:


data: zstruct type marc.

select strgr into corresponding fields of zstruct from marc.

endselect.

But this it is not performance efficient.

You should take the values in the internal table and than process it.


data: zstruct type standard table of marc.

select * from marc into table zstruct where .....

Regards,

Naimesh Patel

0 Kudos

Hi,

I have modified the code as follows:

data: zs type marc.

data: zstruct type standard table of marc.

select strgr from marc into table zstruct.

loop at zstruct into zs.

write zs-strgr.

endloop.

Still, the values are not getting populated in the internal table.

Please let me know what is missing.

Thanks and Regards.

0 Kudos

in the select statement you have to use

select strgr from marc into corresponding fields of table zstruct.

now it will work

hope you got it

Regards

Vardhan

0 Kudos

Since you are selecting only one field from the MARC and your target (ZSTRUCT) has all the fields of the MARC you need to use the CORRESPONDING FIELDS OF addition in the Select query

I have modified your code.


data: zs type marc.
data: zstruct type standard table of marc.

select strgr 
   from marc 
   into corresponding fields of table zstruct.

loop at zstruct into zs.
  write / zs-strgr.
endloop.

Regards,

Naimesh Patel

Sm1tje
Active Contributor
0 Kudos

you are trying to insert ONE field into a structure.

Better to declare a variable for strgr an move it into that.

Former Member
0 Kudos

Hi,

In your code.

Data: zstruct type marc.

When you declare like this, zstruct will have structure of marc. which contains all fields available in MARC table.

And you retriving only one field ie strgr from the table MARC and passing to the structure. now system will get confuse where to place this field in the given zstruct structure . so you have to use

select strgr into corresponding fields of zstruct from marc.

endselect.

now the sap system will put the outputdata from the select statement into structure field zstruct-strgr .

select strgr into corresponding fields of zstruct from marc.

write 😕 zstruct-strgr.

endselect.

now you will get the proper result.

Hope you got it.

Regards

Vardhan

Former Member
0 Kudos

Try:

DATA: zs TYPE marc.

DATA: zstruct TYPE STANDARD TABLE OF marc.

SELECT strgr
  FROM marc
  INTO CORRESPONDING FIELDS OF TABLE zstruct.

LOOP AT zstruct INTO zs.

  WRITE zs-strgr.

ENDLOOP.

Rob

0 Kudos

Rob,

I tried running your code, but there is no output when your code is executed.

Thanks,

Arun.

0 Kudos

That's because you don't have the '/' after the WRITE. (See Naimesh's code.)

Rob

0 Kudos

Check out the table whether it contains data or not

data: zs type marc.

data: zstruct type standard table of marc.

select strgr

from marc

into corresponding fields of table zstruct.

if not ztruct[] is initial.

loop at zstruct into zs.

write / zs-strgr.

endloop.

else

message z(i001) with 'No Data in table'.

endif.

hope you will get the output now

Regards

Vardhan

0 Kudos

'/' is a formatting character to display items line by line. I dont think that would affect the logic of the program.

0 Kudos

Since i am using the code in web Dynpro, i have posted this question in WDA forum. I am closing this thread.

Thanks and Regards.

0 Kudos

TYPES: BEGIN OF is_marc,

  • matnr TYPE matnr,

strgr TYPE strgr,

END OF is_marc.

DATA: zstruct TYPE STANDARD TABLE OF is_marc.

DATA: zs TYPE is_marc.

SELECT strgr FROM marc INTO CORRESPONDING FIELDS OF TABLE zstruct WHERE strgr ne ' '.

LOOP AT zstruct INTO zs.

WRITE: / zs-strgr.

ENDLOOP.

0 Kudos

>

> '/' is a formatting character to display items line by line. I dont think that would affect the logic of the program.

It absolutely does affect the output of the program. If not there, it will put all output on the same line. Using it causes each WRITE to go to a new line.

Rob

0 Kudos

Rob,

You are right. It affects the output of the program no doubt.

My reply specifically mentioned "logic of the program."

The internal table is not getting populated with values and thats where the problem lies. Not in the program output where "/" has its effects.

Thanks and Regards.

0 Kudos

If the field you are looking at is blank, then you will get essentially no output. Since the title of the thread is "Select Statement Error", my point is that the SELECT is now working, but you may not get output. I would call this a logic error.

Rob

Former Member
0 Kudos

You should also select all the key fields from the marc table into the internal table,

other than the strgr field.

Former Member
0 Kudos

Hello,

It is not necessary to select any key field.

Please try the following syntax.

select strgr from marc into CORRESPONDING FIELDS OF zstruct .

it will get values.

have tested it.

Thanks,

Rajat

0 Kudos

Hi,

Instead of declaring internal table of type marc why don't you declare internal table with only one field

data:begin of t_marc occurs 0,

field1 type marc-field1,

end of t_marc.

select field1 from marc into table t_marc where 'condition'.

0 Kudos

abap_inter,

I get the following error message when i use your code:

"Tables with headers are no longer supported in OO context"

Thanks and Regards.