You are on page 1of 49

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

*& Report ZSD_CREATE_SO_FROM_QUOTE


*&
*&---------------------------------------------------------------------*
* PROJECT
# Olex
* DATE WRITTEN
# 04.02.2010
* SYSTEM
# ODE
* SAP VERSION
# 700
* TYPE
# Report
* AUTHOR
# Hariprasad Reddy/Vinay kumar Reddy.Chintagunta
* FUNCTIONAL OWNER #
*----------------------------------------------------------------------* TITLE
# ZSD_OPEN_ORDERS_REPORT
* PURPOSE
# This ALV allows the user to display Open Orders.
* COPIED FROM
# New program
*----------------------------------------------------------------------* CALLED FROM
#
*
#
*----------------------------------------------------------------------* CALLS TO
# None
*
#
*----------------------------------------------------------------------* RESTRICTIONS
#
*
#
*----------------------------------------------------------------------REPORT

zsd_open_orders_report1 NO STANDARD PAGE HEADING


MESSAGE-ID zsd.

TABLES : vbak, vbbe, vbap, lips, marc, vbpa.


***************************************************************************
*****
*
TYPES DECLARING
*
***************************************************************************
*****
TYPES: BEGIN OF ty_final,
vbeln TYPE vbak-vbeln,
"Sales Document
posnr TYPE vbap-posnr,
"Sales Document Item
matnr TYPE vbap-matnr,
"Material Number
maktx TYPE makt-maktx,
"Material description
werks TYPE vbap-werks,
"Plant (Own or External)
* Start of insert by Vijay on 08/02/2011 for Quotation Data wrt Ticket T007
97
auart TYPE vbak-auart,
"Sales Document Type
angdt TYPE vbak-angdt,
"Valid From Date
bnddt TYPE vbak-bnddt,
"Valid To Date
meins TYPE vbap-meins,
"Base Unit of Measure (UoM)
waerk TYPE vbak-waerk,
"Currency
kpein TYPE vbap-kpein,
"Condition Pricing Unit
* End of insert by Vijay on 08/02/2011 for Quotation Data wrt Ticket T00797
lgort TYPE vbbe-lgort,

mbdat
kwmeng
omeng
clabs
sclab
dvbel
aclab
vmeng
vkorg
vtweg
spart
vdatu
kunnr
kunnr1
name1
etenr
edatu
charg
bzirk
brsch
bran1
mvgr2
prodh
netpr
netwr
ernam
gbsta

TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE

vbbe-mbdat,
vbap-kwmeng,
vbbe-omeng,
mchb-clabs,
mchb-clabs,
likp-vbeln,
mchb-clabs,
vbbe-vmeng,
vbak-vkorg,
vbak-vtweg,
vbak-spart,
vbak-vdatu,
vbak-kunnr,
vbak-kunnr,
kna1-name1,
vbep-etenr,
vbep-edatu,
vbbe-charg,
knvv-bzirk,
kna1-brsch,
kna1-bran1,
mvke-mvgr2,
mvke-prodh,
vbap-netpr,
vbap-netwr,
vbak-ernam,
vbup-gbsta,

"Confirmed Quantity
"Sales Organization
"Distribution Channel
"Division
"Requested delivery date
"Sold-to party
"Ship-to party
"Name
"Schedule line date
"Sales District
"Sales Industry
"Sales Industry Code 1.
"Manufacturer
"Product Hierarchy
"Net Value
"Created by
"Overall Delivery status of the Orde

r Item
bstnk TYPE vbak-bstnk,
END OF ty_final.
TYPES: BEGIN OF ty_vbup,
vbeln TYPE vbup-vbeln,
posnr TYPE vbup-posnr,
lfsta TYPE vbup-lfsta,
gbsta TYPE vbup-gbsta,
END OF ty_vbup.
TYPES: BEGIN OF ty_mara,
matnr TYPE mara-matnr,
xchpf TYPE mara-xchpf,
END OF ty_mara.
TYPES: BEGIN OF ty_makt,
matnr TYPE makt-matnr,
maktx TYPE makt-maktx,
END OF ty_makt.
TYPES: BEGIN OF ty_mchb,
matnr TYPE mchb-matnr,
werks TYPE mchb-werks,
lgort TYPE mchb-lgort,
charg TYPE mchb-charg,

"Customer Purchase Order Number

"Sales Document

"Material No
"Batch management indicator

clabs TYPE mchb-clabs,


END OF ty_mchb.
TYPES: BEGIN OF ty_mard,
matnr TYPE mard-matnr,
werks TYPE mard-werks,
lgort TYPE mard-lgort,
labst TYPE mard-labst,
END OF ty_mard.
TYPES: BEGIN OF ty_vbak,
vbeln TYPE vbak-vbeln,
ernam TYPE vbak-ernam,
netwr TYPE vbak-netwr,
ment Currency
vkorg TYPE vbak-vkorg,
vtweg TYPE vbak-vtweg,
spart TYPE vbak-spart,
vdatu TYPE vbak-vdatu,
bstnk TYPE vbak-bstnk,
kunnr TYPE vbak-kunnr,
END OF ty_vbak.
TYPES: BEGIN OF ty_knvv,
kunnr TYPE vbak-kunnr,
vkorg TYPE knvv-vkorg,
vtweg TYPE knvv-vtweg,
spart TYPE knvv-spart,
bzirk TYPE knvv-bzirk,
END OF ty_knvv.
TYPES: BEGIN OF ty_kna1,
kunnr TYPE vbak-kunnr,
name1 TYPE kna1-name1,
brsch TYPE kna1-brsch,
bran1 TYPE kna1-bran1,
END OF ty_kna1.
TYPES: BEGIN OF ty_vbpa,
vbeln TYPE vbpa-vbeln,
posnr TYPE vbpa-posnr,
parvw TYPE vbpa-parvw,
kunnr TYPE vbpa-kunnr,
END OF ty_vbpa.
TYPES: BEGIN OF ty_mvke,
matnr TYPE mvke-matnr,
vkorg TYPE mvke-vkorg,
vtweg TYPE mvke-vtweg,
prodh TYPE mvke-prodh,
mvgr2 TYPE mvke-mvgr2,
END OF ty_mvke.

"Sales Document
"Net Value of the Sales Order in Docu
"Sales Organization
"Distribution Channel
"Division
"Requested delivery date
"Customer purchase order number
"Sold-to party

"Sold-to party
"Sales Organization
"Distribution Channel
"Division
"Sales District

"Customer Number 1
"Sales Industry
"Sales Industry Code 1.

"Sales Document
"Item
"Customer Number 1

"Material Number
"Sales Organization
"Distribution Channel
"Product Hierarchy
"Manufacturer

TYPES: BEGIN OF ty_vbap,


vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr,
matnr TYPE vbap-matnr,
charg TYPE vbap-charg,
posar TYPE vbap-posar,
abgru TYPE vbap-abgru,
netwr TYPE vbap-netwr,
kwmeng TYPE vbap-kwmeng,
nits
werks TYPE vbap-werks,
lgorg TYPE vbap-lgort,
vstel TYPE vbap-vstel,
netpr TYPE vbap-netpr,
kpein TYPE vbap-kpein,
END OF ty_vbap.
TYPES: BEGIN OF ty_vbbe,
vbeln TYPE vbbe-vbeln,
posnr TYPE vbbe-posnr,
etenr TYPE vbbe-etenr,
matnr TYPE vbbe-matnr,
werks TYPE vbbe-werks,
mbdat TYPE vbbe-mbdat,
lgort TYPE vbbe-lgort,
charg TYPE vbbe-charg,
vbtyp TYPE vbbe-vbtyp,
omeng TYPE vbbe-omeng,
vmeng TYPE vbbe-vmeng,
END OF ty_vbbe.
TYPES: BEGIN OF ty_vbep,
vbeln TYPE vbep-vbeln,
posnr TYPE vbep-posnr,
etenr TYPE vbep-etenr,
edatu TYPE vbep-edatu,
wmeng TYPE vbep-wmeng,
bmeng TYPE vbep-bmeng,
END OF ty_vbep.
TYPES: BEGIN OF ty_lips,
vbeln TYPE lips-vbeln,
posnr TYPE lips-posnr,
lfimg TYPE lips-lfimg,
vgbel TYPE lips-vgbel,
vgpos TYPE lips-vgpos,
END OF ty_lips.

"Sales Document
"Sales Document Item
"Material Number
"Batch
"Item Type
"Reason for Rejection
"Net Value
"Cumulative Order Quantity in Sales U
"Plant (Own or External)
"Storage loc
"Shipping Point/Receiving Point
"Net price
"Condition Pricing Unit

"Sales Document
"Item

"Schedule line date

"Open Qty in Stockkeeping


"Confirmed Quantity

"Sales Document
"Item

"Delivery
"Del Item
"Sales Document
"SO Item

* Start of insert by Vijay on 08/02/2011 for Quotation Data wrt Ticket T007
97
TYPES: BEGIN OF ty_qvbak,
vbeln TYPE vbak-vbeln,

"Sales Document

erdat
ernam
angdt
bnddt
vbtyp
auart
netwr
ment Currency
waerk
vkorg
vtweg
spart
vdatu
bstnk
kunnr
END OF

TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE

vbak-erdat,
vbak-ernam,
vbak-angdt,
vbak-bnddt,
vbak-vbtyp,
vbak-auart,
vbak-netwr,

TYPE vbap-waerk,
TYPE vbak-vkorg,
TYPE vbak-vtweg,
TYPE vbak-spart,
TYPE vbak-vdatu,
TYPE vbak-bstnk,
TYPE vbak-kunnr,
ty_qvbak.

"Date on which document was created


"Created By
"Valid From Date
"Valid To Date
"SD Document category
"Sales Document Type
"Net Value of the Sales Order in Docu

TYPES: BEGIN OF ty_qvbap,


vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr,
matnr TYPE vbap-matnr,
arktx TYPE vbap-arktx,
prodh TYPE vbap-prodh,
meins TYPE vbap-meins,
netwr TYPE vbap-netwr,
kwmeng TYPE vbap-kwmeng,
Units
werks TYPE vbap-werks,
lgort TYPE vbap-lgort,
netpr TYPE vbap-netpr,
kpein TYPE vbap-kpein,
END OF ty_qvbap.

"Document Currency
"Sales Organization
"Distribution Channel
"Division
"Requested delivery date
"Customer Purchase Order Number
"Sold-to party

"Sales Document
"Sales Document Item
"Material Number
"Material Short Text
"Product Hierarchy
"Base Unit of Measure
"Net Value
"Cumulative Order Quantity in Sales

