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

regd internal tables

Former Member
0 Likes
1,967

i have to select either kunn2 or lifnr field value from knvp into an internal table field say x based on another field (partner function) value from same table knvp.I appreciate if anyone can suggest me how to proceed with this.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,920

Hi,

data:begin of itab occurs 0,

field1 like knvp-field1,

end of itab.

<b>IF PFUN is initial. (partner function)

select kunn2 into table itab

from knvp.

else.

select lifnr into table itab

from knvp.

endif.</b>

regards,

sowjanya.

i have to select either kunn2 or lifnr field value from knvp into an internal table field say x based on another field (partner function) value from same table knvp.I appreciate if anyone can suggest me how to proceed with this.

19 REPLIES 19
Read only

Former Member
0 Likes
1,920

Hi Priyanka,

Do you have partner function as parameter or select-option or as range and do you need either kunn2 or lifnr, i mean lifnr when kunn2 is initial and kunn2 when lifnr is initial ?

Based on what i understood, here is the code.

If you have partner function as parameter:

data: t_kunn2 like knvp-kunn2,

t_lifnr like knvp-lifnr.

select kunn2 lifnr from knvp into ( t_kunn2, t_lifnr )

where parvw eq p_parvw.

if t_kunn2 is initial.

move t_lifnr to itab-field.

append itab.

clear itab.

else.

move t_kunn2 to itab-field.

append itab.

clear itab.

endif.

endselect.

if you have partner function as select-option or range, then

select kunn2 lifnr from knvp into ( t_kunn2, t_lifnr )

where parvw in p_parvw.

if t_kunn2 is initial.

move t_lifnr to itab-field.

append itab.

clear itab.

else.

move t_kunn2 to itab-field.

append itab.

clear itab.

endif.

endselect.

Hope this will help you.

Regards,

Vivek

PS: Award points if helpful

Read only

Former Member
0 Likes
1,920

Unfortunately you cannot do that in a single select statement but you can do the below.

SELECT kunn2 into table itab

from knvp

where partnerfunction = 'X'.

SELECT lifrn appending table itab

from knvp

where partnerfunction = 'Y'.

regards

Anurag

Message was edited by: Anurag Bankley

Read only

Former Member
0 Likes
1,920

Hi

First you can select all the relevant data from knvp into an internal table.

Now, loop on this internal table, based on partner function, populate the kunn2 or lifnr into field of another internal table (remember it should be wide enough to hold both kinda values).

Regards,

Raj

Read only

Former Member
0 Likes
1,921

Hi,

data:begin of itab occurs 0,

field1 like knvp-field1,

end of itab.

<b>IF PFUN is initial. (partner function)

select kunn2 into table itab

from knvp.

else.

select lifnr into table itab

from knvp.

endif.</b>

regards,

sowjanya.

Read only

0 Likes
1,920

i have to move the values into the same field .

i have already selected partner function and other fields except for field 'x' from different tables into itab.

its like

if itab-parvw = 'CR'

select kunn2 from knvp into x field of itab.

else

select lifnr from knvp into x field of itab.

i dont understand how to select different fields into same field.

Read only

0 Likes
1,920

sowjanya,

how to use the statement exactly .

Read only

0 Likes
1,920

Hi Priyanka,

do this:

loop at itab.

zindex = sy-tabix.

if itab-parvw = 'CR'.

select single kunn2 from knvp into itab-field where parvw = itab-pravw.

else.

select single lifnr from knvp into itab-field where parvw = itab-parvw.

endif.

modify itab index zindex.

endloop.

Regards,

Vivek

Read only

0 Likes
1,920

thanks a lot .I was almost trying the same thing.

Read only

0 Likes
1,920

Since you already have the data in itab....the best way to do it is using the below code.

Select kunn2 into lval from knvp where condition.

itab-field = lval.

modify itab transporting field where parvw = 'CR'.

Select lifnr into lval from knvp where condition.

itab-field = lval.

modify itab transporting field where parvw <> 'CR'.

Read only

0 Likes
1,920

Hi Priyanka,

If your problem is solved, can you close the thread by assigning points to useful answers.

Regards,

Vivek

Read only

0 Likes
1,920

i rewarded points but donno how to close it

Read only

0 Likes
1,920

i have written this code.itab-field is already populated for other values of parvw.i am just trying to change that for 'CR' value.

loop at itab.

if itab-parvw = 'CR'.

select lifnr from knvp into itab-field where parvw = 'CR' and kunnr = itab-kunnr.

modify itab transporting field.

endselect.

endif .

endloop.

i still dont see the values for field for 'CR' value.Its just blank still.

Read only

0 Likes
1,920

Please check if you have the corresponding correct data in KNVP.

Ur code seems to be fine..

<b>loop at itab.

if itab-parvw = 'CR'.

select lifnr from knvp into itab-field where parvw = 'CR' and kunnr = itab-kunnr

<i>and vkorg = 'ABC' and vtweg = '10' and spart = '10'.</i>

modify itab.endselect.

endif .

endloop.</b>

<b><u>--> It might be possible that the lifnr field is blank for the other sales org ..try and check if you can qualify the select with all possible where fields.</u></b>

Message was edited by: Anurag Bankley

Message was edited by: Anurag Bankley

Read only

0 Likes
1,920

i have checked the data is there in knvp.

Read only

Former Member
0 Likes
1,920

Hi

Try this code

SELECT * FROM mska INTO TABLE gt_cms018

WHERE ( werks = g_werks_coil OR werks = g_werks_manf )

AND line EQ p_line.

regards,

vin..

Read only

Former Member
0 Likes
1,920

Hi,

since both are character fields, no problem in moving

in the itab

declare the field as char(10)

and based on the condition move whichever field you want

<b>data:begin of itab occurs 0,

f1(10) type c,

-


end of itab.</b>

if itab-parvw = 'CR'.

select kunn2 from knvp into f1 of itab.

append itab.

else.

select lifnr from knvp into f1 of itab.

append itab.

i hope this helps.

Regards,

Sowjanya

Message was edited by: sowjanya suggula

Read only

Former Member
0 Likes
1,920

hi,

sorry try like this

data:begin of itab occurs 0,

f1(10) type c,

parvw like knvp-parvw,

end of itab.

select parvw from knvp into corresponding fields of table itab up to 10 rows.

if sy-subrc = 0.

loop at itab.

if itab-parvw = 'CR'.

<b>select kunn2 from knvp into itab-f1.

modify itab index sy-tabix.</b>

endselect.

else.

<b>select lifnr from knvp into itab-f1.

modify itab index sy-tabix.</b>

endselect.

endif.

endloop.

endif.

Message was edited by: sowjanya suggula

Message was edited by: sowjanya suggula

Message was edited by: sowjanya suggula

Read only

Former Member
0 Likes
1,920

hi priyanka,

try exactly what i have coded

it is wroking from my end

Read only

Former Member
0 Likes
1,920

Hi,

Try this..

DATA: V_PARVW TYPE KNVP-PARVW.

loop at itab1.

if itab1-parvw = 'CR'.

select lifnr from knvp into itab-field where parvw = <b>'SP'</b> and kunnr = itab-kunnr.

endif.

endloop.

This might work..

Thanks,

Naren

Message was edited by: Narendran Muthukumaran