Jan 25, 2014

Display data dynamically using Field Symbols

1.     Introduction: - Displaying the table contents dynamically as per table name mentioned on selection screen with help of field symbols.  If user enters MARA, then the data from MARA table is retrieved. If VBAK, then VBAK data is shown.  

2.     Steps:- 
Declare two parameter variables as below:-
Create a field symbol as below:-
Initially check whether table exists or not.
If table exists in database then by using create data statement create the data object and assign the reference to data object of w_dref reference variable.
Now assign the reference variable to field symbol as below:
In runtime after assign statement the <t_itab> structure will be same as table name entered on selection screen.
Now select the data from database and put it in field-symbol (dynamic internal table).
Now create the field catalog by using the function module .
Display the data by using function module  as below:-
  
Example:-
Give table name as mara on selection screen and no of records as 100 and press F8. 
List is displayed as below:
Now give table name as VBAK and press F8.

3.     Summary:-
The importance of this tutorial is to display the data as per table name mentioned on selection screen by user with Field symbols concept.
a)     First declare the two parameters one for table name and other for no of records to be displayed.
b)    Declare the field symbol of type standard table.
c)     Check table name given on selection screen exists or not.
d)    Create the internal table at runtime and select the data from table and place it in dynamic internal table (Field symbol).
e)     Create the field catalog and display the data.  
4.     Source Code:-
REPORT y_saptechnical_dynamic NO STANDARD PAGE HEADING.
*"Type-pool............................................................
TYPE-POOLS : slis.*"Parameters elements..................................................
PARAMETERS : p_table TYPE tabname OBLIGATORY,       " Table Name
             p_no    
TYPE i .                       " No of Records to be displayed

DATA:
  w_dref    
TYPE REF TO data,          " w_dref reference variable
  t_line    
TYPE c LENGTH 20.          " w_line to hold a line
DATA :
  t_fcat  
TYPE slis_t_fieldcat_alv.

FIELD-SYMBOLS: <t_itab> 
TYPE STANDARD TABLE.

START-OF-SELECTION.
  
SELECT SINGLE
         tabname                       
" Table Name
    
FROM dd02l
    
INTO t_line
   
WHERE tabname   EQ p_table
     
AND as4vers   EQ ' '
     
AND as4local  EQ 'A'
     
AND tabclass  NE 'INTTAB'
     
AND tabclass  NE 'APPEND'.

  
IF sy-subrc EQ 0.
    
CREATE DATA w_dref TYPE STANDARD TABLE OF (p_table).
    
ASSIGN w_dref->* TO <t_itab>.
    
IF sy-subrc EQ 0.
      
SELECT *                         " All Fields
        
FROM (p_table)
        
INTO TABLE <t_itab> UP TO p_no ROWS.

      
IF sy-subrc EQ 0.
        
PERFORM fill_catalog.
        
PERFORM display.
      ELSE.
        
MESSAGE text-002 TYPE 'S'.
        EXIT.
      ENDIF.                           
" IF sy-subrc EQ 0...
    ELSE.
      
MESSAGE text-003 TYPE 'S'.
      EXIT.
    ENDIF.
  ELSE.
    
MESSAGE text-003 TYPE 'S'.
    
LEAVE LIST-PROCESSING.
  ENDIF.                               
" IF sy-subrc EQ 0...
FORM display .
  
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    
EXPORTING
      it_fieldcat   = t_fcat
    
TABLES
      t_outtab      = <t_itab>
    
EXCEPTIONS
      program_error = 
1
      
OTHERS        = 2.
  
IF sy-subrc <> 0.
    
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno DISPLAY LIKE 'E'
            
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    EXIT.
  ENDIF.                               
" IF sy-subrc <> 0...
ENDFORM.                               
" DISPLAY
FORM fill_catalog .
  
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    
EXPORTING
      i_program_name         = sy-repid
      i_structure_name       = p_table
    
CHANGING
      ct_fieldcat            = t_fcat
    
EXCEPTIONS
      inconsistent_interface = 
1
      program_error          = 
2
      
OTHERS                 = 3.
  
IF sy-subrc <> 0.
    
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno DISPLAY LIKE 'E'
            
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    EXIT.
  ENDIF.                               
" IF sy-subrc <> 0...
ENDFORM.                               
" FILL_CATALOG



Source:
http://saptechnical.com/Tutorials/ABAP/FS/Index.htm
by Vineesh Batchu, Yash Technologies



Oct 17, 2013

Using Sorted table and Index while processing Internal tables

There would have been many instances where we would have to process large entries in an internal table with a WHERE condition. This article is intended to demonstrate the comparison between three different methods in handling this situation.  
First Method: The normal method used by most of us. Standard internal table processing using WHERE condition
Second Method: Same as above, but here we would be using the Sorted table
Third Method: Sorted table and using the Index  
Following is the demo program illustrating the above three methods:

REPORT ZINTERNAL_TABLE_OPERATIONS.
* Program to find the best method in reading the internal tables
* Author: Suresh Kumar Parvathaneni
* Type declaration
TYPES:
  BEGIN OF TY_MARA,
    MATNR LIKE MARA-MATNR,
    MTART LIKE MARA-MTART,
  END OF TY_MARA.
* Internal table declaration
DATA:
  T_MARA TYPE STANDARD TABLE OF TY_MARA,
  T_MARA1 TYPE SORTED TABLE OF TY_MARA
          WITH NON-UNIQUE KEY MTART.
* Variable declaration
DATA:
  W_COUNTER TYPE I,
  W_RUNTIME1 TYPE I,
  W_RUNTIME2 TYPE I,
  W_TABIX LIKE SY-TABIX.
* Table workarea definition
DATA:
  WA_MARA TYPE TY_MARA.
SELECT MATNR                           " Material Number
       MTART                           " Material Type
  FROM MARA
  INTO TABLE T_MARA.
T_MARA1[] = T_MARA[].
* CASE 1: Processing internal table using LOOP..WHERE Condition
GET RUN TIME FIELD W_RUNTIME1.
LOOP AT T_MARA INTO WA_MARA WHERE MTART EQ 'FHMI'.
  ADD 1 TO W_COUNTER.
ENDLOOP.
GET RUN TIME FIELD W_RUNTIME2.
* Calculate Runtime
W_RUNTIME2 = W_RUNTIME2 - W_RUNTIME1.
WRITE W_RUNTIME2.
CLEAR W_COUNTER.
* CASE 2: Using a Sorted table
GET RUN TIME FIELD W_RUNTIME1.
LOOP AT T_MARA1 INTO WA_MARA WHERE MTART EQ 'FHMI'.
  ADD 1 TO W_COUNTER.
ENDLOOP.
GET RUN TIME FIELD W_RUNTIME2.
* Calculate Runtime
W_RUNTIME2 = W_RUNTIME2 - W_RUNTIME1.
WRITE W_RUNTIME2.
CLEAR W_COUNTER.
* CASE 3: Using INDEX on a sorted table
GET RUN TIME FIELD W_RUNTIME1.
READ TABLE T_MARA1 INTO WA_MARA WITH KEY MTART = 'FHMI'.
IF SY-SUBRC EQ 0.
  W_TABIX = SY-TABIX + 1.
  ADD 1 TO W_COUNTER.
  LOOP AT T_MARA1 INTO WA_MARA FROM W_TABIX.
    IF WA_MARA-MTART NE 'FHMI'.
      EXIT.
    ENDIF.
    ADD 1 TO W_COUNTER.
  ENDLOOP.
ENDIF.
GET RUN TIME FIELD W_RUNTIME2.
* Calculate Runtime
W_RUNTIME2 = W_RUNTIME2 - W_RUNTIME1.
WRITE W_RUNTIME2.

Following is the analysis report in microseconds, as per the data volume:  
Records: 21,390
Iteration No
Using NormalLOOP & WHERE
Using Sorted table LOOP & WHERE
Using INDEX on Sorted table
1
897
887
11
2
839
879
10
3
839
877
10
4
834
880
9
5
842
837
10
Records: 132,693
Iteration No
Using NormalLOOP & WHERE
Using Sorted table LOOP & WHERE
Using INDEX on Sorted table
1
34239 
35774 
3567
2
34271 
38250 
3592
3
34492 
36534 
3554
4
34198 
35695 
3584

Sorted table might have given a better performance here if the field in the WHERE condition is the first field in the internal table. However, from the above statistics, we can say that method 3 is better than the other 2 methods. In production environment, the data would be huge and the performance could be much improved with this simple technique.


Thanks to: Suresh Kumar Parvathaneni


Oct 31, 2012

List of FI User Exits

During create the following may be usueful: 
SDVFX001 

User exit header line in delivery to accounting 
SDVFX002 

User exit for A/R line in transfer to accounting 
SDVFX003 

User exit cash clearing in transfer to accounting 
SDVFX004 

User exit G/L line in transfer to accounting 
SDVFX005 

User exit reserves in transfer to accounting 
SDVFX006 

User exit tax line in transfer to accounting 
SDVFX007 

User exit: Billing plan during transfer to Accounting 
SDVFX008 

User exit: Processing of transfer structures SD-FI 
SDVFX009 

Billing doc. processing KIDONO (payment reference number) 
SDVFX010 

User exit item table for the customer lines 
SDVFX011 

Userexit for the komkcv- and kompcv-structures 
V05I0001 

User exits for billing index 
V05N0001 

User Exits for Printing Billing Docs. using POR Procedure 
V60A0001 

Customer functions in the billing document 
V60P0001 

Data provision for additional fields for display in lists 
V61A0001 

Customer enhancement: Pricing 
J_3RSINV