Wednesday, May 2, 2012


DIFFERENCE BERENCE TRANSPARENT, POOL, CLUSTER TABLE :



Transparent
Pool
Cluster
Contain a single table. Used to store master data
They are used to hold a large number of very small tables(stores customizing data or system data)
They are used to hold data from a few number of large tables.(stores system data)
It has a one-to-one relationship with a table in the database
It has a many-to-one relationship with a table in the database
It has a many-to-one relationship with table in the database
For each transparent table there is one associated table in the database
It is stored with other pooled tables in a single table called table pool in the database
Many cluster tables are stored in a single table in the database called a table cluster
The database table has the same name, same number of fields and the fields have the same names
The database table has different name, different number of fields and fields have different names
The database table has different name, different number of fields and fields have different names
There is only a single table
Table pools contain more tables than table clusters
Contains less tables than table pools
Single table can have one or more primary key
Primary key of each table does not begin with same fields or fields
Primary key of each table begins with same fields or fields
Secondary indexes can be created
Secondary indexes cannot be created
Secondary indexes cannot be created
They can be accessed using open and native SQL
They can be accessed using open SQL only
They can be accessed using open  SQL only
USE: They are used to hold master data e.g. Table vendors or table of customers. Example of transaction data is orders placed by customers
USE: They reduce the amount of database resources needed when many small tables have to be opened at the same time
USE: They would be used when the tables have primary key in common and data in these tables are all accesses simultaneously
 

Conversion of SAPSCRIPT to SMARTFORMS


SAP provides a conversion for SAPscript documents to SMARTforms.
This is basically a function module, called FB_MIGRATE_FORM. You can start this function module by hand (via SE37), or create a small ABAP which migrates all SAPscript forms automatically.
You can also do this one-by-one in transaction SMARTFORMS, under
Utilities -> Migrate SAPscript form.
You could also write a small batch program calling transaction SMARTFORMS and running the migration tool.

Wednesday, April 25, 2012

BLOCKED ALV :

Here is a code to implement Blocked ALV display. I hope this code will help u.


*&---------------------------------------------------------------------*
*& Report  ZALV_BLOCKED
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZALV_BLOCKED.

include ZALV_BLOCKED_TOP.
include ZALV_BLOCKED_SEL.
include ZALV_BLOCKED_SUB.

INITIALIZATION.

PERFORM LIST_INIT.

START-OF-SELECTION.

PERFORM FETCH_MARD CHANGING I_MARD.

PERFORM FETCH_MARC USING I_MARD CHANGING I_MARC.

PERFORM FETCH_MARA USING I_MARD CHANGING I_MARA.

PERFORM BUILD_FIELDCAT1 CHANGING I_FIELDCAT.

PERFORM BUILD_FIELDCAT2 CHANGING I_FIELDCAT1.

PERFORM BUILD_FIELDCAT3 CHANGING I_FIELDCAT2.

PERFORM DISPLAY_MARA USING I_MARA.

PERFORM DISPLAY_MARC USING I_MARC.

PERFORM DISPLAY_MARD USING I_MARD.

PERFORM DISPLAY_BLOCK.


TYPE-POOLS : SLIS.

TYPES : BEGIN OF TY_MARA,
        MATNR TYPE MATNR,
        MTART TYPE MTART,
        MBRSH TYPE MBRSH,
        MATKL TYPE MATKL,
        END OF TY_MARA,
      TY_T_MARA TYPE STANDARD TABLE OF TY_MARA,
        BEGIN OF TY_MARC,
          MATNR TYPE MATNR,
          WERKS TYPE WERKS_D,
          EKGRP TYPE EKGRP,
        END OF TY_MARC,
      TY_T_MARC TYPE STANDARD TABLE OF TY_MARC,
        BEGIN OF TY_MARD,
          MATNR TYPE MATNR,
          WERKS TYPE WERKS_D,
          LGORT TYPE LGORT_D,
          LABST TYPE LABST,
        END OF TY_MARD,
      TY_T_MARD TYPE STANDARD TABLE OF TY_MARD.

