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

Simple yet complicated

Former Member
0 Likes
299

HI Guys!!

I need some extraordinary logic here...

Hope you can share yours..

scenario::

I have 2 fields:

field1 field2

1 a

2 b

3 c

2 d

1 a

3 e

I have two fields with respective values::

it seems simple but this is the problem.

I need to create a header wherein the value of field1 would be my first header then

the corresponding line item in field2 would be my second header. like this::

expected output::

1 2 3 <=field1 (if there are 3 same values let it be 1 avoid redundancy)

a a b d c e. <========field2 (second line corresponding values of field1 again if there are same values let it be 1 to avoid redundancy)

I dont know what kind of logic and coding would I be needing to achieve that.

I have 1 internal table w/c has field1 and field 2. everytime I sort field1 ,field2 is unsorted , vice versa.

Please experts , geeks!!ehehe..help me out!!!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
273

&----


*& Report ZTEST566 *

*& *

&----


*& *

*& *

&----


REPORT ZTEST566 .

data: begin of itb occurs 0,

f1 type i,

f2 type c,

end of itb.

data: begin of itb2 occurs 0,

f3 type i,

end of itb2.

data: begin of itb3 occurs 0,

f4 type c,

end of itb3.

itb-f1 = '1'.

itb-f2 = 'a'.

append itb.

clear itb.

itb-f1 = '2'.

itb-f2 = 'b'.

append itb.

clear itb.

itb-f1 = '3'.

itb-f2 = 'c'.

append itb.

clear itb.

itb-f1 = '2'.

itb-f2 = 'd'.

append itb.

clear itb.

itb-f1 = '1'.

itb-f2 = 'a'.

append itb.

clear itb.

itb-f1 = '3'.

itb-f2 = 'e'.

append itb.

clear itb.

data: number type i.

data: char_value(10) type c.

loop at itb.

itb2-f3 = itb-f1.

append itb2.

clear itb2.

endloop.

sort itb2 by f3.

delete adjacent duplicates from itb2 comparing f3.

loop at itb2.

write: itb2-f3.

endloop.

loop at itb2.

*read table itb with key f1 = itb2-f3.

loop at itb where f1 = itb2-f3.

itb3-f4 = itb-f2.

append itb3.

clear itb3.

endloop.

endloop.

skip.

loop at itb3.

write: itb3-f4.

endloop.

<b>Hi this logic will do.

Please reward points if it helps.</b>

Thanks

Phani

1 REPLY 1
Read only

Former Member
0 Likes
274

&----


*& Report ZTEST566 *

*& *

&----


*& *

*& *

&----


REPORT ZTEST566 .

data: begin of itb occurs 0,

f1 type i,

f2 type c,

end of itb.

data: begin of itb2 occurs 0,

f3 type i,

end of itb2.

data: begin of itb3 occurs 0,

f4 type c,

end of itb3.

itb-f1 = '1'.

itb-f2 = 'a'.

append itb.

clear itb.

itb-f1 = '2'.

itb-f2 = 'b'.

append itb.

clear itb.

itb-f1 = '3'.

itb-f2 = 'c'.

append itb.

clear itb.

itb-f1 = '2'.

itb-f2 = 'd'.

append itb.

clear itb.

itb-f1 = '1'.

itb-f2 = 'a'.

append itb.

clear itb.

itb-f1 = '3'.

itb-f2 = 'e'.

append itb.

clear itb.

data: number type i.

data: char_value(10) type c.

loop at itb.

itb2-f3 = itb-f1.

append itb2.

clear itb2.

endloop.

sort itb2 by f3.

delete adjacent duplicates from itb2 comparing f3.

loop at itb2.

write: itb2-f3.

endloop.

loop at itb2.

*read table itb with key f1 = itb2-f3.

loop at itb where f1 = itb2-f3.

itb3-f4 = itb-f2.

append itb3.

clear itb3.

endloop.

endloop.

skip.

loop at itb3.

write: itb3-f4.

endloop.

<b>Hi this logic will do.

Please reward points if it helps.</b>

Thanks

Phani