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: 

ABAP 7.4: SHIFT, places calculated

ralf_wenzel_heuristika
Active Participant
0 Kudos
1,047

Hi,

I want to re-design the following coding sequence:

      CREATE DATA ltype TYPE LINE OF (tabname).
       ASSIGN ltype->* TO FIELD-SYMBOL(<ltype>).
       typedescr = cl_abap_typedescr=>describe_by_data( <ltype> ).
       tabname = typedescr->absolute_name.
       SHIFT tabname:
         LEFT UP TO '=',
         LEFT BY 1 PLACES.


tabname contains i. e.  '/TYPE=MARA', I need the table name MARA. The double-shift bothers me. I'd like to do something like this:


tabname = shift_left( shift_left( val = tabname places = find( val = typedescr->absolute_name sub = '=' ) ) places = 2 ).


(wich means: find the '=' in absolute_name, shift to this char, shift 2 places more, the result is the table's name, i. e. MARA).


What I am doing wrong?

1 ACCEPTED SOLUTION

ChristianGünter
Contributor
0 Kudos
302

Hi Ralf,

may i suggest you another solution?

I would solve this problem with a regular expression.

Something like this:


" submatches MARA in /TYPE=MARA
FIND FIRST OCCURRENCE OF REGEX '\/.*=(.*)' IN tabname
           SUBMATCHES DATA(raw_type).

I know some people find them daunting, but once you mastered them it's quite a powerful tool in your toolbox.

Regards Christian

13 REPLIES 13

ChristianGünter
Contributor
0 Kudos
303

Hi Ralf,

may i suggest you another solution?

I would solve this problem with a regular expression.

Something like this:


" submatches MARA in /TYPE=MARA
FIND FIRST OCCURRENCE OF REGEX '\/.*=(.*)' IN tabname
           SUBMATCHES DATA(raw_type).

I know some people find them daunting, but once you mastered them it's quite a powerful tool in your toolbox.

Regards Christian

0 Kudos
302

Christian Guenter wrote:

Hi Ralf,

may i suggest you another solution?

Only, if the result is ONE coding line

0 Kudos
302
rv_name = substring_after( val = tab_name regex = '=' ).

JNN

0 Kudos
302

bing bing bing - you won!

Thanks, I didn't know "substring after" at all!

0 Kudos
302

Time to have a look at predefined functions ...

0 Kudos
302

DEMO_REGEX_TOY ...

0 Kudos
302

Good and simple.

Remark (in all modesty): I would use sub = `=` instead of regex = `=`, since I tend to avoid huge engines if not needed.

0 Kudos
302

Could also use:

REPLACE '/TYPE=' in tabname WITH ''.

former_member183073
Active Participant
0 Kudos
302

result_tab TYPE LINE OF match_result_tab


FIND FIRST OCCURRENCE OF '=' in tabname RESULTS result_tab.

result_tab-offset = result_tab-offset + 1.

SHIFT tabname LEFT BY result_tab-offset PLACES.

glensimpson
Explorer
0 Kudos
302

Hi Ralf

I'm a bit late to the party here but... can't you just use method GET_RELATIVE_NAME instead of attribute ABSOLUTE_NAME? The method already strips the '/TYPE=' part for you.

Regards

Glen

0 Kudos
302

That's definitively the best solution!

0 Kudos
302

Similar to the OP, I too tried to build my own solution using RegEx but then GET_RELATIVE_NAME( ) caught my eye

0 Kudos
302

Glen Simpson wrote:

Hi Ralf

I'm a bit late to the party here but... can't you just use method GET_RELATIVE_NAME instead of attribute ABSOLUTE_NAME? The method already strips the '/TYPE=' part for you.

Regards

Glen

I tried this, but I got some cases, which does not work. Don't ask me, which cases, it's month ago...