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

Date

Former Member
0 Likes
2,438

concatenate today6(2) '.' today4(2) '.'

today+0(4) into today1.

plz do explain wht does 6(2)/4()/0(4) and '.' stand for....wht does it do ....

15 REPLIES 15
Read only

Former Member
0 Likes
1,940

Hi,

6(2)/4(2)/0(4) are offset values of the field today.

By using these offset values values inside today field is divided into date , month, year and these values are concatenating into the field today1 seperated by period '.'.

Regards,

Sankar

Read only

Former Member
0 Likes
1,940

Hi

It is called Offsetting of a field

if a field is having 10 charcters

then field+4(2) gives the 5th and 6th charcters data

similarly field+6(4) gives the 7th, 8th,9th and 10th char data (4 char)

for a date field first char is year and next 2 char(5th and 6th) are month and last 2 char are day fields

<b>Reward points for useful Answers</b>

Regards

Anji

Message was edited by:

Anji Reddy Vangala

Read only

Former Member
0 Likes
1,940

hi,

Chk this sample.

in_date = '20070903'.

data : out_date(10) type c.

*take variables V1, V2, V3.
V3 = in_date+6(2).
V2 = in_date+4(2).
V1 = in_date+0(4).

Concatenate V3 V2 V1 into out_date separated by '.'.



write out_date."03.09.2007

Rgds

Reshma

Read only

Former Member
0 Likes
1,940

hi

everytime you add m(n) with a string, it means it would select (n) number of numbers from m th position in the given string.

regards

asha

Read only

Former Member
0 Likes
1,940

Hi,

if today contains suppose 20060431 (YYYYMMDD format)

here today+6(2) is from 6th postion 2 characters ie 3 and 1

today+4(2) is from 4th postion 2 characters ie 0 and 4

today+0(4) is first four characaters 2006

and you are concatenating dot(.) in betweeen and making it as

31.07.2006 is format you are trying to see

Regards,

Srinivas

Read only

Former Member
0 Likes
1,940

in sap the values of data is as follows .

"  YYYYMMDD

 " 6(2)-> From 6th position to 6+2 = Upto 8TH Position  is DD.
" 4(2)-> From 4th position to 4+2 = Upto 6TH Position  is MM.
" And 0(4)-> From 0th position to 0+4 = Upto 4TH Position  is YYYY.

SO

' concatenate today+6(2) '.' today+4(2) '.' today+0(4) into today1.

" . "

is an string concatenated with your data .

reward points if it is usefull ...

Girish

Read only

Former Member
0 Likes
1,940

Hi

today+6(2) means it takes 2 digits from 7th position where the postion starts from 0.

today+4(2) means 2 digits from 5th position

today+0(4) means 4 digits from starting value

and it concatenates all these along with fullstop

Regards

sandhya

Read only

Former Member
0 Likes
1,940

Hi,

6(2) means after 6th position it will take next 2 characters(i.e. 7th and 8th position values).

4(2) means it will take 5th and 6th position values.

0(4) means it will take first 4 characters.

ex. today date is 20070731.

6(2) = 31.

4(2) = 07.

0(4) = 2007.

then today1 = 31.07.2007.

Regards,

Bhaskar

Read only

Former Member
0 Likes
1,940

Hi,

plz do explain wht does 6(2)/4()/0(4) and '.' stand for....wht does it do ....

--> it means you have a date field today Format YYYYMMDD

in today+6(2), you are capturing DD 2 digits after 6th digit.

in today+4(2), you are capturing MM 2 digits after 4th digit.

in today+0(4), you are capturing YYYY 4 digits after 0 digit.

now you are saving these value in other field today1 saperated by '.'

the format will be for display now as 'YYYY.MM.DD'

Reward, if helpful,

Sandeep Kaushik

Read only

Former Member
0 Likes
1,940

Processing Sections of Strings

You can address a section of a string in any statement in which non-numeric elementary ABAP types or structures that do not contain internal tables occur using the following syntax:

