Skip to Content
author's profile photo Former Member
Former Member

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

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Oct 09, 2010 at 04:11 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.