Tuesday, June 11, 2013

How to add summition icon in ALV report

REPORT zsummIconExample .

TYPE-POOLS: slis.  " SLIS contains all the ALV data types

*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook     TYPE TABLE OF sbook.
DATA: it_fieldcat  TYPE slis_t_fieldcat_alv,
      wa_fieldcat  TYPE slis_fieldcat_alv.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.

*Fetch data from the database
  SELECT * FROM sbook INTO TABLE it_sbook.

*Build field catalog
  wa_fieldcat-fieldname  = 'CARRID'.    " Fieldname in the data table
  wa_fieldcat-seltext_m  = 'Airline'.   " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'CONNID'.
  wa_fieldcat-seltext_m  = 'Con. No.'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'FLDATE'.
  wa_fieldcat-seltext_m  = 'Date'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'BOOKID'.
  wa_fieldcat-seltext_m  = 'Book. ID'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'PASSNAME'.
  wa_fieldcat-seltext_m  = 'Passenger Name'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'LOCCURAM'.
  wa_fieldcat-seltext_m  = 'Price'.
*Calculate Total for Price
  wa_fieldcat-do_sum     = 'X'.
  wa_fieldcat-datatype = 'QUAN'.
  APPEND wa_fieldcat TO it_fieldcat.

*Pass data and field catalog to ALV function module to display ALV list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      it_fieldcat   = it_fieldcat
    TABLES
      t_outtab      = it_sbook
    EXCEPTIONS
      program_error = 1
      OTHERS        = 2.

Output


Disable Icons in SAP ALV Toolbar

Use below steps to disable icons in ABAP ALV toolbar.
  1. Fetch data from database table.
  2. Build field catalog and fill the excluding table with function codes of icons that you want to disable. &ILT& is the function code for Filter Icon.
  3. Pass field catalog and excluding table to function module ‘REUSE_ALV_GRID_DISPLAY’.
TYPE-POOLS: slis.  " SLIS contains all the ALV data types
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook     TYPE TABLE OF sbook.
DATA: it_fieldcat  TYPE slis_t_fieldcat_alv,
      wa_fieldcat  TYPE slis_fieldcat_alv.
DATA: it_excluding TYPE slis_t_extab,
      wa_excluding TYPE slis_extab.
DATA: g_repid      TYPE sy-repid.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  g_repid = sy-repid.
*Fetch data from the database
  SELECT * FROM sbook INTO TABLE it_sbook.

*Build field catalog
  wa_fieldcat-fieldname  = 'CARRID'.    " Fieldname in the data table
  wa_fieldcat-seltext_m  = 'Airline'.   " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'CONNID'.
  wa_fieldcat-seltext_m  = 'Con. No.'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'FLDATE'.
  wa_fieldcat-seltext_m  = 'Date'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'BOOKID'.
  wa_fieldcat-seltext_m  = 'Book. ID'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'PASSNAME'.
  wa_fieldcat-seltext_m  = 'Passenger Name'.
  APPEND wa_fieldcat TO it_fieldcat.

*Build excluding table. Append the function codes of the icons to
*excluding table that you want to disable
  wa_excluding-fcode = '&ILT'.  " Function code for filter icon
  APPEND wa_excluding TO it_excluding.

*Pass data and field catalog to ALV function module to display ALV list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = g_repid
      it_fieldcat        = it_fieldcat
      it_excluding       = it_excluding
    TABLES
      t_outtab           = it_sbook
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.

aba-alv-disable-icon

What is ABAP Data Dictionary?

SQL can be divided into following 2 parts.
  • DML – Data Manipulation Language
  • DDL – Data Definition Language
DML part consists of query and update commands like SELECT, UPDATE, DELETE, INSERT etc. ABAP programs handle DML part of SQL.
DDL part consist of commands like CREATE TABLE, ALTER TABLE, DROP TABLE, CREATE INDEX etc. ABAP Dictionary handles DDL part of SQL.
So ABAP Dictionary is used to create and manage data definitions (metadata). ABAP Dictionary is used to create Tables, Data Elements, Domains, Views, Lock Objects etc.

What is Open SQL?

