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

Populating the data in String

Former Member
0 Likes
1,296

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

7 REPLIES 7
Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,247

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

Read only

Former Member
0 Likes
1,247

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

Read only

Former Member
0 Likes
1,247

Hi,

Try the below code.

   DATA : Field1(15TYPE 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.

Read only

0 Likes
1,247

Check the attached program I created for some other thread. See if it is helpful to you.

Read only

Former Member
0 Likes
1,247

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.

Read only

Former Member
0 Likes
1,247

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.

Read only

fournier_guillaume
Discoverer
0 Likes
1,247

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(15TYPE 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.