Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

To improve the system performance of the code

Former Member
0 Kudos

Please help me to improve the system performance of the following program. its very urgent


report zsdr0125
          no standard page heading
*         LINE-SIZE  170                                   " SIR 061880
          line-size  210                                   " SIR 061880
          line-count 58
          message-id zz.

***********************************************************************
** Report header ******************************************************
***********************************************************************
** Report name: Activity Costing Report
** Report id:   RO-01148
** Designed/Coded. Tori Chandler. Reporting Team.
** Date: March 01, 2000.
** Original SIR:  016113
** Application Area: V - Sales & Distribution  (OTC)
** Correction/Transport:  D10K951579
** Description:  It is normal business practice for logistics
**               operations to charge business units for the activity
**               incurred on their behalf.  This is consistent with
**               activity based costing principles between BU and
**               shared resources.  The activities involved are picking
**               storage, shipping and receiving.  The purpose of this
**               report is to provide data for the first 3.
**      QRB2 - 03/13/2000 - Tracy, Antoine, Christian, Tori
** History:
* 06/14/2001 SIR 032383 CTS                             Antoine Dailly
* A plant (WERKS) can have several Distrib points (VSTEL)
* SIGN = 032383
***********************************************************************
* Modification History:
* Date       Modified by  SIR       CTS          Description
*11/14/2001  J.CAMPION   034606   D10K979189  Logistics Activity report
*
* Logistics Activity reports
* We added fields ship to customer and country and we also make another
* total
*
* QRB2 Tracy L. Obrien
***********************************************************************
* Modification History:
* Date       Modified by  SIR       CTS          Description
*11/14/2001  J.CAMPION   37838   D10K982890      Select only
*                                                material type HALB
*
*06/12/2002  T OBrien    38784   D10K988181
*        Allow option to get material weight from Master data or
*        from the delivery.
***********************************************************************
*  Modified by    SIR       CTS                         Date
*  Jim Harwood    42730     D10K993119               10 Oct 2002
*
* Description:  Code amended to default the Goods Issue Date range to
* the previous month.  Also amended to print out the Select Options.
***********************************************************************
*  Modified by    SIR       CTS                         Date
*  Jim Harwood    44381     D10K994598               18 Nov 2002
*
* Description:  Correct date range processing.  APPEND statement added
* so that record is added ot internal table S_WADAT.  Also S_VKORG
* removed as it was NO DISPLAY and nothing was assigned to it. It's use
* in an SQL call may be causing the wrong optimization.
***********************************************************************
*  Modified by    SIR       CTS                         Date
*  Tori Chandler  45567     D10K995875               03 Jan 2003
*
* Description:  Correct reporting of weights for non-pickable items
*    when the Material Master Data radiobutton is selected. Also found
*    from SIR 37838, that material type is hardcoded on the LIPS.  I
*    created a new select option and the person needing the report
*    can control if they want only HALB or all line items.  Also,
*    because of this the delivery weight is obtain from header,
*    changing to accumulate from LIPS to match which lines are selected
*  QRB2:  1/15/2003:  Eileen, Jerome and Tori
***********************************************************************
*{   INSERT         D11K901833                                        1
*  Modified by    Sir             CTS                    Date
*  Sue Kastan    48712/054042    D11K901833         28 Aug, 2003
*  Fix overcounting of records from LIPS
***********************************************************************
*}   INSERT
*---------------------------------------------------------------------*
*  Modified by    SIR       CTS                         Date          *
*  Vijay Andea   061880    D11K918628               04/20/2006        *
*                          D11K946194                                 *
*  Description: Enhence ZSDR0125 Activity Cost Driver Report to allow *
*  Analysis by Product Groupings.                                     *
*---------------------------------------------------------------------*
*}   INSERT
*---------------------------------------------------------------------*
*  Modified by            SIR       CTS                    Date       *
*  Prakash Arunachalam  091510   D11K950288             09/26/2006    *
*                                                                     *
*  Description: Correct Activity Cost report  - material weight       *
*  calculation                                                        *
*---------------------------------------------------------------------*
*  Modified by            SIR       CTS                    Date       *
*  Murali Krishna        301978    D50K903293            01/20/2008
*
*  Description: Improve the system performance of this report and
*               clean-up of code into various form routine
*---------------------------------------------------------------------*

* Table declaration.
tables: likp,    " SD Document: Delivery Header Data
        lips,    " SD document: Delivery: Item data
        vepo,    " SD Document: Shipping Unit Item (Content)
        vekp,    " SD Document: Shipping Unit Header
        knvv,    " Customer Master Sales Data
        kna1,    " General Data in Customer Master            SIR 34606
        marm,    " Units of Measure
        mara,    " Material Master: General Data              SIR 38784
        t001l,   " Stge locs
        t001k,   " Valuation area
        tvswz,   " Shipping Points per Plant
        t134,    " Material types
        z0234.   " Alternative Unit of Measure

*** Selection screen.
selection-screen begin of block b1 with frame title text-001.
parameters:     p_werks  like t001l-werks obligatory memory id wrk.
select-options: s_lgort  for  t001l-lgort,
*               S_VKORG  FOR  TVKO-VKORG NO-DISPLAY ," SIR 34606, 42730
*               S_WADAT  FOR  LIKP-WADAT_IST OBLIGATORY NO-EXTENSION,
                s_wadat  for  likp-wadat_ist no-extension,  " SIR 42730
                s_mtart  for  t134-mtart,                   " SIR 45567
                s_lfart  for  likp-lfart no-display no intervals.
selection-screen skip 2.
selection-screen comment 1(21) text-002.                    " SIR 38784
parameters:     p_delwt  radiobutton group grp1,            " SIR 38784
                p_mstwt  radiobutton group grp1.            " SIR 38784
*--------------------------------------------------*Start of SIR 061880
selection-screen skip 2.
selection-screen comment 1(21) text-006.
parameters:     p_voldl radiobutton group 2,     " Volume from Delivery
                p_volmd radiobutton group 2.  " Volume from Master Data
*-----------------------------------------------------End of SIR 061880
selection-screen end of block b1.
*--------------------------------------------------*Start of SIR 061880
selection-screen begin of block b2 with frame title text-007.
select-options: s_cbuun for knvv-kvgr1 no intervals,      " Customer BU
                s_mbuun for mara-prdha+1(2) no intervals, " Material BU
                s_lobus for mara-prdha+3(3) no intervals,         " LOB
                s_pac1  for mara-prdha+6(3) no intervals.   " PAC1
selection-screen end of block b2.
*----------------------------------------------------*End of SIR 061880
*---Type Declaration for Internal Tables------------------------------*

types: begin of t_likp,
          vbeln      like likp-vbeln,  " delivery
          vstel      like likp-vstel,  " shipping point
          lfart      like likp-lfart,  " delivery type
          vkorg      like likp-vkorg,  " Sales organization
          kunag      like likp-kunag,  " sold-to party
          kunnr      like likp-kunnr,  " ship to party        SIR 34606
          btgew      like likp-btgew,  " Delivery weight
          gewei      like likp-gewei,  " Unit of weight
          anzpk      like likp-anzpk,  " Number of Packages   SIR 61880
          volum      like likp-volum,  " Delivery Volume      SIR 61880
          voleh      like likp-voleh,  " Volume Unit          SIR 61880
          vtwiv      like likp-vtwiv,  " Distribution channel
          spaiv      like likp-spaiv,  " Division
          wadat_ist  like likp-wadat_ist,  " actual goods issue date
          del_flg(1) type c,                            "(+) SIR 301978
       end of t_likp.

types: begin of t_lips,
          vbeln      like lips-vbeln,  " delivery
          posnr      like lips-posnr,  " delivery line
          matnr      like lips-matnr,  " material
          lgort      like lips-lgort,  " storage location
          prodh      like lips-prodh,  " product hierarchy
          meins      like lips-meins,  " base UoM
          brgew      like lips-brgew,  " Material weight
          gewei      like lips-gewei,  " Unit of weight
          volum      like lips-volum,  " Material Volume      SIR 61880
          voleh      like lips-voleh,  " Volume Unit          SIR 61880
          lgmng      like lips-lgmng,  " actual delivery quantity
          komkz      like lips-komkz,  " Indicator for picking control
          mtart      like lips-mtart,  " Material type      " SIR 37838
          del_flg(1) type c,                            "(+) SIR 301978
       end of t_lips.

types: begin of t_vepo,
          venum      like vepo-venum,  " shipping unit number
          vbeln      like vepo-vbeln,  " delivery
       end of t_vepo.

types: begin of t_vekp,
          venum      like vekp-venum,  " shipping unit number
          brgew      like vekp-brgew,  " actual weight
          gewei_max  like vekp-gewei_max,  " unit of weight
          vpobjkey   like vekp-vpobjkey,   " key for assigned object
       end of t_vekp.

types: begin of t_knvv,
          kunnr      like knvv-kunnr,  " customer number
          ktgrd      like knvv-ktgrd,  " acct assign group
          kvgr1      like knvv-kvgr1,  " customer group 1
       end of t_knvv.

types: begin of t_kna1,                                     " SIR 34606
          kunnr      like kna1-kunnr,  " customer number    " SIR 34606
          land1      like kna1-land1,  " contry             " SIR 34606
       end of t_kna1.                                       " SIR 34606

types: begin of t_marm,
          matnr      like marm-matnr,  " material
          meinh      like marm-meinh,  " Alt unit of measure     032383
          umrez      like marm-umrez,  " numerator
          umren      like marm-umren,  " denominator
       end of t_marm.

types: begin of t_mara,                                     " SIR 38784
          matnr      like mara-matnr,  " material           " SIR 38784
          prdha      like mara-prdha,  " Product Hierarchy  " SIR 61880
          brgew      like lips-brgew,  " gross weight       " SIR 38784
          gewei      like mara-gewei,  " Unit of weight     " SIR 38784
          volum      like mara-volum,  " Volume             " SIR 61880
          voleh      like mara-voleh,  " Volume Unit        " SIR 61880
          del_flg(1) type c,                            "(+) SIR 301978
       end of t_mara.                                       " SIR 38784