DATA : I_MARA TYPE TY_T_MARA,
       I_MARC TYPE TY_T_MARC,
       I_MARD TYPE TY_T_MARD.

DATA : GV_MATNR TYPE MATNR.

DATA : I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
       I_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV,
       I_FIELDCAT2 TYPE SLIS_T_FIELDCAT_ALV.

DATA: I_EVENTS TYPE SLIS_T_EVENT,
      W_EVENT TYPE SLIS_ALV_EVENT.

DATA : I_LAYOUT TYPE SLIS_LAYOUT_ALV.


*&---------------------------------------------------------------------*
*&  Include           ZALV_BLOCKED_SEL
*&---------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

  SELECT-OPTIONS : S_MATNR FOR GV_MATNR.

SELECTION-SCREEN END OF BLOCK B1.


*&---------------------------------------------------------------------*
*&  Include           ZALV_BLOCKED_SUB
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  FETCH_MARA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_I_MARA  text
*----------------------------------------------------------------------*
FORM FETCH_MARA USING FP_I_MARD TYPE TY_T_MARD
                CHANGING FP_I_MARA TYPE TY_T_MARA.

IF NOT FP_I_MARD IS INITIAL.
SELECT MATNR
       MTART
       MBRSH
       MATKL
  INTO TABLE FP_I_MARA
  FROM MARA
  FOR ALL ENTRIES IN FP_I_MARD
  WHERE MATNR = FP_I_MARD-MATNR.

ENDIF.

ENDFORM. " FETCH_MARA
*&---------------------------------------------------------------------*
*&      Form  FETCH_MARC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_MARA  text
*      <--P_I_MARC  text
*----------------------------------------------------------------------*
FORM FETCH_MARC USING FP_I_MARD TYPE TY_T_MARD
                 CHANGING FP_I_MARC TYPE TY_T_MARC.

  IF NOT FP_I_MARD IS INITIAL.
    SELECT MATNR
           WERKS
           EKGRP
      INTO TABLE FP_I_MARC
      FROM MARC
      FOR ALL ENTRIES IN FP_I_MARD
      WHERE MATNR = FP_I_MARD-MATNR.
  ENDIF.

ENDFORM. " FETCH_MARC
*&---------------------------------------------------------------------*
*&      Form  FETCH_MARD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_I_MARD  text
*      <--P_PERFORM  text
*      <--P_FETCH_MARA  text
*      <--P_I_MARA  text
*----------------------------------------------------------------------*
FORM FETCH_MARD CHANGING FP_I_MARD TYPE TY_T_MARD.

  SELECT MATNR
         WERKS
         LGORT
         LABST
    INTO TABLE FP_I_MARD
    FROM MARD
    WHERE MATNR IN S_MATNR.

ENDFORM. " FETCH_MARD
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_I_FIELDCAT  text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT1 CHANGING FP_I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

  DATA : W_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

w_fieldcat-col_pos = 1.
w_fieldcat-tabname = 'ty_t_mara'.
w_fieldcat-fieldname = 'MATNR'.
w_fieldcat-seltext_m = 'MATERIAL NUMBER'.

append w_fieldcat to i_fieldcat.
clear w_fieldcat.

w_fieldcat-col_pos = 2.
w_fieldcat-tabname = 'ty_t_final'.
w_fieldcat-fieldname = 'MTART'.
w_fieldcat-seltext_m = 'MATERIAL TYPE'.

append w_fieldcat to i_fieldcat.
clear w_fieldcat.

w_fieldcat-col_pos = 3.
w_fieldcat-tabname = 'ty_t_final'.
w_fieldcat-fieldname = 'MBRSH'.
w_fieldcat-seltext_m = 'INDUSTRY SECTOR'.

append w_fieldcat to i_fieldcat.
clear w_fieldcat.

