03-06-2013 11:39 AM
Hi experts,
I am having an issue with the following code regarding the counter.
WHEN 'YCO_NON_PROD_HRS'.
DATA: s_data_cats TYPE zoxd780009.
DATA: s_data_cats2 TYPE zoxd780009.
DATA: s_ctshrs TYPE zoxd780009.
data: it_data TYPE STANDARD TABLE OF zoxd780009.
data: count type i.
sort c_t_data.
*break-point.
LOOP AT c_t_data INTO s_data_cats.
*Get WBS Element POSID.
SELECT SINGLE posid INTO s_data_cats-posid FROM prps
WHERE pspnr = s_data_cats-rproj.
select max( counter ) into count from catsdb.
IF s_data_cats-refcounter IS NOT INITIAL.
SELECT SINGLE * FROM catsdb INTO s_ctshrs WHERE counter = s_data_cats-refcounter.
IF sy-subrc = 0.
if s_data_cats-RPROJ eq s_ctshrs-RPROJ.
s_data_cats-catshours = s_data_cats-catshours - s_ctshrs-catshours.
else.
s_data_cats2-counter = count + 1.
s_data_cats2 = s_ctshrs.
s_data_cats2-apdat = s_data_cats-apdat.
s_data_cats2-status = '30'.
s_data_cats2-catshours = s_ctshrs-catshours * -1.
append s_data_cats2 to c_t_data.
ENDIF.
ENDIF.
endif.
modify c_t_data from s_data_cats.
CLEAR s_data_cats.
CLEAR s_data_cats2.
clear s_ctshrs.
ENDLOOP.
The issue is with counter. It raises a short dump:
The idea is to select the maximal number of counter form table CATSDB and icrease it one by one each time i am creating a new record to avoid having 2 records with the same counter because i am loding the data after into BW.
Thanks for your help.
Amine
03-06-2013 12:13 PM
Hi,
What is your requirement ? Do you want the maximum value of counter field in CATSDB. you have declared count as wrong type.
data : count type catsdb-counter.
select MAX( COUNTER ) INTO COUNT FROM CATSDB.
This will give you the maximum counter value from CATSDB table.
Hope this helps.
Thanks,
Tooshar Bendale
03-06-2013 11:59 AM
Hi Amine,
your declaration of field "count" does not fit the column "counter" of table CATSDB used in your aggregating select statement.
It should be of type CATSCOUNTE (which is char12).
You can still add 1 to field count later on, obviously that only makes real sense if only NUMC is used (which I reckon is in that case).
Best regards,
Thorsten
03-06-2013 12:13 PM
Hi Thorsen,
Ok i will test that.
The idea if the max counter in CATSDB is 999.
When i am in else append (by the way it's how i solved my other issue) : so i will add a counter 1000 to c_t_data.
After the loop, if a new record need to be appended it will have 1001 etc...
Thanks.
Amine
03-06-2013 12:19 PM
Agree with Thorsten
Amine, if according to u'r requirement u want to stick with integer type I, U can always assign the values to variables with suitable data types after your select query
Thanks
Vivek
03-06-2013 11:59 AM
Hi Amine,
What does the dump say? COUNTER in CATSDB is of CHAR12 while COUNT is of TYPE I. Not sure if this because of this. Can you please mention the message in the dump? We can help you based on that!
03-06-2013 12:09 PM
Hi,
In fact it's a conversion error. Here's the complete message error:
Amine.
03-06-2013 12:13 PM
Hi,
What is your requirement ? Do you want the maximum value of counter field in CATSDB. you have declared count as wrong type.
data : count type catsdb-counter.
select MAX( COUNTER ) INTO COUNT FROM CATSDB.
This will give you the maximum counter value from CATSDB table.
Hope this helps.
Thanks,
Tooshar Bendale
03-06-2013 12:22 PM
Hi Tooshar,
I followed Thorsten advice, i declared as following:
data: count type CATSCOUNTE.
I don't have the dump anymore.
But it's not working, the count isn't increasing as i want
Amine
03-06-2013 1:07 PM
Hi Amine,
if the value in field count is numerical then your statement should work. If it is not numerical then you should get a dump.
You definitely have to move the SELECT MAX(.. statement up to before the LOOP starts, because each select will always give you the same result. That means: if you loop twice and add 1 you always get the same value (1000 in your example).
From a logical point of view you also have to be very vareful with what you are doing. Basically you are messing up the data provided in E_T_DATA, because the counter you provided IS NOT the primary key of an entry in CATSDB! That is quite dangerous semantically. I am not sure if anyone ever evaluates the content again, but maybe it was better to use some real character as counter. Like CONCATENATE 'A' counter INTO s_data_cats2-counter. This way you will always be able to identify the entries as "added".
Best regards,
Thorsten
03-06-2013 1:09 PM
Hi,
I guess your requirement is to get the count of records present in CATSDB table ?
Do the following
data : count type i.
select count(*) INTO COUNT FROM CATSDB.
Hope this helps.
Thanks,
Tooshar Bendale
03-06-2013 1:51 PM
Hi Amine,
Declare a temp variable and then increment the counter in the temp variable and then try passing the value.
Also store the count value in another temp1 variable of Int / N type. U should be able to proceed now
Thanks
Vivek
03-06-2013 2:12 PM
Thanks guys,
I solved my issue as following:
select max( counter ) into count from catsdb.
LOOP AT c_t_data INTO s_data_cats.
else.
add 1 to count.
shift count right.
overlay count with '000000000000'.
Every thing is working fine.
Amine