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

splitting the value into 2 variables

Former Member
0 Likes
751

Hi all,

i've an internal table with following entry.

xx123

xx231

xy546

xy987

i need to seperate into 2 variables and put in different internal table how to do this

var1 = xx var2 123

var1 = xx var2 231

var1 = xy var

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
720

Hi,

If the length of the value is fixed you can split the value as below.

var1 = value+0(2).

var2 = value+2(3).

thanks,

sudheer

3 REPLIES 3
Read only

Former Member
0 Likes
721

Hi,

If the length of the value is fixed you can split the value as below.

var1 = value+0(2).

var2 = value+2(3).

thanks,

sudheer

Read only

former_member386202
Active Contributor
0 Likes
720

Hi,

Do like this

Loop at itab into wa.

wa1-var1 = wa-f1+0(2) -


>XX

wa1-var2 = wa-f1+2(3) -


>123

Append wa1 to itab1.

endloop.

Regards,

Prashant

Read only

MarcinPciak
Active Contributor
0 Likes
720

As long as you are working with flat character-type structured table this is easy


TYPES t_field TYPE c LENGTH 5.

DATA gt_in TYPE TABLE OF t_field WITH HEADER LINE.
APPEND: 'xx123' TO gt_in,
        'xx231' TO gt_in,
        'xy546' TO gt_in,
        'xy987' TO gt_in.

TYPES: BEGIN OF t_out,
        field TYPE c LENGTH 2,
        field2 TYPE c LENGTH 3,
       END OF t_out.
DATA: gt_out TYPE TABLE OF t_out.

FIELD-SYMBOLS <out_tab> TYPE t_out.

LOOP AT gt_in.
  ASSIGN gt_in TO <out_tab> CASTING.
  APPEND <out_tab> TO gt_out.
ENDLOOP.

Please note! Such casting is however not possible in Unicode system if source structure (line type of table GT_IN) has X type or is deep one. Otherwise you can have any target structure assuming the length of both is the same and components are mappable (are of character type too).

Regards

Marcin