<f>[+<o>][(<l>)]

By specifying an offset <o> and a length (<l>) directly after the field name <f>, you can address the part of the field starting at position <o>1 with length <l> as though it were an independent data object. The data type and length of the string section are as follows:

Original field

Section

Data type

Data type

Length

C

C

<l>

D

N

<l>

N

N

<l>

T

N

<l>

X

X

<l>

Structure

C

<l>

If you do not specify the length <l>, you address the section of the field from <o> to the end of the field. If the offset and length combination that you specify leads to an invalid section of the field (for example, exceeding the length of the original field), a syntax or runtime error occurs. You cannot use offset and length to address a literal or a text symbol.

You should take particular care when addressing components of structures. To ensure the correct platform-specific alignment of type I and F components, they may contain filler fields, whose lengths you need to consider when calculating the correct offset. Furthermore, SAP plans to convert the internal representation of character types to UNICODE, in which one character will no longer occupy one byte, but instead two or four. Although offset and length specifications can work for character fields (types C, D, N, and T) or for hexadecimal fields (type X), incompatible changes may occur in structures containing a mixture of numeric, character, and hexadecimal fields. SAP therefore recommends that you do not use offset and length to address components of structures.

In nearly all cases, you must specify offset <o> and length <l> as numeric literals without a preceding sign. You may specify them dynamically in the following cases:

When assigning values using MOVE or the assignment operator

When assigning values with WRITE TO

When assigning field symbols using ASSIGN.

When passing actual parameters to subroutines in the PERFORM statement.

DATA TIME TYPE T VALUE '172545'.

WRITE TIME.

WRITE / TIME+2(2).

CLEAR TIME+2(4).

WRITE / TIME.

The output appears as follows:

172545

25

170000

First, the minutes are selected by specifying an offset in the WRITE statement. Then, the minutes and seconds are set to their initial values by specifying an offset in the clear statement.

Offset and Length Specifications in the MOVE Statement

For the MOVE statement, the syntax for specifying offset and length is as follows:

MOVE <f1>[<o1>][(<l1>)] TO <f2>[<o2>][(<l2>)].

Or, when you use the assignment operator:

<f2>[<o2>][(<l2>)] = <f1>[<o1>][(<l1>)].

The contents of the part of the field <f1> which begins at position <o1>1 and has a length of <l1> are assigned to field <f2>, where they overwrite the section which begins at position <o2>1 and has a length of <l2>.

In the MOVE statement, all offset and length specifications can be variables. This also applies to statements with the assignment operator, as long as these can also be written as MOVE statements. In statements where no field name is specified after the assignment operator, (for example, in Numeric Operations), all offset and length specifications must be unsigned number literals.

SAP recommends that you assign values with offset and length specifications only between non-numeric fields. With numeric fields, the results can be meaningless.

DATA: F1(8) VALUE 'ABCDEFGH',

F2(20) VALUE '12345678901234567890'.

F26(5) = F13(5).

In this example, the assignment operator functions as follows:

DATA: F1(8) VALUE 'ABCDEFGH',

F2(8).

DATA: O TYPE I VALUE 2,

L TYPE I VALUE 4.

MOVE F1 TO F2. WRITE F2.

MOVE F1+O(L) TO F2. WRITE / F2.

MOVE F1 TO F2+O(L). WRITE / F2.

CLEAR F2.

MOVE F1 TO F2+O(L). WRITE / F2.

MOVE F1O(L) TO F2O(L). WRITE / F2.

This produces the following output:

ABCDEFGH

CDEF

CDABCD

ABCD

CDEF

First, the contents of F1 are assigned to F2 without offset specifications. Then, the same happens for F1 with offset and length specification. The next three MOVE statements overwrite the contents of F2 with offset 2. Note that F2 is filled with spaces on the right, in accordance with the conversion rule for source type C.

Offset and Length Specifications in the WRITE TO Statement

For the WRITE TO statement, the syntax for specifying offset and length is as follows:

