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: 

ABAP code. Not returning any value..Please help

Former Member
0 Kudos

Hi All,

I need some help with this code...

DESCRIBE TABLE itab1 LINES lin.

IF lin = 1.

select single * INTO table itab2 from mara

where matnr = itab1-matnr.

IF sy-subrc EQ 0.

W_matnr = itab2-matnr.

ENDIF.

ENDLOOP.

My Itab1 is having 1 record but by select single statement is returning with subrc 4 as I don't have value in header, can you please help in this code.

Thank You.

Sunitha

1 ACCEPTED SOLUTION

former_member188685
Active Contributor
0 Kudos

try the changes..

DESCRIBE TABLE itab1 LINES lin.

IF lin = 1.
read table itab1 index 1.  "add this , if it is with header line, else use work area
select single * INTO table itab2 from mara
where matnr = itab1-matnr. 
IF sy-subrc EQ 0.
W_matnr = itab2-matnr.
ENDIF.
.

12 REPLIES 12

Former Member
0 Kudos

Hi,

Can you please share the complete LOOP.....ENDLOOP... that you written for itab1.

0 Kudos

Hi Ajay,

Thank you for your quick reply, Actually there is no loop statements, I have mistypes it.

I have a internal table (itab1) with 1 record and I wanted to get data from mara table based on itab1-matnr.

How can I do that. Thank you.

Regards

Sunitha.

0 Kudos

Hi,

I hope Vijay solution should work for you.......Have you tried that.....I believe in your code..the value of itab1-matnr is missing......Probably because you didn't filled the header line of itab1...and hence get the itab1 header line filled by using READ Statement

0 Kudos

since you are using select single , so don't use internal table

data: wa_mara type mara.

select single * INTO wa_mara from mara
where matnr = itab1-matnr. 
IF sy-subrc EQ 0.
W_matnr = wa_mara-matnr.
ENDIF

.

internal tables with Header line is old style. In OO context you have to use table with out header line, you have to use explict workarea.

0 Kudos

HI Ajay/ Vijay,

Thank you for guiding me. I also thank SDN team for this opportunity.

I will give points to both of u.

Thank u.

former_member188685
Active Contributor
0 Kudos

try the changes..

DESCRIBE TABLE itab1 LINES lin.

IF lin = 1.
read table itab1 index 1.  "add this , if it is with header line, else use work area
select single * INTO table itab2 from mara
where matnr = itab1-matnr. 
IF sy-subrc EQ 0.
W_matnr = itab2-matnr.
ENDIF.
.

0 Kudos

HI Vijay,

Thank You, I have changed the program according to your suggestion, I got the good results in itab2 but again when I am moving into w_matnr. Itab2-matnr field in not having any value.

Looks like always header line does not have any value. please suggest.

Thank you.

sunitha.

0 Kudos

Hi,

Use this

select single * INTO corresponding fields of table itab2 from mara

where matnr = itab1-matnr.

0 Kudos

Sorry that, I am confused since you are using "Select.. Single" you will be resulting in one set of records every time. So, why do you want to use a table to store it. If you want only one value for verification.

data: l_matnr like mara-matnr.

IF lin = 1.

select single * INTO l_matnr from mara

where matnr = itab1-matnr.

ENDIF.

you can use the same l_matnr for next processing steps.

0 Kudos

Try it the easy way:

DESCRIBE TABLE itab1 LINES lin.

IF lin = 1.
  READ TABLE itab1 INDEX 1.
  SELECT SINGLE * FROM mara
  WHERE matnr = itab1-matnr.
  IF sy-subrc EQ 0.
    w_matnr = mara-matnr.
  ENDIF.
ENDIF.

Rob

0 Kudos

Rob,

Your ABAP tip/trick is very useful.

Thank U,

Sunitha

Edited by: Sunitha Reddy on Oct 20, 2008 10:11 PM

0 Kudos

But bear in mind that you need to use an explicit work area in classes.

Rob