*&---------------------------------------------------------------------*
*& Report ZABATCH_ORDER_COMPARE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZABATCH_ORDER_COMPARE LINE-SIZE 300 .
TYPE-POOLS SLIS.
TABLES : RESB,VBAP.
******************SELECTION BEGIN OF **************************************
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETER : P_VBELN TYPE ZRESB-KDAUF,
P_MENGE TYPE VBAP-ZMENG.
SELECTION-SCREEN END OF BLOCK B1 .
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
SELECT-OPTIONS : C_VBELN FOR VBAP-VBELN.
PARAMETER C_MENGE TYPE VBAP-ZMENG.
SELECTION-SCREEN END OF BLOCK B2 .
******************SELECTION END OF **************************************
********** STRUCUTURE DECLARATION ********************************
TYPES : BEGIN OF TY_LEG,
KDAUF TYPE ZRESB-KDAUF,
* MATNR TYPE ZRESB-MATNR,
* REQ_QTY TYPE ZRESB-REQ_QTY,
* BWART TYPE ZRESB-BWART,
END OF TY_LEG.
TYPES : BEGIN OF TY_LEGACY2,
MATNR TYPE ZMSEG-MATNR,
KDAUF TYPE ZMSEG-KDAUF,
REQ_QTY TYPE BDMNG,
BWART TYPE ZMSEG-BWART,
QTY TYPE ZMSEG-QTY,
COST TYPE ZMSEG-COST,
END OF TY_LEGACY2.
TYPES : BEGIN OF TY_ORDER,
MATNR TYPE MATNR ,
KDAUF TYPE KDAUF ,
BWART TYPE BWART,
BDMNG TYPE BDMNG,
END OF TY_ORDER ,
BEGIN OF TY_B_FINAL,
MATNR TYPE MATNR,
ORDER1 TYPE KDAUF,
REQ_QTY1 TYPE BDMNG,
ISSUE_QTY1 TYPE BDMNG,
ISSUE_COST1 TYPE DMBTR,
RETURN_QTY1 TYPE MENGE_D,
RETURN_COST1 TYPE DMBTR,
END OF TY_B_FINAL,
BEGIN OF TY_A_FINAL,
MATNR TYPE MATNR,
ORDER1 TYPE KDAUF,
MAKTX TYPE MAKTX ,
REQ_QTY1 TYPE BDMNG,
ISSUE_QTY1 TYPE BDMNG,
ISSUE_COST1 TYPE DMBTR,
RETURN_QTY1 TYPE MENGE_D,
RETURN_COST1 TYPE DMBTR,
NET_QTY1 TYPE MENGE_D,
ORDER2 TYPE KDAUF,
* MATNR2 TYPE MATNR,
REQ_QTY2 TYPE BDMNG,
ISSUE_QTY2 TYPE BDMNG,
ISSUE_COST2 TYPE DMBTR,
RETURN_QTY2 TYPE MENGE_D,
RETURN_COST2 TYPE DMBTR,
NET_QTY2 TYPE MENGE_D,
REMARK TYPE STRING,
END OF TY_A_FINAL,
BEGIN OF TY_DES,
MATNR TYPE MATNR ,
MAKTX TYPE MAKTX,
END OF TY_DES,
BEGIN OF TY_MSEG,
MATNR TYPE MATNR ,
BWART TYPE BWART,
MENGE TYPE MENGE_D,
DMBTR TYPE DMBTR,
END OF TY_MSEG.
************* INGTERNAL TABLE DECLARATION AND WORKAAREA , VARIABLE ******************
* *******PREVIOUS DATA SAP**************
DATA : IT_PREV_SAP TYPE STANDARD TABLE OF TY_ORDER,
WA_PREV_SAP TYPE TY_ORDER,
WA_PREV_SAP1 TYPE TY_ORDER.
DATA: IT_LEGACY TYPE STANDARD TABLE OF TY_LEG,
WA_LEGACY TYPE TY_LEG.
DATA : IT_MAT_DES TYPE STANDARD TABLE OF TY_DES,
WA_MAT_DES TYPE TY_DES.
DATA : IT_ISSUE_LEGACY TYPE STANDARD TABLE OF TY_LEGACY2,
WA_ISSUE_LEGACY TYPE TY_LEGACY2.
DATA : IT_RETURN_LEGACY TYPE STANDARD TABLE OF TY_LEGACY2,
WA_RETURN_LEGACY TYPE TY_LEGACY2.
DATA : IT_FINAL_B TYPE STANDARD TABLE OF TY_B_FINAL,
WA_FINAL_B TYPE TY_B_FINAL.
DATA : IT_FINAL_BL TYPE STANDARD TABLE OF TY_B_FINAL,
WA_FINAL_BL TYPE TY_B_FINAL.
DATA : IT_ISSUE_SAP TYPE STANDARD TABLE OF TY_MSEG,
IT_RETURN_SAP TYPE STANDARD TABLE OF TY_MSEG,
WA_ISSUE_SAP TYPE TY_MSEG,
WA_RETURN_SAP TYPE TY_MSEG.
* *******END PREVIOUS DATA SAP**************
* *******CURRENT DATA SAP******************
DATA : IT_CURR_SAP TYPE STANDARD TABLE OF TY_ORDER,
WA_CURR_SAP TYPE TY_ORDER,
WA_CURR_SAP1 TYPE TY_ORDER.
DATA : IT_FINAL_C TYPE STANDARD TABLE OF TY_B_FINAL,
WA_FINAL_C TYPE TY_B_FINAL.
************************TEMPORARY TABLE *********************************************
DATA: IT_TEMP_LEGACY TYPE STANDARD TABLE OF TY_LEG,
WA_TEMP_LEGACY TYPE TY_LEG.
DATA : IT_TISSUE_LEGACY TYPE STANDARD TABLE OF TY_LEGACY2,
WA_TISSUE_LEGACY TYPE TY_LEGACY2.
DATA : IT_TEMP_SAP1 TYPE STANDARD TABLE OF TY_ORDER,
WA_TEMP_SAP1 TYPE TY_ORDER.
DATA : IT_TEMP_ISSUE TYPE STANDARD TABLE OF TY_MSEG,
WA_TEMP_ISSUE TYPE TY_MSEG.
DATA : LV_TABIX TYPE I,
FM_NAME TYPE RS38L_FNAM,
TEMP_STR1 TYPE STRING,
TEMP_STR2 TYPE STRING.
DATA : PLAN_QTY1 TYPE MENGE_D,
PLAN_QTY2 TYPE MENGE_D,
PLAN_QTY TYPE MENGE_D,
DRAWN_QTY TYPE MENGE_D,
DRAWN_QTY2 TYPE MENGE_D,
RESULT TYPE MENGE_D,
RATIO_B TYPE MENGE_D.
* ****************FINAL***********************************
DATA : IT_FINAL_A TYPE STANDARD TABLE OF ZBORAD_FINAL,
WA_FINAL_A TYPE ZBORAD_FINAL,
WA_FINAL_A1 TYPE ZBORAD_FINAL.
DATA : IT_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV,
LT_LAYOUT TYPE SLIS_LAYOUT_ALV,
WA_FIELDCAT1 TYPE SLIS_FIELDCAT_ALV.
DATA: IT_LISTHEADER TYPE SLIS_T_LISTHEADER,
WA_LISTHEADER TYPE SLIS_LISTHEADER.
* Dynamic Table Declarations
*
DATA : GT_DYN_TABLE TYPE REF TO DATA,
GW_LINE TYPE REF TO DATA,
GW_LINE1 TYPE REF TO DATA,
WA_FIELDCAT TYPE LVC_S_FCAT,
IT_FIELDCAT TYPE LVC_T_FCAT.
* Field Symbols Declarations
FIELD-SYMBOLS: <GFS_LINE>,<GFS_LINE1>,
<GFS_DYN_TABLE> TYPE STANDARD TABLE,
<FS1>.
DATA : GV_POS TYPE I.
DATA : FNAME TYPE STRING.
**************START-OF-SELECTION.*****************************************************
*****************SELECT DATA FROM LEGACY SYSTEM ******************************************
PERFORM CONVERSION_SALES_NUMBER .
PERFORM SLECT_DATA_LEAGCY.
PERFORM CALCULATE_REQ_LEGACY.
PERFORM ISSUE_QTY_LEGACY.
PERFORM RETURN_QTY_LEGACY.
PERFORM FINAL_LEGACY.
*****************SELECT DATA PREVIOUS SAP SALES ORDER ************************************
PERFORM SELECT_DATA_SAP.
PERFORM CALCULATE_REQ_SAP .
PERFORM ISSUE_QTY_SAP .
PERFORM RETURN_QTY_SAP.
PERFORM FINAL_SAP1.
PERFORM LEGACY_SAP_COMBINE.
*******************END SELECTION PREVIOUS SAP SALES ORDER *********************************
PERFORM SELCT_CURR_DATA_SAP.
PERFORM CALCULATE_CURR_REQ_SAP.
PERFORM ISSUE_CURR_QTY_SAP .
PERFORM RETURN_CURR_QTY_SAP.
PERFORM FINAL_SAP2.
********************************************************************************************
PERFORM FINAL_TABLE_DISPLAY.
PERFORM FILL_FIELDCAT.
PERFORM FILL_FIELDCAT_1.
PERFORM LIST_HEADER .
PERFORM TOP_OF_PAGE.
PERFORM GRID_DISPLAY.
*&---------------------------------------------------------------------*
*& Form SELECT_DATA_SAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SELECT_DATA_SAP .
SELECT MATNR KDAUF BWART BDMNG INTO TABLE IT_PREV_SAP FROM RESB WHERE KDAUF = P_VBELN .
DELETE IT_PREV_SAP WHERE BWART NE '261' AND BWART NE '202' AND BWART NE '201' AND BWART NE '262' .
ENDFORM. " SELECT_DATA_SAP
*&---------------------------------------------------------------------*
*& Form CALCULATE_REQ_SAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALCULATE_REQ_SAP .
SORT IT_PREV_SAP BY MATNR ASCENDING.
LOOP AT IT_PREV_SAP INTO WA_PREV_SAP.
IF IT_TEMP_SAP1 IS NOT INITIAL .
READ TABLE IT_TEMP_SAP1 INTO WA_TEMP_SAP1 WITH KEY MATNR = WA_PREV_SAP-MATNR KDAUF = WA_PREV_SAP-KDAUF.
IF SY-SUBRC EQ 0 .
WA_TEMP_SAP1-BDMNG = WA_TEMP_SAP1-BDMNG + WA_PREV_SAP-BDMNG.
MODIFY IT_TEMP_SAP1 FROM WA_TEMP_SAP1 TRANSPORTING BDMNG.
ENDIF.
WA_TEMP_SAP1-BDMNG = WA_PREV_SAP-BDMNG.
WA_TEMP_SAP1-KDAUF = WA_PREV_SAP-KDAUF.
WA_TEMP_SAP1-MATNR = WA_PREV_SAP-MATNR.
WA_TEMP_SAP1-BWART = WA_PREV_SAP-BWART.
APPEND WA_TEMP_SAP1 TO IT_TEMP_SAP1.
ENDIF .
CLEAR WA_TEMP_SAP1.
ENDLOOP.
REFRESH IT_PREV_SAP.
IT_PREV_SAP[] = IT_TEMP_SAP1[].
READ TABLE IT_PREV_SAP INTO WA_TEMP_SAP1 INDEX SY-TABIX.
REFRESH IT_TEMP_SAP1.
ENDFORM. " CALCULATE_REQ_SAP
*&---------------------------------------------------------------------*
*& Form ISSUE_QTY_SAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ISSUE_QTY_SAP .
SELECT MATNR BWART MENGE DMBTR INTO TABLE IT_ISSUE_SAP FROM MSEG FOR ALL ENTRIES IN IT_PREV_SAP WHERE MATNR = IT_PREV_SAP-MATNR.
DELETE IT_ISSUE_SAP WHERE BWART NE '261' AND BWART NE '201'.
SORT IT_ISSUE_SAP BY MATNR ASCENDING.
LOOP AT IT_ISSUE_SAP INTO WA_ISSUE_SAP.
AT END OF MATNR .
SUM.
WA_TEMP_ISSUE-MATNR = WA_ISSUE_SAP-MATNR.
WA_TEMP_ISSUE-BWART = WA_ISSUE_SAP-BWART.
WA_TEMP_ISSUE-MENGE = WA_ISSUE_SAP-MENGE.
WA_TEMP_ISSUE-DMBTR = WA_ISSUE_SAP-DMBTR.
APPEND WA_TEMP_ISSUE TO IT_TEMP_ISSUE.
ENDAT.
ENDLOOP.
REFRESH IT_ISSUE_SAP.
IT_ISSUE_SAP[] = IT_TEMP_ISSUE[].
READ TABLE IT_ISSUE_SAP INTO WA_ISSUE_SAP INDEX 1.
REFRESH IT_TEMP_ISSUE.
ENDFORM. " ISSUE_QTY_SAP
*&---------------------------------------------------------------------*
*& Form RETURN_QTY_SAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM RETURN_QTY_SAP .
REFRESH IT_TEMP_ISSUE.
SELECT MATNR BWART MENGE DMBTR INTO TABLE IT_RETURN_SAP FROM MSEG FOR ALL ENTRIES IN IT_PREV_SAP WHERE MATNR = IT_PREV_SAP-MATNR.
DELETE IT_RETURN_SAP WHERE BWART NE '262' AND BWART NE '202'.
SORT IT_RETURN_SAP BY MATNR ASCENDING.
LOOP AT IT_RETURN_SAP INTO WA_RETURN_SAP.
AT END OF MATNR.
SUM.
WA_TEMP_ISSUE-MATNR = WA_ISSUE_SAP-MATNR.
WA_TEMP_ISSUE-BWART = WA_ISSUE_SAP-BWART.
WA_TEMP_ISSUE-MENGE = WA_ISSUE_SAP-MENGE.
WA_TEMP_ISSUE-DMBTR = WA_ISSUE_SAP-DMBTR.
APPEND WA_TEMP_ISSUE TO IT_TEMP_ISSUE.
ENDAT.
ENDLOOP.
REFRESH IT_RETURN_SAP.
IT_RETURN_SAP[] = IT_TEMP_ISSUE[].
REFRESH IT_TEMP_ISSUE.
ENDFORM. " RETURN_QTY_SAP
*&---------------------------------------------------------------------*
*& Form FINAL_SAP1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FINAL_SAP1 .
LOOP AT IT_PREV_SAP INTO WA_PREV_SAP.
LV_TABIX = SY-TABIX.
WA_FINAL_B-ORDER1 = WA_PREV_SAP-KDAUF.
WA_FINAL_B-MATNR = WA_PREV_SAP-MATNR.
WA_FINAL_B-REQ_QTY1 = WA_PREV_SAP-BDMNG.
READ TABLE IT_ISSUE_SAP INTO WA_ISSUE_SAP WITH KEY MATNR = WA_PREV_SAP-MATNR.
IF SY-SUBRC = 0.
WA_FINAL_B-ISSUE_QTY1 = WA_ISSUE_SAP-MENGE.
WA_FINAL_B-ISSUE_COST1 = WA_ISSUE_SAP-DMBTR.
ELSE .
WA_FINAL_B-ISSUE_QTY1 = 0.
WA_FINAL_B-ISSUE_COST1 = 0..
ENDIF .
READ TABLE IT_RETURN_SAP INTO WA_RETURN_SAP WITH KEY MATNR = WA_PREV_SAP-MATNR.
IF SY-SUBRC = 0.
WA_FINAL_B-RETURN_QTY1 = WA_RETURN_SAP-MENGE.
WA_FINAL_B-RETURN_COST1 = WA_RETURN_SAP-DMBTR.
ELSE.
WA_FINAL_B-RETURN_QTY1 = 0.
WA_FINAL_B-RETURN_COST1 = 0.
ENDIF.
APPEND WA_FINAL_B TO IT_FINAL_B.
ENDLOOP.
READ TABLE IT_FINAL_B INTO WA_FINAL_B INDEX 1.
REFRESH : IT_ISSUE_SAP,IT_RETURN_SAP.
ENDFORM. " FINAL_SAP1
*&---------------------------------------------------------------------*
*& Form SELCT_C_DATA_SAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SELCT_CURR_DATA_SAP .
SELECT MATNR KDAUF BWART BDMNG INTO TABLE IT_CURR_SAP FROM RESB WHERE KDAUF IN C_VBELN .
DELETE IT_CURR_SAP WHERE BWART NE '261' AND BWART NE '202' AND BWART NE '201' AND BWART NE '262' .
ENDFORM. " SELCT_C_DATA_SAP
*&---------------------------------------------------------------------*
*& Form CALCULATE_CURR_REQ_SAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALCULATE_CURR_REQ_SAP .
SORT IT_CURR_SAP BY MATNR ASCENDING.
LOOP AT IT_CURR_SAP INTO WA_CURR_SAP.
IF IT_TEMP_SAP1 IS NOT INITIAL .
READ TABLE IT_TEMP_SAP1 INTO WA_TEMP_SAP1 WITH KEY MATNR = WA_CURR_SAP-MATNR KDAUF = WA_CURR_SAP-KDAUF.
IF SY-SUBRC EQ 0 .
WA_TEMP_SAP1-BDMNG = WA_TEMP_SAP1-BDMNG + WA_CURR_SAP-BDMNG.
MODIFY TABLE IT_TEMP_SAP1 FROM WA_TEMP_SAP1 TRANSPORTING BDMNG.
ELSE.
WA_TEMP_SAP1-BDMNG = WA_CURR_SAP-BDMNG.
WA_TEMP_SAP1-KDAUF = WA_CURR_SAP-KDAUF.
WA_TEMP_SAP1-MATNR = WA_CURR_SAP-MATNR.
WA_TEMP_SAP1-BWART = WA_CURR_SAP-BWART.
APPEND WA_TEMP_SAP1 TO IT_TEMP_SAP1.
ENDIF.
ELSE.
WA_TEMP_SAP1-BDMNG = WA_CURR_SAP-BDMNG.
WA_TEMP_SAP1-KDAUF = WA_CURR_SAP-KDAUF.
WA_TEMP_SAP1-MATNR = WA_CURR_SAP-MATNR.
WA_TEMP_SAP1-BWART = WA_CURR_SAP-BWART.
APPEND WA_TEMP_SAP1 TO IT_TEMP_SAP1.
ENDIF .
ENDLOOP.
REFRESH IT_CURR_SAP.
IT_CURR_SAP[] = IT_TEMP_SAP1[].
READ TABLE IT_CURR_SAP INTO WA_CURR_SAP INDEX SY-TABIX.
REFRESH IT_TEMP_SAP1.
ENDFORM. " CALCULATE_CURR_REQ_SAP
*&---------------------------------------------------------------------*
*& Form ISSUE_CURR_QTY_SAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ISSUE_CURR_QTY_SAP .
SELECT MATNR BWART MENGE DMBTR INTO TABLE IT_ISSUE_SAP FROM MSEG FOR ALL ENTRIES IN IT_CURR_SAP WHERE MATNR = IT_CURR_SAP-MATNR.
DELETE IT_ISSUE_SAP WHERE BWART NE '261' AND BWART NE '201'.
SORT IT_ISSUE_SAP BY MATNR ASCENDING.
LOOP AT IT_ISSUE_SAP INTO WA_ISSUE_SAP.
AT END OF MATNR.
SUM.
WA_TEMP_ISSUE-MATNR = WA_ISSUE_SAP-MATNR.
WA_TEMP_ISSUE-BWART = WA_ISSUE_SAP-BWART.
WA_TEMP_ISSUE-MENGE = WA_ISSUE_SAP-MENGE.
WA_TEMP_ISSUE-DMBTR = WA_ISSUE_SAP-DMBTR.
APPEND WA_TEMP_ISSUE TO IT_TEMP_ISSUE.
ENDAT.
ENDLOOP.
REFRESH IT_ISSUE_SAP.
IT_ISSUE_SAP[] = IT_TEMP_ISSUE[].
READ TABLE IT_ISSUE_SAP INTO WA_ISSUE_SAP INDEX 1.
ENDFORM. " ISSUE_CURR_QTY_SAP
*&---------------------------------------------------------------------*
*& Form RETURN_CURR_QTY_SAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM RETURN_CURR_QTY_SAP .
REFRESH IT_TEMP_ISSUE.
SELECT MATNR BWART MENGE DMBTR INTO TABLE IT_RETURN_SAP FROM MSEG FOR ALL ENTRIES IN IT_CURR_SAP WHERE MATNR = IT_CURR_SAP-MATNR.
DELETE IT_RETURN_SAP WHERE BWART NE '262' AND BWART NE '202'.
SORT IT_RETURN_SAP BY MATNR ASCENDING.
LOOP AT IT_RETURN_SAP INTO WA_RETURN_SAP.
AT END OF MATNR.
SUM.
WA_TEMP_ISSUE-MATNR = WA_ISSUE_SAP-MATNR.
WA_TEMP_ISSUE-BWART = WA_ISSUE_SAP-BWART.
WA_TEMP_ISSUE-MENGE = WA_ISSUE_SAP-MENGE.
WA_TEMP_ISSUE-DMBTR = WA_ISSUE_SAP-DMBTR.
APPEND WA_TEMP_ISSUE TO IT_TEMP_ISSUE.
ENDAT.
ENDLOOP.
REFRESH IT_RETURN_SAP.
IT_RETURN_SAP[] = IT_TEMP_ISSUE[].
REFRESH IT_TEMP_ISSUE.
ENDFORM. " RETURN_CURR_QTY_SAP
*&---------------------------------------------------------------------*
*& Form FINAL_SAP2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FINAL_SAP2 .
LOOP AT IT_CURR_SAP INTO WA_CURR_SAP.
LV_TABIX = SY-TABIX.
WA_FINAL_C-ORDER1 = WA_CURR_SAP-KDAUF.
WA_FINAL_C-MATNR = WA_CURR_SAP-MATNR.
WA_FINAL_C-REQ_QTY1 = WA_CURR_SAP-BDMNG.
READ TABLE IT_ISSUE_SAP INTO WA_ISSUE_SAP WITH KEY MATNR = WA_CURR_SAP-MATNR.
IF SY-SUBRC = 0.
WA_FINAL_C-ISSUE_QTY1 = WA_ISSUE_SAP-MENGE.
WA_FINAL_C-ISSUE_COST1 = WA_ISSUE_SAP-DMBTR.
ELSE .
WA_FINAL_C-ISSUE_QTY1 = 0.
WA_FINAL_C-ISSUE_COST1 = 0..
ENDIF .
READ TABLE IT_RETURN_SAP INTO WA_RETURN_SAP WITH KEY MATNR = WA_CURR_SAP-MATNR.
IF SY-SUBRC = 0.
WA_FINAL_C-RETURN_QTY1 = WA_RETURN_SAP-MENGE.
WA_FINAL_C-RETURN_COST1 = WA_RETURN_SAP-DMBTR.
ELSE.
WA_FINAL_C-RETURN_QTY1 = 0.
WA_FINAL_C-RETURN_COST1 = 0.
ENDIF.
APPEND WA_FINAL_C TO IT_FINAL_C.
ENDLOOP.
READ TABLE IT_FINAL_C INTO WA_FINAL_C INDEX 1.
REFRESH : IT_ISSUE_SAP,IT_RETURN_SAP.
ENDFORM. " FINAL_SAP2
*&---------------------------------------------------------------------*
*& Form FINAL_TABLE_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FINAL_TABLE_DISPLAY .
LOOP AT IT_FINAL_B INTO WA_FINAL_B.
*AT NEW MATNR .
READ TABLE IT_FINAL_C INTO WA_FINAL_C WITH KEY MATNR = WA_FINAL_B-MATNR .
IF SY-SUBRC = 0.
WA_FINAL_A-ORDER1 = WA_FINAL_B-ORDER1.
WA_FINAL_A-ORDER2 = WA_FINAL_C-ORDER1.
WA_FINAL_A-MATNR = WA_FINAL_B-MATNR.
WA_FINAL_A-REQ_QTY1 = WA_FINAL_B-REQ_QTY1.
WA_FINAL_A-REQ_QTY2 = WA_FINAL_C-REQ_QTY1.
WA_FINAL_A-ISSUE_QTY1 = WA_FINAL_B-ISSUE_QTY1.
WA_FINAL_A-ISSUE_COST1 = WA_FINAL_C-ISSUE_COST1.
WA_FINAL_A-ISSUE_QTY2 = WA_FINAL_B-ISSUE_QTY1.
WA_FINAL_A-ISSUE_COST2 = WA_FINAL_C-ISSUE_COST1.
WA_FINAL_A-RETURN_QTY1 = WA_FINAL_B-RETURN_QTY1.
WA_FINAL_A-RETURN_QTY2 = WA_FINAL_C-RETURN_QTY1.
WA_FINAL_A-RETURN_COST1 = WA_FINAL_B-RETURN_COST1.
WA_FINAL_A-RETURN_COST2 = WA_FINAL_C-RETURN_COST1.
APPEND WA_FINAL_A TO IT_FINAL_A.
ENDIF.
*ENDAT.
ENDLOOP.
.
LOOP AT IT_FINAL_A INTO WA_FINAL_A .
DELETE IT_FINAL_C WHERE MATNR = WA_FINAL_A-MATNR.
DELETE IT_FINAL_B WHERE MATNR = WA_FINAL_A-MATNR.
ENDLOOP.
LOOP AT IT_FINAL_B INTO WA_FINAL_B.
WA_FINAL_A-ORDER1 = WA_FINAL_B-ORDER1.
WA_FINAL_A-MATNR = WA_FINAL_B-MATNR.
WA_FINAL_A-REQ_QTY1 = WA_FINAL_B-REQ_QTY1.
WA_FINAL_A-ISSUE_QTY1 = WA_FINAL_B-ISSUE_QTY1.
WA_FINAL_A-ISSUE_COST1 = WA_FINAL_B-ISSUE_COST1.
WA_FINAL_A-RETURN_QTY1 = WA_FINAL_B-RETURN_QTY1.
WA_FINAL_A-RETURN_COST1 = WA_FINAL_B-RETURN_COST1.
APPEND WA_FINAL_A TO IT_FINAL_A.
ENDLOOP .
CLEAR WA_FINAL_A.
LOOP AT IT_FINAL_C INTO WA_FINAL_C.
WA_FINAL_A-ORDER2 = WA_FINAL_C-ORDER1.
WA_FINAL_A-MATNR = WA_FINAL_C-MATNR.
WA_FINAL_A-REQ_QTY2 = WA_FINAL_C-REQ_QTY1.
WA_FINAL_A-ISSUE_QTY2 = WA_FINAL_C-ISSUE_QTY1.
WA_FINAL_A-ISSUE_COST2 = WA_FINAL_C-ISSUE_COST1.
WA_FINAL_A-RETURN_QTY2 = WA_FINAL_C-RETURN_QTY1.
WA_FINAL_A-RETURN_COST2 = WA_FINAL_C-RETURN_COST1.
APPEND WA_FINAL_A TO IT_FINAL_A.
ENDLOOP.
SORT IT_FINAL_A BY MATNR ASCENDING.
SELECT MATNR MAKTX FROM MAKT INTO TABLE IT_MAT_DES FOR ALL ENTRIES IN IT_FINAL_A WHERE MATNR = IT_FINAL_A-MATNR.
LOOP AT IT_FINAL_A INTO WA_FINAL_A.
LV_TABIX = SY-TABIX.
READ TABLE IT_MAT_DES INTO WA_MAT_DES WITH KEY MATNR = WA_FINAL_A-MATNR.
IF SY-SUBRC = 0.
WA_FINAL_A-MAKTX = WA_MAT_DES-MAKTX.
ENDIF.
**PER COACH VALUE FROM REQUIRE MENT QUANTITY
IF P_MENGE IS NOT INITIAL AND C_MENGE IS NOT INITIAL AND P_MENGE NE 0 AND C_MENGE NE 0.
WA_FINAL_A-PER_COACH1 = WA_FINAL_A-REQ_QTY1 / P_MENGE.
WA_FINAL_A-PER_COACH2 = WA_FINAL_A-REQ_QTY2 / C_MENGE.
ENDIF.
****NET QUANITYT ISSUE - RETURN *********
WA_FINAL_A-NET_QTY1 = ( WA_FINAL_A-ISSUE_QTY1 - WA_FINAL_A-RETURN_QTY1 ).
WA_FINAL_A-NET_QTY2 = ( WA_FINAL_A-ISSUE_QTY2 - WA_FINAL_A-RETURN_QTY2 ).
****NET COST ISSUE - RETURN *********
WA_FINAL_A-NET_COST1 = ( WA_FINAL_A-ISSUE_COST1 - WA_FINAL_A-RETURN_COST1 ).
WA_FINAL_A-NET_COST2 = ( WA_FINAL_A-ISSUE_COST2 - WA_FINAL_A-RETURN_COST2 ).
MODIFY IT_FINAL_A FROM WA_FINAL_A INDEX LV_TABIX TRANSPORTING MAKTX NET_QTY1 NET_QTY2 PER_COACH1 PER_COACH2 NET_COST1 NET_COST2 .
ENDLOOP .
CLEAR WA_FINAL_A.
ENDFORM. " FINAL_TABLE_DISPLAY
*&---------------------------------------------------------------------*
*& Form SLECT_DATA_LEAGCY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SLECT_DATA_LEAGCY .
SELECT KDAUF FROM ZRESB INTO TABLE IT_LEGACY WHERE KDAUF = P_VBELN .
*DELETE IT_LEGACY WHERE BWART NE '261' AND BWART NE '262' AND BWART NE '201' AND BWART NE'202'.
ENDFORM. " SLECT_DATA_LEAGCY
*&---------------------------------------------------------------------*
*& Form CALCULATE_REQ_LEGACY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALCULATE_REQ_LEGACY .
SORT IT_LEGACY BY KDAUF ASCENDING.
*LOOP AT IT_LEGACY INTO WA_LEGACY.
*AT END OF MATNR.
* SUM.
* WA_TEMP_LEGACY-REQ_QTY = WA_LEGACY-REQ_QTY.
* WA_TEMP_LEGACY-KDAUF = WA_LEGACY-KDAUF.
* WA_TEMP_LEGACY-MATNR = WA_LEGACY-MATNR.
* WA_TEMP_LEGACY-BWART = WA_LEGACY-BWART.
*
* APPEND WA_TEMP_LEGACY TO IT_TEMP_LEGACY.
* ENDAT.
*ENDLOOP.
*REFRESH IT_LEGACY.
*IT_LEGACY[] = IT_TEMP_LEGACY[].
READ TABLE IT_PREV_SAP INTO WA_TEMP_SAP1 INDEX SY-TABIX.
REFRESH IT_TEMP_SAP1.
ENDFORM. " CALCULATE_REQ_LEGACY
*&---------------------------------------------------------------------*
*& Form ISSUE_QTY_LEGACY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ISSUE_QTY_LEGACY .
SELECT MATNR
KDAUF
REQ_QTY
BWART
QTY
COST INTO TABLE IT_ISSUE_LEGACY FROM ZMSEG FOR ALL ENTRIES IN IT_LEGACY WHERE KDAUF = IT_LEGACY-KDAUF.
DELETE IT_ISSUE_LEGACY WHERE BWART NE '261' AND BWART NE '201'.
SORT IT_ISSUE_LEGACY BY MATNR ASCENDING.
LOOP AT IT_ISSUE_LEGACY INTO WA_ISSUE_LEGACY.
AT END OF MATNR.
SUM.
WA_TISSUE_LEGACY-MATNR = WA_ISSUE_LEGACY-MATNR.
WA_TISSUE_LEGACY-REQ_QTY = WA_ISSUE_LEGACY-REQ_QTY.
WA_TISSUE_LEGACY-BWART = WA_ISSUE_LEGACY-BWART.
WA_TISSUE_LEGACY-QTY = WA_ISSUE_LEGACY-QTY.
WA_TISSUE_LEGACY-COST = WA_ISSUE_LEGACY-COST.
APPEND WA_TISSUE_LEGACY TO IT_TISSUE_LEGACY.
ENDAT.
ENDLOOP.
REFRESH IT_ISSUE_LEGACY.
IT_ISSUE_LEGACY[] = IT_TISSUE_LEGACY[].
READ TABLE IT_ISSUE_SAP INTO WA_ISSUE_SAP INDEX 1.
REFRESH IT_TISSUE_LEGACY.
ENDFORM. " ISSUE_QTY_LEGACY
*&---------------------------------------------------------------------*
*& Form RETURN_QTY_LEGACY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM RETURN_QTY_LEGACY .
SELECT MATNR
KDAUF
REQ_QTY
BWART
QTY
COST INTO TABLE IT_RETURN_LEGACY FROM ZMSEG FOR ALL ENTRIES IN IT_LEGACY WHERE KDAUF = IT_LEGACY-KDAUF .
DELETE IT_RETURN_LEGACY WHERE BWART NE '262' AND BWART NE '202'.
SORT IT_RETURN_LEGACY BY MATNR ASCENDING.
LOOP AT IT_RETURN_LEGACY INTO WA_RETURN_LEGACY .
AT END OF MATNR.
SUM.
WA_TISSUE_LEGACY-REQ_QTY = WA_RETURN_LEGACY-REQ_QTY.
WA_TISSUE_LEGACY-MATNR = WA_RETURN_LEGACY-MATNR.
WA_TISSUE_LEGACY-BWART = WA_RETURN_LEGACY-BWART.
WA_TISSUE_LEGACY-QTY = WA_RETURN_LEGACY-QTY.
WA_TISSUE_LEGACY-COST = WA_RETURN_LEGACY-COST.
APPEND WA_TISSUE_LEGACY TO IT_TISSUE_LEGACY.
ENDAT.
ENDLOOP.
REFRESH IT_RETURN_LEGACY.
IT_RETURN_LEGACY[] = IT_TISSUE_LEGACY[].
READ TABLE IT_RETURN_LEGACY INTO WA_RETURN_LEGACY INDEX 1.
REFRESH IT_TISSUE_LEGACY.
ENDFORM. " RETURN_QTY_LEGACY
*&---------------------------------------------------------------------*
*& Form FINAL_LEGACY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FINAL_LEGACY .
LOOP AT IT_LEGACY INTO WA_LEGACY.
LV_TABIX = SY-TABIX.
WA_FINAL_BL-ORDER1 = WA_LEGACY-KDAUF.
*WA_FINAL_BL-REQ_QTY1 = WA_LEGACY-REQ_QTY.
READ TABLE IT_ISSUE_LEGACY INTO WA_ISSUE_LEGACY WITH KEY KDAUF = WA_LEGACY-KDAUF.
IF SY-SUBRC = 0.
WA_FINAL_BL-REQ_QTY1 = WA_ISSUE_LEGACY-REQ_QTY.
WA_FINAL_BL-ISSUE_QTY1 = WA_ISSUE_LEGACY-QTY.
WA_FINAL_BL-ISSUE_COST1 = WA_ISSUE_LEGACY-COST.
WA_FINAL_BL-MATNR = WA_ISSUE_LEGACY-MATNR.
ELSE .
WA_FINAL_BL-MATNR = WA_ISSUE_LEGACY-MATNR.
WA_FINAL_BL-REQ_QTY1 = WA_ISSUE_LEGACY-REQ_QTY.
WA_FINAL_BL-ISSUE_QTY1 = 0.
WA_FINAL_BL-ISSUE_COST1 = 0.
ENDIF .
READ TABLE IT_RETURN_LEGACY INTO WA_RETURN_LEGACY WITH KEY KDAUF = WA_LEGACY-KDAUF.
IF SY-SUBRC <> 0.
WA_FINAL_BL-MATNR = WA_RETURN_LEGACY-MATNR.
WA_FINAL_BL-REQ_QTY1 = WA_RETURN_LEGACY-REQ_QTY.
WA_FINAL_BL-RETURN_QTY1 = WA_RETURN_LEGACY-QTY.
WA_FINAL_BL-RETURN_COST1 = WA_RETURN_LEGACY-COST.
ELSE.
WA_FINAL_BL-MATNR = WA_RETURN_LEGACY-MATNR.
WA_FINAL_BL-RETURN_QTY1 = 0.
WA_FINAL_BL-RETURN_COST1 = 0.
WA_FINAL_BL-REQ_QTY1 = WA_RETURN_LEGACY-REQ_QTY.
ENDIF.
APPEND WA_FINAL_BL TO IT_FINAL_BL.
ENDLOOP.
READ TABLE IT_FINAL_BL INTO WA_FINAL_BL INDEX 1.
REFRESH : IT_ISSUE_SAP,IT_RETURN_SAP.
ENDFORM. " FINAL_LEGACY
*&---------------------------------------------------------------------*
*& Form LEGACY_SAP_COMBINE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM LEGACY_SAP_COMBINE .
DATA : IT_TEMP_FINAL LIKE IT_FINAL_B,
WA_TEMP_FINAL LIKE WA_FINAL_B.
IF IT_FINAL_BL IS NOT INITIAL AND IT_FINAL_B IS NOT INITIAL.
APPEND LINES OF IT_FINAL_BL TO IT_FINAL_B.
SORT IT_FINAL_B BY MATNR ASCENDING.
LOOP AT IT_FINAL_B INTO WA_FINAL_B.
AT END OF MATNR .
SUM.
WA_TEMP_FINAL-ORDER1 = WA_FINAL_B-ORDER1.
WA_TEMP_FINAL-MATNR = WA_FINAL_B-MATNR.
WA_TEMP_FINAL-REQ_QTY1 = WA_FINAL_B-REQ_QTY1.
WA_TEMP_FINAL-ISSUE_QTY1 = WA_FINAL_B-ISSUE_QTY1.
WA_TEMP_FINAL-ISSUE_COST1 = WA_FINAL_B-ISSUE_COST1.
WA_TEMP_FINAL-RETURN_QTY1 = WA_FINAL_B-RETURN_QTY1.
WA_TEMP_FINAL-RETURN_COST1 = WA_FINAL_B-RETURN_COST1.
APPEND WA_TEMP_FINAL TO IT_TEMP_FINAL.
ENDAT.
ENDLOOP.
REFRESH IT_FINAL_B.
IT_FINAL_B[] = IT_TEMP_FINAL[].
ELSEIF IT_FINAL_BL IS NOT INITIAL AND IT_FINAL_B IS INITIAL.
IT_FINAL_B[] = IT_FINAL_BL[].
ENDIF.
ENDFORM. " LEGACY_SAP_COMBINE
*&---------------------------------------------------------------------*
*& Form CONVERSION_SALES_NUMBER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CONVERSION_SALES_NUMBER .
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = P_VBELN
IMPORTING
OUTPUT = P_VBELN
.
ENDFORM. " CONVERSION_SALES_NUMBER
*&---------------------------------------------------------------------*
*& Form FILL_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
** Create a dynamic internal table with this structure.
*
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
I_STYLE_TABLE = 'X'
IT_FIELDCATALOG = IT_FIELDCAT
IMPORTING
EP_TABLE = GT_DYN_TABLE
EXCEPTIONS
GENERATE_SUBPOOL_DIR_FULL = 1
OTHERS = 2.
*
IF SY-SUBRC EQ 0.
* Assign the new table to field symbol
ASSIGN GT_DYN_TABLE->* TO <GFS_DYN_TABLE>.
* Create dynamic work area for the dynamic table
CREATE DATA GW_LINE LIKE LINE OF <GFS_DYN_TABLE>.
CREATE DATA GW_LINE1 LIKE LINE OF <GFS_DYN_TABLE>.
ASSIGN GW_LINE->* TO <GFS_LINE>.
ASSIGN GW_LINE1->* TO <GFS_LINE1>.
ENDIF.
*********************
SORT IT_FINAL_A ASCENDING BY ORDER2.
LOOP AT IT_FINAL_A INTO WA_FINAL_A.
IF <GFS_DYN_TABLE> IS NOT INITIAL .
READ TABLE <GFS_DYN_TABLE> ASSIGNING <GFS_LINE1> WITH KEY ('MATNR') = WA_FINAL_A-MATNR .
IF SY-SUBRC EQ 0 .
CONCATENATE WA_FINAL_A-ORDER2 'REQ_QTY2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE1> TO <FS1>.
<FS1> = WA_FINAL_A-REQ_QTY2.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'NET_QTY2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE1> TO <FS1>.
<FS1> = WA_FINAL_A-NET_QTY2.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'NET_COST2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE1> TO <FS1>.
<FS1> = WA_FINAL_A-NET_COST2.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'PER_COACH2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE1> TO <FS1>.
<FS1> = WA_FINAL_A-PER_COACH2.
UNASSIGN <FS1>.
*APPEND <gfs_line> TO <gfs_dyn_table>.
MODIFY TABLE <GFS_DYN_TABLE> FROM <GFS_LINE1>.
CLEAR : <GFS_LINE1>.
ELSE.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-MATNR .
UNASSIGN <FS1>.
ASSIGN COMPONENT 'MAKTX' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-MAKTX.
UNASSIGN <FS1>.
ASSIGN COMPONENT 'REQ_QTY1' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-REQ_QTY1.
UNASSIGN <FS1>.
ASSIGN COMPONENT 'NET_QTY1' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-NET_QTY1.
UNASSIGN <FS1>.
ASSIGN COMPONENT 'NET_COST1' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-NET_COST1.
UNASSIGN <FS1>.
ASSIGN COMPONENT 'PER_COACH1' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-PER_COACH1.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'REQ_QTY2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-REQ_QTY2.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'NET_QTY2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-NET_QTY2.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'NET_COST2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-NET_COST2.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'PER_COACH2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-PER_COACH2.
UNASSIGN <FS1>.
APPEND <GFS_LINE> TO <GFS_DYN_TABLE>.
ENDIF.
ELSE.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-MATNR .
UNASSIGN <FS1>.
ASSIGN COMPONENT 'MAKTX' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-MAKTX.
UNASSIGN <FS1>.
ASSIGN COMPONENT 'REQ_QTY1' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-REQ_QTY1.
UNASSIGN <FS1>.
ASSIGN COMPONENT 'NET_QTY1' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-NET_QTY1.
UNASSIGN <FS1>.
ASSIGN COMPONENT 'NET_COST1' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-NET_COST1.
UNASSIGN <FS1>.
ASSIGN COMPONENT 'PER_COACH1' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-PER_COACH1.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'REQ_QTY2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-REQ_QTY2.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'NET_QTY2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-NET_QTY2.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'NET_COST2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-NET_COST2.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'PER_COACH2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-PER_COACH2.
UNASSIGN <FS1>.
APPEND <GFS_LINE> TO <GFS_DYN_TABLE>.
ENDIF.
*APPEND <gfs_line> TO <gfs_dyn_table>.
UNASSIGN <FS1>.
CLEAR WA_FINAL_A.
ENDLOOP.
*CLEAR: <gfs_line>.
ENDFORM. " FILL_FIELDCAT
*&---------------------------------------------------------------------*
*& Form GRID_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GRID_DISPLAY .
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 = '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 = <GFS_DYN_TABLE>
* 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. " GRID_DISPLAY
*&---------------------------------------------------------------------*
*& Form LIST_HEADER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM LIST_HEADER .
*Type H is used to display headers i.e. big font
WA_LISTHEADER-TYP = 'H'.
WA_LISTHEADER-INFO ='BATCH ORDER COMPARISION '.
APPEND WA_LISTHEADER TO IT_LISTHEADER.
CLEAR WA_LISTHEADER.
* Type S is used to display key and value pairs
WA_LISTHEADER-TYP = 'S'.
WA_LISTHEADER-KEY = 'Date :' .
CONCATENATE SY-DATUM+6(2)
SY-DATUM+4(2)
SY-DATUM(4)
INTO WA_LISTHEADER-INFO
SEPARATED BY '/'.
APPEND WA_LISTHEADER TO IT_LISTHEADER.
CLEAR WA_LISTHEADER.
* Type A is used to display italic font
WA_LISTHEADER-TYP = 'A'.
WA_LISTHEADER-INFO ='SAP ALV Report'.
APPEND WA_LISTHEADER TO IT_LISTHEADER.
CLEAR WA_LISTHEADER.
ENDFORM. " LIST_HEADER
*&---------------------------------------------------------------------*
*& Form TOP_OF_PAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM TOP_OF_PAGE .
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = IT_LISTHEADER
I_LOGO = 'ICF_LOGO'.
ENDFORM. " TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form FILL_FIELDCAT_1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILL_FIELDCAT_1 .
WA_FIELDCAT1-FIELDNAME = 'MATNR'.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 20.
WA_FIELDCAT1-SELTEXT_L = 'MATERIAL'.
WA_FIELDCAT1-COL_POS = 1.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR WA_FIELDCAT1.
WA_FIELDCAT1-FIELDNAME = 'MAKTX'.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 20.
WA_FIELDCAT1-SELTEXT_L = 'MATL_DESC.'.
WA_FIELDCAT1-COL_POS = 2.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR WA_FIELDCAT1.
WA_FIELDCAT1-FIELDNAME = 'REQ_QTY1'.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 12.
WA_FIELDCAT1-SELTEXT_L = 'PREV. REQ QTY'.
WA_FIELDCAT1-COL_POS = 3.
WA_FIELDCAT1-DO_SUM = 'X'.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR WA_FIELDCAT1.
WA_FIELDCAT1-FIELDNAME = 'NET_QTY1'.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 12.
WA_FIELDCAT1-SELTEXT_L = 'PREV. NET QTY'.
WA_FIELDCAT1-COL_POS = 4.
WA_FIELDCAT1-DO_SUM = 'X'.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR WA_FIELDCAT1.
WA_FIELDCAT1-FIELDNAME = 'NET_COST1'.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 12.
WA_FIELDCAT1-SELTEXT_L = 'PREV. NET COST'.
WA_FIELDCAT1-COL_POS = 5.
WA_FIELDCAT1-DO_SUM = 'X'.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR WA_FIELDCAT1.
WA_FIELDCAT1-FIELDNAME = 'PER_COACH1'.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 12.
WA_FIELDCAT1-SELTEXT_L = 'PREV. PER COACH '.
WA_FIELDCAT1-COL_POS = 6.
WA_FIELDCAT1-DO_SUM = 'X'.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR WA_FIELDCAT1.
GV_POS = 6.
LOOP AT IT_FINAL_A INTO WA_FINAL_A.
AT NEW ORDER2.
CONCATENATE WA_FINAL_A-ORDER2 'REQ_QTY2' INTO FNAME .
* read table IT_FIELDCAT1 into WA_FIELDCAT1 with key fieldname = WA_FINAL_A-ORDER2.
* IF SY-SUBRC NE 0.
GV_POS = GV_POS + 1.
WA_FIELDCAT1-FIELDNAME = FNAME.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 12.
WA_FIELDCAT1-SELTEXT_L = FNAME.
WA_FIELDCAT1-DO_SUM = 'X'.
WA_FIELDCAT1-COL_POS = GV_POS.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR : WA_FIELDCAT1, FNAME .
CONCATENATE WA_FINAL_A-ORDER2 'NET_QTY2' INTO FNAME .
GV_POS = GV_POS + 1.
WA_FIELDCAT1-FIELDNAME = FNAME.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 12.
WA_FIELDCAT1-SELTEXT_L = FNAME.
WA_FIELDCAT1-COL_POS = GV_POS.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR :WA_FIELDCAT1,FNAME.
CONCATENATE WA_FINAL_A-ORDER2 'NET_COST2' INTO FNAME .
GV_POS = GV_POS + 1.
WA_FIELDCAT1-FIELDNAME = FNAME.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 12.
WA_FIELDCAT1-SELTEXT_L = FNAME.
WA_FIELDCAT1-COL_POS = GV_POS.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR : WA_FIELDCAT1, FNAME.
CONCATENATE WA_FINAL_A-ORDER2 'PER_COACH2' INTO FNAME .
GV_POS = GV_POS + 1.
WA_FIELDCAT1-FIELDNAME = FNAME.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 12.
WA_FIELDCAT1-SELTEXT_L = FNAME.
WA_FIELDCAT1-COL_POS = GV_POS.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR :WA_FIELDCAT1 ,FNAME.
* ENDIF.
ENDAT.
ENDLOOP.
* LT_LAYOUT-ZEBRA = 'X'.
LT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
*
ENDFORM. " FILL_FIELDCAT_1
*& Report ZABATCH_ORDER_COMPARE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZABATCH_ORDER_COMPARE LINE-SIZE 300 .
TYPE-POOLS SLIS.
TABLES : RESB,VBAP.
******************SELECTION BEGIN OF **************************************
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETER : P_VBELN TYPE ZRESB-KDAUF,
P_MENGE TYPE VBAP-ZMENG.
SELECTION-SCREEN END OF BLOCK B1 .
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
SELECT-OPTIONS : C_VBELN FOR VBAP-VBELN.
PARAMETER C_MENGE TYPE VBAP-ZMENG.
SELECTION-SCREEN END OF BLOCK B2 .
******************SELECTION END OF **************************************
********** STRUCUTURE DECLARATION ********************************
TYPES : BEGIN OF TY_LEG,
KDAUF TYPE ZRESB-KDAUF,
* MATNR TYPE ZRESB-MATNR,
* REQ_QTY TYPE ZRESB-REQ_QTY,
* BWART TYPE ZRESB-BWART,
END OF TY_LEG.
TYPES : BEGIN OF TY_LEGACY2,
MATNR TYPE ZMSEG-MATNR,
KDAUF TYPE ZMSEG-KDAUF,
REQ_QTY TYPE BDMNG,
BWART TYPE ZMSEG-BWART,
QTY TYPE ZMSEG-QTY,
COST TYPE ZMSEG-COST,
END OF TY_LEGACY2.
TYPES : BEGIN OF TY_ORDER,
MATNR TYPE MATNR ,
KDAUF TYPE KDAUF ,
BWART TYPE BWART,
BDMNG TYPE BDMNG,
END OF TY_ORDER ,
BEGIN OF TY_B_FINAL,
MATNR TYPE MATNR,
ORDER1 TYPE KDAUF,
REQ_QTY1 TYPE BDMNG,
ISSUE_QTY1 TYPE BDMNG,
ISSUE_COST1 TYPE DMBTR,
RETURN_QTY1 TYPE MENGE_D,
RETURN_COST1 TYPE DMBTR,
END OF TY_B_FINAL,
BEGIN OF TY_A_FINAL,
MATNR TYPE MATNR,
ORDER1 TYPE KDAUF,
MAKTX TYPE MAKTX ,
REQ_QTY1 TYPE BDMNG,
ISSUE_QTY1 TYPE BDMNG,
ISSUE_COST1 TYPE DMBTR,
RETURN_QTY1 TYPE MENGE_D,
RETURN_COST1 TYPE DMBTR,
NET_QTY1 TYPE MENGE_D,
ORDER2 TYPE KDAUF,
* MATNR2 TYPE MATNR,
REQ_QTY2 TYPE BDMNG,
ISSUE_QTY2 TYPE BDMNG,
ISSUE_COST2 TYPE DMBTR,
RETURN_QTY2 TYPE MENGE_D,
RETURN_COST2 TYPE DMBTR,
NET_QTY2 TYPE MENGE_D,
REMARK TYPE STRING,
END OF TY_A_FINAL,
BEGIN OF TY_DES,
MATNR TYPE MATNR ,
MAKTX TYPE MAKTX,
END OF TY_DES,
BEGIN OF TY_MSEG,
MATNR TYPE MATNR ,
BWART TYPE BWART,
MENGE TYPE MENGE_D,
DMBTR TYPE DMBTR,
END OF TY_MSEG.
************* INGTERNAL TABLE DECLARATION AND WORKAAREA , VARIABLE ******************
* *******PREVIOUS DATA SAP**************
DATA : IT_PREV_SAP TYPE STANDARD TABLE OF TY_ORDER,
WA_PREV_SAP TYPE TY_ORDER,
WA_PREV_SAP1 TYPE TY_ORDER.
DATA: IT_LEGACY TYPE STANDARD TABLE OF TY_LEG,
WA_LEGACY TYPE TY_LEG.
DATA : IT_MAT_DES TYPE STANDARD TABLE OF TY_DES,
WA_MAT_DES TYPE TY_DES.
DATA : IT_ISSUE_LEGACY TYPE STANDARD TABLE OF TY_LEGACY2,
WA_ISSUE_LEGACY TYPE TY_LEGACY2.
DATA : IT_RETURN_LEGACY TYPE STANDARD TABLE OF TY_LEGACY2,
WA_RETURN_LEGACY TYPE TY_LEGACY2.
DATA : IT_FINAL_B TYPE STANDARD TABLE OF TY_B_FINAL,
WA_FINAL_B TYPE TY_B_FINAL.
DATA : IT_FINAL_BL TYPE STANDARD TABLE OF TY_B_FINAL,
WA_FINAL_BL TYPE TY_B_FINAL.
DATA : IT_ISSUE_SAP TYPE STANDARD TABLE OF TY_MSEG,
IT_RETURN_SAP TYPE STANDARD TABLE OF TY_MSEG,
WA_ISSUE_SAP TYPE TY_MSEG,
WA_RETURN_SAP TYPE TY_MSEG.
* *******END PREVIOUS DATA SAP**************
* *******CURRENT DATA SAP******************
DATA : IT_CURR_SAP TYPE STANDARD TABLE OF TY_ORDER,
WA_CURR_SAP TYPE TY_ORDER,
WA_CURR_SAP1 TYPE TY_ORDER.
DATA : IT_FINAL_C TYPE STANDARD TABLE OF TY_B_FINAL,
WA_FINAL_C TYPE TY_B_FINAL.
************************TEMPORARY TABLE *********************************************
DATA: IT_TEMP_LEGACY TYPE STANDARD TABLE OF TY_LEG,
WA_TEMP_LEGACY TYPE TY_LEG.
DATA : IT_TISSUE_LEGACY TYPE STANDARD TABLE OF TY_LEGACY2,
WA_TISSUE_LEGACY TYPE TY_LEGACY2.
DATA : IT_TEMP_SAP1 TYPE STANDARD TABLE OF TY_ORDER,
WA_TEMP_SAP1 TYPE TY_ORDER.
DATA : IT_TEMP_ISSUE TYPE STANDARD TABLE OF TY_MSEG,
WA_TEMP_ISSUE TYPE TY_MSEG.
DATA : LV_TABIX TYPE I,
FM_NAME TYPE RS38L_FNAM,
TEMP_STR1 TYPE STRING,
TEMP_STR2 TYPE STRING.
DATA : PLAN_QTY1 TYPE MENGE_D,
PLAN_QTY2 TYPE MENGE_D,
PLAN_QTY TYPE MENGE_D,
DRAWN_QTY TYPE MENGE_D,
DRAWN_QTY2 TYPE MENGE_D,
RESULT TYPE MENGE_D,
RATIO_B TYPE MENGE_D.
* ****************FINAL***********************************
DATA : IT_FINAL_A TYPE STANDARD TABLE OF ZBORAD_FINAL,
WA_FINAL_A TYPE ZBORAD_FINAL,
WA_FINAL_A1 TYPE ZBORAD_FINAL.
DATA : IT_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV,
LT_LAYOUT TYPE SLIS_LAYOUT_ALV,
WA_FIELDCAT1 TYPE SLIS_FIELDCAT_ALV.
DATA: IT_LISTHEADER TYPE SLIS_T_LISTHEADER,
WA_LISTHEADER TYPE SLIS_LISTHEADER.
* Dynamic Table Declarations
*
DATA : GT_DYN_TABLE TYPE REF TO DATA,
GW_LINE TYPE REF TO DATA,
GW_LINE1 TYPE REF TO DATA,
WA_FIELDCAT TYPE LVC_S_FCAT,
IT_FIELDCAT TYPE LVC_T_FCAT.
* Field Symbols Declarations
FIELD-SYMBOLS: <GFS_LINE>,<GFS_LINE1>,
<GFS_DYN_TABLE> TYPE STANDARD TABLE,
<FS1>.
DATA : GV_POS TYPE I.
DATA : FNAME TYPE STRING.
**************START-OF-SELECTION.*****************************************************
*****************SELECT DATA FROM LEGACY SYSTEM ******************************************
PERFORM CONVERSION_SALES_NUMBER .
PERFORM SLECT_DATA_LEAGCY.
PERFORM CALCULATE_REQ_LEGACY.
PERFORM ISSUE_QTY_LEGACY.
PERFORM RETURN_QTY_LEGACY.
PERFORM FINAL_LEGACY.
*****************SELECT DATA PREVIOUS SAP SALES ORDER ************************************
PERFORM SELECT_DATA_SAP.
PERFORM CALCULATE_REQ_SAP .
PERFORM ISSUE_QTY_SAP .
PERFORM RETURN_QTY_SAP.
PERFORM FINAL_SAP1.
PERFORM LEGACY_SAP_COMBINE.
*******************END SELECTION PREVIOUS SAP SALES ORDER *********************************
PERFORM SELCT_CURR_DATA_SAP.
PERFORM CALCULATE_CURR_REQ_SAP.
PERFORM ISSUE_CURR_QTY_SAP .
PERFORM RETURN_CURR_QTY_SAP.
PERFORM FINAL_SAP2.
********************************************************************************************
PERFORM FINAL_TABLE_DISPLAY.
PERFORM FILL_FIELDCAT.
PERFORM FILL_FIELDCAT_1.
PERFORM LIST_HEADER .
PERFORM TOP_OF_PAGE.
PERFORM GRID_DISPLAY.
*&---------------------------------------------------------------------*
*& Form SELECT_DATA_SAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SELECT_DATA_SAP .
SELECT MATNR KDAUF BWART BDMNG INTO TABLE IT_PREV_SAP FROM RESB WHERE KDAUF = P_VBELN .
DELETE IT_PREV_SAP WHERE BWART NE '261' AND BWART NE '202' AND BWART NE '201' AND BWART NE '262' .
ENDFORM. " SELECT_DATA_SAP
*&---------------------------------------------------------------------*
*& Form CALCULATE_REQ_SAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALCULATE_REQ_SAP .
SORT IT_PREV_SAP BY MATNR ASCENDING.
LOOP AT IT_PREV_SAP INTO WA_PREV_SAP.
IF IT_TEMP_SAP1 IS NOT INITIAL .
READ TABLE IT_TEMP_SAP1 INTO WA_TEMP_SAP1 WITH KEY MATNR = WA_PREV_SAP-MATNR KDAUF = WA_PREV_SAP-KDAUF.
IF SY-SUBRC EQ 0 .
WA_TEMP_SAP1-BDMNG = WA_TEMP_SAP1-BDMNG + WA_PREV_SAP-BDMNG.
MODIFY IT_TEMP_SAP1 FROM WA_TEMP_SAP1 TRANSPORTING BDMNG.
ENDIF.
WA_TEMP_SAP1-BDMNG = WA_PREV_SAP-BDMNG.
WA_TEMP_SAP1-KDAUF = WA_PREV_SAP-KDAUF.
WA_TEMP_SAP1-MATNR = WA_PREV_SAP-MATNR.
WA_TEMP_SAP1-BWART = WA_PREV_SAP-BWART.
APPEND WA_TEMP_SAP1 TO IT_TEMP_SAP1.
ENDIF .
CLEAR WA_TEMP_SAP1.
ENDLOOP.
REFRESH IT_PREV_SAP.
IT_PREV_SAP[] = IT_TEMP_SAP1[].
READ TABLE IT_PREV_SAP INTO WA_TEMP_SAP1 INDEX SY-TABIX.
REFRESH IT_TEMP_SAP1.
ENDFORM. " CALCULATE_REQ_SAP
*&---------------------------------------------------------------------*
*& Form ISSUE_QTY_SAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ISSUE_QTY_SAP .
SELECT MATNR BWART MENGE DMBTR INTO TABLE IT_ISSUE_SAP FROM MSEG FOR ALL ENTRIES IN IT_PREV_SAP WHERE MATNR = IT_PREV_SAP-MATNR.
DELETE IT_ISSUE_SAP WHERE BWART NE '261' AND BWART NE '201'.
SORT IT_ISSUE_SAP BY MATNR ASCENDING.
LOOP AT IT_ISSUE_SAP INTO WA_ISSUE_SAP.
AT END OF MATNR .
SUM.
WA_TEMP_ISSUE-MATNR = WA_ISSUE_SAP-MATNR.
WA_TEMP_ISSUE-BWART = WA_ISSUE_SAP-BWART.
WA_TEMP_ISSUE-MENGE = WA_ISSUE_SAP-MENGE.
WA_TEMP_ISSUE-DMBTR = WA_ISSUE_SAP-DMBTR.
APPEND WA_TEMP_ISSUE TO IT_TEMP_ISSUE.
ENDAT.
ENDLOOP.
REFRESH IT_ISSUE_SAP.
IT_ISSUE_SAP[] = IT_TEMP_ISSUE[].
READ TABLE IT_ISSUE_SAP INTO WA_ISSUE_SAP INDEX 1.
REFRESH IT_TEMP_ISSUE.
ENDFORM. " ISSUE_QTY_SAP
*&---------------------------------------------------------------------*
*& Form RETURN_QTY_SAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM RETURN_QTY_SAP .
REFRESH IT_TEMP_ISSUE.
SELECT MATNR BWART MENGE DMBTR INTO TABLE IT_RETURN_SAP FROM MSEG FOR ALL ENTRIES IN IT_PREV_SAP WHERE MATNR = IT_PREV_SAP-MATNR.
DELETE IT_RETURN_SAP WHERE BWART NE '262' AND BWART NE '202'.
SORT IT_RETURN_SAP BY MATNR ASCENDING.
LOOP AT IT_RETURN_SAP INTO WA_RETURN_SAP.
AT END OF MATNR.
SUM.
WA_TEMP_ISSUE-MATNR = WA_ISSUE_SAP-MATNR.
WA_TEMP_ISSUE-BWART = WA_ISSUE_SAP-BWART.
WA_TEMP_ISSUE-MENGE = WA_ISSUE_SAP-MENGE.
WA_TEMP_ISSUE-DMBTR = WA_ISSUE_SAP-DMBTR.
APPEND WA_TEMP_ISSUE TO IT_TEMP_ISSUE.
ENDAT.
ENDLOOP.
REFRESH IT_RETURN_SAP.
IT_RETURN_SAP[] = IT_TEMP_ISSUE[].
REFRESH IT_TEMP_ISSUE.
ENDFORM. " RETURN_QTY_SAP
*&---------------------------------------------------------------------*
*& Form FINAL_SAP1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FINAL_SAP1 .
LOOP AT IT_PREV_SAP INTO WA_PREV_SAP.
LV_TABIX = SY-TABIX.
WA_FINAL_B-ORDER1 = WA_PREV_SAP-KDAUF.
WA_FINAL_B-MATNR = WA_PREV_SAP-MATNR.
WA_FINAL_B-REQ_QTY1 = WA_PREV_SAP-BDMNG.
READ TABLE IT_ISSUE_SAP INTO WA_ISSUE_SAP WITH KEY MATNR = WA_PREV_SAP-MATNR.
IF SY-SUBRC = 0.
WA_FINAL_B-ISSUE_QTY1 = WA_ISSUE_SAP-MENGE.
WA_FINAL_B-ISSUE_COST1 = WA_ISSUE_SAP-DMBTR.
ELSE .
WA_FINAL_B-ISSUE_QTY1 = 0.
WA_FINAL_B-ISSUE_COST1 = 0..
ENDIF .
READ TABLE IT_RETURN_SAP INTO WA_RETURN_SAP WITH KEY MATNR = WA_PREV_SAP-MATNR.
IF SY-SUBRC = 0.
WA_FINAL_B-RETURN_QTY1 = WA_RETURN_SAP-MENGE.
WA_FINAL_B-RETURN_COST1 = WA_RETURN_SAP-DMBTR.
ELSE.
WA_FINAL_B-RETURN_QTY1 = 0.
WA_FINAL_B-RETURN_COST1 = 0.
ENDIF.
APPEND WA_FINAL_B TO IT_FINAL_B.
ENDLOOP.
READ TABLE IT_FINAL_B INTO WA_FINAL_B INDEX 1.
REFRESH : IT_ISSUE_SAP,IT_RETURN_SAP.
ENDFORM. " FINAL_SAP1
*&---------------------------------------------------------------------*
*& Form SELCT_C_DATA_SAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SELCT_CURR_DATA_SAP .
SELECT MATNR KDAUF BWART BDMNG INTO TABLE IT_CURR_SAP FROM RESB WHERE KDAUF IN C_VBELN .
DELETE IT_CURR_SAP WHERE BWART NE '261' AND BWART NE '202' AND BWART NE '201' AND BWART NE '262' .
ENDFORM. " SELCT_C_DATA_SAP
*&---------------------------------------------------------------------*
*& Form CALCULATE_CURR_REQ_SAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALCULATE_CURR_REQ_SAP .
SORT IT_CURR_SAP BY MATNR ASCENDING.
LOOP AT IT_CURR_SAP INTO WA_CURR_SAP.
IF IT_TEMP_SAP1 IS NOT INITIAL .
READ TABLE IT_TEMP_SAP1 INTO WA_TEMP_SAP1 WITH KEY MATNR = WA_CURR_SAP-MATNR KDAUF = WA_CURR_SAP-KDAUF.
IF SY-SUBRC EQ 0 .
WA_TEMP_SAP1-BDMNG = WA_TEMP_SAP1-BDMNG + WA_CURR_SAP-BDMNG.
MODIFY TABLE IT_TEMP_SAP1 FROM WA_TEMP_SAP1 TRANSPORTING BDMNG.
ELSE.
WA_TEMP_SAP1-BDMNG = WA_CURR_SAP-BDMNG.
WA_TEMP_SAP1-KDAUF = WA_CURR_SAP-KDAUF.
WA_TEMP_SAP1-MATNR = WA_CURR_SAP-MATNR.
WA_TEMP_SAP1-BWART = WA_CURR_SAP-BWART.
APPEND WA_TEMP_SAP1 TO IT_TEMP_SAP1.
ENDIF.
ELSE.
WA_TEMP_SAP1-BDMNG = WA_CURR_SAP-BDMNG.
WA_TEMP_SAP1-KDAUF = WA_CURR_SAP-KDAUF.
WA_TEMP_SAP1-MATNR = WA_CURR_SAP-MATNR.
WA_TEMP_SAP1-BWART = WA_CURR_SAP-BWART.
APPEND WA_TEMP_SAP1 TO IT_TEMP_SAP1.
ENDIF .
ENDLOOP.
REFRESH IT_CURR_SAP.
IT_CURR_SAP[] = IT_TEMP_SAP1[].
READ TABLE IT_CURR_SAP INTO WA_CURR_SAP INDEX SY-TABIX.
REFRESH IT_TEMP_SAP1.
ENDFORM. " CALCULATE_CURR_REQ_SAP
*&---------------------------------------------------------------------*
*& Form ISSUE_CURR_QTY_SAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ISSUE_CURR_QTY_SAP .
SELECT MATNR BWART MENGE DMBTR INTO TABLE IT_ISSUE_SAP FROM MSEG FOR ALL ENTRIES IN IT_CURR_SAP WHERE MATNR = IT_CURR_SAP-MATNR.
DELETE IT_ISSUE_SAP WHERE BWART NE '261' AND BWART NE '201'.
SORT IT_ISSUE_SAP BY MATNR ASCENDING.
LOOP AT IT_ISSUE_SAP INTO WA_ISSUE_SAP.
AT END OF MATNR.
SUM.
WA_TEMP_ISSUE-MATNR = WA_ISSUE_SAP-MATNR.
WA_TEMP_ISSUE-BWART = WA_ISSUE_SAP-BWART.
WA_TEMP_ISSUE-MENGE = WA_ISSUE_SAP-MENGE.
WA_TEMP_ISSUE-DMBTR = WA_ISSUE_SAP-DMBTR.
APPEND WA_TEMP_ISSUE TO IT_TEMP_ISSUE.
ENDAT.
ENDLOOP.
REFRESH IT_ISSUE_SAP.
IT_ISSUE_SAP[] = IT_TEMP_ISSUE[].
READ TABLE IT_ISSUE_SAP INTO WA_ISSUE_SAP INDEX 1.
ENDFORM. " ISSUE_CURR_QTY_SAP
*&---------------------------------------------------------------------*
*& Form RETURN_CURR_QTY_SAP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM RETURN_CURR_QTY_SAP .
REFRESH IT_TEMP_ISSUE.
SELECT MATNR BWART MENGE DMBTR INTO TABLE IT_RETURN_SAP FROM MSEG FOR ALL ENTRIES IN IT_CURR_SAP WHERE MATNR = IT_CURR_SAP-MATNR.
DELETE IT_RETURN_SAP WHERE BWART NE '262' AND BWART NE '202'.
SORT IT_RETURN_SAP BY MATNR ASCENDING.
LOOP AT IT_RETURN_SAP INTO WA_RETURN_SAP.
AT END OF MATNR.
SUM.
WA_TEMP_ISSUE-MATNR = WA_ISSUE_SAP-MATNR.
WA_TEMP_ISSUE-BWART = WA_ISSUE_SAP-BWART.
WA_TEMP_ISSUE-MENGE = WA_ISSUE_SAP-MENGE.
WA_TEMP_ISSUE-DMBTR = WA_ISSUE_SAP-DMBTR.
APPEND WA_TEMP_ISSUE TO IT_TEMP_ISSUE.
ENDAT.
ENDLOOP.
REFRESH IT_RETURN_SAP.
IT_RETURN_SAP[] = IT_TEMP_ISSUE[].
REFRESH IT_TEMP_ISSUE.
ENDFORM. " RETURN_CURR_QTY_SAP
*&---------------------------------------------------------------------*
*& Form FINAL_SAP2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FINAL_SAP2 .
LOOP AT IT_CURR_SAP INTO WA_CURR_SAP.
LV_TABIX = SY-TABIX.
WA_FINAL_C-ORDER1 = WA_CURR_SAP-KDAUF.
WA_FINAL_C-MATNR = WA_CURR_SAP-MATNR.
WA_FINAL_C-REQ_QTY1 = WA_CURR_SAP-BDMNG.
READ TABLE IT_ISSUE_SAP INTO WA_ISSUE_SAP WITH KEY MATNR = WA_CURR_SAP-MATNR.
IF SY-SUBRC = 0.
WA_FINAL_C-ISSUE_QTY1 = WA_ISSUE_SAP-MENGE.
WA_FINAL_C-ISSUE_COST1 = WA_ISSUE_SAP-DMBTR.
ELSE .
WA_FINAL_C-ISSUE_QTY1 = 0.
WA_FINAL_C-ISSUE_COST1 = 0..
ENDIF .
READ TABLE IT_RETURN_SAP INTO WA_RETURN_SAP WITH KEY MATNR = WA_CURR_SAP-MATNR.
IF SY-SUBRC = 0.
WA_FINAL_C-RETURN_QTY1 = WA_RETURN_SAP-MENGE.
WA_FINAL_C-RETURN_COST1 = WA_RETURN_SAP-DMBTR.
ELSE.
WA_FINAL_C-RETURN_QTY1 = 0.
WA_FINAL_C-RETURN_COST1 = 0.
ENDIF.
APPEND WA_FINAL_C TO IT_FINAL_C.
ENDLOOP.
READ TABLE IT_FINAL_C INTO WA_FINAL_C INDEX 1.
REFRESH : IT_ISSUE_SAP,IT_RETURN_SAP.
ENDFORM. " FINAL_SAP2
*&---------------------------------------------------------------------*
*& Form FINAL_TABLE_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FINAL_TABLE_DISPLAY .
LOOP AT IT_FINAL_B INTO WA_FINAL_B.
*AT NEW MATNR .
READ TABLE IT_FINAL_C INTO WA_FINAL_C WITH KEY MATNR = WA_FINAL_B-MATNR .
IF SY-SUBRC = 0.
WA_FINAL_A-ORDER1 = WA_FINAL_B-ORDER1.
WA_FINAL_A-ORDER2 = WA_FINAL_C-ORDER1.
WA_FINAL_A-MATNR = WA_FINAL_B-MATNR.
WA_FINAL_A-REQ_QTY1 = WA_FINAL_B-REQ_QTY1.
WA_FINAL_A-REQ_QTY2 = WA_FINAL_C-REQ_QTY1.
WA_FINAL_A-ISSUE_QTY1 = WA_FINAL_B-ISSUE_QTY1.
WA_FINAL_A-ISSUE_COST1 = WA_FINAL_C-ISSUE_COST1.
WA_FINAL_A-ISSUE_QTY2 = WA_FINAL_B-ISSUE_QTY1.
WA_FINAL_A-ISSUE_COST2 = WA_FINAL_C-ISSUE_COST1.
WA_FINAL_A-RETURN_QTY1 = WA_FINAL_B-RETURN_QTY1.
WA_FINAL_A-RETURN_QTY2 = WA_FINAL_C-RETURN_QTY1.
WA_FINAL_A-RETURN_COST1 = WA_FINAL_B-RETURN_COST1.
WA_FINAL_A-RETURN_COST2 = WA_FINAL_C-RETURN_COST1.
APPEND WA_FINAL_A TO IT_FINAL_A.
ENDIF.
*ENDAT.
ENDLOOP.
.
LOOP AT IT_FINAL_A INTO WA_FINAL_A .
DELETE IT_FINAL_C WHERE MATNR = WA_FINAL_A-MATNR.
DELETE IT_FINAL_B WHERE MATNR = WA_FINAL_A-MATNR.
ENDLOOP.
LOOP AT IT_FINAL_B INTO WA_FINAL_B.
WA_FINAL_A-ORDER1 = WA_FINAL_B-ORDER1.
WA_FINAL_A-MATNR = WA_FINAL_B-MATNR.
WA_FINAL_A-REQ_QTY1 = WA_FINAL_B-REQ_QTY1.
WA_FINAL_A-ISSUE_QTY1 = WA_FINAL_B-ISSUE_QTY1.
WA_FINAL_A-ISSUE_COST1 = WA_FINAL_B-ISSUE_COST1.
WA_FINAL_A-RETURN_QTY1 = WA_FINAL_B-RETURN_QTY1.
WA_FINAL_A-RETURN_COST1 = WA_FINAL_B-RETURN_COST1.
APPEND WA_FINAL_A TO IT_FINAL_A.
ENDLOOP .
CLEAR WA_FINAL_A.
LOOP AT IT_FINAL_C INTO WA_FINAL_C.
WA_FINAL_A-ORDER2 = WA_FINAL_C-ORDER1.
WA_FINAL_A-MATNR = WA_FINAL_C-MATNR.
WA_FINAL_A-REQ_QTY2 = WA_FINAL_C-REQ_QTY1.
WA_FINAL_A-ISSUE_QTY2 = WA_FINAL_C-ISSUE_QTY1.
WA_FINAL_A-ISSUE_COST2 = WA_FINAL_C-ISSUE_COST1.
WA_FINAL_A-RETURN_QTY2 = WA_FINAL_C-RETURN_QTY1.
WA_FINAL_A-RETURN_COST2 = WA_FINAL_C-RETURN_COST1.
APPEND WA_FINAL_A TO IT_FINAL_A.
ENDLOOP.
SORT IT_FINAL_A BY MATNR ASCENDING.
SELECT MATNR MAKTX FROM MAKT INTO TABLE IT_MAT_DES FOR ALL ENTRIES IN IT_FINAL_A WHERE MATNR = IT_FINAL_A-MATNR.
LOOP AT IT_FINAL_A INTO WA_FINAL_A.
LV_TABIX = SY-TABIX.
READ TABLE IT_MAT_DES INTO WA_MAT_DES WITH KEY MATNR = WA_FINAL_A-MATNR.
IF SY-SUBRC = 0.
WA_FINAL_A-MAKTX = WA_MAT_DES-MAKTX.
ENDIF.
**PER COACH VALUE FROM REQUIRE MENT QUANTITY
IF P_MENGE IS NOT INITIAL AND C_MENGE IS NOT INITIAL AND P_MENGE NE 0 AND C_MENGE NE 0.
WA_FINAL_A-PER_COACH1 = WA_FINAL_A-REQ_QTY1 / P_MENGE.
WA_FINAL_A-PER_COACH2 = WA_FINAL_A-REQ_QTY2 / C_MENGE.
ENDIF.
****NET QUANITYT ISSUE - RETURN *********
WA_FINAL_A-NET_QTY1 = ( WA_FINAL_A-ISSUE_QTY1 - WA_FINAL_A-RETURN_QTY1 ).
WA_FINAL_A-NET_QTY2 = ( WA_FINAL_A-ISSUE_QTY2 - WA_FINAL_A-RETURN_QTY2 ).
****NET COST ISSUE - RETURN *********
WA_FINAL_A-NET_COST1 = ( WA_FINAL_A-ISSUE_COST1 - WA_FINAL_A-RETURN_COST1 ).
WA_FINAL_A-NET_COST2 = ( WA_FINAL_A-ISSUE_COST2 - WA_FINAL_A-RETURN_COST2 ).
MODIFY IT_FINAL_A FROM WA_FINAL_A INDEX LV_TABIX TRANSPORTING MAKTX NET_QTY1 NET_QTY2 PER_COACH1 PER_COACH2 NET_COST1 NET_COST2 .
ENDLOOP .
CLEAR WA_FINAL_A.
ENDFORM. " FINAL_TABLE_DISPLAY
*&---------------------------------------------------------------------*
*& Form SLECT_DATA_LEAGCY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SLECT_DATA_LEAGCY .
SELECT KDAUF FROM ZRESB INTO TABLE IT_LEGACY WHERE KDAUF = P_VBELN .
*DELETE IT_LEGACY WHERE BWART NE '261' AND BWART NE '262' AND BWART NE '201' AND BWART NE'202'.
ENDFORM. " SLECT_DATA_LEAGCY
*&---------------------------------------------------------------------*
*& Form CALCULATE_REQ_LEGACY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALCULATE_REQ_LEGACY .
SORT IT_LEGACY BY KDAUF ASCENDING.
*LOOP AT IT_LEGACY INTO WA_LEGACY.
*AT END OF MATNR.
* SUM.
* WA_TEMP_LEGACY-REQ_QTY = WA_LEGACY-REQ_QTY.
* WA_TEMP_LEGACY-KDAUF = WA_LEGACY-KDAUF.
* WA_TEMP_LEGACY-MATNR = WA_LEGACY-MATNR.
* WA_TEMP_LEGACY-BWART = WA_LEGACY-BWART.
*
* APPEND WA_TEMP_LEGACY TO IT_TEMP_LEGACY.
* ENDAT.
*ENDLOOP.
*REFRESH IT_LEGACY.
*IT_LEGACY[] = IT_TEMP_LEGACY[].
READ TABLE IT_PREV_SAP INTO WA_TEMP_SAP1 INDEX SY-TABIX.
REFRESH IT_TEMP_SAP1.
ENDFORM. " CALCULATE_REQ_LEGACY
*&---------------------------------------------------------------------*
*& Form ISSUE_QTY_LEGACY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ISSUE_QTY_LEGACY .
SELECT MATNR
KDAUF
REQ_QTY
BWART
QTY
COST INTO TABLE IT_ISSUE_LEGACY FROM ZMSEG FOR ALL ENTRIES IN IT_LEGACY WHERE KDAUF = IT_LEGACY-KDAUF.
DELETE IT_ISSUE_LEGACY WHERE BWART NE '261' AND BWART NE '201'.
SORT IT_ISSUE_LEGACY BY MATNR ASCENDING.
LOOP AT IT_ISSUE_LEGACY INTO WA_ISSUE_LEGACY.
AT END OF MATNR.
SUM.
WA_TISSUE_LEGACY-MATNR = WA_ISSUE_LEGACY-MATNR.
WA_TISSUE_LEGACY-REQ_QTY = WA_ISSUE_LEGACY-REQ_QTY.
WA_TISSUE_LEGACY-BWART = WA_ISSUE_LEGACY-BWART.
WA_TISSUE_LEGACY-QTY = WA_ISSUE_LEGACY-QTY.
WA_TISSUE_LEGACY-COST = WA_ISSUE_LEGACY-COST.
APPEND WA_TISSUE_LEGACY TO IT_TISSUE_LEGACY.
ENDAT.
ENDLOOP.
REFRESH IT_ISSUE_LEGACY.
IT_ISSUE_LEGACY[] = IT_TISSUE_LEGACY[].
READ TABLE IT_ISSUE_SAP INTO WA_ISSUE_SAP INDEX 1.
REFRESH IT_TISSUE_LEGACY.
ENDFORM. " ISSUE_QTY_LEGACY
*&---------------------------------------------------------------------*
*& Form RETURN_QTY_LEGACY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM RETURN_QTY_LEGACY .
SELECT MATNR
KDAUF
REQ_QTY
BWART
QTY
COST INTO TABLE IT_RETURN_LEGACY FROM ZMSEG FOR ALL ENTRIES IN IT_LEGACY WHERE KDAUF = IT_LEGACY-KDAUF .
DELETE IT_RETURN_LEGACY WHERE BWART NE '262' AND BWART NE '202'.
SORT IT_RETURN_LEGACY BY MATNR ASCENDING.
LOOP AT IT_RETURN_LEGACY INTO WA_RETURN_LEGACY .
AT END OF MATNR.
SUM.
WA_TISSUE_LEGACY-REQ_QTY = WA_RETURN_LEGACY-REQ_QTY.
WA_TISSUE_LEGACY-MATNR = WA_RETURN_LEGACY-MATNR.
WA_TISSUE_LEGACY-BWART = WA_RETURN_LEGACY-BWART.
WA_TISSUE_LEGACY-QTY = WA_RETURN_LEGACY-QTY.
WA_TISSUE_LEGACY-COST = WA_RETURN_LEGACY-COST.
APPEND WA_TISSUE_LEGACY TO IT_TISSUE_LEGACY.
ENDAT.
ENDLOOP.
REFRESH IT_RETURN_LEGACY.
IT_RETURN_LEGACY[] = IT_TISSUE_LEGACY[].
READ TABLE IT_RETURN_LEGACY INTO WA_RETURN_LEGACY INDEX 1.
REFRESH IT_TISSUE_LEGACY.
ENDFORM. " RETURN_QTY_LEGACY
*&---------------------------------------------------------------------*
*& Form FINAL_LEGACY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FINAL_LEGACY .
LOOP AT IT_LEGACY INTO WA_LEGACY.
LV_TABIX = SY-TABIX.
WA_FINAL_BL-ORDER1 = WA_LEGACY-KDAUF.
*WA_FINAL_BL-REQ_QTY1 = WA_LEGACY-REQ_QTY.
READ TABLE IT_ISSUE_LEGACY INTO WA_ISSUE_LEGACY WITH KEY KDAUF = WA_LEGACY-KDAUF.
IF SY-SUBRC = 0.
WA_FINAL_BL-REQ_QTY1 = WA_ISSUE_LEGACY-REQ_QTY.
WA_FINAL_BL-ISSUE_QTY1 = WA_ISSUE_LEGACY-QTY.
WA_FINAL_BL-ISSUE_COST1 = WA_ISSUE_LEGACY-COST.
WA_FINAL_BL-MATNR = WA_ISSUE_LEGACY-MATNR.
ELSE .
WA_FINAL_BL-MATNR = WA_ISSUE_LEGACY-MATNR.
WA_FINAL_BL-REQ_QTY1 = WA_ISSUE_LEGACY-REQ_QTY.
WA_FINAL_BL-ISSUE_QTY1 = 0.
WA_FINAL_BL-ISSUE_COST1 = 0.
ENDIF .
READ TABLE IT_RETURN_LEGACY INTO WA_RETURN_LEGACY WITH KEY KDAUF = WA_LEGACY-KDAUF.
IF SY-SUBRC <> 0.
WA_FINAL_BL-MATNR = WA_RETURN_LEGACY-MATNR.
WA_FINAL_BL-REQ_QTY1 = WA_RETURN_LEGACY-REQ_QTY.
WA_FINAL_BL-RETURN_QTY1 = WA_RETURN_LEGACY-QTY.
WA_FINAL_BL-RETURN_COST1 = WA_RETURN_LEGACY-COST.
ELSE.
WA_FINAL_BL-MATNR = WA_RETURN_LEGACY-MATNR.
WA_FINAL_BL-RETURN_QTY1 = 0.
WA_FINAL_BL-RETURN_COST1 = 0.
WA_FINAL_BL-REQ_QTY1 = WA_RETURN_LEGACY-REQ_QTY.
ENDIF.
APPEND WA_FINAL_BL TO IT_FINAL_BL.
ENDLOOP.
READ TABLE IT_FINAL_BL INTO WA_FINAL_BL INDEX 1.
REFRESH : IT_ISSUE_SAP,IT_RETURN_SAP.
ENDFORM. " FINAL_LEGACY
*&---------------------------------------------------------------------*
*& Form LEGACY_SAP_COMBINE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM LEGACY_SAP_COMBINE .
DATA : IT_TEMP_FINAL LIKE IT_FINAL_B,
WA_TEMP_FINAL LIKE WA_FINAL_B.
IF IT_FINAL_BL IS NOT INITIAL AND IT_FINAL_B IS NOT INITIAL.
APPEND LINES OF IT_FINAL_BL TO IT_FINAL_B.
SORT IT_FINAL_B BY MATNR ASCENDING.
LOOP AT IT_FINAL_B INTO WA_FINAL_B.
AT END OF MATNR .
SUM.
WA_TEMP_FINAL-ORDER1 = WA_FINAL_B-ORDER1.
WA_TEMP_FINAL-MATNR = WA_FINAL_B-MATNR.
WA_TEMP_FINAL-REQ_QTY1 = WA_FINAL_B-REQ_QTY1.
WA_TEMP_FINAL-ISSUE_QTY1 = WA_FINAL_B-ISSUE_QTY1.
WA_TEMP_FINAL-ISSUE_COST1 = WA_FINAL_B-ISSUE_COST1.
WA_TEMP_FINAL-RETURN_QTY1 = WA_FINAL_B-RETURN_QTY1.
WA_TEMP_FINAL-RETURN_COST1 = WA_FINAL_B-RETURN_COST1.
APPEND WA_TEMP_FINAL TO IT_TEMP_FINAL.
ENDAT.
ENDLOOP.
REFRESH IT_FINAL_B.
IT_FINAL_B[] = IT_TEMP_FINAL[].
ELSEIF IT_FINAL_BL IS NOT INITIAL AND IT_FINAL_B IS INITIAL.
IT_FINAL_B[] = IT_FINAL_BL[].
ENDIF.
ENDFORM. " LEGACY_SAP_COMBINE
*&---------------------------------------------------------------------*
*& Form CONVERSION_SALES_NUMBER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CONVERSION_SALES_NUMBER .
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = P_VBELN
IMPORTING
OUTPUT = P_VBELN
.
ENDFORM. " CONVERSION_SALES_NUMBER
*&---------------------------------------------------------------------*
*& Form FILL_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
** Create a dynamic internal table with this structure.
*
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
I_STYLE_TABLE = 'X'
IT_FIELDCATALOG = IT_FIELDCAT
IMPORTING
EP_TABLE = GT_DYN_TABLE
EXCEPTIONS
GENERATE_SUBPOOL_DIR_FULL = 1
OTHERS = 2.
*
IF SY-SUBRC EQ 0.
* Assign the new table to field symbol
ASSIGN GT_DYN_TABLE->* TO <GFS_DYN_TABLE>.
* Create dynamic work area for the dynamic table
CREATE DATA GW_LINE LIKE LINE OF <GFS_DYN_TABLE>.
CREATE DATA GW_LINE1 LIKE LINE OF <GFS_DYN_TABLE>.
ASSIGN GW_LINE->* TO <GFS_LINE>.
ASSIGN GW_LINE1->* TO <GFS_LINE1>.
ENDIF.
*********************
SORT IT_FINAL_A ASCENDING BY ORDER2.
LOOP AT IT_FINAL_A INTO WA_FINAL_A.
IF <GFS_DYN_TABLE> IS NOT INITIAL .
READ TABLE <GFS_DYN_TABLE> ASSIGNING <GFS_LINE1> WITH KEY ('MATNR') = WA_FINAL_A-MATNR .
IF SY-SUBRC EQ 0 .
CONCATENATE WA_FINAL_A-ORDER2 'REQ_QTY2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE1> TO <FS1>.
<FS1> = WA_FINAL_A-REQ_QTY2.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'NET_QTY2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE1> TO <FS1>.
<FS1> = WA_FINAL_A-NET_QTY2.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'NET_COST2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE1> TO <FS1>.
<FS1> = WA_FINAL_A-NET_COST2.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'PER_COACH2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE1> TO <FS1>.
<FS1> = WA_FINAL_A-PER_COACH2.
UNASSIGN <FS1>.
*APPEND <gfs_line> TO <gfs_dyn_table>.
MODIFY TABLE <GFS_DYN_TABLE> FROM <GFS_LINE1>.
CLEAR : <GFS_LINE1>.
ELSE.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-MATNR .
UNASSIGN <FS1>.
ASSIGN COMPONENT 'MAKTX' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-MAKTX.
UNASSIGN <FS1>.
ASSIGN COMPONENT 'REQ_QTY1' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-REQ_QTY1.
UNASSIGN <FS1>.
ASSIGN COMPONENT 'NET_QTY1' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-NET_QTY1.
UNASSIGN <FS1>.
ASSIGN COMPONENT 'NET_COST1' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-NET_COST1.
UNASSIGN <FS1>.
ASSIGN COMPONENT 'PER_COACH1' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-PER_COACH1.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'REQ_QTY2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-REQ_QTY2.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'NET_QTY2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-NET_QTY2.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'NET_COST2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-NET_COST2.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'PER_COACH2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-PER_COACH2.
UNASSIGN <FS1>.
APPEND <GFS_LINE> TO <GFS_DYN_TABLE>.
ENDIF.
ELSE.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-MATNR .
UNASSIGN <FS1>.
ASSIGN COMPONENT 'MAKTX' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-MAKTX.
UNASSIGN <FS1>.
ASSIGN COMPONENT 'REQ_QTY1' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-REQ_QTY1.
UNASSIGN <FS1>.
ASSIGN COMPONENT 'NET_QTY1' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-NET_QTY1.
UNASSIGN <FS1>.
ASSIGN COMPONENT 'NET_COST1' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-NET_COST1.
UNASSIGN <FS1>.
ASSIGN COMPONENT 'PER_COACH1' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-PER_COACH1.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'REQ_QTY2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-REQ_QTY2.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'NET_QTY2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-NET_QTY2.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'NET_COST2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-NET_COST2.
UNASSIGN <FS1>.
CONCATENATE WA_FINAL_A-ORDER2 'PER_COACH2' INTO FNAME .
ASSIGN COMPONENT FNAME OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = WA_FINAL_A-PER_COACH2.
UNASSIGN <FS1>.
APPEND <GFS_LINE> TO <GFS_DYN_TABLE>.
ENDIF.
*APPEND <gfs_line> TO <gfs_dyn_table>.
UNASSIGN <FS1>.
CLEAR WA_FINAL_A.
ENDLOOP.
*CLEAR: <gfs_line>.
ENDFORM. " FILL_FIELDCAT
*&---------------------------------------------------------------------*
*& Form GRID_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GRID_DISPLAY .
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 = '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 = <GFS_DYN_TABLE>
* 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. " GRID_DISPLAY
*&---------------------------------------------------------------------*
*& Form LIST_HEADER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM LIST_HEADER .
*Type H is used to display headers i.e. big font
WA_LISTHEADER-TYP = 'H'.
WA_LISTHEADER-INFO ='BATCH ORDER COMPARISION '.
APPEND WA_LISTHEADER TO IT_LISTHEADER.
CLEAR WA_LISTHEADER.
* Type S is used to display key and value pairs
WA_LISTHEADER-TYP = 'S'.
WA_LISTHEADER-KEY = 'Date :' .
CONCATENATE SY-DATUM+6(2)
SY-DATUM+4(2)
SY-DATUM(4)
INTO WA_LISTHEADER-INFO
SEPARATED BY '/'.
APPEND WA_LISTHEADER TO IT_LISTHEADER.
CLEAR WA_LISTHEADER.
* Type A is used to display italic font
WA_LISTHEADER-TYP = 'A'.
WA_LISTHEADER-INFO ='SAP ALV Report'.
APPEND WA_LISTHEADER TO IT_LISTHEADER.
CLEAR WA_LISTHEADER.
ENDFORM. " LIST_HEADER
*&---------------------------------------------------------------------*
*& Form TOP_OF_PAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM TOP_OF_PAGE .
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = IT_LISTHEADER
I_LOGO = 'ICF_LOGO'.
ENDFORM. " TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form FILL_FIELDCAT_1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILL_FIELDCAT_1 .
WA_FIELDCAT1-FIELDNAME = 'MATNR'.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 20.
WA_FIELDCAT1-SELTEXT_L = 'MATERIAL'.
WA_FIELDCAT1-COL_POS = 1.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR WA_FIELDCAT1.
WA_FIELDCAT1-FIELDNAME = 'MAKTX'.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 20.
WA_FIELDCAT1-SELTEXT_L = 'MATL_DESC.'.
WA_FIELDCAT1-COL_POS = 2.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR WA_FIELDCAT1.
WA_FIELDCAT1-FIELDNAME = 'REQ_QTY1'.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 12.
WA_FIELDCAT1-SELTEXT_L = 'PREV. REQ QTY'.
WA_FIELDCAT1-COL_POS = 3.
WA_FIELDCAT1-DO_SUM = 'X'.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR WA_FIELDCAT1.
WA_FIELDCAT1-FIELDNAME = 'NET_QTY1'.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 12.
WA_FIELDCAT1-SELTEXT_L = 'PREV. NET QTY'.
WA_FIELDCAT1-COL_POS = 4.
WA_FIELDCAT1-DO_SUM = 'X'.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR WA_FIELDCAT1.
WA_FIELDCAT1-FIELDNAME = 'NET_COST1'.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 12.
WA_FIELDCAT1-SELTEXT_L = 'PREV. NET COST'.
WA_FIELDCAT1-COL_POS = 5.
WA_FIELDCAT1-DO_SUM = 'X'.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR WA_FIELDCAT1.
WA_FIELDCAT1-FIELDNAME = 'PER_COACH1'.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 12.
WA_FIELDCAT1-SELTEXT_L = 'PREV. PER COACH '.
WA_FIELDCAT1-COL_POS = 6.
WA_FIELDCAT1-DO_SUM = 'X'.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR WA_FIELDCAT1.
GV_POS = 6.
LOOP AT IT_FINAL_A INTO WA_FINAL_A.
AT NEW ORDER2.
CONCATENATE WA_FINAL_A-ORDER2 'REQ_QTY2' INTO FNAME .
* read table IT_FIELDCAT1 into WA_FIELDCAT1 with key fieldname = WA_FINAL_A-ORDER2.
* IF SY-SUBRC NE 0.
GV_POS = GV_POS + 1.
WA_FIELDCAT1-FIELDNAME = FNAME.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 12.
WA_FIELDCAT1-SELTEXT_L = FNAME.
WA_FIELDCAT1-DO_SUM = 'X'.
WA_FIELDCAT1-COL_POS = GV_POS.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR : WA_FIELDCAT1, FNAME .
CONCATENATE WA_FINAL_A-ORDER2 'NET_QTY2' INTO FNAME .
GV_POS = GV_POS + 1.
WA_FIELDCAT1-FIELDNAME = FNAME.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 12.
WA_FIELDCAT1-SELTEXT_L = FNAME.
WA_FIELDCAT1-COL_POS = GV_POS.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR :WA_FIELDCAT1,FNAME.
CONCATENATE WA_FINAL_A-ORDER2 'NET_COST2' INTO FNAME .
GV_POS = GV_POS + 1.
WA_FIELDCAT1-FIELDNAME = FNAME.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 12.
WA_FIELDCAT1-SELTEXT_L = FNAME.
WA_FIELDCAT1-COL_POS = GV_POS.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR : WA_FIELDCAT1, FNAME.
CONCATENATE WA_FINAL_A-ORDER2 'PER_COACH2' INTO FNAME .
GV_POS = GV_POS + 1.
WA_FIELDCAT1-FIELDNAME = FNAME.
WA_FIELDCAT1-TABNAME = 'IT_FINAL_A'.
WA_FIELDCAT1-OUTPUTLEN = 12.
WA_FIELDCAT1-SELTEXT_L = FNAME.
WA_FIELDCAT1-COL_POS = GV_POS.
APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.
CLEAR :WA_FIELDCAT1 ,FNAME.
* ENDIF.
ENDAT.
ENDLOOP.
* LT_LAYOUT-ZEBRA = 'X'.
LT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
*
ENDFORM. " FILL_FIELDCAT_1