Skip to Content

Error with Abap Counter

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

Sans titre.png (30.4 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Mar 06, 2013 at 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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member amine lamkaissi

      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

  • Posted on Mar 06, 2013 at 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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Mar 06, 2013 at 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!

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Mar 06, 2013 at 02: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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.