Anda di halaman 1dari 7

*&---------------------------------------------------------------------*

*& Report ZNM_SM_R_EXPSHORTDATE *


*& *
*&---------------------------------------------------------------------*
*& Design: *
*& Author: *
*& Date:31-08-2009 *
*& DevID:
*& TRANSPORT REQUEST NO:D47K9A03LS *
*&---------------------------------------------------------------------*

REPORT ZNM_SM_R_EXPSHORTDATE .

TYPE-POOLS:SLIS.

TABLES:ZCONSIGN, ZSREP, VBAK, VBAP, MCH1.

*&---------------------------------------------------------------------*
*& FOR FIELDCATELOG, LAYOUT*
*&---------------------------------------------------------------------*

DATA:GT_FCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,


GW_FCAT TYPE SLIS_FIELDCAT_ALV,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
GD_REPID LIKE SY-REPID.

GD_REPID = SY-REPID.

*DEFINING GT_ZSREP

TYPES:BEGIN OF LT_ZSREP,
ZAREA TYPE ZSREP-ZZIDAREA,
ZREGION TYPE ZSREP-ZZIDREGION,
KUNNR type ZSREP-KUNNR,
PRCTR TYPE ZSREP-PRCTR,
END OF LT_ZSREP,

*DEFINING GT_ZCONSIGN

BEGIN OF LT_ZCONSIGN ,
KUNNR TYPE ZCONSIGN-KUNNR,
NAME1 TYPE ZCONSIGN-NAME1,

PARVW TYPE ZCONSIGN-PARVW,


MATNR TYPE ZCONSIGN-MATNR,
CHARG TYPE ZCONSIGN-CHARG,
KULAB TYPE ZCONSIGN-KULAB,
WERKS TYPE ZCONSIGN-WERKS,
KUKLA TYPE ZCONSIGN-KUKLA,
END OF LT_ZCONSIGN,

*DEFINING GT_MATKX

BEGIN OF LT_MATKX ,
MAKTX TYPE MAKT-MAKTX,
MATNR TYPE MAKT-MAKTX,
END OF LT_MATKX,
*DEFINING GT_MCH1

BEGIN OF LT_MCH1 ,
VFDAT TYPE MCH1-VFDAT,
END OF LT_MCH1,

*DEFINING GT_VBAP

BEGIN OF LT_VBAP,
VBELN TYPE VBAP-VBELN,
END OF LT_VBAP,

*DEFINING GT_VBAK

BEGIN OF LT_VBAK,
AUGRU TYPE VBAK-AUGRU,
END OF LT_VBAK,

*DEFINING GT_MBEW

BEGIN OF LT_MBEW,
MATNR TYPE MBEW-MATNR,
STPRS TYPE MBEW-STPRS,
END OF LT_MBEW,

*DEFINING LT_KNA1
BEGIN OF LT_KNA1,
KUNNR TYPE KNA1-KUNNR,
NAME3 TYPE KNA1-NAME3,
END OF LT_KNA1,

*DEFINING LT_DISP

BEGIN OF LT_DISP,
NAME1 TYPE ZCONSIGN-NAME1,
KUNNR TYPE ZCONSIGN-KUNNR,
ZAREA TYPE ZSREP-ZZIDAREA,
ZREGION TYPE ZSREP-ZZIDREGION,
NAME3 TYPE KNA1-NAME3,
MATNR TYPE ZCONSIGN-MATNR,
MAKTX TYPE MAKT-MAKTX,
CHARG TYPE ZCONSIGN-CHARG,
KULAB TYPE ZCONSIGN-KULAB,
STPRS TYPE MBEW-STPRS,
END OF LT_DISP.

*INTERNAL TABLE DECLARATION

DATA:GT_DISP TYPE STANDARD TABLE OF LT_DISP INITIAL SIZE 0,


GT_ZSERP TYPE STANDARD TABLE OF LT_ZSREP INITIAL SIZE 0,
GT_ZCONSIGN TYPE STANDARD TABLE OF LT_ZCONSIGN INITIAL SIZE 0,
GT_MATKX TYPE STANDARD TABLE OF LT_MATKX INITIAL SIZE 0,
GT_MCH1 TYPE STANDARD TABLE OF LT_MCH1 INITIAL SIZE 0,
GT_VBAP TYPE STANDARD TABLE OF LT_VBAP INITIAL SIZE 0,
GT_VBAK TYPE STANDARD TABLE OF LT_VBAK INITIAL SIZE 0,
GT_MBEW TYPE STANDARD TABLE OF LT_MBEW INITIAL SIZE 0,
GT_KNA1 TYPE STANDARD TABLE OF LT_KNA1 INITIAL SIZE 0,
*WORKAREA DECLARATION

LW_DISP TYPE LT_DISP,


