2007 Jul 18 7:35 AM
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
2007 Jul 18 9:30 AM
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.
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.
2007 Jul 18 7:38 AM
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.
2007 Jul 18 7:45 AM
i think this is could be suitable one.
can you give me a example code pls.
Thanks in advance.
Regards
Rajaram
2007 Jul 18 7:48 AM
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.
2007 Jul 18 8:49 AM
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
2007 Jul 18 7:39 AM
Hi,
Define two separate variables for two matnr and then try to do this.
Regards,
Ameet
2007 Jul 18 7:43 AM
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
2007 Jul 18 9:02 AM
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
2007 Jul 18 7:51 AM
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
2007 Jul 18 7:56 AM
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...
2007 Jul 18 9:00 AM
but i dont have the value for stlal in itab yar, so we can't check it.
2007 Jul 18 9:05 AM
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
2007 Jul 18 9:26 AM
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
2007 Jul 18 9:30 AM
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.
2007 Jul 18 9:51 AM
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
2007 Jul 18 9:59 AM
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
2007 Jul 18 10:25 AM
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
2007 Jul 18 10:25 AM
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.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |