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

Test ranges in an Abap Program

Former Member
0 Likes
2,417

Hi experts,

Let’s say I have some records arriving from my source as following :

Source Table:


Account

Functional Area

Profit Center

Amount

60000

00

10001

50,00

60000

05

20002

130,00

70000

13

30001

-450,00

In my target I want to add one more field that I am going to deduce from a table with the following conditions:

Transformation Table:


Account

Functional Area Range from

Functional Area Range To

Profit Center Range from

Profit Center Range To

Virtual Account

60000

03

10001

10010

AX

60000

04

10

20001

20010

AY

70000

11

20

30000

30010

BX

The red cell means empty or initial.


So the difficulty that I am having is that is to test 2 ranges in order to deduce the Virtual Account into my target which will be as following:

Target Table:


Account

Functional Area

Profit Center

Amount

Virtual Account

60000

00

10001

50,00

AX

60000

05

20002

130,00

AY

70000

13

30001

-450,00

BX

Do you think that an abap program can be efficient in my case?

I tought about the following:

Read Transformation table with key account = Source Table- account

Test that Functional area of source table is between Functional Area Range from and TO

And Profit Center in source tale is between Profit Center Range from and To

And then deduce the virtual account


Thanks for your support.

Amine

1 ACCEPTED SOLUTION
Read only

PeterJonker
Active Contributor
0 Likes
2,269

data:  r_functionalarea type range of  functionalarea,

          r_profitcentre type range of  profitcentre.

r_functionalarea-sign = 'I'

r_functionalarea-option = 'BT'.

r_profitcentre-sign = 'I'

r_profitcentre-option = 'BT'.

loop at transformationtable into workarea_transform.

r_profitcentre-low = workarea-profitcentrefrom.

r_profitcentre-high = workarea-profitcentreto.

r_functionalarea-low = workarea-funtionalareafrom.

r_functionalarea-high = workarea-funtionalareato.

loop at source_table into workarea_source where account = workarea-account

                                                                     functionalarea IN r_functionalarea

                                                                      profitcenter in r_profitcentre

move-corresponding workarea_transform to workarea_target.

move-corresponding workarea_source to workarea_target.

append workarea_target to target_table.

clear: workarea_target,workarea_source.

endloop.

clear: r_profitcentre-low, r_profitcentre-high, r_functionalarea-low, r_functionalarea-high.

clear: workarea_transform.

endloop.

Hi experts,

Let’s say I have some records arriving from my source as following :

Source Table:


Account

Functional Area

Profit Center

Amount

60000

00

10001

50,00

60000

05

20002

130,00

70000

13

30001

-450,00

In my target I want to add one more field that I am going to deduce from a table with the following conditions:

Transformation Table:


Account

Functional Area Range from

Functional Area Range To

Profit Center Range from

Profit Center Range To

Virtual Account

60000

03

10001

10010

AX

60000

04

10

20001

20010

AY

70000

11

20

30000

30010

BX

The red cell means empty or initial.


So the difficulty that I am having is that is to test 2 ranges in order to deduce the Virtual Account into my target which will be as following:

Target Table:


Account

Functional Area

Profit Center

Amount

Virtual Account

60000

00

10001

50,00

AX

60000

05

20002

130,00

AY

70000

13

30001

-450,00

BX

Do you think that an abap program can be efficient in my case?

I tought about the following:

Read Transformation table with key account = Source Table- account

Test that Functional area of source table is between Functional Area Range from and TO

And Profit Center in source tale is between Profit Center Range from and To

And then deduce the virtual account


Thanks for your support.

Amine

17 REPLIES 17
Read only

Former Member
0 Likes
2,269

Hi Amine,

I think that the process u mentioned is good but , i guess u need to hav another field other that account for comparision.

the reason is each time in the loop (Source table), when u read (transformation table), only first entry with account matched will be fetched.

as in case of account 6000 , the below will be read twice in loop (for the first two records)

60000

03

10001

10010

AX

it would be better if u have one more field other than account for comparision..

Regards,

Azhar

Read only

0 Likes
2,269

Thank Azhar,

I agree with you, but i have to read the 2 ranges also in order to deduce the virtual account.

I think that if i find a way how to read and test 2 ranges, my issue will be solved.

