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

Internal table

Former Member
0 Likes
1,256

Hi

I'm having data in myinternal table. Now i want to hard code my internal table as what ever may be the data it shows in output before all the entries it should show an entry as

empname empid

Nanda 2008

raja 2009

samrat 2010

i want output like this in which nanda is the value hard coded by me and the remaining values are fetched by select statements it self. Now i'm getting the data starting from raja but i want an extra name to be added how to perform this??

Regards

Nanda

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,238

Plz reply me

15 REPLIES 15
Read only

Former Member
0 Likes
1,239

Plz reply me

Read only

0 Likes
1,238

Hi nanda,

This is easy,

before you get data into your itab do this.

itab-empname = 'NANDA'.

itab-empno = '2008'.

append itab.

this will solve your problem if your itab has a header line.

if not you'll have to get the data into a work area.

and then append it to your itab.

append work-area to itab.

hope this helps.

Cheers,

~goldie.

Read only

0 Likes
1,238

Hello,

Chk this code :


REPORT ztest_123.

DATA: BEGIN OF itab OCCURS 0,
        ename TYPE char30,
        eid   TYPE i,
      END OF itab.

DATA: wa_tab  LIKE LINE OF itab,
      wa_tab2 LIKE LINE OF itab.
DATA: gv_lines TYPE i.

CLEAR wa_tab.
wa_tab-ename = 'RAJA'.
wa_tab-eid = 2009.
APPEND wa_tab TO itab.

CLEAR wa_tab.
wa_tab-ename = 'SAMRAT'.
wa_tab-eid = 2010.
APPEND wa_tab TO itab.

CLEAR wa_tab.
LOOP AT itab INTO wa_tab.
  WRITE:/ wa_tab-ename,
          wa_tab-eid.
ENDLOOP.

WRITE:/ '*******************************************'.

CLEAR wa_tab.
wa_tab-ename = 'NANDA'.
wa_tab-eid = 2008.
APPEND wa_tab TO itab.

DESCRIBE TABLE itab LINES gv_lines.

CLEAR wa_tab.
LOOP AT itab INTO wa_tab.
  CLEAR wa_tab2.
  DO 1 TIMES.
    READ TABLE itab INTO wa_tab2 INDEX gv_lines.
    IF sy-subrc = 0.

      WRITE:/ wa_tab2-ename,
              wa_tab2-eid.
      DELETE itab INDEX gv_lines.
    ENDIF.
  ENDDO.
  WRITE:/ wa_tab-ename,
          wa_tab-eid.
ENDLOOP.

WRITE:/ '*******************************************'.

Regards,

Deepu.K

Read only

0 Likes
1,238

Hi Goldie

Thanks for ur reply. If i want to declare as a value. How can i declare??

For example i have declared in my internal table as

data: emp like zemp occurs 0 with header line,

emp_name like zemp_det-empname,

emp_id like zemp_det-empid.

Now i want to add a new value as

data: emp like zemp occurs 0 with header line,

emp_name like zemp_det-empname,

emp_id like zemp_det-empid,

name value 'NANDA'.

Now i have to append or inser this value to my internal table how can i do ???

REgards

Nanda

Read only

0 Likes
1,238

Hi deepu

Thanks for ur reply. If i want to declare as a value or a character. How can i declare??

For example i have declared in my internal table as

data: emp like zemp occurs 0 with header line,

emp_name like zemp_det-empname,

emp_id like zemp_det-empid.

Now i want to add a new value as

data: emp like zemp occurs 0 with header line,

emp_name like zemp_det-empname,

emp_id like zemp_det-empid,

name value 'NANDA'.

Now i have to append or insert this value to my internal table how can i do ???

Regards

Nanda

Read only

0 Likes
1,238

Chk this code :


REPORT ztest_123.

DATA: BEGIN OF itab OCCURS 0,
        ename TYPE char30,
        eid   TYPE i,
        add_value TYPE char30 VALUE 'SAP',
      END OF itab.

DATA: wa_tab  LIKE LINE OF itab,
      wa_tab2 LIKE LINE OF itab.
DATA: gv_lines TYPE i.

