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: 

need help with a routine..URGENT

Former Member
0 Kudos
193

HI,

I have to write a routine for BW where we have 2 fields: posting period and balance period..

Posting period has values from 0 to 13 and balance perieod has different valaues...

I need to write a code such that for eg:

when posting period is 3 then balance = balance for period 0 + balance for period 1 balance for period 2 balance for period 3.

It has to add all the balance based on the posting period....

Kindly give suggestions....Please help...

Cheers:

Sam

Message was edited by:

Sam williams

1 ACCEPTED SOLUTION

Former Member
0 Kudos
174

Hi sam,

You can do something like this

DO (posting period +1) times.

l_index = sy-index-1.

Balance = balance for period <l_index> + Balance.

ENDDO.

Regards,

Atish

26 REPLIES 26

Former Member
0 Kudos
174

Hi,

I hope following code will solve your problem.


CASE posting_period.
  WHEN 1.
    balance = balance for period 0 + balance for period 1.
  WHEN 2.
    balance = balance for period 0 + balance for period 1 +balance for period 2.
  WHEN 3.
    balance = balance for period 0 + balance for period 1 +balance for period 2+ balance for period 3
ENDCASE.

If the above code is not useful, please explain in detail whether posting period and balance are stored in an internal table or individual fields.

Reward points if the answer is helpful.

Regards,

Mukul

Message was edited by:

Mukul R. Kulkarni

Former Member
0 Kudos
175

Hi sam,

You can do something like this

DO (posting period +1) times.

l_index = sy-index-1.

Balance = balance for period <l_index> + Balance.

ENDDO.

Regards,

Atish

0 Kudos
174

Hey Atish,

How will i code the logic...

posting period and balance perioed are coming from a table and all the changes have to reflect in the table...i mean if posting period = 2 from a table then we have to make sure the balance in that table is chaged in a manner such that it adds the balance of the posting period 0 and posting period 1...

Please provide me the detail code...i am new to this...

ur help is appreciated...

0 Kudos
174

Hi sam,

Can you paste your code so that we can tell you how to modify the same.

Regards,

Atish

0 Kudos
174

Hi,

Is data coming from an internal table or database table ??

If data is coming an internal table, then following code will solve your problem.


READ it_posting_period INTO x_posting_period INDEX 1.
CLEAR v_sum.
IF sy-subrc = 0.
  LOOP AT it_balance INTO x_balance FROM 1 TO x_posting_period-value.
    v_sum = v_sum + x_balance-amount.
  ENDLOOP.
  Append/Modify your internal table with the total.
ENDIF.

Here, the posting period will be read from an internal table it_posting_period. Then, based on the value of posting period, the internal table it_balance which contains balance will be looped or read and you will get the total in v_sum. Now using this v_sum, you can append or modify your internal table.

Reward points if the answer is helpful.

Regards,

Mukul

Message was edited by:

Mukul R. Kulkarni

0 Kudos
174

Hey Atish,

I still have to begin with it...i was little inclear with the logic...but to explain...

Data: Begin of itab occurs 0,

i_period like table-period,

i_balalnce like table-balance

end of itab.

then what code shud be written..

Thanks man

0 Kudos
174

Hey mukul,

It is coming from the database table and then have to update the database table..

but i think we have to make a internal table first with the two fields as posting period and balance and then update the balalnce in the datatbase table...

please suggest

thanks

0 Kudos
174

Hi,

Yes, that's true, first you will have to fetch data from database, manipulate it and then push it back to database.

Now here, can you explain which database tables you are using for getting the required data ?

Regards,

Mukul

0 Kudos
174

Mukul,

I dont have the datatbase tables yet...i have to provide logic to do this and psedo code to my manager...

but if u see the recent posts from atish and others it seems we can do it suing internal tables...but not sure how...

can u provide me any pseudo code thati can tell my manager...

Thanks

0 Kudos
174

Hi,

Please clarify, is every balance period assigned to a respective posting period ? i.e balance period 1 is assigned to posting period 1. If yes, then the code given in my previous post will work properly. But, you will have to write the code to fetch data from database table into an internal table before using my code.

Reward points if the answer is helpful.

Regards,

Mukul

0 Kudos
174

Mukul,

Balance is associated with every posting period...

I mean in the database we have table with posting period and balance as two fields and we have to update another field with our logic...

Thanks...

0 Kudos
174

Hi,

So, you are saying that, data in database table is like

posting_period balance

00 10

01 15

02 20

03 25

So, if the posting period is 03, total should be 70 but if posting period is 01, total should be 25.

Also, which are the key fields of the database table ?

Regards,

Mukul

0 Kudos
174

Hi Sam,

For writing a psuedo code you must have the design of your DB table ready. Only then you can design your internal table and the logic. I think you first need to get the DB table design from your manager /functional people.

Regards,

Atish

0 Kudos
174

Mukul,

Thats right...

But for now we are not actually updating the database table...its routine that we have to write...we will import the two fields: posting period and balance into our internal table and then do the calculation...this is what my manager says...it is for the BW team that he wants this code...

