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

SPLIT command causes trouble

Former Member
0 Likes
1,015

Hi,

I have a scenario where I have a fieldlist (individual fieldnames separated by blanks, like 'KUNNR BUKRS ERDAT ERNAM ... ').

This fieldlist is split using SPLIT AT ' ', the results are appended to an internal table, one line for every fieldname.

I can only guess, but what happens is, the word ERDAT in that fieldlist is truncated to ERD and the one directly behind it, ERNAM, is left out altogether - I guess that is because of the form of the command, >> SPLIT AT ' ' <<.

Does anyone know this problem and why it happens and how I can fix it?

Thanks a lot!

Regards,

Sapperdapper

7 REPLIES 7
Read only

RaymondGiuseppi
Active Contributor
0 Likes
969

Try to code like

CONDENSE input.

SPLIT input AT space INTO TABLE itab IN CHARACTER MODE.

Regards,
Raymond

Read only

alex_campbell
Contributor
0 Likes
969

How long is the fieldname character string? Are we talking about tens of characters or thousands? Also I hate to ask such a simple question but you're sure that your fieldname character string has all of the characters you think it does?

Read only

Former Member
0 Likes
969

can you please post your exact code snippet?

Read only

0 Likes
969

Hi all,

first of all, thanks for all the help!

@ Alex

Yes, I'm sure the field_names the user inputs are valid (only real, existing SAP DB tables and fields). I'm not sure what you mean about the characters, but the words (they're only words at that stage I presume) are all complete.

@ Yogesh,

Sure I can post my code. The scenario is: I have an example - I need something to work on - with four tables and I have variables Fields1 to Fields4 from one of my dialogs, each being a string and going like this:

- Fields1: 'KUNNR BUKRS GJAHR UM01U ' "Tab1 is KNC1

- Fields2: 'AKONT ' "Tab2 is KNB1

- Fields3: 'KUNNR NAME1 NAME2 ORT01 ERDAT ERNAM ' "Tab3 is KNA1

- Fields4: 'BUTXT WAERS' "Tab4 is T001

I then do the following:

CONCATENATE Fields1 ` ` Fields2 ` ` Fields3 ` ` Fields4 INTO FieldsT.

CONDENSE FieldsT.

* We are now going to use a SPLIT functionality to split this fieldlist

* apart into individual field_names. The result of this SPLIT will be

* saved into the lines of an internal table which, of course, we have

* to declare beforehand.

TYPES: BEGIN OF res_line_type,

       Fieldname TYPE C LENGTH 10,

       END OF res_line_type.

TYPES SPLIT_tab_type TYPE STANDARD TABLE OF res_line_type.

DATA SPLIT_tab TYPE SPLIT_tab_type.

DATA wa_SPLIT TYPE res_line_type.

* Here comes the actual SPLIT command, splitting the fieldlists

* at the separating BLANKs.

SPLIT FieldsT AT ' ' INTO TABLE SPLIT_tab.

You see, what I do (or what I indent to do) is, I concatenate all four fieldlists into one, I use CONDENSE to get rid of blanks at the very beginning and the very end and then I split the whole thing into this table, one row per field_name.

One possible weakness of this approach is, when the user enters two or three blanks inbetween two field_names, I'll end up with a blank line in that table which will wreak havoc in the program.

For some reason, this SPLIT command, as I have said earlier, truncates the fieldname 'ERDAT' to 'ERD' and subsequently ignores the fieldname 'ERNAM', continuing with 'BUTXT' which then of course is in the wrong position and screws up the subsequent processing loop.

@ Raymond,

I will try this alternative code and see if it works.

Thanks again!

Best regards,

Sapperdapper

Read only

former_member194152
Contributor
0 Likes
969

Hi,

Can you change separator in your code from space to

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB and check, try below code if it works for you?

REPORT YTEST.
data temp type String.
data : begin of lt_split OCCURS 0,
         field type char50,
        end of lt_split.
CONCATENATE 'Field1' 'Field2' 'Field3' INTO temp SEPARATED BY
CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
split temp at
CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
INTO TABLE lt_split.
loop at lt_split.
  write : / lt_split-field.
endloop.

Regards,

Gagan

Read only

0 Likes
969

Hi Gagan,

no, unfortunately that did not solve my problem - in the opposite, that did not generate a nice table at all whereas using either >SPLIT AT space< or >SPLIT AT ` `< do - but then I still have the same problem.

@ Raymond

I tried the option IN CHARACTER MODE, but that did not seem to make any difference either.

I will try stopping the loop at the third execution and see what becomes of the corresponding fieldlist.

Best regards,

Sapperdapper

P.S.: Hmm... there seems to be something wrong with my parameter: The parameter where Fields3 (the fieldlist for the third table) comes from is defined as PARAMETERS Fields3 TYPE C LENGTH 999 - but when I put a BREAK-POINT right before my loop, it is truncated, already the fieldname ERDAT becomes ERD and ERNAM is ignored. So it's no wonder this happens - my loop is actually working fine, but it gets incomplete input.

Does this have something to do with the visible length of the field? In my selection screen (which I have defined AS WINDOW), this field is starting at position 60; I haven't defined a length for the field, but the length of the content is 999 - still the variable is truncated right where the visible field ends.

Read only

0 Likes
969

Hi all,

this issue is solved - sort of - it is no longer a requirement for myself to build selection screens, so I don't have to split anything - there is a GUI that a colleague of mine programmed and that will produce an output of two internal tables with table_names and field_names and I just have to use those.

Thanks for all the help!

Best regards,

Sapperdapper