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

truncate strings

Former Member
0 Likes
577

hi all...

i have strings in the follwing form...

adf_er_t_<b>xxxx.dat</b>

ad_effr_tru_<b>xxx.dat</b>

ad_er_tr_<b>yxxx.dat</b>

adf_ff_er_tr_<b>xy.dat</b>

ttf_er_tr_<b>xy.dat</b>

i want to remove the last part of the string....and required first part which is table name...

plz help

Message was edited by: Madan Gopal Sharma

Message was edited by: Madan Gopal Sharma

4 REPLIES 4
Read only

Former Member
0 Likes
518

Hi Madan,

Uee the FM SO_SPLIT_FILE_AND_PATH to get the file name.

Alternatively you can use SPLIT AT 'tr_' in ur case.

SPLIT w_var1 AT 'tr_' into w_var2 w_var3

Hope this helps

CHeers

VJ

Message was edited by: Vijayendra Rao

Read only

Former Member
0 Likes
518

Madan,

You need to have a common character for all the file names for delimiting. In the data you have given its not like that.

SEARCH String for 'DELIM'.

IF SY-SUBRC = 0.

W_POSITION = SY-FDPOS

ELSE.

EXIT.

ENDIF.

Path = String+0(w_position).

regards,

Ravi

Read only

Former Member
0 Likes
518

Hi Madan,

You can use this Function Module , which will completely satisfy your requirement.

It is CV120_SPLIT_FILE.

Check this code.

REPORT ZTEST_SHAIL3 .

data: file_name type DRAW-FILEP,

ext(4) type c.

CALL FUNCTION 'CV120_SPLIT_FILE'

EXPORTING

pf_file = 'hello.txt'

IMPORTING

PFX_FILE = file_name

PFX_EXTENSION = ext

  • PFX_DOTEXTENSION =

.

Regards,

SP.

Read only

Former Member
0 Likes
518

Hi madan,

1. for your requirement,

i have made in independent FORM

in which we pass the string eg.adf_er_t_xxxx.dat

and it returns

<b>adf_er_t</b>

2. there is also a selection screen for testing purpose.

3. just copy paste in new program.

4.

report abc.

*----


data : tabname(30) type c.

*----


parameters : a(50) type c DEFAULT 'adf_er_t_xxxx.dat'.

*----


START-OF-SELECTION.

perform getmydata using a CHANGING TABNAME.

WRITE 😕 TABNAME.

*----


  • INDEPENDENT FORM

*----


form getmydata using pstr changing tabname.

DATA : N TYPE I.

DATA : M TYPE I.

data : begin of itab occurs 0,

f(15) type c,

end of itab.

split PSTR at '_' into table itab.

CLEAR TABNAME.

DESCRIBE TABLE ITAB LINES N.

M = N - 2.

LOOP AT ITAB.

IF SY-TABIX <= M.

CONCATENATE ITAB-F '_' INTO ITAB-F.

MODIFY ITAB.

ENDIF.

ENDLOOP.

LOOP AT ITAB.

IF SY-TABIX < N.

CONCATENATE TABNAME ITAB-F INTO TABNAME.

ENDIF.

ENDLOOP.

endform. "

regards,

amit m.