Google Search - Blog...........

ABAP - Interactive Report With All Events.

REPORT zwk22671 LINE-COUNT 40(3)
LINE-SIZE 200
NO STANDARD PAGE HEADING.

*---------------------------------------
*TABLES
*---------------------------------------
TABLES : mkpf , "MATERIAL DOCUMENT
mseg , "DOCUMENT SEGMENT : MATERIAL
t156t , "MOVEMENT TYPE TEXT
makt. "MATERIAL DESCRIPTIONS

*--------------------------------------------------------
**DECLARATION OF STRUCTURE , INTERNAL TABLES , VARIABLES
*--------------------------------------------------------
*STRUCTURE OF INTERNAL TABLES
DATA : BEGIN OF xtab,
mblnr TYPE mkpf-mblnr , "DOCUMENT NUMBER
mjahr TYPE mkpf-mjahr , "YEAR
budat TYPE mkpf-budat , "POST DATE
blart TYPE mkpf-blart , "DOCUMENT TYPE
END OF xtab.

DATA : BEGIN OF ytab,
mblnr TYPE mseg-mblnr , "DOCUMENT NUMBER
mjahr TYPE mseg-mjahr , "YEAR
zeile TYPE mseg-zeile , "ITEM NUMBER
bwart TYPE mseg-bwart , "MOVEMENT TYPE
btext TYPE t156t-btext , "MOVEMENT DESCRIPTION
matnr TYPE mseg-matnr , "MATERIAL NUMBER
maktx TYPE makt-maktx , "MATERIAL DESCRIPTION
meins TYPE mseg-meins , "UNIT OF MEASURE
menge TYPE mseg-menge , "QUANTITY
dmbtr TYPE mseg-dmbtr , "AMOUNT
END OF ytab.

*INTERNAL TABLE DECLARATION
DATA : i_tab1 LIKE STANDARD TABLE OF xtab WITH HEADER LINE. "INTERNAL TABLE 1 : CONTAINS MATERIAL DETAILS
DATA : i_tab2 LIKE STANDARD TABLE OF ytab WITH HEADER LINE. "INTERNAL TABLE 2 : CONTAINS ITEMWISE MATERIAL DETAILS

*VARIABLES
DATA : v_color TYPE sy-tabix , "FOR SETTING COLOR FORMATS DURING GENERATING REPORT
v_field(20) , "FOR STORING THE CLICKED FIELD NAME
v_value(20) , "FOR STORING THE CLICKED FIELD VALUE
v_mblnr TYPE mkpf-mblnr , "FOR VALIDATING DOCUMENT NUMBER
v_mjahr TYPE mkpf-mjahr , "FOR VALIDATING DOCUMENT YEAR
v_bwart TYPE mseg-bwart , "FOR VALIDATING MOVEMENT TYPE
v_matnr TYPE mseg-matnr . "FOR VALIDATING MATERIAL NUMBER
*------------------
**SELECTION-SCREEN
*------------------
SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_mblnr FOR mkpf-mblnr , "DOCUMENT NUMBER
s_mjahr FOR mkpf-mjahr , "DOCUMENT YEAR
s_bwart FOR mseg-bwart NO INTERVALS NO-EXTENSION, "MOVEMENT TYPE
s_matnr FOR mseg-matnr . "MATERIAL NUMBER
SELECTION-SCREEN : END OF BLOCK blk1.
*---------------------
*AT SELECTION-SCREEN
*---------------------
AT SELECTION-SCREEN.
PERFORM validation. "PERFORMS VALIDATION OF SELECTION-SCREEN FIELDS
*---------------------
*TOP-OF-PAGE
*---------------------
TOP-OF-PAGE.
PERFORM header. "CREATES HEADER FOR THE BASIC LIST
*---------------------
*END-OF-PAGE
*---------------------
END-OF-PAGE. "CREATES FOOTER FOR THE BASIC AND SECONDARY LIST
PERFORM footer.
*---------------------
*START-OF-SELECTION
*---------------------
START-OF-SELECTION.
PERFORM generation_basic. "GENERATES REPORT FOR BASIC LIST WHICH CONTAINS DOCUMENT NO , DOCUMENT YEAR
"POST DATE , DOCUMENT TYPE.
*---------------------
*END-OF-SELECTION
*---------------------
END-OF-SELECTION.
PERFORM report_basic. "DISPLAY REPORT FOR BASIC LIST
*---------------------
*AT LINE-SELECTION
*---------------------
AT LINE-SELECTION.
PERFORM generation_secondary. "GENERATES REPORT FOR SECONDARY LIST BASED ON THE DOCUMENT NUMBER AND DOCUMENT YEAR
"WHICH CONTAINS DOCUMENT NO , YEAR , ITEM NO , MOVEMENT TYPE , MOVEMENT DESCRIPTION ,
"MATERIAL NUMBER , MATERIAL DESC , UNIT OF MEASURE , QUANTITY AND AMOUNT
*----------------------------------
*TOP-OF-PAGE DURING LINE-SELECTION
*----------------------------------
TOP-OF-PAGE DURING LINE-SELECTION.
PERFORM header_secondary. "CREATES HEADER FOR THE SECONDARY LIST
*-----------------
*AT USER-COMMAND
*-----------------
AT USER-COMMAND.
PERFORM user_secondary. "SUBROUTINE FOR HANDLING USER EVENTS
*----------------------------------------------------------------------
**& Form VALIDATION
*----------------------------------------------------------------------
FORM validation .

