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

ITAB not enough

Former Member
0 Likes
1,059

hi

in d below code am getting itab is not long enough can anybody sort it & give me d reason y am getting dat error.

vijay

REPORT ZEX4.

DATA:BEGIN OF ITAB OCCURS 5,

KUNNR LIKE KNA1-KUNNR,

LAND1 LIKE KNA1-LAND1,

NAME1 LIKE KNA1-NAME1,

END OF ITAB.

ITAB-KUNNR = 'NEW CUST1'.

ITAB-LAND1 = 'IN'.

ITAB-NAME1 = 'SUBBA RAO'.

INSERT INTO KNA1 VALUES ITAB.

ERRORS.

IF SY-SUBRC = 0 .

WRITE 😕 'RECORD IS INSERTED'.

ELSE.

WRITE 😕 'RECORD IS NOT INSERTED' .

ENDIF.

10 REPLIES 10
Read only

Former Member
0 Likes
995

Hello Vijay,

IN the code u have declared the ITAB with three fields

It should be like this

DATA: ITAB LIKE KNA! OCCURS 0 WITH HEADER LINE.

<b>Whenever u r using the INSERT statment u need to have the work area structure</b> similar to database table.

<b>And aslo always use MODIFY DB TABLE instead of INSERT</b>

If useful reward.

Vasanth

Read only

Former Member
0 Likes
995

your itab must be same structure as KNA1.

then only you can insert.

reagrds

shiba dutta

Read only

rahulkavuri
Active Contributor
0 Likes
995

hi u cannot do this way, u have to declare an internal table as long oas strcuture of table KNA1.

give like this.

data: itab type table of KNA1 with header line.

Now this works, i have checked it, award points if found helpful

Read only

Former Member
0 Likes
995

check ...

this code is error free...

itab should be of type kna1 when u r using values...

data: itab type kna1 .

ITAB-KUNNR = 'NEW CUST1'.

ITAB-LAND1 = 'IN'.

ITAB-NAME1 = 'SUBBA RAO'.

INSERT into kna1 values ITAB .

IF SY-SUBRC = 0 .

WRITE 😕 'RECORD IS INSERTED'.

ELSE.

WRITE 😕 'RECORD IS NOT INSERTED' .

ENDIF.

Read only

Former Member
0 Likes
995

HI vijay ..Just try this code

REPORT YH_TEST04.

*DATA:BEGIN OF ITAB ,"OCCURS 5,

*KUNNR LIKE KNA1-KUNNR,

*LAND1 LIKE KNA1-LAND1,

*NAME1 LIKE KNA1-NAME1,

*END OF ITAB.

tables:

kna1.

data:

itab1 like kna1.

ITAB1-KUNNR = 'NEW CUST1'.

ITAB1-LAND1 = 'IN'.

ITAB1-NAME1 = 'SUBBA RAO'.

INSERT INTO KNA1 VALUES ITAB1.

IF SY-SUBRC = 0 .

WRITE 😕 'RECORD IS INSERTED'.

ELSE.

WRITE 😕 'RECORD IS NOT INSERTED' .

ENDIF.

Regards Rk

null

Read only

Former Member
0 Likes
995

Hi,

Change the code like this.

REPORT ZEX4.

DATA:BEGIN OF ITAB OCCURS 5,

Include structure kna1.

DATA: END OF ITAB.

clear itab.

ITAB-KUNNR = 'NEW CUST1'.

ITAB-LAND1 = 'IN'.

ITAB-NAME1 = 'SUBBA RAO'.

INSERT INTO KNA1 VALUES ITAB.

ERRORS.

IF SY-SUBRC = 0 .

WRITE 😕 'RECORD IS INSERTED'.

ELSE.

WRITE 😕 'RECORD IS NOT INSERTED' .

ENDIF.

Regards,

Jayaram...

Read only

Former Member
0 Likes
995

Vijay,

You are trying to insert 3 values from ITab.But the structure of the KNA1 is very big.

Reason is : when you have all the columns of the KNA1 in ITAB then only you can insert.Means the structure of the itab should be the same as KNA1.

Pls. reward if useful

Read only

Former Member
0 Likes
995

Hi Vijay....

Use the following code.

DATA ITAB LIKE STANDARD TABLE OF KNA1 initial size 5 WITH HEADER LINE.

ITAB-KUNNR = 'NEW CUST1'.

ITAB-LAND1 = 'IN'.

ITAB-NAME1 = 'SUBBA RAO'.

INSERT INTO KNA1 VALUES ITAB.

*ERRORS.

IF SY-SUBRC = 0 .

WRITE 😕 'RECORD IS INSERTED'.

ELSE.

WRITE 😕 'RECORD IS NOT INSERTED' .

ENDIF.

but no need of internal table itab.

u can write like this:

DATA ITAB TYPE KNA1.

ITAB-KUNNR = 'NEW CUST1'.

ITAB-LAND1 = 'IN'.

ITAB-NAME1 = 'SUBBA RAO'.

INSERT INTO KNA1 VALUES ITAB.

*ERRORS.

IF SY-SUBRC = 0 .

WRITE 😕 'RECORD IS INSERTED'.

ELSE.

WRITE 😕 'RECORD IS NOT INSERTED' .

ENDIF.

Suresh.....

Read only

Former Member
0 Likes
995

thankss

Read only

Former Member
0 Likes
995

Hi Krishna,

1) if you want to insert values from workarea try like this

tables: zemp1.

data: wa_emp type zemp1.

wa_emp-id = 10.

wa_emp-name = 'name10'.

insert into zemp1 values wa_emp.

and check for the values in your database table.

2) if u use internal table for inserting values use the following code

tables: zemp1.

data: itab like zemp1 occurs 0 with header line.

itab-id = 12.

itab-name = 'name12'.

append itab.

insert zemp1 from table itab.