Application Development 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: 

internal table process

Former Member
0 Kudos

Hi All,

Would like to ask the logic.

I have an internal table below. I not sure if need to have another 2 new internal table for the processing below.

Appreciate of the example of coding.

material / cost center / cost

KA1234 / 90045 / 500

KA1234 / 90045 / 120

KA5678 / 70067 / 1000

KA5678 / 70067 / 1500

KA5678 / 70067 / 200

XA1234 / 90045 / 400

XA5678 / 70067 / 2000

I need to sort and group where both material and cost center the same and cost add up.

material / cost-center / cost

KA1234 / 90045 / 620

KA5678 / 70067 / 2700

XA1234 / 90045 / 400

XA5678 / 70067 / 2000

Next, when the last 4 digit of the material & also cost center the same between KA and XA, the difference of the cost is

cost in XA - cost in KA = Y then move the difference which is Y into a variable.

I take material 1234 as example

400 - 620 = (220), then add (220) into a new variable.

Thanks

Rgds

1 ACCEPTED SOLUTION

Former Member
0 Kudos

first sort..

then

use loop at your internal table..." take a variable so that you can put the total into and also take another table to put the data into

now use command ON CHNAGE OF or AT NEW..and clear you total variable.

other wise continue adding the value in the loop

then put a read statement in the collection table (new table)

then if sy-subrc <> 0 then modify the table with the value

and if sy-subrc = 0..appentd the value .

endloop..

this will do you first requirement...

using the simlar approach you can implement you other part...

one point that i would like to make...that this is general logic...

anyways...

best of luck..

and i hope this helps..

cheers

Yadesh

11 REPLIES 11

Clemenss
Active Contributor
0 Kudos

Anonymous,

use COLLECT statement.

Don't ask for coding. Thats what you get paid for.

Or search for a job as taxi driver

Regards,

Clemens

Former Member
0 Kudos

hi,

appreciate for the real reply.

if u do not want to reply, just ignore. do not insult people in the forum.

rgds

Clemenss
Active Contributor
0 Kudos

sorry.

And thank you for active contribution

Ask_Comm

Posts: 898

Registered: 9/11/07

Forum Points: 0

Regards,

Clemens

Former Member
0 Kudos

just behave yourself in the forum. why need to be so proud of yourself?

i not offending you at all and why u insult other people?

Former Member
0 Kudos

>

> just behave yourself in the forum. why need to be so proud of yourself?

> i not offending you at all and why u insult other people?

Stop asking for logic. Being an ABAP Developer, you should understand the scenario and write a logic for that,First you have to try out something on ABAP editor using your knowledge and then come back with questions. That is how it should work. I am sure you are smart enough to device a logic and on debugging it you will know how to make it better, got it??? That is how you should work. Not the way you are doing now.

And always dont expect people to give you the answers you want, and I really dont find any wrong in what Clemens said, If an ABAP developer is asking for code, then it is similar to a taxi driver asking "how to drive?"

Vishwa.

Former Member
0 Kudos

first sort..

then

use loop at your internal table..." take a variable so that you can put the total into and also take another table to put the data into

now use command ON CHNAGE OF or AT NEW..and clear you total variable.

other wise continue adding the value in the loop

then put a read statement in the collection table (new table)

then if sy-subrc <> 0 then modify the table with the value

and if sy-subrc = 0..appentd the value .

endloop..

this will do you first requirement...

using the simlar approach you can implement you other part...

one point that i would like to make...that this is general logic...

anyways...

best of luck..

and i hope this helps..

cheers

Yadesh

Former Member
0 Kudos

Hi Folks,

Wots happening here... Behave urself Mr.Clemens Li .. There are lot of people who are not as intelligent like u...

To discuss thier doubts and to help them we have these types of Forums... Either cooperate with the people in the forum or jus F... off... Dont think like ur a Macho because u earned lot of points.. behave urself .. learn to respect others..

Cheers.

Sanil

0 Kudos

@ Ask_Comm and SANIL,

on behalf of Clemens as I read him a bit more than you, would like to say, he didnot mean to say you are not intelligent by pointing your posts,but he must have meant about the forum rules, which also says not to ask all coding.

you can prepare a draft code and we can help.

@Clemens ,

i know its friday and high again ??

and that taxi driver thing went a bit hard.

@ASK and SANIL,

again to say.. please dont take it other way.. and keep posting..

0 Kudos

Either cooperate with the people in the forum or jus F... off... Dont think like ur a Macho because u earned lot of points.. behave urself .. learn to respect others..

Its ridiculous that people make such statements on a forum like SDN.

@ Ask_Comm and SANIL

Please refrain from using harsh language on the forum. Also, It is against posting guidelines to ask for code.

Subhankar
Active Contributor
0 Kudos

Hi

Please check the sample code

TYPES: BEGIN OF x_tab,

matnr TYPE matnr,

cost_cnt TYPE char10,

cost TYPE char10,

END OF x_tab.

DATA: i_tab TYPE STANDARD TABLE OF x_tab,

i_final TYPE STANDARD TABLE OF x_tab,

wa_tab TYPE x_tab,

l_cost TYPE char10 VALUE 0.

wa_tab-matnr = '1'.

wa_tab-cost_cnt = 'A'.

wa_tab-cost = 10.

APPEND wa_tab TO i_tab.

wa_tab-matnr = '2'.

wa_tab-cost_cnt = 'A'.

wa_tab-cost = 10.

APPEND wa_tab TO i_tab.

wa_tab-matnr = '1'.

wa_tab-cost_cnt = 'A'.

wa_tab-cost = 10.

APPEND wa_tab TO i_tab.

wa_tab-matnr = '1'.

wa_tab-cost_cnt = 'B'.

wa_tab-cost = 10.

APPEND wa_tab TO i_tab.

wa_tab-matnr = '2'.

wa_tab-cost_cnt = 'A'.

wa_tab-cost = 10.

APPEND wa_tab TO i_tab.

wa_tab-matnr = '3'.

wa_tab-cost_cnt = 'A'.

wa_tab-cost = 10.

APPEND wa_tab TO i_tab.

SORT i_tab.

LOOP AT i_tab INTO wa_tab.

l_cost = l_cost + wa_tab-cost.

AT END OF cost_cnt.

wa_tab-cost = l_cost.

APPEND wa_tab TO i_final.

l_cost = 0.

ENDAT.

ENDLOOP.

WRITE: 'ABC'. " Here your final table is ready

Thanks !

Subhankar

0 Kudos

Hello Subhankar,

Does not COLLECT do the same thing? Why take the pains of coding some extra lines

Cheers,

Suhas