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

calculation [pls]

Former Member
0 Likes
386

Hi all

Can u tell me how to do this(like in bank statement,first line items balance should be carryword and do calacution with second line items debit and credit),

Formula is balance = opening +debit +(-credit) fro sytabix = 1

-2167.00 + 201614.00 + 0 = 199447.00

For sy-tabix ne 1

Bala = balance + debit +(-credit)

199447.002284.00(-0)= 201731.00

01731.000(-269919.00) = -68188.00

Debit,, Credit,, Balance

opening 2167.00

201614.00,, 0.00,, 199447.00

2284.00,, 0.00,, 201731.00

0.00,, 269919.00,, -68188.00

0.00,, 122285.00,,-190473.00

2217.00,, 0.00,, -188256.00

195624.00 ,, 0.00,, 7368.00

0.00,, 366491.00,,-359123.00

Thanks & Regards

2 REPLIES 2
Read only

Former Member
0 Likes
364

OBal = '-2167'.

Loop at items.

*If your credit values are maintained as positive values

itab-credit = itab-credit * -1.

If sy-tabix = 1.

Bal = OBal + itab-debit + itab-credit.

Else.

Bal = Bal + itab-debit + itab-credit.

Endif.

EndLoop.

Read only

Former Member
0 Likes
364

Hope this helps


DATA:
  wk_bal                   TYPE p DECIMALS 2,
  BEGIN OF inrec,
    debit            TYPE p DECIMALS 2,
    credit           TYPE p DECIMALS 2,
    balance          TYPE p DECIMALS 2,
  END OF inrec,
  it_trans LIKE STANDARD TABLE OF inrec.

START-OF-SELECTION.
  PERFORM build_trans.

  LOOP AT it_trans INTO inrec.
    IF sy-tabix = 1.
      WRITE:/1 'Debit',
            21 'Credit',
            41 'Balance'.
      WRITE:/ 'Opening' UNDER 'Debit',
              inrec-balance UNDER 'Balance' RIGHT-JUSTIFIED.
      wk_bal = inrec-balance.
    ELSE.
      wk_bal = wk_bal + inrec-debit - inrec-credit.
      WRITE:/ wk_bal UNDER 'Balance' RIGHT-JUSTIFIED.
      IF inrec-debit GT 0.
        WRITE: inrec-debit UNDER 'Debit'  RIGHT-JUSTIFIED.
      ENDIF.
      IF inrec-credit GT 0.
        WRITE: inrec-credit UNDER 'Credit'  RIGHT-JUSTIFIED.
      ENDIF.
    ENDIF.
  ENDLOOP.


*&---------------------------------------------------------------------*
*&      Form  build_trans
*&---------------------------------------------------------------------*
FORM build_trans.
  REFRESH it_trans.
  inrec-debit  = 0.
  inrec-credit = 0.
  inrec-balance = '-2167.00'.
  APPEND inrec TO it_trans.

  inrec-debit  = '201614.00'.
  inrec-credit = 0.
  inrec-balance = 0.
  APPEND inrec TO it_trans.

  inrec-debit  = '2284.00'.
  inrec-credit = 0.
  inrec-balance = 0.
  APPEND inrec TO it_trans.

  inrec-debit  = 0.
  inrec-credit = '269919.00'.
  inrec-balance = 0.
  APPEND inrec TO it_trans.

  inrec-debit  = 0.
  inrec-credit = '122285.00'.
  inrec-balance = 0.
  APPEND inrec TO it_trans.

  inrec-debit  = '2217.00'.
  inrec-credit = 0.
  inrec-balance = 0.
  APPEND inrec TO it_trans.

  inrec-debit  = '195624.00'.
  inrec-credit = 0.
  inrec-balance = 0.
  APPEND inrec TO it_trans.

  inrec-debit  = 0.
  inrec-credit = '366491.00'.
  inrec-balance = 0.
  APPEND inrec TO it_trans.

ENDFORM.                    " build_trans

and the Output


Debit               Credit              Balance            
Opening                                         2,167.00-  
      201,614.00                              199,447.00   
        2,284.00                              201,731.00   
                          269,919.00           68,188.00-  
                          122,285.00          190,473.00-  
        2,217.00                              188,256.00-  
      195,624.00                                7,368.00   
                          366,491.00          359,123.00-