cancel
Showing results for 
Search instead for 
Did you mean: 

Sign reversal in end routine for all key figures of data package

Former Member
0 Kudos

Hi all,

I am searching for an efficient and scalable way to reverse the sign of every key figure, which occurs in the data package structure. This should be done in the end routine of a transformation.

Background: I want to do a loop-load on an InfoCube using Transformation/DTP. All key figures of the extracted data shall be reversed. Thus, I achieve a nullification in the InfoCube (MINUS plus PLUS gives ZERO).

Currently, I multiply every key figure field with -1 in the end routine (using very simple ABAP), which works fine. The coding looks as follows:

<SOURCE_FIELDS>-/BIC/ZCOGJBONU
          = <SOURCE_FIELDS>-/BIC/ZCOGJBONU * -1.
<SOURCE_FIELDS>-/BIC/ZCOGMRABA
          = <SOURCE_FIELDS>-/BIC/ZCOGMRABA * -1.
<SOURCE_FIELDS>-/BIC/ZCOGVVADJ
          = <SOURCE_FIELDS>-/BIC/ZCOGVVADJ * -1.

... and so on for the other key figures.

The negative thing about this static solution is, that this does not scale automatically, if new key figures are added to the cube for instance; you must need to adjust the routine in such cases.

I am searching for efficient ABAP code, which basically dynamically checks the structure of the DATA_PACKAKGE against key figure data types and automatically applies the multiplication with -1 for all of those key figure fields in the structure. That would be scalable, as it would not need to be adjusted, if the key figure number changes in the InfoCube.

Is there any function module from SAP, which can solve this problem? Has anyone of you written ABAP code, which provides a solution to this issue?

Thanks to any answers in advance.

Best regards,

Philipp

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

I have not coded for this particular challenge as of yet. The following will help though. You can select the fields of the target table (Infocube Fact Table) from table DD03L, and then loop at the resulting list of fields. Inside the loop you can assign a Field Symbol to the contents of a variable that holds a concatenation of "<SOURCE_FIELDS>-" and the fact table field name.

Here is how the code would look:

data: it_dd03l type standard table of dd03l,

wa_dd03l type dd03l,

w_field_name(80) type c.

field-symbols: <fn> type any.

select *

into table it_dd03l

from dd03l

where tabname eq "<u><b>FACT TABLE NAME</b></u>"

and as4local eq 'A'

and datatype eq "<u><b>DESIRED DATA TYPE</b></u>".

Loop at source_package assigning <SOURCE_FIELDS>.

w_field_name = '<SOURCE_FIELDS>-'.

loop at it_dd03l into wa_dd03l.

move wa_dd03l-fieldname to w_field_name+16(66).

assign (w_field_name) to <fn>.

<fn> = <fn> * -1.

endloop.

Endloop.

Answers (1)

Answers (1)

Former Member
0 Kudos

ABAP statement DESCRIBE can tell you what type of data it is. You have to use field symbols, scan the entire row using ASSIGN COMPONENT statement, stop at each field, determine if it is numeric, and then apply your logic.

Below is the code I have used to convert character type fields to upper case. You have to make necessary changes to suit your needs.


  DO.
    ASSIGN COMPONENT sy-index OF STRUCTURE rec_data TO <fs_field>.
    IF sy-subrc <> 0.
      EXIT. "out of the DO loop
    ENDIF.

    IF NOT <fs_field> IS INITIAL.
      DESCRIBE FIELD <fs_field> TYPE l_field_type.

      IF l_field_type = 'C'.
        IF i_trim_flag = 'X'.
          CALL FUNCTION 'Z_CEB_TRIM_PROHIBITED_CHARS'
               CHANGING
                    c_text = <fs_field>.
        ELSE.
          TRANSLATE <fs_field> TO UPPER CASE.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDDO.

Former Member
0 Kudos

Hi Sudhi,

very helpful answer!

Thanks!