Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Optimize BW start and end routine

Former Member
0 Kudos

Hello,

I created start and end routine from dso to cube to enhance some other data.

In developement system everything works fine. But in production system there are too much data. Because of that dtp needs a lot of time.

Can you tell me how I can optimize coding?

Global:

*$*$ begin of global - insert your declaration only below this line  *-*
* 20130517 2462
* Deklaration der internen Tabellen und Workareas

* Lieferköpfe inkl. Lieferpriorität
     TYPES:
     BEGIN OF gs_dlv_head,
       deliv_numb     TYPE /bi0/oideliv_numb,
       dlv_prio       TYPE /bi0/oidlv_prio,
       END OF gs_dlv_head.

     DATA: lt_dlv_head TYPE STANDARD TABLE OF gs_dlv_head
           WITH KEY deliv_numb.
     "interne Tabelle
     DATA: ls_dlv_head LIKE LINE OF lt_dlv_head. "Workarea

*$*$ end of global - insert your declaration only before this line   *-*

Start routine:

* 20130517 2462
* Füllen der internen Tabellen aus Lieferköpfen (ZSD_D28).

BREAK-POINT.

* Auftragspositionen

     LOOP AT SOURCE_PACKAGE ASSIGNING <source_fields>.
       SELECT deliv_numb
              dlv_prio

       FROM /bic/azsd_d2800
       INTO ls_dlv_head
       WHERE deliv_numb = <source_fields>-refer_doc.
       ENDSELECT.
       APPEND ls_dlv_head TO lt_dlv_head.
     ENDLOOP.

BREAK-POINT.

     SORT  lt_dlv_head ASCENDING BY deliv_numb.
     DELETE ADJACENT DUPLICATES FROM lt_dlv_head COMPARING deliv_numb.

*$*$ end of routine - insert your code only before this line         *-*

End routine:

*$*$ 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.

* 20110124 IT_CBO
* Füllen der fehlenden Felder im Ziel mit Daten aus den
* Auftragskpoepfen und Lieferpositionen.

     DATA: lt_rp LIKE RESULT_PACKAGE.
     DATA: lv_count TYPE i.
     DATA: lv_ship_point(10) TYPE c,
           lv_sales_off(10) TYPE c.

     LOOP AT RESULT_PACKAGE ASSIGNING <result_fields>.

* Auftragspositionen

       BREAK-POINT.

       READ TABLE lt_dlv_head
       INTO ls_dlv_head
       WITH KEY deliv_numb = <result_fields>-deliv_numb.

       IF sy-subrc = 0.
         <result_fields>-dlv_prio       = ls_dlv_head-dlv_prio.
         <result_fields>-deliv_numb     = ls_dlv_head-deliv_numb.
       ELSE.
         <result_fields>-deliv_numb = ''.
         <result_fields>-deliv_item = ''.
         IF <result_fields>-bill_type = 'ZBV' OR
         <result_fields>-bill_type = 'ZBVR'.
           <result_fields>-dlv_prio       = '50'.
         ENDIF.
       ENDIF.

       CONCATENATE '000000' <result_fields>-sales_off INTO lv_sales_off.
       CONCATENATE '000000' <result_fields>-ship_point INTO lv_ship_point
       .

       IF <result_fields>-ship_point IS INITIAL.
         <result_fields>-profit_ctr = lv_sales_off.
       ELSE.
         <result_fields>-profit_ctr = lv_ship_point.
       ENDIF.

     ENDLOOP.

I hope you can help me!

Regards

Jesper

1 ACCEPTED SOLUTION

matt
Active Contributor
0 Kudos

Instead of having a start and end routine, consider using an expert routine. That way the data is only gone through once. You have to code any rules by hand, however.

Define tl_dlv_head as a sorted table, or, even better, a hashed table.

Use SELECT... FOR ALL ENTRIES... into a suitably defined internal table and read from that, instead of one select per loop.

