Skip to Content
-2

Add table lines to a string including the null values.

Nov 06, 2017 at 03:41 PM

89

avatar image
Former Member

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.

10 |10000 characters needed characters left characters exceeded

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.

0
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Horst Keller
Nov 06, 2017 at 04:40 PM
2
Show 8 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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

0
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   `.
0

Not a question of luck ...

1

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

1
Former Member

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

0

Respecting blanks works.

m6bdp.png (8.6 kB)
iguts.png (916 B)
0
Former Member

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.

capture.jpg (43.2 kB)
capture.jpg (13.8 kB)
0
Former Member

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.
1
avatar image
Former Member Nov 07, 2017 at 03:47 PM
0

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.

Share
10 |10000 characters needed characters left characters exceeded