Application Development 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: 

how to split a complex string

manish_malakar0316
Active Participant
0 Kudos
721

capture.png

Hi Experts,

I have a string which is separated by comma. However, I cannot use the SPLIT statement as the comma is used in denoting amounts as well, for e.g. "123,456,000" and also they are enclosed within quotes (please refer to the attachment). So when there are no values, they are filled with zero and separated by commas. But when there are values, it becomes complex to separate them and store them in an internal table in their respective columns. Any idea how it can be done ?

My internal table is declared as follows and I have to strore them inside the fields declared.

Regards,

Manish

BEGIN OF ty_interest_calc,<br>          date(10),<br>          fund_name(50),<br>          cusip_isin(15),<br>          acnt_no(10),<br>          div_rate(13),<br>          ded_rate(13),<br>          daily_div(13),<br>          mtd_div(10),<br>          position_local(12),<br>          fx_rate(1),<br>          position_usd(12),<br>          nav(1),<br>          shares(12),<br>          acnt_name(50),<br>          curr(3),<br>          company_name(20),<br>          tax_id(10),<br>        END OF ty_interest_calc.<br>
1 ACCEPTED SOLUTION

Tomas_Buryanek
Active Contributor
666

This looks like normal CSV format.

Try cl_rsda_csv_converter to read data from the string to your structure. There are many examples how to use this class 🙂

-- Tomas --
7 REPLIES 7

Tomas_Buryanek
Active Contributor
667

This looks like normal CSV format.

Try cl_rsda_csv_converter to read data from the string to your structure. There are many examples how to use this class 🙂

-- Tomas --

666

tomas.buryanek

Thanks for the tip with the class, Tomas! It might come in handy in the future!

Cheers

Bärbel

666

8b889d0e8e6f4ed39f6c58e35664518f You are welcome 🙂

By the way, I used this class quite many times already, and it was always helpful and without a problem.

-- Tomas --

666

Thanks Tomas...this was the correct solution !

Sandra_Rossi
Active Contributor
0 Kudos
666

Be careful to <br> tags in the code you posted. You may fix it via Actions > Edit. This is correct formatting:

TYPES : BEGIN OF ty_interest_calc,
          date(10),
          fund_name(50),
          cusip_isin(15),
          acnt_no(10),
          div_rate(13),
          ded_rate(13),
          daily_div(13),
          mtd_div(10),
          position_local(12),
          fx_rate(1),
          position_usd(12),
          nav(1),
          shares(12),
          acnt_name(50),
          curr(3),
          company_name(20),
          tax_id(10),
        END OF ty_interest_calc.

Sandra_Rossi
Active Contributor
0 Kudos
666

Also, you can show the image directly in your question (with just copy/paste)

BaerbelWinkler
Active Contributor
0 Kudos
666

manish.malakar0316

Hi Manish!

Do you have control over the string format and/or can request a change from "," to something rarely used in field content like e.g. "|"? This would be a lot easier than trying to wrestle with the variable nature of where a comma can show up.

A comma or even semi-colon are rarely a good option to use as a field delimiter because they tend to show up in user entered content or numbers as in your case.

Cheers

Bärbel