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

string

Former Member
0 Likes
948

Hi friends,

I need a piece of code for finding out the last three character in a string.

The string contains the path with file name. i need to fetch the file name extension only.

please suggest me the code for the above

thanks in advance

sai

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
889

use split statement to achieve it will work.

SPLIT File AT . INTO fil ext.

8 REPLIES 8
Read only

Former Member
0 Likes
890

use split statement to achieve it will work.

SPLIT File AT . INTO fil ext.

Read only

Former Member
0 Likes
889

Hi ,

first u need to find out length of the string

n = strlen(string).

n = n - 3.

now by using offset lengths u can get it

file = string+n(3).

regards

Prabhu

Read only

Former Member
0 Likes
889

Hi

Search for '.' in the string and than you take sy-fdpos, which will give the character position and from that take 3 position.

for example

data : l_temp_string.

l_string : c:\new\temp\create.doc

search for '.' in the string l_string.

l_temp_string = l_string+sy-fdpos(3).

I think this should work

Regards

MD

Read only

Former Member
0 Likes
889

Hi,

RIGHT(@SHORT_TEXT,3)

Displays the last three characters of the string. For example, a value of FINALCOST would be displayed as OST.

Hope that helps.

Regards,

Surinder

Read only

Former Member
0 Likes
889

Hi Sai,

Try this:

w_strlen = strlen( w_str1 ).

w_offset = w_strlen - 3.

w_str2 = w_str1+ w_offset(3).

write: / w_str2.

Regards,

Chandra Sekhar

Read only

Former Member
0 Likes
889

Hi,

You can split the string at a delimiter here '.' (dot). eg is

DATA: string(60) TYPE c,

p1(20) TYPE c,

p2(20) TYPE c,

del(1) TYPE c VALUE '.'. (delimiter)

string = ' filename.ext'.

SPLIT string AT del INTO p1 p2.

It will split the string. put your filename into p1 and your extension into p2.

Then you can read p2 and know your file extension.

I hope it will help.

regards

Natasha Garg

Read only

Former Member
0 Likes
889

hello sai, here im sending a code with this u can get the extension.

DATA: PATH TYPE STRING VALUE 'C:\Documents and Settings\prakashreddys\Desktop\VA01.TXT'.

DATA: LENGTH TYPE I.

DATA: EXTEN(3) TYPE C.

DATA: COUNT TYPE STRING.

LENGTH = STRLEN( PATH ).

WRITE: LENGTH.

COUNT = LENGTH - 3.

EXTEN = PATH+COUNT(3).

WRITE: / EXTEN.

Read only

0 Likes
889

Hello,

i am working in SAP BI and i have a very similar problem. The point is that i have never programmed in ABAP so I hope someone can help me in that matter. In the SAP Source-Sytem from where I am extracting the data there is a field with the name ZZFILE_NAME. The content of this field is for example the following data:

Example 1: u201C/home_dev/x11/Electricidad/0024/Alta/A1/0024_A1_01_01_20080522_ES0031406938784737AY0F_200800000001.xmlu201D

or

*Example 2:*u201C/home_dev/x11/Gas/No_GND/0230/A1_SCTD_GC_0031_0230_02_20080526_100721.xmlu201D

I just need to import into the Business Warehouse System the content of the data after the last slash. So in the case of the example I need just:

Example 1:

u201C0024_A1_01_01_20080522_ES0031406938784737AY0F_200800000001.xmlu201D

or

Example 2:

u201CA1_SCTD_GC_0031_0230_02_20080526_100721.xmlu201D

The transfer-Routine actually is like the following code. What do I have to change there?

PROGRAM trans_routine.

----


  • CLASS routine DEFINITION

----


*

----


CLASS lcl_transform DEFINITION.

PUBLIC SECTION.

  • Attributs

DATA:

p_check_master_data_exist

TYPE RSODSOCHECKONLY READ-ONLY,