types: begin of t_tvswz,
          vstel      like tvswz-vstel, " shipping point
       end of t_tvswz.

types: begin of t_z0234,                                        "032383
          vstel      like z0234-vstel, " shipping point          032383
          zpaluom    like z0234-zpaluom," pallet unit of measure 032383
          zcsuom     like z0234-zcsuom," Case unit of measure    032383
       end of t_z0234.                                          "032383

types: begin of t_output_dt,
          wadat_ist    like likp-wadat_ist, " Goods issue date
          ktgrd        like knvv-ktgrd," acct assign group
          bu           like knvv-kvgr1," business unit
          kunnr        like kna1-kunnr," ship to location     SIR 34606
          land1        like kna1-land1," ship to location     SIR 34606
          d_btgew      like likp-btgew," delivery weight
          m_brgew      like lips-brgew," material weight
          a_brgew      like vekp-brgew," actual weight of ship unit
          num_del      type i,         " counter of deliveries
          num_pallets  type i,         " number of pallets
          num_cases    type i,         " number of cases
          num_loose    type i,         " loose quantity
          num_delln    type i,         " counter of delivery lines
*         packages     like likp-anzpk," Number of Packages " SIR 61880
          packages(3)  type p,         " Number of Packages " SIR 61880
          volume       like lips-volum," Volume             " SIR 61880
          lobus(3)     type c,         " Line of Business   " SIR 61880
          pac1(3)      type c,                    " PAC1    " SIR 61880

       end of t_output_dt.

types: begin of t_output_ag,
          ktgrd        like knvv-ktgrd," acct assign group
          bu           like knvv-kvgr1," business unit
          land1        like kna1-land1," country              SIR 34606
          d_btgew      like likp-btgew," delivery weight
          m_brgew      like lips-brgew," material weight
          a_brgew      like vekp-brgew," actual weight of ship unit
          num_del      type i,         " counter of deliveries
          num_pallets  type i,         " number of pallets
          num_cases    type i,         " number of cases
          num_loose    type i,         " loose quantity
          num_delln    type i,         " counter of delivery lines
*         packages     like likp-anzpk," Number of Packages " SIR 61880
          packages(3)  type p,         " Number of Packages " SIR 61880
          volume       like lips-volum," Volume             " SIR 61880
          lobus(3)     type c,         " Line of Business   " SIR 61880
          pac1(3)      type c,                   " PAC1     " SIR 61880

       end of t_output_ag.

types: begin of t_output_gs,                                " SIR 34606
          ktgrd        like knvv-ktgrd," acct assign group  " SIR 34606
          bu           like knvv-kvgr1," business unit      " SIR 34606
          d_btgew      like likp-btgew," delivery weight    " SIR 34606
          m_brgew      like lips-brgew," material weight    " SIR 34606
          a_brgew      like vekp-brgew," actual weight      " SIR 34606
          num_del      type i,         " counter of deliv   " SIR 34606
          num_pallets  type i,         " number of pallets  " SIR 34606
          num_cases    type i,         " number of cases    " SIR 34606
          num_loose    type i,         " loose quantity     " SIR 34606
          num_delln    type i,         " counter of deliv   " SIR 34606
*         packages     like likp-anzpk, " Number of Package " SIR 61880
          packages(3)  type p,          " Number of Packages" SIR 61880
          volume       like lips-volum, " Volume            " SIR 61880
          lobus(3)     type c,          " Line of Business  " SIR 61880
          pac1(3)      type c,           " PAC1             " SIR 61880
       end of t_output_gs.                                  " SIR 34606
*-------------------------------------------------* Begin of SIR 061880

* Material Type
types: begin of t_mtart,
       mtart like t134-mtart,                           " Material Type
       end of t_mtart.

* Customer Business Unit.
types: begin of t_kvgr1,
       kvgr1 like knvv-kvgr1,                        " Customer Group 1
       end of t_kvgr1.

* sales Organization.
types: begin of t_lgort,
       lgort like t001l-lgort,                     " Sales Organization
       end of t_lgort.

*                                                   Begin of SIR 301978
*      Header: Material Document
types: begin of t_mkpf,
         vgart    type mkpf-vgart,
         xblnr    type likp-vbeln,
       end   of t_mkpf.
*                                                     End of SIR 301978

*---------------------------------------------------* End of SIR 061880
*---Internal Tables---------------------------------------------------*

data:  i_likp        type  t_likp occurs 0 with header line,
       i_temp_likp   type  t_likp occurs 0 with header line,
       v_likp        type  t_likp,
       i_lips        type  t_lips occurs 0 with header line,
       i_temp_lips   type  t_lips occurs 0 with header line,
       v_lips        type  t_lips,
       i_vepo        type  t_vepo occurs 0,
*      V_VEPO        TYPE  T_VEPO,
       i_vekp        type  t_vekp occurs 0,
       v_vekp        type  t_vekp,
       i_knvv        type  t_knvv occurs 0 with header line,
       v_knvv        type  t_knvv,
       i_kna1        type  t_kna1 occurs 0,                 " SIR 34606
       v_kna1        type  t_kna1,                          " SIR 34606
       i_z0234       type  t_z0234 occurs 0,                "    032383
       v_z0234       type  t_z0234,                         "    032383
       i_z0234_uom   type  t_z0234 occurs 0,                "    032383
       v_z0234_uom   type  t_z0234,                         "    032383
       i_marm        type  t_marm occurs 0 with header line," SIR 61880
       i_marm_pallet type  t_marm occurs 0 with header line,
       v_marm_pallet type  t_marm,
       i_marm_case   type  t_marm occurs 0 with header line,
       v_marm_case   type  t_marm,
*-------------------------------------------------* Begin of SIR 061880
*      I_MARA        TYPE  T_MARA OCCURS 0,                 " SIR 38784
       i_mara1       type  t_mara  occurs 0 with header line,
       i_mtart       type  t_mtart occurs 0 with header line,
       i_kvgr1       type  t_kvgr1 occurs 0 with header line,
       i_lgort       type  t_lgort occurs 0 with header line,
       v_kvgr1       type  t_kvgr1,
*---------------------------------------------------* End of SIR 061880
       v_mara        type  t_mara,                          " SIR 38784
       i_tvswz       type  t_tvswz occurs 0,
       v_tvswz       type  t_tvswz,                     "(+) SIR 301978
       i_output_dt   type  t_output_dt occurs 0,
       v_output_dt   type  t_output_dt,
       i_output_ag   type  t_output_ag occurs 0,
       v_output_ag   type  t_output_ag,
       i_output_gs   type  t_output_gs occurs 0,            " SIR 34606
       v_output_gs   type  t_output_gs,                     " SIR 34606
       i_mkpf        type  table of t_mkpf with header line."SIR 301978


***********************************************************************
*** Data Declarations *
***********************************************************************
data:  v_page(3)        type c,                          " Page Counter
       v_comp           like t001k-bukrs,       " zbsn0001 company code
       v_title(24)      type c,                 " zbsn0001 report title
       v_rpttyp         type c,                           " report type
       v_ok             type c,             " control While... endwhile
       v_diff_date      type p,                " days between selection
       v_werks          like t001l-werks,                       " plant
*      v_z0234_zpaluom  like z0234-zpaluom,  " Pallet Unit of Measure
*      v_z0234_zcsuom   like z0234-zcsuom,   " Case Unit of Measure
       v_palwto         type p decimals 6,                 " SIR 091510
*       "like likp-btgew,       " Weight after conversion
       v_vekp_tabix     like sy-tabix,                  " index on read
       v_vekp_sum_brgew like vekp-brgew,                " actual weight
       v_pallet_qty     like lips-lgmng,        " calculated pallet qty
       v_pallet_integer type i,                       " true pallet qty
       v_case_qty       like lips-lgmng,          " calculated case qty
       v_case_integer   type i,                         " true case qty
       v_qty_not_pallets like lips-lgmng,                  " calculated
       v_num_pallets    like lips-lgmng,    " calculated nbr of pallets
       v_num_pallets_int type i,                  " true nbr of pallets
       v_num_cases      like lips-lgmng,      " calculated nbr of cases
       v_num_cases_int  type i,                     " true nbr of cases
       v_total_case_qty like lips-lgmng,                " case quantity
       v_loose_qty      type i,             " calculated loose quantity
*-------------------------------------------------* Begin of SIR 061880
       v_volume         like lips-volum,      " Volume After Convertion
       v_cbuun          like knvv-kvgr1,                  " Customer BU
       v_mbuun          like knvv-kvgr1,                  " Material BU
       v_lobus(3)       type c,                      " Line of Business
       v_pac1(3)        type c,                                  " PAC1
       v_flag           type c.            " Flag Indicator for No Data
*---------------------------------------------------* End of SIR 061880

*                                                   Begin of SIR 301978
*---------------------------------------------------------------------*
* Ranges
*---------------------------------------------------------------------*
ranges : r_vstel for tvswz-vstel.
*                                                     End of SIR 301978
*---------------------------------------------------------------------*
* Constants
*---------------------------------------------------------------------*
data:  c_uom(3)        type c value 'KG'.    " Kilogram Unit of Meas.
data : c_vom like mara-voleh value 'M3'.   " Metter Cube.  " SIR 061880
constants : c_wl(2) type c value 'WL'.                  "(+) SIR 301978
*---------------------------------------------------------------------*
* Initialization.
*---------------------------------------------------------------------*
initialization.
  s_lfart-sign   = 'I'.
  s_lfart-option = 'EQ'.
  s_lfart-low    = 'LF  '.
  append s_lfart.
  s_lfart-low    = 'NL  '.
  append s_lfart.
  s_lfart-low    = 'NLCC'.
  append s_lfart.
  s_lfart-low    = 'ZLFI'.
  append s_lfart.
*---------------------------------------------------------------------*
* AT SELECTION-SCREEN.
*---------------------------------------------------------------------*
at selection-screen.

