You are on page 1of 10

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

*& AUTHOR: KANNE SRINIVASA RAO


*& TITLE: DELIVERY WISE DELIVERY REPORT
*&DESCRIPTION: DISPLAY A DELIVERY REPORT BASED ON DELIVERY NO
*&TRANSPORT REQUEST NO: QASK900149
*&VERSION:V1
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
REPORT ZALV_DELIVERYWISE_REPORT NO STANDARD PAGE HEADING LINE-SIZE 300.
*&---------------------------------------------------------------------*
*& STRUCTURE DECLARATIONS
*&---------------------------------------------------------------------*
TYPE-POOLS SLIS.
DATA: W_FCAT TYPE slis_fieldcat_alv,
T_FCAT TYPE SLIS_T_FIELDCAT_ALV,
W_KEYINFO TYPE SLIS_KEYINFO_ALV,
W_SORT TYPE slis_sortinfo_alv,
T_SORT TYPE SLIS_T_SORTINFO_ALV.
*STRUCTURE DECLARATION FOR DELIVERY HEADER DATA
TYPES: BEGIN OF TY_LIKP,
VBELN TYPE VBELN_VL,"Delivery No
ERDAT TYPE ERDAT,"Date on Which Record Was Created
BZIRK TYPE BZIRK,"Sales district
ROUTE TYPE ROUTE,"Route
KUNNR TYPE KUNWE,"Ship-to party
XABLN TYPE XABLN,"Goods Receipt/Issue Slip Number
END OF TY_LIKP,
*STRUCTURE DECLARATION FOR ROUTES: TEXTS
BEGIN OF TY_TVROT,
ROUTE TYPE ROUTE,"Route
BEZEI TYPE ROUTBEZ,"Description of Route
END OF TY_TVROT,
*STRUCTURE DECLARATION FOR GENERAL DATA IN CUSTOMER MASTER
BEGIN OF TY_KNA1,
KUNNR TYPE KUNNR,"Cust No
NAME1_C TYPE NAME1_GP,"Cust Name
ORT01_C TYPE ORT01_GP,"To City
PZTLZ TYPE PSTLZ,"Postal Code
REGIO TYPE REGIO,"Region (State, Province, County)
TELF2 TYPE TELF2,"Second telephone number
END OF TY_KNA1,
*STRUCTURE DECLARATION FOR DELIVERY: ITEM DATA
BEGIN OF TY_LIPS,
VBELN TYPE VBELN_VL,"Delivery
POSNR TYPE POSNR_VL,"Delivery Item
MATNR TYPE MATNR,"Material Number
WERKS TYPE WERKS_D,"Plant
LFIMG TYPE LFIMG,"Actual quantity delivered (in sales units)
ARKTX TYPE ARKTX,"Short text for sales order item
END OF TY_LIPS,
*STRUCTURE DCLARATION FOR MATERIAL DESCRIPTIONS
BEGIN OF TY_MAKT,

MATNR TYPE MATNR,"Material Number


