Why does the following code:

  DATA: l_str TYPE string,
        l_dat TYPE d.

  l_dat = sy-datum.
  l_str = l_dat.
  WRITE:/ l_str.

  l_dat = ( sy-datum + 1 ).
  l_str = l_dat.
  WRITE:/ l_str.

  l_dat = sy-datum.
  l_dat = ( l_dat + 1 ).
  l_str = l_dat.
  WRITE:/ l_str.

  l_dat = sy-datum.
  l_str = ( l_dat + 1 ).
  WRITE:/ l_str.

Result in the output (specifically the last line):

  20130208
  20130209
  20130209
  734909

And what is the best way to do this instead so as always to get the expected values?

asked 08 Feb '13, 16:42

Marius%20Piedallu%20van%20Wyk's gravatar image

Marius Pieda...
1612411
accept rate: 33%


To understand how this works you probably should check conversion rules for elementary data types. When you add value to variable l_dat it's converted to the number of days since 01.01.0001. In first and 2nd example number is converted back to datum type while you use assignment operator.

Try to use MF 'FORMAT DATE 4 OUTPUT'.

permanent link

answered 09 Feb '13, 08:08

Pawel%20Hixohe%20Grze%C5%9Bkowiak's gravatar image

Pawel Hixohe...
2112511
accept rate: 16%

1

Yup, I also figured this. Just a minor correction. The date is since 01.01.0000... with SAP seeing 01.01.0000 and 00.00.0000 as interchangeably meaning Error (both are equivalent to integer 0).

(09 Feb '13, 13:53) Marius Pieda...

yes, the date is specified as from that date as being valid. However, the integer -> date conversion seems to be zero offset on 01.01.0000 thus adding one gives you the first 'valid' date of 01.01.0001

(31 May '13, 08:30) Marius Pieda...
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×28
×2
×1
×1

question asked: 08 Feb '13, 16:42

question was seen: 8,330 times

last updated: 31 May '13, 08:30