*---------------------------------------------------------------------*
* SIR 42730 - If no Goods Issue Date has been specified in the
*             Select Options set the range to the previous month.
*---------------------------------------------------------------------*

  if s_wadat-low is initial.

    s_wadat-sign      = 'I'.
    s_wadat-option    = 'BT'.
    s_wadat-high      = sy-datum.              " Today's date
    s_wadat-high+6(2) = '01'.                  " First of this month
    s_wadat-high      = s_wadat-high - 1.      " End of last month

    s_wadat-low       = s_wadat-high.          " End of last month
    s_wadat-low+6(2)  = '01'.                  " First of last month
    append s_wadat.

  endif.     " SIR 42730 IF S_WADAT-LOW IS INITIAL.

  clear v_werks.                                        "(+) SIR 301978

* Validate Plant/Storage Location from selection screen
  select werks up to 1 rows into v_werks from t001l
        where werks =  p_werks  and
              lgort in s_lgort.
  endselect.

  if sy-subrc ne 0.
    message e045 with text-e01.
  endif.

* Validate Storage Location
  if not s_lgort[] is initial.
    select lgort from t001l into table i_lgort where lgort in s_lgort.
    if sy-subrc ne 0.
      message e045 with text-e09.
    endif.
  endif.

* Validate date range.  do not allow more that 31 days
  if not s_wadat-high is initial.
    v_diff_date = s_wadat-high - s_wadat-low.
    if v_diff_date >= '31'.
      message e045 with text-e02.
    endif.
  endif.

*-------------------------------------------------* Begin of SIR 061880
* Validation for Material Type in Selection Screen
  if not s_mtart[] is initial.
    select mtart from t134 into table i_mtart where mtart in s_mtart.
    if sy-subrc ne 0.
      message e045 with text-e07.
    endif.
  endif.

at selection-screen on block b2.

* Validation for Material Business Unit and Customer Business Unit.
  if s_cbuun-low is not initial and s_mbuun-low is not initial.
    message e045 with text-e05.
  endif.

* Validation for Possible combinations of Material BU, Line of Business
* and PAC1
  if ( s_mbuun-low is not initial and s_lobus-low is not initial
                                and s_pac1-low is not initial )
  or ( s_mbuun-low is not initial and s_lobus-low is not initial )
  or ( s_lobus-low is not initial and s_pac1-low is not initial )
  or ( s_mbuun-low is not initial and s_pac1-low is not initial ).
    message e045 with text-e06.
  endif.

* Validation for Customer Business Unit.
  if not s_cbuun[] is initial.
    select kvgr1 from tvv1 into table i_kvgr1 where kvgr1 in s_cbuun.
    if sy-subrc ne 0.
      message e045 with text-e08.
    endif.
*    free: i_kvgr1.
  endif.

*---------------------------------------------------- End of SIR 061880
*---------------------------------------------------------------------*
* TOP-OF-PAGE
*---------------------------------------------------------------------*
* Top of the page routine to print the headers and columns
*---------------------------------------------------------------------*
top-of-page.

  format color col_heading on.
  if v_rpttyp = 'D'.
    v_title = text-h01.
  else.
    v_title = text-h02.
  endif.
  perform zbsn0001_standard_header     " Standard Report Heading Form
           using v_comp v_title 'U' v_page.
  skip.

  if v_rpttyp = 'D'.
    perform write_dtlvl_headings.
  else.
    perform write_aglvl_headings.
  endif.

*---------------------------------------------------------------------*
*       FORM WRITE_DTLVL_HEADINGS                                     *
*---------------------------------------------------------------------*
*   for date detail level, print the column headers                   *
*---------------------------------------------------------------------*
form write_dtlvl_headings.

  write: /001 text-h03,                " Acct
          038 text-h04,                " ------ P I C K I N G ------
          105 text-h05,                " ----- S H I P P I N G -----
         /001 text-h06,                " Group
          007 text-h07,                " Date
          017 text-h08,                " BU
          021 text-h17,                " ship to party            34606
          030 text-h18,                " country
          039 text-h09,                " Pallets
          057 text-h10,                " Cases
          075 text-h11,                " Loose
          093 text-h12,                " Lines
          105 text-h13,                " Material Kg
          124 text-h16,                " Delivery Kg
          143 text-h14,                " Actual Kg
          161 text-h15,                " Deliveries
*----------------------------------------------------Start of SIR 61880
          173 text-h20,                " Packages
          189 text-h21,                " Volume
          201 text-h22,                " LOB
          207 text-h23.                " PAC1
*-----------------------------------------------------*End of SIR 61880
  skip.

endform.                               " end of write_dtlvl_headings.

*---------------------------------------------------------------------*
*       FORM WRITE_AGLVL_HEADINGS                                     *
*---------------------------------------------------------------------*
*      for account group detail level, print the column headers       *
*---------------------------------------------------------------------*
form write_aglvl_headings.

  write: /001 text-h03,                " Acct
          038 text-h04,                " ------ P I C K I N G ------
          105 text-h05,                " ----- S H I P P I N G -----
         /001 text-h06,                " Group
          017 text-h08,                " BU
          030 text-h18,                " country              SIR 34606
          039 text-h09,                " Pallets
          057 text-h10,                " Cases
          075 text-h11,                " Loose
          093 text-h12,                " Lines
          105 text-h13,                " Material Kg
          124 text-h16,                " Delivery Kg
          143 text-h14,                " Actual Kg
          161 text-h15,                " Deliveries
*---------------------------------------------------*Start of SIR 61880
          173 text-h20,                " Packages
          189 text-h21,                " Volume
          201 text-h22,                " LOB
          207 text-h23.                " PAC1
*-----------------------------------------------------*End of SIR 61880
  skip.

endform.                               " end of write_aglvl_headings.

***********************************************************************
*-------------------------- SUBBROUTINES -----------------------------*
***********************************************************************

include zbsn0001.      " Include to print all Standard Report Titles
include zsdn0004.      " Print the Select Options

***********************************************************************
*** MAIN SELECTION.                                                   *
***********************************************************************
start-of-selection.

  refresh:  i_likp, i_temp_likp, i_lips, i_temp_lips, i_vepo,
            i_vekp, i_knvv, i_marm_pallet, i_marm_case, i_tvswz,
            i_output_dt, i_output_ag, i_mara1.
  clear:    v_likp, v_lips, v_vekp, v_knvv, v_mara,
            v_marm_pallet, v_marm_case, v_output_dt, v_output_ag.
  v_rpttyp = 'D'.

*---------------------------------------------------------------------*
* SIR 42730 - Echo the Select Options to the output listing and print
*             the Goods Issue Date range being used.
*---------------------------------------------------------------------*
  write: /,/.     " SIR 43730 - Skip a couple of lines to centre it.

  perform zsdn0004_print_select_options using sy-cprog ' '.

  if s_wadat-high is initial.
    write: /,/, text-003, 34 s_wadat-low.
  else.
    write: /,/, text-003, 34 s_wadat-low, 44 text-004, 47 s_wadat-high.
  endif.

  new-page.
*---------------------------------------------------------------------*
* Main Processing.                                                    *
*---------------------------------------------------------------------*
  perform get_data.

  if not i_lips[] is initial.
    perform create_output.
  endif.

*---------------------------------------------------------------------*
* END-OF-SELECTION
*---------------------------------------------------------------------*
end-of-selection.
*-------------------------------------------------* Start of SIR 061880
*   PERFORM WRITE_REPORT.
  if not i_output_dt[] is initial and not i_output_ag[] is initial and
                                      not i_output_gs[] is initial.
    perform write_report.

  else.
    skip 2.
    write:/ text-e03.
    skip 2.
    uline.
    clear: v_flag.
  endif.
*---------------------------------------------------* End of SIR 061880

*---------------------------------------------------------------------*
*       FORM GET_DATA                                                 *
*---------------------------------------------------------------------*
* build all of the internal tables needed for the report              *
* selects on t001k, z0234, likp, lips, vepo, vekp, knvv & marm, mara  *
*---------------------------------------------------------------------*
form get_data.

  perform get_data_t001k.                                  " SIR 301978

  perform get_data_tvswz.                                  " SIR 301978

  if sy-subrc = 0.                     " Build shipping point range

    perform get_data_Z0234.                                " SIR 301978

    if sy-subrc ne 0.
      v_flag = 'X'.
*      stop.
    else.
      sort i_z0234 by vstel.                                   " 032383
    endif.

*                                                  Begin of  SIR 301978

*   The data retrievalfrom LIKP has been modified for performance
*   reasons
    perform get_data_mkpf.                                 " SIR 301978

    if sy-subrc eq 0.

*     Deleting data other than Goods issued for delivery
      delete i_mkpf where vgart ne c_wl.
      sort i_mkpf by xblnr.

    endif.

*   Deleting the data from the internal table i_likp by comparing
*   shipping point
    r_vstel-sign = 'I'.
    r_vstel-option = 'EQ'.
    clear : v_tvswz.

    loop at i_tvswz into v_tvswz.

      r_vstel-low = v_tvswz-vstel.
      append r_vstel.

    endloop.

    if not i_mkpf[] is initial.

      perform get_data_likp.                             " SIR 301978

    endif.

    if sy-subrc = 0.

      delete i_likp where not lfart in s_lfart.
*                                                  End    of SIR 301978

*     Get data for the delivery lines
      if not i_likp[] is initial.

        perform get_data_lips.                         " SIR 301978

*                                                  Begin of SIR 301978
        if i_lips[] is initial.

          v_flag = 'X'.
          message i089 with text-i02.
          leave list-processing.

        endif.                    " Return code for LIPS select

*                                                     End of SIR 301978
      endif.
*-------------------------------------------------* Begin of SIR 061880

*     Get Data From MARA (Material Master) to Read Material Weight and
*     Material Voluem from Master Data.
      if not i_lips[] is initial.
*                                                   Begin of SIR 301978

