11-27-2015 1:50 PM
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?
11-27-2015 2:41 PM
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
11-27-2015 2:41 PM
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
11-27-2015 2:48 PM
Christian Guenter wrote:
Hi Ralf,
may i suggest you another solution?
Only, if the result is ONE coding line
11-27-2015 4:26 PM
11-27-2015 4:30 PM
bing bing bing - you won!
Thanks, I didn't know "substring after" at all!
11-27-2015 5:34 PM
11-27-2015 5:44 PM
11-30-2015 10:32 AM
Good and simple.
Remark (in all modesty): I would use sub = `=` instead of regex = `=`, since I tend to avoid huge engines if not needed.
12-02-2015 9:46 PM
11-27-2015 2:42 PM
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.
11-29-2015 10:13 PM
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
11-30-2015 10:23 AM
11-30-2015 12:25 PM
Similar to the OP, I too tried to build my own solution using RegEx but then GET_RELATIVE_NAME( ) caught my eye
11-30-2015 12:48 PM
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...