03-31-2008 11:03 AM
Hi all
am retriving the matnrs from mara table into an internal table it_mara
then what i need is
A description of each relevant material should be retrieved from the Material Descriptions table (MAKT).
To retrieve the records, select from the table according to the following criteria:
MAKT-MATNR (Material) IN Material (Note 5 selection)
MAKT-SPRAS (Language key) EQ SY-LANGU (Users logon language)
Retrieve the Material description field (MAKTX). If a description is not found, a default text should be substituted indicating no material description.
what should i do.
03-31-2008 11:06 AM
Try like this..
data: begin of itab occurs 0,
matnr like makt-matnr,
maktx like makt-maktx,
end of itab.
select matnt maktx into corresponding fields of table itab from makt for all entries in itab where matnr = itab-matnr and spras = 'E'.
loop at itab.
if itab-maktx is initial.
itab-maktx = 'UR DESCRIPTION'.
endif.
modify itab.
clear:itab.
endloop.
Reward if usefull...
Regards
Sugumar G
Edited by: Sugumar Ganesan on Mar 31, 2008 12:17 PM
Edited by: Sugumar Ganesan on Mar 31, 2008 12:36 PM
03-31-2008 11:07 AM
The specification tells you precisely what to do, doesn't it?
"To retrieve the records, select from the table (MAKT) according to the following criteria:
MAKT-MATNR (Material) IN Material (Note 5 selection)
MAKT-SPRAS (Language key) EQ SY-LANGU (Users logon language)"
I'm not sure how it can be clearer than that. Try reading the help on the ABAP keyword "SELECT".
matt
03-31-2008 11:13 AM
see my problem is not for the slection part
the problem is while selecting for the corresponding materials if one materila does not have the description then i have to update it by writing "no description" and then update that internal table
now how to do it ahile doing the selection process not after the selection
03-31-2008 11:08 AM
once you get the data in your internal table, you can do as follows
loop at itab into wa.
if wa-maktx is initial.
wa-maktx = <some default text>
endif.
modify itab from wa transporting maktx.
endloop.
03-31-2008 11:13 AM
Hi,
Try the following,
loop at it_mara.
select single maktx from makt where matnr = it_mara-matnr and
spras = 'EN'.
if sy-subrc = 0.
it_mara-maktx = makt-maktx.
else.
it_mara-maktx = 'default text'.
endif.
modify it_mara index sy-tabix.
endloop.
03-31-2008 11:14 AM
Hi,
Loop at itab.
select single * from makt where matnr = itab-matnr and
spras = sy-langu.
if sy-subrc eq 0.
move : makt-maktx to itab-maktx.
else.
move : 'no text found' to itab-maktx.
endif.
modify itab iindex sy-tabix.
endloop.
Regards,
Morris Bond.
03-31-2008 11:16 AM
HI,
Tables: mara, makt.
data: begin of itab occurs 0,
matnr like mara-matnr,
maktx like makt-maktx,
end of itab.
select-options: s_matnr for mara-matnr.
Select * from mara into corresponding fields of table itab where matnr in s_matnr.
loop at itab.
select single * from makt where matnr = itab-matnr
and spras = SY-LANGU .
if makt-maktx is initial.
itab-maktx = 'defauld description'.
else.
itab-maktx = makt-maktx.
endif.
modify itab.
clear itab.
Write:/ itab-matnr , itab-maktx.
endloop.
Regards,
S.Nehru.
03-31-2008 11:28 AM
Hi
the solution you provided will owrk fine
but as per selection is considered it is always advised not to do the selection inside a loop
so what should i do now in order to avoid my performance issues here
03-31-2008 11:47 AM
Hi,
Try This code,
Tables: mara, makt.
data: begin of it_mara occurs 0,
matnr like mara-matnr,
end of it_mara.
data: begin of it_makt occurs 0,
matnr like makt-matnr,
maktx like makt-maktx,
end of it_makt.
data: begin of itab occurs 0,
matnr like mara-matnr,
maktx like makt-maktx,
end of itab.
select-options: s_matnr for mara-matnr.
Select matnr from mara into table it_mara where matnr in s_matnr.
if not it_mara[] is initial.
select maktx from makt into table it_makt for all ENTRIES IN it_mara
WHERE matnr = it_mara-matnr
and spras = SY-LANGU .
endif.
loop at it_mara.
READ TABLE it_makt WITH KEY matnr = it_mara-matnr.
itab-matnr = it_mara-matnr.
if it_makt-maktx is initial.
itab-maktx = 'defauld description'.
else.
itab-maktx = it_makt-maktx.
endif.
APPEND itab.
clear itab.
endloop.
LOOP at itab.
Write:/ itab-matnr , itab-maktx.
endloop.
Regards,
Brown.
03-31-2008 12:30 PM
I'd do an outer join on MARA and MAKT into the internal table. Then sort the itab by description, and loop through it, setting the default description so long as the description is blank.
matt