*       Delete the duplicate material from delivery item table
        i_temp_lips[] = i_lips[].
        sort i_temp_lips by matnr.
        delete adjacent duplicates from i_temp_lips comparing matnr.

        perform get_data_mara.                         " SIR 301978

        if sy-subrc = 0.

          sort i_mara1 by matnr.
          clear i_temp_lips.
          refresh i_temp_lips.
*                                                     End of SIR 301978
        else.
          v_flag = 'X'.
          message i089 with text-i01.
          leave list-processing.
        endif.
      endif.

*     Filter I_LIPS and I_MARA1 When Either material BU or Line of
*     Business (LOB) or PAC1 are not left Balnk
      perform filter_data_for_prdha.

*     Get data for the sold-to customer
      perform i_knvv_fill_data.

*    Filter I_LIKP & I_LIPS & I_MARA for Cust-BU, When Cust-Bu is not
*    left Blank.
      perform filter_likp_lips_mara_custbu.

*---------------------------------------------------- End of SIR 061880
*-------------------------------------------------* Begin of SIR 034606
*     Get data for the ship to party
      i_temp_likp[]  = i_likp[].
      sort i_temp_likp by kunnr.
      delete adjacent duplicates from i_temp_likp comparing kunnr.
      perform get_data_kna1.                             " SIR 301978
      if sy-subrc = 0.
        sort i_kna1 by kunnr.
      endif.
*---------------------------------------------------* End of SIR 034606
    else.
      v_flag = 'X'.
      message i089 with text-i04.
      leave list-processing.
    endif.                               " return code to LIKP select
*    endif.                                                " SIR 061880
    free: i_temp_likp.
  endif.                               " return code for TVSWZ select

* Process table LIPS

  if not i_lips[] is initial.
    i_temp_lips[] = i_lips[].
    sort i_temp_lips by vbeln.
    delete adjacent duplicates from i_temp_lips comparing vbeln.

*   Get actual weight

    perform get_data_vepo.                                 " SIR 301978
    if sy-subrc = 0.
      sort i_vepo by venum.
      delete adjacent duplicates from i_vepo comparing venum.
      perform get_data_vekp.                               " SIR 301978
      sort i_vekp by vpobjkey.
    endif.
    free:  i_vepo, i_temp_lips.

    i_temp_lips[] = i_lips[].
    sort i_temp_lips by matnr.
    delete adjacent duplicates from i_temp_lips comparing matnr.

*   Get Units of Measure for Material
    perform read_data_from_marm.                           " SIR 061880
*                                                   Begin of SIR 032383
    i_z0234_uom = i_z0234.
    sort i_z0234_uom by zpaluom.
    delete adjacent duplicates from i_z0234_uom comparing zpaluom.
*                                                   End   of SIR 032383

    clear i_marm_pallet.                                   " SIR 061880
    refresh  i_marm_pallet.                                " SIR 061880

    loop at i_z0234_uom into v_z0234_uom.             "LOOP Z0234 032383
*-------------------------------------------------* Begin of SIR 061880
*     Get Alternative Unit of Measure for Pallets
      perform i_marm_pallet_fill.

    endloop.                                      "ENDLOOP Z0234 032383
** get alternative UoM for pallets
*      SELECT MATNR                     " material
*             MEINH                     " Alt unit of measure  " 032383
*             UMREZ                     " numerator
*             UMREN                     " denominator
**     into table i_marm_pallet                                " 032383
*      APPENDING TABLE I_MARM_PALLET                            "032383
*      FROM MARM
*      FOR ALL ENTRIES IN I_TEMP_LIPS
*      WHERE MATNR = I_TEMP_LIPS-MATNR  AND
**           meinh = v_z0234_zpaluom.                          " 032383
*            MEINH = V_Z0234_UOM-ZPALUOM.                      " 032383
*---------------------------------------------------* End of SIR 061880
    sort i_marm_pallet by matnr meinh.

    free i_z0234_uom.                                           "032383
    i_z0234_uom = i_z0234.                                      "032383
    sort i_z0234_uom by zcsuom.                                 "032383
    delete adjacent duplicates from i_z0234_uom comparing zcsuom."32383
    clear i_marm_case.                                     " SIR 061880
    refresh i_marm_case.                                   " SIR 061880

    loop at i_z0234_uom into v_z0234_uom.            "LOOP Z0234 032383
*-------------------------------------------------* Begin of SIR 061880
*     Get Alternative Unit of Measure for Cases
      perform i_marm_case_fill.

    endloop.                                      "ENDLOOP Z0234 032383
*---------------------------------------------------* End of SIR 061880
    sort i_marm_case by matnr meinh.
  else.
    v_flag = 'X'.
    message i089 with text-i02.
*      leave list-processing.
  endif.                               " table LIPS is empty
endform.                               " get_data

*---------------------------------------------------------------------*
*       FORM CREATE_OUTPUT                                            *
*---------------------------------------------------------------------*
* process internal table LIPS, for each delivery/delivery lines create*
* an output record and collect into i_output internal table.  Fields  *
* used for header are goods issue date, acct assign, BU for customer, *
* total weight, total weight for shipping unit and count of           *
* deliveries, the remaining fields will have a value of zero for the  *
* collect.  For each delivery line, fields used are goods issue date, *
* acct assign, BU for material, number of pallets, number of cases,   *
* loose quantity and number of delivery lines.  The remaining header  *
* fiels will be zero for the collect.                                 *
*---------------------------------------------------------------------*
form create_output.
*-------------------------------------------------* Begin of SIR 061880
  sort i_mara1 by matnr.
  sort i_lips by vbeln posnr matnr.
  sort i_likp by vbeln.
  sort i_z0234 by vstel.
  sort i_knvv by kunnr.
  sort i_kna1 by kunnr.
  sort i_vekp by vpobjkey.
  sort i_marm_pallet by matnr meinh.
  sort i_marm_case by matnr meinh.
* LOOP AT I_LIPS INTO V_LIPS.
  loop at i_lips.
    clear v_lips.
    v_lips = i_lips.
*---------------------------------------------------* End of SIR 061880
    at new vbeln.
      perform collect_header_data.
    endat.
    if not v_lips-komkz is initial.                         " SIR 45567
      perform collect_item_data.
    endif.                                                  " SIR 45567
  endloop.
endform.                               " create_output

*---------------------------------------------------------------------*
*       FORM COLLECT_HEADER_DATA                                      *
*---------------------------------------------------------------------*
* Fields used for header are goods issue date, acct assign,           *
* BU for customer, total weight, total weight for shipping unit       *
* and count ofdeliveries, the remaining fields will have a value of   *
* zero for the collect.                                               *
*---------------------------------------------------------------------*
form collect_header_data.

  clear:  v_likp, v_knvv, v_vekp, v_vekp_sum_brgew.
  v_ok = 'Y'.

  read table i_likp into v_likp with key vbeln = v_lips-vbeln
                                               binary search.
  if sy-subrc = 0.                                         " SIR 061880

    clear v_z0234.                                      "(+) SIR 301978

    read table i_z0234 into v_z0234                              "32383
         with key vstel = v_likp-vstel                           "32383
         binary search.                                          "32383

    read table i_knvv into v_knvv with key kunnr = v_likp-kunag
                                                 binary search.
    if sy-subrc ne 0.
      select single ktgrd kvgr1 into (v_knvv-ktgrd, v_knvv-kvgr1)
        from knvv where kunnr = v_likp-kunag  and
                        vkorg = v_likp-vkorg  and
                       vtweg = '01' and          " intercompany values
                       spart = '01'.             " intercompany values
    endif.

    clear v_kna1.                                           " SIR 34606
    read table i_kna1 into v_kna1                           " SIR 34606
       with key kunnr = v_likp-kunnr                        " SIR 34606
       binary search.                                       " SIR 34606

    read table i_vekp into v_vekp
       with key vpobjkey(10) = v_likp-vbeln
       binary search.
    if sy-subrc = 0.
      v_vekp_tabix = sy-tabix.
      while v_ok = 'Y'.
        if v_vekp-gewei_max ne c_uom.
          perform z_unit_conversion
            using v_vekp-brgew v_vekp-gewei_max c_uom v_palwto.
          v_vekp_sum_brgew = v_vekp_sum_brgew + v_palwto.
        else.
          v_vekp_sum_brgew = v_vekp_sum_brgew + v_vekp-brgew.
        endif.
        v_vekp_tabix = v_vekp_tabix + 1.
        read table i_vekp into v_vekp
           index v_vekp_tabix.
        if sy-subrc = 0.
          if v_vekp-vpobjkey(10) ne v_likp-vbeln.
            v_ok = 'N'.
          endif.
        else.
          v_ok = 'N'.
        endif.
      endwhile.
    endif.
  endif.                                                   " SIR 061880
* populate output tables
  clear: v_output_dt, v_output_ag,v_output_gs.              " SIR 34606
  v_output_dt-wadat_ist = v_likp-wadat_ist.

  v_output_dt-ktgrd     = v_knvv-ktgrd.
  v_output_ag-ktgrd     = v_knvv-ktgrd.
  v_output_gs-ktgrd     = v_knvv-ktgrd.                     " SIR 34606
*-------------------------------------------------* Begin of SIR 061880
*  V_OUTPUT_DT-BU        = V_KNVV-KVGR1.
*  V_OUTPUT_AG-BU        = V_KNVV-KVGR1.
*  V_OUTPUT_GS-BU        = V_KNVV-KVGR1.                    " SIR 34606

* Populate Business Unit,Line of Busness and PAC1 Values in Header Data
  perform get_busunit_lobus_pac1_data1.
*---------------------------------------------------* End of SIR 061880
  v_output_dt-kunnr = v_kna1-kunnr.                         " SIR 34606
* V_OUTPUT_AG-KUNNR = V_KNA1-KUNNR.                         " SIR 34606
  v_output_dt-land1 = v_kna1-land1.                         " SIR 34606
  v_output_ag-land1 = v_kna1-land1.                         " SIR 34606

  v_output_dt-a_brgew     = v_vekp_sum_brgew.
  v_output_ag-a_brgew     = v_vekp_sum_brgew.
  v_output_gs-a_brgew     = v_vekp_sum_brgew.               " SIR 34606

  if s_mbuun[] is initial and                               " SIR 61880
     s_lobus[] is initial and                               " SIR 61880
     s_pac1[] is  initial.                                  " SIR 61880
    v_output_dt-num_del   = 1.
    v_output_ag-num_del   = 1.
    v_output_gs-num_del   = 1.                              " SIR 34606
