You are on page 1of 11

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

*& Report ZSD_RDD0084_DELIVERY_REP


*
*&
*
*&---------------------------------------------------------------------*
*&
Author : Ali Mohammed
*
*&
Title : Delivery Report- ALV Lock object
*
*&
Purpose: This report is used to display all the delivery header
*&
data,ITem data and ship to party address data
*& Transport:GROK900025
*& Version :V1
*&---------------------------------------------------------------------*
*& Version
Transport
Purpose
*&---------------------------------------------------------------------*
*& V2
GROK900026
Addition of new fields
*&---------------------------------------------------------------------*
REPORT ZSD_RDD0084_DELIVERY_REP NO STANDARD PAGE HEADING
.
TYPE-POOLS:SLIS.
to use Lock objects in Program?
*&---------------------------------------------------------------------*
*& Structure Declaration
*&---------------------------------------------------------------------*
* Structure declaration for delivery header
TYPES:BEGIN OF TY_LIKP,
VBELN TYPE VBELN_VL, "Delivery Number
VKORG TYPE VKORG,
"Sales Org
LFART TYPE LFART,
"Delivery Type
LDDAT TYPE LDDAT,
"Load Date
KUNNR TYPE KUNWE,
"Ship to party
END OF TY_LIKP,
* Structure declaration for
BEGIN OF TY_LIPS,
VBELN TYPE VBELN_VL,
POSNR TYPE POSNR_VL,
MATNR TYPE MATNR,
MATKL TYPE MATKL,
WERKS TYPE WERKS_D,
LGORT TYPE LGORT_D,
NTGEW TYPE NTGEW_15,
VGBEL TYPE VGBEL,
END OF TY_LIPS,

delivery item data


"Delivery number
"Delivery ITem
"Material
"Material Grp
"Plant
"Sloc
"Net Weight
"Sales Ord

* Structure Declaration for ship to party address


BEGIN OF TY_KNA1,
KUNNR TYPE KUNNR, "Cust Num
NAME1 TYPE NAME1_GP, "Cust Name
ORT01 TYPE ORT01_GP, "City
PSTLZ TYPE PSTLZ,
"Potal
REGIO TYPE REGIO,
"Region
END OF TY_KNA1,
* Structure declaration for Sales ITem
BEGIN OF TY_VBAP,
VBELN TYPE VBELN_VA, "Sales Ord
POSNR TYPE POSNR_VA, "Sales Item
MATNR TYPE MATNR,
"Material
PSTYV TYPE PSTYV, "Catagory

" How

NETWR TYPE NETWR_AP, "Net Value


WAERK TYPE WAERK,
"UOM
END OF TY_VBAP,
* Structure Declaration for final output
BEGIN OF TY_OUTPUT,
CHECK TYPE CHAR1,
ALV list output
VBELN TYPE VBELN_VL, "Delivery Number
VKORG TYPE VKORG,
"Sales Org
LFART TYPE LFART,
"Delivery Type
LDDAT TYPE LDDAT,
"Load Date
KUNNR TYPE KUNWE,
"Ship to party
NAME1
ORT01
PSTLZ
REGIO

TYPE
TYPE
TYPE
TYPE

NAME1_GP,
ORT01_GP,
PSTLZ,
REGIO,

" This field is for checkbox in

"Cust Name
"City
"Potal
"Region

POSNR TYPE POSNR_VL, "Delivery ITem


MATNR TYPE MATNR,
"Material
MATKL TYPE MATKL,
"Material Grp
WERKS TYPE WERKS_D, "Plant
LGORT TYPE LGORT_D, "Sloc
NTGEW TYPE NTGEW_15, "Net Weight
END OF TY_OUTPUT.
*&---------------------------------------------------------------------*
*& Internal table declaration
*&---------------------------------------------------------------------*
*
Internal table declaration for delivery header
DATA:T_LIKP TYPE STANDARD TABLE OF TY_LIKP INITIAL SIZE 0,
*

Internal table declaration for delivery item


T_LIPS TYPE STANDARD TABLE OF TY_LIPS INITIAL SIZE 0,

Internal table declaration for ship to party address


T_KNA1 TYPE STANDARD TABLE OF TY_KNA1 INITIAL SIZE 0,

Internal table declaration for sales Item


T_VBAP TYPE STANDARD TABLE OF TY_VBAP INITIAL SIZE 0,