Open SQL is a set of ABAP statements that performs operations like reads, modifies or deletes data in the SAP database. Open SQL is independent of the database system, so the syntax of the open SQL is uniform for all the databases supported by SAP.
All open SQL statements are passed to the database interface. The DB interface converts the open SQL to native SQL and passes it on to the database.
List of Open SQL statements
OPEN SQLDESCRIPTION
SELECTReads data from database
INSERTInserts lines to database
UPDATEChanges the contents of lines in database
MODIFYInserts lines into database or changes the contents of existing lines
DELETEDeletes lines from database
All Open SQL statements fill the following two system fields:
  • SY-SUBRC – After every Open SQL statement, the system field SY-SUBRC contains the value 0 if the operation was successful, a value other than 0 if not.
  • SY-DBCNT – After an open SQL statement, the system field SY-DBCNT contains the number of database lines processed.

Saturday, June 8, 2013

Debug SE16 to allow record changes


If you are not authorized to change table entries or the table has been create without table maintenance allowed (all SAP tables), you can still change entries via data browser (SE16) by means of debugging. The process is as follows:

1. Display record entries for desired table via SE16 or SE11.
2. Select record which requires updating by highlighting it and pressing the display icon (glasses, F7).
3. Type /h in command box and press enter.
4. Now press enter again and you should enter debugging mode
5. Change the value of code from ‘SHOW’ to ‘EDIT’, remember to press the ‘change field contents’
    icon (pencil) in-order to store new value.
6. Press F8 (execute) to leave debug.
7. You should now have change access to the selected record.
8. Hit ‘SAVE’ to save any changes.
9. Remember there is a reason why you can’t do this without debugging it, one reason being that it could
    introduce inconsistencies in the table data.

Edit SAP tables

Step-by-step
1) Go to transaction SE16N or alternatively use shortcut and type just ‘N’. Enter here the table that you wish to edit.
SE16N or just N
SE16N or just N
2) In the command field enter ‘&SAP_EDIT’ and press enter. The maintenance indicator in SE16N will switch on.
Command field entry
Command field entry
3) Narrow your search results by entering selection criteria and press F8 to run the report.
4) You can remove lines or just add/change data and press save.
&SAP_EDIT - SE16N - Table results
&SAP_EDIT - SE16N - Table results

Table Maintenance Generator in SAP


Follow these steps to create table maintenance generator.
1. Execute TCODE SE54.
2. Enter the table name. Select “Generated Objects.” Click Create.

02112010-tmg-01
3. Click “Yes“
02112010-tmg-02

4. Now enter these following settings, just like shown in pictures below.

02112010-tmg-03
5. Select “Generated Objects > Create“.
02112010-tmg-04

Example of List Box

REPORT  ZLISTBOX.

types: begin of t_ekko,
  ebeln type ekko-ebeln,
  end of t_ekko.
data: it_ekko TYPE STANDARD TABLE OF t_ekko,
      wa_ekko like line of it_ekko.

TYPE-POOLS: VRM.

DATA: NAME  TYPE VRM_ID,
      LIST  TYPE VRM_VALUES,
      VALUE LIKE LINE OF LIST.

PARAMETERS: P_PARM(10) AS LISTBOX VISIBLE LENGTH 10.

*AT SELECTION-SCREEN OUTPUT.
AT SELECTION-SCREEN OUTPUT.

  SELECT ebeln
   up to 10 rows
    from ekko
    into table it_ekko.

  loop at it_ekko into wa_ekko.
    VALUE-KEY =  wa_ekko-ebeln.
    VALUE-TEXT = wa_ekko-ebeln.
    APPEND VALUE TO LIST.
  endloop.

  NAME = 'P_PARM'.
  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      ID     = NAME
      VALUES = LIST.


Monday, June 3, 2013

Reading data from a file (presentation server) in ABAP

REPORT ZREADDATA.

* Data declarations for later use
PARAMETERS FILENAME(128) DEFAULT 'c:\users\default\testfile.dat'
                         LOWER CASE.
TABLES CUSTOMERS.
DATA ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100
                   WITH HEADER LINE.
CALL FUNCTION 'WS_UPLOAD'
     EXPORTING
          FILENAME        = FILENAME
     TABLES
          DATA_TAB        = ALL_CUSTOMERS
     EXCEPTIONS
          FILE_OPEN_ERROR = 1
          OTHERS          = 2.
CASE SY-SUBRC.
  WHEN 1.
    WRITE 'Error when file opened'.
    EXIT.
  WHEN 2.
    WRITE 'Error during data transfer'.
    EXIT.