LW_ZSREP TYPE LT_ZSREP,
LW_ZCONSIGN TYPE LT_ZCONSIGN,
LW_MATKX TYPE LT_MATKX,
LW_VBAP TYPE LT_VBAP,
LW_VBAK TYPE LT_VBAK,
LW_KNA1 TYPE LT_KNA1,
LW_MBEW TYPE LT_MBEW.

*&---------------------------------------------------------------------*
*& SELECT-OPTION
*&---------------------------------------------------------------------*

SELECT-OPTIONS:S_NAME1 FOR ZCONSIGN-NAME1,


S_KUNNR FOR ZCONSIGN-KUNNR,
S_AREA FOR ZSREP-ZZIDAREA,
S_REGION FOR ZSREP-ZZIDREGION,
S_VFDAT FOR MCH1-VFDAT,
S_MATNR FOR ZCONSIGN-MATNR,
S_CHARG FOR ZCONSIGN-CHARG,
S_VBELN FOR VBAK-VBELN,
S_WERKS FOR ZCONSIGN-WERKS,
"S_KUKLA FOR KNA1-KUKLA,
S_AUGRU FOR VBAK-AUGRU,
S_BSARK FOR VBAK-BSARK.

*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*

START-OF-SELECTION.

PERFORM DATA.

END-OF-SELECTION.

PERFORM CREATE_FCAT.
PERFORM DISP_ALV.

*&---------------------------------------------------------------------*
*& Form DATA
*&---------------------------------------------------------------------*
* Fetching all the data required from the database tables

form DATA .

SELECT ZZIDAREA
ZZIDREGION
KUNNR
PRCTR
FROM ZSREP INTO TABLE GT_ZSERP WHERE ZZIDAREA IN S_AREA AND ZZIDREGION IN
S_REGION.
SELECT KUNNR
NAME1
PARVW
MATNR
CHARG
KULAB
WERKS
KUKLA
FROM ZCONSIGN INTO TABLE GT_ZCONSIGN WHERE MATNR = S_MATNR AND WERKS =
S_WERKS AND KUNNR = S_KUNNR .

SELECT MATNR
MAKTX
FROM MAKT INTO TABLE GT_MATKX WHERE MATNR = S_MATNR.

SELECT MATNR
CHARG
VFDAT FROM MCH1 INTO TABLE GT_MCH1 WHERE MATNR = S_MATNR AND CHARG =
S_CHARG.

IF NOT GT_ZCONSIGN[] IS INITIAL.

SELECT VBELN
MATNR
CHARG
FROM
VBAP INTO TABLE GT_VBAP FOR ALL ENTRIES IN GT_ZCONSIGN WHERE MATNR =
GT_ZCONSIGN-MATNR AND CHARG = GT_ZCONSIGN-CHARG.

SORT GT_VBAP BY VBELN.


DELETE ADJACENT DUPLICATES FROM GT_VBAP COMPARING VBELN.

ENDIF.

IF NOT GT_ZCONSIGN[] IS INITIAL.

SELECT VBELN
AUGRU
FROM VBAK INTO TABLE GT_VBAK FOR ALL ENTRIES IN GT_VBAP WHERE VBELN =
GT_VBAP-VBELN.

ENDIF.

SELECT MATNR
STPRS
FROM MBEW INTO TABLE GT_MBEW WHERE MATNR = S_MATNR.

SELECT KUNNR NAME3 FROM KNA1 INTO TABLE GT_KNA1 WHERE KUNNR = S_KUNNR.
LOOP AT GT_ZSERP INTO LW_ZSREP.
CLEAR LW_DISP.
LW_DISP-ZAREA = LW_ZSREP-ZAREA.
LW_DISP-ZREGION = LW_ZSREP-ZREGION.

READ TABLE GT_ZCONSIGN INTO LW_ZCONSIGN WITH KEY KUNNR = LW_ZSREP-KUNNR.


IF SY-SUBRC = 0.
LW_DISP-NAME1 = LW_ZCONSIGN-NAME1.
LW_DISP-KUNNR = LW_ZCONSIGN-KUNNR.
LW_DISP-MATNR = LW_ZCONSIGN-MATNR.
LW_DISP-CHARG = LW_ZCONSIGN-CHARG.
LW_DISP-KULAB = LW_ZCONSIGN-KULAB.

READ TABLE GT_MATKX INTO LW_MATKX WITH KEY MATNR = LW_ZCONSIGN-MATNR.


IF SY-SUBRC = 0.
LW_DISP-MAKTX = LW_MATKX-MAKTX.
ENDIF.

READ TABLE GT_MBEW INTO LW_MBEW WITH KEY MATNR = LW_ZCONSIGN-MATNR.


IF SY-SUBRC = 0.
LW_DISP-STPRS = LW_MBEW-STPRS.
ENDIF.
ENDIF.

READ TABLE GT_KNA1 INTO LW_KNA1 WITH KEY KUNNR = LW_ZSREP-KUNNR.


IF SY-SUBRC = 0.
LW_DISP-NAME3 = LW_KNA1-NAME3.
ENDIF.

APPEND LW_DISP TO GT_DISP.