* Internal table declaration for final output


T_OUTPUT TYPE STANDARD TABLE OF TY_OUTPUT INITIAL SIZE 0,
*&---------------------------------------------------------------------*
*& Work area declaration
*&---------------------------------------------------------------------*
* Work area declaration for delivery header
W_LIKP TYPE TY_LIKP,
* Work area declartion for delivery item
W_LIPS TYPE TY_LIPS,
* Work area declaration for ship to party address
W_KNA1 TYPE TY_KNA1,
* Work area declaration for Sales ITem
W_VBAP TYPE TY_VBAP,

* Work area declaration for final output


W_OUTPUT TYPE TY_OUTPUT,
W_OUTPUT1 TYPE TY_OUTPUT,
*&---------------------------------------------------------------------*
*& Global Variable declaration
*&---------------------------------------------------------------------*
G_VBELN TYPE LIKP-VBELN,
G_VBELN1 TYPE VBELN_VL,
*&---------------------------------------------------------------------*
*& ALV declaration
*&---------------------------------------------------------------------*
* Fieldcat Declarations
W_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
T_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV,
* Subtotal
W_SORT TYPE SLIS_SORTINFO_ALV,
T_SORT TYPE SLIS_T_SORTINFO_ALV,

" This is for subtotals

* Header
W_HEAD TYPE SLIS_LISTHEADER,
T_HEAD TYPE SLIS_T_LISTHEADER.

" This is for list header

*&---------------------------------------------------------------------*
*& Selection screen declaration
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
SELECT-OPTIONS:S_VBELN FOR G_VBELN.
SELECTION-SCREEN END OF BLOCK B1.
*&---------------------------------------------------------------------*
*& Initialization
*&---------------------------------------------------------------------*
INITIALIZATION.
* Clear Work areas
CLEAR:W_LIKP,
W_LIPS,
W_KNA1,
W_OUTPUT.
* Refresh internal tables
REFRESH:T_LIKP,
T_LIPS,
T_KNA1,
T_OUTPUT.
*&---------------------------------------------------------------------*
*& At selection screen declaration
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN.
* Validating the delivery num
PERFORM SUB_VALIDATE_VBELN.
*&---------------------------------------------------------------------*
*& Start of selection declaration

*&---------------------------------------------------------------------*
START-OF-SELECTION.
* Get LIKP data
PERFORM SUB_GET_LIKP.
* Get LIPS data
PERFORM SUB_GET_LIPS.
* Get Kna1 data
PERFORM SUB_GET_KNA1.
* Displaying the output
PERFORM SUB_DISP_OUT.
* Displaying the data in ALV
PERFORM SUB_DISP_ALV.
*&---------------------------------------------------------------------*
*&
Form sub_validate_vbeln
*&---------------------------------------------------------------------*
* This subroutine is used to validate delivery number
*----------------------------------------------------------------------*
FORM SUB_VALIDATE_VBELN .
DATA:L_VBELN TYPE VBELN_VL.
SELECT SINGLE VBELN
FROM VBUK
INTO L_VBELN
WHERE VBELN IN S_VBELN.
IF SY-SUBRC <> 0.
MESSAGE E002(ZBATCH32) WITH 'Invalid number sales order num range'.
ENDIF.
ENDFORM.
" sub_validate_vbeln
*&---------------------------------------------------------------------*
*&
Form SUB_GET_LIKP
*&---------------------------------------------------------------------*
* This subroutine is used to get delivery header data
*----------------------------------------------------------------------*
FORM SUB_GET_LIKP .
SELECT VBELN "Delivery num
VKORG "Sales Org
LFART "Deliver type
LDDAT "Load date
KUNNR "Ship to party
FROM LIKP
INTO TABLE T_LIKP
WHERE VBELN IN S_VBELN.
IF SY-SUBRC <> 0.
MESSAGE I002(ZBATCH32) WITH 'Data not maintained for given range'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM.
" SUB_GET_LIKP
*&---------------------------------------------------------------------*
*&
Form SUB_GET_LIPS
*&---------------------------------------------------------------------*
* This subroutine is used to delivery item data