WRITE <f1>[<o1>][(<l1>)] TO <f2>[<o2>][(<l2>)].

The contents of the part of the field <f1> which begins at position <o1>1 and has a length of <l1> are converted to a character field and assigned to field <f2>, where they overwrite the section which begins at position <o2>1 and has a length of <l2>.

In the WRITE TO statement, the offset and length specifications of the target field can be variables. The offset and length of the target field must be numeric literals without a preceding sign.

DATA: STRING(20),

NUMBER(8) TYPE C VALUE '123456',

OFFSET TYPE I VALUE 8,

LENGTH TYPE I VALUE 12.

WRITE NUMBER(6) TO STRING+OFFSET(LENGTH) LEFT-JUSTIFIED.

WRITE: / STRING.

CLEAR STRING.

WRITE NUMBER(6) TO STRING+OFFSET(LENGTH) CENTERED.

WRITE: / STRING.

CLEAR STRING.

WRITE NUMBER TO STRING+OFFSET(LENGTH) RIGHT-JUSTIFIED.

WRITE: / STRING.

CLEAR STRING.

This produces the following output:

123456

123456

123456

The first six characters of the field NUMBER are written left-justified, centered, and right-justified into the last 12 characters of the field STRING.

Read only

Former Member
0 Likes
1,940

Processing Sections of Strings

You can address a section of a string in any statement in which non-numeric elementary ABAP types or structures that do not contain internal tables occur using the following syntax:

<f>[+<o>][(<l>)]

By specifying an offset <o> and a length (<l>) directly after the field name <f>, you can address the part of the field starting at position <o>1 with length <l> as though it were an independent data object. The data type and length of the string section are as follows:

Original field

Section

Data type

Data type

Length

C

C

<l>

D

N

<l>

N

N

<l>

T

N

<l>

X

X

<l>

Structure

C

<l>

If you do not specify the length <l>, you address the section of the field from <o> to the end of the field. If the offset and length combination that you specify leads to an invalid section of the field (for example, exceeding the length of the original field), a syntax or runtime error occurs. You cannot use offset and length to address a literal or a text symbol.

You should take particular care when addressing components of structures. To ensure the correct platform-specific alignment of type I and F components, they may contain filler fields, whose lengths you need to consider when calculating the correct offset. Furthermore, SAP plans to convert the internal representation of character types to UNICODE, in which one character will no longer occupy one byte, but instead two or four. Although offset and length specifications can work for character fields (types C, D, N, and T) or for hexadecimal fields (type X), incompatible changes may occur in structures containing a mixture of numeric, character, and hexadecimal fields. SAP therefore recommends that you do not use offset and length to address components of structures.

In nearly all cases, you must specify offset <o> and length <l> as numeric literals without a preceding sign. You may specify them dynamically in the following cases:

When assigning values using MOVE or the assignment operator

When assigning values with WRITE TO

When assigning field symbols using ASSIGN.

When passing actual parameters to subroutines in the PERFORM statement.

DATA TIME TYPE T VALUE '172545'.

WRITE TIME.

WRITE / TIME+2(2).

CLEAR TIME+2(4).

WRITE / TIME.

The output appears as follows:

172545

25

170000

First, the minutes are selected by specifying an offset in the WRITE statement. Then, the minutes and seconds are set to their initial values by specifying an offset in the clear statement.

Offset and Length Specifications in the MOVE Statement

For the MOVE statement, the syntax for specifying offset and length is as follows:

MOVE <f1>[<o1>][(<l1>)] TO <f2>[<o2>][(<l2>)].

Or, when you use the assignment operator:

<f2>[<o2>][(<l2>)] = <f1>[<o1>][(<l1>)].

The contents of the part of the field <f1> which begins at position <o1>1 and has a length of <l1> are assigned to field <f2>, where they overwrite the section which begins at position <o2>1 and has a length of <l2>.

