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

Reading any value from table into a string (Especially date etc..)

Former Member
0 Likes
1,291

How would I read any value from a table into a string?

Currently doing the following...

data ret_val type string.

select single (wa_map-qes_field) from z_qekko into ret_val

where

angnr = _angnr.

When the source field is a date it bombs though.

The result goes into a BDCDATA-fval.

regards

Dylan.

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
0 Likes
1,270

Not logged into a system at the moment, so can't check precisely, but you could do...

PARAMETERS: p_field TYPE fieldname.

DATA: lp_data TYPE REF TO DATA.
FIELD-SYMBOLS: <value>.

CREATE DATA lp_data LIKE (p_field).
ASSIGN lp_data->* TO <value>.

SELECT SINGLE (fieldname) FROM table INTO <value> WHERE... 

matt

Not logged into a system at the moment, so can't check precisely, but you could do...

PARAMETERS: p_field TYPE fieldname.

DATA: lp_data TYPE REF TO DATA.
FIELD-SYMBOLS: <value>.

CREATE DATA lp_data LIKE (p_field).
ASSIGN lp_data->* TO <value>.

SELECT SINGLE (fieldname) FROM table INTO <value> WHERE... 

matt

8 REPLIES 8
Read only

Former Member
0 Likes
1,270

select single

field1 from table

into v_field

where field1 = p_field.

<REMOVED BY MODERATOR>

venkat.

Edited by: Alvaro Tejada Galindo on Feb 29, 2008 10:20 AM

Read only

0 Likes
1,270

May be I dont understand your solution but, that is even less generic.

Did you notice that the field is determined via select single (field_to_read) from into generic_type_of some sort

what data type did you use for v_field ?

Wouldnt the solution require some type of <fs>?

regards

Dylan.

Read only

matt
Active Contributor
0 Likes
1,271

Not logged into a system at the moment, so can't check precisely, but you could do...

PARAMETERS: p_field TYPE fieldname.

DATA: lp_data TYPE REF TO DATA.
FIELD-SYMBOLS: <value>.

CREATE DATA lp_data LIKE (p_field).
ASSIGN lp_data->* TO <value>.

SELECT SINGLE (fieldname) FROM table INTO <value> WHERE... 

matt

Read only

Former Member
0 Likes
1,270

That looks good.

Will try it out now.

Thanks

Dylan.

Read only

Former Member
0 Likes
1,270

Tried...

1 DATA: lp_data TYPE REF TO DATA.

2 FIELD-SYMBOLS: <value> TYPE ANY.

3 CREATE DATA lp_data LIKE (wa_map-qes_field).

4 ASSIGN lp_data->* TO <value>.

5 SELECT SINGLE (wa_map-qes_field) FROM zquadrem_qekko INTO <value> WHERE angnr = _angnr.

Complains that (wa_map-qes_field) is not defined in line 3.

Think that the bracket thing is only available via SQL.

What about CREATE DATA lp_data type ref to object. ?

Would the above declaration work?

regards

Read only

matt
Active Contributor
0 Likes
1,270

REF TO OBJECT won't work.

Can you do CREATE DATA lp_data TYPE (wa_map-qes_field). ? Sorry - I like to check things before posting, but as I said, I've not got a system to log into today!

You can probably use RTTS - if your SAP version is high enough - to determine the correct type. Search on RTTS - there's some good documentation in SDN on it, with worked examples. [like this one.|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b332e090-0201-0010-bdbd-b735e96fe0ae]

matt

Read only

Former Member
0 Likes
1,270

Hi,

I changed it to TYPE anyway and it worked.

Thanks, for your help!

Dylan.

Read only

Former Member
0 Likes
1,270

tables:mara.

data:v_matnr like mara-matnr.

select-options: s_matnr for mara-matnr.

select single matnr

from mara

into v_matnr

where matnr in s_matnr.

write:/ v_matnr.

<REMOVED BY MODERATOR>

venkat .

Edited by: Alvaro Tejada Galindo on Feb 29, 2008 10:21 AM