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: 

help in insert

Former Member
0 Kudos

HI,

i have internal table and i wont to insert the data from internal table to database table how i can do that?


   LOOP AT reptab INTO wa_reptab.
    MOVE : wa_reptab TO wa_reptab2.
    INSERT wa_reptab into   TABLE zsd_input_table.

  ENDLOOP.


i have erorr like that:

"ZSD_INPUT_TABLE" is not an internal table - the "OCCURS n"

specification is missing.

1 ACCEPTED SOLUTION

ferry_lianto
Active Contributor
0 Kudos

Hi,

Please try this.


LOOP AT reptab INTO wa_reptab.
  MODIFY zsd_input_table FROM wa_reptab. 
ENDLOOP.

Regards,

Ferry Lianto

19 REPLIES 19

Former Member
0 Kudos

LOOP AT reptab INTO wa_reptab.

insert zsd_input_table from wa_reptab.

endloop.

zsd_input_table,reptab and wa_reptab should have same structure.

reptab should be internal table having occurs 0 declaration.

0 Kudos

hi vasu

this is my declartion.

DATA: reptab TYPE TABLE OF zsd_input_table .

DATA: wa_reptab TYPE zsd_input_table,

wa_reptab2 TYPE zsd_input_table.

Regards

0 Kudos

declaration is right.

Problem was with insert statement.

So use in the way I suggested and for security purpose u can lock the entries.

use lock objects for that.

call function enqueue_lockobjectname.

*--insert records...

call function dequeue_lockobjectname.

create lock object in se11

0 Kudos

Since "reptab" is declared like "zsd_input_table", just use the following statement.

INSERT zsd_input_table FROM TABLE reptab.

0 Kudos

hi Srinivas

i try like u post and i have dump like:

how can i avoid that?

An exception occurred. This exception is dealt with in more detail below

. The exception, which is assigned to the class 'CX_SY_OPEN_SQL_DB', was

neither

caught nor passed along using a RAISING clause, in the procedure

"SELECT-ORDERS" "(FORM)"

.

Since the caller of the procedure could not have expected this exception

to occur, the running program was terminated.

The reason for the exception is:

If you use an ABAP/4 Open SQL array insert to insert a record in

the database and that record already exists with the same key,

this results in a termination.

(With an ABAP/4 Open SQL single record insert in the same error

situation, processing does not terminate, but SY-SUBRC is set to 4.)

Regards

0 Kudos

In all probability you have duplicate records (either in the database or in your itab). Check in debugging if your internal table has records with duplicate key field values. Also check your if any of your internal table key field values are already in the database table.

In your dump statement, you will find more information as to where the error code was. Please post that part of the code. If it happened at the INSERT statement, then it is probably duplicate keys.

0 Kudos

HI SRINIVAS,

i try with that code and i still have the same dump in the insert :

DELETE ADJACENT DUPLICATES FROM reptab.

INSERT zsd_input_table FROM TABLE reptab .

Best Regards

0 Kudos

Hope you removed the loop statement.

Also change INSERT to a MODIFY and see if you still get the dump.

Former Member
0 Kudos

Hi Tal,

Whenever we try to modify/update a table , it is better to lock the table .

Update / modify and then release the lock to avoid the deadlocks.

So first enqueue the table u want to update.

MODIFY dbtab FROM wa.

then dequeue the table.

here in your code, try this

<b>enqueue the table u want to update.

Insert dbtab FROM wa.

then dequeue the table.</b>

Reward if Useful.

Regards,

Chitra

0 Kudos

hi chitra

what is enqueue and dequeue?

Regards

0 Kudos

Hi Tal,

As I have mentioned earlier,

Whenever we try to modify/update a table , it is better to lock the table .

Update / modify and then release the lock to avoid the deadlocks.

this locking is done by enqueue and release the lock is done by dequeue.

You can use this .

**- to lock the table

CALL FUNCTION 'ENQUEUE_E_TABLEE'

EXPORTING

mode_rstable = 'E'

tabname = ' table name'

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

**_ here you have to insert

    • to release the lock

CALL FUNCTION 'DEQUEUE_E_TABLEE'

EXPORTING

mode_rstable = 'E'

tabname = 'table name'.

Reward if useful.

Regards,

