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

Please advice on code in the post

Former Member
0 Likes
926

Hi,

I have a key field in a table which has systemtime (HHMISS) as one of the key fields.

Aim is to develope a program which reverses entries in this table based on the selection.

Following is the part of code which reverses entries:

loop at itab.

itab-ORIGINALAMOUNT = -1 * itab-ORIGINALAMOUNT.

itab-CORRECTEDAMT = -1 * itab-CORRECTEDAMT.

itab-DIFFAMT = -1 * itab-DIFFAMT.

itab-SYSTEMDATE = sy-datum.

itab-SYSTEMTIME = SY-UZEIT.

modify itab.

endloop.

insert ztable1 from table itab.

Now this part of code executes in a fraction of second.

Resulting in SYSTEMTIME to be same for all entries.

This creates a problem when the table already has reverse entries and you again try to reverse it.

As now itab will have duplicate keys.

(If i execute single step then this problem does not occur as it takes me atleast a second to comeback to the second entry)

Practically chances for this cases to occur are negligible but I want consider all possibilities in the code.

Basically what I want is that all updated entries in itab should have a distinct SYSTEMTIME.

SYSTEMTIME may not be accurate, will work. Changing systemtime field to include long timestamp is not an option as I cannot change the table definition.

Can someone please suggest me a solution to this problem?

Friends I am not an ABAP'er so if you can support your suggestion with exact code then that would be a great help to me.,

Thanks in advance,

CD

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
890

Hi,

Try using GET TIME to get the current time during the execution of the program..It may help..

THanks

Naren

8 REPLIES 8
Read only

Former Member
0 Likes
891

Hi,

Try using GET TIME to get the current time during the execution of the program..It may help..

THanks

Naren

Read only

0 Likes
890

Narendra, problem its just 3-4 records so execution is within the same second (difference of nano second).

Is there a way I can assign a random offset to systemtime on each loop execution?

Read only

0 Likes
890

Dave, thanks I though about it. But I cant change the field in table.

Just changing the field in itab wont help, right? Sorry I didnt gt ur point exactly.

field in table is of type TIMS (len:6)

Read only

0 Likes
890

Just get the time into a local variable once before the loop and then add 1 second in each loop.

data: lv_time type tims.
field-symbol: <ls_itab> like line of itab.

lv_time = sy-uzeit.

loop at itab assigning <ls_itab>.

<ls_itab>-ORIGINALAMOUNT = -1 * itab-ORIGINALAMOUNT.
<ls_itab>-CORRECTEDAMT = -1 * itab-CORRECTEDAMT.
<ls_itab>-DIFFAMT = -1 * itab-DIFFAMT.
<ls_itab>-SYSTEMDATE = sy-datum.
<ls_itab>-SYSTEMTIME = lv_time.
add 1 to lv_time.

endloop.

insert ztable1 from table itab.

Read only

0 Likes
890

Karthik and Andre...

Both of your solutions worked for me. But I am going with Andre's as execution is faster. Thanks once again to all of you for help

Read only

Former Member
0 Likes
890

Hello,

I suggest you to change the time key field to the type TIMESTAMPL that is the time stamp (with fraction of seconds), see some samples at SAP Help documentation to the command CONVERT DATE.


DATA: time_stamp TYPE timestamp, 
      dat TYPE d, 
      tim TYPE t, 
      tz  TYPE ttzz-tzone. 

tz = 'BRAZIL'. 
dat = '20030309'. 
tim = '013000'. 

CONVERT DATE dat TIME tim DAYLIGHT SAVING TIME 'X' 
        INTO TIME STAMP time_stamp TIME ZONE tz. 
WRITE: / time_stamp. 

CONVERT DATE dat TIME tim DAYLIGHT SAVING TIME ' ' 
        INTO TIME STAMP time_stamp TIME ZONE tz. 
WRITE: / time_stamp. 

Regards.

Read only

Former Member
0 Likes
890

loop at itab.

itab-ORIGINALAMOUNT = -1 * itab-ORIGINALAMOUNT.

itab-CORRECTEDAMT = -1 * itab-CORRECTEDAMT.

itab-DIFFAMT = -1 * itab-DIFFAMT.

itab-SYSTEMDATE = sy-datum.

  • ( Add this statement so it has unique timing in the seconds place )

WAIT UP TO 1 SECONDS.

itab-SYSTEMTIME = SY-UZEIT.

modify itab.

endloop.

Hope this helps .

Thanks,

Karthik

Read only

Former Member
0 Likes
890

Hi,

if possible add a key to the table with a running sequence number..so that it will be easy to avoid duplicates..

Thanks

Naren