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

Concatenating non-character fields

Former Member
0 Likes
1,910

Hi,

I have a nested structure which I am trying to convert into a flat structure so that I can output this to a flat file.

I am trying to concatenate all the fields within my nested structure into a text field but the concatenate command does not automatically convert numerics/quantities.

An extract of my code is as follows:-

loop at itab-rec2 into wa2.

concatenate wa2-ntgew wa2-gewei wa2-volum

wa2-ean11 into text.

tlines-line = text.

append tlines.

clear text.

endloop.

Can anyone advise me on how I can convert the numeric/qty fields into a character string so I can the concatenate all the fields into a string.

Thanks,

Ruby

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,209

Hi,

concatenate is posible only for character strings

follow below logic

data lv_ntweg(17) type c

lv_gewei(17) type c

lv_vol(17) type c.

loop at itab-rec2 into wa2.

<b>lv_ntweg = wa2-ntgew

lv_gewei = wa2-gewei

lv_vol = wa2-volum .

condense :lv_ntweg,lv_vol,lv_gewei.

concatenate lv_ntweg,lv_vol,lv_gewei.

wa2-ean11 into text.</b>tlines-line = text.

append tlines.

clear text.

endloop.

Regards,

amole

Hi,

I have a nested structure which I am trying to convert into a flat structure so that I can output this to a flat file.

I am trying to concatenate all the fields within my nested structure into a text field but the concatenate command does not automatically convert numerics/quantities.

An extract of my code is as follows:-

loop at itab-rec2 into wa2.

concatenate wa2-ntgew wa2-gewei wa2-volum

wa2-ean11 into text.

tlines-line = text.

append tlines.

clear text.

endloop.

Can anyone advise me on how I can convert the numeric/qty fields into a character string so I can the concatenate all the fields into a string.

Thanks,

Ruby

5 REPLIES 5
Read only

Former Member
0 Likes
1,209

Hi,

U may create another internal table where those numeric/ quan fields will be char type including rest of the fields of internal table 1. loop at the 1st internal table then move all the fields to the 2nd internal table . And from the 2nd internal table u can try concatenate.

Pl try .

Cheers.

Read only

Former Member
0 Likes
1,210

Hi,

concatenate is posible only for character strings

follow below logic

data lv_ntweg(17) type c

lv_gewei(17) type c

lv_vol(17) type c.

loop at itab-rec2 into wa2.

<b>lv_ntweg = wa2-ntgew

lv_gewei = wa2-gewei

lv_vol = wa2-volum .

condense :lv_ntweg,lv_vol,lv_gewei.

concatenate lv_ntweg,lv_vol,lv_gewei.

wa2-ean11 into text.</b>tlines-line = text.

append tlines.

clear text.

endloop.

Regards,

amole

Read only

Former Member
0 Likes
1,209

Hi,

Create another internal table with all fields as character types. Then move all entries from the original Itab to the new one.

itab_char[] = itab_original[].

Read only

Former Member
0 Likes
1,209

U would need to write the particular data into character variables and than use concatenate.

lntgew(17) type c.

lgewei(17) type c.

write wa2-ntgew to lntgew using edit mask 'RR_________.___'.

write wa2-gewei to lgewei using edit mask 'RR_________.___'.

concatnate lntgew lgewei into text.

Read only

Clemenss
Active Contributor
0 Likes
1,209

Hi Ruby,

mybe this could help:

<pre>

data:

lv_separator type c,

lv_offset type syfdpos,

lv_len type sytleng,

lv_chars type tab512.

field-symbols:

<any> type any.

lv_separator = abap_char_utilities=>horizontal_tab.

loop at itab.

do.

assign component sy-index of structure itab to <any>.

if sy-subrc <> 0.

exit."loop

endif.

describe field <any> output length lv_len.

write <any> to lv_chars+lv_offset(lv_len).

add lv_len to lv_offset.

  • if field separator is needed add these lines

write lv_separator to lv_chars+lv_offset(1).

add 1 to lv_offset.

enddo.

transfer lv_chars to file.

clear lv_chars.

endloop." at itab.

</pre>

This will write a formatted output file but it will use the output formatting options defined for the actual user/language/system. This will determine the representation of numeric and date fields and all other fields with output conversion. That means that in the file you will have what you see on a list or grogram screen, not what you see in debugger. Fields are separated by tabulator. As all fields always are output in the same length, you may omit this part.

Regards,

Clemens