*----------------------------------------------------------------------*
FORM SUB_GET_LIPS .
* CHECK T_LIKP IS NOT INITIAL.
SELECT VBELN "Delivery num
POSNR "Delv Item
MATNR "MAterial
MATKL "MAterial Grp
WERKS "Plant
LGORT "Sloc
NTGEW "NEt Weight
VGBEL "Sales Ord
FROM LIPS
INTO TABLE T_LIPS
FOR ALL ENTRIES IN T_LIKP
WHERE VBELN = T_LIKP-VBELN.
ENDFORM.
" SUB_GET_LIPS
*&---------------------------------------------------------------------*
*&
Form SUB_GET_KNA1
*&---------------------------------------------------------------------*
* This subroutine is used to get ship to party address data
*----------------------------------------------------------------------*
FORM SUB_GET_KNA1 .
* CHECK T_LIKP IS NOT INITIAL.
SELECT KUNNR "Ship to party
NAME1 "Cust name
ORT01 "CIty
PSTLZ "Postal
REGIO "Regio
FROM KNA1
INTO TABLE T_KNA1
FOR ALL ENTRIES IN T_LIKP
WHERE KUNNR = T_LIKP-KUNNR.
ENDFORM.
" SUB_GET_KNA1
*&---------------------------------------------------------------------*
*&
Form sub_disp_out
*&---------------------------------------------------------------------*
* This subroutine ise used to display the output
*----------------------------------------------------------------------*
FORM SUB_DISP_OUT .
LOOP AT T_LIPS INTO W_LIPS.
* Moving the delivery item data to final output
W_OUTPUT-VBELN = W_LIPS-VBELN.
W_OUTPUT-POSNR = W_LIPS-POSNR.
W_OUTPUT-MATNR = W_LIPS-MATNR.
W_OUTPUT-MATKL = W_LIPS-MATKL.
W_OUTPUT-WERKS = W_LIPS-WERKS.
W_OUTPUT-LGORT = W_LIPS-LGORT.
W_OUTPUT-NTGEW = W_LIPS-NTGEW.
* Moving Delivery header data
CLEAR W_LIKP.
READ TABLE T_LIKP INTO W_LIKP WITH KEY VBELN = W_LIPS-VBELN.

IF SY-SUBRC = 0.
W_OUTPUT-VKORG
W_OUTPUT-LFART
W_OUTPUT-LDDAT
W_OUTPUT-KUNNR
ENDIF.

=
=
=
=

W_LIKP-VKORG.
W_LIKP-LFART.
W_LIKP-LDDAT.
W_LIKP-KUNNR.

* Moving ship to party address data


CLEAR W_KNA1.
READ TABLE T_KNA1 INTO W_KNA1 WITH KEY KUNNR = W_LIKP-KUNNR.
IF SY-SUBRC = 0.
W_OUTPUT-NAME1 = W_KNA1-NAME1.
W_OUTPUT-ORT01 = W_KNA1-ORT01.
W_OUTPUT-PSTLZ = W_KNA1-PSTLZ.
W_OUTPUT-REGIO = W_KNA1-REGIO.
ENDIF.
APPEND W_OUTPUT TO T_OUTPUT.
CLEAR W_OUTPUT.
ENDLOOP.
ENDFORM.
" sub_disp_out
*&---------------------------------------------------------------------*
*&
Form SUB_DISP_ALV
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM SUB_DISP_ALV .
* Populating the fieldcat internal table
PERFORM SUB_CREATE_FCAT USING: '1' 'CHECK' '' '' 'X' 'X',
ast but one is for check box and other is for edit the checkbox
'2' 'VBELN' 'Delivery Num' '' '' '',
'3' 'POSNR' 'Delv Item' '' '' '',
'4' 'MATNR' 'Material' '' '' '',
'5' 'VKORG' 'Sales Org' '' '' '',
'6' 'LDDAT' 'Load Date' '' '' '',
'7' 'NAME1' 'Cust Name' '' '' '',
'8' 'ORT01' 'City' '' '' '',
'9' 'NTGEW' 'Net Value' 'X' '' 'X'.
* Subtotals
W_SORT-FIELDNAME = 'VBELN'.
W_SORT-SUBTOT = 'X'.
APPEND W_SORT TO T_SORT.
CLEAR W_SORT.
* Header
W_HEAD-TYP = 'H'.
W_HEAD-INFO = 'DELIVERY REPORT'.
APPEND W_HEAD TO T_HEAD.
CLEAR W_HEAD.
W_HEAD-TYP = 'S'.
W_HEAD-KEY = 'Delivery No:'.
CONCATENATE S_VBELN-LOW
'to'
S_VBELN-HIGH
INTO W_HEAD-INFO
SEPARATED BY SPACE.

" l

APPEND W_HEAD TO T_HEAD.


CLEAR W_HEAD.
* PERFORM TOP_OF_PAGE.
* PERFORM SUB_USER_COMMAND.
* Displaying the data in ALV
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
= 'SUB_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
= 'DELIVERY REPORT'
* I_GRID_SETTINGS
=
* IS_LAYOUT
=
IT_FIELDCAT
= T_FIELDCAT
* IT_EXCLUDING
=
* IT_SPECIAL_GROUPS
=
IT_SORT
= T_SORT
* IT_FILTER
=
* IS_SEL_HIDE
=
* I_DEFAULT
= 'X'
* I_SAVE
= ' '
* IS_VARIANT
=
* IT_EVENTS
=
* IT_EVENT_EXIT
=
* IS_PRINT
=
* IS_REPREP_ID
=
* I_SCREEN_START_COLUMN
= 0
* I_SCREEN_START_LINE
= 0
* I_SCREEN_END_COLUMN
= 0
* I_SCREEN_END_LINE
= 0
* IT_ALV_GRAPHICS
=
* IT_HYPERLINK
=
* IT_ADD_FIELDCAT
=
* IT_EXCEPT_QINFO
=
* I_HTML_HEIGHT_TOP
=
* I_HTML_HEIGHT_END
=
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER
=
* ES_EXIT_CAUSED_BY_USER
=
TABLES
T_OUTTAB
= T_OUTPUT
* 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.
" SUB_DISP_ALV
*&---------------------------------------------------------------------*
*&
Form SUB_CREATE_FCAT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM SUB_CREATE_FCAT USING P_COL TYPE CHAR2
P_FNAME TYPE CHAR10
P_TEXT TYPE CHAR30
P_SUM TYPE CHAR1
P_CHECK TYPE CHAR1
" This paramter i
s for checkbox in ALV
P_EDIT TYPE CHAR1.
" This is to enab
le checkbox in ALV
W_FIELDCAT-COL_POS = P_COL.
W_FIELDCAT-FIELDNAME = P_FNAME.
W_FIELDCAT-SELTEXT_M = P_TEXT.
W_FIELDCAT-DO_SUM = P_SUM.
W_FIELDCAT-CHECKBOX = P_CHECK.
W_FIELDCAT-EDIT = P_EDIT.
ckbox
APPEND W_FIELDCAT TO T_FIELDCAT.
CLEAR W_FIELDCAT.

" This is for checkbox in ALV


" This is for edit(Enable) the che

ENDFORM.
" SUB_CREATE_FCAT
*&---------------------------------------------------------------------*
*&
Form top_of_page
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM TOP_OF_PAGE .
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY
= T_HEAD
I_LOGO
= 'SUBASH_B32'
* I_END_OF_LIST_GRID
=
.
ENDFORM.
" top_of_page
*&---------------------------------------------------------------------*
*&
Form sub_user_command
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM SUB_USER_COMMAND USING R_UCOMM TYPE SY-UCOMM
" Keep a break point here and execute. If u double click in particular
R_SELFIELD TYPE SLIS_SELFIELD.
" line in ALV, &IC1 triggers at R_UCOMM
CASE R_UCOMM.
WHEN '&IC1'.
CHECK R_SELFIELD-FIELDNAME = 'VBELN'.
G_VBELN1 = R_SELFIELD-VALUE.
PERFORM SUB_DISP_SALES.
WHEN '&DATA_SAVE'.
utton of ALV output then &DATA_SAVE triggers
PERFORM SUB_SAVE_DATA.

" If u click on Save b

ENDCASE.
ENDFORM.
" sub_user_command
*&---------------------------------------------------------------------*
*&
Form sub_disp_sales
*&---------------------------------------------------------------------*
*
This subroutine is used for Secondary detail list from basic list
*
*----------------------------------------------------------------------*
FORM SUB_DISP_SALES .
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = G_VBELN1
IMPORTING
OUTPUT = G_VBELN1.

" This is for leading zeros

