Tuesday, June 23, 2009

How to Debug any screen on SAP

its very simple just put this code on a text file and save it with what even name you want e.g debug

[FUNCTION]
Command=/H
Title=Debugger
Type=SystemCommand



when ever you want to debug you dont have to use /h but just drag and drop this on the SAP screen this enables you to debug on popup screens

Hope this will be useful

nafran

Wednesday, June 10, 2009

how to get the first day and last day SAP

Most of the time when we need the first day and the last day of a given month we always run to get a function. why use a function when its so easy to code it

*get first and last date of month and year
CONCATENATE s_bdatj-low s_mnr-low '01' INTO gv_date1.

gv_month = s_mnr-low .
gv_month = gv_month + 01.

CONCATENATE s_bdatj-low gv_month '01' INTO gv_date2.

gv_date2 = gv_date2 - 1.

Monday, June 8, 2009

only way of parallel or Multi Threading on SAP

Sometimes you get programs where you might have done almost all the programming best practices and Indexing and other stuff but still the program will run very slow.On a time like this sometimes we might wonder is there anyway to do parallel processing or something like multi treading on SAP.
Hmm.... there is only one way that I can think about in SAP and we can get all most all features on Parallel processing from this way.


CALL FUNCTION 'Fetch_Data'
STARTING NEW TASK 'Fetch'
performing RETURN_FROM_WAIT ON END OF TASK
     EXPORTING
input            = input
TABLES
output             = output
EXCEPTIONS
COMMUNICATION_FAILURE = 1
SYSTEM_FAILURE        = 2.





Important : you cant use any import parameters on the function no this
method the only option is to using the RETURN_FROM_WAIT which is a
perform.


For Eg when you want to fetch data parallel do it using 2 functions and using the perform
you can have  a flag to make sure that fetching is completed.
  
This is just a over view I got this document from Daniel Perecky
Multi Threading

this has lots of information no how to program this way.
I would love to see some comments about this :)

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.

PARAMETERS: rows 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.





Thursday, April 23, 2009

Use of binary search option

When a programmer uses the read command, the table is sequentially searched. This slows down the processing. Instead of this, use the binary search addition. The binary search algorithm helps faster search of a value in an internal table. It is advisable to sort the internal table before doing a binary search. Binary search repeatedly divides the search interval in half. If the value to be searched is less than the item in the middle of the interval, the search is narrowed to the lower half, otherwise the search is narrowed to the upper half.

Not Recommended

Read table int_fligh with key airln = ‘LF’.

Recommended

Read table int_fligh with key airln = ‘LF’ binary search.


source: http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_BinarySearch.asp

Modifying a group of lines of an internal table

Use the variations of the modify command to speed up this kind of processing.

Not recommended

Loop at int_fligh.

If int_fligh-flag is initial.

Int_fligh-flag = ‘X’.

Endif.

Modify int_fligh.

Endloop.

Recommended

Int_fligh-flag = ‘X’.

Modify int_fligh transporting flag where flag is initial.


source: http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_ModifyingGroupOfLines.asp


Google