MAKTX TYPE MAKTX,"Material Description (Short Text)
END OF TY_MAKT,
*STRUCTURE DECLARATION FOR PLANTS/BRANCHES
BEGIN OF TY_T001W,
WERKS TYPE WERKS_D,"Plant
NAME1_P TYPE NAME1,"Plant Name
ORT01_P TYPE ORT01,"From City
END OF TY_T001W,
*STRUCTURE DECLARATION FOR FINAL HEADER DATA
BEGIN OF TY_FINAL_HEADER,
VBELN TYPE VBELN_VL,"Delivery No
ERDAT TYPE ERDAT,"Date on Which Record Was Created
ROUTE TYPE ROUTE,"Route
BEZEI TYPE ROUTBEZ,"Description of Route
NAME1_C TYPE NAME1_GP,"Cust Name
ORT01_C TYPE ORT01_GP,"To City
PZTLZ TYPE PSTLZ,"Postal Code
BZIRK TYPE BZIRK,"Sales district
XABLN TYPE XABLN,"Goods Receipt/Issue Slip Number
REGIO TYPE REGIO,"Region (State, Province, County)
TELF2 TYPE TELF2,"Second telephone number
END OF TY_FINAL_HEADER,
*STRUCTURE DECLARATION FOR FINAL ITEM DATA
BEGIN OF TY_FINAL_ITEM,
VBELN TYPE VBELN_VL,"Delivery No
POSNR TYPE POSNR_VL,"Delivery Item
MATNR TYPE MATNR,"Material Number
MAKTX TYPE MAKTX,"Material Description (Short Text)
WERKS TYPE WERKS_D,"Plant
NAME1_P TYPE NAME1,"Plant Name
ARKTX TYPE ARKTX,"Short text for sales order item
ORT01_P TYPE ORT01,"From City
LFIMG TYPE LFIMG,"Actual quantity delivered (in sales units)
END OF TY_FINAL_ITEM.
*&---------------------------------------------------------------------*
*& INTERNAL TABLE(S) DECLARATIONS
*&---------------------------------------------------------------------*
DATA: T_LIKP TYPE TABLE OF TY_LIKP,
T_TVROT TYPE TABLE OF TY_TVROT,
T_KNA1 TYPE TABLE OF TY_KNA1,
T_LIPS TYPE TABLE OF TY_LIPS,
T_MAKT TYPE TABLE OF TY_MAKT,
T_T001W TYPE TABLE OF TY_T001W,
T_FINAL_HEADER TYPE TABLE OF TY_FINAL_HEADER,
T_FINAL_ITEM TYPE TABLE OF TY_FINAL_ITEM.
*&---------------------------------------------------------------------*
*& WORK AREA(S) DECLARATIONS
*&---------------------------------------------------------------------*
DATA: W_LIKP TYPE TY_LIKP,
W_TVROT TYPE TY_TVROT,
W_KNA1 TYPE TY_KNA1,
W_LIPS TYPE TY_LIPS,
W_MAKT TYPE TY_MAKT,
W_T001W TYPE TY_T001W,

W_FINAL_HEADER TYPE TY_FINAL_HEADER,


W_FINAL_ITEM TYPE TY_FINAL_ITEM.
*&---------------------------------------------------------------------*
*& GLOBAL DECLARATIONS
*&---------------------------------------------------------------------*
DATA: G_VBELN TYPE VBELN_VL."Delivery No
*&---------------------------------------------------------------------*
*& SELECTION SCREEN DECLARATIONS
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_VBELN FOR G_VBELN OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B1.
*&---------------------------------------------------------------------*
*& INITIALIZATION
*&---------------------------------------------------------------------*
INITIALIZATION.
CLEAR: W_LIKP,
W_TVROT,
W_KNA1,
W_LIPS,
W_MAKT,
W_T001W,
W_FINAL_HEADER,
W_FINAL_ITEM.
REFRESH: T_LIKP,
T_TVROT,
T_KNA1,
T_LIPS,
T_MAKT,
T_T001W,
T_FINAL_HEADER,
T_FINAL_ITEM.
*&---------------------------------------------------------------------*
*& SELECTION SCREEN VALIDATIONS
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN.
*VALIDATION FOR DELIVERY NUMBER
PERFORM VALIDATE_VBELN.

*&---------------------------------------------------------------------*
*& START-OF-SELECTION EVENT
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*FETCH DELIVERY HEADER DATA
PERFORM GET_LIKP_DATA.
*FETCH ROUTES: TEXTS
PERFORM GET_TVROT_DATA.
*FETCH CUSTOMER MASTER DATA
PERFORM GET_KNA1_DATA.

*POPULATE INTO FINAL HEADER TABLE


