‎2008 May 08 12:21 PM
Hi,
i Do This Code and i Wont To have idea How to do it Better.
i have to do the select for every month for 13 month before today.
Regards
&----
*& Form ap
&----
text
----
-->P_L_BEGDA13 text
-->P_L_BEGDA12 text
-->P_CATS_TAB text
----
FORM ap TABLES p_cats_tab USING p_l_begda13
p_l_begda12.
SELECT *
FROM catsdb
APPENDING CORRESPONDING FIELDS OF TABLE p_c_tab
WHERE workdate BETWEEN p_l_begda1 AND p_l_begda2.
ENDFORM. " ap
PERFORM: ap TABLES cats_tab1 USING l_begda13 l_begda12 ,
ap TABLES cats_tab2 USING l_begda12 l_begda11 ,
ap TABLES cats_tab3 USING l_begda11 l_begda10 ,
ap TABLES cats_tab4 USING l_begda10 l_begda9 ,
ap TABLES cats_tab5 USING l_begda9 l_begda8 ,
ap TABLES cats_tab6 USING l_begda8 l_begda7 ,
ap TABLES cats_tab7 USING l_begda7 l_begda6 ,
ap TABLES cats_tab8 USING l_begda6 l_begda5 ,
ap TABLES cats_tab9 USING l_begda5 l_begda4 ,
ap TABLES cats_tab10 USING l_begda4 l_begda3 ,
ap TABLES cats_tab11 USING l_begda3 l_begda2 ,
ap TABLES cats_tab12 USING l_begda2 l_begda1 ,
ap TABLES cats_tab13 USING l_begda1 sy-datum .
‎2008 May 08 1:08 PM
Hi,
To reduce the load on Database you can use the below logic but it increases the ABAP load.
Step 1: Get the lowest and highest date of all date fields which you are passing in the where clause.
1.Append an internal table which will have one field and of date type and with all date fields
2.Sort the internal table.
3. Get first and last record of the internal table which has max and min values and store them in varaibles V1 and V2.
Step 2: Select data from table CATSDB once into the internal table ITAB1 by using the variables V1 and V2 in the WHERE clause.
Step 3: Loop through the internal table ITAB1 and populate other respective internal table using the CASE statement or IF statement.
Regards,
Satya
‎2008 May 08 12:57 PM
Hi Frinds,
Do i write this code in the Best way?
If not i need tips to do it Better.
Regards
‎2008 May 08 1:08 PM
Hi,
To reduce the load on Database you can use the below logic but it increases the ABAP load.
Step 1: Get the lowest and highest date of all date fields which you are passing in the where clause.
1.Append an internal table which will have one field and of date type and with all date fields
2.Sort the internal table.
3. Get first and last record of the internal table which has max and min values and store them in varaibles V1 and V2.
Step 2: Select data from table CATSDB once into the internal table ITAB1 by using the variables V1 and V2 in the WHERE clause.
Step 3: Loop through the internal table ITAB1 and populate other respective internal table using the CASE statement or IF statement.
Regards,
Satya
‎2008 May 08 1:08 PM
I think this is the best possible way ..
The other way would be to pass all the 13 months at a time ..
but would take huge time to get data ...
‎2008 May 08 1:18 PM
Hi Ricardo,
To calculate teh date b4 13 months from current date..
parameters input_date type sy-datum.
data output_date type sy-datum.
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = input_date
days = '00'
months = '13'
signum = '-'
years = '00'
IMPORTING
calc_date = output_date.
write : / 'Current Date' , sy-datum.
write : 'Output DATE', output_date.Also rather then appending the records for each month in same internal table... why dont you select the data from the database table at one shot...it will reduce the network traffic between appl server and database server...
nd Don't use select * ...
instead of it use select field1 field2 field3 etc...
it will also help to improve the performance...
Don't use into CORRESPONDING FIELDS OF statement also... its obsolete....
use below stmt
SELECT field1 field2 field3
FROM catsdb
into table TABLE p_c_tab
WHERE workdate BETWEEN input_date AND output_date.Also its better for performance if you can include some more fields like PERNR in where condition..
Hope it will solve your problem
Reward points if useful...
Thanks & Regards
ilesh 24x7
‎2008 May 08 1:41 PM
Hi,
You can improve it by making certain changes.
1) By removing corresponding fields of from select quiery and instead of using * try to declare a structure containing the required fields and declare the internal table of its type .
exp : select f1 f2 f3
from catsdb
into table t_catsdb
where workdate in ( p_l_begda1 , p_l_begda2 ) .
2) Instead of using parameter use select-options.
3) in the perform without using table write everything under using
exp:
PERFORM: ap USING cats_tab1 l_begda13 l_begda12 .
This will increase the performance lable of your coding.
Reward some points.
Bye,
Anomitro