TYPES: BEGIN OF ty_qvbpa,


vbeln TYPE vbpa-vbeln,
posnr TYPE vbpa-posnr,
parvw TYPE vbpa-parvw,
kunnr TYPE vbpa-kunnr,
adrnr TYPE vbpa-adrnr,
END OF ty_qvbpa.

"Plant (Own or External)


"Storage loc
"Net price
"Condition Pricing Unit

"Sales Document
"Item
"Partner Function
"Customer Number 1
"Address Number

TYPES: BEGIN OF ty_adrc,


addrnumber TYPE adrc-addrnumber, "Address Number
name1
TYPE adrc-name1,
"Name
END OF ty_adrc.
TYPES: BEGIN OF ty_vbuk,
vbeln TYPE vbuk-vbeln,
gbstk TYPE vbuk-gbstk,
END OF ty_vbuk.
* End of insert by Vijay on 08/02/2011

"Sales Document

TYPES: BEGIN OF ty_fieldcatalog.


INCLUDE STRUCTURE lvc_s_fcat.
TYPES: END OF ty_fieldcatalog.
TYPES: BEGIN OF ty_sort.
INCLUDE STRUCTURE lvc_s_sort.
TYPES: END OF ty_sort.
TYPES: BEGIN OF ty_shp_idx_gdsi.
INCLUDE STRUCTURE shp_idx_gdsi.
TYPES: END OF ty_shp_idx_gdsi.
TYPES: BEGIN OF ty_shp_idx_pick.
INCLUDE STRUCTURE shp_idx_pick.
TYPES: END OF ty_shp_idx_pick.
TYPES: BEGIN OF ty_tot,
matnr TYPE vbbe-matnr,
werks TYPE vbbe-werks,
lgort TYPE vbbe-lgort,
omeng TYPE vbbe-omeng,
"Open Qty in Stockkeeping
vmeng TYPE vbbe-vmeng,
"Confirmed Quantity
END OF ty_tot.
*data: it_sort like line of LVC_T_SORT.
***************************************************************************
*****
*
DATA DECLARING
*
***************************************************************************
*****

DATA: it_vbak TYPE TABLE OF ty_vbak


it_vbap TYPE TABLE OF ty_vbap
* Start of insert by Vijay on 08/02/2011
et # T00797
it_qvbak TYPE TABLE OF ty_qvbak
it_qvbap TYPE TABLE OF ty_qvbap
it_qvbpa TYPE TABLE OF ty_qvbpa
it_adrc TYPE TABLE OF ty_adrc
it_vbuk TYPE TABLE OF ty_vbuk
* End of insert by Vijay on 08/02/2011
it_vbbe TYPE TABLE OF ty_vbbe
it_vbbe1 TYPE TABLE OF ty_vbbe
it_vbbe2 TYPE TABLE OF ty_vbbe
it_tot
TYPE TABLE OF ty_tot
it_d_tot TYPE TABLE OF ty_tot
it_vbep TYPE TABLE OF ty_vbep
it_makt TYPE TABLE OF ty_makt
it_mchb TYPE TABLE OF ty_mchb
it_mard TYPE TABLE OF ty_mard
it_mara TYPE TABLE OF ty_mara
it_knvv TYPE TABLE OF ty_knvv

WITH HEADER LINE,


WITH HEADER LINE,
to display Quotation Data wrt Tick
WITH
WITH
WITH
WITH
WITH

HEADER
HEADER
HEADER
HEADER
HEADER

LINE,
LINE,
LINE,
LINE,
LINE,

WITH
WITH
WITH
WITH
WITH
WITH
WITH
WITH
WITH
WITH
WITH

HEADER
HEADER
HEADER
HEADER
HEADER
HEADER
HEADER
HEADER
HEADER
HEADER
HEADER

LINE,
LINE,
LINE,
LINE,
LINE,
LINE,
LINE,
LINE,
LINE,
LINE,
LINE,

it_kna1
it_mvke
it_vbup
it_vbpa
it_lips
it_final
wa_final

TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE

TABLE OF ty_kna1
TABLE OF ty_mvke
TABLE OF ty_vbup
TABLE OF ty_vbpa
TABLE OF ty_lips
TABLE OF ty_final,
ty_final.

WITH
WITH
WITH
WITH
WITH
"WITH

HEADER
HEADER
HEADER
HEADER
HEADER
HEADER

LINE,
LINE,
LINE,
LINE,
LINE,
LINE.

DATA: it_shp_idx_gdsi TYPE TABLE OF ty_shp_idx_gdsi WITH HEADER LINE,


it_shp_idx_pick TYPE TABLE OF ty_shp_idx_pick WITH HEADER LINE.
*** ALV declaration for container
DATA: o_container1 TYPE REF TO cl_gui_custom_container,
o_grid1
TYPE REF TO cl_gui_alv_grid,
o_container2 TYPE REF TO cl_gui_custom_container,
o_grid2
TYPE REF TO cl_gui_alv_grid,
gs_layout
TYPE lvc_s_layo,
gs_varaint
TYPE disvariant,
gs_toolbar
TYPE stb_button,
g_repid
LIKE sy-repid.
DATA: it_fieldcatalog
it_sort
wa_fieldcatalog

TYPE TABLE OF ty_fieldcatalog,


TYPE TABLE OF ty_sort,
TYPE ty_fieldcatalog.

DATA: ok_code TYPE sy-ucomm.


DATA: v_flag
v_flag_p
v_check
v_x
v_lfimg

TYPE
TYPE
TYPE
TYPE
TYPE

c,
c,
c,
c VALUE 'X',
lips-lfimg.

DATA: v_checked1 TYPE cua_active,


v_checked2 TYPE cua_active.
DATA: v_quot
v_sales
v_records
v_total
v_lines

TYPE
TYPE
TYPE
TYPE
TYPE

char1,
char1,
string,
char20,
i.

**************
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive,

handle_menu_button
FOR EVENT menu_button OF cl_gui_alv_grid
IMPORTING e_object e_ucomm,
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm,
handle_double_click
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column es_row_no.
PRIVATE SECTION.
ENDCLASS.

"lcl_event_receiver DEFINITION

*----------------------------------------------------------------------*
*
CLASS lcl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_toolbar.
* 2.At event TOOLBAR define a toolbar element of type 1 by using
*
event paramenter E_OBJECT. Remember its function code.
*.......
* Part I: Define a menu button including a function code that
*
is evaluated in 'handle_MENU_BUTTON
*.......
* append a separator to normal toolbar
CLEAR gs_toolbar.
MOVE 3 TO gs_toolbar-butn_type.
APPEND gs_toolbar TO e_object->mt_toolbar.
*...................
* append a menu with default button (Type 1)
* The function code of the default button is the same as
* the one for the menu.
* If the user klicks on the default button ALV raises
* directly event BEFORE_USER_COMMAND
* (then USER_COMMAND, AFTER_USER_COMMAND).
* If the user klicks on the menu button ALV raises event MENU_BUTTON.
CLEAR gs_toolbar.
MOVE 'BATCH' TO gs_toolbar-function.
* --> This function code is evaluated in 'handle_menu_button'
MOVE icon_detail TO gs_toolbar-icon.
MOVE 'Batch management'(200) TO gs_toolbar-quickinfo.
MOVE 1 TO gs_toolbar-butn_type.
MOVE space TO gs_toolbar-disabled.

APPEND gs_toolbar TO e_object->mt_toolbar.


ENDMETHOD.
"handle_toolbar
*-------------------------------------------------------------------METHOD handle_menu_button.
* 3.At event MENU_BUTTON query your function code and define a
*
menu in the same way as a context menu.
*..........
* Part II: Evaluate 'e_ucomm' to see which menu button of the toolbar
*
has been clicked on.
*
Define then the corresponding menu.
*
The menu contains function codes that are evaluated
*
in 'handle_user_command'.
*...........
*

*
*

query e_ucomm to find out which menu button has been clicked on
IF e_ucomm = 'BATCH'.
CALL METHOD e_object->add_function
EXPORTING
fcode
= 'BATCH'
text
= text-100 "batch V_TEXT.
checked = v_checked1.
3a.) choose a default function and define the same function code
as used for the menu.
CALL METHOD e_object->add_function
EXPORTING
fcode
= 'NON_BATCH'
text
= text-200 "non batch
checked = v_checked2.

ENDIF.
ENDMETHOD.
"handle_menu_button
*--------------------------------------------------------------------METHOD handle_user_command.
* 4.At event USER_COMMAND query the function code of each function
*
defined in step 3.
*.........
* Part III : Evaluate user command to invoke the corresponding
*
function.
*.........
DATA: lt_rows TYPE lvc_t_row.
* get selected row
CALL METHOD o_grid1->get_selected_rows
IMPORTING
et_index_rows = lt_rows.
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc NE 0.
* add your handling, for example
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid

txt2
txt1

= sy-subrc
= 'Error in Flush'(500).

ENDIF.
* go to other table
ok_code = e_ucomm.
CASE e_ucomm.
WHEN 'BATCH'.
CLEAR v_checked2.
v_checked1 = v_x.
LEAVE TO SCREEN 100.
WHEN 'NON_BATCH'.
CLEAR v_checked1.
v_checked2 = v_x.
LEAVE TO SCREEN 200.
ENDCASE.
*

CALL METHOD O_GRID1->SET_TOOLBAR_INTERACTIVE.

ENDMETHOD.
*
* lcl_event_receiver (Implementation)

"handle_user_command

METHOD handle_double_click.
CASE e_column.
WHEN 'VBELN'.
READ TABLE it_final INTO wa_final INDEX e_row.
SET PARAMETER ID 'AUN' FIELD wa_final-vbeln.
CALL TRANSACTION 'VA02' AND SKIP FIRST SCREEN.
WHEN 'MATNR'.
READ TABLE it_final INTO wa_final INDEX e_row.
SET PARAMETER ID 'MAT' FIELD wa_final-matnr.
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
WHEN 'CLABS'.
READ TABLE it_final INTO wa_final INDEX e_row.
SET PARAMETER ID 'MAT' FIELD wa_final-matnr.
SET PARAMETER ID 'WRK' FIELD wa_final-werks.
SET PARAMETER ID 'LAG' FIELD wa_final-lgort.
CALL TRANSACTION 'ZMMBE' AND SKIP FIRST SCREEN.
WHEN 'POSNR'.
READ TABLE it_final INTO wa_final INDEX e_row.
SET PARAMETER ID 'MAT' FIELD wa_final-matnr.
SET PARAMETER ID 'WRK' FIELD wa_final-werks.
SET PARAMETER ID 'LAG' FIELD wa_final-lgort.
CALL TRANSACTION 'ZMMBE' AND SKIP FIRST SCREEN.
WHEN 'CHARG'.
READ TABLE it_final INTO wa_final INDEX e_row.
SET PARAMETER ID 'MAT' FIELD wa_final-matnr.
SET PARAMETER ID 'WRK' FIELD wa_final-werks.
SET PARAMETER ID 'LAG' FIELD wa_final-lgort.
CALL TRANSACTION 'ZMMBE' AND SKIP FIRST SCREEN.
WHEN 'DVBEL'.
READ TABLE it_final INTO wa_final INDEX e_row.

