Search code examples
reportabapalv

Transform report with distribution by months


I have the following ALV report generated from the RFKSLD00 program:

enter image description here

I need to generate a report based on the above report like this one (as part of my work):

enter image description here

Any ideas how to do this? I am not asking for a solution but some steps on how to achieve this.


Solution

  • Each line of the original report is one line of your report, you need just to adjust the sums for local currency, i.e. multiply all values by local currency rate. The yellow totals lines shouldn't confuse you, they are generated by grid, not by report.

    The only thing that is missing in original report is debit and credit of balance carryforward, I suppose in the original you have already reconciliated value. To get separate values for it you need inspecting the code.

    The initial step would be to declare final structure and table based on it:

     TYPES: BEGIN OF ty_report,
              rec_acc TYPE skont,
              vendor TYPE lifnr,
              ...
              jan_deb TYPE wrbtr,
              jan_cred TYPE wrbtr,
              febr_deb TYPE wrbtr,
              febr_cred TYPE wrbtr,
              ...
              acc_bal_deb TYPE wrbtr,
              acc_bal_cred TYPE wrbtr,
            END OF ty_report,
            tt_report TYPE TABLE OF ty_report.
     DATA:  lt_report TYPE tt_report.
    

    Then you only need looping original report internal table and fill your final structure, not missing currency conversion:

    select single * from tcurr
            into @DATA(tcurr)
            where fcurr = 'EUR'
            and   tcurr = 'AUD'. "<- your  local currency
    
    DATA(lv_ukurs) = tcurr-ukurs.
    
    LOOP AT orig_table INTO DATA(orig_line).
    
     APPEND INITIAL LINE INTO lt_report ASSIGNING FIELD-SYMBOL(<fs_rep>).
     MOVE-CORRESPONDING orig_line TO <fs_rep>.
    
     CASE orig_line-monat. "<- your period
      WHEN '01'.
       <fs_rep>-jan_deb = orig_line-debit.
       <fs_rep>-jan_cred = orig_line-credit.
      WHEN '02'.
       <fs_rep>-febr_deb = orig_line-debit.
       <fs_rep>-febr_cred = orig_line-credit.
      ...
     ENDCASE.
    
     DO 30 TIMES.
      ASSIGN COMPONENT sy-index OF STRUCTURE <fs_rep> TO FIELD-SYMBOL(<field>).
       CHECK sy-subrc = 0.
      DESCRIBE FIELD <field> TYPE DATA(TYP).
       CHECK TYP = 'P'.
      CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
       EXPORTING
       DATE                    = sy-datum
       FOREIGN_CURRENCY        = 'EUR'
       LOCAL_CURRENCY          = 'AUD'
       FOREIGN_AMOUNT          = <field>
       TYPE_OF_RATE            = 'M'
      IMPORTING
       EXCHANGE_RATE           = lv_ukurs
       LOCAL_AMOUNT            = <field>.
     ENDDO.
    
    ENDLOOP.
    

    I recommend to name all components of your final structure ty_report the same as in original as much as possible. Thus you can maximally utilize MOVE-CORRESPONDING and avoid manual coding.

    This is just quick shot and I may be missing some details and errors.