Skip to Content
avatar image
Former Member

Enhancing 0ASSET_ATTR issue

Hi Experts,

   I have written the below code at t-code CMOD at INCLUDE ZXRSAU02 in FUNCTION EXIT_SAPLRSAP_002 to enhance 0Asset_attr datasource by looking up into ANLZ table for RAUMN field and copy it to BWFIAA_ASSETMASTER, which is the structure for 0asset_attr.

*&---------------------------------------------------------------------*

*&  Include           ZXRSAU02

*&---------------------------------------------------------------------*

DATA: A_S_INFOSTRU LIKE BWFIAA_ASSETMASTER,

       cocd type c LENGTH 4,

       m_asset_no type c LENGTH 12,

       a_sub_no type c LENGTH 4,

       DAT_E  type DATS,

       it_data type STANDARD TABLE OF ANLZ,

       wa_data type anlz.

CASE I_DATASOURCE.

  WHEN '0ASSET_ATTR'.

  LOOP AT I_T_DATA INTO A_S_INFOSTRU.

  IF A_S_INFOSTRU-Z_ROOM = ''.

* CLEAR L_STAT.

* L_STAT = A_S_INFOSTRU-BWSTZCRZHED.

    "clnt = '100'.

    cocd = a_s_infostru-BUKRS.

    m_asset_no = a_s_infostru-ANLN1.

    a_sub_no = a_s_infostru-ANLN2.

    DAT_E = a_s_infostru-DATETO.

   "Go to ECC table ANLZ and select the record for room

*Select all fields of a SAP database table into in itab

SELECT *

   FROM anlz

   INTO TABLE it_data.

     LOOP at it_data into  wa_DATA

                     WHERE MANDT = '100'

                     AND BUKRS = cocd

                     AND ANLN1 = m_asset_no

                     AND ANLN2 = a_sub_no

                     AND BDATU = dat_e.

      A_S_INFOSTRU-Z_ROOM = wa_data-RAUMN.

      endloop.

      delete i_t_data.

      APPEND a_s_infostru to i_t_data.

    ENDIF.

    endloop.

* L_TABIX = SY-TABIX.

ENDCASE.


When I execute the code at RSA3 with loop in the code, I go into infinite loop. Also, is the data in I_T_DATA written back to the datasource ?


Thanks in advance,


Regards,

Draksh

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Dec 22, 2014 at 10:26 PM

    Hi ,

    SELECT query written with in loop and extracting all data from ANLZ, it create performance issue.

    Steps

    1 First create internal table with required fields

    2 Fetch only required records with the help of SELECT

    3 Use READ statement within loop

    Regards,

    Nanda

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Nanda,

         I shall try that. Also, is 'deleting and amending the record' the right way to insert the ZField to existing record? also writing to I_T_Data writes back to datasource?

      Regards,
      Draksh

  • avatar image
    Former Member
    Dec 22, 2014 at 11:38 PM

    Hi Draksharam

    Try this:

    TYPES: BEGIN OF ty_data,       

               bukrs TYPE anlz-bukrs,       

              anln1 TYPE anlz-anln1,       

              anln2 TYPE anlz-anln2,       

              bdatu TYPE anlz-bdatu,       

              raumn TYPE anlz-raumn,      

         END OF ty_data.

    DATA: it_data TYPE TABLE OF ty_data,     

              wa_data like LINE OF it_data.    

    CASE I_DATASOURCE. 

         WHEN '0ASSET_ATTR'.

              SELECT  bukrs       

                             anln1       

                             anln2       

                             bdatu       

                             raumn  

                   FROM anlz  

              INTO TABLE it_data 

    FOR ALL ENTRIES IN I_T_DATA  

    WHERE bukrs = i_t_data-bukrs AND       

                   anln1 = i_t_data-anln1 AND       

                   anln2 = i_t_data-anln2 AND       

                   bdatu = i_t_date-dateto. 

         IF sy-subrc EQ 0.    

              SORT it_data BY bukrs anln1 anln2 bdatu. 

         ENDIF. 

         LOOP AT I_T_DATA INTO A_S_INFOSTRU.   

                   l_sytabix  = sy-tabix.   

                   IF A_S_INFOSTRU-Z_ROOM = ''.       

                        READ TABLE it_data INTO wa_data WITH KEY bukrs = i_t_data-bukrs                            

                                                                                                        anln1 = i_t_data-anln1                            

                                                                                                        anln2 = i_t_data-anln2                            

                                                                                                        bdatu = i_t_date-dateto       

                        BINARY SEARCH.       

                        IF sy-subrc EQ 0.           

                                  A_S_INFOSTRU-Z_ROOM = wa_data-RAUMN.           

                                  MODIFY i_t_data from a_s_infostru-z_room INDEX l_sy-tabix TRANSPORTING z_room.       

                        ENDIF.     

                 ENDIF.

       endloop.

    endcase.

    Regards,

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Francisco Rodriguez,

          I am getting the following error message

      'the specified type has no structure and therefore no component called 'BUKRS'. component called 'BUKRS'

      at

      WHEN '0ASSET_ATTR'.

      SELECT bukrs anln1 anln2 bdatu raumn

      Can you help me sort this out?

      Regards,
      Draksh