SET PARAMETER ID 'VL' FIELD wa_final-dvbel.


CALL TRANSACTION 'VL02N' AND SKIP FIRST SCREEN.
ENDCASE.
ENDMETHOD.
ENDCLASS.

"HANDLE_DOUBLE_CLICK
"lcl_event_receiver IMPLEMENTATION

***************************************************************************
*****
*
SELECTION SCREEN
*
***************************************************************************
*****
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_kunnr FOR vbak-kunnr,
s_shipto FOR vbpa-kunnr,
s_bstnk FOR vbak-bstnk OBLIGATORY,
s_matnr FOR vbap-matnr,
s_werks FOR vbap-werks, " OBLIGATORY,
*
s_mbdat FOR vbbe-mbdat OBLIGATORY,
s_vbeln FOR lips-vbeln,
s_auart FOR vbak-auart NO INTERVALS NO-EXTENSION,
s_mbdat FOR vbbe-mbdat.
*PARAMETER
p_auart LIKE vbak-auart.
**PARAMETERS:
**

P_BATCH RADIOBUTTON GROUP RAD1,


P_NBATCH RADIOBUTTON GROUP RAD1.

SELECTION-SCREEN END OF BLOCK b1.


* Start of insert by Vijay on 08/02/2011 wrt Ticket T00797
* Additional selection is added to the screen as both Sales Order and
* Quotation data has to be displayed based on the user selection
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
*PARAMETERS: p_order RADIOBUTTON GROUP rad DEFAULT 'X',
*
p_qt
RADIOBUTTON GROUP rad.
PARAMETERS: p_order AS CHECKBOX USER-COMMAND fc03,
p_qt
AS CHECKBOX USER-COMMAND fc03.

SELECTION-SCREEN END OF BLOCK b2.


* End of insert by Vijay on 08/02/2011 wrt Ticket T00797
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
PARAMETERS:

p_open RADIOBUTTON GROUP rad1 MODIF ID id1 DEFAULT 'X',


p_close RADIOBUTTON GROUP rad1 MODIF ID id1,
p_all
RADIOBUTTON GROUP rad1 MODIF ID id1.

SELECTION-SCREEN END OF BLOCK b3.


AT SELECTION-SCREEN OUTPUT.
IF p_order EQ ' ' AND p_qt EQ ' '.
LOOP AT SCREEN.
IF screen-group1 = 'ID1'.
screen-active = 0.
ENDIF.
MODIFY SCREEN.
CLEAR: p_qt, p_order.
ENDLOOP.
ENDIF.
IF v_sales EQ ' '.
IF p_order EQ 'X'.
v_sales = 'X'.
CLEAR: v_quot, p_qt.
ENDIF.
ENDIF.
IF v_quot EQ ' '.
IF p_qt EQ 'X'.
v_quot = 'X'.
CLEAR: v_sales, p_order.
ENDIF.
ENDIF.
IF p_order EQ 'X'.
LOOP AT SCREEN.
IF screen-group1 EQ 'ID1'.
screen-active = '1'.
CLEAR p_qt.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ELSEIF p_qt EQ 'X'.
LOOP AT SCREEN.
IF screen-group1 EQ 'ID1'.
screen-active = '0'.
CLEAR p_order.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.
***************************************************************************
*****
*
AT SELECTION-SCREEN
*
***************************************************************************
*****

AT SELECTION-SCREEN .
SELECT

SINGLE *
FROM marc
WHERE matnr IN s_matnr
AND werks IN s_werks.

IF sy-subrc <> 0.
READ TABLE s_werks INDEX 1.
IF NOT s_matnr[] IS INITIAL.
MESSAGE e100 WITH s_matnr-low 'is not maintained for plant' s_werkslow.
ELSE.
MESSAGE e100 WITH s_werks-low 'does not exit'.
ENDIF.
ENDIF.
IF ( p_order EQ 'X' AND p_qt EQ 'X' AND sy-ucomm = 'ONLI' ) OR ( p_order
EQ '' AND p_qt EQ '' AND sy-ucomm = 'ONLI' ).
MESSAGE e032.
ENDIF.
***************************************************************************
*****
*
START-OF-SELECTION
*
***************************************************************************
*****
START-OF-SELECTION.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*&
Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS'.
IF p_order = 'X' AND p_all = 'X'.
SET TITLEBAR 'TITLE'.
ELSEIF p_order = 'X' AND p_open = 'X'.
SET TITLEBAR 'TITLE_OPEN'.
ELSEIF p_order = 'X' AND p_close = 'X'.
SET TITLEBAR 'TITLE_CLOSE'.
ELSEIF p_qt = 'X'.
SET TITLEBAR 'TITLE_QT'.
ENDIF.
ENDMODULE.
" STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
Module GET_DATA_100 OUTPUT
*&---------------------------------------------------------------------*
MODULE get_data_100 OUTPUT.

IF p_order EQ 'X'.
PERFORM get_data_order.
ELSEIF p_qt EQ 'X'.
PERFORM get_data_quotation. "Insert by Vijay on 08/02/2011 wrt Ticket T
00797
ENDIF.
ENDMODULE.
" GET_DATA_100 OUTPUT
*&---------------------------------------------------------------------*
*&
Module DISPLAY_DATA_100 OUTPUT
*&---------------------------------------------------------------------*
MODULE display_data_100 OUTPUT.
IF o_container1 IS INITIAL.
CREATE OBJECT o_container1
EXPORTING
container_name = 'CONT1'.
IF sy-subrc = 0.
CREATE OBJECT o_grid1
EXPORTING
i_parent = o_container1.
ENDIF.
IF p_order EQ 'X'.
PERFORM build_fieldcat.
ELSEIF p_qt EQ 'X'.
PERFORM build_fieldcat_quot.
et T00797
ENDIF.

"Insert by Vijay on 08/02/2011 wrt Tick

PERFORM number_of_records.
gs_varaint-report = sy-repid.
gs_layout-grid_title = v_records.

CALL METHOD o_grid1->set_table_for_first_display


EXPORTING
is_variant
= gs_varaint
i_save
= 'A'
i_default
= ' '
is_layout
= gs_layout
CHANGING
it_outtab
= it_final
it_fieldcatalog
= it_fieldcatalog
it_sort
= it_sort
it_filter
=
EXCEPTIONS
invalid_parameter_combination = 1
program_error
= 2
too_many_lines
= 3
OTHERS
= 4

.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
********
* ->Create Object to receive events and link them to handler methods.
* When the ALV Control raises the event
* the corresponding method is automatically called FOR ALL INSTANCES.
* (Complies to their definition as CLASS-METHODS).
*
SET HANDLER lcl_event_receiver=>handle_user_command
lcl_event_receiver=>handle_menu_button
lcl_event_receiver=>handle_double_click
lcl_event_receiver=>handle_toolbar FOR ALL INSTANCES.
*
********
* raise event TOOLBAR:
CALL METHOD o_grid1->set_toolbar_interactive.
ELSE.
* Since new data has been selected, 'grid2' must be refreshed!
CALL METHOD o_grid1->refresh_table_display.
ENDIF.
ENDMODULE.
" DISPLAY_DATA_100 OUTPUT
*&---------------------------------------------------------------------*
*&
Form BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM build_fieldcat .
REFRESH it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'KUNNR'.
wa_fieldcatalog-scrtext_m = 'Sold-to-Party'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'KUNNR1'.
wa_fieldcatalog-scrtext_m = 'Ship-to-Party'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'NAME1'.
wa_fieldcatalog-scrtext_m = 'Ship to Name'.
APPEND wa_fieldcatalog TO it_fieldcatalog.

CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'BSTNK'.
wa_fieldcatalog-scrtext_m = 'PO Number'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'VBELN'.
wa_fieldcatalog-scrtext_m = 'Sales Doc'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'POSNR'.
wa_fieldcatalog-scrtext_m = 'Item'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
*
*
*
*

CLEAR : WA_FIELDCATALOG.
WA_FIELDCATALOG-FIELDNAME = 'ETENR'.
WA_FIELDCATALOG-SCRTEXT_M = 'Schedule line item'.
APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'MATNR'.
wa_fieldcatalog-scrtext_m = 'Material No'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'MAKTX'.
wa_fieldcatalog-scrtext_m = 'Material Description'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'WERKS'.
wa_fieldcatalog-scrtext_m = 'Plant'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'KWMENG'.
wa_fieldcatalog-scrtext_m = 'Order Qty'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'VMENG'.
wa_fieldcatalog-scrtext_m = 'Confirm Qty'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'OMENG'.
wa_fieldcatalog-scrtext_m = 'Open Qty'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'MBDAT'.
wa_fieldcatalog-scrtext_m = 'Req. Del. Date'.

APPEND wa_fieldcatalog TO it_fieldcatalog.


CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'VDATU'.
wa_fieldcatalog-scrtext_m = 'Del. Date'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'CLABS'.
wa_fieldcatalog-scrtext_m = 'Total Stock'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'ACLAB'.
wa_fieldcatalog-scrtext_m = 'Available Stock'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'SCLAB'.
wa_fieldcatalog-scrtext_m = 'Sch. for Del.'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'DVBEL'.
wa_fieldcatalog-scrtext_m = 'Delivery No'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'KPEIN'.
wa_fieldcatalog-scrtext_m = 'Per/Unit'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'NETPR'.
wa_fieldcatalog-scrtext_m = 'Net Price'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'NETWR'.
wa_fieldcatalog-scrtext_m = 'Net Value'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'LGORT'.
wa_fieldcatalog-scrtext_m = 'S Loc'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
IF ok_code = 'BATCH' OR
ok_code IS INITIAL.
* IF P_BATCH = 'X'.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'CHARG'.
wa_fieldcatalog-scrtext_m = 'Batch'.

APPEND wa_fieldcatalog TO it_fieldcatalog.


ENDIF.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'VKORG'.
wa_fieldcatalog-scrtext_m = 'Sales Org'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'VTWEG'.
wa_fieldcatalog-scrtext_m = 'Dist'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'SPART'.
wa_fieldcatalog-scrtext_m = 'Div'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
*
*
*
*
*
*
*
*
*
*
*
*
*
*

CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'KUNNR'.
wa_fieldcatalog-scrtext_m = 'Sold-to-Party'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'KUNNR1'.
wa_fieldcatalog-scrtext_m = 'Ship-to-Party'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'NAME1'.
wa_fieldcatalog-scrtext_m = 'Name'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'BZIRK'.
wa_fieldcatalog-scrtext_m = 'Sales District'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'BRSCH'.
wa_fieldcatalog-scrtext_m = 'Sales Industry'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'BRAN1'.
wa_fieldcatalog-scrtext_m = 'Sales Ind. Code'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'MVGR2'.
wa_fieldcatalog-scrtext_m = 'Manufacturer'.
APPEND wa_fieldcatalog TO it_fieldcatalog.

CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'PRODH'.
wa_fieldcatalog-scrtext_m = 'Prd. Hierarchy'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'ERNAM'.
wa_fieldcatalog-scrtext_m = 'Created By'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
gs_layout-zebra
= 'X'.
gs_layout-cwidth_opt = 'X'.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*

REFRESH IT_SORT.
CLEAR WA_SORT.
WA_SORT-SPOS
WA_SORT-FIELDNAME
WA_SORT-UP
APPEND WA_SORT TO

= 1.
= 'VBELN'.
= 'X'.
IT_SORT.

CLEAR WA_SORT.
WA_SORT-SPOS
WA_SORT-FIELDNAME
WA_SORT-UP
APPEND WA_SORT TO

= 2.
= 'POSNR'.
= 'X'.
IT_SORT.

CLEAR WA_SORT.
WA_SORT-SPOS
WA_SORT-FIELDNAME
WA_SORT-UP
APPEND WA_SORT TO

= 3.
= 'ETENR'.
= 'X'.
IT_SORT.

CLEAR WA_SORT.
WA_SORT-SPOS
WA_SORT-FIELDNAME
WA_SORT-UP
APPEND WA_SORT TO

= 4.
= 'MATNR'.
= 'X'.
IT_SORT.

ENDFORM.
" BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'EXIT'.
PERFORM exit_program.
WHEN 'BACK'.
SET SCREEN 0.
LEAVE SCREEN.

WHEN 'CANC'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
" USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*&
Module FORMULATE_DATA OUTPUT
*&---------------------------------------------------------------------*
MODULE formulate_data OUTPUT.
IF p_order EQ 'X'.
PERFORM fill_final_table.
ELSEIF p_qt EQ 'X'.
PERFORM fill_final_table_quot.
et T00797
ENDIF.
ENDMODULE.

"Insert by Vijay on 08/02/2011 wrt Tick

" FORMULATE_DATA

OUTPUT

*&---------------------------------------------------------------------*
*&
Form FILL_FINAL_TABLE
*&---------------------------------------------------------------------*
FORM fill_final_table .
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*

REFRESH : it_d_tot, it_tot, it_final.


it_vbbe1[] = it_vbbe[].
APPEND LINES OF it_vbbe2 TO it_vbbe1.
LOOP AT it_vbbe.
IF it_vbbe-vbtyp = 'C'.
MOVE-CORRESPONDING it_vbbe TO it_tot.
COLLECT it_tot.
ENDIF.
ENDLOOP.
LOOP AT it_vbbe2.
MOVE-CORRESPONDING it_vbbe2 TO it_d_tot.
COLLECT it_d_tot.
ENDLOOP.
SORT: it_vbbe
it_mara
it_vbep
it_vbbe1
it_kna1
it_vbak
it_knvv
it_mchb
it_vbpa

BY
BY
BY
BY
BY
BY
BY
BY
BY

vbeln posnr etenr mbdat,


matnr,
vbeln posnr etenr,
vbeln posnr mbdat,
kunnr,
vbeln,
kunnr vkorg vtweg spart,
matnr werks charg,
vbeln posnr.

LOOP AT it_vbbe.
CLEAR: wa_final, v_flag_p,v_lfimg .

*
LOOP AT it_lips WHERE vgbel = it_vbbe-vbeln
*
AND vgpos = it_vbbe-posnr.
*
*
CLEAR it_vbbe1 .
*
READ TABLE it_vbbe1 WITH KEY vbeln = it_lips-vbeln
*
posnr = it_lips-posnr.
*
IF sy-subrc = 0.
*
MOVE: it_lips-vbeln TO wa_final-dvbel.
*
v_lfimg = v_lfimg + it_lips-lfimg.
*
ENDIF.
*
*
ENDLOOP.
*
*
MOVE: v_lfimg TO wa_final-sclab.
*
*
IF NOT ok_code IS INITIAL.
*
READ TABLE it_mara WITH KEY matnr = it_vbbe-matnr BINARY SEARCH.
*
IF sy-subrc = 0.
*
IF ok_code = 'NON_BATCH'.
*
CHECK it_mara-xchpf = ' '.
*
ELSEIF ok_code = 'BATCH'.
*
CHECK it_mara-xchpf = 'X'.
*
ENDIF.
*
ENDIF.
*
ENDIF.
*
*
MOVE: it_vbbe-vbeln TO wa_final-vbeln,
*
it_vbbe-posnr TO wa_final-posnr,
*
it_vbbe-matnr TO wa_final-matnr,
*
it_vbbe-charg TO wa_final-charg,
*
it_vbbe-etenr TO wa_final-etenr,
*
it_vbbe-werks TO wa_final-werks,
*
it_vbbe-omeng TO wa_final-omeng.
**
IT_VBBE-VMENG TO WA_FINAL-VMENG.
*
*
IF it_vbbe-omeng > 0.
"Open Qty in St
ockkeeping
*
READ TABLE it_vbep WITH KEY vbeln = it_vbbe-vbeln
*
posnr = it_vbbe-posnr
*
etenr = it_vbbe-etenr BINARY SEARCH.
*
IF sy-subrc = 0.
*
MOVE it_vbep-edatu TO wa_final-mbdat.
*
ENDIF.
*
ENDIF.
**
break mtsvsukhavas.
*
*
CLEAR it_vbak .
*
READ TABLE it_vbak WITH KEY vbeln = it_vbbe-vbeln BINARY SEARCH.
*
IF sy-subrc = 0.
*
CHECK it_vbak-kunnr IN s_kunnr.
*
MOVE: it_vbak-vkorg TO wa_final-vkorg,
*
it_vbak-vtweg TO wa_final-vtweg,
*
it_vbak-spart TO wa_final-spart,

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

it_vbak-kunnr TO wa_final-kunnr,
it_vbak-ernam TO wa_final-ernam.
ENDIF.
CLEAR it_kna1 .
READ TABLE it_kna1 WITH KEY kunnr = it_vbak-kunnr BINARY SEARCH.
IF sy-subrc = 0.
MOVE: it_kna1-brsch TO wa_final-brsch,
it_kna1-bran1 TO wa_final-bran1.
ENDIF.
CLEAR it_vbpa.
READ TABLE it_vbpa WITH KEY vbeln = it_vbbe-vbeln
posnr = it_vbbe-posnr BINARY SEARCH.
IF sy-subrc = 0.
MOVE: it_vbpa-kunnr TO wa_final-kunnr1.
ELSE.
CLEAR it_vbpa.
READ TABLE it_vbpa WITH KEY vbeln = it_vbbe-vbeln.
IF sy-subrc = 0.
MOVE: it_vbpa-kunnr TO wa_final-kunnr1.
ENDIF.
ENDIF.
CLEAR it_kna1 .
READ TABLE it_knvv WITH KEY kunnr = it_vbak-kunnr
vkorg = it_vbak-vkorg
vtweg = it_vbak-vtweg
spart = it_vbak-spart BINARY SEARCH.
IF sy-subrc = 0.
MOVE: it_knvv-bzirk TO wa_final-bzirk.
ENDIF.
CLEAR it_kna1 .
READ TABLE it_mvke WITH KEY matnr = it_vbbe-matnr
vkorg = it_vbak-vkorg
vtweg = it_vbak-vtweg.
IF sy-subrc = 0.
MOVE: it_mvke-mvgr2 TO wa_final-mvgr2,
it_mvke-prodh TO wa_final-prodh.
ENDIF.
CLEAR it_vbap .
READ TABLE it_vbap WITH KEY vbeln = it_vbbe-vbeln
posnr = it_vbbe-posnr.
IF sy-subrc = 0.
IF wa_final-omeng > 0.
MOVE : it_vbap-netpr TO wa_final-netpr,
it_vbap-netwr TO wa_final-netwr.
ENDIF.
MOVE: it_vbap-kwmeng TO wa_final-kwmeng,
"Order Qty
it_vbap-kpein TO wa_final-kpein.
"Condition Pricing Un

it
*
ENDIF.
*
***Material text
*
CLEAR it_makt .
*
READ TABLE it_makt WITH KEY matnr = it_vbbe-matnr.
*
IF sy-subrc = 0.
*
MOVE it_makt-maktx TO wa_final-maktx.
*
ENDIF.
** break mtsvsukhavas.
***Shi-to_party
*
IF it_vbbe-charg IS INITIAL.
*
READ TABLE it_mard WITH KEY matnr = it_vbbe-matnr
*
werks = it_vbbe-werks.
*
IF sy-subrc = 0.
*
MOVE: it_mard-lgort TO wa_final-lgort,
*
it_mard-labst TO wa_final-clabs.
**
WA_FINAL-ACLAB = IT_MARD-LABST - WA_FINAL-VMENG - IT_LIPS-LFIMG.
*
ENDIF.
*
*
CLEAR it_tot.
*
READ TABLE it_tot WITH KEY matnr = it_vbbe-matnr
*
werks = it_vbbe-werks.
*
IF sy-subrc = 0.
*
CLEAR it_d_tot.
*
READ TABLE it_d_tot WITH KEY matnr = it_vbbe-matnr
*
werks = it_vbbe-werks.
*
*
wa_final-aclab = it_mard-labst - it_d_tot-vmeng.
*
*
ENDIF.
*
ELSE.
*
CLEAR it_mchb.
*
READ TABLE it_mchb WITH KEY matnr = it_vbbe-matnr
*
werks = it_vbbe-werks
*
charg = it_vbbe-charg BINARY SEARCH.
*
IF sy-subrc = 0.
*
MOVE: it_mchb-clabs TO wa_final-clabs,
*
it_mchb-lgort TO wa_final-lgort.
*
wa_final-aclab = it_mchb-clabs - wa_final-vmeng.
*
ENDIF.
*
ENDIF.
*
*
READ TABLE it_kna1 WITH KEY kunnr = it_vbpa-kunnr.
*
*
IF sy-subrc = 0.
*
MOVE:it_kna1-name1 TO wa_final-name1.
*
ENDIF.
*
*
LOOP AT it_vbep WHERE vbeln = it_vbbe-vbeln
*
AND posnr = it_vbbe-posnr
*
AND bmeng > 0.
*
wa_final-vmeng = wa_final-vmeng + it_vbep-bmeng.
"Confirmed qty

