Monday, February 13, 2012

Day 3

Let's learn about Reports.

Reports are of 3 types.
  1. Classical
  2. Interactive
  3. ALV - Mostly used reports.

Classical Report events are as follows

  1. Intialization
  2. At selection screen
  3. Start of selection
  4. End of selection
  5. Top of Page
  6. End of Page


Classical Report

TABLES MARA.
TYPES: BEGIN OF stu,
matnr TYPE mara-matnr,
mtart TYPE mara-mtart,
mbrsh TYPE mara-mbrsh,
matkl TYPE mara-matkl,
meins TYPE mara-meins,
END OF stu.

DATA: wa TYPE stu,
itab TYPE TABLE OF stu.

DATA Count TYPE i.
SELECT-OPTIONS: S_matnr for mara-matnr. " for letting you writ at-seslection command for the report"

INITIALIZATION.
Count = 5.

AT SELECTION-SCREEN.
IF S_matnr is initial.
MESSAGE 'Enter Value to Proceed' TYPE 'E'. " this is the error message that is going to display."


ENDIF.

START-OF-SELECTION.
SELECT matnr mtart mbrsh matkl meins FROM MARA INTO TABLE itab WHERE Matnr in S_matnr.

LOOP AT Itab INTO wa.
Count = count + 5.
write:/ count, wa-matnr, wa-mtart, wa-mbrsh, wa-matkl, wa-meins.

ENDLOOP.

END-of-SELECTION.

TOP-OF-Page.

WRITE:/ 'Header'.

end-of-PAGE.
WRITE:/ 'Footer'.


INTERACTIVE REPORT
In an interactive report , we write all the codes just like a classical report, on top of that we write at line selection line to make it interactive.

for that

apart from the above prog u need to include the data u want it to display from the other table . In this case , if we click on matnr we want the info of matkx.
so in the begin of stu line include.

maktx type mara-maktx


at LINE-SELECTION.
SELECT
matnr
maktx from makt INTO TABLE itab1 where matnr = wa-matnr.

LOOP AT itab1 INTO wa1.
WRITE:/ wa1-matnr, wa1-maktx.

ENDLOOP.


II exercise linking vbrk and vbrp

TABLES: VBRK , VBRP.

TYPES: BEGIN OF stu,
vbeln TYPE vbrk-vbeln,
vbtyp TYPE vbrk-vbtyp,
vtweg TYPE vbrk-vtweg,
vsbed TYPE vbrk-vsbed,
posnr TYPE vbrp-posnr,
END OF stu.

DATA: COUNT TYPE I,
WA TYPE STU,
ITAB TYPE TABLE OF STU,
WA1 TYPE STU,
ITAB1 TYPE TABLE OF STU.
SELECT-OPTIONS : S_VBELN FOR vbrk-vbeln.

INITIALIZATION.

COUNT = 1.

AT SELECTION-SCREEN.
IF S_VBELN IS INITIAL.
MESSAGE: 'PLEASE ENTER THE VALUE TO PROCEED' TYPE 'E'.
ENDIF.

START-OF-SELECTION.

SELECT vbeln
vbtyp
vtweg
vsbed FROM VBRK INTO TABLE ITAB WHERE VBELN IN S_VBELN.

LOOP AT ITAB INTO WA.
COUNT = COUNT + 1.
WRITE:/ COUNT, WA-VBELN, WA-VBTYP, WA-VTWEG, WA-VSBED.
ENDLOOP.


END-OF-SELECTION.

TOP-OF-PAGE.
WRITE:/ 'HEADER'.
END-OF-PAGE.
WRITE:/ 'FOOTER'.

at LINE-SELECTION.
SELECT vbeln posnr from vbrp INTO TABLE itab1 WHERE VBELN = wa-VBELN.
LOOP AT itab1 INTO wa1.
WRITE:/ wa1-vbeln, wa1-posnr.

ENDLOOP.

ALV REPORT

HERE YOU NEED TO WRITE A ROUTINE AND A SUB ROUTINE.

PERFORM SELECT.
PERFORM DESIGN.
PERFORM DISPLAY


TYPE-POOLS slis.
TYPES: BEGIN OF stu,
carrid TYPE scarr-carrid,
carrname TYPE scarr-carrname,
currcode TYPE scarr-currcode,
END OF stu.

DATA: wa_scarr TYPE stu,
i_scarr TYPE TABLE OF stu.
DATA: FWA TYPE SLIS_FIELDCAT_ALV,
F_TAB TYPE TABLE OF SLIS_FIELDCAT_ALV.

"noW WRITE ROTUINE"

PERFORM SELECT.
PERFORM DESIGN.
PERFORM DISPLAY.

"NOW WRITE SUB-ROTUINE"

FORM SELECT.
SELECT Carrid
carrname
currcode FROM SCARR INTO TABLE I_SCARR.
ENDFORM.

FORM dESIGN.
FWA-FIELDNAME = 'CARRID'.
FWA-SELTEXT_M = 'AIRCODE'.
FWA-KEY = 'X'. " TO mENTION THAT IT IS A KEY FIELD"
APPEND FWA TO F_TAB.
CLEAR FWA.

FWA-FIELDNAME = 'CURRCODE'.
FWA-SELTEXT_M = 'CURRENCY'.
APPEND FWA TO F_TAB.
CLEAR FWA.

ENDFORM.


FORM DISPLAY.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
* I_CALLBACK_PROGRAM = ' '
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
IT_FIELDCAT = F_TAB[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = I_SCARR[]
* 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.

No comments:

Post a Comment