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: 

Problem Populating Internal table

Former Member
0 Kudos
93

I have a small problem filling my internal table.I have some 10 fields in my internal table.I am filling some 5 fields in the internal table using a join and i have to fill the other 5 fields seperately ie modify the internal table after the first select query...So without looping can we do it in any easy way...

13 REPLIES 13

Former Member
0 Kudos
60

example:

data: begin of itab occurs 0,

field1(10),

field2(10),

end of itab.

itab-field1 = 'hello'.

modify itab transporting field1 where ....

Former Member
0 Kudos
60

select ... into (<fields>) from ...

<fill the other 5 fileds>

endselect.

You will have one loop between select and endselect.

Former Member
0 Kudos
60

Hi Mavreck,

I think its not possible to modify an internal table's multiple rows without looping.

Regards,

Narinder Singh

0 Kudos
60

hi Narinder ,

did you check the <b>transporting</b> option in modify?

<b>You can modify multiple rows without looping</b>

0 Kudos
60

Hi Joseph,

Thanks for correcting, But using transporting what i understand is that all records can only be modified with same values only. What if user want to modify each record

with different valus, he has to use loop???

Regards,

Narinder Singh

0 Kudos
60

hi Narinder,

<b>You right! sorry</b>, i didn't thought about this possibility.

0 Kudos
60

If i use modify itab transporting field bt select... endselect....Its going 4 short dump...

0 Kudos
60

Hi,

Actually modify ... and select ... endselect are 2 different options to solve your problem. It depends on the values that you want to modify with.

0 Kudos
60

if you use modify of an itab within the select endselect, you need to tell the modify stt , that which line should be updated . something like modify .. index 5 .(to modify the 5th record) or

modify .... where <logical expression>.

Regards

Raja

0 Kudos
60

I think your best bet is to do a loop. Why would you want to hit the database more than once if you don't have to. What I mean is, doing a SELECT ENDSELECT will cause you to hit the database n times where n is the number of records that you are selecting. Why not do an array fetch, then loop at the the itab and get the rest of your fields then modify your itab. You know, LOOPS are not such a bad thing.

data: begin of itab occurs 0,
      f1 type c,
      f2 type c,
      f3 type c,
      f4 type c,      
      f5 type c,
      f6 type c,
      f7 type c,
      f8 type c,
      f9 type c,
      f10 type c,
      end of itab.

select * into corresponding fields of table itab
       from Some_Table
               where field = p_field.

loop at itab.

select Single * from some_table
        into xsome_table
                where fld1 = itab-fld1.
itab-fld6 = xsome_table-fld6.

" More code here


Modify itab.



endloop.

Regards,

Rich Heilman

jayanthi_jayaraman
Active Contributor
0 Kudos
60

Hi,

If you are going to modify the same values[say field2 = 'ABC'] for all the records,then without loop you can do that.

Otherwise,if you need to modify it differently for each record,then

select...Endselect is the best approach.

former_member181959
Contributor
0 Kudos
60

i think for that you need to use inner join.

i am giving you a sample inner join statement.

with this statement we can retrieve data from

3 tables and we can populate in a single table...

SELECT A~EBELN

A~LIFNR

A~AEDAT

B~EBELP

B~MATNR

B~NETPR

C~ETENR

C~MENGE

C~WEMNG

FROM ( EKKO AS A INNER JOIN EKPO AS B

ON AEBELN = BEBELN )

INNER JOIN EKET AS C

ON AEBELN = CEBELN

AND BEBELP = CEBELP

INTO TABLE ITAB

WHERE A~EBELN IN PNO.

i hope it will help you.

bye...

regards,

prasad

Former Member
0 Kudos
60

Hey,

Ths only way is to use MOVE CORRESPONDING FIELDS in the select query. And the loop that internal table.

Since if u use SELECT...END SELECT...performance will be bad. Since unnecessary access to database will take place "N" times.

Regs,

Venkat