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

Filtering Characters in a table

Former Member
0 Likes
1,783

Hi,

Please help hows the coding if i want to filter a character within a table?

e.g ABC123ED - i want to get 23ED

Thanks,

PAUL

Hi,

Please help hows the coding if i want to filter a character within a table?

e.g ABC123ED - i want to get 23ED

Thanks,

PAUL

10 REPLIES 10
Read only

faisalatsap
Active Contributor
0 Likes
1,528

Hi, Pwaren

Please Test the following Sample Code i think you need some thing like this.

TYPES: BEGIN OF ty,
  char(20),
  END OF ty.

DATA: it TYPE STANDARD TABLE OF ty WITH HEADER LINE.

it-char = '123ABC'. APPEND it. it-char = '123ABCD'. APPEND it. it-char = 'ABCD123'. APPEND it.

LOOP AT it.
  IF it-char CS '3ABC'.
    WRITE: / it-char.
  ENDIF.
ENDLOOP.

Please Reply if else Requirement,

Best Regards,

Faisal

Read only

Former Member
0 Likes
1,528

>

> e.g ABC123ED - i want to get 23ED

Whats the logic behind this, you always what to get the last 4 characters or what?

Tell the requirement clearly.

Regards

Karthik D

Read only

0 Likes
1,528

Hi,

Yeah, i want to get the last 4 characters from the string from a certain tables.

PAUL

Read only

0 Likes
1,528

Here is more clear details.

e.g

Table: KNNK-KUNNR

KUNNR field got this values:

-ADW12GE

-NHG56TG

-NH67HG5

-U6T7F65

i only want to get the last for charaters.

Thanks in advance

PAUL

Read only

0 Likes
1,528

calculate the length of ur strings every time

len = strlen(kunnr).

offset = len - 4.

kunnr = kunnr+offset(4).

Read only

0 Likes
1,528

Hi PwarrenP,

To get the last 4 chars always you can try like this...

first pass your value to get a leading zero and fill all the chars & try to take last 4 with the offset.


DATA : BEGIN OF ITAB OCCURS 0,
       CHAR(20),
       END OF ITAB.
DATA : LEN(2) TYPE C.
DATA : CNT(2) TYPE C.

ITAB-CHAR = 'ASFH'.
APPEND ITAB.
ITAB-CHAR = '12C4SSFA'.
APPEND ITAB.
ITAB-CHAR = '12CSFD4SA'.
APPEND ITAB.
ITAB-CHAR = '1SDFA2C4SA'.
APPEND ITAB.
ITAB-CHAR = '12C4SAA'.
APPEND ITAB.
ITAB-CHAR = '12C4SAFSD'.
APPEND ITAB.

LOOP AT ITAB.
  CLEAR : LEN.
  LEN = STRLEN( ITAB-CHAR ).
  CNT = LEN - 4.

  WRITE : / ITAB-CHAR+CNT(4).

ENDLOOP.
 

Thanks & regards,

Dileep .C

That was a bit late PAUL....

By the way what was your solution...!

Edited by: Dileep Kumar Chinnaiah on Jun 16, 2009 4:39 PM

Read only

Former Member
0 Likes
1,528

Hi,

Please go through this thread...

Hope it helps...

Read only

Former Member
0 Likes
1,528

use offset like variable+offset(len)

Thanks

Venkat

Read only

Nawanandana
Active Contributor
0 Likes
1,528

hi

you can used this code for it


data : text(8),
text2(4).


text = ' ABC123ED'.


text2 = text+3(4).

regard

nawa

Read only

0 Likes
1,528

Thanks for prompt response.. Solved.

PAUL