‎2010 Sep 01 5:02 PM
Hello ,
I am using Read statement in my program. The program is showing output but it is not accurate.
We are getting values in Table but we are not able to get values in Work area.
I am pasting the code follow.T_ADRC,T_T001W and T_EKPO are the tables in which date is getting fetched accurately.
But in T_T001w-werks or t_ekpo-werks there is no data fetched, ultimately it is making SY-SUBRC = 4.
Can you sauggest me way to remove this bug?
The code is as follows:
READ TABLE T_T001W WITH KEY WERKS = T_EKPO-WERKS BINARY SEARCH.
READ TABLE T_ADRC WITH KEY ADDRNUMBER = T_T001W-ADRNR BINARY SEARCH.
IF SY-SUBRC = 0.
T_DETAIL_REC-DTL_SHIP_TO_COUNTRY = T_ADRC-COUNTRY.
MOVE T_DETAIL_REC-DTL_SHIP_TO_COUNTRY TO T_DISPLAY_REC-DTL_SHIP_TO_COUNTRY.
ENDIF.
Please suggest me a way to move data to work area from table.
Harish
‎2010 Sep 01 7:04 PM
Hi
Whenever you read a table you first have to sort the table usinh key fields.Otherwise read will give unexpected result
The code is as follows:
SORT T_T001 ascending by bukrsREAD TABLE T_T001W WITH KEY WERKS = T_EKPO-WERKS BINARY SEARCH.
SORT T_ADRC ascending by addrnumberREAD TABLE T_ADRC WITH KEY ADDRNUMBER = T_T001W-ADRNR BINARY SEARCH.
IF SY-SUBRC = 0.
T_DETAIL_REC-DTL_SHIP_TO_COUNTRY = T_ADRC-COUNTRY.
MOVE T_DETAIL_REC-DTL_SHIP_TO_COUNTRY TO T_DISPLAY_REC-DTL_SHIP_TO_COUNTRY.
ENDIF.
Thanks
Rahul
‎2010 Sep 01 5:11 PM
Hi..
If corresponding entries exists in the tables but still sy-subrc is 4, then you need to sort the tables used, with the corresponding key field you are using in the read statement. This is because Read statement does not works properly if the tables are not sorted as per the key fields used in read.
Regards,
Karthik
‎2010 Sep 01 6:17 PM
Hi,
If you are using Binary Search then you should sort the internal table first with field you are using in the read statement.
Try to remove the binary search and check your results.
Thanks,
Venkat
‎2010 Sep 01 7:04 PM
Hi
Whenever you read a table you first have to sort the table usinh key fields.Otherwise read will give unexpected result
The code is as follows:
SORT T_T001 ascending by bukrsREAD TABLE T_T001W WITH KEY WERKS = T_EKPO-WERKS BINARY SEARCH.
SORT T_ADRC ascending by addrnumberREAD TABLE T_ADRC WITH KEY ADDRNUMBER = T_T001W-ADRNR BINARY SEARCH.
IF SY-SUBRC = 0.
T_DETAIL_REC-DTL_SHIP_TO_COUNTRY = T_ADRC-COUNTRY.
MOVE T_DETAIL_REC-DTL_SHIP_TO_COUNTRY TO T_DISPLAY_REC-DTL_SHIP_TO_COUNTRY.
ENDIF.
Thanks
Rahul
‎2010 Sep 02 9:19 AM
Dear all,
I have used Sort before read.Still it is not working properly. Will try by removing Binary Search.
Harish
‎2010 Sep 02 9:24 AM
Hi,
READ TABLE T_T001W WITH KEY WERKS = T_EKPO-WERKS BINARY SEARCH.T_EKPO is an internal table or internal table with header line ? If it is not defined as an internal table with header line, you have to read the required record into the workara and use the work area data for reading the data from internal table T_T001W. Check the same for other READ statements also.
Regards
Vinod
‎2010 Sep 02 11:48 AM
Hi,
Try the below code.Check the value os sy-subrc. Also check if value is populated in workarea.
READ TABLE T_T001W INTO WA_T001W WITH KEY WERKS = WA_EKPO-WERKS BINARY SEARCH.
IF sy-subrc eq 0.
READ TABLE T_ADRC INTO WA_ADRC WITH KEY ADDRNUMBER = WA_T001W-ADRNR BINARY SEARCH.
IF SY-SUBRC = 0.
T_DETAIL_REC-DTL_SHIP_TO_COUNTRY = WA_ADRC-COUNTRY.
MOVE T_DETAIL_REC-DTL_SHIP_TO_COUNTRY TO T_DISPLAY_REC-DTL_SHIP_TO_COUNTRY.
ENDIF.
ENDIF.
Thanks & Regards,
Neela
‎2010 Sep 06 12:07 PM
Hello,
All of you thanks for theie replies. I got the answer.
Harish