*-------------------------------------------------* Begin of SIR 061880
* Number of Packages
    v_output_dt-packages   = v_likp-anzpk.
    v_output_ag-packages   = v_likp-anzpk.
    v_output_gs-packages   = v_likp-anzpk.
  else.
    clear: v_output_dt-num_del,
           v_output_ag-num_del,
           v_output_gs-num_del,
           v_output_dt-packages,
           v_output_ag-packages,
           v_output_gs-packages.
  endif.
*---------------------------------------------------* End of SIR 061880
  collect v_output_dt into i_output_dt.
  collect v_output_ag into i_output_ag.
  collect v_output_gs into i_output_gs.                     " SIR 34606
endform.                               " collect_header_data

*---------------------------------------------------------------------*
*       FORM COLLECT_ITEM_DATA                                        *
*---------------------------------------------------------------------*
* For each delivery line, fields used are goods issue date,           *
* acct assign, BU for material, number of pallets, number of cases,   *
* loose quantity and number of delivery lines.  The remaining header  *
* fiels will be zero for the collect.                                 *
*---------------------------------------------------------------------*
form collect_item_data.

  clear:  v_pallet_qty,      v_pallet_integer,
          v_case_qty,        v_case_integer,
          v_num_pallets,     v_num_pallets_int,
          v_num_cases,       v_num_cases_int,
          v_qty_not_pallets, v_total_case_qty, v_loose_qty.

  read table i_marm_pallet into v_marm_pallet
             with key matnr = v_lips-matnr
                      meinh = v_z0234-zpaluom binary search."32382


  if sy-subrc = 0.
    v_pallet_qty = v_marm_pallet-umrez / v_marm_pallet-umren.
* round down partial pallets
    v_pallet_integer = v_pallet_qty - '.499'.
  endif.

  read table i_marm_case into v_marm_case
              with key matnr = v_lips-matnr
                       meinh = v_z0234-zcsuom binary search."32382

  if sy-subrc = 0.
    v_case_qty = v_marm_case-umrez / v_marm_case-umren.
* round down partial cases
    v_case_integer = v_case_qty - '.499'.
  endif.

  if v_pallet_integer > 0.
    v_num_pallets     = v_lips-lgmng / v_pallet_integer.
    v_num_pallets_int = v_num_pallets - '.499'.
  endif.
  v_qty_not_pallets = v_lips-lgmng -
                      ( v_num_pallets_int * v_pallet_integer ).
  if v_case_integer > 0.
    v_num_cases     = v_qty_not_pallets / v_case_integer.
    v_num_cases_int = v_num_cases - '.499'.
  endif.
  v_total_case_qty     = v_num_cases_int * v_case_integer.
  if v_qty_not_pallets = v_total_case_qty.
    v_loose_qty = 0.
  else.
    v_loose_qty = 1.
  endif.
* populate output tables
  clear: v_output_dt, v_output_ag, v_output_gs.             " SIR 34606
  v_output_dt-wadat_ist   = v_likp-wadat_ist.
  v_output_dt-ktgrd       = v_knvv-ktgrd.
  v_output_ag-ktgrd       = v_knvv-ktgrd.
  v_output_gs-ktgrd       = v_knvv-ktgrd.                   " SIR 34606

  v_output_dt-kunnr = v_kna1-kunnr.                         " SIR 34606
* V_OUTPUT_AG-KUNNR = V_KNA1-KUNNR.                         " SIR 34606
  v_output_dt-land1 = v_kna1-land1.                         " SIR 34606
  v_output_ag-land1 = v_kna1-land1.                         " SIR 34606
*-------------------------------------------------* Begin of SIR 061880
*  V_OUTPUT_DT-BU          = V_LIPS-PRODH+1(2).
*  V_OUTPUT_AG-BU          = V_LIPS-PRODH+1(2).
*  V_OUTPUT_GS-BU          = V_LIPS-PRODH+1(2).             " SIR 34606
*
* Populate Business Unit,Line of Business and PAC1 Values for Item Data.
  perform get_busunit_lobus_pac1_data2.
  if V_OUTPUT_DT-BU is initial.
   clear V_OUTPUT_DT.
   exit.
  endif.
*---------------------------------------------------* End of SIR 061880
* get delivery weight from delivery lines instead of header " SIR 45567
  if v_lips-gewei = c_uom.
    v_output_dt-d_btgew  = v_lips-brgew.
    v_output_ag-d_btgew  = v_lips-brgew.
    v_output_gs-d_btgew  = v_lips-brgew.                    " SIR 34606
  else.
    perform z_unit_conversion
         using v_lips-brgew v_lips-gewei c_uom v_palwto.
    v_output_dt-d_btgew  = v_palwto.
    v_output_ag-d_btgew  = v_palwto.
    v_output_gs-d_btgew  = v_palwto.                        " SIR 34606
  endif.

* Get material weight from delivery (LIPS)(IF P_DELWT = 'X')" SIR 38784

  if p_delwt = 'X'.                                         " SIR 38784
    if v_lips-gewei = c_uom.
      v_output_dt-m_brgew  = v_lips-brgew.
      v_output_ag-m_brgew  = v_lips-brgew.
      v_output_gs-m_brgew  = v_lips-brgew.                  " SIR 34606
    else.
      perform z_unit_conversion
           using v_lips-brgew v_lips-gewei c_uom v_palwto.
      v_output_dt-m_brgew  = v_palwto.
      v_output_ag-m_brgew  = v_palwto.
      v_output_gs-m_brgew  = v_palwto.                      " SIR 34606
    endif.

  else.                                                     " SIR 38784
* Get material weight from Master data (MARA)               " SIR 38784

    read table i_mara1 into v_mara                          " SIR 38784
                           with key matnr = v_lips-matnr    " SIR 38784
                           binary search.                   " SIR 38784
    if v_mara-gewei = c_uom.                                " SIR 38784
      v_output_dt-m_brgew  = v_mara-brgew * v_lips-lgmng.   " SIR 38784
      v_output_ag-m_brgew  = v_mara-brgew * v_lips-lgmng.   " SIR 38784
      v_output_gs-m_brgew  = v_mara-brgew * v_lips-lgmng.   " SIR 38784
    else.                                                   " SIR 38784
      perform z_unit_conversion                             " SIR 38784
           using v_mara-brgew v_mara-gewei c_uom v_palwto.  " SIR 38784
      v_output_dt-m_brgew  = v_palwto * v_lips-lgmng.       " SIR 38784
      v_output_ag-m_brgew  = v_palwto * v_lips-lgmng.       " SIR 38784
      v_output_gs-m_brgew  = v_palwto * v_lips-lgmng.       " SIR 38784
    endif.                                                  " SIR 38784
  endif.                                                    " SIR 38784
*-------------------------------------------------* Begin of SIR 061880
* To Get the Volume Data.
  perform get_volume_data.
*---------------------------------------------------* End of SIR 061880
  v_output_dt-num_pallets = v_num_pallets_int.
  v_output_ag-num_pallets = v_num_pallets_int.
  v_output_gs-num_pallets = v_num_pallets_int.              " SIR 34606
  v_output_dt-num_cases   = v_num_cases_int.
  v_output_ag-num_cases   = v_num_cases_int.
  v_output_gs-num_cases   = v_num_cases_int.                " SIR 34606
  v_output_dt-num_loose   = v_loose_qty.
  v_output_ag-num_loose   = v_loose_qty.
  v_output_gs-num_loose   = v_loose_qty.                    " SIR 34606
*{   INSERT         D11K901833                                        1
* Sir 054042/48712 insert code to put in 0 instead of 1 for collect
* value for delivery lines
  if v_lips-lgmng = 0.
    v_output_dt-num_delln   = 0.
    v_output_ag-num_delln   = 0.
    v_output_gs-num_delln   = 0.
  else.
* end of insert for 054042/48712
*}   INSERT
    v_output_dt-num_delln   = 1.
    v_output_ag-num_delln   = 1.
    v_output_gs-num_delln   = 1.                            " SIR 34606
*{   INSERT         D11K901833                                        2
  endif.
*}   INSERT
  collect v_output_dt into i_output_dt.
  collect v_output_ag into i_output_ag.
  collect v_output_gs into i_output_gs.                     " SIR 34606

endform.                               " collect_item_data

*---------------------------------------------------------------------*
*       FORM Z_UNIT_CONVERSION                                        *
*---------------------------------------------------------------------*
*    convert weight to KG                                             *
*---------------------------------------------------------------------*
form z_unit_conversion using v_in   like likp-btgew
                             v_unit like t006-msehi
                             v_uom  like t006-msehi
                             v_out  like v_palwto.
                             "like likp-btgew.

*BEGIN OF 091510
  data: v_in1 type p decimals 6,
        v_out1 type p decimals 6.

  v_in1 = v_in.

  call function 'UNIT_CONVERSION_SIMPLE'
    exporting
      input                = v_in1
      unit_in              = v_unit
      unit_out             = v_uom
    importing
      output               = v_out1
    exceptions
      conversion_not_found = 1
      division_by_zero     = 2
      input_invalid        = 3
      output_invalid       = 4
      overflow             = 5
      type_invalid         = 6
      units_missing        = 7
      unit_in_not_found    = 8
      unit_out_not_found   = 9
      others               = 10.

      v_out =  v_out1.
*BEGIN OF 091510
endform.                                      " z_unit_conversion