w_fieldcat-col_pos = 4.
w_fieldcat-tabname = 'ty_t_final'.
w_fieldcat-fieldname = 'MATKL'.
w_fieldcat-seltext_m = 'MATERIAL GROUP'.

append w_fieldcat to i_fieldcat.
clear w_fieldcat.

ENDFORM. " BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_I_FIELDCAT1  text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT2 CHANGING FP_I_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV.

  DATA : W1_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

w1_fieldcat-tabname = 'ty_t_marc'.
w1_fieldcat-fieldname = 'MATNR'.
w1_fieldcat-seltext_m = 'MATERIAL NUMBER'.

append w1_fieldcat to i_fieldcat1.
clear w1_fieldcat.

w1_fieldcat-tabname = 'ty_t_marc'.
w1_fieldcat-fieldname = 'WERKS'.
w1_fieldcat-seltext_m = 'PLANT'.

append w1_fieldcat to i_fieldcat1.
clear w1_fieldcat.

w1_fieldcat-tabname = 'ty_t_marc'.
w1_fieldcat-fieldname = 'EKGRP'.
w1_fieldcat-seltext_m = 'PURCHASING GROUP'.

append w1_fieldcat to i_fieldcat1.
clear w1_fieldcat.

ENDFORM. " BUILD_FIELDCAT2
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT3
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_I_FIELDCAT2  text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT3 CHANGING FP_I_FIELDCAT2 TYPE SLIS_T_FIELDCAT_ALV.

  DATA : W2_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

w2_fieldcat-tabname = 'ty_t_mard'.
w2_fieldcat-fieldname = 'MATNR'.
w2_fieldcat-seltext_m = 'MATERIAL NUMBER'.

append w2_fieldcat to i_fieldcat2.
clear w2_fieldcat.

w2_fieldcat-tabname = 'ty_t_mard'.
w2_fieldcat-fieldname = 'WERKS'.
w2_fieldcat-seltext_m = 'PLANT'.

append w2_fieldcat to i_fieldcat2.
clear w2_fieldcat.

w2_fieldcat-tabname = 'ty_t_mard'.
w2_fieldcat-fieldname = 'LGORT'.
w2_fieldcat-seltext_m = 'STORAGE LOCATION'.

append w2_fieldcat to i_fieldcat2.
clear w2_fieldcat.

w2_fieldcat-tabname = 'ty_t_mard'.
w2_fieldcat-fieldname = 'LABST'.
w2_fieldcat-seltext_m = 'VALUATED STOCK'.

append w2_fieldcat to i_fieldcat2.
clear w2_fieldcat.

ENDFORM. " BUILD_FIELDCAT3
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_MARA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_MARA  text
*----------------------------------------------------------------------*
FORM DISPLAY_MARA USING FP_I_MARA TYPE TY_T_MARA.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
  EXPORTING
    IS_LAYOUT                        = I_LAYOUT
    IT_FIELDCAT                      = I_FIELDCAT
    I_TABNAME                        = 'MARA'
    IT_EVENTS                        = I_EVENTS
*   IT_SORT                          =
*   I_TEXT                           = ' '
  TABLES
    T_OUTTAB                         = FP_I_MARA
* EXCEPTIONS
*   PROGRAM_ERROR                    = 1
*   MAXIMUM_OF_APPENDS_REACHED       = 2
*   OTHERS                           = 3
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


ENDFORM. " DISPLAY_MARA
*&---------------------------------------------------------------------*
*&      Form  LIST_INIT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM LIST_INIT .

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
  EXPORTING
    I_CALLBACK_PROGRAM             = SY-REPID
*   I_CALLBACK_PF_STATUS_SET       = ' '
*   I_CALLBACK_USER_COMMAND        = ' '
*   IT_EXCLUDING                   =
          .


ENDFORM. " LIST_INIT
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_MARC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_MARC  text
*----------------------------------------------------------------------*
FORM DISPLAY_MARC USING FP_I_MARC TYPE TY_T_MARC.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
    EXPORTING
      IS_LAYOUT                        = I_LAYOUT
      IT_FIELDCAT                      = I_FIELDCAT1
      I_TABNAME                        = 'MARC'
      IT_EVENTS                        = I_EVENTS