PERFORM POPULATE_FINAL_HEADER_DATA.
*FETCH DELIVERY ITEM DATA
PERFORM GET_LIPS_DATA.
*FETCH MATERIAL DESCRIPTION
PERFORM GET_MAKT_DATA.
*FETCH PLANT DETAILS
PERFORM GET_T001W_DATA.
*POPULATE INTO FINAL ITEM TABLE
PERFORM POPULATE_FINAL_ITEM_DATA.
*PROVIDE FIELD CATALOG
PERFORM FIELD_CATALOG USING : '1' 'VBELN' 'Delivery Number' 'T_FINAL_HEADER' '
',
'2' 'ERDAT' 'Doc Date' 'T_FINAL_HEADER' ' ',
'3' 'ROUTE' 'Route' 'T_FINAL_HEADER' ' ',
'4' 'BEZEI' 'Route Text' 'T_FINAL_HEADER' ' ',
'5' 'NAME1_C' 'Cust Name' 'T_FINAL_HEADER' ' ',
'6' 'ORT01_C' 'To City' 'T_FINAL_HEADER' ' ',
'7' 'PZTLZ' 'Postal' 'T_FINAL_HEADER' ' ',
'8' 'BZIRK' 'Sales Dist' 'T_FINAL_HEADER' ' ',
'9' 'XABLN' 'G.R Num' 'T_FINAL_HEADER' ' ',
'10' 'TELF2' 'Mob Num' 'T_FINAL_HEADER' ' ',
'11' 'POSNR' 'Del Item' 'T_FINAL_ITEM' ' ',
'12' 'MATNR' 'Material' 'T_FINAL_ITEM' ' ',
'13' 'MAKTX' 'Material Des' 'T_FINAL_ITEM' ' ',
'14' 'WERKS' 'Plant' 'T_FINAL_ITEM' ' ',
'15' 'NAME1_P' 'Plant Name' 'T_FINAL_ITEM' ' ',
'16' 'ARKTX' 'Short Text' 'T_FINAL_ITEM' ' ',
'17' 'ORT01_P' 'From City' 'T_FINAL_ITEM' ' ',
'18' 'LFIMG' 'Del Qty' 'T_FINAL_ITEM' 'X'.

*PROVIDE KEYINFO
PERFORM KEY_INFO.
*PROVIDE SORT
PERFORM SORT.
*DISPLAY REPORT
PERFORM DISPLAY_REPORT.

*&---------------------------------------------------------------------*
*&
Form VALIDATE_VBELN
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM VALIDATE_VBELN .
DATA L_VBELN TYPE VBELN_VL."Delivery No

SELECT SINGLE VBELN FROM LIKP INTO L_VBELN WHERE VBELN IN S_VBELN.
IF SY-SUBRC <> 0.
MESSAGE E010(ZMSGCLS).
ENDIF.
ENDFORM.
" VALIDATE_VBELN
*&---------------------------------------------------------------------*
*&
Form GET_LIKP_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM GET_LIKP_DATA .
SELECT VBELN
ERDAT
ROUTE
KUNNR
BZIRK
XABLN
FROM LIKP INTO CORRESPONDING FIELDS OF TABLE T_LIKP
WHERE VBELN IN S_VBELN.
ENDFORM.
" GET_LIKP_DATA
*&---------------------------------------------------------------------*
*&
Form GET_TVROT_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM GET_TVROT_DATA .
DATA:LT_LIKP TYPE TABLE OF TY_LIKP.
LT_LIKP = T_LIKP.
SORT LT_LIKP BY ROUTE.
DELETE ADJACENT DUPLICATES FROM LT_LIKP COMPARING ROUTE.
SELECT ROUTE
BEZEI
FROM TVROT INTO TABLE T_TVROT
FOR ALL ENTRIES IN LT_LIKP
WHERE ROUTE = LT_LIKP-ROUTE AND SPRAS = 'EN'.
ENDFORM.
" GET_TVROT_DATA
*&---------------------------------------------------------------------*
*&
Form GET_KNA1_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM GET_KNA1_DATA .
DATA:LT_LIKP TYPE TABLE OF TY_LIKP.
LT_LIKP = T_LIKP.
SORT LT_LIKP BY KUNNR.

DELETE ADJACENT DUPLICATES FROM LT_LIKP COMPARING KUNNR.


