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: 

Add table lines to a string including the null values.

former_member300258
Participant
0 Kudos

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.

1 ACCEPTED SOLUTION
12 REPLIES 12

Sandra_Rossi
Active Contributor
0 Kudos

CONCATENATE charfield1 charfield2 charfield3 INTO result RESPECTING BLANKS SEPARATED BY '|'

0 Kudos

Thanks for the reply Horst. I tried but no luck.

0 Kudos

'Respecting blanks' addition in concatenate statement will work. It will add the space.

0 Kudos
Try again:
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   `.

horst_keller
Product and Topic Expert
Product and Topic Expert

Not a question of luck ...

matt
Active Contributor

"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.

0 Kudos

Respecting blanks works.

0 Kudos

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.

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.

Sandra_Rossi
Active Contributor
0 Kudos

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.

former_member300258
Participant
0 Kudos

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.