Saturday, March 26, 2011

Event in ABAP Report


Event in ABAP report determine process flow of a program. The events are triggered depended on the way the output is generated. They begin after event keyword and end when the next event reached.

Event keyword:

INITIALIZATION.

Occurs when report initialized.
We can use it to check user authorization or prepare output for selection screen.



AT SELECTION-SCREEN OUTPUT :

Occurs each time selection screen about to generated.
We can use it to modify selection screen, for example hide / unhide parameter.

AT SELECTION-SCREEN.

Occurs each user command in selection screen. we can use it to perform checking on user input.

START-OF-SELECTION

Occurs after the standard selection screen has been processed.,
data is read in this event.

END-OF-SELECTION

Occurs after start-of-selection.

TOP-OF-PAGE

Occurs when a new page starts.
Use it for write report header.

END-OF-PAGE

Occurs when a page ends.
Use it for write report footer.

AT LINE-SELECTION

Occurs when the user double-click on report.

AT USER-COMMAND

Occurs when the user push toolbar button.

This is program to demonstrate how to use event properly.


    REPORT ZAALGAL0008
    LINE-COUNT 10(1).

    TABLES: sflight.

    DATA: BEGIN OF t_report OCCURS 3,
    carrid LIKE sflight-carrid,
    connid LIKE sflight-connid,
    END OF t_report.

    *begin selection screen

    PARAMETERS p_datum LIKE sy-datum.
    PARAMETERS p_check AS CHECKBOX.

    *end selection screen

    INITIALIZATION.

    *begin initialization

    MOVE sy-datum TO p_datum.

    *end initialization

    AT SELECTION-SCREEN.
    *begin at selection-screen
    MESSAGE I888(sabapdocu) WITH 'At selection-screen'.
    IF p_check = 'X'.
    MESSAGE E888(sabapdocu) WITH 'Clear checkbox'.
    ENDIF.
    *end at selection-screen

    AT SELECTION-SCREEN OUTPUT.
    *begin at selection-screen output
    MESSAGE I888(sabapdocu) WITH 'At selection-screen output'.
    *end at selection-screen output

    START-OF-SELECTION.
    *begin start-of-selection.
    MESSAGE I888(sabapdocu) WITH 'start-of-selection'.
    SELECT * FROM sflight.
    MOVE sflight-carrid TO t_report-carrid.
    MOVE sflight-connid TO t_report-connid.
    APPEND t_report.
    ENDSELECT.
    *end start-of-selection.

    END-OF-SELECTION.
    *begin end-of-selection.
    MESSAGE I888(sabapdocu) WITH 'end-of-selection'.
    FORMAT COLOR col_normal.
    DO 30 TIMES.
    LOOP AT t_report.
    WRITE / t_report-carrid.
    WRITE t_report-connid.
    ENDLOOP.
    ENDDO.
    *end end-of-selection.

    TOP-OF-PAGE.
    FORMAT COLOR col_heading.
    WRITE 'This is header'.

    END-OF-PAGE.
    FORMAT COLOR col_total.
    WRITE 'This is footer'.

    AT LINE-SELECTION.
    WRITE: / 'Cursor Row:', sy-curow.
    WRITE: / 'Cursor Col:', sy-cucol.

Monday, March 21, 2011

How to declare internal table with header line and without header line.

internal table with header line.

data: begin of itab occurs 0,
       num1 type i,
       num2 type i,
       ........,
       ........,
      end of itab.

internal table without header line.

types: begin of itab,
        num1 type i,
        num2 type i,
        ........,
        ........,
       end of itab.
data: itab1 type itab occurs 0.


Internal table is declared by many ways:

(A)
Data : BEGIN OF IT_TAB occurs 10,
       num1 type i,
        num2 type i,
       END OF IT_TAB.

(B)
TYPES : BEGIN OF tT_TAB,
        num1 type i,
        num2 type i,
        END OF tT_TAB.

DATA : tT_TAB TYPE STANDARD TBLE OF tT_TAB with header line.

(C)
TYPES : BEGIN OF tT_TAB,
        num1 type i,
        num2 type i,
        END OF tT_TAB.