*---------------------------------------------------------------------*
*       FORM WRITE_REPORT                                             *
*---------------------------------------------------------------------*
form write_report.
  sort i_output_dt by wadat_ist  ktgrd  bu kunnr land1.     " SIR 34606
  loop at i_output_dt into v_output_dt.
    write: /001 v_output_dt-ktgrd,
            006 v_output_dt-wadat_ist,
            017 v_output_dt-bu,
            021 v_output_dt-kunnr,                          " SIR 34606
            032 v_output_dt-land1,                          " SIR 34606
            035 v_output_dt-num_pallets,
            052 v_output_dt-num_cases,
            070 v_output_dt-num_loose,
            088 v_output_dt-num_delln,
            100 v_output_dt-m_brgew unit c_uom,
            119 v_output_dt-d_btgew unit c_uom,
            138 v_output_dt-a_brgew unit c_uom,
            159 v_output_dt-num_del,
*-------------------------------------------------* Begin of SIR 061880
            173 v_output_dt-packages right-justified,
            182 v_output_dt-volume unit c_vom.
    if s_lobus[] is not initial.
      write: 201 v_output_dt-lobus.
    endif.
    if s_pac1[] is not initial.
      write: 201 v_output_dt-lobus.
      write: 207 v_output_dt-pac1.
    endif.
*---------------------------------------------------* End of SIR 061880
    at end of wadat_ist.
      skip.
    endat.
  endloop.
  v_rpttyp = 'T'.
  format color col_heading on.
  skip 2.
  write:  /060 text-h02.
  perform write_aglvl_headings.
  format color off.
  sort i_output_ag by ktgrd bu land1.                       " SIR 34606
  loop at i_output_ag into v_output_ag.
    write: /001 v_output_ag-ktgrd,
            017 v_output_ag-bu,
            032 v_output_ag-land1,                          " SIR 34606
            035 v_output_ag-num_pallets,
            052 v_output_ag-num_cases,
            070 v_output_ag-num_loose,
            088 v_output_ag-num_delln,
            100 v_output_ag-m_brgew unit c_uom,
            119 v_output_ag-d_btgew unit c_uom,
            138 v_output_ag-a_brgew unit c_uom,
            159 v_output_ag-num_del,
*-------------------------------------------------* Begin of SIR 061880
            173 v_output_ag-packages right-justified,
            182 v_output_ag-volume unit c_vom.
    if s_lobus[] is not initial.
      write: 201 v_output_ag-lobus.
    endif.
    if s_pac1[] is not initial.
      write: 201 v_output_ag-lobus.
      write: 207 v_output_ag-pac1.
    endif.
*---------------------------------------------------* End of SIR 061880
  endloop.
*                                                             SIR 34606
* We add a new total
  format color col_heading on.
  skip 2.
  write:  /060 text-h19.
  perform write_gsvl_headings.
  format color off.
  sort i_output_gs by ktgrd  bu.
  loop at i_output_gs into v_output_gs.
    write: /001 v_output_gs-ktgrd,
            017 v_output_gs-bu,
            035 v_output_gs-num_pallets,
            052 v_output_gs-num_cases,
            070 v_output_gs-num_loose,
            088 v_output_gs-num_delln,
            100 v_output_gs-m_brgew unit c_uom,
            119 v_output_gs-d_btgew unit c_uom,
            138 v_output_gs-a_brgew unit c_uom,
            159 v_output_gs-num_del,
*-------------------------------------------------* Begin of SIR 061880
            173 v_output_gs-packages right-justified,
            182 v_output_gs-volume unit c_vom.
    if s_lobus[] is not initial.
      write: 201 v_output_gs-lobus.
    endif.
    if s_pac1[] is not initial.
      write: 201 v_output_gs-lobus.
      write: 207 v_output_gs-pac1.
    endif.

*---------------------------------------------------* End of SIR 061880
  endloop.

endform.                               " write_report
*&--------------------------------------------------------------------*
*&      Form  WRITE_GSVL_HEADINGS
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
form write_gsvl_headings.
  write: /001 text-h03,                " Acct
          038 text-h04,                " ------ P I C K I N G ------
          105 text-h05,                " ----- S H I P P I N G -----
         /001 text-h06,                " Group
          017 text-h08,                " BU
          039 text-h09,                " Pallets
          057 text-h10,                " Cases
          075 text-h11,                " Loose
          093 text-h12,                " Lines
          105 text-h13,                " Material Kg
          124 text-h16,                " Delivery Kg
          143 text-h14,                " Actual Kg
          161 text-h15,                " Deliveries
*---------------------------------------------------*Begin of SIR 61880
          173 text-h20,                " Packages
          189 text-h21,                " Volume
          201 text-h22,                " LOB
          207 text-h23.                " PAC1
*-----------------------------------------------------*End of SIR 61880
  skip.

endform.                    " WRITE_GSVL_HEADINGS

*&--------------------------------------------------------------------*
*&      Form FILTER_DATA_FOR_PRDHA
*&--------------------------------------------------------------------*
* Filter I_LIPS and I_MARA1 When Either Material BU or Line of Business
* (LOB) or PAC1 are not left Balnk
*---------------------------------------------------------------------*
form filter_data_for_prdha.

  if not s_mbuun[] is initial or not s_lobus[] is initial or
     not s_pac1[] is initial.

*   Filter I_MARA1 When Either Material BU or Line of Business (LOB) or
*   PAC1 are not left Balnk
    perform i_mara1_filter.

*   Filter I_LIPS When Either Material BU or Line of Business (LOB) or
*   PAC1 are not left Balnk
    perform i_lips_filter.
  endif.
endform.                    " FILTER_DATA_FOR_PRDHA.

*&--------------------------------------------------------------------*
*&      Form  GET_BUSUNIT_LOBUS_PAC1_DATA1
*&--------------------------------------------------------------------*
* Populate Business Unit,Line of Busness and PAC1 Values in Header Data
*---------------------------------------------------------------------*
form get_busunit_lobus_pac1_data1.

* When Customer BU, Material BU, LOB and PAC1 are Left Blank.

  if ( s_cbuun[] is initial and  s_mbuun[] is initial and
      s_lobus[] is initial and s_pac1[] is initial ).

    v_output_dt-bu = v_knvv-kvgr1.
    v_output_ag-bu = v_knvv-kvgr1.
    v_output_gs-bu = v_knvv-kvgr1.

* When Material BU, LOB and PAC1 are Left Blank.
  elseif s_mbuun[] is initial and s_cbuun[] is not initial.

    clear v_cbuun.
    read table s_cbuun into v_cbuun with key low = v_knvv-kvgr1.
    if sy-subrc = 0.
      v_output_dt-bu = v_knvv-kvgr1.
      v_output_ag-bu = v_knvv-kvgr1.
      v_output_gs-bu = v_knvv-kvgr1.
    endif.

  elseif s_mbuun[] is not initial and s_cbuun[] is initial.

    v_output_dt-bu = v_mara-prdha+1(2).
    v_output_ag-bu = v_mara-prdha+1(2).
    v_output_gs-bu = v_mara-prdha+1(2).
*   Determine Material Business Unit, Line of Business and PAC1
*   for Header as well as Item Data
    perform get_mbu_lob_pac1_data.

  endif.

endform.                    " GET_BUSUNIT_LOBUS_PAC1_DATA1

*&--------------------------------------------------------------------*
*&      Form  I_MARA1_FILTER
*&--------------------------------------------------------------------*
* Filter I_MARA1 When Either Material BU or Line of Business (LOB) or
* PAC1 are not left Balnk
*---------------------------------------------------------------------*
form i_mara1_filter .

  if not i_mara1[] is initial.

    sort i_mara1 by prdha.

    if not s_mbuun[] is initial.
      delete i_mara1 where not prdha+1(2) in s_mbuun.
    endif.

    if not s_lobus[] is initial.
      delete i_mara1 where not prdha+3(3) in s_lobus.
    endif.

    if not s_pac1[] is initial.
      delete i_mara1 where not prdha+6(3) in s_pac1.
    endif.

    if i_mara1[] is initial.
      v_flag = 'X'.
    endif.

  endif.

endform.                    " I_MARA1_FILTER

*&--------------------------------------------------------------------*
*&      Form  I_LIPS_FILTER
*&--------------------------------------------------------------------*
* Filter I_LIPS When Either material BU or Line of Business (LOB) or
* PAC1 are not left Balnk
*---------------------------------------------------------------------*
form i_lips_filter .

  clear: i_lips,
         i_mara1.
  sort:  i_lips by matnr,
         i_mara1 by matnr.

  loop at i_lips.

    read table i_mara1 with key matnr = i_lips-matnr binary search.

    if sy-subrc <> 0.
*                                                   Begin of SIR 301978
*     Flag has been set to delete entries from the internal table
*     i_lips out side of the loop.
*     delete i_lips.
      i_lips-del_flg = 'X'.
      modify i_lips.
*                                                     End of SIR 301978
    endif.
  endloop.

  delete i_lips where del_flg = 'X'.                  "(+) SIR 301978

  if i_lips[] is initial.
    v_flag = 'X'.
    message i089 with text-i02.
    leave list-processing.
  endif.

endform.                    " I_LIPS_FILTER

*&--------------------------------------------------------------------*
*&      Form  READ_DATA_FROM_MARM
*&--------------------------------------------------------------------*
*  Get Units of Measure for Material
*---------------------------------------------------------------------*
form read_data_from_marm .

* Get Units of Measure for Material
  select matnr                                               " Material
         meinh                            " Alternative Unit of Measure
         umrez                                              " Numerator
         umren                                            " Denominator
         from marm
        into table i_marm
        for all entries in i_temp_lips
        where matnr = i_temp_lips-matnr.
  if sy-subrc = 0.
    sort i_marm by meinh.
  endif.

endform.                    " READ_DATA_FROM_MARM

*&--------------------------------------------------------------------*
*&      Form  I_MARM_PALLET_FILL
*&--------------------------------------------------------------------*
* Get Alternative Unit of Measure for Pallets
*---------------------------------------------------------------------*
form i_marm_pallet_fill.
  loop at i_marm where meinh = v_z0234_uom-zpaluom.
    if sy-subrc = 0.
      move-corresponding i_marm to i_marm_pallet.
    endif.
    append i_marm_pallet.
    clear i_marm_pallet.
  endloop.
