Skip to Content
avatar image
-2
Former Member

Add table lines to a string including the null values.

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Nov 06, 2017 at 04:40 PM
    Add comment
    10|10000 characters needed characters exceeded

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

    Add comment
    10|10000 characters needed characters exceeded