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

modify

Former Member
0 Likes
1,415

Hi Folks,

SORT IT_EKPO BY KUNNR.

LOOP AT IT_EKPO INTO WA_EKPO.

READ TABLE IT_KNA1 INTO WA_KNA1 WITH KEY KUNNR = WA_EKPO-KUNNR BINARY SEARCH.

IF SY-SUBRC = 0.

WA_KNA1-KUNNR = WA_EKPO-KUNNR.

ENDIF.

modify it_kna1 from wa_kna1.

ENDLOOP.

thing is i am having 1,2,3 materials shipped to a single customer .

so i have to get the corresponding kunnr for that material.

when i am using this statement its giving me a dump.

thing is i have to modify it_kna1 based upon it_ekpo-kunnr.

if any alternative method do let me know.

regards

jana

1 ACCEPTED SOLUTION
Read only

former_member194669
Active Contributor
0 Likes
1,384

Hi,

Check this



SORT IT_EKPO BY KUNNR.
LOOP AT IT_EKPO INTO WA_EKPO.

READ TABLE IT_KNA1 INTO WA_KNA1 WITH KEY KUNNR = WA_EKPO-KUNNR BINARY SEARCH.
IF SY-SUBRC = 0.
WA_KNA1-KUNNR = WA_EKPO-KUNNR.
modify it_kna1 from wa_kna1.  " PUT INSIDE IF
ENDIF.
ENDLOOP.

aRs

16 REPLIES 16
Read only

former_member194669
Active Contributor
0 Likes
1,385

Hi,

Check this



SORT IT_EKPO BY KUNNR.
LOOP AT IT_EKPO INTO WA_EKPO.

READ TABLE IT_KNA1 INTO WA_KNA1 WITH KEY KUNNR = WA_EKPO-KUNNR BINARY SEARCH.
IF SY-SUBRC = 0.
WA_KNA1-KUNNR = WA_EKPO-KUNNR.
modify it_kna1 from wa_kna1.  " PUT INSIDE IF
ENDIF.
ENDLOOP.

aRs

Read only

0 Likes
1,384

Hi Ars,

i got a dump we cant use modify inside a loop.

regards

jana

Read only

Former Member
0 Likes
1,384

Hi,

try doing this

SORT IT_EKPO BY KUNNR.
LOOP AT IT_EKPO INTO WA_EKPO.

<b> w_sytabix = sy-tabix.</b>
READ TABLE IT_KNA1 INTO WA_KNA1 WITH KEY KUNNR = WA_EKPO-KUNNR BINARY SEARCH.
IF SY-SUBRC = 0.
WA_KNA1-KUNNR = WA_EKPO-KUNNR.
ENDIF.
<b>modify it_kna1 from wa_kna1 index w_sytabix</b>.
ENDLOOP.

Cheers

VJ

Read only

0 Likes
1,384

hi VJ,

its working but its not modifying it_kna1 and i am not getting the next customer number.

i mean bfore it_kna1 is having 2 entries and after modify it shud be 3 but its skipping out the last entry

regards

jana.

Read only

Former Member
0 Likes
1,384

Are you sure you want to do:

modify it_kna1 from wa_kna1.

outside of the if - statement?

Chris

Read only

Former Member
0 Likes
1,384

Change the modify statement to

MODIFY it_kna1 FROM wa_kna1 WHERE kunnr = wa_kna1-kunnr.

Read only

former_member194669
Active Contributor
0 Likes
1,384

Hi,

Use with modify inside the IF and ENDIF statement and also use index option. Why it is giving dump is it is not find proper index to modify the I_KNA1 table


modify it_kna1 from wa_kna1 index sy-tabix.  

aRs

Read only

Former Member
0 Likes
1,384

IF SY-SUBRC = 0.

WA_KNA1-KUNNR = WA_EKPO-KUNNR.

<b>modify <i>TABLE</i> it_kna1 from wa_kna1.</b>

ENDIF.

