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

ABAP STRING OPERATIONS

Former Member
0 Likes
2,067

What is the ABAP code to find characters of a string after the forward slash(/) ?

For eg : USER/SAP/ABC.CSV

How to retrive ABC.CSV which is after /.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,448

Hi Saikanth,

1.Use FM PC_SPLIT_COMPLETE_FILENAME

 

2. By giving the full path to the FM,

   we get

   a) file name (only file name)

   b) also we can get the extension separately in other parameter

7 REPLIES 7
Read only

jitendra_it
Active Contributor
0 Likes
1,448

Hello Saikanth,

you can use FM SO_SPLIT_FILE_AND_PATH.

But this FM works with \ only so first you can replace / with \ in string using REPLACE ALL

then that FM.

Read only

Former Member
0 Likes
1,448

Please first search for related post before posting, very basic question.

v_str = 'USER/SAP/ABC.CSV'.

split v_str AT '\' into table it_result.

loop at it_result into wa_result.

if wa_result CS '.'.

v_mystr = wa_result.

endif.

Read only

pavanm592
Contributor
0 Likes
1,448

Hi Saikanth,

DATA: str1 TYPE string,

       str2 TYPE string,

       str3 TYPE string,

       itab TYPE TABLE OF string,

       text TYPE string.

   text = 'USER/SAP/ABC.CSV'.

SPLIT text AT '/' INTO: str1 str2 str3,

                           TABLE itab.


Regards,

Pavan

Read only

Former Member
0 Likes
1,449

Hi Saikanth,

1.Use FM PC_SPLIT_COMPLETE_FILENAME

 

2. By giving the full path to the FM,

   we get

   a) file name (only file name)

   b) also we can get the extension separately in other parameter

Read only

0 Likes
1,448

Hi Saikanth,

     Use this FM: SPLIT_FILENAME

This FM takes care of both the '\' and '/'.

SAP has provided most of these utility functionalities our of box, so reuse those rather than doing string operation on your own.

Regards,

Tashi

Read only

Former Member
0 Likes
1,448

Thank you all for ur responses...

really helpful....

Read only

Former Member
0 Likes
1,448

HI Sai,

Use the Following Code:

DATA :   G_FILE          TYPE STRING,

               G_EXTENSION         TYPE STRING,
              G_FILE_EXT          TYPE CHAR255.

CALL FUNCTION 'CH_SPLIT_FILENAME'
      EXPORTING
        complete_filename = g_file " Your File Name
      IMPORTING
        extension         = g_extension
        name_with_ext     = g_file_ext
      EXCEPTIONS
        invalid_drive     = 1
        invalid_path      = 2
        OTHERS            = 3.

Thanks And Regards

Mohit