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: 

Explain this code

Former Member
0 Kudos

Hi friends,

can you plz explain this..

TYPES:BEGIN OF ITAB1,

MATNR TYPE MATNR,

ERNAM TYPE ERNAM,

END OF ITAB1,

ITAB2 TYPE STANDARD TABLE OF ITAB1 WITH NON-UNIQUE DEFAULT KEY.

DATA:WA_SELECT TYPE ITAB2 .

DATA:WA_READ TYPE ITAB1.

SELECT MATNR ERNAM FROM MARA INTO TABLE WA_SELECT..

plz let me know this logic... is this is correct or.. any misteque is there..

thanks

babu

1 ACCEPTED SOLUTION

Former Member
0 Kudos

just check the change in select in bold

SELECT MATNR ERNAM FROM MARA INTO TABLE <b>ITAB2..</b>

WA_SELECT is just a workarea , It holds only one record , instead use ITAB2

9 REPLIES 9

Former Member
0 Kudos

just check the change in select in bold

SELECT MATNR ERNAM FROM MARA INTO TABLE <b>ITAB2..</b>

WA_SELECT is just a workarea , It holds only one record , instead use ITAB2

0 Kudos

Hi Chandra,

I already tryd with. this but.. that time i'm getting following error...

Error------"Field ITAB2 is unknown.. it is neither in one of the specified tables nor defined by DATA statement.."

plz any one explain... and let me know...

thanks

baby

0 Kudos

Hi

No! See the code:

TYPES: BEGIN OF ITAB1,
               MATNR TYPE MATNR,
               ERNAM TYPE ERNAM,
            END OF ITAB1,
            ITAB2 TYPE STANDARD TABLE OF ITAB1 WITH NON-UNIQUE DEFAULT KEY.

DATA:WA_SELECT TYPE ITAB2 .

ITAB2 is a type table, so WA_SELECT is a table too, not a work area. Just as I said in my previuos answer here I think it's useless ITAB2, you can use WA_SELECT only:

TYPES: BEGIN OF ITAB1,
               MATNR TYPE MATNR,
               ERNAM TYPE ERNAM,
            END OF ITAB1.

DATA: WA_SELECT TYPE STANDARD TABLE OF ITAB1 WITH NON-UNIQUE DEFAULT KEY .

Max

0 Kudos

Hi

The line SELECT MATNR ERNAM FROM MARA INTO TABLE WA_SELECT is right.

Max

Former Member
0 Kudos

Hi

The MARA table has only one key (excepted the client): MATNR, so it should be better:

TYPES: BEGIN OF ITAB1,
                MATNR TYPE MATNR,
                ERNAM TYPE ERNAM,
             END OF ITAB1,
             
            ITAB2 TYPE STANDARD TABLE OF ITAB1 WITH UNIQUE KEY MATNR.

DATA: WA_SELECT TYPE ITAB2 .

DATA: WA_READ TYPE ITAB1.

SELECT MATNR ERNAM FROM MARA INTO TABLE WA_SELECT.

If you need to read the data using user name, u can insert ERNAM in the UNIQUE KEY too:

TYPES: BEGIN OF ITAB1,
                MATNR TYPE MATNR,
                ERNAM TYPE ERNAM,
             END OF ITAB1,
             
            ITAB2 TYPE STANDARD TABLE OF ITAB1 WITH UNIQUE KEY MATNR ERNAM.

DATA: WA_SELECT TYPE ITAB2 .

DATA: WA_READ TYPE ITAB1.

SELECT MATNR ERNAM FROM MARA INTO TABLE WA_SELECT.

I believe it's useless to define the type table ITAB2 in this situation, u need the type ITAB1 only:

TYPES: BEGIN OF ITAB1,
                MATNR TYPE MATNR,
                ERNAM TYPE ERNAM,
             END OF ITAB1.

DATA: WA_SELECT TYPE STANDARD TABLE OF ITAB1 WITH UNIQUE KEY MATNR ERNAM.
 .
DATA: WA_READ TYPE ITAB1.

SELECT MATNR ERNAM FROM MARA INTO TABLE WA_SELECT.

Max

Former Member
0 Kudos

hi Babu,

just change ur code like this

REPORT ychatest2.

TYPES:BEGIN OF itab1,
matnr TYPE matnr,
ernam TYPE ernam,
END OF itab1.

data : itab2 TYPE STANDARD TABLE OF itab1 WITH NON-UNIQUE DEFAULT KEY.
DATA:wa_select TYPE itab1 .

DATA:wa_read TYPE itab1.

SELECT matnr ernam FROM mara INTO TABLE itab2.

Former Member
0 Kudos

Hi.

You are selecting single fields into an internal table.

WA_SELECT is defined as table so thats right.

The logic is OK but you should change the naming. WA_ (work area) should be used as prefix for a variable representing a line of the internal table. Maybe you can use the prefix LT_ (local table) for internal tables.

TYPES:BEGIN OF ITAB1,
MATNR TYPE MATNR,
ERNAM TYPE ERNAM,
END OF ITAB1,

ITAB2 TYPE STANDARD TABLE OF ITAB1 WITH NON-UNIQUE DEFAULT KEY.

DATA:WA_READ TYPE ITAB1.

<b>DATA:LT_SELECT TYPE ITAB2 .</b>

SELECT MATNR ERNAM FROM MARA INTO TABLE LT_SELECT.

After executing this piece of code the internal table LT_SELECT holds the fields MATNR and ERNAM for all entries from the database table MARA.

Regards,

Timo.

Former Member
0 Kudos

hi

first u r creating one structure called itab1.

TYPES:BEGIN OF ITAB1,

MATNR TYPE MATNR,

ERNAM TYPE ERNAM,

END OF ITAB1,

then u r creating an internal table itab2 like the structure itab1 with non-unique key.

ITAB2 TYPE STANDARD TABLE OF ITAB1 WITH NON-UNIQUE DEFAULT KEY.

u r creating one one more internal table like itab2.

DATA:WA_SELECT TYPE ITAB2 .

u r creating one more structure like itab1.

DATA:WA_READ TYPE ITAB1.

u r fetching matnr ernam fields from mara and putting into internal table-wa_select.

SELECT MATNR ERNAM FROM MARA INTO TABLE WA_SELECT..

reward if useful.

Former Member
0 Kudos

Hi

Itab1 and wa_select are not internal table. itab1 is a structure. And wa_select is a work area for internal table itab2.

So itab2 is an internal table.

modify select statement by

SELECT MATNR ERNAM FROM MARA INTO TABLE ITAB2 where matnr = p_matnr.

Also its not necessary to declare WITH NON-UNIQUE DEFAULT KEY.

Reward me if its helpful

Regards

Ravi