CLEAR wa_tab.
wa_tab-ename = 'RAJA'.
wa_tab-eid = 2009.
wa_tab-add_value  = 'SAP'.
APPEND wa_tab TO itab.

CLEAR wa_tab.
wa_tab-ename = 'SAMRAT'.
wa_tab-eid = 2010.
wa_tab-add_value  = 'SAP'.
APPEND wa_tab TO itab.

CLEAR wa_tab.
LOOP AT itab INTO wa_tab.
  WRITE:/ wa_tab-ename,
          wa_tab-eid,
          wa_tab-add_value.
ENDLOOP.

WRITE:/ '***********************************************'.

CLEAR wa_tab.
wa_tab-ename = 'NANDA'.
wa_tab-eid = 2008.
wa_tab-add_value  = 'SAP'.
APPEND wa_tab TO itab.

DESCRIBE TABLE itab LINES gv_lines.

CLEAR wa_tab.
LOOP AT itab INTO wa_tab.
  CLEAR wa_tab2.
  DO 1 TIMES.
    READ TABLE itab INTO wa_tab2 INDEX gv_lines.
    IF sy-subrc = 0.

      WRITE:/ wa_tab2-ename,
              wa_tab2-eid,
              wa_tab2-add_value.
      DELETE itab INDEX gv_lines.
    ENDIF.
  ENDDO.
  WRITE:/ wa_tab-ename,
          wa_tab-eid,
          wa_tab-add_value.
ENDLOOP.

WRITE:/ '***********************************************'.

Regards,

Deepu.K

Read only

0 Likes
1,238

Hi

By using the Append statement i can put my word into that internal table but there are so many fields in that internal table how to specify that this variable should be go to that particular field of that table??

For ex:

comp name , comp id, emp name, emp id

now my internal table is having the data as shown above and i tried to code like this

append 'NANDA' to emp. " internal table for emp details

when i checked in debugging the value nanda is going to comp name where i want to show this in emp name how to change this??

Read only

0 Likes
1,238

nanda,

the best way is to get your data into a workarea.

check this:

data: wa_line like line of itab.
.
.
wa_line-empname = 'NANDA'. " or the variable containing 'NANDA'
wa_line-empid = '2008'. "or the variable containig '2008' 
Append wa_line to itab.

This code will append a record with blank compname, compid.

or else you can modify your itab for a particular record using this statement.

 MODIFY TABLE itab from wa_line EXPORTING FIELDS empname empid 
      WHERE compname = 'MYCOMPANY'. "whatever record you want to modify

This code only moves the fields empname and empid for an existing record.

You can exclude the WHERE clause if you like.

the second code you can do it even after entering all the data into your itab.

but the first code you have to do it before entering data into itab.

~goldie

Read only

0 Likes
1,238

Hi

I got the solution for the above one. But can u solve my one doubt i'll surely assign points.

There are 4 fields in an internal table. Lets suppose

emp-name, emp-id, comp-name, comp-id. Now in my case the company id is same for all the employees but it is repeating for all employees. So i want to keep it for the top most employee and i want to delete all other comp-id. How to perform this???

Read only

0 Likes
1,238

Hi,

If you want to display in ALV , you can do that...

You can build a SORT table in ALV and do that

But internal table is a temporary one , so why do u want that in internal table, do u want that in output

Read only

0 Likes
1,238

Yes i want to display that in output. I want only 1st field to be displayed and the remaining should be null at the same time the remaining data should also come

Read only

0 Likes
1,238

Hi

If i want to insert a new line at the first row but different fields how can i add that ???

if u consider my previous one we can see that i want to add a line at the begin of itab so i added a line by using append.

now my output is coming like this

emp-name emp-no comp-name comp-id

Nanda

and the data follows by the remaining one so if i want a new word to be added for the 1st line but different field. How can it be possible??

Read only

0 Likes
1,238

get the whole record into a work area.

and append the whole thing.

if you just want to display you can use the control statements

AT NEW.

and then display it.

goldie

Read only

0 Likes
1,238

sample coding plz

Read only

0 Likes
1,238

wa-empname = 'NANDA'.
wa-empno = '2008'.

modify table itab from wa transporting empno WHERE empname = 'NANDA'.