09-22-2008 7:30 PM
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.
09-22-2008 7:36 PM
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
09-22-2008 7:36 PM
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
09-22-2008 8:40 PM
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.
09-22-2008 8:48 PM
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
09-22-2008 9:07 PM
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
09-22-2008 7:38 PM
you are trying to insert ONE field into a structure.
Better to declare a variable for strgr an move it into that.
09-22-2008 8:43 PM
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
09-22-2008 8:48 PM
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
09-22-2008 9:14 PM
Rob,
I tried running your code, but there is no output when your code is executed.
Thanks,
Arun.
09-22-2008 9:23 PM
That's because you don't have the '/' after the WRITE. (See Naimesh's code.)
Rob
09-22-2008 9:31 PM
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
09-24-2008 1:37 AM
'/' is a formatting character to display items line by line. I dont think that would affect the logic of the program.
09-24-2008 2:30 AM
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.
09-24-2008 9:17 AM
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.
09-24-2008 1:48 PM
>
> '/' 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
09-24-2008 2:07 PM
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.
09-24-2008 2:10 PM
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
09-23-2008 7:30 AM
You should also select all the key fields from the marc table into the internal table,
other than the strgr field.
09-23-2008 7:47 AM
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
09-23-2008 8:01 AM
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'.
09-24-2008 2:05 AM
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.