Friday, May 22, 2009

create custom menu exits

I got this spacial requirement when i was working with a project.

where a generic menu bar is required which can add items according to the customer.

the first thing to do in such requirement is to add a fcode in menu painter starting with +XXX ( replace X).

once this is done handle the fcode using a function

CALL CUSTOMER-FUNCTION '010'.

with in this function you can do what ever you what to do for when that item is clicked.


then on a standard SAP enhancement(smod) add your program name and the fcode and add your function exit on it.

create a project on cmod and add the enhancement you will find the exit and the menu exit.

if this is not clear pls post a comment ( coz i just wrote it in a way how i will understand)

Thursday, May 7, 2009

best way to code nested loops SAP


REPORT  ZPARALLEL_CURSOR.
TABLES:
  likp,
  lips.

DATA:
      t_likp  
TYPE TABLE OF likp,
      t_lips  
TYPE TABLE OF lips,
      t_lips1 
TYPE SORTED TABLE OF lips
      
WITH NON-UNIQUE KEY vbeln.




DATA:
      w_runtime1 
TYPE I,
      w_runtime2 
TYPE I,
      w_counter 
TYPE I,
      w_index 
LIKE sy-INDEX.

DATA:
      likp_l 
TYPE I,
      lips_l 
TYPE I.

PARAMETERSrows TYPE i OBLIGATORY.

START-
OF-SELECTION.
SELECT *
FROM likp
INTO TABLE t_likp up to rows ROWS.



DESCRIBE TABLE t_likp LINES likp_l.

WRITE:/ 'records in likp: ' .
WRITE likp_l.

SELECT *
INTO TABLE t_lips
FROM lips
  
FOR ALL ENTRIES IN t_likp
  
WHERE vbeln = t_likp-vbeln.


DESCRIBE TABLE t_lips LINES lips_l.


WRITE:/ 'records in lips: ' .
WRITE lips_l.


**********************************************************************
**********************************************************************
**********************************************************************

GET RUN TIME FIELD w_runtime1.

LOOP AT t_likp INTO likp.
  
LOOP AT t_lips INTO lips WHERE vbeln EQ likp-vbeln.

  
ENDLOOP.
ENDLOOP.

GET RUN TIME FIELD w_runtime2.

w_runtime2 = w_runtime2 - w_runtime1.

WRITE:/.
WRITE:/'Time taken on normal where condition:'.
WRITE: w_runtime2.

**********************************************************************
**********************************************************************
**********************************************************************
GET RUN TIME FIELD w_runtime1.
SORT t_likp BY vbeln.
SORT t_lips BY vbeln.

LOOP AT t_likp INTO likp.

  
LOOP AT t_lips INTO lips FROM w_index.
    
IF likp-vbeln NE lips-vbeln.
      w_index = sy-tabix.
      
EXIT.
    
ENDIF.

  
ENDLOOP.
ENDLOOP.


GET RUN TIME FIELD w_runtime2.

w_runtime2 = w_runtime2 - w_runtime1.


WRITE:/.
WRITE:/.
WRITE:/'Time taken with parallel cursor:' , w_runtime2.



**********************************************************************
**********************************************************************
**********************************************************************

GET RUN TIME FIELD w_runtime1.

SORT t_lips BY vbeln.
t_lips1[] = t_lips[].




LOOP AT t_likp INTO likp.
  
LOOP AT t_lips1 INTO lips WHERE vbeln EQ likp-vbeln.
  
ENDLOOP.

ENDLOOP.

GET RUN TIME FIELD w_runtime2.

w_runtime2 = w_runtime2 - w_runtime1.

WRITE:/.
WRITE:/.
WRITE:/'Time taken for a sorted table with where condition:' , w_runtime2.





Google