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

Select single within a loop

Former Member
0 Likes
1,096

Hi,

I have one here that puzzles me. Why can the select not select the record within a loop ?

LOOP AT t_condtab INTO wa_condtab.

READ TABLE t_kotetab WITH KEY knuma = wa_condtab-knuma.

WRITE t_kotetab-kschl TO wa_condtab-kschl.

WRITE t_kotetab-vkorg TO wa_condtab-vkorg.

WRITE t_kotetab-kunnr TO wa_condtab-kunnr.

WRITE t_kotetab-zzprodh4 TO wa_condtab-zzprodh4.

WRITE t_kotetab-knumh TO wa_condtab-knumh.

SELECT SINGLE name1 INTO wa_condtab-name1

FROM kna1

WHERE kunnr = wa_condtab-kunnr.

MODIFY t_condtab FROM wa_condtab.

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,058

instead of writing -

WRITE t_kotetab-kschl TO wa_condtab-kschl.

WRITE t_kotetab-vkorg TO wa_condtab-vkorg.

WRITE t_kotetab-kunnr TO wa_condtab-kunnr.

WRITE t_kotetab-zzprodh4 TO wa_condtab-zzprodh4.

WRITE t_kotetab-knumh TO wa_condtab-knumh.

write -

wa_condtab-kunnr = t_kotetab-vkorg .

also check if the program if going into loop by putting a break point.i mean if table t_condtab has any data or not.

11 REPLIES 11
Read only

Former Member
0 Likes
1,059

instead of writing -

WRITE t_kotetab-kschl TO wa_condtab-kschl.

WRITE t_kotetab-vkorg TO wa_condtab-vkorg.

WRITE t_kotetab-kunnr TO wa_condtab-kunnr.

WRITE t_kotetab-zzprodh4 TO wa_condtab-zzprodh4.

WRITE t_kotetab-knumh TO wa_condtab-knumh.

write -

wa_condtab-kunnr = t_kotetab-vkorg .

also check if the program if going into loop by putting a break point.i mean if table t_condtab has any data or not.

Read only

athavanraja
Active Contributor
0 Likes
1,058

whats the sy-subrc after select stt.

debug, you will find it yourself.

Raja

Read only

Former Member
0 Likes
1,058

Hello,

Does wa_condtab-kunnr is having data when it is used in select statement.

Check it in debug mode.

Alse check does wa_condtab-kunnr is having leading zero's.

If useful reward.

Vasanth

Read only

Former Member
0 Likes
1,058

Hi Peter ,

The select must select data in loop also till you give the correct values in the where clause.

So please check the following , is there data in the table for the condition you are giving in the where clause and if yes please check if the preceeding zeros are same in both the select statement and the transparent table.

Regards

Arun

Read only

Former Member
0 Likes
1,058

Hi Peter,

is wa_condtab-kunnr LIKE KNA1-KUNNR?

*

look via debugger if wa_condtab-kunnr is filled as you need.

Regards, Dieter

Read only

Former Member
0 Likes
1,058

its may be because of read table and the statement

WRITE t_kotetab-kunnr TO wa_condtab-kunnr.

here your wa_condtab-kunnr value is replaced by t_kotetab-kunnr .

just check whether it is containing the correct value or not.

regads

shiba dutta

Read only

Former Member
0 Likes
1,058

Hi Peter

Try this way:

Use FM:CONVERSION_EXIT_ALPHA_INPUT for leading ZEROES for KUNNR and then use in select statement.

Eg: kun type kunnr.

LOOP AT t_condtab INTO wa_condtab.

   READ TABLE t_kotetab WITH KEY knuma = wa_condtab-knuma.

   WRITE t_kotetab-kschl TO wa_condtab-kschl.
   WRITE t_kotetab-vkorg TO wa_condtab-vkorg.
   WRITE t_kotetab-kunnr TO wa_condtab-kunnr.
   WRITE t_kotetab-zzprodh4 TO wa_condtab-zzprodh4.
   WRITE t_kotetab-knumh TO wa_condtab-knumh.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    INPUT         = wa_condtab-kunnr
  IMPORTING
    OUTPUT        = kun.

   SELECT SINGLE name1 INTO wa_condtab-name1
      FROM kna1
      WHERE kunnr = kun.

   MODIFY t_condtab FROM wa_condtab.

ENDLOOP.

Kind Regards

Eswar

Read only

surya_gupta3
Explorer
0 Likes
1,058

Most probably the statement

READ TABLE t_kotetab WITH KEY knuma = wa_condtab-knuma.

is failing. Please write

READ TABLE t_kotetab WITH KEY knuma = wa_condtab-knuma.

IF SY-SUBRC <> 0.

*MESSAGE

continue.

ENDIF.

Read only

Former Member
0 Likes
1,058

LOOP AT t_condtab INTO wa_condtab.

READ TABLE t_kotetab WITH KEY knuma = wa_condtab-knuma.

<b>if sy-subrc eq 0.</b>

WRITE t_kotetab-kschl TO wa_condtab-kschl.

WRITE t_kotetab-vkorg TO wa_condtab-vkorg.

WRITE t_kotetab-kunnr TO wa_condtab-kunnr.

WRITE t_kotetab-zzprodh4 TO wa_condtab-zzprodh4.

WRITE t_kotetab-knumh TO wa_condtab-knumh.

SELECT SINGLE name1 INTO wa_condtab-name1

FROM kna1

WHERE kunnr = wa_condtab-kunnr.

MODIFY t_condtab FROM wa_condtab.

<b>endif.</b>

ENDLOOP.

please check sy-subrc after read and always check sy-subrc after read.

regds,

kiran

Read only

Former Member
0 Likes
1,058

HI,

This may help you solve your issue.

Use MOVE in place of WRITE.

Put a breakpoint and see whats the value in wa_condtab-kunnr.

Try to see if you have any value in the NAME1 field in the table KNA1 through SE16 for the same KUNNR.

Just check whats the value of SY-SUBRC after the SELECT Query.

Revert if you still face problems.

Thanks

Mayank

Read only

Former Member
0 Likes
1,058

Dear Peter,

Before the Loop Statement, ensure that the Table - t_kotetab is sorted by KNUMA.

SORT t_kotetab BY knuma.

LOOP AT t_condtab INTO wa_condtab.

READ TABLE t_kotetab WITH KEY knuma = wa_condtab-knuma

BINARY SEARCH.

IF SY-SUBRC EQ 0.

wa_condtab-kschl = t_kotetab-kschl.

wa_condtab-vkorg = t_kotetab-vkorg.

wa_condtab-kunnr = t_kotetab-kunnr.

wa_condtab-zzprodh4 = t_kotetab-zzprodh4.

wa_condtab-knumh = t_kotetab-knumh.

SELECT SINGLE name1 INTO wa_condtab-name1

FROM kna1

WHERE kunnr = t_kotetab-kunnr.

  • ----------------------------------------------------------------------------------------------

  • You need to play with this value - name1. But within the Loop for

  • every pass the name1 values will change.

  • ----------------------------------------------------------------------------------------------

MODIFY t_condtab FROM wa_condtab TRANSPORTING kschl

vkorg

kunnr

zzprodh4

knumh.

ENDIF.

ENDLOOP.

Regards,

Abir

************************************

  • Don't forget to award Points *