*VALIDATING MATERIAL DOCUMENT NUMBER
SELECT SINGLE mblnr
INTO v_mblnr
FROM mkpf
WHERE mblnr IN s_mblnr.
IF sy-subrc NE 0.
MESSAGE 'ENTER CORRECT DOCUMENT NUMBER' TYPE 'E'.
ENDIF.

*VALIDATING MATERIAL DOCUMENT YEAR
SELECT SINGLE mjahr
INTO v_mjahr
FROM mkpf
WHERE mjahr IN s_mjahr.
IF sy-subrc NE 0.
MESSAGE 'ENTER CORRECT MATERIAL DOCUMENT YEAR' TYPE 'E'.
ENDIF.

*VALIDATING MOVEMENT TYPE
SELECT SINGLE bwart
INTO v_bwart
FROM mseg
WHERE bwart IN s_bwart.
IF sy-subrc NE 0.
MESSAGE 'ENTER CORRECT MOVEMENT TYPE' TYPE 'E'.
EnDIF.

*VALIDATING MATERIAL NUMBER
SELECT SINGLE matnr
INTO v_matnr
FROM mseg
WHERE matnr IN s_matnr.
IF sy-subrc NE 0.
MESSAGE 'ENTER CORRECT MATERIAL NUMBER' TYPE 'E'.
ENDIF.
ENDFORM. " VALIDATION

*&---------------------------------------------------------------------
**& Form HEADER
*----------------------------------------------------------------------
FORM header .

WRITE :/30 'MATERIAL DOCUMENTS' COLOR 1. "TITLE OF BASIC LIST
WRITE :/1(89) sy-uline.
FORMAT COLOR 1.
WRITE :/1 sy-vline ,
3 'DOCUMENT NUMBER' ,
23 sy-vline ,
25 'YEAR' ,
45 sy-vline ,
47 'POST DATE' ,
67 sy-vline ,
69 'DOCTYP' ,
89 sy-vline .
FORMAT RESET.
WRITE :/1(89) sy-uline.

ENDFORM. " HEADER

*&---------------------------------------------------------------------
**& Form FOOTER
*----------------------------------------------------------------------
FORM footer .
IF sy-lsind EQ 0. "CHECKS WHICH LIST IS IT BASIC LIST OR SECONDARY (AND NO. OF SECONDARY LIST)

WRITE :/1(89) sy-uline.

ELSEIF sy-lsind EQ 1.

WRITE :/1(192) sy-uline.
ENDIF.

