cancel
Showing results for 
Search instead for 
Did you mean: 

Calculated field in "End Routine" produces inconsistent result

Former Member
0 Kudos

Hi SCN, I hope you can easily answer my question.

- SAP BW 7.

- Transformation between DSO and Cube with an End Routine that calculates a field. In case it matters, I pasted the End Routine at the end of this post.

- The calculated field works like this:

For each row, check all other existing rows (with the same material-code, during the last 2 years of the creation date, for the same purchase organization, ...) and depending if a row (or multiple rows) are found, a value is written into the calculated field.

That way we know if this material has been bought from the same/different supplier during the last 2 years, or maybe it has not been bought at all during the last 2 years and so on.

Now we get to the problem that we experience:

- When I simulate or run the DTP for the two material-codes that we use for testing, the results are as expected:

ZPURINFO is the calculated field.

When I run it for all the data in the DSO (about 420.000 rows) I get varying results for each run:

1st run:

Second run:

I set the Package size in the DTP to 5.000 (with 50.000 we got dumps because the memory of the server was used up).

I set the Semantic Group to (Material-code ticked) though I do know that this should not matter, as this only affects DSO->DSO and not DSO->Cube.

The ABAP developer is not a BW-ABAP-dev but a regular ECC-ABAP-dev.

Why are we getting changing results every time we run the complete DSOs data and how can we fix that problem?

  METHOD end_routine.
*=== Segments ===

FIELD-SYMBOLS:
<RESULT_FIELDS>   
TYPE _ty_s_TG_1.

DATA:
MONITOR_REC    
TYPE rstmonitor.

*$*$ begin of routine - insert your code only below this line        *-*
... "insert your code here
*--  fill table "MONITOR" with values of structure "MONITOR_REC"
*-   to make monitor entries
... "to cancel the update process
*    raise exception type CX_RSROUT_ABORT.

TYPES:
BEGIN OF ty_dso,
soursystem
TYPE rssoursysid,
oi_ebeln
TYPE /bi0/oioi_ebeln,
oi_ebelp
TYPE /bi0/oioi_ebelp,
vendor
TYPE /bi0/oivendor,
material
TYPE /bi0/oimaterial,
aedat
TYPE /bi0/oiaedat,
doc_cat
TYPE /bi0/oidoc_cat,
doc_type
TYPE /bi0/oidoc_type,
doc_date
TYPE /bi0/oidoc_date,
END OF ty_dso.

DATA:
lv_prevyear
TYPE /bi0/oiaedat,
lv_prevyear2
TYPE /bi0/oiaedat,
lt_dso_h
TYPE TABLE OF /bic/azd001800,
lt_dso_i
TYPE TABLE OF /bic/azd001800,
wa_dso
TYPE /bic/azd001800,
ls_dso
TYPE /bic/azd001800,
wa_dso_i
TYPE /bic/azd001800.

DATA: loc_tabix LIKE sy-tabix,
loc_vendor_found
,
loc_purinfo2
TYPE /bic/oizpurinfo,
loc_purinfo3
TYPE /bic/oizpurinfo,
loc_purinfo4
TYPE /bic/oizpurinfo.

FIELD-SYMBOLS: <fs_dso> TYPE /bic/azd001800.
*    Field-symbols:
*          <lt_DSO> type ZTAB_AZD001800,
*          <wa_DSO> like <lt_dso>.

SORT RESULT_PACKAGE BY oi_ebeln oi_ebelp aedat.

*   select the header lines from ZD0018 DSO
*    SELECT * FROM /bic/azd001800
*      INTO TABLE lt_dso_h
*      FOR ALL ENTRIES IN RESULT_PACKAGE
*     WHERE oi_ebeln = RESULT_PACKAGE-oi_ebeln AND
*      WHERE /bic/zorigin LIKE 'SAP%'
*        AND oi_ebelp = '00000'.

*    SORT lt_dso_h BY oi_ebeln oi_ebelp aedat.

*   select the corresponding item lines from the DSO
*    READ TABLE lt_dso_h INDEX 1 TRANSPORTING NO FIELDS.
*    IF sy-subrc = 0.
SELECT * FROM /bic/azd001800
INTO TABLE lt_dso_i
FOR ALL ENTRIES IN RESULT_PACKAGE
WHERE purch_org = RESULT_PACKAGE-purch_org AND
material 
= RESULT_PACKAGE-material AND
/bic/zorigin
LIKE 'SAP%' AND
oi_ebelp
NE '00000'.
READ TABLE lt_dso_i INDEX 1 TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
SELECT * FROM /bic/azd001800
INTO TABLE lt_dso_h
FOR ALL ENTRIES IN lt_dso_i
WHERE oi_ebeln = lt_dso_i-oi_ebeln AND
/bic/zorigin
LIKE 'SAP%' AND
oi_ebelp
= '00000'.
ENDIF.
*    ENDIF.
*   fill the "changed on date" in the item table also
SORT lt_dso_h BY oi_ebeln.
SORT lt_dso_i BY oi_ebeln.

