Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Logic Required

Hi,

TYPES:BEGIN OF t_test,

am1 TYPE DMBTR,

am2 TYPE DMBTR,

typ TYPE CHAR2,

pe1 TYPE P DECIMALS 2,

pe2 TYPE P DECIMALS 2,

END OF t_test.

DATA:it_test TYPE TABLE OF t_test.

DATA:wa_test LIKE LINE OF it_test.

wa_test-am1 = '110'.

wa_test-am2 = '190'.

wa_test-typ = 'SE'.

wa_test-pe1 = '12'.

wa_test-pe2 = '14'.

APPEND wa_test TO it_test.

CLEAR wa_test.

wa_test-am1 = '110'.

wa_test-am2 = '190'.

wa_test-typ = 'SE'.

wa_test-pe1 = '12'.

wa_test-pe2 = '14'.

APPEND wa_test TO it_test.

CLEAR wa_test.

wa_test-am1 = '100'.

wa_test-am2 = '240'.

wa_test-typ = 'SR'.

wa_test-pe1 = '12'.

wa_test-pe2 = '14'.

APPEND wa_test TO it_test.

CLEAR wa_test.

wa_test-am1 = '100'.

wa_test-am2 = '240'.

wa_test-typ = 'SR'.

wa_test-pe1 = '12'.

wa_test-pe2 = '14'.

APPEND wa_test TO it_test.

CLEAR wa_test.

wa_test-am1 = '10'.

wa_test-am2 = '120'.

wa_test-typ = 'HR'.

wa_test-pe1 = '12'.

wa_test-pe2 = '14'.

APPEND wa_test TO it_test.

CLEAR wa_test.

wa_test-am1 = '10'.

wa_test-am2 = '120'.

wa_test-typ = 'HR'.

wa_test-pe1 = '12'.

wa_test-pe2 = '14'.

APPEND wa_test TO it_test.

CLEAR wa_test.

I want the output like this in the internal table.

220 380 SE 12 14

200 480 SR 12 14

20 240 HR 12 14

Here in this internal table only 2 amount fields and 2 Rate fields are there. But in my original ionternal table nearly 30 amount fields and 20 Rate fields are there. Could you please help me with logic?

Tags:
Former Member
Former Member replied

Hi,

please find the below code

TYPES:BEGIN OF t_test,

am1 TYPE DMBTR,

am2 TYPE DMBTR,

typ TYPE CHAR2,

pe1 TYPE P DECIMALS 2,

pe2 TYPE P DECIMALS 2,

END OF t_test.

DATA:it_test TYPE TABLE OF t_test,

it_test1 TYPE TABLE OF t_test.

DATA:wa_test LIKE LINE OF it_test,

wa_test1 LIKE LINE OF it_test.

wa_test-am1 = '110'.

wa_test-am2 = '190'.

wa_test-typ = 'SE'.

wa_test-pe1 = '12'.

wa_test-pe2 = '14'.

APPEND wa_test TO it_test.

CLEAR wa_test.

wa_test-am1 = '110'.

wa_test-am2 = '190'.

wa_test-typ = 'SE'.

wa_test-pe1 = '12'.

wa_test-pe2 = '14'.

APPEND wa_test TO it_test.

CLEAR wa_test.

wa_test-am1 = '100'.

wa_test-am2 = '240'.

wa_test-typ = 'SR'.

wa_test-pe1 = '12'.

wa_test-pe2 = '14'.

APPEND wa_test TO it_test.

CLEAR wa_test.

wa_test-am1 = '100'.

wa_test-am2 = '240'.

wa_test-typ = 'SR'.

wa_test-pe1 = '12'.

wa_test-pe2 = '14'.

APPEND wa_test TO it_test.

CLEAR wa_test.

wa_test-am1 = '10'.

wa_test-am2 = '120'.

wa_test-typ = 'HR'.

wa_test-pe1 = '12'.

wa_test-pe2 = '14'.

APPEND wa_test TO it_test.

CLEAR wa_test.

wa_test-am1 = '10'.

wa_test-am2 = '120'.

wa_test-typ = 'HR'.

wa_test-pe1 = '12'.

wa_test-pe2 = '14'.

APPEND wa_test TO it_test.

CLEAR wa_test.

sort it_test by typ.

loop at it_test into wa_test.

read table it_test1 into wa_test1 with key typ = wa_test-typ.

if sy-subrc ne 0.

move-corresponding wa_test to wa_test1.

append wa_test1 to it_test1.

else.

clear: wa_test-pe1,

wa_test-pe2.

collect wa_test into it_test1.

endif.

endloop.

loop at it_test1 into wa_test1.

write:/ wa_test1-am1,wa_test1-am2,wa_test1-typ,wa_test1-pe1,wa_test1-pe2.

endloop.

Regards,

Suresh.

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question