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 in loop

laxman_sankhla3
Participant
0 Likes
1,019

hi

i need help

FORM GET_DATA.

SELECT AEBELN ALIFNR AEKORG AKNUMV BVGABE BGJAHR B~BELNR

LNAME1 LNAME2

FROM EKKO AS A

INNER JOIN EKBE AS B ON BEBELN = AEBELN

INNER JOIN LFA1 AS L ON LLIFNR = ALIFNR

INTO CORRESPONDING FIELDS OF TABLE ITAB .

  • WHERE B~VGABE = '2'.

SELECT EKPOEBELN EKPOEBELP EKPOMATNR EKPOTXZ01 EKPO~WERKS

EKPONETWR EKPOMENGE EKPOMWSKZ EKPONETPR EKPO~PACKNO

FROM EKPO

INTO CORRESPONDING FIELDS OF TABLE ITAB1

FOR ALL ENTRIES IN ITAB

WHERE EKPO~EBELN = ITAB-EBELN and

EKPO~BUKRS = 'GSPL'.

LOOP AT ITAB.

READ TABLE ITAB1 WITH KEY EBELN = ITAB-EBELN.

  • IF ITAB1-EBELN = ITAB-EBELN.

IF sy-subrc eq 0.

  • ITAB1-EBELN = ITAB-EBELN.

ITAB1-LIFNR = ITAB-LIFNR.

  • ITAB1-EBELP = ITAB-EBELP.

ITAB1-BELNR = ITAB-BELNR.

ITAB1-KNUMV = ITAB-KNUMV.

ITAB1-NAME1 = ITAB-NAME1.

ITAB1-NAME2 = ITAB-NAME2.

ITAB1-GJAHR = ITAB-GJAHR.

modify itab1 index sy-tabix.

ENDIF.

<b>for above code all data coming right for each and every line item .

and for below code nothing is coming</b> .

SELECT KONVKNUMV KONVKSCHL KONVKBETR KONVKPOSN KONV~KWERT

KONV~KPOSN FROM KONV

INTO CORRESPONDING FIELDS OF TABLE ITAB5

WHERE KONV~KNUMV = ITAB1-KNUMV and

konv~knumv = itab1-ebelp and

Konv~lifnr = itab1-lifnr.

<b>loop at itab5.

READ TABLE ITAB5 WITH KEY knumv = ITAB1-knumv .

IF sy-subrc eq 0.

IF ITAB5-KSCHL = 'NAVS' OR ITAB5-KSCHL = 'NAVM'.

ITAB1-KBETR = ITAB5-KBETR.

modify ITAB1 transporting KBETR

where KNUMV = ITAB1-KNUMV AND EBELP = ITAB1-EBELP .

ELSEIF ITAB5-KSCHL = 'FRA1' OR ITAB5-KSCHL = 'FRC1' OR

ITAB5-KSCHL = 'FRB1'.

ITAB1-KWERT = ITAB5-KWERT .

modify ITAB1 transporting KWERT

where KNUMV = ITAB1-KNUMV AND EBELP = ITAB1-EBELP.

.

endif.

endif.</b>

ENDLOOP.

endloop.

please help me

thanks .

9 REPLIES 9
Read only

Former Member
0 Likes
994

SELECT KONVKNUMV KONVKSCHL KONVKBETR KONVKPOSN KONV~KWERT

KONV~KPOSN FROM KONV

INTO CORRESPONDING FIELDS OF TABLE ITAB5

<b>for all entries in itab1</b> -> use for all entries

WHERE KONV~KNUMV = ITAB1-KNUMV and

konv~knumv = itab1-ebelp and

Konv~lifnr = itab1-lifnr.

Read only

Former Member
0 Likes
994

Hi

see better to write the join for EKKO,EKPO,and LFNR and EKBE together because we have to pass ekko-knumv and ekpo-ebelp fields to konv-knumv and konv-kposn fields

in your case they are in different int tables

knumv in ITAB and ebelp in ITAB1