LOOP AT lt_dso_h INTO ls_dso.
READ TABLE lt_dso_i WITH KEY oi_ebeln = ls_dso-oi_ebeln
TRANSPORTING NO FIELDS.
loc_tabix
= sy-tabix.
IF loc_tabix NE 0.
LOOP AT lt_dso_i INTO wa_dso_i FROM loc_tabix.
IF ls_dso-oi_ebeln NE  wa_dso_i-oi_ebeln.
EXIT.
ENDIF.
wa_dso_i
-aedat = ls_dso-aedat.
wa_dso_i
-doc_cat = ls_dso-doc_cat.
wa_dso_i
-doc_type = ls_dso-doc_type.
wa_dso_i
-doc_date = ls_dso-doc_date.
MODIFY lt_dso_i FROM wa_dso_i INDEX loc_tabix.
ENDLOOP.
ENDIF.
ENDLOOP.

*   select the mMOVEX records also
SELECT * FROM /bic/azd001800
APPENDING TABLE lt_dso_i
WHERE /bic/zorigin = 'MOVEX'.

SORT lt_dso_i BY oi_ebeln oi_ebelp aedat.

CLEAR ls_dso.
SORT lt_dso_h BY soursystem oi_ebeln.
SORT lt_dso_i BY purch_org material.

LOOP AT RESULT_PACKAGE ASSIGNING <result_fields>.
*     clear the SAP data from header lines and item lines without header
IF <result_fields>-/bic/zorigin CS 'SAP'.
IF <result_fields>-oi_ebelp = '00000'.
*       clear the header lines doc number for later delete
CLEAR <result_fields>-oi_ebeln.
CONTINUE.
ELSE.
IF ls_dso-oi_ebeln NE <result_fields>-oi_ebeln.
*         at new doc number check if header for the item exists
CLEAR ls_dso.
READ TABLE lt_dso_h INTO ls_dso
WITH KEY soursystem = <result_fields>-soursystem
oi_ebeln  
= <result_fields>-oi_ebeln BINARY
SEARCH.
IF sy-subrc NE 0.
*if no header exists -> clear doc number for later delete of the line
CLEAR <result_fields>-oi_ebeln.
CONTINUE.
ENDIF.
ENDIF.

IF ls_dso-aedat IS NOT INITIAL.
*       copy the header data into the item line fields
<result_fields>
-aedat = ls_dso-aedat.
<result_fields>
-doc_cat = ls_dso-doc_cat.
<result_fields>
-doc_type = ls_dso-doc_type.
<result_fields>
-doc_date = ls_dso-doc_date.
ENDIF.
ENDIF.
ENDIF.

*     determine ZPURINFO field
*     set the date interval
DATA: lv_year TYPE i.
lv_year
= <result_fields>-aedat(4).
SUBTRACT 2 FROM lv_year.
lv_prevyear
= <result_fields>-aedat.
lv_prevyear+0
(4) = lv_year.

*     set default 01
<result_fields>
-/bic/zpurinfo = 01.

*     search for PO items with the same material and the same purch.org
*     in the last 2 year before the change date of the record
READ TABLE lt_dso_i WITH KEY purch_org = <result_fields>-purch_org
material 
= <result_fields>-material
TRANSPORTING NO FIELDS.
loc_tabix
= sy-tabix.
CLEAR: loc_purinfo2, loc_purinfo3, loc_purinfo4, loc_vendor_found.

LOOP AT lt_dso_i INTO wa_dso FROM loc_tabix.
IF wa_dso-purch_org NE <result_fields>-purch_org OR
wa_dso
-material NE <result_fields>-material.
EXIT.
ENDIF.
IF wa_dso-oi_ebeln = <result_fields>-oi_ebeln AND
wa_dso
-oi_ebelp = <result_fields>-oi_ebelp.
CONTINUE.
ENDIF.
IF wa_dso-aedat LT lv_prevyear OR
wa_dso
-aedat GE <result_fields>-aedat.
CONTINUE.
ENDIF.
IF NOT loc_vendor_found = 'X'.
loc_purinfo2
= 02.
ENDIF.