*- Instance for getting request runtime attributs;

  • Available information: Refer to methods of

  • interface 'if_rsbk_request_admintab_view'

p_r_request

TYPE REF TO if_rsbk_request_admintab_view READ-ONLY.

PRIVATE SECTION.

TYPE-POOLS: rsd, rstr.

  • Rule specific types

TYPES:

BEGIN OF tys_SC_1,

  • Field: ZZFILE_NAME File URL.

ZZFILE_NAME TYPE C LENGTH 255,

  • Field: RECORD.

RECORD TYPE RSARECORD,

END OF tys_SC_1.

TYPES:

BEGIN OF tys_TG_1,

  • InfoObject: ZCSWFILEN NOMBRE FICHERO XML MENSAJE.

/BIC/ZCSWFILEN TYPE /BIC/OIZCSWFILEN,

END OF tys_TG_1.

$$ begin of global - insert your declaration only below this line -

... "insert your code here

$$ end of global - insert your declaration only before this line -

METHODS

compute_ZCSWFILEN

IMPORTING

request type rsrequest

datapackid type rsdatapid

SOURCE_FIELDS type tys_SC_1

EXPORTING

RESULT type tys_TG_1-/BIC/ZCSWFILEN

monitor type rstr_ty_t_monitor

RAISING

cx_rsrout_abort

cx_rsrout_skip_record

cx_rsrout_skip_val.

METHODS

invert_ZCSWFILEN

IMPORTING

i_th_fields_outbound TYPE rstran_t_field_inv

i_r_selset_outbound TYPE REF TO cl_rsmds_set

i_is_main_selection TYPE rs_bool

i_r_selset_outbound_complete TYPE REF TO cl_rsmds_set

i_r_universe_inbound TYPE REF TO cl_rsmds_universe

CHANGING

c_th_fields_inbound TYPE rstran_t_field_inv

c_r_selset_inbound TYPE REF TO cl_rsmds_set

c_exact TYPE rs_bool.

ENDCLASS. "routine DEFINITION

$$ begin of 2nd part global - insert your code only below this line *

... "insert your code here

$$ end of 2nd part global - insert your code only before this line *

----


  • CLASS routine IMPLEMENTATION

----


*

----


CLASS lcl_transform IMPLEMENTATION.

METHOD compute_ZCSWFILEN.

  • IMPORTING

  • request type rsrequest

  • datapackid type rsdatapid

  • SOURCE_FIELDS-ZZFILE_NAME TYPE C LENGTH 000255

  • EXPORTING

  • RESULT type tys_TG_1-/BIC/ZCSWFILEN

DATA:

MONITOR_REC TYPE rsmonitor.

*$*$ begin of routine - insert your code only below this line *-*

... "insert your code here

*-- fill table "MONITOR" with values of structure "MONITOR_REC"

*- to make monitor entries

... "to cancel the update process

  • raise exception type CX_RSROUT_ABORT.

... "to skip a record

  • raise exception type CX_RSROUT_SKIP_RECORD.

... "to clear target fields

  • raise exception type CX_RSROUT_SKIP_VAL.

RESULT = .

$$ end of routine - insert your code only before this line -

ENDMETHOD. "compute_ZCSWFILEN

----


  • Method invert_ZCSWFILEN

----


*

  • This subroutine needs to be implemented only for direct access

  • (for better performance) and for the Report/Report Interface

  • (drill through).

  • The inverse routine should transform a projection and

  • a selection for the target to a projection and a selection

  • for the source, respectively.

  • If the implementation remains empty all fields are filled and

  • all values are selected.

*

----


*

----


METHOD invert_ZCSWFILEN.

$$ begin of inverse routine - insert your code only below this line-

... "insert your code here

$$ end of inverse routine - insert your code only before this line -

ENDMETHOD. "invert_ZCSWFILEN

ENDCLASS. "routine IMPLEMENTATION