*
ENDLOOP.
***************
*
CLEAR v_flag.
*
LOOP AT it_vbbe1 WHERE vbeln = it_vbbe-vbeln
*
AND posnr = it_vbbe-posnr.
*
IF it_vbbe1-vmeng > 0 AND
*
it_vbbe1-omeng > 0.
*
v_flag = 'X'.
*
MOVE: it_vbbe1-omeng TO wa_final-omeng,
*
it_vbbe1-mbdat TO wa_final-mbdat.
*
DELETE it_vbbe1 WHERE vbeln = it_vbbe1-vbeln
*
AND posnr = it_vbbe1-posnr
*
AND etenr = it_vbbe1-etenr.
*
*
DELETE it_vbbe WHERE vbeln = it_vbbe1-vbeln
*
AND posnr = it_vbbe1-posnr
*
AND etenr = it_vbbe1-etenr.
*
*
ELSEIF it_vbbe1-vmeng = 0.
*
v_flag = 'X'.
*
MOVE: it_vbbe1-omeng TO wa_final-omeng.
*
*
READ TABLE it_vbep WITH KEY vbeln = it_vbbe-vbeln
*
posnr = it_vbbe-posnr
*
etenr = 1.
*
IF sy-subrc = 0.
*
MOVE: it_vbep-edatu TO wa_final-mbdat.
*
*
ENDIF.
*
DELETE it_vbbe1 WHERE vbeln = it_vbbe1-vbeln
*
AND posnr = it_vbbe1-posnr
*
AND etenr = it_vbbe1-etenr.
*
*
DELETE it_vbbe WHERE vbeln = it_vbbe1-vbeln
*
AND posnr = it_vbbe1-posnr
*
AND etenr = it_vbbe1-etenr.
*
CONTINUE.
*
ENDIF.
*
*
IF v_flag = ' '.
*
MOVE: it_vbbe1-omeng TO wa_final-omeng,
*
it_vbbe1-mbdat TO wa_final-mbdat.
*
ENDIF.
*
*
CLEAR it_vbep.
*
READ TABLE it_vbep WITH KEY vbeln = it_vbbe1-vbeln
*
posnr = it_vbbe1-posnr
*
etenr = it_vbbe1-etenr.
*
IF sy-subrc = 0.
*
MOVE it_vbep-edatu TO wa_final-vdatu.
*
ENDIF.
*
*
APPEND wa_final TO it_final.

*
v_flag_p = 'X'.
*
CLEAR:wa_final-kwmeng, wa_final-omeng, wa_final-mbdat, wa_finalvmeng.
*
DELETE it_vbbe1 WHERE vbeln = it_vbbe1-vbeln
*
AND posnr = it_vbbe1-posnr
*
AND etenr = it_vbbe1-etenr.
*
*
DELETE it_vbbe WHERE vbeln = it_vbbe1-vbeln
*
AND posnr = it_vbbe1-posnr
*
AND etenr = it_vbbe1-etenr.
*
ENDLOOP.
*******************
*
IF v_flag_p = ' '.
*
APPEND wa_final TO it_final.
*
ENDIF.
* ENDLOOP.
*
* SORT it_final BY vbeln posnr etenr matnr.
*
** Start of insert by Vijay on 10/02/2011 wrt Ticket # T00797
*
** To delete open/close records based on the user selection
* IF p_open = 'X'.
*
LOOP AT it_vbup WHERE gbsta = 'C'.
*
DELETE it_final WHERE vbeln = it_vbup-vbeln AND posnr = it_vbupposnr.
*
ENDLOOP.
* ELSEIF p_close = 'X'.
*
LOOP AT it_vbuk WHERE gbstk <> 'C'.
*
DELETE it_final WHERE vbeln = it_vbuk-vbeln.
*
ENDLOOP.
* ENDIF.
*
** To display total number of records at the top of the list
* IF NOT it_final[] IS INITIAL.
*
CLEAR v_lines.
*
DESCRIBE TABLE it_final LINES v_lines.
* ENDIF.
*
** End of insert by Vijay on 10/02/2011 wrt Ticket # T00797

REFRESH : it_d_tot, it_tot, it_final.


it_vbbe1[] = it_vbbe[].
APPEND LINES OF it_vbbe2 TO it_vbbe1.
SORT: it_vbbe
it_mara
it_vbep
it_vbbe1
it_kna1

BY
BY
BY
BY
BY

vbeln posnr etenr mbdat,


matnr,
vbeln posnr etenr,
vbeln posnr mbdat,
kunnr,

it_vbak
it_knvv
it_mchb
it_vbpa

BY
BY
BY
BY

vbeln,
kunnr vkorg vtweg spart,
matnr werks charg,
vbeln posnr.

LOOP AT it_vbbe WHERE


IF it_vbbe-vbtyp =
MOVE: it_vbbe-matnr
it_vbbe-werks
it_vbbe-lgort
it_vbbe-omeng
it_vbbe-vmeng
COLLECT it_tot.
*
ENDIF.
ENDLOOP.

vbtyp = 'C'.
'C'.
TO it_tot-matnr,
TO it_tot-werks,
TO it_tot-lgort,
TO it_tot-omeng,
TO it_tot-vmeng.

LOOP AT it_vbbe2.
MOVE: it_vbbe2-matnr
it_vbbe2-werks
it_vbbe2-lgort
it_vbbe2-omeng
it_vbbe2-vmeng
COLLECT it_d_tot.
ENDLOOP.

TO
TO
TO
TO
TO

it_d_tot-matnr,
it_d_tot-werks,
it_d_tot-lgort,
it_d_tot-omeng,
it_d_tot-vmeng.

DELETE it_vbap WHERE abgru IS NOT INITIAL OR posar IS NOT INITIAL.


LOOP AT it_vbap.
*

IF it_vbap-abgru IS INITIAL.
CLEAR: wa_final, v_flag_p, v_lfimg, v_check.

*
*
*
*
*
*
*
*
*

CLEAR it_mara.
READ TABLE it_mara WITH KEY matnr = it_vbap-matnr.
IF sy-subrc = 0.
IF it_mara-xchpf EQ 'X' AND it_vbap-posar NE ''.
v_check = 'X'.
ELSEIF it_mara-xchpf EQ '' AND it_vbap-posar NE ''.
v_check = 'X'.
ENDIF.
ENDIF.

IF NOT v_check EQ 'X'.


MOVE: it_vbap-vbeln
it_vbap-posnr
it_vbap-matnr
it_vbap-charg
it_vbap-werks
it_vbap-netpr
it_vbap-netwr
it_vbap-kwmeng

TO
TO
TO
TO
TO
TO
TO
TO

wa_final-vbeln,
wa_final-posnr,
wa_final-matnr,
wa_final-charg,
wa_final-werks,
wa_final-netpr,
wa_final-netwr,
wa_final-kwmeng,

"Sales Document
"Item
"Material
"Batch
"Plant
"Net Price
"Net Value
"Order Qty

it_vbap-kpein

TO wa_final-kpein.

"Condition Pricing Unit

CLEAR it_vbup.
READ TABLE it_vbup WITH KEY vbeln = it_vbap-vbeln
posnr = it_vbap-posnr.
IF sy-subrc = 0.
MOVE it_vbup-gbsta TO wa_final-gbsta.
ENDIF.
LOOP AT it_lips WHERE vgbel = it_vbap-vbeln
AND
vgpos = it_vbap-posnr
AND
lfimg > 0.
MOVE: it_lips-vbeln TO wa_final-dvbel.
CLEAR it_vbbe1 .
READ TABLE it_vbbe1 WITH KEY vbeln = it_lips-vbeln
posnr = it_lips-posnr.
IF sy-subrc = 0.
v_lfimg = v_lfimg + it_lips-lfimg.
ENDIF.
ENDLOOP.
MOVE: v_lfimg TO wa_final-sclab.
IF NOT ok_code IS INITIAL.
READ TABLE it_mara WITH KEY matnr = it_vbap-matnr BINARY SEARCH.
IF sy-subrc = 0.
IF ok_code = 'NON_BATCH'.
CHECK it_mara-xchpf = ' '.
ELSEIF ok_code = 'BATCH'.
CHECK it_mara-xchpf = 'X'.
ENDIF.
ENDIF.
ENDIF.
CLEAR it_vbbe.
READ TABLE it_vbbe WITH KEY vbeln = it_vbap-vbeln
posnr = it_vbap-posnr.
IF sy-subrc = 0.
MOVE: it_vbbe-omeng TO wa_final-omeng,
it_vbbe-etenr TO wa_final-etenr.
ENDIF.
IF it_vbap-charg IS INITIAL.
CLEAR it_mard.
READ TABLE it_mard WITH KEY matnr = it_vbap-matnr
werks = it_vbap-werks.
IF sy-subrc = 0.
MOVE: it_mard-lgort TO wa_final-lgort,
it_mard-labst TO wa_final-clabs.

ENDIF.
CLEAR it_tot.
READ TABLE it_tot WITH KEY matnr = it_vbap-matnr
werks = it_vbap-werks.
IF sy-subrc = 0.
CLEAR it_d_tot.
READ TABLE it_d_tot WITH KEY matnr = it_vbap-matnr
werks = it_vbap-werks.
IF sy-subrc = 0.
wa_final-aclab = it_mard-labst - it_d_tot-vmeng.
ENDIF.
ENDIF.
ELSE.
CLEAR it_mchb.
READ TABLE it_mchb WITH KEY matnr = it_vbap-matnr
werks = it_vbap-werks
charg = it_vbap-charg BINARY SEARCH.
IF sy-subrc = 0.
MOVE: it_mchb-clabs TO wa_final-clabs,
it_mchb-lgort TO wa_final-lgort.
wa_final-aclab = it_mchb-clabs - wa_final-vmeng.
ENDIF.
ENDIF.
LOOP AT it_vbep WHERE vbeln = it_vbap-vbeln
AND
posnr = it_vbap-posnr.
IF

it_vbep-wmeng GT 0 AND it_vbep-bmeng EQ 0 AND it_vbep-etenr E

MOVE
ELSEIF