SELECT KUNNR
NAME1
ORT01
PSTLZ
REGIO
TELF2
FROM KNA1 INTO TABLE T_KNA1
FOR ALL ENTRIES IN LT_LIKP
WHERE KUNNR = LT_LIKP-KUNNR.

ENDFORM.
" GET_KNA1_DATA
*&---------------------------------------------------------------------*
*&
Form POPULATE_FINAL_HEADER_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM POPULATE_FINAL_HEADER_DATA .
LOOP AT T_LIKP INTO W_LIKP.
W_FINAL_HEADER-VBELN = W_LIKP-VBELN.
W_FINAL_HEADER-ERDAT = W_LIKP-ERDAT.
W_FINAL_HEADER-ROUTE = W_LIKP-ROUTE.
W_FINAL_HEADER-BZIRK = W_LIKP-BZIRK.
W_FINAL_HEADER-XABLN = W_LIKP-XABLN.
READ TABLE T_TVROT INTO W_TVROT WITH KEY ROUTE = W_LIKP-ROUTE.
W_FINAL_HEADER-BEZEI = W_TVROT-BEZEI.
READ TABLE T_KNA1 INTO
W_FINAL_HEADER-NAME1_C
W_FINAL_HEADER-ORT01_C
W_FINAL_HEADER-PZTLZ =
W_FINAL_HEADER-TELF2 =

W_KNA1 WITH KEY KUNNR = W_LIKP-KUNNR.


= W_KNA1-NAME1_C.
= W_KNA1-ORT01_C.
W_KNA1-PZTLZ.
W_KNA1-TELF2.

APPEND W_FINAL_HEADER TO T_FINAL_HEADER.


ENDLOOP.
ENDFORM.
" POPULATE_FINAL_HEADER_DATA
*&---------------------------------------------------------------------*
*&
Form GET_LIPS_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*]
FORM GET_LIPS_DATA .
SELECT VBELN
POSNR
MATNR
WERKS
LFIMG

ARKTX
FROM LIPS INTO TABLE T_LIPS
FOR ALL ENTRIES IN T_LIKP
WHERE VBELN = T_LIKP-VBELN.
ENDFORM.
" GET_LIPS_DATA
*&---------------------------------------------------------------------*
*&
Form GET_MAKT_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM GET_MAKT_DATA .
DATA LT_LIPS TYPE TABLE OF TY_LIPS.
LT_LIPS = T_LIPS.
SORT LT_LIPS BY MATNR.
DELETE ADJACENT DUPLICATES FROM LT_LIPS COMPARING MATNR.
SELECT MATNR
MAKTX FROM MAKT
INTO TABLE T_MAKT
FOR ALL ENTRIES IN T_LIPS
WHERE MATNR = T_LIPS-MATNR AND SPRAS = 'EN'.
ENDFORM.
" GET_MAKT_DATA
*&---------------------------------------------------------------------*
*&
Form GET_T001W_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM GET_T001W_DATA .
DATA LT_LIPS TYPE TABLE OF TY_LIPS.
LT_LIPS = T_LIPS.
SORT LT_LIPS BY WERKS.
DELETE ADJACENT DUPLICATES FROM LT_LIPS COMPARING WERKS.
SELECT WERKS
NAME1
ORT01
FROM T001W INTO TABLE T_T001W
FOR ALL ENTRIES IN T_LIPS
WHERE WERKS = T_LIPS-WERKS.
ENDFORM.
" GET_T001W_DATA
*&---------------------------------------------------------------------*
*&
Form POPULATE_FINAL_ITEM_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM POPULATE_FINAL_ITEM_DATA .

LOOP AT T_LIPS INTO W_LIPS.


