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 Read statement

Former Member
0 Likes
1,080

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,052

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 bukrs

READ TABLE T_T001W WITH KEY WERKS = T_EKPO-WERKS BINARY SEARCH.

SORT  T_ADRC  ascending by addrnumber

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.

Thanks

Rahul

7 REPLIES 7
Read only

Former Member
0 Likes
1,052

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

Read only

Former Member
0 Likes
1,052

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

Read only

Former Member
0 Likes
1,053

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 bukrs

READ TABLE T_T001W WITH KEY WERKS = T_EKPO-WERKS BINARY SEARCH.

SORT  T_ADRC  ascending by addrnumber

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.

Thanks

Rahul

Read only

0 Likes
1,052

Dear all,

I have used Sort before read.Still it is not working properly. Will try by removing Binary Search.

Harish

Read only

0 Likes
1,052

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

Read only

0 Likes
1,052

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

Read only

0 Likes
1,052

Hello,

All of you thanks for theie replies. I got the answer.

Harish