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

Insert record into ztable

Former Member
0 Likes
682

Hello experts,

i have written the following logic.

IT_CAL[] = IT_PRICING[].

CLEAR : WA_PRICING.

LOOP AT IT_CAL INTO WA_CAL.

SELECT SINGLE * FROM ZPRICING_SCALE WHERE ZCERTTYPE = WA_CAL-ZCERTTYPE

AND ZCUT = WA_CAL-ZCUT

AND ZGRWT_FR = WA_CAL-ZGRWT_FR

AND ZGRWT_TO = WA_CAL-ZGRWT_TO

AND ZFR_DAY = WA_CAL-ZFR_DAY

AND ZTO_DAY = WA_CAL-ZTO_DAY

AND ZCON_RATE = WA_CAL-ZCON_RATE.

IDX = SY-TABIX.

IF SY-SUBRC EQ 0.

WA_CAL-ZTO_DATE = SY-DATUM.

MODIFY ZPRICING_SCALE FROM WA_CAL." TRANSPORTING ZFR_DATE.

WA_PRICING-ZCERTTYPE = WA_CAL-ZCERTTYPE.

WA_CAL-ZFR_DATE = SY-DATUM.

WA_CAL-ZTO_DATE = '31129999'.

INSERT INTO ZPRICING_SCALE VALUES WA_CAL.

COMMIT WORK.

ELSE.

WA_CAL-ZFR_DATE = SY-DATUM.

INSERT INTO ZPRICING_SCALE VALUES WA_CAL.

ENDIF.

ENDLOOP.

my requirement is to find out the matching record with above selection criteria.

if it finds any matching record then i have to change the 'TO' date to today's date and also

append one line into z table with same line but 'FROM' date will be today's date and 'TO' days will be 3112999.

the above query is updating but not able to insert the record.

plz help.

Regards,

Ashmita Singh.

5 REPLIES 5
Read only

former_member215917
Active Participant
0 Likes
650

Hi Ashmita,

can you check what are the key fields for Z-table? if they are same, then you might not be able to insert entry.

Gouri.

Read only

Former Member
0 Likes
650

Hi Ashmita,

Can you detail your requirment in now coded part,

wht I understood from this is, you want to check the entry in the Ztable if it exist u want to modify it and if it is not there u want to insert the record.

If this is the case then,

use your select query from the ztable if sy-dbcnt is initial. then insert tht entry into ztable else, modify the entry using the work area.

Thanks,

Anmol.

Read only

Former Member
0 Likes
650

Hi Ahsmita,

I assume that the date field which are changing is a non key field. Since there already is a record with same key fields(Data) the modify statement is updating the record. If you want a new record add one more new field(item) ( increment the value for every new field or simply make the date field as key field.

Thanks,

Venkat

Read only

Former Member
0 Likes
650

Hi ,

Thanks to all. Exactly, i want to change the date field if an existing record found .

eg.

there are to date fields1.From and 2. To

From date is decided on the day record is added but TO is always 99991231.

if suppose From - 20100812 and TO-99991231.

Then for the above record in ztable my query should update the TO date to today's date and also insert a new record

with From- 20100819 and TO-99991231.

IDX = SY-TABIX.

IF SY-SUBRC EQ 0.

WA_CAL-ZTO_DATE = SY-DATUM.

MODIFY ZPRICING_SCALE FROM WA_CAL INDEX idx TRANSPORTING ZFR_DATE.

but the above query is adding new line in ztable instead of modifying the same line.

and also i am getting a syntax error. "." expected after "WA_CAL"

And i have changed the date fields to key fields.

plz help

Records

Ashmita Singh

Edited by: Ashmita Singh on Aug 19, 2010 8:54 AM

Read only

0 Likes
650

Hi Ashmita,

This is called delimiting a record, which is common in SAP HR infotypes.

For this, two steps are required:

a) First find the correct existing record with TO DATE = 99991231 (forget the from date)

Modify the TO DATE to 20100819 (i.e. new date Minus 1)

b) Insert new record with all fields duly populated.

At this time put FROM DATE = 20100819 TO DATE = 99991231.

Regards,

Amit Mittal.