I need to provide a pseudo code for that...

Please suggest...and thanks a lot...

0 Kudos
174

Hey Atish,

The design of the table is such that it has two fields : posting period and balance and there is another field year to date balance for which we have to write the logic..does this info answer ur question or do we need more info...

Please help...

Thanks

0 Kudos
174

Hi sam,

Can you please elaborate things

For eg

Field1 Field2 Field3

Poper Balan ????

04 1000 ???

05 2000 ???

Can you just expalin what exactly you want in third field. where to get all the values, etc?

Regards,

Atish

0 Kudos
174

Hey Atish,

Thanks for the effort buddy...I will try an explain the best i can..

PostingPeriod Balance YearToDateBal

0 100

1 20 120 << this we have to compute

2 30 150<< like this we have to compute till posting period 12

-


12 - sum<< like this...now we have to write a routine for this to happen..posting period and balance are coming from th database somewhere so we have to get in an internal table...dont worry about the name of the table for now...both posting period and balance are in the same table but yeartodatebal is not in the same table as them...

Did i explain in detail or u need more info...

this is all what i know and i have to write code...i know its tough and without sdn help its impossible...

Thanks

0 Kudos
174

Hi Sam,

What are the key fields in your DB table, I presume only Posting period.

So at any point of time there will be only 12 or 16 entries in the table (If you take period as 12 or 16) so I think there is a flaw in the design of the DB table. I know I am going out of track to your original question :).

Your DB table should have Fiscal year as another key.

Now Doing your logic, I will try and paste it for you

Regards,

Atish

0 Kudos
174

Hello Sam,

Try something like this

SORT ITAB by period.

LOOP AT ITAB.

CASE ITAB-PERIOd.

WHEn 1.

l_bal_1 = itab-balance.

itab-ytdbalance = l_bal_1.

WHEN 2.

l_bal_2 = l_bal_1 + itab-balance.

itab-ytdbalance = l_bal_2.

WHEN 3.

l_bal_3 = l_bal_2 + itab-balance.

.

.

.

.

ENDCASE.

MODIFY ITAB.

ENDLOOP.

....NOw your ITAB is done

UPDATE <DB table> USINS ITAB.

Regards,

Atish

0 Kudos
174

Hey Sam,

I hope following code will solve your problem.


DATA : l_tabix  TYPE sy-tabix,
       l_tabix1 TYPE sy-tabix.

SELECT posting_period balance
  FROM
  INTO TABLE it_itab
  WHERE .....

IF sy-subrc = 0.
  LOOP AT it_itab INTO x_itab.
    l_tabix = sy-tabix.
    IF sy-tabix = 1.
      x_itab-yeartodatebal = x_itab-balance.
    ELSE.
      l_tabix1 = l_tabix - 1.
      READ TABLE it_itab INTO x_itab1 INDEX l_tabix1.
      IF sy-subrc = 0.
        x_itab-yeartodatebal = x_itab-yeartodatebal + x_itab1-yeartodatebal.
      ENDIF.
    ENDIF.
    MODIFY it_itab FROM x_itab INDEX l_tabix.
  ENDLOOP.
ENDIF.

After this is done your internal table it_itab will have data in all three fields. You just need to update the database table with contents of your internal table.

Reward points if the answer is helpful.

Regards,

Mukul

0 Kudos
174

Hey Atish,

U r right in that database table there ia also a field fiscal year...but i dont know how we can use it...

Also how shud i declare the internal table...i mean does it have to be theree different tables or one itab..can u please explain that and thanks a million for ur help...

Thanks

0 Kudos
174

Hi,

Declare only one internal table with three fields as posting_period, balance and yeartodatebal.

Regards,

Mukul

0 Kudos
174

Hi Sam,

The internal table will be of the same type of DB table and the code I provided will work for you.

Regards,

Atish

0 Kudos
174

Mukul and Atish,

Thanks a lot...I still have to show the pseudo code to my manager...lets see what does he suggest...i will come back and award points for sure...

but apart from the points i wanted to say that because of u guys we people here can learn and understand ABAP...and also get help in crucial points...

Ur effort is highly appreciated guys...

Thanks Again...

former_member194669
Active Contributor
0 Kudos
174

Hi,

Do this way


DATA: BEGIN OF series,
         n1 TYPE i VALUE 10,
         n2 TYPE i VALUE 20,
         n3 TYPE i VALUE 30,
         n4 TYPE i VALUE 40,
         n5 TYPE i VALUE 50,
         n6 TYPE i VALUE 60,
      END OF series.

DATA sum TYPE i.

ADD series-n1 THEN series-n2 UNTIL series-n5 GIVING sum.
WRITE sum.

ADD series-n2 THEN series-n3 UNTIL series-n6 TO sum.
WRITE / sum.

The output is as follows:

       150

       350

Look closely in the code and apply in your code. I think it will help u.

aRs

0 Kudos
174

HI,

Thanks for the effort...

but the values are coming from a table and have to update the table...

how can i use this code or what else can i do...

Thanks