endform.                    " I_MARM_PALLET_FILL

*&--------------------------------------------------------------------*
*&      Form  I_MARM_CASE_FILL
*&--------------------------------------------------------------------*
* Get Alternative Unit of Measure for Cases
*---------------------------------------------------------------------*
form i_marm_case_fill.

  loop at i_marm where meinh = v_z0234_uom-zcsuom.
    if sy-subrc = 0.
      move-corresponding i_marm to i_marm_case.
    endif.
    append i_marm_case.
    clear i_marm_case.
  endloop.

endform.                    " I_MARM_CASE_FILL
*&--------------------------------------------------------------------*
*&      Form  GET_BUSUNIT_LOBUS_PAC1_DATA2
*&--------------------------------------------------------------------*
* Populate Business Unit,Line of Business and PAC1 Values for Item Data
*---------------------------------------------------------------------*
form get_busunit_lobus_pac1_data2.

* When Customer BU, Material BU, LOB and PAC1 are Left Blank.

  read table i_mara1 into v_mara with key matnr = v_lips-matnr
                                                 binary search.
  if ( s_cbuun[] is initial and  s_mbuun[] is initial and
      s_lobus[] is initial and s_pac1[] is initial ).
    v_output_dt-bu          = v_mara-prdha+1(2).
    v_output_ag-bu          = v_mara-prdha+1(2).
    v_output_gs-bu          = v_mara-prdha+1(2).
* When Material BU, LOB and PAC1 are Left Blank.
  elseif s_mbuun[] is initial and s_cbuun[] is not initial.
    clear v_cbuun.
    read table s_cbuun into v_cbuun with key low = v_knvv-kvgr1.
    if sy-subrc = 0.
      v_output_dt-bu          = v_mara-prdha+1(2).
      v_output_ag-bu          = v_mara-prdha+1(2).
      v_output_gs-bu          = v_mara-prdha+1(2).
    endif.
  elseif s_mbuun[] is not initial and s_cbuun[] is initial.
    v_output_dt-bu = v_mara-prdha+1(2).
    v_output_ag-bu = v_mara-prdha+1(2).
    v_output_gs-bu = v_mara-prdha+1(2).
  endif.
* Determine Material Business Unit, Line of Business and PAC1
* for Header as well as Item Data
    perform get_mbu_lob_pac1_data.
*  endif.

endform.                    " GET_BUSUNIT_LOBUS_PAC1_DATA2

*&--------------------------------------------------------------------*
*&      Form  GET_VOLUME_DATA
*&--------------------------------------------------------------------*
* To Get the Volume Data.
*---------------------------------------------------------------------*
form get_volume_data.

  if p_voldl = 'X'.
*   Get Volume data from Delivery
    perform get_volume_from_lips.
  elseif p_volmd = 'X'.
*   Get Volume data from Master data
    perform get_volume_from_mara.
  endif.

endform.                    " GET_VOLUME_DATA

*&--------------------------------------------------------------------*
*&      Form  GET_VOLUME_FROM_LIPS
*&--------------------------------------------------------------------*
* Get Volume data from Delivery
*---------------------------------------------------------------------*
form get_volume_from_lips .

  if v_lips-voleh = c_vom.
    v_output_dt-volume  = v_lips-volum.
    v_output_ag-volume  = v_lips-volum.
    v_output_gs-volume  = v_lips-volum.                     " SIR 34606
  else.
