cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate total amount of Balance, prev. periods for selected periods

Former Member
0 Kudos

Hello Experts,

I have a requirement

For S6 = xx to zz in the selection screen, sum up FAGLFLEXT-HSL01 to FAGLFLEXT-HSLzz-1

If zz = 01 display the value 0.

S6 is select option for period input that can be 1 to 16.

after sum up i have to store it to field HSLTOT.

please guide me on this can anyone post code please.

Thanks in advance.

bsapman.

Accepted Solutions (1)

Accepted Solutions (1)

Clemenss
Active Contributor
0 Kudos

Hi,

modify according to your need:

*&---------------------------------------------------------------------*
*&      Form  consolidate_totals
*&---------------------------------------------------------------------*
FORM consolidate_totals
  USING     pt_tot                        TYPE table
  CHANGING  pt_acc_balance                TYPE ty_t_acc_balance..
* FAGLFLEXT fields TSL01 .. TSL16 and HSL01 .. HSL16
* collected per account, currency abd period into debit and credit
* transaction ans local currency
  DATA:
    lv_fieldname                          TYPE fieldname,
    lv_num2                               TYPE num2,
    ls_acc_balance                        TYPE LINE OF  ty_t_acc_balance..

  FIELD-SYMBOLS:
    <anystruc>                            TYPE ANY,
    <anyfield>                            TYPE ANY,
    <drcrk>                               TYPE shkzg,
    <tsl>                                 TYPE tslvt12,
    <hsl>                                 TYPE hslvt12.
  LOOP AT pt_tot ASSIGNING <anystruc>.
* currency and account
    MOVE-CORRESPONDING:
      <anystruc> TO ls_acc_balance.
    ASSIGN COMPONENT 'DRCRK' OF STRUCTURE <anystruc> TO <drcrk>.
    IF <drcrk>                            = 'S'.
      ASSIGN:
        ls_acc_balance-deb_t TO <tsl>,
        ls_acc_balance-deb_h TO <hsl>.
    ELSE.
      ASSIGN:
        ls_acc_balance-cre_t TO <tsl>,
        ls_acc_balance-cre_h TO <hsl>.
    ENDIF." <drcrk> 0 'S'.
    DO 16 TIMES.
      ls_acc_balance-perio                = lv_num2 = sy-index.
      CONCATENATE 'TSL' lv_num2 INTO lv_fieldname.
      ASSIGN COMPONENT lv_fieldname OF STRUCTURE <anystruc> TO <anyfield>.
      PERFORM move_if_ok
        USING sy-subrc  <anyfield> CHANGING: <tsl>.
      CONCATENATE 'HSL' lv_num2 INTO lv_fieldname.
      ASSIGN COMPONENT lv_fieldname OF STRUCTURE <anystruc> TO <anyfield>.
      PERFORM move_if_ok
        USING sy-subrc  <anyfield> CHANGING: <hsl>.
      CHECK:
         <tsl> IS NOT INITIAL OR <hsl> IS NOT INITIAL.
      ls_acc_balance-bal_t                = ls_acc_balance-deb_t - ls_acc_balance-cre_t.
      ls_acc_balance-bal_h                = ls_acc_balance-deb_h - ls_acc_balance-cre_h.
      COLLECT ls_acc_balance INTO pt_acc_balance.
      CLEAR:
        ls_acc_balance-deb_t,
        ls_acc_balance-cre_t,
        ls_acc_balance-bal_t,
        ls_acc_balance-deb_h,
        ls_acc_balance-cre_h,
        ls_acc_balance-bal_h.
    ENDDO.
  ENDLOOP." at pt_tot assigning <anystruc>.
ENDFORM.                    " consolidate_totals

Regards,

Clemens

Answers (0)