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

logic needed for table data insertion

Former Member
0 Likes
823

table EVPOC contains objnr ,versn,evpai,datab,poc.

i have designed a similar Ztable (ZEVPOC) with fileds as of EVPOC but with date and time

as additional fields.

whenever an entry is made in tcode CJ2B it gets updated in EVPOC.

I have wrriten code which inserts all records if EVPOC to ZEVPOC.

TABLES : evpoc.

DATA: BEGIN OF itab OCCURS 0,

objnr LIKE evpoc-objnr,

versn_ev LIKE evpoc-versn_ev,

evpai LIKE evpoc-evpai,

datab LIKE evpoc-datab,

poc LIKE evpoc-poc,

END OF itab.

DATA : wa TYPE zevpoc,

v_objnr LIKE evpoc-objnr.

SELECT * FROM evpoc INTO CORRESPONDING FIELDS OF TABLE itab.

LOOP AT itab.

wa-objnr = itab-objnr.

wa-versn_ev = itab-versn_ev.

wa-evpai = itab-evpai.

wa-datab = itab-datab.

wa-poc = itab-poc.

wa-date1 = sy-datum.

wa-time1 = sy-uzeit.

INSERT INTO zevpoc VALUES wa.

CLEAR: itab.

ENDLOOP.

which inserts all records from EVPOC to ZEVPOC via this code which is inside tcode ZPOC.

my requirement is if there is only one record in EVPOC after running this code i will get

one records in ZEVPOC (correct)

but again if i run ZPOC , ztable should insert the same record with

date and time .

if i run zpoc 20 times it should insert in ZEVPOC 20 times the same record inspite of the fact

that EVPOC has only 1 record

.

5 REPLIES 5
Read only

Former Member
0 Likes
717

Hi,

Apply the initial check.

TABLES : evpoc.

DATA: BEGIN OF itab OCCURS 0,

objnr LIKE evpoc-objnr,

versn_ev LIKE evpoc-versn_ev,

evpai LIKE evpoc-evpai,

datab LIKE evpoc-datab,

poc LIKE evpoc-poc,

END OF itab.

DATA : wa TYPE zevpoc,

v_objnr LIKE evpoc-objnr.

SELECT * FROM evpoc INTO CORRESPONDING FIELDS OF TABLE itab.

LOOP AT itab.

wa-objnr = itab-objnr.

wa-versn_ev = itab-versn_ev.

wa-evpai = itab-evpai.

wa-datab = itab-datab.

wa-poc = itab-poc.

wa-date1 = sy-datum.

wa-time1 = sy-uzeit.

<Populate ITAB_ZEVPOS with ZEVPOS >

IF ITAB_ZEVPOS[] IS INITIAL

INSERT INTO zevpoc VALUES wa.

ENDIF

CLEAR: itab.

ENDLOOP.

Hope it helps....

Read only

former_member212005
Active Contributor
0 Likes
717

You have to make the date and time fields as part of primary key in the database table ZEVPOC...

This will ensure that you have as many entries in ZEVPOC how many times you run the program...

Before inserting....populate the date field with sy-datum and time field with sy-uzeit...

Hope it clears! Otherwise please let me know!

Read only

Former Member
0 Likes
717

Hi,


my requirement is if there is only one record in EVPOC after running this code i will get
one records in ZEVPOC (correct)
but again if i run ZPOC , ztable should insert the same record with
date and time .
if i run zpoc 20 times it should insert in ZEVPOC 20 times the same record inspite of the fact
that EVPOC has only 1 record

If you have duplicate entries in your records for the same key you will get dump so just add the extension ... accepting duplicate keys..

Read only

Former Member
0 Likes
717

hi,

for this requirement :

1) open the table in se11.

2) open table maintenance generator

3) then go to enviroment => modification => events

there create event " 05 CREATE ENTRY".

in this event write the following code :

FORM create_entry.


   ZEVPOC-date = sy-datum  .
  ZEVPOC-TIME  = sy-uzeit  .

ENDFORM.           "create_entry

now when u create the same entry again and again it will create it with the automatically generated date and time in the column of date and time as per ur requirement

it will help u

rahul

Edited by: RAHUL SHARMA on Jun 16, 2009 4:50 AM

Read only

Nawanandana
Active Contributor
0 Likes
717

hi


ABLES : evpoc.

DATA: BEGIN OF itab OCCURS 0,
objnr LIKE evpoc-objnr,
versn_ev LIKE evpoc-versn_ev,
evpai LIKE evpoc-evpai,
datab LIKE evpoc-datab,
poc LIKE evpoc-poc,
END OF itab.

DATA : wa TYPE zevpoc,
v_objnr LIKE evpoc-objnr.


SELECT * FROM ZEVPOC  INTO CORRESPONDING FIELDS OF TABLE itab2.



SELECT * FROM evpoc INTO CORRESPONDING FIELDS OF TABLE itab.


DELETE  itab  WHERE objnr = itab2-objnr.

LOOP AT itab.
wa-objnr = itab-objnr.
wa-versn_ev = itab-versn_ev.
wa-evpai = itab-evpai.
wa-datab = itab-datab.
wa-poc = itab-poc.
wa-date1 = sy-datum.
wa-time1 = sy-uzeit.

if wa is not initial.
INSERT INTO zevpoc VALUES wa.
endif.

CLEAR: itab.
ENDLOOP.


Hope it wil be help ful to u..

regard

nawa