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

An interview Question

Former Member
0 Likes
1,471

I have one internal table which contains material number field and a material description field. Material number field is filled and material desc field is left empty. I need to fill the mat desc field corresponding to the materialno field that is there in the internal table. From which table you will have to select the material desc field and what is the logic??

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,433

from makt table.

select matnr

maktx

from makt

into table it_makt

for all entries in it_mara

where matnr = it_mara-matnr

and spras = 'EN'.

loop at it_mara.

lv_tabix = sy-tabix.

read table it_makt with key matnr = it_mara-matnr.

if sy-subrc = 0.

it_mara-maktx = it_makt-maktx.

modify it_mara index lv_tabix.

endif.

endloop.

Regards,

Ravi

17 REPLIES 17
Read only

Former Member
0 Likes
1,433

Hi

- MARA is the table for master data

- MAKT is the table for the shirt descriptions

SELECT SINGLE * FROM MAKT WHERE SPRAS = SY-LANGU

AND MATNR = MARA-MATNR.

Max

Read only

Former Member
0 Likes
1,433

Hi srininvas,

1.

DATA : TABIX TYPE SY-TABIX.

LOOP AT ITAB.

SELECT SINGLE MAKTX

INTO ITAB-MAKTX

FROM MAKT

WHERE MATNR = ITAB-MATNR

AND SPRAS = SY-LANGU.

MODIFY ITAB INDEX SY-TABIX.

ENDLOOP.

regards,

amit m.

Read only

0 Likes
1,433

Hi Amit,

As per your logic, if I have 1000 records in itab, then the select stmt should run 1000 times, a performance issue. Hope we should not use Select stmt in a loop. What do you say?

Regards,

Srinu.

Read only

0 Likes
1,433

Have a empty table exactly like the one you have and use the for all entries clause.

IF NOT ITAB[] IS INITIAL.

SELECT MATNR MAKTX FROM MAKT

FOR ALL ENTRIES OF ITAB

WHERE MATNR = ITAB-MATNR.

ENDIF.

This way you will get all the values in one shot.

Regards,

Ravi

Note : Please close the thread if the issue is resolved

Read only

0 Likes
1,433

Hi srinivas,

1. Yes, you are perfectly right.

2. To reduce, this,

we should use FOR ALL ENTRIES.

3. Then the program will go like this.

(only one database read)

4. Just copy paste.

5.

report abc.

*----


DATA : BEGIN OF ITAB OCCURS 0,

MATNR LIKE MARA-MATNR,

MAKTX LIKE MAKT-MAKTX,

END OF ITAB.

data : TABIX TYPE SY-TABIX.

*----- EXTRA INTERNAL TABLE

DATA : MYTAB LIKE TABLE OF ITAB WITH HEADER LINE.

*----


START-OF-SELECTION.

ITAB-MATNR = '000000000000000004'.

APPEND ITAB.

ITAB-MATNR = '000000000000000005'.

APPEND ITAB.

ITAB-MATNR = '000000000000000006'.

APPEND ITAB.

*----


Select in MYTAB

if itab[] is not initial.

SELECT MATNR MAKTX FROM MAKT

INTO TABLE MYTAB

FOR ALL ENTRIES IN ITAB

WHERE MATNR = ITAB-MATNR

AND SPRAS = SY-LANGU.

*----


loop at itab.

TABIX = SY-TABIX.

READ TABLE MYTAB WITH KEY MATNR = ITAB-MATNR.

IF SY-SUBRC = 0.

ITAB-MAKTX = MYTAB-MAKTX.

MODIFY ITAB INDEX TABIX.

ENDIF.

endloop.

endif.

BREAK-POINT.

regards,

amit m.

Read only

Former Member
0 Likes
1,434

from makt table.

select matnr

maktx

from makt

into table it_makt

for all entries in it_mara

where matnr = it_mara-matnr

and spras = 'EN'.

loop at it_mara.

lv_tabix = sy-tabix.

read table it_makt with key matnr = it_mara-matnr.

if sy-subrc = 0.

it_mara-maktx = it_makt-maktx.

modify it_mara index lv_tabix.

endif.

endloop.

Regards,

Ravi

Read only