*     IT_SORT                          =
*     I_TEXT                           = ' '
    TABLES
      T_OUTTAB                         = FP_I_MARC
*   EXCEPTIONS
*     PROGRAM_ERROR                    = 1
*     MAXIMUM_OF_APPENDS_REACHED       = 2
*     OTHERS                           = 3
            .
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


ENDFORM. " DISPLAY_MARC
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_MARD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_MARD  text
*----------------------------------------------------------------------*
FORM DISPLAY_MARD USING FP_I_MARD TYPE TY_T_MARD.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
  EXPORTING
    IS_LAYOUT                        = I_LAYOUT
    IT_FIELDCAT                      = I_FIELDCAT2
    I_TABNAME                        = 'MARD'
    IT_EVENTS                        = I_EVENTS
*   IT_SORT                          =
*   I_TEXT                           = ' '
  TABLES
    T_OUTTAB                         = FP_I_MARD
* EXCEPTIONS
*   PROGRAM_ERROR                    = 1
*   MAXIMUM_OF_APPENDS_REACHED       = 2
*   OTHERS                           = 3
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


ENDFORM. " DISPLAY_MARD
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_BLOCK
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISPLAY_BLOCK .

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
* EXPORTING
*   I_INTERFACE_CHECK             = ' '
*   IS_PRINT                      =
*   I_SCREEN_START_COLUMN         = 0
*   I_SCREEN_START_LINE           = 0
*   I_SCREEN_END_COLUMN           = 0
*   I_SCREEN_END_LINE             = 0
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER       =
*   ES_EXIT_CAUSED_BY_USER        =
* EXCEPTIONS
*   PROGRAM_ERROR                 = 1
*   OTHERS                        = 2
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


ENDFORM. " DISPLAY_BLOCK
ALV Report Without declaring Fieldcatalog :


*&---------------------------------------------------------------------*
*& Report  ZALV_AA_GRID
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZALV_AA_GRID.

TYPES : BEGIN OF TY_MARA,
        MATNR TYPE MATNR,
        MTART TYPE MTART,
        MBRSH TYPE MBRSH,
        MATKL TYPE MATKL,
        MEINS TYPE MEINS,
        END OF TY_MARA,
      TY_T_MARA TYPE STANDARD TABLE OF TY_MARA.

DATA : I_MARA TYPE TY_T_MARA,
       GV_MATNR TYPE MATNR.

DATA : I_ALV TYPE REF TO CL_GUI_ALV_GRID.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
  SELECT-OPTIONS : S_MATNR FOR GV_MATNR.
SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF SCREEN 9001.

SELECTION-SCREEN END OF SCREEN 9001.

SELECT MATNR
       MTART
       MBRSH
       MATKL
       MEINS
  INTO TABLE I_MARA
  FROM MARA
  WHERE MATNR IN S_MATNR.

CREATE OBJECT I_ALV EXPORTING I_PARENT = CL_GUI_CONTAINER=>SCREEN0.

          CALL METHOD I_ALV->SET_TABLE_FOR_FIRST_DISPLAY
          EXPORTING I_STRUCTURE_NAME = 'MARA'
          CHANGING IT_OUTTAB = I_MARA.

           CALL SELECTION-SCREEN 9001.
SAP ABAP  : How to get Started

Being able to use ABAP effectively requires more than just knowledge of the keywords. To be able to start with ABAP effectively you need to have a basic understanding of the architecture of the SAP NetWeaver Application Server ABAPand some of its strengths such as development on a central server or integrated software logistics (SAP Change and Transport system). And, of course, you need the knowledge of the basic tools of the ABAP development environment and ABAP itself as a language.
First of all try to write your first program i.e ''Hello World'' program in ABAP.
ABAP Flow of Events :