it_vbep-edatu TO wa_final-mbdat.
it_vbep-wmeng EQ 0 AND it_vbep-bmeng GT 0 AND it_vbep-etenr G

MOVE
ELSEIF

it_vbep-edatu TO wa_final-vdatu.
it_vbep-wmeng GT 0 AND it_vbep-bmeng GT 0 AND it_vbep-etenr E

Q 1.

T 1.

Q 1.
MOVE: it_vbep-edatu TO wa_final-vdatu,
it_vbep-edatu TO wa_final-mbdat.
ENDIF.
wa_final-vmeng = wa_final-vmeng + it_vbep-bmeng.

"Confirmed qty

ENDLOOP.
IF wa_final-dvbel IS INITIAL.
CLEAR wa_final-vdatu.
ENDIF.
CLEAR it_vbak .
READ TABLE it_vbak WITH KEY vbeln = it_vbap-vbeln BINARY SEARCH.

IF sy-subrc = 0.
CHECK it_vbak-kunnr IN
MOVE: it_vbak-vkorg TO
it_vbak-vtweg TO
it_vbak-spart TO
it_vbak-bstnk TO
it_vbak-kunnr TO
it_vbak-ernam TO

s_kunnr.
wa_final-vkorg,
wa_final-vtweg,
wa_final-spart,
wa_final-bstnk,
wa_final-kunnr,
wa_final-ernam.

CLEAR it_kna1 .
READ TABLE it_kna1 WITH KEY kunnr = it_vbak-kunnr BINARY SEARCH.
IF sy-subrc = 0.
MOVE: it_kna1-brsch TO wa_final-brsch,
it_kna1-bran1 TO wa_final-bran1.
ENDIF.
CLEAR it_knvv .
READ TABLE it_knvv WITH KEY kunnr = it_vbak-kunnr
vkorg = it_vbak-vkorg
vtweg = it_vbak-vtweg
spart = it_vbak-spart BINARY SEARCH.
IF sy-subrc = 0.
MOVE: it_knvv-bzirk TO wa_final-bzirk.
ENDIF.
CLEAR it_mvke .
READ TABLE it_mvke WITH KEY matnr = it_vbap-matnr
vkorg = it_vbak-vkorg
vtweg = it_vbak-vtweg.
IF sy-subrc = 0.
MOVE: it_mvke-mvgr2 TO wa_final-mvgr2,
it_mvke-prodh TO wa_final-prodh.
ENDIF.
ENDIF.
CLEAR it_vbpa.
READ TABLE it_vbpa WITH KEY vbeln = it_vbap-vbeln
posnr = it_vbap-posnr
parvw = 'WE' BINARY SEARCH.
IF sy-subrc = 0.
MOVE: it_vbpa-kunnr TO wa_final-kunnr1.
CLEAR it_kna1.
READ TABLE it_kna1 WITH KEY kunnr = it_vbpa-kunnr.
IF sy-subrc = 0.
MOVE:it_kna1-name1 TO wa_final-name1.
ENDIF.
ELSE.

CLEAR it_vbpa.
READ TABLE it_vbpa WITH KEY vbeln = it_vbap-vbeln
parvw = 'WE'.
IF sy-subrc = 0.
MOVE: it_vbpa-kunnr TO wa_final-kunnr1.
CLEAR it_kna1.
READ TABLE it_kna1 WITH KEY kunnr = it_vbpa-kunnr.
IF sy-subrc = 0.
MOVE:it_kna1-name1 TO wa_final-name1.
ENDIF.
ENDIF.
ENDIF.
**Material text
CLEAR it_makt .
READ TABLE it_makt WITH KEY matnr = it_vbap-matnr.
IF sy-subrc = 0.
MOVE it_makt-maktx TO wa_final-maktx.
ENDIF.
*
*
*
*
*

*
*

LOOP AT it_vbep WHERE vbeln = it_vbap-vbeln


AND
posnr = it_vbap-posnr
AND
bmeng > 0.
wa_final-vmeng = wa_final-vmeng + it_vbep-bmeng.
ENDLOOP.
CLEAR v_flag.
LOOP AT it_vbbe1

WHERE
AND

vbeln = it_vbap-vbeln
posnr = it_vbap-posnr.

READ TABLE it_vbbe1 WITH KEY vbeln = it_vbap-vbeln


posnr = it_vbap-posnr.
IF sy-subrc = 0.
IF it_vbbe1-vmeng > 0 AND
it_vbbe1-omeng > 0.
v_flag = 'X'.

MOVE: it_vbbe1-omeng TO wa_final-omeng.


it_vbbe1-mbdat TO wa_final-mbdat.
DELETE it_vbbe1 WHERE vbeln = it_vbbe1-vbeln
AND
posnr = it_vbbe1-posnr
AND
etenr = it_vbbe1-etenr.
DELETE it_vbbe

WHERE vbeln = it_vbbe1-vbeln


AND
posnr = it_vbbe1-posnr
AND
etenr = it_vbbe1-etenr.

"Confirmed qty

ELSEIF it_vbbe1-vmeng = 0.
v_flag = 'X'.
MOVE: it_vbbe1-omeng TO wa_final-omeng.
DELETE it_vbbe1 WHERE vbeln = it_vbbe1-vbeln
AND
posnr = it_vbbe1-posnr
AND
etenr = it_vbbe1-etenr.
DELETE it_vbbe

WHERE vbeln = it_vbbe1-vbeln


AND
posnr = it_vbbe1-posnr
AND
etenr = it_vbbe1-etenr.

CONTINUE.
ENDIF.

IF v_flag = ' '.


MOVE: it_vbbe1-omeng TO wa_final-omeng.
it_vbbe1-mbdat TO wa_final-mbdat.
ENDIF.
APPEND wa_final TO it_final.
v_flag_p

= 'X'.

CLEAR:wa_final-kwmeng, wa_final-omeng, wa_final-vmeng.


DELETE it_vbbe1 WHERE vbeln = it_vbbe1-vbeln
AND
posnr = it_vbbe1-posnr
AND
etenr = it_vbbe1-etenr.
DELETE it_vbbe

WHERE vbeln = it_vbbe1-vbeln


AND
posnr = it_vbbe1-posnr
AND
etenr = it_vbbe1-etenr.

ENDIF.
*
ENDLOOP.
******************
IF v_flag_p = ' '.
APPEND wa_final TO it_final.
ENDIF.
*

ENDIF.

ENDIF.
ENDLOOP.
SORT it_final BY vbeln posnr etenr matnr.

* Start of insert by Vijay on 10/02/2011 wrt Ticket # T00797

* To delete open/close records based on the user selection


IF p_open = 'X'.
DELETE it_final WHERE gbsta EQ 'C' OR gbsta EQ ''.
ELSEIF p_close = 'X'.
DELETE it_final WHERE gbsta NE 'C' AND gbsta NE ''.
ENDIF.
* End of insert by Vijay on 10/02/2011 wrt Ticket # T00797
ENDFORM.
" FILL_FINAL_TABLE
*&---------------------------------------------------------------------*
*&
Module DISPLAY_DATA_200 OUTPUT
*&---------------------------------------------------------------------*
MODULE display_data_200 OUTPUT.
IF o_container2 IS INITIAL.
CREATE OBJECT o_container2
EXPORTING
container_name = 'CONT2'.
IF sy-subrc = 0.
CREATE OBJECT o_grid2
EXPORTING
i_parent = o_container2.
ENDIF.
IF p_order EQ 'X'.
PERFORM build_fieldcat.
ELSEIF p_qt EQ 'X'.
PERFORM build_fieldcat_quot.
ENDIF.
gs_varaint-report = sy-repid.

CALL METHOD o_grid2->set_table_for_first_display


EXPORTING
is_variant
= gs_varaint
i_save
= 'A'
i_default
= ' '
is_layout
= gs_layout
CHANGING
it_outtab
= it_final
it_fieldcatalog
= it_fieldcatalog
it_sort
= it_sort
it_filter
=
EXCEPTIONS
invalid_parameter_combination = 1
program_error
= 2
too_many_lines
= 3
OTHERS
= 4
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.


ENDIF.
* raise event TOOLBAR:
CALL METHOD o_grid2->set_toolbar_interactive.
ELSE.
* Since new data has been selected, 'grid2' must be refreshed!
CALL METHOD o_grid2->refresh_table_display.
ENDIF.
ENDMODULE.
" DISPLAY_DATA_200 OUTPUT
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0200 INPUT.
CASE ok_code.
WHEN 'EXIT'.
PERFORM exit_program.
WHEN 'BACK'.
SET SCREEN 0.
LEAVE SCREEN.
WHEN 'CANC'.
LEAVE PROGRAM.
ENDCASE.
ok_code = 'NON_BATCH'.
ENDMODULE.
" USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
*&
Form EXIT_PROGRAM
*&---------------------------------------------------------------------*
FORM exit_program .
CALL METHOD o_container1->free.
IF NOT o_container2 IS INITIAL.
CALL METHOD o_container2->free.
ENDIF.
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc NE 0.
* add your handling, for example
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid
txt2 = sy-subrc
txt1 = 'Error in Flush'(500).
ENDIF.
LEAVE PROGRAM.
ENDFORM.
" EXIT_PROGRAM
*&---------------------------------------------------------------------*

*&
Form GET_DATA_ORDER
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM get_data_order .
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*

SELECT vbeln posnr etenr matnr werks lgort


vbtyp mbdat omeng vmeng charg
INTO TABLE it_vbbe
FROM vbbe
WHERE vbeln IN s_vbeln
AND matnr IN s_matnr
AND werks IN s_werks
AND mbdat IN s_mbdat
AND vbtyp = 'C'.
IF NOT it_vbbe[] IS INITIAL.
SELECT vbeln gbstk
FROM vbuk
INTO TABLE it_vbuk
FOR ALL ENTRIES IN it_vbbe
WHERE vbeln = it_vbbe-vbeln.
SELECT vbeln posnr lfsta gbsta
FROM vbup
INTO TABLE it_vbup
FOR ALL ENTRIES IN it_vbbe
WHERE vbeln = it_vbbe-vbeln
AND posnr = it_vbbe-posnr.
SELECT vbeln posnr etenr matnr werks lgort
vbtyp mbdat omeng vmeng charg
INTO TABLE it_vbbe2
FROM vbbe
WHERE matnr IN s_matnr
AND werks IN s_werks
AND vbtyp = 'J'.
SELECT vbeln posnr etenr edatu wmeng bmeng
INTO TABLE it_vbep
FROM vbep
FOR ALL ENTRIES IN it_vbbe
WHERE vbeln = it_vbbe-vbeln
AND posnr = it_vbbe-posnr.
SELECT vbeln netwr vkorg vtweg
spart vdatu kunnr ernam
INTO TABLE it_vbak
FROM vbak

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

