This is a interactive report , which is generally used by the client's.
If you go through this report , you get the process of real time .
This report contain the Standard table and fields .
In this report comparison of two Sales ' order Related year .
*&---------------------------------------------------------------------*
*& Report xxxx
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT xxxx.
TYPE-POOLS SLIS.
TABLES : resb.
******************selection screen begin **************************
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETER : P_VBELN TYPE CHAR10 OBLIGATORY.
*
SELECTION-SCREEN END OF BLOCK B1 .
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
PARAMETER S_VBELN TYPE CHAR10 OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B2 .
********************selection screen end ***************************
DATA : IT_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV,
LT_LAYOUT TYPE SLIS_LAYOUT_ALV,
WA_FIELDCAT1 TYPE SLIS_FIELDCAT_ALV.
DATA : IT_FIELDCAT2 TYPE SLIS_T_FIELDCAT_ALV.
* LT_LAYOUT TYPE SLIS_LAYOUT_ALV,
* WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DATA : P1_VBELN TYPE VBELN_VA,
P2_VBELN TYPE J_OBJNR.
TYPES : BEGIN OF TY_COEP,
BELNR TYPE COEP-BELNR,
WTGBTR TYPE COEP-WTGBTR,
OBJNR TYPE COEP-OBJNR,
KSTAR TYPE COEP-KSTAR,
PAROB TYPE COEP-PAROB,
BEKNZ TYPE COEP-BEKNZ,
MEGBTR TYPE COEP-MEGBTR,
END OF TY_COEP.
TYPES : BEGIN OF TY_SHOP,
SHOP(2) TYPE C,
BELNR TYPE COEP-BELNR,
WTGBTR TYPE COEP-WTGBTR,
OBJNR TYPE COEP-OBJNR,
KSTAR TYPE COEP-KSTAR,
PAROB TYPE COEP-PAROB,
BEKNZ TYPE COEP-BEKNZ,
MEGBTR TYPE COEP-MEGBTR,
END OF TY_SHOP.
TYPES : BEGIN OF TY_FINAL,
SHOP TYPE CHAR2,
MEGBTR1 TYPE COEP-MEGBTR,
MEGBTR2 TYPE MEGXXX,
END OF TY_FINAL.
DATA : IT_COEP TYPE TABLE OF TY_COEP,
WA_COEP TYPE TY_COEP.
DATA : IT_PREV TYPE TABLE OF TY_COEP,
WA_PREV TYPE TY_COEP,
IT_CURR TYPE TABLE OF TY_COEP,
WA_CURR TYPE TY_COEP.
DATA : IT_SHOP_PREV TYPE TABLE OF TY_SHOP,
IT_SHOP_PREV1 TYPE TABLE OF TY_SHOP,
IT_SHOP_PREV2 TYPE TABLE OF TY_SHOP,
WA_SHOP_PREV TYPE TY_SHOP,
IT_SHOP_CURR TYPE TABLE OF TY_SHOP,
IT_SHOP_CURR1 TYPE TABLE OF TY_SHOP,
IT_SHOP_CURR2 TYPE TABLE OF TY_SHOP,
WA_SHOP_CURR TYPE TY_SHOP.
DATA : IT_FINAL TYPE STANDARD TABLE OF TY_FINAL ,
WA_FINAL TYPE TY_FINAL.
************START OF SELECTION *************************
PERFORM SELECT_DATA USING P_VBELN . " PREVIOUS BATCH ORDER .
PERFORM GET_DATA_TABLE. " GET DATA AND REFRESH THE TABLE .
PERFORM SELECT_DATA USING S_VBELN . " CURRENT BATC ORDER .
PERFORM GET_DATA_TABLE2 . " GET_DATA_TABLE 2 .
PERFORM CALCULATION_ON_PREV. " GET DATA PREVIOUS .
PERFORM CALCULATION_ON_CURR. " GET DATA CURRENT .
PERFORM CALCULATION_FINAL. " FINAL CALCULATION .
PERFORM FILL_FIELDCATLOG. " FILL_FIELDCATLOG
PERFORM DISPLAY_TABLE. " DISPLAY TABLE.
*PERFORM INTERACTIVE_FLOW . " INTERACTIVE LOGIC.
*&---------------------------------------------------------------------*
*& Form SELECT_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SELECT_DATA USING P1_VBELN .
CONCATENATE 'OR' P1_VBELN '%' INTO P2_VBELN .
SELECT BELNR
WTGBTR
OBJNR
KSTAR
PAROB
BEKNZ MEGBTR INTO CORRESPONDING FIELDS OF TABLE IT_COEP FROM COEP WHERE OBJNR LIKE P2_VBELN.
ENDFORM. " SELECT_DATA
*&---------------------------------------------------------------------*
*& Form GET_DATA_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA_TABLE .
IT_PREV[] = IT_COEP[].
REFRESH IT_COEP.
DELETE IT_PREV WHERE KSTAR+0(5) NE 'P7172' AND KSTAR+7(2) NE '51' AND KSTAR+7(2) NE '52' .
ENDFORM. " GET_DATA_TABLE
*&---------------------------------------------------------------------*
*& Form REFRESH_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA_TABLE2 .
IT_CURR[] = IT_COEP[].
REFRESH IT_COEP.
DELETE IT_CURR WHERE KSTAR+0(5) NE 'P7172' AND KSTAR+7(2) NE '51' AND KSTAR+7(2) NE '52' .
ENDFORM. " GET_DATA_TABLE
*&---------------------------------------------------------------------*
*& Form CALCULATION_ON_PREV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALCULATION_ON_PREV .
LOOP AT IT_PREV INTO WA_PREV.
WA_SHOP_PREV-SHOP = WA_PREV-KSTAR+5(2).
WA_SHOP_PREV-BELNR = WA_PREV-BELNR.
WA_SHOP_PREV-WTGBTR = WA_PREV-WTGBTR .
WA_SHOP_PREV-OBJNR = WA_PREV-OBJNR.
WA_SHOP_PREV-PAROB = WA_PREV-PAROB.
WA_SHOP_PREV-BEKNZ = WA_PREV-BEKNZ.
WA_SHOP_PREV-MEGBTR = WA_PREV-MEGBTR.
WA_SHOP_PREV-KSTAR = WA_PREV-KSTAR.
APPEND WA_SHOP_PREV TO IT_SHOP_PREV.
CLEAR : WA_SHOP_PREV , WA_PREV.
ENDLOOP.
CLEAR WA_SHOP_PREV.
IT_SHOP_PREV1[] = IT_SHOP_PREV[].
SORT IT_SHOP_PREV ASCENDING BY SHOP.
LOOP AT IT_SHOP_PREV INTO WA_SHOP_PREV.
AT END OF SHOP.
SUM.
MODIFY IT_SHOP_PREV FROM WA_SHOP_PREV INDEX SY-TABIX TRANSPORTING MEGBTR.
ENDAT.
ENDLOOP.
SORT IT_SHOP_PREV DESCENDING BY SHOP MEGBTR.
DELETE ADJACENT DUPLICATES FROM IT_SHOP_PREV COMPARING SHOP.
ENDFORM. " CALCULATION_ON_PREV
*&---------------------------------------------------------------------*
*& Form CALCULATION_ON_CURR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALCULATION_ON_CURR .
LOOP AT IT_CURR INTO WA_CURR.
WA_SHOP_CURR-SHOP = WA_CURR-KSTAR+5(2).
WA_SHOP_CURR-BELNR = WA_CURR-BELNR.
WA_SHOP_CURR-WTGBTR = WA_CURR-WTGBTR .
WA_SHOP_CURR-OBJNR = WA_CURR-OBJNR.
WA_SHOP_CURR-PAROB = WA_CURR-PAROB.
WA_SHOP_CURR-BEKNZ = WA_CURR-BEKNZ.
WA_SHOP_CURR-MEGBTR = WA_CURR-MEGBTR.
WA_SHOP_CURR-KSTAR = WA_CURR-KSTAR.
APPEND WA_SHOP_CURR TO IT_SHOP_CURR.
CLEAR : WA_SHOP_CURR , WA_CURR.
ENDLOOP.
CLEAR WA_SHOP_PREV.
IT_SHOP_CURR1[] = IT_SHOP_CURR.
SORT IT_SHOP_CURR ASCENDING BY SHOP.
LOOP AT IT_SHOP_CURR INTO WA_SHOP_CURR.
AT END OF SHOP.
SUM.
MODIFY IT_SHOP_CURR FROM WA_SHOP_CURR INDEX SY-TABIX TRANSPORTING MEGBTR.
ENDAT.
ENDLOOP.
SORT IT_SHOP_CURR DESCENDING BY SHOP MEGBTR.
DELETE ADJACENT DUPLICATES FROM IT_SHOP_CURR COMPARING SHOP.
ENDFORM. " CALCULATION_ON_CURR
*&---------------------------------------------------------------------*
*& Form CALCULATION_FINAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALCULATION_FINAL .
LOOP AT IT_SHOP_PREV INTO WA_SHOP_PREV.
WA_FINAL-SHOP = WA_SHOP_PREV-SHOP.
WA_FINAL-MEGBTR1 = WA_SHOP_PREV-MEGBTR.
APPEND WA_FINAL TO IT_FINAL.
CLEAR WA_FINAL.
ENDLOOP.
CLEAR WA_FINAL.
LOOP AT IT_SHOP_CURR INTO WA_SHOP_CURR.
WA_FINAL-SHOP = WA_SHOP_CURR-SHOP.
WA_FINAL-MEGBTR2 = WA_SHOP_CURR-MEGBTR.
APPEND WA_FINAL TO IT_FINAL.
CLEAR WA_FINAL.
ENDLOOP.
SORT IT_FINAL BY SHOP ASCENDING.
LOOP AT IT_FINAL INTO WA_FINAL.
AT END OF SHOP.
SUM.
MODIFY IT_FINAL FROM WA_FINAL INDEX SY-TABIX TRANSPORTING MEGBTR1 MEGBTR2.
ENDAT.
ENDLOOP.
SORT IT_FINAL DESCENDING BY SHOP MEGBTR1 MEGBTR2.
DELETE ADJACENT DUPLICATES FROM IT_FINAL COMPARING SHOP.
ENDFORM. " CALCULATION_FINAL
*&---------------------------------------------------------------------*
*& Form DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILL_FIELDCATLOG.
WA_FIELDCAT1-fieldname = 'SHOP'.
WA_FIELDCAT1-tabname = 'IT_FINAL'.
WA_FIELDCAT1-outputlen = 2.
WA_FIELDCAT1-seltext_l = 'SHOP NUMBER'.
WA_FIELDCAT1-col_pos = 1.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR WA_FIELDCAT1.
WA_FIELDCAT1-fieldname = 'MEGBTR1'.
WA_FIELDCAT1-tabname = 'IT_FINAL'.
WA_FIELDCAT1-outputlen = 20.
WA_FIELDCAT1-seltext_l = 'HOURS 1'.
WA_FIELDCAT1-col_pos = 2.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR WA_FIELDCAT1.
WA_FIELDCAT1-fieldname = 'MEGBTR2'.
WA_FIELDCAT1-tabname = 'IT_FINAL'.
WA_FIELDCAT1-outputlen = 20.
WA_FIELDCAT1-seltext_l = 'HOURS2'.
WA_FIELDCAT1-col_pos = 3.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR WA_FIELDCAT1.
LT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
*LOOP AT IT_FINAL INTO WA_FINAL .
* WRITE :/ WA_FINAL-SHOP,
* WA_FINAL-MEGBTR1,
* WA_FINAL-MEGBTR2.
*ENDLOOP.
ENDFORM. " FILL_FIELDCATLOG
*&---------------------------------------------------------------------*
*& Form DISPLAY_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DISPLAY_TABLE .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-CPROG
* I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = 'INTERACTIVE_FLOW'
* I_CALLBACK_TOP_OF_PAGE = '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 = LT_LAYOUT
IT_FIELDCAT = IT_FIELDCAT1
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = 'A'
* 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 = IT_FINAL
* 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_TABLE
*&---------------------------------------------------------------------*
*& Form INTERACTIVE_FLOW
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P1_VBELN text
*----------------------------------------------------------------------*
FORM INTERACTIVE_FLOW USING ucomm TYPE sy-ucomm selfield TYPE slis_selfield.
CASE UCOMM.
WHEN '&IC1'.
IF SELFIELD-FIELDNAME = 'MEGBTR1'.
READ TABLE IT_FINAL INTO WA_FINAL INDEX SELFIELD-TABINDEX.
PERFORM GET_DATA_PREV.
CLEAR WA_FINAL.
REFRESH IT_FIELDCAT2.
ELSEIF SELFIELD-FIELDNAME = 'MEGBTR2'.
READ TABLE IT_FINAL INTO WA_FINAL INDEX SELFIELD-TABINDEX.
PERFORM GET_DATA_CURR.
CLEAR WA_FINAL.
REFRESH IT_FIELDCAT2.
ENDIF.
ENDCASE.
ENDFORM. " INTERACTIVE_FLOW
*&---------------------------------------------------------------------*
*& Form GET_DATA_PREV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA_PREV .
IT_SHOP_PREV2[] = IT_SHOP_PREV1[].
DELETE IT_SHOP_PREV2 WHERE SHOP NE WA_FINAL-SHOP.
PERFORM FILL_FIELDCAT_1.
PERFORM DISPLAY_TABLE_1 CHANGING IT_SHOP_PREV2.
ENDFORM. " GET_DATA_PREV
*&---------------------------------------------------------------------*
*& Form FILL_FIELDCAT_1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILL_FIELDCAT_1 .
WA_FIELDCAT1-fieldname = 'SHOP'.
WA_FIELDCAT1-tabname = 'IT_PREV_SHOP'.
WA_FIELDCAT1-outputlen = 2.
WA_FIELDCAT1-seltext_l = 'SHOP NUMBER'.
WA_FIELDCAT1-col_pos = 1.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT2.
CLEAR WA_FIELDCAT1.
WA_FIELDCAT1-fieldname = 'BELNR'.
WA_FIELDCAT1-tabname = 'IT_PREV_SHOP'.
WA_FIELDCAT1-outputlen = 20.
WA_FIELDCAT1-seltext_l = 'DOCUMENT NUMBER '.
WA_FIELDCAT1-col_pos = 2.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT2.
CLEAR WA_FIELDCAT1.
WA_FIELDCAT1-fieldname = 'WTGBTR'.
WA_FIELDCAT1-tabname = 'IT_PREV_SHOP'.
WA_FIELDCAT1-outputlen = 20.
WA_FIELDCAT1-seltext_l = 'TOTAL COST'.
WA_FIELDCAT1-col_pos = 3.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT2.
CLEAR WA_FIELDCAT1.
WA_FIELDCAT1-fieldname = 'KSTAR'.
WA_FIELDCAT1-tabname = 'IT_PREV_SHOP'.
WA_FIELDCAT1-outputlen = 20.
WA_FIELDCAT1-seltext_l = 'COST ELEMENT'.
WA_FIELDCAT1-col_pos = 4.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT2.
CLEAR WA_FIELDCAT1.
WA_FIELDCAT1-fieldname = 'BEKNZ'.
WA_FIELDCAT1-tabname = 'IT_PREV_SHOP'.
WA_FIELDCAT1-outputlen = 20.
WA_FIELDCAT1-seltext_l = 'CRE/DBE'.
WA_FIELDCAT1-col_pos = 5.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT2.
CLEAR WA_FIELDCAT1.
WA_FIELDCAT1-fieldname = 'MEGBTR'.
WA_FIELDCAT1-tabname = 'IT_PREV_SHOP'.
WA_FIELDCAT1-outputlen = 20.
WA_FIELDCAT1-seltext_l = 'HOURS'.
WA_FIELDCAT1-col_pos = 6.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT2.
CLEAR WA_FIELDCAT1.
LT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
ENDFORM. " FILL_FIELDCAT_1
*&---------------------------------------------------------------------*
*& Form DISPLAY_TABLE_1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_IT_SHOP_PREV2 text
*----------------------------------------------------------------------*
FORM DISPLAY_TABLE_1 CHANGING P_IT_SHOP_PREV2 TYPE STANDARD TABLE.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-CPROG
* 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 = LT_LAYOUT
IT_FIELDCAT = IT_FIELDCAT2
* 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 = P_IT_SHOP_PREV2
* 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_TABLE_1
*&---------------------------------------------------------------------*
*& Form GET_DATA_CURR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA_CURR .
IT_SHOP_CURR2 = IT_SHOP_CURR1.
DELETE IT_SHOP_CURR2 WHERE SHOP NE WA_FINAL-SHOP.
PERFORM FILL_FIELDCAT_1.
PERFORM DISPLAY_TABLE_1 CHANGING IT_SHOP_CURR2.
ENDFORM. " GET_DATA_CURR