IF wa_dso-itm_cat = <result_fields>-itm_cat AND
wa_dso
-vendor  = <result_fields>-vendor.
loc_purinfo4
= 04.
ENDIF.
IF wa_dso-vendor = <result_fields>-vendor.
CLEAR loc_purinfo2.
loc_vendor_found
= 'X' .
loc_purinfo3
= 03.
ENDIF.
ENDLOOP.
IF NOT loc_purinfo3 IS INITIAL.
<result_fields>
-/bic/zpurinfo = 03.
ENDIF.
IF NOT loc_purinfo2 IS INITIAL.
<result_fields>
-/bic/zpurinfo = 02.
ENDIF.
IF NOT loc_purinfo4 IS INITIAL.
<result_fields>
-/bic/zpurinfo = 04.
ENDIF.
ENDLOOP.


*   delete the header lines and item lines, that has no header
*   therefore was the doc number cleared
DELETE RESULT_PACKAGE
WHERE oi_ebeln IS INITIAL
AND /bic/zorigin CS 'SAP'.

*$*$ end of routine - insert your code only before this line         *-*
ENDMETHOD.                    "end_routine

Accepted Solutions (0)

Answers (4)

Answers (4)

RafkeMagic
Active Contributor
0 Kudos

Alexander Jarmai wrote:


*   fill the "changed on date" in the item table also
SORT lt_dso_h BY oi_ebeln.
SORT lt_dso_i BY oi_ebeln.

LOOP AT lt_dso_h INTO ls_dso.
READ TABLE lt_dso_i WITH KEY oi_ebeln = ls_dso-oi_ebeln
TRANSPORTING NO FIELDS.
loc_tabix
= sy-tabix.
IF loc_tabix NE 0.
LOOP AT lt_dso_i INTO wa_dso_i FROM loc_tabix.
IF ls_dso-oi_ebeln NE  wa_dso_i-oi_ebeln.
EXIT.
ENDIF.
wa_dso_i
-aedat = ls_dso-aedat.
wa_dso_i
-doc_cat = ls_dso-doc_cat.
wa_dso_i
-doc_type = ls_dso-doc_type.
wa_dso_i
-doc_date = ls_dso-doc_date.
MODIFY lt_dso_i FROM wa_dso_i INDEX loc_tabix.
ENDLOOP.
ENDIF.
ENDLOOP.

What are you actually trying to achieve here?

You sort the item table by PO number (and not by item). Then you try to read 'a' line (first one in whatever the sort results - which is rather random I guess). You then loop from the table index of that record, then you keep updating the first line you read with the same information (loc_tabix is not updated anymore).

So, let's assume you have a PO with 5 items. After this part of your code 1 random item is going to be updated with the change date (document category, document type and document date) of the header.

That's just strange to me...

Former Member
0 Kudos

Thank you; I passed this on to the developer and hopefully at the end of the week we have a tested solution, so that I can award points.

RafkeMagic
Active Contributor
0 Kudos

Ok, thanks for the feedback.

There may be other mistakes... I just stopped looking after the part I mentionned in my previous message.

roland_szajko
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Alexander

You make a sorting on result_package directly. This shouldn't be done, since this can effect the order of the incoming records.

Instead of sorting result_package directly, use an internal table in the FAE and this way the order of records will/should always be the same.

br

Roland


Former Member
0 Kudos

Thank you Roland, I will pass that on to the ABAP developer.

Chie, I do not understand your reply.

Akanksha, ZD0018 key = 0SOURSYSTEM, 0OI_EBELN, 0OI_EBELP

(Source system ID, Purchasing document number, Purchasing document position)

former_member214274
Active Participant
0 Kudos

Hi Alexander,

Since there are many sort operations your routine, you can consider setting semantic group as creation date along with material  and purchasing organization in your DTP.

In this way you will have similar data in one package and this may prevent inconsistency in your calculated field.

Hope this helps.

Thanks,

Akanksha

Former Member
0 Kudos

Hi,

Have limited knowledge on SD side, so cannot understand your issue as:

1) Expected result and 1st/2nd run is in difference format (or field order)

2) I can't see how 1st and 2nd run varying...

Please provide some more information.

But test run and real run difference because there are more key values in the result_packet and the 2 key used in your example may in difference packet, so you may review your login base on that as well.

Regards

Bill

former_member214274
Active Participant
0 Kudos

Hi,

What are the key fields for DSO ZD0018?

rgds

Akanksha