CLEAR: LW_ZCONSIGN, LW_MATKX, LW_MBEW, LW_KNA1.
ENDLOOP.
endform. " DATA

*&---------------------------------------------------------------------*
*& Form CREATE_FCAT
*&---------------------------------------------------------------------*
* CREATING FIELD CATELOG

form CREATE_FCAT .

GT_FCAT-FIELDNAME = 'NAME1'.
GT_FCAT-SELTEXT_M = 'Rep Names'.
GT_FCAT-COL_POS = 1.
GT_FCAT-OUTPUTLEN = 35.
GT_FCAT-EMPHASIZE = 'X'.
GT_FCAT-KEY = 'X'.
APPEND GT_FCAT TO GT_FCAT.
CLEAR GT_FCAT.

GT_FCAT-FIELDNAME = 'KUNNR'.
GT_FCAT-SELTEXT_M = 'Rep Bins'.
GT_FCAT-COL_POS = 2.
GT_FCAT-OUTPUTLEN = 10.
GT_FCAT-EMPHASIZE = 'X'.
GT_FCAT-KEY = 'X'.
APPEND GT_FCAT TO GT_FCAT.
CLEAR GT_FCAT.

GT_FCAT-FIELDNAME = 'ZZIDAREA'.
GT_FCAT-SELTEXT_M = 'Areas'.
GT_FCAT-COL_POS = 3.
GT_FCAT-OUTPUTLEN = 4.
GT_FCAT-EMPHASIZE = 'X'.
GT_FCAT-KEY = 'X'.
APPEND GT_FCAT TO GT_FCAT.
CLEAR GT_FCAT.

GT_FCAT-FIELDNAME = 'ZZIDREGION'.
GT_FCAT-SELTEXT_M = 'Regions'.
GT_FCAT-COL_POS = 4.
GT_FCAT-OUTPUTLEN = 3.
GT_FCAT-EMPHASIZE = 'X'.
GT_FCAT-KEY = 'X'.
APPEND GT_FCAT TO GT_FCAT.
CLEAR GT_FCAT.

GT_FCAT-FIELDNAME = 'NAME3'.
GT_FCAT-SELTEXT_M = 'Inventory Type'.
GT_FCAT-COL_POS = 5.
GT_FCAT-OUTPUTLEN = 35.
GT_FCAT-EMPHASIZE = 'X'.
GT_FCAT-KEY = 'X'.
APPEND GT_FCAT TO GT_FCAT.
CLEAR GT_FCAT.

GT_FCAT-FIELDNAME = 'MATNR'.
GT_FCAT-SELTEXT_M = 'Part Nos'.
GT_FCAT-COL_POS = 6.
GT_FCAT-OUTPUTLEN = 18.
GT_FCAT-EMPHASIZE = 'X'.
GT_FCAT-KEY = 'X'.
APPEND GT_FCAT TO GT_FCAT.
CLEAR GT_FCAT.

GT_FCAT-FIELDNAME = 'MAKTX'.
GT_FCAT-SELTEXT_M = 'Part Desc'.
GT_FCAT-COL_POS = 7.
GT_FCAT-OUTPUTLEN = 40.
GT_FCAT-EMPHASIZE = 'X'.
GT_FCAT-KEY = 'X'.
APPEND GT_FCAT TO GT_FCAT.
CLEAR GT_FCAT.

GT_FCAT-FIELDNAME = 'CHARG'.
GT_FCAT-SELTEXT_M = 'Serial/Lots Exp date'.
GT_FCAT-COL_POS = 8.
GT_FCAT-OUTPUTLEN = 10.
GT_FCAT-EMPHASIZE = 'X'.
GT_FCAT-KEY = 'X'.
APPEND GT_FCAT TO GT_FCAT.
CLEAR GT_FCAT.

GT_FCAT-FIELDNAME = 'KULAB'.
GT_FCAT-SELTEXT_M = 'Qty'.
GT_FCAT-COL_POS = 9.
GT_FCAT-OUTPUTLEN = 13.
GT_FCAT-EMPHASIZE = 'X'.
GT_FCAT-KEY = 'X'.
APPEND GT_FCAT TO GT_FCAT.
CLEAR GT_FCAT.

GT_FCAT-FIELDNAME = 'STPRS'.
GT_FCAT-SELTEXT_M = 'Std Cost'.
GT_FCAT-COL_POS = 10.
GT_FCAT-OUTPUTLEN = 11.
GT_FCAT-EMPHASIZE = 'X'.
GT_FCAT-KEY = 'X'.
APPEND GT_FCAT TO GT_FCAT.
CLEAR GT_FCAT.
endform. " CREATE_FCAT

*&---------------------------------------------------------------------*
*& Form DISP_ALV
*&---------------------------------------------------------------------*
* DISPLAY ALV

Form DISP_ALV .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
IT_FIELDCAT = GT_FCAT
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = GT_DISP
* 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. " DISP_ALV