DATA : iT_TAB TYPE STANDARD OF tT_TAB.
   
(D)
DATA : BEGIN OF IT_TAB,
       num1 type i,
        num2 type i,
       END oF IT_TAB.

DATA : wa_TAB LIKE LINE OF IT_TAB,
       wa_TAB TYPE OF IT_TAB

An Analysis of Component-based Software Development -Maximize the reuse of existing software

Check out this SlideShare Presentation:

SAP FI Configuration Guide

Check out this SlideShare Presentation:

SAP BAPI setp-by-step

Check out this SlideShare Presentation:

Example of SYMBOLS and ICONS

REPORT  ZSYMBOLSANDICONS.

INCLUDE  <LIST>.  
WRITE: / 'Phone :', SYM_PHONE  AS  SYMBOL.
WRITE: / 'Alarm :', ICON_ALARM  AS  ICON.
WRITE: / 'Green Light :',
               ICON_GREEN_LIGHT  AS  ICON  HOTSPOT.
FORMAT HOTSPOT ON.
  WRITE: / 'Hello ABAP', 'Hi!'.
FORMAT HOTSPOT OFF.

Example of COLOR Format STATEMENT

REPORT  ZCOLORFORMATSTATEMENT.

FORMAT  COLOR  1.
WRITE: / ‘Hello World’, ‘Test’  COLOR  7.
FORMAT  COLOR  OFF.

Example of Frame sy-vline, U_line

REPORT  ZFrameTEST


uline: /(45).
write: /1 sy-vline, 'Column #1',
          15 sy-vline, 'Column #2',
          30 sy-vline, 'Column #3',
          45 sy-vline.
uline: /(45).

Example of TOP-OF-PAGE formatting

REPORT zHeaderColorTest.

TOP-OF-PAGE.
  FORMAT COLOR 1.
  WRITE: / 'Report Header'.
  ULINE.

START-OF-SELECTION.
  DO 100 TIMES.
    WRITE: / sy-index.
  ENDDO.

Sunday, March 20, 2011

Example of using Describe Table in ABAP Programming

DESCRIBE TABLE is used to count the Total rows in a table.

REPORT  Z_STUFFING_REPORT.

TABLES:   MARA.
       
select single * from MARA where ERSDA = '04/3/2011'.

DATA: LIN TYPE I.
      
DESCRIBE TABLE MARA LINES LIN.
 
write:/ 'Total Rows:', LIN.

Example of using Substring in ABAP Programming

REPORT  Z_STUFFING_REPORT.

TABLES:   MARA.
       

select single * from MARA where ERSDA = '04/3/2011'.


DATA: LIN TYPE I,
        tues1 TYPE i,
        tues2 TYPE i,
        total_tues TYPE i.
 

DESCRIBE TABLE MARA LINES LIN.
 

Loop at MARA.
    DESCRIBE TABLE MARA LINES LIN.
    s = MARA-MATKL+0(1).
    IF s = '2'.
      tues1 = tues1 + 1.
    else.
      tues2 = tues2 + 2.
    ENDIF.
  endloop.

total_tues = tues1 + tues2.

write:/ 'Total Tues: ', total_tues.

Example of using Substring in ABAP Programming

REPORT  Z_STUFFING_REPORT.

TABLES:   MARA.
       

select single * from MARA where ERSDA = '04/3/2011'.


DATA: LIN TYPE I,
        tues1 TYPE i,
        tues2 TYPE i,
        total_tues TYPE i.
 

DESCRIBE TABLE MARA LINES LIN.
 

Loop at MARA.
    DESCRIBE TABLE MARA LINES LIN.
    s = MARA-MATKL+0(1).
    IF s = '2'.
      tues1 = tues1 + 1.
    else.
      tues2 = tues2 + 2.
    ENDIF.
  endloop.

total_tues = tues1 + tues2.

write:/ 'Total Tues: ', total_tues.

The ABAP Query

Check out this SlideShare Presentation:

Drop Down lists in the selection parameters

PROGRAM ztest.   TYPE-POOLS : vrm.   DATA : name TYPE vrm_id,        list TYPE vrm_values,        value LIKE LINE OF list. ...