Application Development 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: 

Sample code to get 1st 5 characters of a field and also how to use help ?

Former Member
0 Kudos

hi ABAP4 experts,

We are kind of new at ABAP4. We'd be appreciated if you would provide sample code to get 1st 5 characters of a field and also let us know on how to use ABAP4 help to look for such kind solution that next time we don't have to bother you guys here!

We will give you reward points!

Message was edited by: Kevin Smith

5 REPLIES 5

Former Member
0 Kudos

Kevin,

Assuming var1 is your field var+0(5) will give you the first 5 characters of the field.

Field+starting position(length)

The concerned link is here. You can find the help for ABAP here

http://help.sap.com/saphelp_nw04/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm

Regards,

Ravi

Note : Please mark the helpful posts

0 Kudos

just want to add that its only ABAP now & the '4' in the end to indicate 4GL has been dropped a while ago by SAP.

Regards,

Suresh Datti

Former Member
0 Kudos

Hi Kevin,

**We'd be appreciated if you would provide sample code to get 1st 5 characters of a field

simple.

data : var1(12),

var2(5).

var1 = 'SUNNY ON SDN'.

var2 = var1(5)

write var2.

check this refernce thread which will give u some idea on offset .

**let us know on how to use ABAP4 help to look for such kind solution that next time we don't have to bother you guys here!

Kevin , one simple way to use ABAP4 help is to press F1 on the field or on the keyword and you will get lots of help including the sample code.

Hope this will help you

Cheers

Sunny

Rewrd points, if found helpful

Former Member
0 Kudos

Hi Kevin,

here is the Example for the offset which you want

DATA TIME TYPE T VALUE '172545'.

WRITE TIME.

WRITE / TIME+2(2).

CLEAR TIME+2(4).

WRITE / TIME.

<u>The output appears as follows:</u>

172545

25

170000

<i>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.</i>

<b>2nd Example:-</b>

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.

if you want more info

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb341a358411d1829f0000e829fbfe/content.htm

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3294358411d1829f0000e829fbfe/content.htm

hope this solves your Problem

Thanks

Sudheer

Former Member
0 Kudos

You already got answers for getting the first 5 characters. If you are not sure about what search criteria to use in ABAP help to get the answer, then this is the place. That is the reason for this forum.

But just in this case, what you are looking for is an offset of a string. So, you can either try <b><u>offset</u></b> or <b><u>string functions</u></b>. But you will also find it when you are looking for MOVE or WRITE help. So in most cases, there are several ways to search the ABAP help to get the answer you need. Since there are several ways, it is always easier to get an instant answer here.