ENDFORM. " FOOTER

*&---------------------------------------------------------------------
**& Form GENERATION_BASIC
*----------------------------------------------------------------------
FORM generation_basic .

SELECT mkpf~mblnr "DOCUMENT NUMBER
mkpf~mjahr "DOCUMENT YEAR
mkpf~budat "POST DATE
mkpf~blart "DOCUMENT TYPE
INTO TABLE i_tab1
FROM mkpf INNER JOIN mseg ON mkpf~mjahr EQ mseg~mjahr AND
mkpf~mblnr EQ mseg~mblnr

WHERE mkpf~mblnr IN s_mblnr
AND mkpf~mjahr IN s_mjahr
AND mseg~bwart IN s_bwart
AND mseg~matnr IN s_matnr.

IF sy-subrc NE 0.
WRITE :/ 'MATERIAL DATA NOT FOUND'.
ENDIF.

DELETE ADJACENT DUPLICATES FROM i_tab1 COMPARING mblnr mjahr.

ENDFORM. " GENERATION_BASIC
*&---------------------------------------------------------------------
**& Form REPORT_BASIC
*----------------------------------------------------------------------
FORM report_basic .

LOOP AT i_tab1.

v_color = sy-tabix MOD 2.

IF v_color EQ 0.
FORMAT COLOR 1 INTENSIFIED OFF.
ELSE.
FORMAT COLOR 2 INTENSIFIED OFF.
ENDIF.

WRITE :/1 sy-vline ,
3 i_tab1-mblnr ,
23 sy-vline ,
25 i_tab1-mjahr ,
45 sy-vline ,
47 i_tab1-budat ,
67 sy-vline ,
69 i_tab1-blart ,
89 sy-vline .

HIDE : i_tab1-mblnr , i_tab1-mjahr. "STORING THE VALUE OF FIELDS CLICKED IN SYSTEM AREA
ENDLOOP.
FORMAT RESET.
WRITE :/1(89) sy-uline.

ENDFORM. " REPORT_BASIC
*&---------------------------------------------------------------------
**& Form GENERATION_SECONDARY
*----------------------------------------------------------------------
FORM generation_secondary .

IF sy-lsind EQ 1.

SET PF-STATUS 'DISPLAY'.

GET CURSOR FIELD v_field VALUE v_value. "GET THE FIELD VALUE AND NAME WHERE THE CURSOR WAS CLICKED

CASE v_field.

WHEN 'I_TAB1-MBLNR'. "DISPLAYS SECONDARY LIST ONLY IF DOCUMENT NUMBER IS CLICKED

SELECT mseg~mblnr "DOCUMENT NUMBER
mseg~mjahr "DOCUMENT YEAR
mseg~zeile "ITEM NUMBER
mseg~bwart "MOVEMENT TYPE
t156t~btext "MOVEMENT DESCRIPTION
mseg~matnr "MATERIAL NUMBER
makt~maktx "MATERIAL DESCRIPTION
mseg~meins "UNIT OF MEASURE
mseg~menge "QUANTITY
mseg~dmbtr "AMOUNT
INTO TABLE i_tab2
FROM ( ( mseg INNER JOIN t156t
ON mseg~bwart EQ t156t~bwart )
INNER JOIN makt
ON mseg~matnr EQ makt~matnr )
WHERE mseg~mblnr EQ i_tab1-mblnr
AND mseg~mjahr EQ i_tab1-mjahr
AND t156t~spras EQ sy-langu
AND makt~spras EQ sy-langu.

DELETE ADJACENT DUPLICATES FROM i_tab2 COMPARING mblnr mjahr.

WHEN OTHERS.

MESSAGE 'SELECT DOCUMENT NUMBER' TYPE 'E'.

ENDCASE.

LOOP AT i_tab2.

v_color = sy-tabix MOD 2.

IF v_color EQ 0.
FORMAT COLOR 1 INTENSIFIED OFF.
ELSE.
FORMAT COLOR 2 INTENSIFIED OFF.
ENDIF.