fetch ekbe-ebelp into itab1 and use that

see the code

if not itab1[] is initial.

SELECT KONVKNUMV KONVKSCHL KONVKBETR KONVKPOSN KONV~KWERT

KONV~KPOSN FROM KONV

<b>INTO CORRESPONDING FIELDS OF TABLE ITAB5

for all entries in itab1</b>

WHERE <b>KONV~KNUMV = ITAB1-KNUMV and

konv~kposn = itab1-ebelp</b> .

Reward points for useful Answers

Regards

Anji

Message was edited by:

Anji Reddy Vangala

Read only

0 Likes
994

is there any problem in Loop .

because for first line item value is coming for some Purchase Order

and second line item is not coming .

thanks.

Read only

0 Likes
994

Yes - see my other response.

Rob

Read only

Former Member
0 Likes
994

Laxman,

Can you see if the select statement is working?

If not, use for all entries.

If the problem is in the Loop, i think it is because of the READ TABLE.

You are reading a table that is not sorted, so the statement READ TABLE won't work.

Reward points if helpful please.

Regrads.

Read only

0 Likes
994

loop at itab5.

problem in read table

READ TABLE ITAB1 WITH KEY knumv = ITAB5-knumv .

IF sy-subrc eq 0.

IF ITAB5-KSCHL = 'NAVS' OR ITAB5-KSCHL = 'NAVM'.

ITAB1-KBETR = ITAB5-KBETR.

modify ITAB1 transporting KBETR

where KNUMV = ITAB1-KNUMV AND EBELP = ITAB1-EBELP .

ELSEIF ITAB5-KSCHL = 'FRA1' OR ITAB5-KSCHL = 'FRC1' OR

ITAB5-KSCHL = 'FRB1'.

ITAB1-KWERT = ITAB5-KWERT .

modify ITAB1 transporting KWERT

where KNUMV = ITAB1-KNUMV AND EBELP = ITAB1-EBELP.

.

endif.

endif.

ENDLOOP.

endloop.

Read only

former_member194669
Active Contributor
0 Likes
994

Hi,

Check this


select konv~knumv konv~kschl konv~kbetr konv~kposn konv~kwert
konv~kposn from konv
into corresponding fields of table itab5
for all entries in itab1
where konv~knumv = itab1-knumv and
konv~kposn = itab1-ebelp .

loop at itab.
  read table itab1 with key ebeln = itab-ebeln.
  if sy-subrc eq 0.
    itab1-lifnr = itab-lifnr.
    itab1-belnr = itab-belnr.
    itab1-knumv = itab-knumv.
    itab1-name1 = itab-name1.
    itab1-name2 = itab-name2.
    itab1-gjahr = itab-gjahr.

    modify itab1 index sy-tabix.

    loop at itab5 where knumv = itab1-knumv
      if itab5-kschl = 'NAVS' or itab5-kschl = 'NAVM'.
      itab1-kbetr = itab5-kbetr.
      modify itab1 transporting kbetr
      where knumv = itab1-knumv and ebelp = itab1-ebelp .

    elseif itab5-kschl = 'FRA1' or itab5-kschl = 'FRC1' or
      itab5-kschl = 'FRB1'.
      itab1-kwert = itab5-kwert .
      modify itab1 transporting kwert
      where knumv = itab1-knumv and ebelp = itab1-ebelp.
    endif.
  endloop.

endif.
endloop.

aRs

Read only

Former Member
0 Likes
994

I don't know the effects of using a read table inside a loop, on the same itab here:

loop at itab5.

READ TABLE ITAB5 WITH KEY knumv = ITAB1-knumv .

IF sy-subrc eq 0.

But you could use an if instead of the read table... replacing the mentioned code with this:

LOOP AT itab5.

IF itab5-knumv = itab1-knumv.

Read only

Former Member
0 Likes
994

If you loop at itab5 and within that loop read itab5, I don't know what the results will be. Better to work out clearer logic.

Rob