You have to use <b>MODIFY TABLE it_kna1 from wa_kna1</b> statement... then it wont give the dump..

One suggestion .. you should put MODIFY statement should be inside IF... ENDIF.

Reward if useful

Regards

Prax

Read only

0 Likes
1,384

hi folks,

Still not working folks,

thing is i have material 13 which is ordered by 2 customers like

material customer no.

13 a

13 a

13 b

but kna1 will have only 2 entries i have to modify as per the material .

and using modify i am not getting the 3rd entry.

please guide me.

regards

jana

Read only

0 Likes
1,384

Check my last post....

<i>

I'm not getting..why u r reading a record from KNA1 for EKPO-KUNNR... and then if record is read then u r assigning same value to KNA1-KUNNR.

So it will never get updated..

wa_ekpo-kunnr and wa_kna1-kunnr will always be same..

since u have read the data from KNA1 for wa_ekpo-kunnr..

Are u sure u have to update... IT_KNA1 from IT_EKPO..

I think it should be reverse...

Have a thought.. tell me if I'm wrong..

Regards

Prax

</i>

Regards

Prax

Read only

0 Likes
1,384

hi Prax,

The how wud i go forward of getting the customer numbers based on the materials ..

please guide me i am unable to get it.

regards'

jana

Read only

0 Likes
1,384

Hi.. I'm not much aware of these tables.. since I'm working more on HR module..

but what I think I think..

u r not using correct tables..

In EKPO, EBELN and EBELP are primary key fields..

In KNA1, KUNNR is primary field.

so based on MATNR in EKPO, u want to update KUNNR in KNA1. procedure seems to be wrong.. consult ur functional person for more info or may be somebody else here can tell u..

I told u the wrong logic in ur code...

<b><i>One more thing I found in ur logic is..

13 a

13 a

13 b

You will get only 2 entries in KNA1..

since there are only two customer numbers...

from where this 3rd one came ?</i>

</b>

Regards

Prax

Read only

0 Likes
1,384

hi folks,

let me put this way.

i have to group materials by customer .

material customer

13 a

13 a

-


13 b

i have to update kna1 as i will be getting address numbers based upon kunnr .

how wud i go fwd for this requirement

regards

jana

Read only

0 Likes
1,384

Irrespective of how many material customer combinations you have, you need only one kna1 record per customer and from the same KNA1 record, you will get one ADRNR per customer and you can get the address from ADRC using ADRNR. Your logic should be

loop at it_ekpo.

read table it_kna1 with key kunnr = it_ekpo-customer.

if sy-subrc = 0.

select from ADRC where adrnr = it_kna1-adrnr.

endif.

endloop.

EKPO is for POs, how are you getting customers here? Are you taking EKPO-KUNNR? Sometimes, you can override the address in the PO itself and in such cases, EKPO-ADRNR will be filled in. So you may not even have to go to KNA1.

Read only

Former Member
0 Likes
1,384

I'm not getting..why u r reading a record from KNA1 for EKPO-KUNNR... and then if record is read then u r assigning same value to KNA1-KUNNR.

So it will never get updated..

wa_ekpo-kunnr and wa_kna1-kunnr will always be same..

since u have read the data from KNA1 for wa_ekpo-kunnr..

Are u sure u have to update... IT_KNA1 from IT_EKPO..

I think it should be reverse...

Have a thought.. tell me if I'm wrong..

Regards

Prax

Read only

former_member194669
Active Contributor
0 Likes
1,384

Hi,

I think you want to update the i_KNA1 ?


SORT IT_EKPO BY KUNNR.
LOOP AT IT_EKPO INTO WA_EKPO.
READ TABLE IT_KNA1 INTO WA_KNA1 WITH KEY KUNNR = WA_EKPO-KUNNR BINARY SEARCH.
IF SY-SUBRC NE 0.
WA_KNA1-KUNNR = WA_EKPO-KUNNR.
Append wa_kna1 to i_kna1.
ENDIF.
ENDLOOP.


aRs