WRITE :/1 sy-vline ,
3 i_tab2-mblnr ,
12 sy-vline ,
14 i_tab2-mjahr ,
19 sy-vline ,
21 i_tab2-zeile ,
30 sy-vline ,
32 i_tab2-bwart ,
40 sy-vline ,
42 i_tab2-btext ,
72 sy-vline ,
74 i_tab2-matnr ,
94 sy-vline ,
96 i_tab2-maktx ,
146 sy-vline ,
148 i_tab2-meins ,
153 sy-vline ,
155 i_tab2-menge ,
170 sy-vline ,
172 i_tab2-dmbtr ,
192 sy-vline .

ENDLOOP.

WRITE :/1(192) sy-uline.

FORMAT RESET.

ELSEIF sy-lsind EQ 2.

GET CURSOR FIELD v_field VALUE v_value. "GET THE FIELD VALUE AND NAME WHERE THE CURSOR WAS CLICKED

CASE v_field.

WHEN 'I_TAB2-MBLNR'. "DISPLAYS SECONDARY LIST ONLY IF DOCUMENT NUMBER IS CLICKED

SET PARAMETER ID : "SETTING PARAMETER ID FOR DOCUMENT NUMBER AND YEAR.
'MBN' FIELD i_tab2-mblnr ,
'MJA' FIELD i_tab2-mjahr.

CALL TRANSACTION 'MB03' AND SKIP FIRST SCREEN. "CALLING TRABSACTION CODE 'MBO3'.

WHEN OTHERS.
MESSAGE 'SELECT DOCUMENT NUMBER' TYPE 'E'.

ENDCASE.

ENDIF.


ENDFORM. " GENERATION_SECONDARY

*&---------------------------------------------------------------------
**& Form HEADER_SECONDARY
*----------------------------------------------------------------------
FORM header_secondary .

WRITE :/50 'ITEMWISE MATERIAL DOCUMENTS' COLOR 1.

WRITE :/1(192) sy-uline.

FORMAT COLOR 1.

WRITE :/1 sy-vline ,
3 'DOCUMENT NO' ,
12 sy-vline ,
14 'YEAR' ,
19 sy-vline ,
21 'ITEM NO.' ,
30 sy-vline ,
32 'MOV TYP' ,
40 sy-vline ,
42 'MOV DESCRIPTION' ,
72 sy-vline ,
74 'MATERIAL NO' ,
94 sy-vline ,
96 'MATERIAL DESCRIPTION' ,
146 sy-vline ,
148 'UOM' ,
153 sy-vline ,
155 'QUANTITY' ,
170 sy-vline ,
172 'AMOUNT' ,
192 sy-vline .

WRITE :/1(192) sy-uline.

FORMAT RESET.

ENDFORM. " HEADER_SECONDARY

*&---------------------------------------------------------------------
**& Form USER_SECONDARY
*----------------------------------------------------------------------
FORM user_secondary .

IF sy-ucomm EQ 'DISPLAY'. "EXECUTES ONLY IF 'DISPLAY DOCUMENTS' ITEM IS CLICKED ON APPLICATION TOOL BAR.

IF sy-lsind EQ 2.


GET CURSOR FIELD v_field VALUE v_value. "GET THE FIELD VALUE AND NAME WHERE THE CURSOR WAS CLICKED

CASE v_field.

WHEN 'I_TAB2-MBLNR'. "DISPLAYS SECONDARY LIST ONLY IF DOCUMENT NUMBER IS CLICKED
SET PARAMETER ID :
'MBN' FIELD i_tab2-mblnr ,
'MJA' FIELD i_tab2-mjahr.
CALL TRANSACTION 'MB03' AND SKIP FIRST SCREEN.

WHEN OTHERS.
MESSAGE 'SELECT DOCUMENT NUMBER' TYPE 'E'.

ENDCASE.

ENDIF.

LEAVE PROGRAM.

ENDIF.

ENDFORM. " USER_SECONDARY

No comments:

Post a Comment