Amine

Read only

anup_deshmukh4
Active Contributor
0 Likes
2,269

Hello Amine,

Would a Corrrect use of Collet Statement be helpful ?

Thanks an Regards,

Anup

Read only

0 Likes
2,269

Hi Anup,

What do you mean? I am not familiar with this abap command?

Amine

Read only

0 Likes
2,269

Hello Amine ,

Sorry it was a typo its  'Collect ' , I assume you are trying to Consolidate the data  in the target table .

Read only

0 Likes
2,269

Exaclty Anup,

I want to consolidate the data as explained with the tables in my initial question.

Thanks.

Amine

Read only

0 Likes
2,269

Yes.. so in that case apart from your Amount all are Non-Numeric fields so you can use Collect Statement efficiently to build your target table.

Read only

PeterJonker
Active Contributor
0 Likes
2,270

data:  r_functionalarea type range of  functionalarea,

          r_profitcentre type range of  profitcentre.

r_functionalarea-sign = 'I'

r_functionalarea-option = 'BT'.

r_profitcentre-sign = 'I'

r_profitcentre-option = 'BT'.

loop at transformationtable into workarea_transform.

r_profitcentre-low = workarea-profitcentrefrom.

r_profitcentre-high = workarea-profitcentreto.

r_functionalarea-low = workarea-funtionalareafrom.

r_functionalarea-high = workarea-funtionalareato.

loop at source_table into workarea_source where account = workarea-account

                                                                     functionalarea IN r_functionalarea

                                                                      profitcenter in r_profitcentre

move-corresponding workarea_transform to workarea_target.

move-corresponding workarea_source to workarea_target.

append workarea_target to target_table.

clear: workarea_target,workarea_source.

endloop.

clear: r_profitcentre-low, r_profitcentre-high, r_functionalarea-low, r_functionalarea-high.

clear: workarea_transform.

endloop.

Read only

0 Likes
2,269

Very interesting approach.

Amine

Read only

0 Likes
2,269

Hi Peter,

How can i manage the start of a range when it's empty?

Account

Functional Area Range from

Functional Area Range To

60000

03

Normally that means:

Account

Functional Area Range from

60000

60000

01

60000

02

60000

03

Thanks.

Amine

Read only

0 Likes
2,269

Dear amine lamkaissi

Go with your approach that's easy i think

for your previous question , i think following method will work

while looping that particular field show empty value right , based on that you can increase the counter, and do the deduction , add one more extra field use counter, like count = count +1 .

for example if particular field value is empty , then made it like '00' in program.

Regards,

Bastin.G

Read only

0 Likes
2,269

Dear Bastin,

Actually it was a mistake, it's more like this

Normally that means:

Account

Functional Area Range from

60000

60000

00

60000

01

60000

02

60000

03

Empty, 00, 01, 02, 03

Thanks.

Amine

Read only

0 Likes
2,269

Dear amine lamkaissi

Add one more column in internal table call like status

if values empty means add '00' in that column and sort it,

then finally use delete adjacent duplicates from internal table command

and finally you will get it unique numbers

Regards,

Bastin.G

Read only

0 Likes
2,269

Let me explain clearly,

For example values empty means pass '00' to different column which u newly added in ITAB.

then for other  functional values pass the same values to that column while looping.

then you will get internal table like,

60000 - > 00

60000 ->00

60000->01

60000->02

60000->03

now you can sort the internal table then use delete adjacent syntax you will get desired values hope it helps

Regards,

Bastin.G

Read only

0 Likes
2,269

Hi Peter,

In this code:

loop at source_table into workarea_source where account = workarea-account

                                                                     functionalarea IN r_functionalarea

                                                                      profitcenter in r_profitcentre

You meant the follwing right?

loop at source_table into workarea_source where account = workarea_target-account

                                                                     functionalarea IN r_functionalarea

                                                                      profitcenter in r_profitcentre

Thanks.

Amine

Read only

0 Likes
2,269

I think the correct code should be:

loop at source_table into workarea_source where account = workarea_transform-account functionalarea IN r_functionalarea profitcenter in r_profitcentre

workarea_transform is the work area of the outer loop.

Read only

0 Likes
2,269

Ok Thanks Kaushalya.

Amine