‎2012 Apr 19 3:51 PM
Dear All,
I had a unique requirement. Where i need to fill the data in a field of type string.
The requirement is as follows. I have a list of fields i need to fill all these fields in a string field, such that
FIELD1(8) = '00001234'
FIELD2(10) = 'abcdefghij'.
FIELD3(20) = '1234abcd4567efgh8901'.
In FIELD_STRING
FIELD1 occupy 0 to 7 Char and from 8 to 15 Char it should be SPACE and FIELD2 should occupy from 16 to 25 and 26 to 30 Char should be SPACE and FIELD3 should occupy from 31 to 50 Char.
FIELD_STRING = '00001234 abcdefghij 1234abcd4567efgh8901'.
I tried using the CONCATENATING syntax but i couldn't able to full fill this, especially the different character of spaces in between of fields.. could any one suggest the better option.
Regards,
NSK
‎2012 Apr 19 3:56 PM
Try to create a local structure (DATA: BEGIN OF xxx, FIELD1 TYPE C 8, DUMMY TYPE C 8, etc. END OF xxx.) Then move the fields in the subfields of the structure, also you won't get annoyed by Unicode this way. (Offset/length specifications in Unicode programs.)
Regards,
Raymond
‎2012 Apr 19 4:00 PM
Hi Shashikanth ,
One possible solution wold be to defined a variable of length 50 , as i assume the length of your final string is 50 . Move the required string at the correct places in the new variable and once you are done ,finally move the value of new variable to the string e.g.
----------------------------------------------------
Data : one type string ,
THREE TYPE CHAR50 ,
two type char10 .
TWO = 'AAAAAAAAAA'.
THREE+4(10) = TWO.
ONE = THREE.
------------------------------------------------
Regards
Arun
‎2012 Apr 19 4:09 PM
Hi,
Try the below code.
DATA : Field1(15) TYPE c,
field2(15) TYPE c,
field3(20) TYPE c.
DATA: FIELD_STRING TYPE String.
FIELD1 = '00001234'.
FIELD2 = 'abcdefghij'.
FIELD3 = '1234abcd4567efgh8901'.
CONCATENATE field1 field2 field3 INTO field_string RESPECTING BLANKS.
Thanks,
Chitra.
‎2012 Apr 19 5:02 PM
Check the attached program I created for some other thread. See if it is helpful to you.
‎2012 Apr 26 11:50 AM
Try following example :
data : FIELD1(8) type c value '00001234',
FIELD2(10) type c value 'abcdefghij',
FIELD3(20) type c value '1234abcd4567efgh8901',
sp1(8) type c,
sp(6) type c.
DATA: FIELD_STRING TYPE String.
CONCATENATE field1 sp1 field2 sp field3 INTO field_string RESPECTING BLANKS.
write field_string.
‎2012 Apr 26 12:07 PM
Hi,
The following steps should give u desired result.
When using CONCATENATE option for fields, write single quotations without space between all the fields. Then keep cursor between two quotations and press ALT + 255. U will get a space. This space will occupy a space between two fields.
CONCATENATE field1 '' field2 '' field3 into string.
‎2012 Apr 26 12:19 PM
You can use structure.
TYPES : begin of line,
string1(8) type c,
string2(10) type c,
filler(1) type c,
string3(20) type c,
end of line.
data : w_line type line.
DATA : Field1(15) TYPE c,
field2(15) TYPE c,
field3(20) TYPE c.
DATA: string TYPE String.
FIELD1 = '00001234'.
FIELD2 = 'abcdefghij'.
FIELD3 = '1234abcd4567efgh8901'.
clear w_line.
w_line-string1 = FIELD1.
w_line-string2 = FIELD2.
w_line-string3 = FIELD3.
Move w_line to string.
Write string.