W_FINAL_ITEM-VBELN = W_LIPS-VBELN.
W_FINAL_ITEM-POSNR = W_LIPS-POSNR.
W_FINAL_ITEM-MATNR = W_LIPS-MATNR.
W_FINAL_ITEM-WERKS = W_LIPS-WERKS.
W_FINAL_ITEM-LFIMG = W_LIPS-LFIMG.
W_FINAL_ITEM-ARKTX = W_LIPS-ARKTX.
READ TABLE T_MAKT INTO W_MAKT WITH KEY MATNR = W_LIPS-MATNR.
W_FINAL_ITEM-MAKTX = W_MAKT-MAKTX.
READ TABLE T_T001W INTO W_T001W WITH KEY WERKS = W_LIPS-WERKS.
W_FINAL_ITEM-NAME1_P = W_T001W-NAME1_P.
W_FINAL_ITEM-ORT01_P = W_T001W-ORT01_P.
APPEND W_FINAL_ITEM TO T_FINAL_ITEM.
ENDLOOP.

ENDFORM.
" POPULATE_FINAL_ITEM_DATA
*&---------------------------------------------------------------------*
*&
Form DISPLAY_REPORT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM DISPLAY_REPORT .

*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*

CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'


EXPORTING
I_INTERFACE_CHECK
= ' '
I_CALLBACK_PROGRAM
=
I_CALLBACK_PF_STATUS_SET
= ' '
I_CALLBACK_USER_COMMAND
= ' '
IS_LAYOUT
=
IT_FIELDCAT
= T_FCAT
IT_EXCLUDING
=
IT_SPECIAL_GROUPS
=
IT_SORT
= T_SORT
IT_FILTER
=
IS_SEL_HIDE
=
I_SCREEN_START_COLUMN
= 0
I_SCREEN_START_LINE
= 0
I_SCREEN_END_COLUMN
= 0
I_SCREEN_END_LINE
= 0
I_DEFAULT
= 'X'
I_SAVE
= ' '
IS_VARIANT
=
IT_EVENTS
=
IT_EVENT_EXIT
=
I_TABNAME_HEADER
= 'T_FINAL_HEADER'
I_TABNAME_ITEM
= 'T_FINAL_ITEM'
I_STRUCTURE_NAME_HEADER
=
I_STRUCTURE_NAME_ITEM
=
IS_KEYINFO
= W_KEYINFO
IS_PRINT
=

*
*
*
*
*
*
*
*
*

*
*
*
*
*

IS_REPREP_ID
=
I_BYPASSING_BUFFER
=
I_BUFFER_ACTIVE
=
IR_SALV_HIERSEQ_ADAPTER
=
IT_EXCEPT_QINFO
=
I_SUPPRESS_EMPTY_DATA
= ABAP_FALSE
IMPORTING
E_EXIT_CAUSED_BY_CALLER
=
ES_EXIT_CAUSED_BY_USER
=
TABLES
T_OUTTAB_HEADER
= T_FINAL_HEADER
T_OUTTAB_ITEM
= T_FINAL_ITEM
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_REPORT
*&---------------------------------------------------------------------*
*&
Form FIELD_CATALOG
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_0413 text
*
-->P_0414 text
*
-->P_0415 text
*
-->P_0416 text
*
-->P_0417 text
*----------------------------------------------------------------------*
FORM FIELD_CATALOG USING COLPOS
FNAME
TEXT
TABLENAME
TOTAL.
W_FCAT-COL_POS = COLPOS.
W_FCAT-FIELDNAME = FNAME.
W_FCAT-SELTEXT_M = TEXT.
W_FCAT-TABNAME = TABLENAME.
W_FCAT-DO_SUM = TOTAL.
APPEND W_FCAT TO T_FCAT.
ENDFORM.
" FIELD_CATALOG
*&---------------------------------------------------------------------*
*&
Form KEY_INFO
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM KEY_INFO .
W_KEYINFO-HEADER01 = 'VBELN'.
W_KEYINFO-ITEM01 = 'VBELN'.
ENDFORM.
" KEY_INFO

*&---------------------------------------------------------------------*
*&
Form SORT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM SORT .
W_SORT-FIELDNAME = 'VBELN'.
W_SORT-SUBTOT = 'X'.
APPEND W_SORT TO T_SORT.
ENDFORM.

" SORT