1. Load Of Program : When a program is called using SUBMIT or using a transaction code, then – at every call – a new internal session is opened and the event block is executed once at every call. You can initialize global data objects of the program here. The event block must be executed completely; otherwise, a runtime error will occur.Therefore, no statements are allowed to be executed that leave the event block without returning.At the first call of an external Procedure (sub-program or function module), the framework program of the called procedure is loaded into the internal session of the caller, thus triggering the event LOAD-OF-PROGRAM.

2. Initialization : This event keyword defines an event block whose event is triggered by the ABAP runtime environment during the flow of an executable program, directly after LOAD-OF-PROGRAM and before the selection screen processing of any existing standard selection screen. This gives you the one-time opportunity to initialize the input fields of the selection screen.

3. At Selection Screen :  The event keyword AT SELECTION-SCREEN provides you with several possibilities to carry out processing blocks while the system is processing the selection screen. To react on different events, that can occur when the selection screen is processed, the keyword AT SELECTION-SCREEN has various options. All the Validation Done on Selection Screen is done through this event. The AT SELECTION SCREEN event is triggered after the user enters value on the selection screen and presses enter or Executes it.

4. Start Of Selection : Start Of Selection is triggered after the selection screen is processed. In an executable program, all statements that are not declarations and that are listed before the first explicit processing block, or if the program does not contain any explicit processing blocks, then all functional statements of the program, are assigned to an implicit event block START-OF-SELECTION, which is inserted before any START-OF-SELECTION event blocks.If the program is linked to a logical database, preparatory tasks can be performed at START-OF-SELECTION before the logical database imports the data.

5. End Of Selection : END-OF-SELECTION is the last system event to be processed during the runtime of a report program.  It occurs after all logical database records have been read, and before any user-invoked events. END-OF-SELECTION occurs only once.

6. Top Of Page : TOP-OF-PAGE is used for page headers on the basic list only. TOP-OF-PAGE is triggered when the system encounters a WRITE, SKIP, or ULINE statement on the basic list. TOP-OF-PAGE occurs the moment the first line of the first page is written to the screen. NEW-PAGE also invokes the TOP-OF-PAGE event. This occurs when a new page is started – that is, immediately before the first line in a new page is to be output.

7. End Of Page : The END-OF-PAGE event is used for page footers. This event is triggered when the system encounters insufficient space on the current output page.  The LINE-COUNT statement within the REPORT statement specifies the size of the page area.  If a LINE-COUNT is not explicitly coded, the END-OF-PAGE event block will not be processed. So the LINE-COUNT is defined like this if the page contains 50 lines and 3 lines are for the footer then it should be written as LINE-COUNT 50(3).

8 .  At Line Selection : This statement defines an event block whose event is triggered by the ABAP runtime environment during the display of a screen list – provided the scren cursor is on a list line and you select a function using the function code PICK. Through the definition of this event block, the standard list status is automatically enhanced in such a way that the function code F2 and, with it, the double-click mouse function is linked up to the function code PICK.

9. At User Command : This statement defines an event block whose event is triggered by the ABAP runtime environment if, during the display of a screen list, a function with a self-defined function code was chosen.

10. At PFn : This statemet defines an event block whose event is triggered by the ABAP runtime environment during list display – provided the screen cursor is on a list line and a function is selected using the function code PFn. Here n stands for a number between 01 and 24. In the= standard list status, these function codes are assigned to the function keys of the input device.
How To Upload Logo in ALV ? 



 Logo should be uploaded into application server using transaction 'OAER'.
    1.     Go to Transaction OAER,
    2.     Give Class Name as PICTURES
    3.     Class type as OT
    4.     Object Key as the name of the Object u want to specify
    5.     Upon execution you would be prompted to give the file path details. Just upload which ever logo u want to display
    6.     Now you can use the same name in your ALV FM
    In your ALV program, you need to have event for TOP_OF_PAGE, and also this works only in case of Grid not in ALV LIS.