CLEAR W_LIPS.
READ TABLE T_LIPS INTO W_LIPS WITH KEY VBELN = G_VBELN1.
CHECK SY-SUBRC = 0.
SELECT VBELN "Sales Ord
POSNR "SAles Item
MATNR "MAterial
PSTYV "Catagory
NETWR "Net Value
WAERK "UOM
FROM VBAP
INTO TABLE T_VBAP
WHERE VBELN = W_LIPS-VGBEL.
*Creating the fieldcat
REFRESH T_FIELDCAT1.
PERFORM SUB_CREATE_FCAT1 USING: '1'
'2'
'3'
'4'
'5'
'6'

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

'VBELN'
'POSNR'
'MATNR'
'PSTYV'
'NETWR'
'WAERK'

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
I_INTERFACE_CHECK
= '
I_BYPASSING_BUFFER
= '
I_BUFFER_ACTIVE
= '
I_CALLBACK_PROGRAM
=
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
=
IT_EXCLUDING
=
IT_SPECIAL_GROUPS
=
IT_SORT
=
IT_FILTER
=

'Sales Ord' '',


'Item' '',
'Material' '',
'Catagory' '',
'Net Value' 'X',
'UOM' ''.

'
'
'
SY-CPROG
'
'
'
'
'
'
'SALES REPORT'
T_FIELDCAT1

* IS_SEL_HIDE
=
* I_DEFAULT
= 'X'
* I_SAVE
= ' '
* IS_VARIANT
=
* IT_EVENTS
=
* IT_EVENT_EXIT
=
* IS_PRINT
=
* IS_REPREP_ID
=
* I_SCREEN_START_COLUMN
= 0
* I_SCREEN_START_LINE
= 0
* I_SCREEN_END_COLUMN
= 0
* I_SCREEN_END_LINE
= 0
* IT_ALV_GRAPHICS
=
* IT_HYPERLINK
=
* IT_ADD_FIELDCAT
=
* IT_EXCEPT_QINFO
=
* I_HTML_HEIGHT_TOP
=
* I_HTML_HEIGHT_END
=
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER
=
* ES_EXIT_CAUSED_BY_USER
=
TABLES
T_OUTTAB
= T_VBAP
* 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.
" sub_disp_sales
*&---------------------------------------------------------------------*
*&
Form sub_create_fcat1
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM SUB_CREATE_FCAT1 USING P_COL TYPE CHAR2
P_FNAME TYPE CHAR10
P_TEXT TYPE CHAR30
P_SUM TYPE CHAR1.
W_FIELDCAT-COL_POS = P_COL.
W_FIELDCAT-FIELDNAME = P_FNAME.
W_FIELDCAT-SELTEXT_M = P_TEXT.
W_FIELDCAT-DO_SUM = P_SUM.
APPEND W_FIELDCAT TO T_FIELDCAT1.
CLEAR W_FIELDCAT.
ENDFORM.
" sub_create_fcat1
*&---------------------------------------------------------------------*
*&
Form SUB_SAVE_DATA
*&---------------------------------------------------------------------*
*
This subroutine is used to save the data in the data base table
*
ZSAMPLE_B32
*----------------------------------------------------------------------*
FORM SUB_SAVE_DATA .
DATA:T_SAMPLE TYPE STANDARD TABLE OF ZSAMPLE_B32 INITIAL SIZE 0,
AMPLE_B32 custom table

" ZS

W_SAMPLE TYPE ZSAMPLE_B32.


LOOP AT T_OUTPUT INTO W_OUTPUT WHERE CHECK = 'X'.
MOVE-CORRESPONDING W_OUTPUT TO W_SAMPLE.
to database
APPEND W_SAMPLE TO T_SAMPLE.
CLEAR W_SAMPLE.
ENDLOOP.
* lock the table
CALL FUNCTION 'ENQUEUE_EZLOCK_B32'.
ustom table locked. Just call, no parameters.
CHECK SY-SUBRC = 0.
n modify

" one by one record

" for Which table ZSAMPLE_B32 c


" if it is reading the lock the

MODIFY ZSAMPLE_B32 FROM TABLE T_SAMPLE.


IF SY-SUBRC = 0.
MESSAGE S002(ZBATCH32) WITH 'Data inserted successfully'.
ENDIF.
* Release the table
CALL FUNCTION 'DEQUEUE_EZLOCK_B32'.
DEQUEUE generated by lock object ,

" Just call the function module


" no parameters-This is for rele

asing the table lock


ENDFORM.

" SUB_SAVE_DATA