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

Internal table read statement fails

Former Member
0 Likes
4,551

I am trying to read the internal table into work area with some key values. But it fails,it returns with sy-subrc =4. Can anyone help me in this?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,826

Hi Sarika,

I see that you different definition for table it_lineitemdt and workarea s_lineitemdt.

Try this.

DATA: it_lineitemdt TYPE STANDARD TABLE OF /bic/aassosit300.

DATA: s_lineitemdt LIKE LINE OF it_lineitemdt.

DATA: t_source TYPE STANDARD TABLE OF table.

DATA: s_source LIKE LINE OF t_source.

*(make sure this table t_source has first three fields are logsys, doc_number & s_ord_item.)

Get data into your t_source table.

Now get data in you it_lineitemdt table for all entries in t_source.

SELECT  logsys doc_number s_ord_item contrstart contr1end

   FROM (i_db_tab) into corresponding fields of table it_lineitemdt

      FOR all entries in t_source

WHERE logsys = t_source-logsys

      AND doc_number = t_source-doc_number

      AND s_ord_item = t_source-s_ord_item.

    sort it_lineitemdt by logsys doc_number s_ord_item.

    sort t_source by logsys doc_number s_ord_item.

LOOP at t_source into i_source.

clear s_lineitemdt.

READ TABLE it_lineitemdt into s_lineitemdt with key logsys = i_source-logsys

                                                                     doc_number = i_source-doc_number

                                                                       s_ord_item = i_source-s_ord_item                                                                       binary search.

if sy-subrc EQ 0

endif.

.

ENDLOOP.

I'm guessing this will help.

Thanks,

Amulya

21 REPLIES 21
Read only

Former Member
0 Likes
3,826

hello,

it may be the case the table is not holding a record with the key you rae passing. If not explain what is happening with an example.

best regards,

swanand

Read only

Former Member
0 Likes
3,826

Hi,

Please check the data population in internal table and u'r Read statement.

Thanks

Vivek

Read only

Former Member
0 Likes
3,826

I have check the internal table it does have the key values which I am passing. I using doc number sales order item and logsys as my key and whenever these three conditions are passing I want to populate the result fields for some date. But in any condition the dates are 00000000.

Thanks

Sarika

Read only

Former Member
0 Likes
3,826

Hi Sarika,

Can you post your read statement here? So we can help better.

Thanks,

Amulya

Read only

Former Member
0 Likes
3,826

Amulya,

Following is the code for your reference.

loop at  t_source into i_source.


      clear result_fields.


      move-corresponding i_source to result_fields.

clear s_lineitemdt.


          read table it_lineitemdt into s_lineitemdt with key


                     logsys = i_source-logsys


                 doc_number = i_source-doc_number


                 s_ord_item = i_source-s_ord_item


                                  binary search.


      if sy-subrc = 0.


         result_fields-contrstart = s_lineitemdt-contrstart.


         result_fields-contr1end = s_lineitemdt-contr1end.


      endif.


*********************************************************


*Append RESULTS_PACKAGE


*


      append result_fields to result_package.


    endloop.

Thanks

Sarika

Read only

0 Likes
3,826

hello,

you should sort the table  it_lineitemdt using fields logsys, doc_number and s_ord_item before the loop statement.

best regards,

swanand

Read only

Former Member
0 Likes
3,826

Did you sort the table it_lineitemdt before reading (by the key fields) as you are using binary search? Try that and let me know if it worked.

Thanks,

Amulya

Read only

Former Member
0 Likes
3,826

Amulya, Swanand

this is first part of my code for you rreference. I did sort the it_lineitemdt table.

select  logsys doc_number s_ord_item contrstart contr1end


       from (i_db_tab) into corresponding fields of table it_lineitemdt


              for all entries in t_source


       where logsys = t_source-logsys


and   doc_number = t_source-doc_number


       and   s_ord_item = t_source-s_ord_item.


    sort it_lineitemdt by logsys doc_number s_ord_item.

