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

HOW TO MATCH FIELDS WITH DIFFERENT LENGTH

Former Member
0 Likes
6,327

I am working on a report. I have table <b>MARD</b> and <b>WRPL</b>. We use <b>plants (werks)</b> which is character - 4 in length for MARD and we want to use it to reference <b>customer (kunnr)</b> which is character 10.

Kunnr comes with leading zeros because of its length. so a plant 0501 will come as 000000501. I removed the leading zeros with the function module "CONVERSION_EXIT_ALPHA_OUTPUT". But the problem i know have that after removing the leading zeros a plant eg 0022 will become 22 on customer kunnr which is given errors.

Is there a way to remove the leading zeros up to just 4 in length. Eg. <b>i want 0000000022 to become 0022.</b>

Thanks for your help.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,561

hi

use shift command.

shift lv_kunnr left by 6 places deleting leading 0.

Thanks

Mahesh

6 REPLIES 6
Read only

former_member194669
Active Contributor
0 Likes
2,561

Hi,

Like this way


data : v_werks like t001w-werks.
" Move 22 value to v_werks after fm CONV EXIT ALPHA OUTPUT
unpack kunnr to v_werks.

aRs

Read only

Former Member
0 Likes
2,561

You can do achieve the same as below..

Compare kunnr+6(4) with Werks.

like,

if kunnr+6(4) eq werks. "it will always consider last 4 characters of kunnr

*do something

endif.

Here no need to convert and use any FM.

Reward if it helps.

Thanks

Read only

Former Member
0 Likes
2,561

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
2,562

hi

use shift command.

shift lv_kunnr left by 6 places deleting leading 0.

Thanks

Mahesh

Read only

0 Likes
2,561

Hi

What data type you have declared for that field

declare as

data: it_mara(3) type N.

It will solve your problem

or if it is not solved then u can try along with that statement this statement too

SHIFT IT_MARA LEFT DELETING LEADING '0000'.

Reward all helpfull answers

Regards

Pavan

Read only

Former Member
0 Likes
2,561

Thanks all.

I got someone to help me.