Skip to Content
author's profile photo Former Member
Former Member

Code optimisation

Hi, can anyone help me optimise this code...and elemenate the redundancy ?

DATA: t_display TYPE TABLE OF zstatchng ,

lt_display LIKE LINE OF t_display ,

BEGIN OF t_ekbe OCCURS 0,

ebeln TYPE ebeln,

belnr TYPE mblnr,

END OF t_ekbe,

BEGIN OF t_ser01 OCCURS 0,

obknr TYPE objknr,

END OF t_ser01,

BEGIN OF t_objk OCCURS 0,

sernr TYPE gernr,

matnr TYPE matnr,

END OF t_objk,

SELECT * FROM ekbe INTO CORRESPONDING FIELDS OF TABLE t_ekbe

WHERE ebeln IN s_po[] AND bewtp = 'L'.

LOOP AT t_ekbe.

SELECT * FROM ser01 INTO CORRESPONDING FIELDS OF TABLE t_ser01

WHERE lief_nr = t_ekbe-belnr.

IF sy-subrc = 0.

LOOP AT t_ser01.

SELECT * FROM objk INTO CORRESPONDING FIELDS OF TABLE t_objk

WHERE obknr = t_ser01-obknr.

LOOP AT t_objk.

MOVE t_objk-sernr TO lt_display-sernr.

MOVE t_objk-matnr TO lt_display-matnr.

SELECT * FROM equi WHERE sernr = t_objk-sernr.

ENDSELECT.

CALL FUNCTION 'STATUS_TEXT_EDIT'

EXPORTING

client = sy-mandt

objnr = equi-objnr

only_active = 'X'

spras = sy-langu

IMPORTING

line = risa0-statusline

EXCEPTIONS

object_not_found = 1.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

MOVE risa0-statusline TO lt_display-STATUSLINE.

move equi-werk to lt_display-werk.

ENDLOOP.

MOVE t_ekbe-ebeln TO lt_display-ebeln.

MOVE t_ekbe-belnr TO lt_display-vbeln.

APPEND lt_display TO t_display.

ENDLOOP.

ENDIF.

ENDLOOP.

Is there a better way to code the same ?Please reply.Urgent..Thanks.

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 08:05 PM

    Try using this code and make the necessary adjustments

    TYPES: BEGIN OF ty_ekbe,
             ebeln TYPE ekbe-ebeln,
             belnr TYPE ekbe-belnr,
           END OF ty_ekbe,
    
           BEGIN OF ty_ser01,
             obknr   TYPE ser01-obknr  ,
             lief_nr TYPE ser01-lief_nr,
           END OF ty_ser01,
    
           BEGIN OF ty_objk,
             obknr TYPE objk-obknr,
             obzae TYPE objk-obzae,
             sernr TYPE objk-sernr,
             matnr TYPE objk-matnr,
           END OF ty_objk,
    
           BEGIN OF ty_equi,
             equnr TYPE equi-equnr,
             sernr TYPE equi-sernr,
             matnr TYPE equi-matnr,
             objnr TYPE equi-objnr,
             werks TYPE equi-werks,
           END OF ty_equi.
    
    DATA: w_ekbe     TYPE                 ty_ekbe ,
          w_ser01    TYPE                 ty_ser01,
          w_objk     TYPE                 ty_objk ,
    
          t_ekbe     TYPE        TABLE OF ty_ekbe ,
          t_ekbe_tmp TYPE        TABLE OF ty_ekbe ,
          t_ser01    TYPE SORTED TABLE OF ty_ser01
            WITH NON-UNIQUE KEY lief_nr,
          t_objk     TYPE SORTED TABLE OF ty_objk
            WITH NON-UNIQUE KEY obknr,
          t_objk_tmp TYPE        TABLE OF ty_objk ,
          t_equi     TYPE SORTED TABLE OF ty_equi
            WITH NON-UNIQUE KEY sernr matnr.
    
    SELECT ebeln
           belnr
      FROM ekbe
      INTO TABLE t_ekbe
      WHERE ebeln IN s_po
      AND   bewtp EQ 'L'.
    
    IF sy-subrc EQ 0.
    
      t_ekbe_tmp[] = t_ekbe[].
    
      SORT t_ekbe_tmp BY belnr.
    
      DELETE ADJACENT DUPLICATES FROM t_ekbe_tmp COMPARING belnr.
    
      SELECT obknr
            lief_nr
        FROM ser01
        INTO TABLE t_ser01
        FOR ALL ENTRIES IN t_ekbe_tmp
        WHERE lief_nr EQ t_ekbe_tmp-belnr.
    
      IF sy-subrc EQ 0.
    
        SELECT obknr
               obzae
               sernr
               matnr
          FROM objk
          INTO TABLE t_objk
          FOR ALL ENTRIES IN t_ser01
          WHERE obknr EQ t_ser01-obknr.
    
        IF sy-subrc EQ 0.
    
          t_objk_tmp[] = t_objk[].
    
          SORT t_objk_tmp BY sernr matnr.
    
          DELETE ADJACENT DUPLICATES FROM t_objk_tmp COMPARING sernr matnr.
    
          SELECT equnr
                 sernr
                 matnr
                 objnr
                 werks
            FROM equi
            INTO TABLE t_equi
            FOR ALL ENTRIES IN t_objk_tmp
            WHERE sernr EQ t_objk_tmp-sernr
            AND   matnr EQ t_objk_tmp-matnr.
    
        ENDIF.
    
      ENDIF.
    
      LOOP AT t_ekbe INTO w_ekbe.
    
        LOOP AT t_ser01 INTO w_ser01
          WHERE lief_nr EQ w_ekbe-belnr.
    
          LOOP AT t_objk INTO w_objk
            WHERE obknr EQ w_ser01-obknr.
    
            LOOP AT t_equi INTO w_equi
              WHERE sernr EQ w_objk-sernr
              AND   matnr EQ w_objk-matnr.
    
              MOVE: w_objk-sernr TO lt_display-sernr,
                    w_objk-matnr TO lt_display-matnr.
    
              CLEAR risa0-statusline.
    
              CALL FUNCTION 'STATUS_TEXT_EDIT'
                EXPORTING
                  objnr  = w_equi-objnr
                  spras  = sy-langu
                IMPORTING
                  line   = risa0-statusline
                EXCEPTIONS
                  OTHERS = 0.
    
              MOVE: risa0-statusline TO lt_display-statusline,
                    w_equi-werk      TO lt_display-werk      ,
                    w_ekbe-ebeln     TO lt_display-ebeln     ,
                    w_ekbe-belnr     TO lt_display-vbeln     .
    
              APPEND lt_display TO t_display.
    
            ENDLOOP.
    
          ENDLOOP.
    
        ENDLOOP.
    
      ENDLOOP.
    
    ENDIF.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 04, 2007 at 08:23 PM

    Hi Deepti,

    First of all in your code try to get rid of LOOP in SELECT and ENDSELECT.

    and it's preferable to use SELECT INTO TABLE, instead of CORRESPONDING FIELDS

    try to use INNER JOIN or use FOR ALL ENTRIES instead of this.

    Pavan

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.