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

help me pls

Former Member
0 Likes
2,071

hi experts

i have a query like this

select matnr stlal STLAN from mast

into corresponding fields of table ITAB1

for all entries in ITAB

where matnr = itab-matnr.

I have two same matnr in the itab.

this query works fine for the first matnr.

for the second matnr , it is not working and not picking the data also.

but i need to read two matnrs. Can anyone tell me how to read.

Thanks in advance.

Regards

Rajaram

1 ACCEPTED SOLUTION
Read only

VXLozano
Active Contributor
0 Likes
2,007

Ok, let's re-start the whole thing.

I will suppose, after read all your messages, that you have an internal table with some informed fields (like MATNR), and with some without information (like STLAL). You want to update those empty fields in your initial table.

DATA: wa1 LIKE LINE OF itab.
DATA: l_index TYPE sy-tabix.

LOOP AT itab INTO wa1.
  l_index = sy-tabix.
  SELECT SINGLE stlal stlan
    INTO CORRESPONDING FIELDS OF wa1
    FROM mast
    WHERE matnr = wa1-matnr.
  IF sy-subrc = 0.
    MODIFY itab FROM wa1 INDEX l_index.
  ENDIF.
ENDLOOP.

DATA: wa1 LIKE LINE OF itab,
      wa2 LIKE LINE OF itab2.
 
LOOP AT itab INTO wa1.
  CLEAR wa2.
  SELECT SINGLE matnr stlal stlan
    INTO CORRESPONDING FIELDS OF wa2
    FROM mast
    WHERE matnr = wa1-matnr.
  IF sy-subrc = 0.
    APPEND wa2 TO itab2.
  ENDIF.
ENDLOOP.
17 REPLIES 17
Read only

VXLozano
Active Contributor
0 Likes
2,007

FOR ALL ENTRIES will delete duplicates from your selection.

If you need two entries, you will need to find a workaround.

Maybe you can do a JOIN between the selection of your itab and the one with FOR ALL ENTRIES...

Or (not performance good) a LOOP itab. SELECT SINGLE. ENDLOOP. To get one entry per itab row.

Read only

Former Member
0 Likes
2,007

i think this is could be suitable one.

can you give me a example code pls.

Thanks in advance.

Regards

Rajaram

Read only

VXLozano
Active Contributor
0 Likes
2,007

As I said FOR ALL ENTRIES will delete duplicates.

SELECT *
  INTO TABLE itab
  FROM lala
  WHERE lolo.

LOOP AT itab INTO workarea.
  SELECT SINGLE *
    INTO wa2
    FROM table2
    WHERE field = workarea-field.
  APPEND wa2 INTO itab2.
ENDLOOP.

Read only

Former Member
0 Likes
2,007

Its giving error yar.

DATA: wa LIKE LINE OF itab.

DATA: wa2 LIKE LINE OF itab1.

LOOP AT itab INTO wa.

SELECT SINGLE *

INTO wa2

FROM mast

WHERE matnr = wa-matnr.

APPEND wa2 to itab1.

i tried this code.

the type of the database table and work area are not unicode

Read only

Former Member
0 Likes
2,007

Hi,

Define two separate variables for two matnr and then try to do this.

Regards,

Ameet

Read only

Former Member
0 Likes
2,007

hi raja

this is becoz ur need to loop at the table into ur work area (if tablle is w/o header line) and then fire this query to select data for both matnr .

in case ur using header line u need not include work area

just loop at itab

it is not advised touse a select inside loop so u can use for all enteries in itab fg

select a b c from database table into itab1 for all enteries in itab where matnr = itab-matnr .

reward points if helpfull

regards

swati

Read only

0 Likes
2,007

still am not getting yar

LOOP AT itab INTO wa.

SELECT SINGLE *

INTO wa2

FROM mast

WHERE matnr = wa-matnr.

APPEND wa2-stlal to itab1.

APPEND wa2-matnr to itab1.

APPEND wa2-stlan to itab1.

ENDLOOP.

i tried this code but not working

regards

Rajaram

Read only

Former Member
0 Likes
2,007

Hi Rajaram, if you want to get 2 matnr fields with the same values instead of using one field in where condition use 2 fields like

select matnr stlal STLAN from mast

into corresponding fields of table ITAB1

for all entries in ITAB

where matnr = itab-matnr and

stlal = itab-stlal.

I am not sure but it may work, regards

Read only

0 Likes
2,007

Why he would use that sentence if he had both fields? If itab1 has both fields he is seeking at itab2, he don't need to access the database, just append those fields to a new itab...

Read only

0 Likes
2,007

but i dont have the value for stlal in itab yar, so we can't check it.

Read only

Former Member
0 Likes
2,007

Hi,

Loop at ITAB.
" Here write the Conversion exit for ITAB-MATNR to conver the material number to internal format. then Modify the table
ENDLOOP.

select matnr stlal STLAN from mast
into corresponding fields of table ITAB1
for all entries in ITAB
where matnr = itab-matnr.

Regards

Sudheer

Read only

0 Likes
2,007

Holy Goddess!

Did you read the problem? He cannot use FOR ALL ENTRIES because he wants duplicate records!

Raja, you must change your in-LOOP selection syntax

a) Getting just the fields of the itab2

b) using INTO CORRESPONDING FIELDS OF wa2

Read only

VXLozano
Active Contributor
0 Likes
2,008

Ok, let's re-start the whole thing.

I will suppose, after read all your messages, that you have an internal table with some informed fields (like MATNR), and with some without information (like STLAL). You want to update those empty fields in your initial table.

DATA: wa1 LIKE LINE OF itab.
DATA: l_index TYPE sy-tabix.

LOOP AT itab INTO wa1.
  l_index = sy-tabix.
  SELECT SINGLE stlal stlan
    INTO CORRESPONDING FIELDS OF wa1
    FROM mast
    WHERE matnr = wa1-matnr.
  IF sy-subrc = 0.
    MODIFY itab FROM wa1 INDEX l_index.
  ENDIF.
ENDLOOP.

Read only

Former Member
0 Likes
2,007

select matnr stlal STLAN from mast

into corresponding fields of table ITAB1

for all entries in ITAB

where matnr = itab-matnr.

actually i want to modify the itab1 not itab,

how can change the coding.

Regards

Rajaram

Read only

Former Member
0 Likes
2,007

select query from mast table for the internal table itab.

but

the data which i pick from the mast table has to be updated or added to the itab1.

This is my requirement, suggest me.

thanks.

Regards

Rajaram

Read only

Former Member
0 Likes
2,007

Hi Lozano

I got it, now it is working pakka.

Thanks, thanks a lot.

And thank you very much to one and all who have shared your ideas.

Thank you very much.

Regards

Rajaram

Read only

VXLozano
Active Contributor
0 Likes
2,007
DATA: wa1 LIKE LINE OF itab,
      wa2 LIKE LINE OF itab2.
 
LOOP AT itab INTO wa1.
  CLEAR wa2.
  SELECT SINGLE matnr stlal stlan
    INTO CORRESPONDING FIELDS OF wa2
    FROM mast
    WHERE matnr = wa1-matnr.
  IF sy-subrc = 0.
    APPEND wa2 TO itab2.
  ENDIF.
ENDLOOP.