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

where condition with different type

Former Member
0 Likes
1,877

Hi friends

I want to fetch data from a Z table based on another table using field vbeln. The corresponding field in Z table is having a different character length. how can i do it.

SELECT docno vendrinv cpudt FROM zmdh INTO TABLE gt_zmdh

FOR ALL ENTRIES IN gt_vbrk WHERE vendrinv EQ gt_vbrk-vbeln AND dele_indi NE 'X'.

here vendrinv is having a type C & length 15 where as vbeln has type C and length 10.

I dont want to use loop for doing it.

Regards

Sathar

5 REPLIES 5
Read only

Former Member
0 Likes
1,312

It works very well. check this.

data: begin of it_data occurs 0,
       vbeln(20),
       matnr type matnr,
      end of it_data.

select vbeln
       matnr
  from vbap
  into table it_data
  up to 3 rows.

  break-point.

Read only

ThomasZloch
Active Contributor
0 Likes
1,312

you could add a field help_vendrinv to gt_vbrk in length 15 and move the contents of vbeln into that field before you do the "for all entries".

You might even be able to declare gt_vbrk-vbeln in length 15 to start with, no need for a help field then.

Cheers

Thomas

Read only

0 Likes
1,312

I have tried moving all contents of gt_vbrk into a new table with similiar fields but changed the type of vbeln to vendrinv. But the problem here is it added 5 zeroes to vbeln in the new table and the where condition will always go false.

Rgds

Read only

0 Likes
1,312

both fields are type C as you say, so there should not be an issue with leading zeroes unless you add them yourself somehow. Or is vendrinv actually of type N?

Anyway, if you declare GT_VBRK-VBELN same as ZMDH-VENDRINV, you can still select the values from VBRK into it and then use the field to select ZMDH using "for all entries".

Otherwise I have no further idea.

Cheers

Thomas

Read only

0 Likes
1,312

Hi Thomas

Thanks for your reply. I find that when I copy the contents of gt_vbrk to the temporary internal table which has the field vbeln with type same as vendrinv, five characters from next field is getting added to this. ie there is a shift of 5 characters to the left side for all fields after vbeln.

Now I have solved the problem in this way. I dont know whether this is the best method. Anyway it solved my prob for time being.

I have declared a temp int table with single field vbeln having data type & length same as vbeln. Now copied vbeln from gt_vbrk to this table. Again declared another int table with single field vbeln having data type & length same as vendrinv and moved the contents from prev temp table to this table.

Once again thanks to all for spending your precious time in this.

Regards

Sathar