cancel
Showing results for 
Search instead for 
Did you mean: 

Extract characters right of hyphen

charla_robertson
Participant
0 Kudos

Hi all,

I'm trying to extract data from a field that contains hyphens. I want the data to the right of the hyphen only. This data can be different lengths.

Sample data:

0105-GROC

0890-PHARMA

In the above samples, I want to extract GROC in the first, PHARMA in the second.

Any suggestions?

Thanks

Charla

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

If the no of characters to theleft is constant, then you can use offset to trim them off and get only the chars to the right of hypen.

Ravi Thothadri

charla_robertson
Participant
0 Kudos

Unfortunately, the number of characters to the left is not consistent.

Another sample of data:

RETAIL-OVH --> where I want to extract OVH

Thanks

Former Member
0 Kudos

Hi Charla,

In that case you need to do some coding to select the fields.

Regards.

charla_robertson
Participant
0 Kudos

I've started the coding already in the transfer rules, it is as follows:

if sy-subrc = 0.

SPLIT l_proctrgr AT '-' INTO table itab.

LOOP at ITAB.

WRITE ITAB.

ENDLOOP.

RESULT = itab.

endif.

Although, the field is coming through blank. Not sure why...

Thanks

Former Member
0 Kudos

Hi Charla,

Try like this.

DATA: str1 TYPE string, 
      str2 TYPE string.

SPLIT l_proctrgr AT '-' INTO: str1 str2.

If sy-subrc = 0.
       RESULT = str2.
endif.

Regards.

charla_robertson
Participant
0 Kudos

I've tried that example and the field is still coming in blank.

Thanks

Charla

Former Member
0 Kudos

Hi Charla,

Try to debug your load and see where it is failing.

Else use TRAN_STRUCTURE-FIELDNAME

like

DATA: str1 TYPE string,

str2 TYPE string.

SPLIT TRAN_STRUCTURE-<field_name> AT '-' INTO: str1 str2.

If sy-subrc = 0.

RESULT = str2.

endif.

Regards.

Former Member
0 Kudos

Hello Charla,

Try this one. The syntax given above is wrong because of the ":".


DATA: leftstr TYPE string, 
           rightstr TYPE string.

* Please replace <your field here with the field from your trans structure> 
SPLIT trans_structure-<your field here> AT '-' INTO leftstr rightstr.
 
RESULT = rightstr.

Hope this helps.

Answers (1)

Answers (1)

Former Member
0 Kudos

You must be secure that your transfer rules are activated....

And Check if theres any initial routine that could filter some values.....

Regards