cancel
Showing results for 
Search instead for 
Did you mean: 

Need help in correcting the ABAP code

Former Member
0 Kudos

Hi All,

I have written the below code,
where:

  1. 1. It selects all the entries from
    the zlookup table into internal table itab.
  2. 2. It compares whether the current
    day system timestamp is in between the start and end timestamp in the zlookup.
  3. 3. if sy-subrc is 0 then it should
    delete the source package where the source system in zlookup and source package
    is same.

Question: I am using CS(compare string) here to compare source system from
internal table and source package. Please let me know if this code works
properly.

Waiting for your inputs!! Thanks In Advance!!

LOOP AT SOURCE_PACKAGE ASSIGNING
<source_fields>

-----

-----

-----

Select * from zlookup into table itab.

Loop at itab into wtab.

If wtab-starttimestamp<=systimestamp and wtab-endtimestam>=systimestamp.

Delete source package where sourcesys cs wtab-source.

end if.

End loop.

---

----

End loop

Systimestamp = system current timestamp

Process chain IDSourcesys
PC1AAA,CCC
PC2AAA,BBB
PC3AAA,CCC
PC4CCC
PC5DDD
PC6BBB

SourceStarttimestampEndtimestamp
AAA2014101609162620141016131626
BBB2014101609162620141016151626
CCC

Regards,

Roopa KS

Accepted Solutions (1)

Accepted Solutions (1)

former_member185132
Active Contributor
0 Kudos

You dont need the LOOP at SOURCE_PACKAGE.

Also, for performance reasons change the LOOP at itab thusly


Loop at itab into wtab where  starttimestamp<=systimestamp and           endtimestam>=systimestamp.


You can remove the IF statement within the LOOP AT

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi All,

Thanks for all your reply and help.

I have question where, my SAP system time is CET but system time is UTC.

I should compare time by converting UTC to CET right?

Please let me know!

Thanks and Regards,

Roopa KS

former_member185132
Active Contributor
0 Kudos

Depends. Please check what is the timestamp present in the ZLOOKUP table. The system/person that generates the entries of ZLOOKUP should be able to help you with that info.

If the ZLOOKUP timestamp is in UTC, you need to convert system time to UTC. If the ZLOOKUP is in CET and your system time is also CET, then no conversion is necessary.

0 Kudos

Hi,

Please use below type of sample code, because it will take so much of time to execute the code if we write select statement in loop  and endloop.

If there is a chance, please use for all entries functionality in your select statment.

Select * from zlookup into table itab.

LOOP AT SOURCE_PACKAGE ASSIGNING <source_fields>

-----

-----


read table itab into wtab with key wtab-starttimestamp<=systimestamp and wtab-endtimestam>=systimestamp.
if sy-subrc = 0.

Delete source package where sourcesys cs wtab-source.
endif.

End loop.

Regards,

Nagaraju K

Former Member
0 Kudos

Hi Nagaraju,

Can we use "And" in read statement, i am not sure about it.

Please let me know.

read table itab into wtab with key wtab-starttimestamp<=systimestamp and wtab-endtimestam>=systimestamp.

Thanks In Advance!!

Roopa KS

Former Member
0 Kudos

Hi Roopa,

you cannot use "AND" in read statement, and in your scenario you want to check the fields like     start time  and end time with current day system time stamp. I am just giving a rough code in terms of Work Area  .

loop at itab into wa. ---->  which is Source Package.

loop at itab1 into wa1 where starttime = sy-uzeit and endtime = sy-uzeit.

if sy-subrc = 0.

delete itab where sourcesys EQ wa1-source.

endif.

endloop.

endloop.

Hope this will help you.

Former Member
0 Kudos

Hi Roopa,

you cannot use "AND" in read statement, and in your scenario you want to check the fields like     start time  and end time with current day system time stamp. I am just giving a rough code in terms of Work Area  .

loop at itab into wa. ---->  which is Source Package.

loop at itab1 into wa1 where starttime = sy-uzeit and endtime = sy-uzeit.

if sy-subrc = 0.

delete itab where sourcesys EQ wa1-source.

endif.

endloop.

endloop.

Hope this will help you.

Former Member
0 Kudos

Hello Roopa,

Below code should be fine for your requirement:

-----------------------------------------------------------------

DATA: time TYPE timestamp" = Current Timestamp to get value of current time
* Assign current timestamp to field
GET TIME STAMP FIELD time.

SELECT * FROM zlookup INTO TABLE it_zlookup.    " select from table

LOOP AT it_zlookup INTO wa_zlookup WHERE starttime LE time AND endtime GE time.
*now loop on source package 
LOOP AT it_sourcepackage INTO wa_sourcepackage WHERE system CS wa_zlookup-srcsystem.
DELETE it_sourcepackage INDEX sy-tabix.
ENDLOOP.

ENDLOOP.
----------------------------------------------------------------

Please let me know if there are any questions.

Thanks

Amit

former_member185132
Active Contributor
0 Kudos

Hi Amit,

Instead of the source package loop i.e. the below code


LOOP AT it_sourcepackage INTO wa_sourcepackage WHERE system CS wa_zlookup-srcsystem.

DELETE it_sourcepackage INDEX sy-tabix.

ENDLOOP.


Why not use the simpler (and faster)


DELETE  it_sourcepackage WHERE system CS wa_zlookup-srcsystem.



Former Member
0 Kudos

Hi,

I think the command "CS" is used to compare the fields in a internal table but i think it cannot compare the fields between two internal tables and i don't think there is a system defined fields like "systimestamp" . Correct me if i am wrong.

Thank you

former_member185132
Active Contributor
0 Kudos

The code isn't comparing the fields in two itabs. The code is comparing a field it_sourcepackage with a field in a work area (i.e. wa_lookup-srcsystem).

You're right that there isn't a standard timestamp field, but you can create a timestamp using the CONVERT date d1 time t1 INTO TIME STAMP command.

Former Member
0 Kudos

Hi Roopa,

Do not write select statement inside the loop it will degrade the performance, since for every loop a select statement will be executed. so better to write select statement outside the loop and did you  implemented the  logic you have mentioned , if not implement it and if you got stuck at any point let us know.

Thank you.

Former Member
0 Kudos

Thanks Sunil,

I will write the Select statement outside the first loop.

Regards,

Roopa KS