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: 

need help on Internal tables.

Former Member
0 Kudos

Hi All,

I am facing a problem in processing Internal Tables.

Suppose I have a list of PL ID’s in a table ZPL. I have a list of employees in another table ZEMP.

Name details in NAME Table.

ZPL

-


PL ID

PLEMPKEY

ZEMP

-


PLEMPKEY

EMP

NAME

-


ID

NAME

Output structure

-


PLID

EMP

EMPNAME

Now if user gives 4* as input parameter.

Then I need to retrieve all PL ID’s starting with 4 and for each pl id I need to show them the employees under him and also emp name.

First I have retrieved data from ZPL & ZEMP by joining these two tables using PLEMPKEY and stored the data in ITAB1.

Now to get the name I am reading Name table. By doubt is

ITAB1 Structure is similar to ouput structure and is PLID, EMP details are filled. EMP NAME is vacant after the query.

Can we write a select query against the table NAME

SELECT NAME INTO CORRESPONDING FIELDS OF ITAB1 FROM NAME

WHERE ID = ITAB1-PLID.

I tried it is not working. Is this not possible.

Merging internal tables.

One more thing, if I have an internal table ITAB1 with 4 fields f1,f2,f3,f4 and

ITAB2 with F3 F5 F6 F7

Now I need to move F2 value to f7 for all MATCHING F3 entries.

I tried this using Loop at ITAB1 and Read at ITAB2 and moved the needed fields to a new internal table.

My doubt is can we directly update itab2 f7 field.

Please pass on your suggestions.

Thanks,

Eureka.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

SELECT NAME INTO CORRESPONDING FIELDS OF ITAB1 FROM NAME

WHERE ID = ITAB1-PLID.

You cannot write select query like this.

Define another internal table ITAB_NAME of structure similar to NAME and then write select query as below:

SELECT ID NAME INTO TABLE ITAB_NAME FROM NAME FOR ALL ENTRIES IN TABLE ITAB1

WHERE ID = ITAB1-PLID.

Here you will get names of all the employees.

Sort ITAB1 by ID.

SORT ITAB_NAME by ID.

Loop at ITAB1 into WA_ITAB1.

l_index = sy-tabix.

read table ITAB_NAME into wa_itab_name

with key id = wa_itab1-id.

wa_itab1-id = wa_itab_name-id.

modify itab1 from wa_itab1 index l_index.

Endloop.

I hope this will solve your problem.

Best Regards,

Vibha

*Please mark all the helpful answers

3 REPLIES 3

Former Member
0 Kudos

u have to join all three table .

then only u will get.

<b>select zpl~plid

zpl~plempkey

zemp~emp

name~name

into corresponding fields of table itab

from zpl innner join zemp on

zpl-plempkey = zemp-plempkey

inner join name on

zpl-pl-id = name-id

where zpl~plid = s_plid(selections) </b>

Regards

Prabhu

no sytax checks please

Former Member
0 Kudos

Hi

Hope this can give you some idea:

select plid pleempkey name
       into table it_out
       from zpl as a 
       inner join zemp
       on a~plempkey = b~plempkey
       inner join name as c
       on a~plid = c~id
       where a~plid like '4%'.

I guess PLID of table ZPL and ID of table NAME are same.

If ID of Name is same as EMP of table ZEMP, you select query should be some thing like below.

select plid pleempkey name
       into table it_out
       from zpl as a 
       inner join zemp
       on a~plempkey = b~plempkey
       inner join name as c
       on b~emp = c~id
       where a~plid like '4%'.

Kind Regards

Eswar

Former Member
0 Kudos

SELECT NAME INTO CORRESPONDING FIELDS OF ITAB1 FROM NAME

WHERE ID = ITAB1-PLID.

You cannot write select query like this.

Define another internal table ITAB_NAME of structure similar to NAME and then write select query as below:

SELECT ID NAME INTO TABLE ITAB_NAME FROM NAME FOR ALL ENTRIES IN TABLE ITAB1

WHERE ID = ITAB1-PLID.

Here you will get names of all the employees.

Sort ITAB1 by ID.

SORT ITAB_NAME by ID.

Loop at ITAB1 into WA_ITAB1.

l_index = sy-tabix.

read table ITAB_NAME into wa_itab_name

with key id = wa_itab1-id.

wa_itab1-id = wa_itab_name-id.

modify itab1 from wa_itab1 index l_index.

Endloop.

I hope this will solve your problem.

Best Regards,

Vibha

*Please mark all the helpful answers