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

remove bracket from the logic

Former Member
0 Likes
3,095

Hi,

I have data as:

DATA :lv_var2(100) TYPE c VALUE '[ [D7] ]/[ [DG] ]/[ [AB] ]'.

In an internal table i want the data as

it_tab D7

DG

AB

How do i remove this bracket..?

Edited by: neha gupta on Jul 26, 2010 6:59 AM

Edited by: neha gupta on Jul 26, 2010 7:00 AM

Edited by: neha gupta on Jul 26, 2010 7:01 AM

9 REPLIES 9
Read only

former_member156446
Active Contributor
0 Likes
2,081

we first of all... we dont see the brackets... may be it could be the forum theme that killing them to display...

if at all you are having some brackets and want to remove that you can use " find all occurrences of ')" in field and use replace statement..

or

check that the field of the itab can hold only alphabets and numbers only... any thing else found need to be replaced with space.

Read only

former_member585060
Active Contributor
0 Likes
2,081

Hi,

Use REPLACE ALL OCCURRENCES OF and SPLIT statement.

Sample :-

TYPES: BEGIN OF itab_type,
        word(20),
      END   OF itab_type.

DATA: itab TYPE STANDARD TABLE OF itab_type WITH
                NON-UNIQUE DEFAULT KEY.

DATA :lv_var2(100) TYPE c VALUE '[ D7] /[ DG] /[ AB]'.

START-OF-SELECTION.

REPLACE ALL OCCURRENCES OF '[' in lv_var2 WITH ' '.
REPLACE ALL OCCURRENCES OF ']' in lv_var2 WITH ' '.

  SPLIT lv_var2 AT '/' INTO TABLE itab.

Internal table itab has the required format entries.

Regards

Bala Krishna

Read only

0 Likes
2,081

how will i split this: '[[ZDEC(<>ZB2){-}]/[ZDEB(){}]/[ZDED(){}]]'

i used replace and split :

it_tab became like : ZDEC(<>ZB2){-}

ZDEB(){+}

ZDED(){+}

Now i want furthur split..Like below:

Types:

BEGIN OF ts_inc,

fkart TYPE fkart,

sign(2) TYPE c,

augru TYPE augru,

plus(1) TYPE c,

END OF ts_inc.

fkart sign augru plus

ZDEC <> ZB2 -

ZDEB +

ZDED +

how should i achieve this..?

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,081

Do you know what are the special characters which can be passed to the string ?

You can use the FMs: 'SF_SPECIALCHAR_DELETE' & 'ES_REMOVE_SPECIAL_CHARACTER' as reference & build a custom FM.

I tried to use RegEx [[:punct:]] but doesn't solve your requirement. The output using the 3 techniques are:

1. Using SF_SPECIALCHAR_DELETE: [ZDECZB2{}ZDEB{}ZDED{}]

2. Using ES_REMOVE_SPECIAL_CHARACTER: ZDEC ZB2 /ZDEB /ZDED

3. Using REGEX [[:punct:]]: ZDECZB2ZDEBZDED (i don't think you would be interested in this !!!)

BR,

Suhas

Read only

0 Likes
2,081

Hi,

Is the pattern fixed in the lv_var2? for the value given in second posting, you can try below method,

DATA : i_inc TYPE TABLE OF ts_inc,
       wa_inc TYPE ts_inc.

DATA : lv_len TYPE i,
       lv_fkart TYPE fkart,
       lv_sign TYPE c.

START-OF-SELECTION.
  REPLACE ALL OCCURRENCES OF '[' IN lv_var2 WITH ' '.
  REPLACE ALL OCCURRENCES OF ']' IN lv_var2 WITH ' '.
  REPLACE ALL OCCURRENCES OF '{' IN lv_var2 WITH ','.
  REPLACE ALL OCCURRENCES OF '}' IN lv_var2 WITH ' '.

  SPLIT lv_var2 AT '/' INTO TABLE itab.

  LOOP AT itab INTO wa_itab.
    SPLIT wa_itab-word AT ',' INTO
                              lv_fkart lv_sign.
    wa_inc-fkart = lv_fkart.
    wa_inc-sign = lv_sign.

    APPEND wa_inc TO i_inc.

    CLEAR : wa_itab, wa_inc, lv_fkart, lv_sign.

  ENDLOOP.

Move the variable into particular field in above LOOP and ENDLOOP, i have populated in FKART and SIGN fields, you can declare LV_FKART and LV_SIGN as strings and move the values, as FKART can hold only 4 characters, in out put you are able to see ZDEC not ZDEC ZB2.

Regards

Bala Krishna

Read only

Former Member
0 Likes
2,081
REPLACE ALL OCCURRENCES OF '[' in lv_var2 WITH ''.
REPLACE ALL OCCURRENCES OF ']' in lv_var2 WITH ''.
REPLACE ALL OCCURRENCES OF '/' in lv_var2 WITH ''.
CONDENSE lv_var2 NO-GAPS.

Now your data string is converted to :-

lv_var2 = D7DGAB

Use like below for

l

v_var2+0(2) = w_D7.

lv_var2+2(4) = w_DG.

lv_var2+4(6) = w_AB.

Read only

0 Likes
2,081

hi ,

Use this code .

TYPES: BEGIN OF S_T,

sVAL(3) TYPE c,

END OF S_T.

DATA :lv_var2(100) TYPE c VALUE '[ D7] /[ DG] /[ AB] '.

DATA: I_Tab TYPE STANDARD TABLE OF S_T,

WA TYPE S_T.

REPLACE ALL OCCURRENCES OF '[' IN lv_var2 WITH ''.

REPLACE ALL OCCURRENCES OF ']' IN lv_var2 WITH ''.

SPLIT lv_var2 at '/' INTO TABLE I_Tab.

With Regards.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,081

data:lv_string type string.
data:it type table of char255.
lv_string = '[ D7] /[ DG] /[ AB] '.
REPLACE ALL OCCURRENCES OF REGEX '[^[:alnum:]]' IN lv_string WITH ` `.
condense lv_string.
write lv_string.
split lv_string at ` `  into table it.
Read only

0 Likes
2,081

Won't work for [ZDEC(ZB2){-}/ZDEB(){}/ZDED(){}] as required by the OP. (dunno why the text is getting striked !!!)

'[^[:alnum:]]' -> Is a negation of the Alphanumeric values. It'll delete the signs - & + also. Not as required by the OP.

BR,

Suhas