0 Likes
1,433

hi,

or select DB-View <b>MARAV</b>

A.

Read only

0 Likes
1,433

Hi Ravi,

This logic seems good. But in the selct stmt, in the where clause, ie where matnr = it_mara-matnr, the internal table should run in a loop. Otherwise, it will take only one matnr value from the itab. Am I right? Can you Explain?

Regards,

Srinu.

Read only

0 Likes
1,433

No it will do that for all the rows of the internal table, that is what the significance of the FOR ALL ENTRIES clause. so, it will be one statement.

Regards,

Ravi

Note : Please mark all the helpful answers and close the thread if the question is answered

Read only

Former Member
0 Likes
1,433

hi,

use table <b>makt</b> which has the material description MAKTX and MATNR(material no.)

select matnr maktx from

makt

into itab.

endselect.

Read only

Former Member
0 Likes
1,433

Hi,

I am assuming you have field with diffrent fields which also contains matrail number and description.

One way is to loop around this table and select maktx from makt table in loop.

BUt select within loop is not very time efficent and if you haev a huge amount o material, this will slow your program.

Instead, you can select the material texts corresponding to the material numbers in you internal table( itab_material) in one select statement using 'for all entires' and then processing the internal tables. This is faster than Select in Loop.

consider the following code :

data : begin of itab_matnr occurs 0,

matnr like mara-matnr,

maktx like makt-maktx,

field3...

field4...

field5....

end of itab_matnr.

data : begin of itab_desc occurs 0,

matnr like mara-matnr,

maktx like makt-maktx,

end of itab_desc.

select matnr

field3

field4....from matnr where...

select maktx from makt

into itab_desc

for all entries in itab_matnr.

loop at itab_matnr.

read table itab_desc with key matnr = itab_matnr-matnr.

if sy-subrc eq 0.

itab_matnr-maktx = itab_desc-maktx.

append itab_matnr.

clear itab_matnr.

endif.

endloop.

Read only

Former Member
0 Likes
1,433

2 ways to fetch your material description

MAKT - will store material descriptions

assume you have data in IT_MARA with MATNR & MATKX are the 2 fields.

1.

LOOP AT IT_MARA.

SELECT SINGLE MAKTX

INTO IT_MARA-MAKTX

FROM MAKT

WHERE MATNR = IT_MARA-MAKTX

AND SPRAS = sy-langu.

if sy-subrc = 0.

modify it_mara index v_tabix transporting maktx.

endif.

endloop.

now your it_mara will have maktx(material descriptions)

Read only

0 Likes
1,433

srinivas kamireddy

MARA -- Material Master

MART -- Material Description

MARA has a primary key field MATNR.

MAKT has a Primary Key of MATNR and Language.

1. Fill the Internal Table (iMara) with the records from MARA.(hopefully atleast MATNR).

2. Loop the Internal Table. Read the MAKT for <b>Description</b> with the help of MATNR.

3. Update the Internal Table.

Thanks

Jack

Read only

0 Likes
1,433

Hope we should not use Select stmt in a loop. What do you say?

Regards,

Srinu.

Read only

0 Likes
1,433

The "for all entries" clause is actually used to avoid the selects in loops.

You are right when you said we shouldn't use selects in loops.

Regards,

ravi

Read only

Former Member
0 Likes
1,433

MAKT is for descriptions.

Select Desc from MAKT into itab2 for all entries in itab where matno = itab-matno.

This will give the descriptions.

Also u can check MARAV for all the materials details

Read only

Former Member
0 Likes
1,433

Hi,


* First check whether the internal table is empty or not
  IF lines( ITAB ) > 0.
     SELECT MATNR MAKTX FROM MAKT INTO 
       CORESPONDING FIELDS OF TABLE ITAB2
        FOR ALL ENTRIES IN ITAB
         WHERE MATNR EQ ITAB-MATNR AND
             SPRAS EQ SY-LANGU.
     IF SY-SUBRC EQ 0.
        SORT ITAB2 by MATNR.
     ENDIF.
  ENDIF.

Where,

ITAB2 contains MATNR and MAKTX

Regs,

Venkat Ramanana

Message was edited by: Venkat Ramanan Natarajan