Chitra

0 Kudos

hi chitra

i try like u write and i get only one recored in database table from 30000 recored that i have in the inetrnal table what i have to change here?

Regards



  CALL FUNCTION 'ENQUEUE_E_TABLEE'
    EXPORTING
      mode_rstable   = 'E'
      tabname        = 'ZSD_INPUT_TABLE'
    EXCEPTIONS
      foreign_lock   = 1
      system_failure = 2
      OTHERS         = 3.
**_ here you have to insert


  LOOP at reptab INTO wa_reptab.

  MODIFY  zsd_input_table FROM wa_reptab.

  ENDLOOP.


** to release the lock
  CALL FUNCTION 'DEQUEUE_E_TABLEE'
    EXPORTING
      mode_rstable = 'E'
      tabname      = 'ZSD_INPUT_TABLE'.


0 Kudos

Hi Tal ,

Check how many entries u get in the "reptab".

Remove the loop and give a try

Reward if useful.

regards,

Chitra

0 Kudos

Hi Tal,

Try this.

CALL FUNCTION 'ENQUEUE_E_TABLEE'

EXPORTING

mode_rstable = 'E'

tabname = 'ZSD_INPUT_TABLE'

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

**_ here you have to insert

MODIFY zsd_input_table FROM table reptab.

    • to release the lock

CALL FUNCTION 'DEQUEUE_E_TABLEE'

EXPORTING

mode_rstable = 'E'

tabname = 'ZSD_INPUT_TABLE'.

Reward If Useful.

Regards,

Chitra

Former Member
0 Kudos

change code like

INSERT into TABLE zsd_input_table FROM wa_reptab .

Former Member
0 Kudos

Hi,

Remove loop endloop and write the statement as below

 insert zsd_input_table from table reptab.

<b> Reward for helpful answers</b>

Satish

Former Member
0 Kudos

Hi,

You below code :

LOOP AT reptab INTO wa_reptab.
    MOVE : wa_reptab TO wa_reptab2.
    INSERT INTO zsd_input_table VALUES wa_reptab. 
ENDLOOP.

Thanks,

Sriram Ponna.

ferry_lianto
Active Contributor
0 Kudos

Hi,

Please try this.


LOOP AT reptab INTO wa_reptab.
  MODIFY zsd_input_table FROM wa_reptab. 
ENDLOOP.

Regards,

Ferry Lianto

Former Member
0 Kudos

HI,

CHECH THIS CODE,

TABLES : AFKO,

AFPO.

DATA : BEGIN OF GI_AFKO OCCURS 1,

AUFNR LIKE AFKO-AUFNR,

END OF GI_AFKO.

data gi_AFPO like ZPRODUCT occurs 0 with header line.

*DATA : BEGIN OF GI_AFPO OCCURS 100,

  • MANDT LIKE

  • MATNR LIKE AFPO-MATNR,

  • DWERK LIKE AFPO-DWERK,

  • END OF GI_AFPO.

DATA: gv_date(11)," LIKE ekpo-aedat,

gv_date1(11),

year(4),

month(2),

day(2),

flag(1),

read_flag(1).

START-OF-SELECTION.

gv_date1 = sy-datum.

year = gv_date1+0(4).

month = gv_date1+4(2).

day = gv_date1+6(2).

year = year - 3.

CLEAR gv_date1.

CONCATENATE year month day INTO gv_date1.

select aufnr

from afko

into table gi_afko

where ( GLTRP <= sy-datum AND gltrp >= gv_date1 ) .

IF SY-SUBRC = 0.

select matnr

dwerk

from afpo

into CORRESPONDING FIELDS OF table gi_afpo

for all entries in gi_afko

where aufnr = gi_afko-aufnr.

ENDIF.

SORT GI_AFPO BY MATNR.

IF NOT GI_AFPO[] IS INITIAL.

MODIFY ZPRODUCT FROM TABLE GI_AFPO.

IF SY-SUBRC = 0.

MESSAGE I003 WITH 'VALUES UPDATED IN TO TABLE ZPRODUCT'.

ELSE.

MESSAGE I003 WITH 'VALUES NOT UPDATED IN TO TABLE ZPRODUCT'.

ENDIF.

u can use modify statement to modify from internal table.

regards

siva