ABAP log

September 6, 2007

Caught by TABIX.

Filed under: ABAP, SAP — abaplog @ 8:23 pm

One of my little ABAP programs surprised me today by crashing into ST22. It was just a simple counter taking values from SY-TABIX in an internal table LOOP. I looked again and again. It seemed that a variable of type INT4 (declared to be compatible with SY-TABIX, as I thought) could not accumulate a five-digit number. The solution was simply to have a fresh look at the underlying data type into Data Dictionary. Here, look at my test program:

report ztest.

data:
  lf_tabix  type sytabix,
  lf_tabix2 type tabix.

lf_tabix = 10000.
write: / lf_tabix.
lf_tabix2 = 10000.
write: / lf_tabix2. 

After clicking several times on the type TABIX, I have finally noticed that TABIX is a structure! Four bytes, occupied by one field. And when you use the structure as a whole, ABAP treats it like a character string, and any number greater than 9999 gets screwed.

Well… time to retake BC400.

Advertisements

6 Comments »

  1. If tabix is treated as a character string shud not the 4 digits be printed and rest truncated ?

    Comment by azeem — September 7, 2007 @ 4:55 am

  2. Yes, it’s truncated, but ABAP also places an asterisk (*) into the first position. So when you treat the result as a number you land immediately in ST22.

    Comment by abaplog — September 8, 2007 @ 9:05 pm

  3. Matey, why you don’t use sy-tabix as a TYPE? I’m sure it’s a dirty trick, but it works fine.

    Not the sytabix type you used, just
    DATA: lf_tabix TYPE sy-tabix.

    Or do I am missing something?

    Comment by vlozano — September 13, 2007 @ 9:42 am

  4. TYPE SY-TABIX would work but it’s conceptually wrong. SY-TABIX is not a type but a global field, therefore I never use this kind of declaration. It’s just a replacement for LIKE.

    Comment by abaplog — September 17, 2007 @ 7:45 pm

  5. I see it. But if the system will treat them in a different way if you declare the type or the like… why do not to use the like way, then? (ouch, I’m sure my English hurts here)
    But the conceptually thing, I mean. SAP ignores its own concepts, why must we keep them (if they will hurt our fine tuned and clean work?).

    Comment by vlozano — September 25, 2007 @ 8:50 am

  6. The result of the declaration will be the same. Or maybe I forget: is LIKE allowed in OO context? – doesn’t matter. It’s only that I think that TYPE is more clear. A personal choice anyway.

    Comment by abaplog — September 25, 2007 @ 7:14 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: