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

printing offset values

Former Member
0 Likes
1,434

in the following code i want only delivery no from sdata.its length is 10.and is the first value in sdata.

i want to get only delivery no from sdata and print it inthe table along with idocno.

pz tell me how to do it

tables:edid4.

types:begin of ty_edid4,

DOCNUM type EDI_DOCNUM,

sdata type EDI_SDATA,

end of ty_edid4.

data:it_edid4 type table of ty_edid4,

wa_edid4 type ty_edid4.

select-options:s_docnum for edid4-docnum.

start-of-selection.

select DOCNUM

sdata

from

edid4 into table it_edid4

where docnum in s_docnum.

loop at it_edid4 into wa_edid4.

write:/ wa_edid4-docnum,'|',wa_edid4-sdata.

endloop.

6 REPLIES 6
Read only

Former Member
0 Likes
920

Hi pavan,

did u try using wa_edid4-sdata+0(10).

regards,

sap fan

Read only

Former Member
0 Likes
920

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

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
920

Hi,

Try this:

WRITE:/ wa_edid4-docnum,'|',wa_edid4-sdata+0(2).

Read only

0 Likes
920

Mistake...

WRITE:/ wa_edid4-docnum,'|',wa_edid4-sdata+0(10).

Read only

Former Member
0 Likes
920

HI,

You can write in this way

loop at it_edid4 into wa_edid4.

write:/ wa_edid4-docnum,'|',wa_edid4-sdata+0(10).

endloop.

Regards

Sudheer

Read only

Former Member
0 Likes
920

Hi..

Try this...

loop at it_edid4 into wa_edid4.

write:/ wa_edid4-docnum,'|',<b>wa_edid4-sdata+0(10)</b>.

endloop.

regards.