Skip to Content
avatar image
Former Member

performance for huge table

Hi  Friends

I need to fill data from excel file and implement below logic for all the fields  and at last finally need to update custom table .

    A  table has  more then 35 fields  then in these fields there is one field  ' STATUS ',

first after picking data from file  need  to check all 35 fields one by one from starting 2nd field of table ,, if any field has value then its mean  1  ,if not then 0   like that  need to read table from  2nd field of table and concatenate these values and pass to  field  STATUS .

Eg   if  table  test had  5 fields

1  A =  'ttt' .

2  B =     ,

3  C =  '33'

4  D =  '343',

5  Status .      In this case  status values should be  '1011'.

now my query if  what could be the most optimized , performance side best method to write this logic as there will be multiple records and  35 fields need to read to update this logic .

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    May 29, 2015 at 07:26 AM

    Hi Kushi,

    Your doubt regarding performance is correct ... But I think, 30 IF .. ENDIFs and 30 times DO will not have much difference .. May be its a nested loop but both does the same right! .. DO might have very small performance than IFs .. For example if you have 100 fields you can't imagine how many lines we should write for that ...

    As MATTHEW suggested, it is better to keep SY-SUBRC check and populate the number for DO statement dynamically ..

    I think you can close the thread, this will be the best optimised and good code for your requirement ...

    Thanks & Regards,

    Arun. 😊

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 21, 2015 at 07:58 PM

    Why don't you give this a try yourself and get back to the group if you have specific questions?

    Rob

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Kushi Sharma wrote:

      Rob you are genius , :-)

      I have some family members who may disagree with you 😈

      If you want help with a real situation, you will have to supply some real details.

      I suggest that you close this discussion and start a new one.

      Rob

      Message was edited by: Rob Burbank

  • avatar image
    Former Member
    May 28, 2015 at 02:16 PM

    Hi,

    Try below ...

    TYPES : BEGIN OF test,

               matnr TYPE char10,

               mtart TYPE char10,

               mbrsh TYPE char10,

               status TYPE char3,

             END OF test.

    DATA : tab TYPE TABLE OF test,

            wa_mara TYPE test.

    FIELD-SYMBOLS: <wa_mara>  TYPE test,

                    <fs_value> TYPE any.

    wa_mara-matnr = 100.

    wa_mara-mtart = 'aaa'.

    wa_mara-mbrsh = 'bbb'.

    APPEND wa_mara TO tab.

    wa_mara-matnr = 100.

    wa_mara-mtart = space.

    wa_mara-mbrsh = 'bbb'.

    APPEND wa_mara TO tab.

    wa_mara-matnr = 100.

    wa_mara-mtart = 'aaa'.

    wa_mara-mbrsh = space.

    APPEND wa_mara TO tab.

    wa_mara-matnr = space.

    wa_mara-mtart = 'aaa'.

    wa_mara-mbrsh = 'bbb'.

    APPEND wa_mara TO tab.

    LOOP AT tab ASSIGNING <wa_mara>.

       DO 3 TIMES.

         ASSIGN COMPONENT sy-index OF STRUCTURE <wa_mara> TO <fs_value>.

         IF <fs_value> IS NOT INITIAL.

           CONCATENATE <wa_mara>-status '1' INTO <wa_mara>-status.

         ELSE.

           CONCATENATE <wa_mara>-status '0' INTO <wa_mara>-status.

         ENDIF.

       ENDDO.

       WRITE : / <wa_mara>-matnr, <wa_mara>-mtart, <wa_mara>-mbrsh, <wa_mara>-status.

    ENDLOOP.


    In place of 3 you can give your number(i.e., number of fields in your structure) ..


    Output

    ----------


    Hope this will be best optimised logic .. 😊


    Thanks & Regards,

    Arun.



    Capture.PNG (2.1 kB)
    Add comment
    10|10000 characters needed characters exceeded

    • For safety, I'd prefer to see:

           ASSIGN COMPONENT sy-index OF STRUCTURE <wa_mara> TO <fs_value>.

           IF sy-subrc IS INITIAL AND <fs_value> IS NOT INITIAL.

             CONCATENATE <wa_mara>-status '1' INTO <wa_mara>-status.

           ELSE.

             CONCATENATE <wa_mara>-status '0' INTO <wa_mara>-status.

           ENDIF.

      The DO is fixed for a specific test table, so it doesn't change the algorithmic order. You have to check each field of the test table. The only other way you can do it is by

      LOOP AT tab ASSIGNING <wa_mara>.

         IF <wa_mara>-matnr IS INITIAL.

             CONCATENATE <wa_mara>-status '1' INTO <wa_mara>-status.

           ELSE.

             CONCATENATE <wa_mara>-status '0' INTO <wa_mara>-status.

           ENDIF.

         IF <wa_mara>-mtart IS INITIAL.

             CONCATENATE <wa_mara>-status '1' INTO <wa_mara>-status.

           ELSE.

             CONCATENATE <wa_mara>-status '0' INTO <wa_mara>-status.

           ENDIF.


      ...etc.

         ENDDO.

         WRITE : / <wa_mara>-matnr, <wa_mara>-mtart, <wa_mara>-mbrsh, <wa_mara>-status.

      ENDLOOP.


      The difficulty with this is that you've got awful code (even with some kind of modularisation), that you have to edit the program if the structure of tab ever changes. The performance hit with the DO is slight - I've used this kind of construct many times and never needed to change it. Also, if you use DESCRIBE FIELD... COMPONENTS... you get the number of iterations required for your DO, which will mean your program will not need to be edited no matter how the driving table change in the background.

  • May 31, 2015 at 10:31 AM

    This message was moderated.


    Add comment
    10|10000 characters needed characters exceeded