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

problem with standard routine

Former Member
0 Likes
521

Hello All

Can anyone find out mistake in this code.

DATA: I TYPE I, " Number of PO item lines

HEADER_AMOUNT LIKE TKOMV-KWERT. " Header amount

  • Determine header condition amount.

READ TABLE TKOMV WITH KEY KPOSN = 0 KSCHL = XKOMV-KSCHL.

CHECK SY-SUBRC IS INITIAL.

HEADER_AMOUNT = TKOMV-KWERT.

  • Determine number of PO item lines

LOOP AT TKOMV WHERE NOT KPOSN IS INITIAL.

AT NEW KPOSN.

I = I + 1.

ENDAT.

ENDLOOP.

CHECK NOT I IS INITIAL.

  • Apportion header amount to item condition

XKWERT = HEADER_AMOUNT / I.

The loop is not ending in this case.

Points will be rewarded if my problem is solved.

4 REPLIES 4
Read only

Former Member
0 Likes
487

Sonal,

To find the number of items please correct the code as below:

  • Determine number of PO item lines

LOOP AT TKOMV WHERE<b> KNUMV = TKOMV-KNUMV</b>

AND NOT KPOSN IS INITIAL.

AT NEW KPOSN.

I = I + 1.

ENDAT.

ENDLOOP.

Keep rest all code as it is.

Let me know if this works,

Thanks.

Read only

Former Member
0 Likes
487

Putting a Where statement on your LOOP. Then having the AT NEW command will not work.

Try the following: -

LOOP AT TKOMV.

check not KPOSN is initial.

AT NEW KPOSN.

I = I + 1.

ENDAT.

ENDLOOP.

Read only

Former Member
0 Likes
487

Hi Sonal,

Is KPOSN the first field in the table TKOMV? It should be the first field to use at new kposn.

Also, you must sort t_komv on the field KPOSN first .

sort t_komv by KPOSN.

Regards,

Ravi

Read only

Former Member
0 Likes
487

Sonal ,

KPOSN will always Unique for each and every line, So no need to do all these Stuff . Directly u can find out no of line items ?

<b>by using describe or loop-endloop.</b>

Reegards

prabhu