11-06-2017 3:41 PM
Hi Experts,
I had to ask this after I did a wide search.
I am trying to add a table line especially the values of all the key fields into a string. for example, my table has 3 key fields
MANDT | KEY1(length-5)|KEY2(length-3)
100| |10
100|10023|10
i expect to have the result as '100 10' and '1001002310'.
For the 1st entry, between value 100 and 10, i need a space of 5 characters as the length of field KEY1
I couldn't make it with the option of concatenation. is there any other easy way other than setting by offset.
Thanks in advance.
11-06-2017 4:40 PM
11-06-2017 4:38 PM
CONCATENATE charfield1 charfield2 charfield3 INTO result RESPECTING BLANKS SEPARATED BY '|'
11-06-2017 4:40 PM
11-06-2017 5:42 PM
11-07-2017 5:39 AM
'Respecting blanks' addition in concatenate statement will work. It will add the space.
11-07-2017 5:51 AM
DATA firstfield(4) VALUE 'A'.
DATA secondfield(4) VALUE 'B'.
DATA result TYPE string.
CONCATENATE firstfield secondfield INTO result RESPECTING BLANKS SEPARATED BY '|'.
ASSERT result = `A |B `.
11-07-2017 6:41 AM
11-07-2017 7:36 AM
"No luck" is not really a good description of what has not worked. What would be a good description is
What you tried.
The results you got
The results you wanted.
11-07-2017 10:42 AM
11-07-2017 1:55 PM
OK. When I used RESPECTING BLANKS, it didn't even concatenate the fields with values.
Now I am using offset to leave the space since concatenate option not working.
11-07-2017 3:07 PM
For me this has worked. But I only put the data into a string variable. Maybe something is wrong with your data declaration of 'ls_object_key'? How does it look like?
DATA: lo_struct TYPE REF TO cl_abap_structdescr,
lv_tabname TYPE tabname16,
lt_comp1 TYPE ddfields,
ls_comp1 TYPE dfies,
lv_string TYPE string,
lt_table TYPE TABLE OF [tablename],
ls_struc TYPE [tablename].
FIELD-SYMBOLS: <fs_tab> TYPE table,
<fs_struc> TYPE any,
<fs_comp>.
lv_tabname = '[tablename]'.
SELECT * FROM (lv_tabname) INTO TABLE lt_table.
ASSIGN lt_table TO <fs_tab>.
ASSIGN ls_struc TO <fs_struc>.
lo_struct ?= cl_abap_elemdescr=>describe_by_name( lv_tabname ).
lt_comp1 = lo_struct->get_ddic_field_list( ).
LOOP AT <fs_tab> INTO <fs_struc>.
LOOP AT lt_comp1 INTO ls_comp1 WHERE keyflag = 'X'.
ASSIGN COMPONENT ls_comp1-fieldname OF STRUCTURE <fs_struc> TO <fs_comp>.
CONCATENATE lv_string <fs_comp>
INTO
lv_string RESPECTING BLANKS.
ENDLOOP.
ENDLOOP.
11-07-2017 7:58 AM
The words "null value" are misleading, as it often refers to the Unicode "NULL" character U+0000.
You are of course talking about the space character.
11-07-2017 3:47 PM
Thanks Daniel. It is working now after I use a string to concatenate and move to em to ls_object_key-tabkey which is a character. Thanks to Horst as well. Closing the thread.