Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

sy-datum

Former Member
0 Likes
2,570

hi

how can i write only sy-datum first two character ?

hi

how can i write only sy-datum first two character ?

17 REPLIES 17
Read only

bpawanchand
Active Contributor
0 Likes
2,161

Hi

data :

w_c(2) type c.

w_c = sy-datum+0(2).

Regards

Pavan

Read only

Former Member
0 Likes
2,161

Hi,

You should declare a temporary variable & use offset (of 2 characters)

Example:-

data :
w_var(2) type c.

w_var = sy-datum+0(2).
write w_var.

Luck,

Bhumika

Read only

Former Member
0 Likes
2,161

Hi,

Data: w_offset(2) type c.

w_offset = sy-datum+0(2).

Write: w_offset.

Read only

0 Likes
2,161

this is output 20 . this is year

ı want to day .

and ?

Read only

0 Likes
2,161

hi

write : sy-datum+6(2).

Regards

Pavan

Read only

0 Likes
2,161

Hi,

as date will be yyyymmdd.

so to get the date..

w_c = sy-datum+6(2).

Good luck

Narin

Read only

0 Likes
2,161

Hi,

Chenge then,

Data: w_offset(2) type c.
 
w_offset = sy-datum+6(2).
 
Write: w_offset.

Read only

Former Member
0 Likes
2,161

hi,

Use Offset. By using Offset you can extract any number of characters from a string from any position.

You can extract this date part by applying Offset settings.

Date1 type sy-datum.

date(2) type c.

Date = Date1+0(2).

Write:/ Date.

Regards

Sumit Agarwal

Read only

Former Member
0 Likes
2,161

>

> hi

>

> how can i write only sy-datum first two character ?

write sy-datum+0(2).

Read only

Former Member
0 Likes
2,161

Hi,

Here you can offset to get the value of your requirment

Syntax 1:

data :
temp(2) type c.

temp = sy-datum+0(2).

Syntax 2:

data :
temp  type string.

temp = sy-datum+0(2).

for detail in offset check

http://help.sap.com/saphelp_nw04/Helpdata/EN/79/c55470b3dc11d5993800508b6b8b11/content.htm

Regards,

Anirban

Read only

narin_nandivada3
Active Contributor
0 Likes
2,161

Hi

Data:

w_date(2) type c.

to get the first two character the specify the offset length as 2.

so to get from the starting position specify it as 0.

w_date = sy-datum+0(2).

0--> Postion

2--> length of characters

Hope this would help you.

Good luck

Narin

Read only

Former Member
0 Likes
2,161

hey copy this program and directly execute.

DATA: DAT LIKE SY-DATUM,

DAT1(2) type c.

DAT = SY-DATUM.

write:/ 'IF U WANT TO DISPLAY DATE '.

dat1 = dat+6(2).

WRITE:DAT1.

write:/ 'IF U WANT TO DISPLAY month '.

DAT1 = DAT+4(2).

WRITE:DAT1.

write:/ 'if u want to display 20 of 2008'.

DAT1 = DAT+0(2).

WRITE:DAT1.

Read only

Former Member
0 Likes
2,161

as others have also said, do it like:

write: sy-datum+6(2). " for day
write: sy-datum+4(2).          " for month
write: sy-datum+2(2).          " for year

With luck,

Pritam.

Read only

0 Likes
2,161

thanks all.

Read only

Former Member
0 Likes
2,161

Hi,

Data : sdat type c.

clear sdat.

sdat = sy-datum+0(2). //it will first 2 character from the date.

// here 0 indicates starting position of the word.

// (2) indicates how many characters from the starting position.

Regards,

Harish

Read only

Former Member
0 Likes
2,161

hi..

check out this

DATA: L_DAY(2) TYPE C,

L_MONTH(2) TYPE C,

L_YEAR(4) TYPE C,

L_LTEXT TYPE T247-LTX.

DATA: L_DATE TYPE STRING.

CALL FUNCTION 'HR_IN_GET_DATE_COMPONENTS'

EXPORTING

IDATE = SY-DATUM

IMPORTING

DAY = L_DAY

MONTH = L_MONTH

YEAR = L_YEAR

LTEXT = L_LTEXT

EXCEPTIONS

INPUT_DATE_IS_INITIAL = 1

TEXT_FOR_MONTH_NOT_MAINTAINED = 2

OTHERS = 3.

now choose from this what you want?

Read only

matt
Active Contributor
0 Likes
2,161

Anyone who's used offset, go and read this article about "magic numbers" to understand why they are BAD http://en.wikipedia.org/wiki/Magic_number_%28programming%29#Unnamed_numerical_constant

The correct way of parsing sy-datum is:

BEGIN OF data_ty,
    yyyy TYPE c length 4,
    mm   TYPE c length 2,
    dd   TYPE c length 2,
END OF data_ty.

DATA: l_mydat TYPE data_ty.

l_mydat = sy-daturm.

WRITE: / l_mydat-dd

This is much more meaningful and obvious than sy-datum+2(6). By using the type formulation, you've explicitly said with the structure of sy-datum is. If it changes (highly unlikely, I know, but it's the principle), then you only have to change the type definition- not potentially a hundred places in your program.

matt