Thanks

Sarika

Read only

0 Likes
3,826

one more thing, can you send the data definition of  it_lineitemdt table

best regards,

swanand

Read only

0 Likes
3,826

During debug, try to check if data(fields logsys,doc_number,s_ord_item) in it_lineitemdt and t_source are in the same format or not. Just to see if we are missing any leading zero's for any fields. If possible try to give a screenshot of debug screen showing values.

-Amulya

Read only

Former Member
0 Likes
3,826

Swanand

Here is the data defination:

DATA: it_lineitemdt TYPE STANDARD TABLE OF /bic/aassosit300.




DATA: BEGIN OF s_lineitemdt,


            logsys TYPE /bic/aassosit300-logsys,


            doc_number TYPE /bic/aassosit300-doc_number,


            s_ord_item TYPE /bic/aassosit300-s_ord_item,


      contrstart TYPE /bic/aassosit300-contrstart,


      contr1end TYPE /bic/aassosit300-contr1end,


END OF s_lineitemdt.

Read only

0 Likes
3,826

apart from what amulya said above one moe thing to check is -

when you loop (loop at  t_source into i_source) just check that data definition of t_source and i_source is same and the fields are in same sequence.

Other than you need to send screen shot of the table and the debug point where you are reading with the key values used.

best regards,

swanand

Read only

Former Member
0 Likes
3,826

this is for your reference.

Thanks,

sarika

Read only

Former Member
0 Likes
3,826

Amulya, Swanand,

Did you get the chance to go through the screenshots?

Thanks

Sarika

Read only

0 Likes
3,826

hello,

can you send the internal table as an excel and also the screen shot of the read statement with the keys. (the current one is not that clear.)

best regards,

swanand

Read only

Former Member
0 Likes
3,827

Hi Sarika,

I see that you different definition for table it_lineitemdt and workarea s_lineitemdt.

Try this.

DATA: it_lineitemdt TYPE STANDARD TABLE OF /bic/aassosit300.

DATA: s_lineitemdt LIKE LINE OF it_lineitemdt.

DATA: t_source TYPE STANDARD TABLE OF table.

DATA: s_source LIKE LINE OF t_source.

*(make sure this table t_source has first three fields are logsys, doc_number & s_ord_item.)

Get data into your t_source table.

Now get data in you it_lineitemdt table for all entries in t_source.

SELECT  logsys doc_number s_ord_item contrstart contr1end

   FROM (i_db_tab) into corresponding fields of table it_lineitemdt

      FOR all entries in t_source

WHERE logsys = t_source-logsys

      AND doc_number = t_source-doc_number

      AND s_ord_item = t_source-s_ord_item.

    sort it_lineitemdt by logsys doc_number s_ord_item.

    sort t_source by logsys doc_number s_ord_item.

LOOP at t_source into i_source.

clear s_lineitemdt.

READ TABLE it_lineitemdt into s_lineitemdt with key logsys = i_source-logsys

                                                                     doc_number = i_source-doc_number

                                                                       s_ord_item = i_source-s_ord_item                                                                       binary search.

if sy-subrc EQ 0

endif.

.

ENDLOOP.

I'm guessing this will help.

Thanks,

Amulya

Read only

Former Member
0 Likes
3,826

Amulya,

DATA: s_lineitemdt LIKE LINE OF it_lineitemdt.

it worked. Now I am seeing the data in my target DSO. please let me know how to assign points.

Thanks a lot,

Sarika

Read only

0 Likes
3,826

hello,

If you see the replies, I had pointed out that earlier.

best regards,

swanand

Read only

0 Likes
3,826

Hello Swanand,

Thanks alot for all your help.

Read only

0 Likes
3,826

you are welcome.

Read only

Former Member
0 Likes
3,826

Amulya,

Not only that i also did

sort t_source by logsys doc_number s_ord_item.

Thanks

Sarika