FOR ALL ENTRIES IN it_vbbe


WHERE vbeln = it_vbbe-vbeln.
SELECT vbeln posnr matnr kwmeng werks
vstel charg lgort netpr netwr kpein
INTO TABLE it_vbap
FROM vbap
FOR ALL ENTRIES IN it_vbbe
WHERE vbeln = it_vbbe-vbeln
AND posnr = it_vbbe-posnr.
SELECT matnr maktx
INTO TABLE it_makt
FROM makt
FOR ALL ENTRIES IN it_vbbe
WHERE matnr = it_vbbe-matnr
AND spras = sy-langu.
SELECT matnr werks charg lgort clabs
INTO TABLE it_mchb
FROM mchb
FOR ALL ENTRIES IN it_vbbe
WHERE matnr = it_vbbe-matnr
AND werks = it_vbbe-werks.
SELECT matnr werks lgort labst
INTO TABLE it_mard
FROM mard
FOR ALL ENTRIES IN it_vbbe
WHERE matnr = it_vbbe-matnr
AND werks = it_vbbe-werks.
SELECT matnr xchpf
INTO TABLE it_mara
FROM mara
FOR ALL ENTRIES IN it_vbbe
WHERE matnr = it_vbbe-matnr.
SELECT vbeln posnr parvw kunnr
FROM vbpa
INTO TABLE it_vbpa
FOR ALL ENTRIES IN it_vbbe
WHERE vbeln = it_vbbe-vbeln
AND parvw = 'WE'.
SELECT vbeln posnr vgbel vgpos lfimg
FROM lips
INTO TABLE it_lips
FOR ALL ENTRIES IN it_vbbe
WHERE vgbel = it_vbbe-vbeln
AND vgpos = it_vbbe-posnr.
ENDIF.

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

IF NOT it_lips[] IS INITIAL.


SELECT * FROM
shp_idx_gdsi
INTO TABLE it_shp_idx_gdsi
FOR ALL ENTRIES IN it_lips
WHERE vbeln = it_lips-vbeln.
SELECT * FROM
shp_idx_pick
INTO TABLE it_shp_idx_pick
FOR ALL ENTRIES IN it_lips
WHERE vbeln = it_lips-vbeln.
ENDIF.
IF NOT it_vbak[] IS INITIAL.
SELECT kunnr vkorg vtweg spart bzirk
INTO TABLE it_knvv
FROM knvv
FOR ALL ENTRIES IN it_vbak
WHERE kunnr = it_vbak-kunnr
AND vkorg = it_vbak-vkorg
AND vtweg = it_vbak-vtweg
AND spart = it_vbak-spart.
SELECT kunnr name1 brsch bran1
INTO TABLE it_kna1
FROM kna1.
FOR ALL ENTRIES IN IT_VBAK
WHERE KUNNR = IT_VBAK-KUNNR.
SELECT matnr vkorg vtweg mvgr2 prodh
INTO TABLE it_mvke
FROM mvke
FOR ALL ENTRIES IN it_vbak
WHERE vkorg = it_vbak-vkorg
AND vtweg = it_vbak-vtweg.
ENDIF.
CLEAR: it_vbak,
it_vbbe,
it_mara,
it_lips,

it_vbap, it_knvv, it_kna1, it_mvke,


it_vbuk, it_vbup, it_vbep, it_vbbe2,
it_mard, it_makt, it_mchb, it_vbpa,
it_shp_idx_gdsi, it_shp_idx_pick.

REFRESH: it_vbak,
it_vbbe,
it_mara,
it_lips,

it_vbap, it_knvv, it_kna1, it_mvke,


it_vbuk, it_vbup, it_vbep, it_vbbe2,
it_mard, it_makt, it_mchb, it_vbpa,
it_shp_idx_gdsi, it_shp_idx_pick.

IF NOT p_auart IS INITIAL.

IF NOT s_shipto[] IS INITIAL.


SELECT

vbeln posnr
parvw kunnr
FROM
vbpa
INTO TABLE it_vbpa
WHERE vbeln IN s_vbeln
AND
kunnr IN s_shipto.
IF NOT it_vbpa[] IS INITIAL.
SELECT vbeln ernam
netwr vkorg
vtweg spart
vdatu bstnk
kunnr
FROM
vbak
INTO TABLE it_vbak
FOR ALL ENTRIES IN it_vbpa
WHERE
vbeln = it_vbpa-vbeln
AND
erdat IN s_mbdat
AND
vbtyp = 'C'
AND
auart IN s_auart
AND
bstnk IN s_bstnk
AND
kunnr IN s_kunnr.
ENDIF.
ELSE.
SELECT

vbeln
netwr
vtweg
vdatu
kunnr
FROM vbak
INTO TABLE
WHERE vbeln
AND
erdat
AND
vbtyp
AND
auart
AND
bstnk
AND
kunnr

ernam
vkorg
spart
bstnk

it_vbak
IN s_vbeln
IN s_mbdat
= 'C'
IN s_auart
IN s_bstnk
IN s_kunnr.

ENDIF.
CLEAR it_vbpa.
REFRESH it_vbpa.
*
*
*
*
*
*

ELSE.
SELECT

vbeln
netwr
vtweg
vdatu

ernam
vkorg
spart
bstnk

*
*
*
*
*
*
*
*
*
*

kunnr
vbak
TABLE
vbeln
erdat
vbtyp
bstnk
kunnr

FROM
INTO
WHERE
AND
AND
AND
AND

it_vbak
IN s_vbeln
IN s_mbdat
= 'C'
IN s_bstnk
IN s_kunnr.

ENDIF.
IF NOT it_vbak[] IS INITIAL.
SELECT

vbeln posnr
matnr charg
posar abgru
netwr kwmeng
werks lgort
vstel netpr
kpein
FROM vbap
INTO TABLE it_vbap
FOR ALL ENTRIES IN it_vbak
WHERE vbeln = it_vbak-vbeln
AND
matnr IN s_matnr
AND
werks IN s_werks.

SELECT

kunnr vkorg
vtweg spart
bzirk
FROM knvv
INTO TABLE it_knvv
FOR ALL ENTRIES IN it_vbak
WHERE kunnr = it_vbak-kunnr
AND
vkorg = it_vbak-vkorg
AND
vtweg = it_vbak-vtweg
AND
spart = it_vbak-spart.

SELECT
FROM
INTO
SELECT

*
*
*

kunnr name1
brsch bran1
kna1
TABLE it_kna1.

matnr vkorg
vtweg prodh
mvgr2
FROM mvke
INTO TABLE it_mvke.
FOR ALL ENTRIES IN it_vbak
WHERE vkorg = it_vbak-vkorg
AND
vtweg = it_vbak-vtweg.

ENDIF.

IF NOT it_vbap[] IS INITIAL.


SELECT

vbeln posnr
etenr matnr
werks mbdat
lgort charg
vbtyp omeng
vmeng
FROM vbbe
INTO TABLE it_vbbe
FOR ALL ENTRIES IN it_vbap
WHERE vbeln = it_vbap-vbeln
AND
matnr = it_vbap-matnr
AND
werks = it_vbap-werks.

*
*
*
*
*

SELECT vbeln gbstk


FROM vbuk
INTO TABLE it_vbuk
FOR ALL ENTRIES IN it_vbap
WHERE vbeln = it_vbap-vbeln.
SELECT

vbeln posnr
lfsta gbsta
FROM vbup
INTO TABLE it_vbup
FOR ALL ENTRIES IN it_vbap
WHERE vbeln = it_vbap-vbeln
AND
posnr = it_vbap-posnr.

SELECT

vbeln posnr
etenr matnr
werks mbdat
lgort charg
vbtyp omeng
vmeng
FROM vbbe
INTO TABLE it_vbbe2
FOR ALL ENTRIES IN it_vbap
WHERE matnr = it_vbap-matnr
AND
werks = it_vbap-werks
AND
vbtyp = 'J'.

SELECT

vbeln posnr
etenr edatu
wmeng bmeng
FROM vbep
INTO TABLE it_vbep
FOR ALL ENTRIES IN it_vbap
WHERE vbeln = it_vbap-vbeln
AND
posnr = it_vbap-posnr.

SELECT

matnr maktx

FROM makt
INTO TABLE it_makt
FOR ALL ENTRIES IN it_vbap
WHERE matnr = it_vbap-matnr
AND
spras = sy-langu.
SELECT

matnr werks
lgort charg
clabs
FROM mchb
INTO TABLE it_mchb
FOR ALL ENTRIES IN it_vbap
WHERE matnr = it_vbap-matnr
AND
werks = it_vbap-werks.

SELECT

matnr werks
lgort labst
FROM mard
INTO TABLE it_mard
FOR ALL ENTRIES IN it_vbap
WHERE matnr = it_vbap-matnr
AND
werks = it_vbap-werks.

SELECT matnr xchpf


FROM mara
INTO TABLE it_mara
FOR ALL ENTRIES IN it_vbap
WHERE matnr = it_vbap-matnr.
SELECT

vbeln posnr
parvw kunnr
FROM vbpa
INTO TABLE it_vbpa
FOR ALL ENTRIES IN it_vbap
WHERE vbeln = it_vbap-vbeln
AND
arvw = 'WE'.
SELECT

vbeln posnr
lfimg vgbel
vgpos
FROM lips
INTO TABLE it_lips
FOR ALL ENTRIES IN it_vbap
WHERE vgbel = it_vbap-vbeln
AND
vgpos = it_vbap-posnr.

ENDIF.
IF NOT it_lips[] IS INITIAL.
SELECT * FROM
shp_idx_gdsi

INTO TABLE it_shp_idx_gdsi


FOR ALL ENTRIES IN it_lips
WHERE vbeln = it_lips-vbeln.
SELECT * FROM
shp_idx_pick
INTO TABLE it_shp_idx_pick
FOR ALL ENTRIES IN it_lips
WHERE vbeln = it_lips-vbeln.
ENDIF.
ENDFORM.

" GET_DATA_ORDER

*&---------------------------------------------------------------------*
*&
Form GET_DATA_QUOTATION
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM get_data_quotation .
CLEAR: it_qvbak, it_qvbap, it_knvv, it_kna1, it_qvbpa, it_mvke, it_adrc.
REFRESH: it_qvbak, it_qvbap, it_knvv, it_kna1, it_qvbpa, it_mvke, it_adrc
.
*

IF NOT p_auart IS INITIAL.


IF NOT s_shipto[] IS INITIAL.
SELECT