* Conversion Of Volume Units (Other Than Cubic Metter [M3] to be
* converted to Metter Cube.
    perform z_volume_conversion
         using v_lips-volum v_lips-voleh c_vom v_volume.
    v_output_dt-volume  = v_volume.
    v_output_ag-volume  = v_volume.
    v_output_gs-volume  = v_volume.
  endif.

endform.                    " GET_VOLUME_FROM_LIPS
*&--------------------------------------------------------------------*
*&      Form  GET_VOLUME_FROM_MARA
*&--------------------------------------------------------------------*
* Get Volume data from Master data
*---------------------------------------------------------------------*
form get_volume_from_mara .
  data: v_temp_volum like lips-volum.

  read table i_mara1 into v_mara with key matnr = v_lips-matnr
                                                 binary search.
  if sy-subrc = 0.
    v_temp_volum = v_mara-volum.
    if v_mara-voleh = c_vom.
      v_output_dt-volume  = v_temp_volum * v_lips-lgmng.
      v_output_ag-volume  = v_temp_volum * v_lips-lgmng.
      v_output_gs-volume  = v_temp_volum * v_lips-lgmng.
    else.
* Conversion Of Volume Units (Other Than Metter Cube-M3 to be converted
* to Metter Cube.
      v_temp_volum = v_temp_volum * v_lips-lgmng.
      perform z_volume_conversion
         using v_temp_volum v_mara-voleh c_vom v_volume.
      v_output_dt-volume  = v_volume.
      v_output_ag-volume  = v_volume.
      v_output_gs-volume  = v_volume.
    endif.
  endif.
endform.                    " GET_VOLUME_FROM_MARA
*&--------------------------------------------------------------------*
*&      Form  Z_VOLUME_CONVERSION
*&--------------------------------------------------------------------*
* Conversion Of Volume Units (Other Than Metter Cube-M3 to be converted
* to Metter Cube.
*---------------------------------------------------------------------*
form z_volume_conversion using v_in   like lips-volum
                               v_unit like t006-msehi
                               v_vom  like t006-msehi
                               v_out  like lips-volum.

  call function 'UNIT_CONVERSION_SIMPLE'
    exporting
      input                = v_in
      unit_in              = v_unit
      unit_out             = v_vom
    importing
      output               = v_out
    exceptions
      conversion_not_found = 1
      division_by_zero     = 2
      input_invalid        = 3
      output_invalid       = 4
      overflow             = 5
      type_invalid         = 6
      units_missing        = 7
      unit_in_not_found    = 8
      unit_out_not_found   = 9
      others               = 10.
endform.                                          " Z_VOLUME_CONVERSION
*&--------------------------------------------------------------------*
*&      Form GET_MBU_LOB_PAC1_DATA
*&--------------------------------------------------------------------*
* Determine Material Business Unit, Line of Business and PAC1.
*---------------------------------------------------------------------*
form get_mbu_lob_pac1_data.
  clear: i_mara1.
  clear: v_mara,
         v_mbuun,
         v_lobus,
         v_pac1.
* When Material Business Unit in not Blank.
  if not s_mbuun[] is initial.
    read table i_mara1 into v_mara with key matnr = v_lips-matnr
                                                    binary search.
    if sy-subrc = 0.
      read table s_mbuun into v_mbuun with key low = v_mara-prdha+1(2).
      if sy-subrc = 0.
        v_output_dt-bu = v_mara-prdha+1(2).
        v_output_ag-bu = v_mara-prdha+1(2).
        v_output_gs-bu = v_mara-prdha+1(2).
      endif.
    endif.
  endif.

* When Line Of Bisuness in not Blank.
  if not s_lobus[] is initial.
    read table i_mara1 into v_mara with key matnr = v_lips-matnr
                                                    binary search.
    if sy-subrc = 0.
      read table s_lobus into v_lobus with key low = v_mara-prdha+3(3).
      if sy-subrc = 0.
* When S_MBUUN[] is also Initial
        if s_mbuun[] is initial.
          v_output_dt-bu = v_mara-prdha+1(2).
          v_output_ag-bu = v_mara-prdha+1(2).
          v_output_gs-bu = v_mara-prdha+1(2).
        endif.
        v_output_dt-lobus = v_mara-prdha+3(3).
        v_output_ag-lobus = v_mara-prdha+3(3).
        v_output_gs-lobus = v_mara-prdha+3(3).
      endif.
    endif.
* When PAC1 is not Blank.
  elseif not s_pac1[] is initial.
    read table i_mara1 into v_mara with key matnr = v_lips-matnr
                                                    binary search.
    if sy-subrc = 0.
      read table s_pac1 into v_pac1 with key low = v_mara-prdha+6(3).
      if sy-subrc = 0.
* When S_MBUUN[] is also Initial
        if s_mbuun[] is initial.
          v_output_dt-bu = v_mara-prdha+1(2).
          v_output_ag-bu = v_mara-prdha+1(2).
          v_output_gs-bu = v_mara-prdha+1(2).
        endif.
* When S_LOBUS[] is also Initial.
        if s_lobus[] is initial.
          v_output_dt-lobus = v_mara-prdha+3(3).
          v_output_ag-lobus = v_mara-prdha+3(3).
          v_output_gs-lobus = v_mara-prdha+3(3).
        endif.
        v_output_dt-pac1 = v_mara-prdha+6(3).
        v_output_ag-pac1 = v_mara-prdha+6(3).
        v_output_gs-pac1 = v_mara-prdha+6(3).
      endif.
    endif.
  endif.

endform.                    " GET_MBU_LOB_PAC1_DATA
*&--------------------------------------------------------------------*
*&      Form  filter_data_for_customer_bu
*&--------------------------------------------------------------------*
* Filter I_LIPS for Customer BU, When Customer Bu not left Blank.
*---------------------------------------------------------------------*
form filter_likp_lips_mara_custbu.

  if not s_cbuun[] is initial.

    sort i_knvv by kunnr.
    sort i_likp by kunag.

*   Filter I_LIKP for I_KNVV
    loop at i_likp.

      clear i_likp-del_flg.                             "(+) SIR 301978

      read table i_knvv with key kunnr = i_likp-kunag binary search.
      if sy-subrc ne 0.
*                                                   Begin of SIR 301978

*       Flag has been set to delete entries from the internal table
*       i_likp out side the loop.

*       delete i_likp.
        i_likp-del_flg = 'X'.
        modify i_likp.
*                                                     End of SIR 301978
        delete i_likp.
      endif.

    endloop.

    delete i_likp where del_flg = 'X'.                  "(+) SIR 301978

    if not i_likp[] is initial.

      sort i_likp by vbeln.
      sort i_lips by vbeln.

*      Filter I_LIPS for I_LIKP.
      loop at i_lips.

        clear i_lips-del_flg.                           "(+) SIR 301978

        read table i_likp with key vbeln = i_lips-vbeln binary search.
        if sy-subrc ne 0.

*                                                   Begin of SIR 301978

*   Flag has been set to delete entries from the internal table i_lips
*   out side the loop.
*         delete i_lips.
          i_lips-del_flg = 'X'.
          modify i_lips.
*                                                     End of SIR 301978

        endif.
      endloop.

      delete i_lips where del_flg = 'X'.                "(+) SIR 301978

      if i_lips[] is initial.
        v_flag = 'X'.
         message i089 with text-i02.
         leave list-processing.
      endif.
    else.
      v_flag = 'X'.
       message i089 with text-i04.
       leave list-processing.
    endif.

* Filter I_MARA1 for I_LIPS.
    if not i_lips[] is initial.
      sort i_mara1 by matnr.
      sort i_lips by matnr.
      loop at i_mara1.
        read table i_lips with key matnr = i_mara1-matnr binary search.
        if sy-subrc ne 0.
*                                                   Begin of SIR 301978

*   Flag has been set to delete entries from the internal table i_mara1
*    out side the loop.
*         delete i_mara1.
          i_mara1-del_flg = 'X'.
          modify i_mara1.
*                                                     End of SIR 301978
        endif.
      endloop.

      delete i_mara1 where del_flg = 'X'.               "(+) SIR 301978

      if i_mara1[] is initial.
        v_flag = 'X'.
*         message i089 with text-i03.
*         leave list-processing.
      endif.
    else.
      v_flag = 'X'.
       message i089 with text-i02.
       leave list-processing.
    endif.
  endif.

endform.                    " filter_likp_lips_mara_custbu
*&--------------------------------------------------------------------*
*&      Form  i_knvv_fill_data
*&--------------------------------------------------------------------*
* Populate i_knvv and filter for Customer-BU
* Get data for the sold-to customer
*---------------------------------------------------------------------*
form i_knvv_fill_data .
*                                                   Begin of SIR 301978

* Deleting duplicate entries from delivery header table by comparing
* Sold-to-party,sales organization
  clear   i_temp_likp.
  refresh i_temp_likp.

  i_temp_likp[] = i_likp[].

  sort i_temp_likp by kunag vkorg.
  delete adjacent duplicates from i_temp_likp comparing kunag vkorg.

*                                                     End of SIR 301978

  select kunnr                                        " Customer number
         ktgrd                               " Account assignment group
         kvgr1                                       " Customer group 1
   into table i_knvv
   from knvv
*                                                   Begin of SIR 301978
*  for all entries in i_likp
*  where kunnr = i_likp-kunag and
*        vkorg = i_likp-vkorg.
    for all entries in i_temp_likp
  where kunnr = i_temp_likp-kunag and
        vkorg = i_temp_likp-vkorg.
*                                                     End of SIR 301978

  if sy-subrc = 0.

    sort i_knvv by kunnr ktgrd kvgr1.
    delete adjacent duplicates from i_knvv comparing kunnr.

    if not s_cbuun[] is initial.
      sort i_knvv by kvgr1.

*     Filter I_KNVV When Customer Business Unit is not Left Blank.
      delete i_knvv where kvgr1 not in s_cbuun.
      if i_knvv[] is initial.
        v_flag = 'X'.
      endif.
    endif.
*                                                   Begin of SIR 301978
    clear   i_temp_likp.
    refresh i_temp_likp.
*                                                     End of SIR 301978

  endif.
endform.                    " i_knvv_fill_data

*&---------------------------------------------------------------------*
*&      Form  get_data_t001k
*&---------------------------------------------------------------------*
*  * Get company code for the plant,  use in zbsn0001
*----------------------------------------------------------------------*
FORM get_data_t001k .

* Get company code for the plant,  use in zbsn0001
  select single bukrs into v_comp from t001k
           where bwkey = p_werks.

  if sy-subrc ne 0.
    v_flag = 'X'.
     message i089 with text-i01.
     leave list-processing.
  endif.

ENDFORM.                    " get_data_t001k

*&---------------------------------------------------------------------*
*&      Form  get_data_tvswz
*&---------------------------------------------------------------------*
*  * Get shipping points by plant
*----------------------------------------------------------------------*
FORM get_data_tvswz .

* Get shipping points by plant
  select vstel into table i_tvswz from tvswz
             where werks = p_werks.

ENDFORM.                    " get_data_tvswz

*&---------------------------------------------------------------------*
*&      Form  get_data_Z0234
*&---------------------------------------------------------------------*
* Get alternative UoM for pallet and case for a plant. It is correct
* To check VSTEL against parameter for the plant.
*----------------------------------------------------------------------*
FORM get_data_Z0234 .

*   Get alternative UoM for pallet and case for a plant. It is correct
*   To check VSTEL against parameter for the plant.
    select vstel zpaluom zcsuom
*           into (v_z0234_zpaluom, v_z0234_zcsuom)             " 032383
           into table i_z0234                                  " 032383
           from z0234
*           where vstel = p_werks.                             " 032383
           for all entries in i_tvswz                          " 032383
           where vstel = i_tvswz-vstel.                        " 032383


ENDFORM.                    " get_data_Z0234

*&---------------------------------------------------------------------*
*&      Form  get_data_mkpf
*&---------------------------------------------------------------------*
*     get the material document from MKPF
*----------------------------------------------------------------------*
FORM get_data_mkpf .

* to get the material document from MKPF
    select vgart
           xblnr
      from mkpf
      into table i_mkpf
     where budat in s_wadat.

ENDFORM.                    " get_data_mkpf

*&---------------------------------------------------------------------*
*&      Form  get_data_likp
*&---------------------------------------------------------------------*
*  Get the delivery header data from LIKP
*----------------------------------------------------------------------*
FORM get_data_likp .

  select vbeln                       " Delivery
         vstel                       " shipping point
         lfart                       " delivery type
         vkorg                       " Sales organization
         kunag                       " sold to party
         kunnr                       " ship to party
         btgew                       " total weight
         gewei                       " unit of weight
         anzpk                       " Number of Packages
         volum                       " Volume
         voleh                       " Volume Unit
         vtwiv                       " Distribution channel
         spaiv                       " Division
         wadat_ist                   " goods issue date
    into table i_likp
    from likp
     for all entries in i_mkpf
   where vbeln eq i_mkpf-xblnr
     and vstel in r_vstel.

ENDFORM.                    " get_data_likp
*&---------------------------------------------------------------------*
*&      Form  get_data_lips
*&---------------------------------------------------------------------*
*    Get data for the delivery lines
*----------------------------------------------------------------------*
FORM get_data_lips .

  select vbeln                     " delivery
         posnr                     " delivery line
         matnr                     " material
         lgort                     " storage location
         prodh                     " product hierarchy
         meins                     " base UoM
         brgew                     " gross weight
         gewei                     " unit of weight
         volum                     " Volume           SIR 61880
         voleh                     " Volume Unit      SIR 61880
         lgmng                     " Actual delivery quantity
         komkz                  " Indicator for picking control
         mtart                    " Material type   " sir 37838
    into table i_lips
    from lips
     for all entries in i_likp
   where vbeln = i_likp-vbeln.

*                                                   Begin of SIR 301978
*    and lgort in s_lgort
*    and mtart in s_mtart.

  if sy-subrc = 0.

*   Deleting the data from i_lips comparing storage location and
*   material type
    delete i_lips where not lgort in s_lgort.
    delete i_lips where not mtart in s_mtart.

    sort i_lips by matnr.

  endif.
*                                                     End of SIR 301978
ENDFORM.                    " get_data_lips

*&---------------------------------------------------------------------*
*&      Form  get_data_mara
*&---------------------------------------------------------------------*
* Get Data From MARA (Material Master) to Read Material Weight and
* Material Voluem from Master Data.
*----------------------------------------------------------------------*

FORM get_data_mara .

  select matnr
         prdha
         brgew
         gewei
         volum
         voleh
    into table i_mara1
    from mara
*    for all entries in i_lips
*  where matnr = i_lips-matnr.
    for all entries in i_temp_lips
  where matnr = i_temp_lips-matnr.

ENDFORM.                    " get_data_mara

*&---------------------------------------------------------------------*
*&      Form  get_data_kna1
*&---------------------------------------------------------------------*
*    Get data for the ship to party
*----------------------------------------------------------------------*
FORM get_data_kna1 .

  select kunnr
         land1
    into table i_kna1
    from kna1
     for all entries in i_temp_likp
   where kunnr = i_temp_likp-kunnr.

ENDFORM.                    " get_data_kna1

*&---------------------------------------------------------------------*
*&      Form  get_data_vepo
*&---------------------------------------------------------------------*
*   Get shipping unit number and delivery
*----------------------------------------------------------------------*
FORM get_data_vepo .

  select venum                       " shipping unit number
         vbeln                       " delivery
    into table i_vepo
    from vepo
     for all entries in i_temp_lips
   where vbeln = i_temp_lips-vbeln.

ENDFORM.                    " get_data_vepo

*&---------------------------------------------------------------------*
*&      Form  get_data_vekp
*&---------------------------------------------------------------------*
*   Get actual weight
*----------------------------------------------------------------------*
FORM get_data_vekp .

  select venum                     " shipping unit number
         brgew                     " total weight
         gewei_max                 " unit of weight
         vpobjkey                  " key of assigned object
    into table i_vekp
    from vekp
     for all entries in i_vepo
   where venum = i_vepo-venum.

ENDFORM.                    " get_data_vekp

Code Formatted by: Alvaro Tejada Galindo on Mar 19, 2008 5:26 PM

1 REPLY 1

Jelena
Active Contributor
0 Kudos

Since this is your first post, let me clue you in. This forum is meant for asking very short and specific questions. For example, if you've asked, how could you improve a particular one SELECT statement, I'm sure many people would have helped you.

But you cannot seriously expect someone on this forum to spend his/her time and review such a long program. For this people are normally getting paid, you know.