‎2007 Mar 09 9:12 AM
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.
‎2007 Mar 09 9:18 AM
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
‎2007 Mar 09 9:20 AM
your itab must be same structure as KNA1.
then only you can insert.
reagrds
shiba dutta
‎2007 Mar 09 9:20 AM
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
‎2007 Mar 09 9:22 AM
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.
‎2007 Mar 09 9:23 AM
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
‎2007 Mar 09 9:23 AM
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...
‎2007 Mar 09 9:24 AM
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
‎2007 Mar 09 9:25 AM
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.....
‎2007 Mar 09 9:26 AM
‎2007 Mar 09 9:32 AM
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.