vbeln posnr
parvw kunnr
adrnr
FROM vbpa
INTO TABLE it_qvbpa
WHERE vbeln IN s_vbeln
AND
kunnr IN s_shipto.
IF NOT it_qvbpa[] IS INITIAL.
SELECT vbeln erdat
ernam angdt
bnddt vbtyp
auart netwr
waerk vkorg
vtweg spart
vdatu bstnk
kunnr
FROM vbak
INTO TABLE it_qvbak
FOR ALL ENTRIES IN it_qvbpa
WHERE vbeln = it_qvbpa-vbeln

AND
AND
AND
AND
AND
ENDIF.

erdat
auart
vbtyp
bstnk
kunnr

IN
IN
=
IN
IN

s_mbdat
s_auart
'B'
s_bstnk
s_kunnr.

ELSE.
SELECT

vbeln
ernam
bnddt
auart
waerk
vtweg
vdatu
kunnr
FROM vbak
INTO TABLE
WHERE vbeln
AND
erdat
AND
auart
AND
vbtyp
AND
bstnk
AND
kunnr

erdat
angdt
vbtyp
netwr
vkorg
spart
bstnk

it_qvbak
IN s_vbeln
IN s_mbdat
IN s_auart
= 'B'
IN s_bstnk
IN s_kunnr.

ENDIF.
CLEAR it_qvbpa.
REFRESH it_qvbpa.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*

ELSE.
SELECT

vbeln
ernam
bnddt
auart
waerk
vtweg
vdatu
kunnr
FROM vbak
INTO TABLE
WHERE vbeln
AND
erdat
AND
vbtyp
AND
bstnk
AND
kunnr

erdat
angdt
vbtyp
netwr
vkorg
spart
bstnk

it_qvbak
IN s_vbeln
IN s_mbdat
= 'B'
IN s_bstnk
IN s_kunnr.

ENDIF.
IF NOT it_qvbak[] IS INITIAL.

SELECT

vbeln posnr
matnr arktx
prodh meins
netwr kwmeng
werks lgort
netpr kpein
FROM vbap
INTO TABLE it_qvbap
FOR ALL ENTRIES IN it_qvbak
WHERE vbeln = it_qvbak-vbeln
AND
matnr IN s_matnr
AND
werks IN s_werks.

SELECT

kunnr vkorg
vtweg spart
bzirk
FROM knvv
INTO TABLE it_knvv
FOR ALL ENTRIES IN it_qvbak
WHERE kunnr = it_qvbak-kunnr.

SELECT

kunnr name1
brsch bran1
FROM kna1
INTO TABLE it_kna1
FOR ALL ENTRIES IN it_qvbak
WHERE kunnr = it_qvbak-kunnr.

SELECT

*
*
*

matnr vkorg
vtweg prodh
mvgr2
FROM mvke
INTO TABLE it_mvke.
FOR ALL ENTRIES IN it_qvbak
WHERE vkorg = it_qvbak-vkorg
AND
vtweg = it_qvbak-vtweg.

ENDIF.
IF NOT it_qvbap[] IS INITIAL.
SELECT

vbeln posnr
parvw kunnr
adrnr
FROM vbpa
INTO TABLE it_qvbpa
FOR ALL ENTRIES IN it_qvbap
WHERE vbeln = it_qvbap-vbeln
AND
posnr = it_qvbap-posnr
AND
parvw = 'WE'.

IF NOT it_qvbpa[] IS INITIAL.

SELECT addrnumber name1


FROM adrc
INTO TABLE it_adrc
FOR ALL ENTRIES IN it_qvbpa
WHERE addrnumber = it_qvbpa-adrnr.
ENDIF.
ENDIF.
ENDFORM.

" GET_DATA_QUOTATION

*&---------------------------------------------------------------------*
*&
Form BUILD_FIELDCAT_QUOT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM build_fieldcat_quot .
REFRESH it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'KUNNR'.
wa_fieldcatalog-scrtext_m = 'Sold-to party'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'KUNNR1'.
wa_fieldcatalog-scrtext_m = 'Ship-to party'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'NAME1'.
wa_fieldcatalog-scrtext_m = 'Ship to Name'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'BSTNK'.
wa_fieldcatalog-scrtext_m = 'PO Number'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'VBELN'.
wa_fieldcatalog-scrtext_m = 'Sales Document'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'POSNR'.
wa_fieldcatalog-scrtext_m = 'Item'.
APPEND wa_fieldcatalog TO it_fieldcatalog.

CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'MATNR'.
wa_fieldcatalog-scrtext_m = 'Material No'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'MAKTX'.
wa_fieldcatalog-scrtext_m = 'Material Description'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'WERKS'.
wa_fieldcatalog-scrtext_m = 'Plant'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'ANGDT'.
wa_fieldcatalog-scrtext_m = 'Valid from Date'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'BNDDT'.
wa_fieldcatalog-scrtext_m = 'Valid to Date'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'KWMENG'.
wa_fieldcatalog-scrtext_m = 'Order Quantity'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'MEINS'.
wa_fieldcatalog-scrtext_m = 'UoM'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'KPEIN'.
wa_fieldcatalog-scrtext_m = 'Per/Unit'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'NETPR'.
wa_fieldcatalog-scrtext_m = 'Net Price'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'WAERK'.
wa_fieldcatalog-scrtext_m = 'Currency'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'NETWR'.

wa_fieldcatalog-scrtext_m = 'Net Value'.


APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'VKORG'.
wa_fieldcatalog-scrtext_m = 'Sales Org'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'VTWEG'.
wa_fieldcatalog-scrtext_m = 'Dist'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'SPART'.
wa_fieldcatalog-scrtext_m = 'Div'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
*
*
*
*
*
*
*
*
*
*
*
*
*
*

CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'KUNNR'.
wa_fieldcatalog-scrtext_m = 'Sold-to party'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'KUNNR1'.
wa_fieldcatalog-scrtext_m = 'Ship-to party'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'NAME1'.
wa_fieldcatalog-scrtext_m = 'Name'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'BZIRK'.
wa_fieldcatalog-scrtext_m = 'Sales District'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'BRSCH'.
wa_fieldcatalog-scrtext_m = 'Sales Industry'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'BRAN1'.
wa_fieldcatalog-scrtext_m = 'Sales Industry Code 1'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'MVGR2'.
wa_fieldcatalog-scrtext_m = 'Manufacturer'.
APPEND wa_fieldcatalog TO it_fieldcatalog.

CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'PRODH'.
wa_fieldcatalog-scrtext_m = 'Product Hierarchy'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR : wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'ERNAM'.
wa_fieldcatalog-scrtext_m = 'Created By'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
gs_layout-zebra
= 'X'.
gs_layout-cwidth_opt = 'X'.
ENDFORM.

" BUILD_FIELDCAT_QUOT

*&---------------------------------------------------------------------*
*&
Form FILL_FINAL_TABLE_QUOT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM fill_final_table_quot .
CLEAR: wa_final, it_qvbap.
REFRESH: it_final.
LOOP AT it_qvbap.
CLEAR wa_final.
MOVE: it_qvbap-vbeln
it_qvbap-posnr
it_qvbap-matnr
it_qvbap-arktx
it_qvbap-werks
it_qvbap-kwmeng
it_qvbap-meins
it_qvbap-prodh
it_qvbap-lgort
it_qvbap-netwr
it_qvbap-netpr
it_qvbap-kpein

TO
TO
TO
TO
TO
TO
TO
TO
TO
TO
TO
TO

wa_final-vbeln,
wa_final-posnr,
wa_final-matnr,
wa_final-maktx,
wa_final-werks,
wa_final-kwmeng,
wa_final-meins,
wa_final-prodh,
wa_final-lgort,
wa_final-netwr,
wa_final-netpr,
wa_final-kpein.

CLEAR it_qvbak.
READ TABLE it_qvbak WITH KEY vbeln = it_qvbap-vbeln.
IF sy-subrc = 0.
MOVE: it_qvbak-ernam
it_qvbak-angdt
it_qvbak-bnddt
it_qvbak-waerk

TO
TO
TO
TO

wa_final-ernam,
wa_final-angdt,
wa_final-bnddt,
wa_final-waerk,

it_qvbak-auart
it_qvbak-vkorg
it_qvbak-vtweg
it_qvbak-spart
it_qvbak-vdatu
it_qvbak-bstnk
it_qvbak-kunnr

TO
TO
TO
TO
TO
TO
TO

wa_final-auart,
wa_final-vkorg,
wa_final-vtweg,
wa_final-spart,
wa_final-vdatu,
wa_final-bstnk,
wa_final-kunnr.

CLEAR it_knvv.
READ TABLE it_knvv WITH KEY kunnr = it_qvbak-kunnr.
IF sy-subrc = 0.
MOVE it_knvv-bzirk TO wa_final-bzirk.
ENDIF.
CLEAR it_kna1.
READ TABLE it_kna1 WITH KEY kunnr = it_qvbak-kunnr.
IF sy-subrc = 0.
MOVE: it_kna1-brsch TO wa_final-brsch,
it_kna1-bran1 TO wa_final-bran1.
ENDIF.
CLEAR it_mvke.
READ TABLE it_mvke WITH KEY matnr = it_qvbap-matnr
vkorg = it_qvbak-vkorg
vtweg = it_qvbak-vtweg.
IF sy-subrc = 0.
MOVE it_mvke-mvgr2 TO wa_final-mvgr2.
ENDIF.
ENDIF.

CLEAR it_qvbpa.
READ TABLE it_qvbpa WITH KEY vbeln = it_qvbap-vbeln
posnr = it_qvbap-posnr
parvw = 'WE'.
IF sy-subrc = 0.
MOVE it_qvbpa-kunnr

TO

wa_final-kunnr1.

CLEAR it_adrc.
READ TABLE it_adrc WITH KEY addrnumber = it_qvbpa-adrnr.
IF sy-subrc = 0.
MOVE it_adrc-name1 TO wa_final-name1.
ENDIF.
ENDIF.
APPEND wa_final TO it_final.
ENDLOOP.
ENDFORM.

" FILL_FINAL_TABLE_QUOT

*&---------------------------------------------------------------------*
*&
Form NUMBER_OF_RECORDS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM number_of_records .
* To display total number of records at the top of the list
CLEAR: v_lines, v_total, v_records.
DESCRIBE TABLE it_final LINES v_lines.
MOVE v_lines TO v_total.
SHIFT v_total LEFT DELETING LEADING space.
CONCATENATE 'Number of Records: ' v_total INTO v_records SEPARATED BY spa
ce.
ENDFORM.

" NUMBER_OF_RECORDS