Application Development 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 table not working

jitendra_it
Active Contributor
0 Kudos

Hello All,

This the the table structure 

field A ,B,C,D,E,F are part of primary key and there are other fields also such as G,J,I,J.

data has maintained in table.

Now field B,E,F are having some data in table(A,C,D = null) and I want to get those data using Read table statement but its getting failed

Read Table IT_XYZ into WA_XYZ  with key  A =  wa-a

                                                                B =  wa-b     

                                                                C =  wa-c

                                                                D =  wa-d

                                                                E =  wa-e

                                                                F =  wa-f

What i am doing wrong. Please suggest.

Best Regards,

Jitendra

14 REPLIES 14

Former Member
0 Kudos

From your query, the table fields A,C and D are blank in the table. So if wa-a, wa-c, wa-d are having any values, your read statement wont work as it would be searching for that values in the table.

Former Member
0 Kudos

Hi Jitendra,

Statement seems to be correct. Check wa-a, wa-b, etc... conditions might not be getting fulfilled.

Regards,

Shahir Mirza

krishna_k19
Contributor
0 Kudos

Can you provide the sample data for fields A, B,..I,J and at the same time Workarea data also then we can figure it out the problem.

Thanks in advance,

Krishna

Former Member
0 Kudos

what is the error you are facing.

I don't thing so there is anyerror in the code given by you..

Please read the following link..

http://help.sap.com/SAPHELP_470/Helpdata/EN/fc/eb35f8358411d1829f0000e829fbfe/content.htm

hope it will help you..

BR

Former Member
0 Kudos

one more thing..

Read Table IT_XYZ into WA_XYZ  with key  A =  wa-a

                                                                B =  wa-b     

                                                                C =  wa-c

                                                                D =  wa-d

                                                                E =  wa-e

                                                                F =  wa-f.

in this A =  wa-a <and>  B =  wa-b <and> ...
it works like this means each condition get appended with and statement so this can be the reason you are not getting correct data.

So you should create a dynamic query to give in the condition..

BR

Chandra..

former_member185177
Contributor
0 Kudos

Hi Jitendra,

Basic point

Before going to read any internal table, make sure that Intenal table should be sorted.

So as per your requirement sort the internal table with fields B,E and F.

READ TABLE  IT_XYZ into WA_XYZ  with key  B =  wa-b     

                                                                            E =  wa-e

                                                                            F =  wa-f

                                                             Binary search.

If SY-SUBRC = 0.

*  write your logic........................

endif.

Regards,

Krishna.

Former Member
0 Kudos

Hi Jitendra,

Are you using another READ operation to fill the workarea "WA" (mentioned in the above scenario)? 

Thanks,

Shahanaz Hussain,

Applexus Technologies.

0 Kudos

@All,

There is data exits in internal table which match criteria with wa data but still it is not working

0 Kudos

This can not be possible.

Read Table IT_XYZ into WA_XYZ  with key  A =  wa-a

                                                                B =  wa-b     

                                                                C =  wa-c

                                                                D =  wa-d

                                                                E =  wa-e

                                                                F =  wa-f.

in this A =  wa-a <and>  B =  wa-b <and> ...
it works like this means each condition get appended with and statement so this can be the reason you are not getting correct data.

something must coming wrong..

So you should create a dynamic query to give in the condition..

0 Kudos

Hi Jitendra,

If you are filling work area WA using a READ statement, then before ENDLOOP statement of the main LOOP, CLEAR workarea WA.

Thanks,

Shahanaz Hussain,

Applexus Technologies.

0 Kudos

data: BEGIN OF xyz,
     a type string,
     b type string,
     c type string,
     d type string,
     e type string,
     f type string,
END OF xyz,
it_xyz like TABLE OF xyz,
wa_xyx like xyz.

wa_xyx-= 'a'.
wa_xyx-= 'b'.
wa_xyx-= 'c'.

APPEND wa_xyx to it_xyz.
CLEAR wa_xyx.

wa_xyx-= 'b'.
wa_xyx-= 'c'.
wa_xyx-= 'd'.

APPEND wa_xyx to it_xyz.
CLEAR wa_xyx.


READ TABLE it_xyz INTO wa_xyx with KEY a = 'a' b = 'b' c = 'c'.

if sy-subrc = 0.
   write: wa_xyx-a , wa_xyx-b , wa_xyx-c.
   ENDIF.


READ TABLE it_xyz INTO wa_xyx with KEY a = 'a' b = 'b'.

if sy-subrc = 0.
   write: wa_xyx-a , wa_xyx-b , wa_xyx-c.
   ENDIF.

see the code...

Its working fine.

anubhab
Active Participant
0 Kudos

Hi Jitendra,

Query is ok as per structure. But as per your coding, it will search the table for those record, that matches the selection criteria. Now if you want to read the records from table those are having A,C & D as null, then you need to pass null value in your selection criteria for those field. Or else you can remove those or some other fields from selection criteria to get data from table. READ TABLE won't return any data, until unless it matches all the selection criteria. That is the reason, your query is failing. Hope I made myself clear.

Regards,

Anubhab

former_member182915
Active Contributor
0 Kudos

Hello Jitendra ,

syntax point of view your read statement is ok, and also you say data is in the internal table , if for some field the value is null better remove from query . again if you thing you condition is right just put a break point before read  statement and do a check in debug mode that acc to condition is their any record in internal table if record is in internal table and not fetched that means the condition needed to fetch record are not still provided.

Hope This will Solve Your Problem.

former_member946717
Contributor
0 Kudos

Hi Jitendra,

As Krishna Chaitnya already said,

SORT IT_XYZ BY B E F.

READ TABLE IT_XYZ INTO WA_XYZ  WITH KEY B =  WA-B     

                                                                        E =  WA-E

                                                                        F =  WA-F

                                                             BINARY SEARCH.

This will surely work!