Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Read Master Data + Routine in Transformation

Hello forum,

Within a transformation from PSA to an Info Cube, I would like to read master data (0CUSTOMER) using and Info Object within my PSA and if I find the record in there, assign this value (Customer #), otherwise, assign a dummy precalculated number.

I guess I would have to use a routine to achieve something like that but I have no ABAP experience at all. Any idea from you experts out there?

Thanks for your help.

P.s. BI 7.0

Former Member
replied

You have a choice. You can either buffer into an internal table (which is like an array but different!) all the records at the start. Or you can read from the buffer and if it isn't there, then read from the database, and put it into the buffer for next time. You can further improve performance by using the right kind of table. There are three kinds of internal table - HASHED, SORTED and STANDARD. For lookups, HASHED is usually the quickest.

For what you are doing I'd choose the second kind of buffering, as you may actually only need 15 customer records and there could be thousands in the database table, and use a hashed table for lookup.

In the start routine, in the global data, have the following:

* Define line type of customer record
TYPES: BEGIN OF customer_ty,
         customer TYPE /bi0/oicustomer,
         exists   TYPE flag,
       END OF customer_ty.

* Define hashed internal table, keyed on customer
DATA: th_customer TYPE HASHED TABLE OF customer_ty WITH UNIQUE KEY customer.

In the routine do this:

DATA: ls_customer TYPE customer_ty.

READ TABLE th_customer INTO ls_customer
                       WITH TABLE KEY customer = your_info_object_in_the_psa.

* Read from database if not found
IF sy-subrc IS NOT INITIAL.
  SELECT SINGLE customer FROM /bi0/scustomer INTO ls_customer-customer
      WHERE customer EQ your_info_object_in_the_psa.
  IF sy-subrc IS INITIAL.
    ls_customer-exists = 'X'.
  ENDIF.
  INSERT ls_customer INTO TABLE th_customer.

ENDIF.

IF ls_customer-exists IS NOT INITIAL.
  result = ls_customer-customer.
ELSE.
  result = 'some dummy value'.
ENDIF.

If you want to buffer the entire table do it like this:

In the start routine, in the global data, have the following:

* Define hashed internal table, keyed on customer
DATA: th_customer TYPE HASHED TABLE OF /bi0/oicustomer WITH UNIQUE KEY table_line.

In the start routine itself.

SELECT customer FROM /bi0/scustomer INTO TABLE th_customer.

Then in the routine:

READ TABLE th_customer WITH TABLE KEY customer = your_info_object_in_the_psa
                      TRANSPORTING NO FIELDS.

IF sy-subrc IS NOT INITIAL.
  result = 'some dummy value'.
ELSE.
  result = your_info_object_in_the_psa.
ENDIF.

This applies to both 7.0 and 3.5, though the structure of the code surrounding it is different.

matt

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question