12-14-2006 12:24 PM
Here the final internal table is not being populated .Can anybody tell me, why?
Thanks in advance.......
LOOP AT it_mara INTO wa_mara.
READ TABLE it_makt INTO wa_makt WITH KEY matnr = wa_mara-matnr
BINARY SEARCH.
IF sy-subrc = 0.
MOVE wa_mara-matnr TO wa_final-matnr.
MOVE wa_mara-matkl TO wa_final-matkl.
MOVE wa_makt-maktx TO wa_final-maktx.
APPEND wa_final TO it_final.
ENDIF.
ENDLOOP.
LOOP AT it_mara INTO wa_mara.
READ TABLE it_mseg INTO wa_mseg WITH KEY matnr = wa_mara-matnr
BINARY SEARCH.
IF sy-subrc = 0.
MOVE wa_mseg-bwart TO wa_final-bwart.
APPEND wa_final TO it_final.
ENDIF.
ENDLOOP.
SORT it_final BY matnr bwart.
LOOP AT it_final INTO wa_final.
IF wa_final-bwart = '101' OR
wa_final-bwart = '103' OR
wa_final-bwart = '105'.
count_gr = count_gr + 1.
ENDIF.
IF wa_final-bwart = '201' OR
wa_final-bwart = '261' OR
wa_final-bwart = '281' OR
wa_final-bwart = '291' OR
wa_final-bwart = '301' OR
wa_final-bwart = '311' OR
wa_final-bwart = '541'.
count_gi = count_gi + 1.
ENDIF.
ENDLOOP.
12-14-2006 12:27 PM
The reason could be that both the READ TABLE statements are failing. Sort the internal tables, it_makt and it_mseg before the loop (LOOP AT it_mara INTO wa_mara). Binary search will work correctly only if the involved tables are sorted on the fields.
sort it_makt by matnr.
sort it_mseg by matnr.
loop at it_mara into wa_mara.
...
endloop.
Regards,
Manoj
12-14-2006 12:28 PM
hi ,
TRY LIKE THIS .
LOOP AT IT_MARA .
READ TABLE IT_MAKT ..............
READ TABLE IT_MSEG ..............
MOVE DATA TO WORK AREA .
APPEND WORKAREA TO IT_FINAL .
ENDLOOP .
Regards ,
Senthil
12-14-2006 12:30 PM
LOOP AT it_mara INTO wa_mara.
clear: wa_mara.
READ TABLE it_makt INTO wa_makt WITH KEY matnr = wa_mara-matnr
BINARY SEARCH.
IF sy-subrc = 0.
READ TABLE it_mseg INTO wa_mseg WITH KEY matnr = wa_mara-matnr
BINARY SEARCH.
if sy-subrc = 0.
MOVE wa_mseg-bwart TO wa_final-bwart.
MOVE wa_mara-matnr TO wa_final-matnr.
MOVE wa_mara-matkl TO wa_final-matkl.
MOVE wa_makt-maktx TO wa_final-maktx.
IF wa_final-bwart = '101' OR
wa_final-bwart = '103' OR
wa_final-bwart = '105'.
count_gr = count_gr + 1.
ENDIF.
IF wa_final-bwart = '201' OR
wa_final-bwart = '261' OR
wa_final-bwart = '281' OR
wa_final-bwart = '291' OR
wa_final-bwart = '301' OR
wa_final-bwart = '311' OR
wa_final-bwart = '541'.
count_gi = count_gi + 1.
ENDIF.
APPEND wa_final TO it_final.
ENDIF.
endif.
ENDLOOP.
Regs
Manas Ranjan Panda
12-14-2006 12:30 PM
i hope in ur post there is only one loop.
sort it_mara by matnr . " check this
LOOP AT it_mara INTO wa_mara.
READ TABLE it_mseg INTO wa_mseg WITH KEY matnr = wa_mara-matnr. "only this
IF sy-subrc = 0.
MOVE wa_mseg-bwart TO wa_final-bwart.
APPEND wa_final TO it_final.
ENDIF.
endloop.
remove the binary search for a while and see if this is populating .
regards,
vijay
Message was edited by:
Vijay
12-14-2006 12:31 PM
Hi Jyoti,
Replace you code with the below one...(two loops can be clubed)
LOOP AT it_mara INTO wa_mara.
READ TABLE it_makt INTO wa_makt WITH KEY matnr = wa_mara-matnr
BINARY SEARCH.
IF sy-subrc = 0.
MOVE wa_mara-matnr TO wa_final-matnr.
MOVE wa_mara-matkl TO wa_final-matkl.
MOVE wa_makt-maktx TO wa_final-maktx.
READ TABLE it_mseg INTO wa_mseg WITH KEY matnr = wa_mara-matnr
BINARY SEARCH.
IF sy-subrc = 0.
MOVE wa_mseg-bwart TO wa_final-bwart.
ENDIF.
APPEND wa_final TO it_final.
ENDIF.
ENDLOOP.
Regards,
Satya
12-14-2006 12:37 PM
sort it_mara by matnr .
" chk this .
regards,
vijay
12-14-2006 12:32 PM
Hi Jyothi,
You need to SORT on the field name before you use BINARY SEARCH on that field in READ statement.
Add these two lines of code prior to your main LOOP...ENDLOOP statements.
<b>SORT IT_MAKT BY MATNR.
SORT IT_MESG BY MATNR.</b>
LOOP AT it_mara INTO wa_mara.
READ TABLE it_makt INTO wa_makt WITH KEY matnr = wa_mara-matnr
BINARY SEARCH.
IF sy-subrc = 0.
MOVE wa_mara-matnr TO wa_final-matnr.
MOVE wa_mara-matkl TO wa_final-matkl.
MOVE wa_makt-maktx TO wa_final-maktx.
APPEND wa_final TO it_final.
ENDIF.
ENDLOOP.
LOOP AT it_mara INTO wa_mara.
READ TABLE it_mseg INTO wa_mseg WITH KEY matnr = wa_mara-matnr
BINARY SEARCH.
IF sy-subrc = 0.
MOVE wa_mseg-bwart TO wa_final-bwart.
APPEND wa_final TO it_final.
ENDIF.
ENDLOOP.
Thanks,
Vinay
12-14-2006 12:42 PM
hi,
If you final table not getting data. If any of the read statement failed. It won't fill internal table. First check the internal table empty or not.Do Sorting before reading data.
regards,
K. Kishore