In the MOVE statement, all offset and length specifications can be variables. This also applies to statements with the assignment operator, as long as these can also be written as MOVE statements. In statements where no field name is specified after the assignment operator, (for example, in Numeric Operations), all offset and length specifications must be unsigned number literals.

SAP recommends that you assign values with offset and length specifications only between non-numeric fields. With numeric fields, the results can be meaningless.

DATA: F1(8) VALUE 'ABCDEFGH',

F2(20) VALUE '12345678901234567890'.

F26(5) = F13(5).

In this example, the assignment operator functions as follows:

DATA: F1(8) VALUE 'ABCDEFGH',

F2(8).

DATA: O TYPE I VALUE 2,

L TYPE I VALUE 4.

MOVE F1 TO F2. WRITE F2.

MOVE F1+O(L) TO F2. WRITE / F2.

MOVE F1 TO F2+O(L). WRITE / F2.

CLEAR F2.

MOVE F1 TO F2+O(L). WRITE / F2.

MOVE F1O(L) TO F2O(L). WRITE / F2.

This produces the following output:

ABCDEFGH

CDEF

CDABCD

ABCD

CDEF

First, the contents of F1 are assigned to F2 without offset specifications. Then, the same happens for F1 with offset and length specification. The next three MOVE statements overwrite the contents of F2 with offset 2. Note that F2 is filled with spaces on the right, in accordance with the conversion rule for source type C.

Offset and Length Specifications in the WRITE TO Statement

For the WRITE TO statement, the syntax for specifying offset and length is as follows:

WRITE <f1>[<o1>][(<l1>)] TO <f2>[<o2>][(<l2>)].

The contents of the part of the field <f1> which begins at position <o1>1 and has a length of <l1> are converted to a character field and assigned to field <f2>, where they overwrite the section which begins at position <o2>1 and has a length of <l2>.

In the WRITE TO statement, the offset and length specifications of the target field can be variables. The offset and length of the target field must be numeric literals without a preceding sign.

DATA: STRING(20),

NUMBER(8) TYPE C VALUE '123456',

OFFSET TYPE I VALUE 8,

LENGTH TYPE I VALUE 12.

WRITE NUMBER(6) TO STRING+OFFSET(LENGTH) LEFT-JUSTIFIED.

WRITE: / STRING.

CLEAR STRING.

WRITE NUMBER(6) TO STRING+OFFSET(LENGTH) CENTERED.

WRITE: / STRING.

CLEAR STRING.

WRITE NUMBER TO STRING+OFFSET(LENGTH) RIGHT-JUSTIFIED.

WRITE: / STRING.

CLEAR STRING.

This produces the following output:

123456

123456

123456

The first six characters of the field NUMBER are written left-justified, centered, and right-justified into the last 12 characters of the field STRING.

Read only

Former Member
0 Likes
1,940

Hi.

It's the same of

data date(10).
write today to date.

Example, after the instruction:

today: 20070119

date: 19.01.2007

Read only

Former Member
0 Likes
1,940

hi,

totdate will be in dd.mm.yyyy format.

6(2) refers to date field consists of 6 characters.out of which only first two characters are chosen for displaying dd.

4(2) after dd we have month ie... mm so we are pointing to fourth position.

4 will give the year value. yyyy.

Reward with points if helpful.

Read only

former_member378318
Contributor
0 Likes
1,940

It feels like I'm missing out on something if I do not reply to this thread, so here goes:

Hi S K,

Word! The concatenate command in this case is building a date in the format DD.MM.YYYY

Reward points if theres any left?

Read only

Former Member
0 Likes
1,940

hi

if we write 6(2) means it will select the 2 charcters from the selected string.i.e., the number which is specified in the bracket will givens length to be selected & number before bracket gives the starting poisition.

concatenates means it will merge or joins all the specified fields with seperated by '.' in ur example.

In sap the date is stored in the yyyy.mm.dd formate. so in your query it will displays todays date in the formate dd.mm.yyyy.

when 6(2) is written it will select the date & 4(2) is taken it will select the month & 0(4) is written year.