ENDCASE.
* Display the result
LOOP AT ALL_CUSTOMERS.
  WRITE: / ALL_CUSTOMERS-NAME,
           ALL_CUSTOMERS-CITY.
ENDLOOP.


Transferring data to a file in ABAP

REPORT ZTRANSFERDATA.

* Data declarations for later use
PARAMETERS FILENAME(128) DEFAULT '/usr/tmp/testfile.dat'
                         LOWER CASE.
TABLES CUSTOMERS.
DATA MSG_TEXT(50).
* Get data for file transfer
DATA ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100
                   WITH HEADER LINE.
SELECT * FROM CUSTOMERS INTO TABLE ALL_CUSTOMERS.
SORT ALL_CUSTOMERS BY CITY.
LOOP AT ALL_CUSTOMERS.
  WRITE: / ALL_CUSTOMERS-CITY,
           ALL_CUSTOMERS-NAME.
ENDLOOP.
* Opening the File
OPEN DATASET FILENAME FOR OUTPUT IN TEXT MODE
                      MESSAGE MSG_TEXT.
IF SY-SUBRC NE 0.
  WRITE: 'File cannot be opened. Reason:', MSG_TEXT.
  EXIT.
ENDIF.
* Transferring Data
LOOP AT ALL_CUSTOMERS.
  TRANSFER ALL_CUSTOMERS-NAME TO FILENAME.
ENDLOOP.
* Closing the File
CLOSE DATASET FILENAME.


Ordering query results in ABAP

REPORT ZORDERQUERY.

* Work area
TABLES CUSTOMERS.
* Reading table entries in a specified order
SELECT * FROM CUSTOMERS
       ORDER BY CITY NAME.
  WRITE: / CUSTOMERS-CITY,
           CUSTOMERS-NAME.
ENDSELECT.

Dynamic read table command in ABAP

REPORT ZDYREADTABLE.

* Parameters for reading a single line, can be modified by the end user
PARAMETERS: KEY1(10)         DEFAULT 'NAME',
            VALUE1(25),
            KEY2   LIKE KEY1 DEFAULT 'ID',
            VALUE2 LIKE VALUE1.
* Declarations for later use
TABLES CUSTOMERS.
DATA ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100
                   WITH HEADER LINE.
* Filling the internal table
SELECT * FROM CUSTOMERS INTO TABLE ALL_CUSTOMERS.
* Dynamic read table command
READ TABLE ALL_CUSTOMERS
   WITH KEY (KEY1) = VALUE1
            (KEY2) = VALUE2.
* Displaying the result
IF SY-SUBRC EQ 0.
  WRITE: / ALL_CUSTOMERS-ID,
           ALL_CUSTOMERS-NAME,
           ALL_CUSTOMERS-CITY,
           ALL_CUSTOMERS-TELEPHONE.
ELSE.
  WRITE 'Entry not found'.
ENDIF.


Application Log Creation in ABAP

LS_LOG-OBJECT = 'SALESORD'.
LS_LOG-SUBOBJECT = 'SALESITEM'.
CALL FUNCTION 'BAL_LOG_CREATE'
  EXPORTING
    I_S_LOG = LS_LOG
  IMPORTING
    E_LOG_HANDLE = L_LOGHAND
  EXCEPTIONS
    LOG_HEADER_INCONSISTENT = 1
    OTHERS = 2.
L_MSG-MSGTY = 'E'.
L_MSG-MSGID = 'B1'.
L_MSG-MSGNO = '999'.
L_MSG-MSGV1 = 'Update failed for'.
L_MSG-MSGV2 = LV_WI_ID.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
  EXPORTING
    I_LOG_HANDLE = L_LOGHAND
    I_S_MSG = L_MSG
  IMPORTING
    E_MSG_WAS_LOGGED = B_LOG
    E_MSG_WAS_DISPLAYED = B_DISP
  EXCEPTIONS
    LOG_NOT_FOUND = 1
    MSG_INCONSISTENT = 2
    LOG_IS_FULL = 3
    OTHERS = 4.
* save logs


CALL FUNCTION 'BAL_DB_SAVE'
  EXPORTING
    I_SAVE_ALL = 'X'
  EXCEPTIONS
    OTHERS = 1.