If the logic gets more complicated, it's probably worth investing in the time of an expert ABAP developer.

8 REPLIES 8

matt
Active Contributor
0 Kudos

Instead of having a start and end routine, consider using an expert routine. That way the data is only gone through once. You have to code any rules by hand, however.

Define tl_dlv_head as a sorted table, or, even better, a hashed table.

Use SELECT... FOR ALL ENTRIES... into a suitably defined internal table and read from that, instead of one select per loop.

If the logic gets more complicated, it's probably worth investing in the time of an expert ABAP developer.

0 Kudos

Hello Jesper,

I don't think you need a start routine at all. I think everything can be done in the end routine.

Delete the start routine and try the following in your end routine:

* Lieferköpfe inkl. Lieferpriorität
     TYPES:
     BEGIN OF gs_dlv_head,
       deliv_numb     TYPE /bi0/oideliv_numb,
       dlv_prio       TYPE /bi0/oidlv_prio,
     END OF gs_dlv_head.

     DATA: lt_dlv_head          TYPE STANDARD TABLE OF gs_dlv_head,

                 lht_dlv_head        TYPE HASHED TABLE OF gs_dlv_head

                                                           WITH UNIQUE KEY deliv_numb,

                 ls_dlv_head         TYPE gs_dlv_head. "Workarea

                 lv_count               TYPE i,

                 lv_ship_point(10) TYPE c,

                 lv_sales_off(10)   TYPE c.

     SELECT deliv_numb dlv_prio
       FROM /bic/azsd_d2800
       INTO CORRESPONDING FIELDS OF TABLE lt_dlv_head
       FOR ALL ENTRIES IN result_package
       WHERE result_package-deliv_numb EQ /bic/azsd_d2800-deliv_numb.

     IF sy-subrc = 0.
       SORT lt_dlv_head.
       DELETE ADJECENT DUPLICATES FROM lt_dlv_head COMPARING deliv_numb.
       lht_dlv_head[] = lt_dlv_head[].
       FREE: lt_dlv_head.
     ENDIF.

     LOOP AT result_package ASSIGNING <result_fields>.
       READ TABLE lht_dlv_head INTO ls_dlv_head
       WITH TABLE KEY deliv_numb = <result_fields>-deliv_numb.
       IF sy-subrc = 0.
         <result_fields>-dlv_prio   = ls_dlv_head-dlv_prio.
         <result_fields>-deliv_numb = ls_dlv_head-deliv_numb.
       ELSE.
         <result_fields>-deliv_numb  = ''.
         <result_fields>-deliv_item    = ''.
         IF <result_fields>-bill_type EQ 'ZBV' OR
             <result_fields>-bill_type EQ 'ZBVR'.
           <result_fields>-dlv_prio  = '50'.
         ENDIF.
       ENDIF.
      
       CONCATENATE '000000' <result_fields>-sales_off INTO lv_sales_off.
       CONCATENATE '000000' <result_fields>-ship_point INTO lv_ship_point.

       IF <result_fields>-ship_point IS INITIAL.
         <result_fields>-profit_ctr = lv_sales_off.
       ELSE.
         <result_fields>-profit_ctr = lv_ship_point.
       ENDIF.
     ENDLOOP.

Hope it will do the job for you.

Try to avoid SELECT in LOOP/ENDLOOP and SELECT/ENDSELECT. These are real performance killers.

Use hashed tables if possible.

Rgds,

René

0 Kudos

Sorry, previous code contains a small error.

Please try the following code:

* Lieferköpfe inkl. Lieferpriorität
     TYPES:
     BEGIN OF gs_dlv_head,
       deliv_numb     TYPE /bi0/oideliv_numb,
       dlv_prio       TYPE /bi0/oidlv_prio,
     END OF gs_dlv_head.

     DATA: lt_dlv_head          TYPE STANDARD TABLE OF gs_dlv_head,

                 lht_dlv_head        TYPE HASHED TABLE OF gs_dlv_head

                                                           WITH UNIQUE KEY deliv_numb,

                 ls_dlv_head         TYPE gs_dlv_head, "Workarea

                 lv_count               TYPE i,

                 lv_ship_point(10) TYPE c,

                 lv_sales_off(10)   TYPE c.

     SELECT deliv_numb dlv_prio
       FROM /bic/azsd_d2800
       INTO CORRESPONDING FIELDS OF TABLE lt_dlv_head
       FOR ALL ENTRIES IN result_package
       WHERE deliv_numb EQ result_package-deliv_numb.

     IF sy-subrc = 0.
       SORT lt_dlv_head.
       DELETE ADJECENT DUPLICATES FROM lt_dlv_head COMPARING deliv_numb.
       lht_dlv_head[] = lt_dlv_head[].
       FREE: lt_dlv_head.
     ENDIF.

     LOOP AT result_package ASSIGNING <result_fields>.
       READ TABLE lht_dlv_head INTO ls_dlv_head
       WITH TABLE KEY deliv_numb = <result_fields>-deliv_numb.
       IF sy-subrc = 0.
         <result_fields>-dlv_prio   = ls_dlv_head-dlv_prio.
         <result_fields>-deliv_numb = ls_dlv_head-deliv_numb.
       ELSE.
         <result_fields>-deliv_numb  = ''.
         <result_fields>-deliv_item    = ''.
         IF <result_fields>-bill_type EQ 'ZBV' OR
             <result_fields>-bill_type EQ 'ZBVR'.
           <result_fields>-dlv_prio  = '50'.
         ENDIF.
       ENDIF.
      
       CONCATENATE '000000' <result_fields>-sales_off INTO lv_sales_off.
       CONCATENATE '000000' <result_fields>-ship_point INTO lv_ship_point.

       IF <result_fields>-ship_point IS INITIAL.
         <result_fields>-profit_ctr = lv_sales_off.
       ELSE.
         <result_fields>-profit_ctr = lv_ship_point.
       ENDIF.
     ENDLOOP.

Former Member
0 Kudos

Hey René,

thanks a lot! These channgings really helped me!

Regards

Jesper

matt
Active Contributor
0 Kudos

Rather than:

CONCATENATE '000000' <result_fields>-sales_off INTO lv_sales_off.

Use

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

    INPUT = <result>-sales_off

    OUTPUT = lv_sales_off.

This will ensure that you get the correct number of leading zeros, without having to worry about the length of the fields yourself. It also makes the code more robust - you don't need to change it should the lengths of the fields change. Unlikely, I know, but still it is safer.

Similarly for

CONCATENATE '000000' <result_fields>-ship_point INTO lv_ship_point

Former Member
0 Kudos

Hey Matthew,

thanks for your help but, your mentioned coding is not accepted by SAP.

"Input" should be the problem. It says:

"E:Statt "INPUT" wurde "IMPORTING parameter", "CHANGING parameter",

"EXPORTING parameter", "EXCEPTIONS parameter" oder "TABLES parameter"

erwartet."

In English:

"E:Instead of "INPUT",  "IMPORTING parameter", "CHANGING parameter",

"EXPORTING parameter", "EXCEPTIONS parameter" or "TABLES parameter"

has been expected."

I am not really good in ABAP Coding so what would you recommend me to do?

Regards

Jesper

matt
Active Contributor
0 Kudos

Entschuldigung - mein Fehler. (Sorry, my mistake)

Click on PATTERN, and enter CONVERSION_EXIT_ALPHA_INPUT in the "CALL FUNCTION" field. Click on green arrow. This will give you the correct syntax.

Or you can put your cursor on CALL or FUNCTION within your code, and click on F1 and read the ABAP help that tells you the correct syntax.

Former Member
0 Kudos

Hey Matthew,

this was helpful. Thanks!

Regards

Jesper