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

Need some programming help

Former Member
0 Likes
1,117

Hi,

I am trying to query data from some tables and tyring to figure what is the best way to do it.

types: begin of ty_test,
            field1 type num08 ,
            field2 type char30,
         end of ty_test,
        tt_test type standard table of ty_test.


data: t_inp type standard table of tt_test,
        t_tbla type standard table of tt_test.

lets consider the table t_inp has 10 entries and based on entries from t_inp I need to get related data from table A

select objid sobid from  A
                          into table  t_tbla 
                          for all entries in table t_inp 
                          where field1 = t_inp-field2.

If I do this I get an error saying that to use for all entries it needs to be of the same type and length

I will have to do something similar atleast 3 to 4 times.

Note:- << Removed>> I am trying to avoid using select end select statement.

Thanks

Vick

Added code tags.

Please do not offer rewards

And please use a meaningful subject. Everyone needs programming help.

Edited by: Rob Burbank on Feb 27, 2009 11:08 AM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,094

Hi Vick,

types: begin of t_source,
           field1 type tab1-field1,
           field2 type tab1-field2,
           field_tmp  type tab1-field2,  "declare one more filed in first internatable with the type of second  internal table filed   --->ccheck 1.
         eend of t_source

data: it_inpt type table of t_source.
data:wa_inpt like line of it_inpt.



loop at it_inp  into wa_iinp
wa_inpt-field_tmp  = wa_iinp-field1
modify it_inp from wa_inpt index sy-tabix tranporting field_tmp    ----- >> check 2
clear wa_inpt.
endloop.


select objid sobid from A
into table t_tbla 
for all entries in table t_inp 
where field1 = t_inp-field_tmp.  " here you have to do the type of field1 and field2 should be equal. --->check 3

Note: if you are using the For all entries you must note that fields which you are comparing that must be equal.

hope it helps you.

Regards

12 REPLIES 12
Read only

Former Member
0 Likes
1,095

Hi Vick,

types: begin of t_source,
           field1 type tab1-field1,
           field2 type tab1-field2,
           field_tmp  type tab1-field2,  "declare one more filed in first internatable with the type of second  internal table filed   --->ccheck 1.
         eend of t_source

data: it_inpt type table of t_source.
data:wa_inpt like line of it_inpt.



loop at it_inp  into wa_iinp
wa_inpt-field_tmp  = wa_iinp-field1
modify it_inp from wa_inpt index sy-tabix tranporting field_tmp    ----- >> check 2
clear wa_inpt.
endloop.


select objid sobid from A
into table t_tbla 
for all entries in table t_inp 
where field1 = t_inp-field_tmp.  " here you have to do the type of field1 and field2 should be equal. --->check 3

Note: if you are using the For all entries you must note that fields which you are comparing that must be equal.

hope it helps you.

Regards

Read only

Former Member
0 Likes
1,094

loop at t_inp.

posted by mistake.

Edited by: kartik tarla on Feb 27, 2009 9:46 PM

Read only

Former Member
0 Likes
1,094

Declare field2 LIKE a-field1.

Read only

Former Member
0 Likes
1,094

loop at t_inp.
wa-field = t_inp-field2."where wa field is of type num08
append wa to t_temp.
endloop.

now use t_temp in for all entries instead of t_inp

Read only

Former Member
0 Likes
1,094

I dont want to use the loop statement because I have to do the similar process 3 to 4 more times.

Read only

0 Likes
1,094

then modify the structure of t_inp or else u have to use loop

Read only

0 Likes
1,094

I cannot modiy the t_inp structure, is there any way I can utilize field symbols or equivalent to modify the structure dynamically with the data in them, may be assign to another fieldsymbol with a different structure ??? just a thought, you guys are the experts you wud know it better.

Thanks

Vick

Read only

0 Likes
1,094

Vick - analyze your problem.

You want to use FOR ALL ENTRIES.

You have a table that has the correct data, but in a format that can't be used by FOR ALL ENTRIES.

So, one way or another, you need a table with the correct entries in the correct format.

Rob

Read only

0 Likes
1,094

Rob,

I know that what I am trying to do sounds dumb but I feel that the language shud have been a little bit more flexible.

I need to retreive data from HRP1001 table based on certain condition and as u know how the data is stored in the HRP1001 table. I will be retreiving the data based on a certain realtionship and the resulting id will be in the sobid field so based on the sobids from ur query1 I need to read the same table again but with a different realtionship and retrieve the data. I need to repeat this process for 4 times and every time I will end up looping so I thought may be I will pose this question to the experts, as some of you guys know to trick the system really well.

It looks like there is no easy way out other than looping so I guees I will stick to this.

I appreciate for your time and effort in trying to solve my query.

Thanks

Vick

Read only

0 Likes
1,094

>

> I know that what I am trying to do sounds dumb but I feel that the language shud have been a little bit more flexible.

Nope - not dumb at all. But it has come up before and I don't know of another solution.

Rob

Read only

Former Member
0 Likes
1,094

1) Add a field to table t_inp with the same characteristics as t_tbla-field1.

2) After populating t_inp, loop through it and assign field2 to the new field.

3) Use the new field in the SELECT.

Rob

Read only

Former Member
0 Likes
1,094

If you can't change the structure, then a loop and a variable of the same type as a-field1 are your only way.