Showing posts with label Program. Show all posts
Showing posts with label Program. Show all posts

Thursday, 25 January 2024

Material Availability Z Program


 report  z_mm_mb52.


tables:marcmardvbaplipsekpovbfaekbemarmvbbemarambew,mkol.
type-poolsslis.

ranges r_auart for vbbe-auart.

databegin of inv occurs 100,
       sel,
       werks like mard-werks" Plant
       lgort like mard-lgort" SLoc
       matnr like mard-matnr" Material
       mtart like mara-mtart" Material Type
       stprs like mbew-stprs" Standard Price
       avail  type  decimals ,"VALUE '-xxxx' ,"LIKE MARD-LABST, " Available
       labst type decimals ,"MARD-LABST, " Unrestricted use
       insme like mard-insme" Quality Inspection
       retme like mard-retme" Returns
       trans like marc-umlmc" Stock in transit (calculated)
       umlmc like marc-umlmc" Stock Transfer (plant)
       umlme like mard-umlme" Transfer (SLoc)
       wesbs like ekbe-wesbs" GR Blocked Stock
       trame like marc-trame" Stock in transit
       speme like mard-speme" Blocked
       kwmeng like vbap-kwmeng" Sales orders
       lfimg  type decimals ,"LIKE LIPS-LFIMG, " Scheduled for Delivery
       menge like ekpo-menge" Open Purch. Orders
       value like mbew-salk3" Stock Value (Calculated)
       meins like mara-meins" Unit of measure
       einme like mard-einme" Restricted Batches
       vlabst like mbew-salk3" Unrestricted use Value
       vinsme like mbew-salk3" Quality Inspection Value
       vretme like mbew-salk3" Returns Value
       vtrame like mbew-salk3" Stock in transit Value
       veinme like mbew-salk3" Restricted Batches Value
       vspeme like mbew-salk3" Blocked Value
       lfires type decimals "LIKE LIPS-LFIMG,
       lfisto type decimals " LIKE LIPS-LFIMG,
       lfisls type decimals " LIKE LIPS-LFIMG,
       outfak type decimals ,
       lines type i,
       cols type i,
       labstc(15),
       lfiresc(15),
       lfistoc(15),
       lfislsc(15),
       availc(15),
       outfakc(15),
     end of inv.

data invcol like table of inv with header line,
       invrow like table of inv with header line.

types :begin of ty_inv,
       werks type mard-werks" Plant
       lgort type mard-lgort" SLoc
       matnr type mard-matnr" Material
       avail  type decimals ,"LIKE MARD-LABST, " Available
       labst type decimals ,"MARD-LABST, " Unrestricted use
       lfires type decimals "LIKE LIPS-LFIMG,
       lfisto type decimals " LIKE LIPS-LFIMG,
       lfisls type decimals " LIKE LIPS-LFIMG,
       outfak type decimals ,
       lines type i,
       cols type i,
       end of ty_inv.

data t_inv type standard table of ty_inv.


databegin of t_vbbe occurs 100,
        sel,
        vbeln type vbbe-vbeln,
        posnr type vbbe-posnr,
        matnr type vbbe-matnr,
        werks type vbbe-werks,
        lgort type vbbe-lgort,
        omeng type decimals 0"TYPE VBBE-OMENG,
        mbdat type vbbe-mbdat,
        vbgrp(2),
      end of t_vbbe.

databegin of t_lipcol occurs 100,
        vbeln type vbbe-vbeln,
        posnr type vbbe-posnr,
        matnr type vbbe-matnr,
        werks type vbbe-werks,
        lgort type vbbe-lgort,
        omeng type vbbe-omeng,
        mbdat type vbbe-mbdat,
        vbgrp(2),
     end of t_lipcol.

data begin of t_87 occurs 100,
        matnr type vbbe-matnr,
        werks type vbbe-werks,
        lgort type vbbe-lgort,
        omeng type vbbe-omeng,
       end of t_87.

data begin of t_80 occurs 100,
        matnr type vbbe-matnr,
        werks type vbbe-werks,
        lgort type vbbe-lgort,
        omeng type vbbe-omeng,
       end of t_80.

data begin of t_40 occurs 100,
        matnr type vbbe-matnr,
        werks type vbbe-werks,
        lgort type vbbe-lgort,
        omeng type vbbe-omeng,
       end of t_40.

databegin of t_mdbs occurs 100,
        ebeln type mdbs-ebeln,
        ebelp type mdbs-ebelp,
        matnr type mdbs-matnr,
        werks type mdbs-werks,
        lgort type mdbs-lgort,
        menge type mdbs-menge,
        wemng type mdbs-wemng,
        mengef type mdbs-menge,
      end of t_mdbs.

databegin of t_mdbso occurs 100,
        matnr type mdbs-matnr,
        werks type mdbs-werks,
        lgort type mdbs-lgort,
        mengef type mdbs-menge,
      end of t_mdbso.

data begin of it_datah occurs 100,
       matnr(40type c,
       werks(40type c,
       lgort(40type c,
       labst(40type c,
       lfires(40type c,
       lfisto(40type c,
       lfisls(40type c,
*       LFIMG(40) TYPE C,
       avail(40type c,
       outfak(40),
*       COLS TYPE I,
       end of it_datah.

data begin of it_datai occurs 100,
       matnr like mard-matnr" Material
       werks like mard-werks" Plant
       lgort like mard-lgort" SLoc
       labst  type decimals ,
       lfires  type decimals 0,
       lfisto  type decimals 0,
       lfisls  type decimals 0,
*       LFIMG  TYPE P DECIMALS 0 ,
       avail  type decimals ,
       outfak  type decimals ,
       end of it_datai.


datafieldtab type slis_t_fieldcat_alv,
      heading  type slis_t_listheader,
      layout   type slis_layout_alv,
      events   type slis_t_event,
      repname  like sy-repid,
      f2code   like sy-ucomm value  '&ETA',
      g_save(1type c,
      g_exit(1type c,
      g_variant like disvariant,
      gx_variant like disvariant.

data  p_fieldtab  type table of slis_fieldcat_alv.

data:  table_n type i,
       gd_percent(10type i.

*
data:  x_layout     type slis_layout_alv.

data :  wa_fcat_inv type slis_fieldcat_alv,
        wa_fcat_vbbe type slis_fieldcat_alv,
        it_fcat_inv type slis_t_fieldcat_alv,
        it_fcat_vbbe type slis_t_fieldcat_alv.
data :
* Alv
      wa_top_inv type slis_listheader,
      wa_top_vbbe type slis_listheader,
      it_top_inv type slis_t_listheader,
      it_top_vbbe type slis_t_listheader,
      it_fcat_ekpo type slis_t_fieldcat_alv,

      wa_event type slis_alv_event,
      wa_event_inv type slis_alv_event,
      wa_event_vbbe type slis_alv_event,
      it_event type slis_t_event,
      it_event_vbbe type slis_t_event,
      it_event_inv type slis_t_event,

      t_sort type  slis_t_sortinfo_alv,
      sort like line of t_sort,

      r_ucomm    type sy-ucomm,
      rs_selfield type slis_selfield,
      v_selfield type slis_selfield-value,
      v_prog  type sy-repid,
      v_name  type sy-uname.

*--- Gui
data ok_code type sy-ucomm,
       save_ok like ok_code,
       output  like ok_code,
*       G_OUTDEL TYPE LIPS-VBELN,
       g_werks type lips-werks,
       g_lgort type lips-lgort,
       txt2_werks type string,
       txt2_lgort type string,
       g_scan(13type c,
       init.


*&SPWIZARD: DECLARATION OF TABLECONTROL 'TBL_CTR_INV' ITSELF
controlstbl_ctr_inv type tableview using screen 0102.

data:
*      cols TYPE CXTAB_COLUMN,
      cols like line of tbl_ctr_inv-cols,
      lines type i.
data  g_vbeln(4type c.

initialization.
  repname sy-repid.
  v_prog sy-repid.
  v_name sy-uname.

  selection-screen begin of block sel with frame title text-001.
  select-optionss_werks for marc-werks default '1000'" Plant
                  s_matnr for marc-matnr" Material
                  s_lgort for mard-lgort"Storage Location
                  s_mtart for mara-mtart no-display" Material Type
                  matart for mara-mtart no-display,
                  matkla for mara-matkl no-display,
                  ekgrup for marc-ekgrp no-display,
                  so_sobkz for mkol-sobkz  no-display .
  selection-screen end of block sel.

  selection-screen begin of screen 0100 as window title txtblk03.
  parameters:  p_pdirp   type pfeflnamel default 'D:\',
               psavep    type string default 'Stock Availability.XLS'.
  selection-screen end of screen 0100.



at selection-screen.
  perform check_entry.

start-of-selection.
  perform get_data.

  call screen 0102.    "SINI

**  Don't Delete This
*  PERFORM build_fieldcat.
*  PERFORM L_build_layout.
*  PERFORM event_inv.
**  PERFORM sort_alv.
*  PERFORM View.
*  PERFORM ucomm_inv USING r_ucomm
*                     CHANGING rs_selfield.
***********************************************

top-of-page.
  perform top_inv.

top-of-page during line-selection.
  perform top_vbbe.

end-of-selection.
*&---------------------------------------------------------------------*
*&      Form  INITIALIZE_VARIANT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form initialize_variant.
  g_save 'A'.
  clear g_variant.
  g_variant-report repname.
  gx_variant g_variant.
  call function 'REUSE_ALV_VARIANT_DEFAULT_GET'
    exporting
      i_save     g_save
    changing
      cs_variant gx_variant
    exceptions
      not_found  2.
  if sy-subrc 0.
*    P_VARI = GX_VARIANT-VARIANT.
  endif.
endform.                               " INITIALIZE_VARIANT

*&---------------------------------------------------------------------*
*&      Form  GET_MARD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form get_mard.

  select  mard~matnr mard~lgort mard~werks mard~labst
          mard~insme mard~retme mard~umlme mard~speme mard~einme
          mara~meins
           into corresponding fields of inv
    from mard
    inner join mara as mara on mara~matnr mard~matnr
                         where mard~matnr in s_matnr
                         and   mard~werks in s_werks
                         and   mard~lgort in s_lgort.
    append inv.
  endselect.

  perform filter_by_material_type.
endform.                               " GET_MARD

*&---------------------------------------------------------------------*
*&      Form  FILTER_BY_MATERIAL_TYPE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form filter_by_material_type.

  loop at inv.
    clear inv-mtart.
    select single mtart
           into inv-mtart
           from mara
           where matnr eq inv-matnr
           and   mtart in s_mtart.
    if sy-subrc eq 0.
      modify inv.
    else.
      delete inv.
    endif.
  endloop.

endform.                    " FILTER_BY_MATERIAL_TYPE

**&---------------------------------------------------------------------*
*&      Form  GET_LIPS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form get_vbbe."LIPS.
  datalfimg like inv-lfimg.
  loop at inv.
    clearlfimginv-lfimg.
    select omeng
           into lfimg
           from vbbe
           where matnr eq inv-matnr
           and   werks eq inv-werks
           and   lgort eq inv-lgort "VBTYP EQ 'J'.
           and   vbtyp eq 'J'.
      add lfimg to inv-lfimg.
    endselect.
    modify inv.
  endloop.
endform.                               " GET_LIPS
*&---------------------------------------------------------------------*
*&      Form  GET_VBAP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form get_vbap.
  datakwmeng like inv-kwmeng.
  loop at inv.
    clearkwmenginv-kwmeng.
    select omeng
           into kwmeng
           from vbbe
           where matnr eq inv-matnr
           and   werks eq inv-werks
           and   vbtyp eq 'C'.
      add kwmeng to inv-kwmeng.
    endselect.
    inv-avail inv-labst inv-insme inv-kwmeng inv-lfimg.
    modify inv.
  endloop.
endform.                               " GET_VBAP

*&---------------------------------------------------------------------*
*&      Form  GET_PRICE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form get_price.

  loop at inv.
    select single verpr  "STPRS
           from mbew
           into inv-stprs
           where matnr eq inv-matnr
           and   bwkey eq inv-werks
           and   bwtar eq space.

    if sy-subrc eq 0.
      inv-value inv-stprs *
                inv-labst + inv-insme + inv-trans + inv-speme ).

      inv-vlabst  inv-labst * inv-stprs.
      inv-vinsme  inv-insme * inv-stprs.
      inv-vretme  inv-retme * inv-stprs.
      inv-vtrame  inv-trame * inv-stprs 100.
      inv-veinme  inv-einme * inv-stprs.
      inv-vspeme  inv-speme * inv-stprs.
      inv-avail inv-labst inv-lfimg.
      if inv-labst 0.
        inv-labstc space.
      else.
        inv-labstc inv-labst.
      endif.

      if inv-lfires 0.
        inv-lfiresc space.
      else.
        inv-lfiresc inv-lfires.
      endif.

      if inv-lfisto 0.
        inv-lfistoc space.
      else.
        inv-lfistoc inv-lfisto.
      endif.

      if inv-lfisls 0.
        inv-lfislsc space.
      else.
        inv-lfislsc inv-lfisls.
      endif.

      if inv-avail 0.
        inv-availc space.
      else.
        inv-availc inv-avail.
      endif.

      if inv-outfak 0.
        inv-outfakc space.
      else.
        inv-outfakc inv-outfak.
      endif.

      modify inv.
    endif.
  endloop.

endform.                    " GET_PRICE
*&---------------------------------------------------------------------*
*&      Form  CHECK_ENTRY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form check_entry.

  call function 'MMIM_ENTRYCHECK_MAIN'
    tables
      it_matnr s_matnr
      it_werks s_werks
      it_lgort s_lgort
      it_ekgrp ekgrup
      it_sobkz so_sobkz.

endform.                    " CHECK_ENTRY
*&---------------------------------------------------------------------*
*&      Form  PROGRESS_BAR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_2919   text
*      -->P_SY_TABIX  text
*      -->P_P_MATE_LINE  text
*----------------------------------------------------------------------*
form progress_bar  using  p_value
                          p_tabix
                          p_nlines.
  dataw_text(40),
        w_percentage type p,
        w_percent_char(10),
        w_rec type string.

  w_percentage p_tabix / p_nlines 100.
  w_percent_char w_percentage.
  shift w_percent_char left deleting leading ' '.
  concatenate p_value w_percent_char ' % Complete'(003into w_text separated by space.
* This check needs to be in otherwise when looping around big tables
* SAP will re-display indicator too many times causing report to run
* very slow. (No need to re-display same percentage anyway)
  if w_percentage gt gd_percent or p_tabix eq 1.
    call function 'SAPGUI_PROGRESS_INDICATOR'
      exporting
        percentage w_percentage
        text       w_text.
    gd_percent w_percentage.
  endif.

endform.                    " PROGRESS_BAR
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form build_fieldcat .

  refresh it_fcat_inv.
  if inv is not initial.
    data lv_col type value 0.

    lv_col                 + lv_col.
    wa_fcat_inv-col_pos   lv_col.
    wa_fcat_inv-fieldname 'MATNR'.
    wa_fcat_inv-tabname   'IT_inv'.
    wa_fcat_inv-seltext_l 'Material'.
    append wa_fcat_inv to it_fcat_inv.
    clear wa_fcat_inv.

    lv_col                 + lv_col.
    wa_fcat_inv-col_pos   lv_col.
    wa_fcat_inv-fieldname 'WERKS'.
    wa_fcat_inv-tabname   'IT_inv'.
    wa_fcat_inv-seltext_l 'Plant'.
    append wa_fcat_inv to it_fcat_inv.
    clear wa_fcat_inv.

    lv_col                 + lv_col.
    wa_fcat_inv-col_pos   lv_col.
    wa_fcat_inv-fieldname 'LGORT'.
    wa_fcat_inv-tabname   'IT_inv'.
    wa_fcat_inv-seltext_l 'Sloc'.
    append wa_fcat_inv to it_fcat_inv.
    clear wa_fcat_inv.

    lv_col                 + lv_col.
    wa_fcat_inv-col_pos   lv_col.
    wa_fcat_inv-fieldname 'LABST'.
    wa_fcat_inv-tabname   'IT_inv'.
    wa_fcat_inv-no_zero   'X'.
    wa_fcat_inv-seltext_l 'Unrestricted Use'.
    append wa_fcat_inv to it_fcat_inv.
    clear wa_fcat_inv.

    lv_col                 + lv_col.
    wa_fcat_inv-col_pos   lv_col.
    wa_fcat_inv-fieldname 'LFIRES'.
    wa_fcat_inv-tabname   'IT_inv'.
    wa_fcat_inv-no_zero   'X'.
    wa_fcat_inv-seltext_l 'DO Reserved (87***)'.
    append wa_fcat_inv to it_fcat_inv.
    clear wa_fcat_inv.

    lv_col                 + lv_col.
    wa_fcat_inv-col_pos   lv_col.
    wa_fcat_inv-fieldname 'LFISTO'.
    wa_fcat_inv-tabname   'IT_inv'.
    wa_fcat_inv-no_zero   'X'.
    wa_fcat_inv-seltext_l 'DO STO (80***)'.
    append wa_fcat_inv to it_fcat_inv.
    clear wa_fcat_inv.

    lv_col                 + lv_col.
    wa_fcat_inv-col_pos   lv_col.
    wa_fcat_inv-fieldname 'LFISLS'.
    wa_fcat_inv-tabname   'IT_inv'.
    wa_fcat_inv-no_zero   'X'.
    wa_fcat_inv-seltext_l 'DO Sales (40***)'.
    append wa_fcat_inv to it_fcat_inv.
    clear wa_fcat_inv.

    lv_col                 + lv_col.
    wa_fcat_inv-col_pos   lv_col.
    wa_fcat_inv-fieldname 'AVAIL'.
    wa_fcat_inv-tabname   'IT_inv'.
    wa_fcat_inv-no_zero   'X'.
    wa_fcat_inv-seltext_l 'Available'.
    append wa_fcat_inv to it_fcat_inv.
    clear wa_fcat_inv.

    lv_col                 + lv_col.
    wa_fcat_inv-col_pos   lv_col.
    wa_fcat_inv-fieldname 'OUTFAK'.
    wa_fcat_inv-tabname   'IT_inv'.
    wa_fcat_inv-no_zero   'X'.
    wa_fcat_inv-seltext_l 'Outstanding Factory'.
    append wa_fcat_inv to it_fcat_inv.
    clear wa_fcat_inv.
  endif.

endform.                    "

*&---------------------------------------------------------------------*
*&      Form  L_BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form l_build_layout .
  x_layout-zebra 'X'.
  x_layout-colwidth_optimize 'X'.
  x_layout-box_fieldname 'SEL' .
endform.                    " L_BUILD_LAYOUT
*&---------------------------------------------------------------------*
*&      Form  VIEW
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form view .

  if    inv is not initial
    and it_fcat_inv is not initial.

    call function 'REUSE_ALV_GRID_DISPLAY'
     exporting
        i_callback_program                v_prog
*       i_callback_pf_status_set          = ' '
        i_callback_pf_status_set =        'F_STATUS_SET'
        i_callback_user_command           'UCOMM_INV'
        i_callback_top_of_page            'TOP_INV'
        is_layout                         x_layout
        it_fieldcat                       it_fcat_inv
        it_events                         it_event
        it_sort                          t_sort
      tables
        t_outtab                          inv[]
      exceptions
        program_error                     1
        others                            2.
  endif.


endform.                    " VIEW
*&---------------------------------------------------------------------*
*&      Form  f_status_set
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->RT_EXTAB   text
*----------------------------------------------------------------------*
form f_status_set using rt_extab type slis_t_extab.
  set pf-status 'ZALVV'.
endform.                    "f_status_set


*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_UCOMM    text
*      -->P_SELFIELD text
*----------------------------------------------------------------------*
form user_command  using r_ucomm    like sy-ucomm
                         changing rs_selfield type slis_selfield.
  case r_ucomm.
    when '&IC1'.
      if rs_selfield-tabindex > and
       rs_selfield-sumindex le 0.
        refresh invcol.
        read table inv into invcol index  rs_selfield-tabindex.
        append invcol.
        perform second_grid.
      endif.
    when '&DWN'.
      clearp_pdirp,psavep.
      call screen 0101 starting at 10 05.
  endcase.

endform.                    "USER_COMMAND
*&---------------------------------------------------------------------*
*&      Module  PF_STATUS  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module pf_status output.
  set pf-status 'Z_ST_ALV'.
endmodule.                 " PF_STATUS  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  STATUS_0101  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module status_0101 output.
  set pf-status 'Z_ST_ALV'.
*  SET TITLEBAR 'xxx'.
  perform modify_screen_101.
endmodule.                 " STATUS_0101  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0101  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module user_command_0101 input.

  case sy-ucomm.
    when '&EXEC'.
      if p_pdirp is not initial and psavep is not initial.
        perform download.
        message'Download Complete ' type 'S'.
        leave to screen 0.
      else.
        message'Folder and File Name Cannot Empty ' type 'S'.
      endif.
    when 'G_FIND'.
      perform find.
    when '&CANC'.
      leave to screen .
  endcase.

endmodule.                 " USER_COMMAND_0101  INPUT
*&---------------------------------------------------------------------*
*&      Form  MODIFY_SCREEN_101
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form modify_screen_101 .
  loop at screen.
    if screen-name 'OK_CODE'." 'pdirp'.
      screen-input '0'.
*      P_PDIRP = 'D:\'.
      psavep 'Stock Availability.XLS'.
      modify screen.
    endif.
  endloop.
endform.                    " MODIFY_SCREEN_101
*&---------------------------------------------------------------------*
*&      Form  FIND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form find .
  datafname type string.
  call method cl_gui_frontend_services=>directory_browse
    exporting
      window_title         'Select Directory'
    changing
      selected_folder      fname
    exceptions
      cntl_error           1
      error_no_gui         2
      not_supported_by_gui 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.
  p_pdirp fname.

endform.                    " FIND
*&---------------------------------------------------------------------*
*&      Form  DOWNLOAD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form download.

  loop at inv.
    move-corresponding inv to it_datai.
    append it_datai.
  endloop.
  concatenate p_pdirp '\' psavep into psavep.

  if it_datai[] is not initial.

    call function 'GUI_DOWNLOAD'
      exporting
        filename                psavep
        write_field_separator   'X'
      tables
        data_tab                it_datah
      exceptions
        file_write_error        1
        no_batch                2
        gui_refuse_filetransfer 3
        invalid_type            4
        no_authority            5
        unknown_error           6
        header_not_allowed      7
        separator_not_allowed   8
        filesize_not_allowed    9
        header_too_long         10
        dp_error_create         11
        dp_error_send           12
        dp_error_write          13
        unknown_dp_error        14
        access_denied           15
        dp_out_of_memory        16
        disk_full               17
        dp_timeout              18
        file_not_found          19
        dataprovider_exception  20
        control_flush_error     21
        others                  22.
    if sy-subrc <> 0.
      message id sy-msgid type sy-msgty number sy-msgno
              with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.

    call function 'GUI_DOWNLOAD'
      exporting
        filename                psavep
        write_field_separator   'X'
        append                  'X'
        filetype                'ASC'
      tables
        data_tab                it_datai
      exceptions
        file_write_error        1
        no_batch                2
        gui_refuse_filetransfer 3
        invalid_type            4
        no_authority            5
        unknown_error           6
        header_not_allowed      7
        separator_not_allowed   8
        filesize_not_allowed    9
        header_too_long         10
        dp_error_create         11
        dp_error_send           12
        dp_error_write          13
        unknown_dp_error        14
        access_denied           15
        dp_out_of_memory        16
        disk_full               17
        dp_timeout              18
        file_not_found          19
        dataprovider_exception  20
        control_flush_error     21
        others                  22.
    if sy-subrc <> 0.
      message id sy-msgid type sy-msgty number sy-msgno
              with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.
  endif.
endform.                    " DOWNLOAD
*&---------------------------------------------------------------------*
*&      Form  GET_LIPS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_lips .
  select from vbbe into corresponding fields of table t_vbbe
    for all entries in inv
    where werks eq inv-werks
     and matnr eq inv-matnr
    and  lgort eq inv-lgort
    and  vbtyp 'J'.

  sort t_vbbe by matnr lgort vbeln.
  loop at t_vbbe.
    t_vbbe-vbgrp t_vbbe-vbeln(2).
    modify t_vbbe.
  endloop.

  sort t_vbbe by matnr lgort vbgrp.
  loop at t_vbbe.
    move t_vbbe-matnr to t_lipcol-matnr.
    move t_vbbe-lgort to t_lipcol-lgort.
    move t_vbbe-vbgrp to t_lipcol-vbgrp.
    move t_vbbe-omeng to t_lipcol-omeng.
    collect t_lipcol into t_lipcol .
  endloop.

  loop at t_lipcol.
    if t_lipcol-vbgrp '87'.
      move-corresponding t_lipcol to t_87.
      append t_87.
    elseif t_lipcol-vbgrp '80'.
      move-corresponding t_lipcol to t_80.
      append t_80.
    elseif t_lipcol-vbgrp '40'.
      move-corresponding t_lipcol to t_40.
      append t_40.
    endif.
  endloop.

  sort inv  by matnr lgort.
  sort t_87 by matnr lgort.
  sort t_80 by matnr lgort.
  sort t_40 by matnr lgort.
  sort inv by matnr lgort.
  loop at inv.
    read table t_87 with key matnr inv-matnr
                             lgort inv-lgort binary search.

    if sy-subrc eq 0inv-lfires t_87-omeng.endif.

    read table t_80 with key matnr inv-matnr
                             lgort inv-lgort binary search.

    if sy-subrc eq 0.inv-lfisto t_80-omeng.endif.

    read table t_40 with key matnr inv-matnr
                            lgort inv-lgort binary search.
    if sy-subrc eq 0.inv-lfisls t_40-omeng.endif.
    modify inv.
  endloop.

endform.                    " GET_LIPS
*&---------------------------------------------------------------------*
*&      Form  GET_MDBS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_mdbs .

  refresh t_mdbs.
  select from mdbs into corresponding fields of table t_mdbs
     for all entries in inv
     where werks eq inv-werks
      and matnr eq inv-matnr
      and  lgort eq inv-lgort
      and  bstyp 'F'
      and  loekz ' ' and  elikz ' ' and retpo ' '
      and  ebeln like '5%'.

*    Calculate factory Qty
  loop at t_mdbs.
    t_mdbs-mengef =  t_mdbs-menge t_mdbs-wemng .
    modify t_mdbs.
  endloop.

  sort t_mdbs by matnr lgort.
  loop at t_mdbs.
    move t_mdbs-werks to t_mdbso-werks.
    move t_mdbs-matnr to t_mdbso-matnr.
    move t_mdbs-lgort to t_mdbso-lgort.
    move t_mdbs-mengef to t_mdbso-mengef.
    collect t_mdbso into t_mdbso .
  endloop.

  sort inv  by matnr lgort.
  sort t_mdbso by matnr lgort.
  loop at inv.
    read table t_mdbso with key matnr inv-matnr
                                lgort inv-lgort binary search.

    if sy-subrc eq 0inv-outfak t_mdbso-mengef.endif.
    modify inv.
  endloop.
endform.                    " GET_MDBS

*&---------------------------------------------------------------------*
*&      Form  BUI_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form bui_fieldcat.

  clear wa_fcat_vbbe.
  refresh it_fcat_vbbe.

  if  t_vbbe[] is not initial.
    data lv_col type value 0.

    lv_col                 + lv_col.
    wa_fcat_vbbe-col_pos   lv_col.
    wa_fcat_vbbe-fieldname 'VBELN'.
    wa_fcat_vbbe-tabname   't_vbbe'.
    wa_fcat_vbbe-seltext_l 'Outb Delivery or Purchase Order'.
    append wa_fcat_vbbe to it_fcat_vbbe.
    clear wa_fcat_vbbe.

    lv_col                 + lv_col.
    wa_fcat_vbbe-col_pos   lv_col.
    wa_fcat_vbbe-fieldname 'POSNR'.
    wa_fcat_vbbe-tabname   't_vbbe'.
    wa_fcat_vbbe-seltext_l 'Line Item'.
    append wa_fcat_vbbe to it_fcat_vbbe.
    clear wa_fcat_vbbe.

*    lv_col                 = 1 + lv_col.
*    wa_fcat_vbbe-col_pos   = lv_col.
*    wa_fcat_vbbe-fieldname = 'MATNR'.
*    wa_fcat_vbbe-tabname   = 't_vbbe'.
*    wa_fcat_vbbe-seltext_l = 'Material'.
*    APPEND wa_fcat_vbbe TO it_fcat_vbbe.
*    CLEAR wa_fcat_vbbe.
*
*    lv_col                 = 1 + lv_col.
*    wa_fcat_vbbe-col_pos   = lv_col.
*    wa_fcat_vbbe-fieldname = 'WERKS'.
*    wa_fcat_vbbe-tabname   = 't_vbbe'.
*    wa_fcat_vbbe-seltext_l = 'Plant'.
*    APPEND wa_fcat_vbbe TO it_fcat_vbbe.
*    CLEAR wa_fcat_vbbe.
*
*    lv_col                 = 1 + lv_col.
*    wa_fcat_vbbe-col_pos   = lv_col.
*    wa_fcat_vbbe-fieldname = 'LGORT'.
*    wa_fcat_vbbe-tabname   = 't_vbbe'.
*    wa_fcat_vbbe-seltext_l = 'Storage Location'.
*    APPEND wa_fcat_vbbe TO it_fcat_vbbe.
    clear wa_fcat_vbbe.

    lv_col                 + lv_col.
    wa_fcat_vbbe-col_pos   lv_col.
    wa_fcat_vbbe-fieldname 'OMENG'.
    wa_fcat_vbbe-tabname   't_vbbe'.
    wa_fcat_vbbe-seltext_l 'Quantity'.
    append wa_fcat_vbbe to it_fcat_vbbe.
    clear wa_fcat_vbbe.

  endif.

endform.                    " BUI_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  VIE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form vie .
  if  it_fcat_vbbe is not initial.

    call function 'REUSE_ALV_GRID_DISPLAY'
     exporting
        i_callback_program                v_prog
*       i_callback_pf_status_set          = ' '
        i_callback_user_command           'UCOMM_VBBE'
        i_callback_top_of_page            'TOP_VBBE'
        is_layout                         x_layout
        it_fieldcat                       it_fcat_vbbe
        it_events                         it_event_vbbe
      tables
        t_outtab                          t_vbbe
      exceptions
        program_error                     1
        others                            2.
  endif.

endform.                    " VIE -----------------------*
*&      Form  EVENT_INV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form event_inv .

  refresh it_event.
  call function 'REUSE_ALV_EVENTS_GET'
*  EXPORTING
*    I_LIST_TYPE           = 0
   importing
     et_events             it_event
   exceptions
     list_type_wrong       1
     others                2.

  if it_event is not initial.
    clear wa_event.
    read table it_event into wa_event
    with key name 'USER_COMMAND'.

    if sy-subrc 0.
      wa_event-form 'UCOMM_INV'.
      modify it_event from wa_event
      index sy-tabix transporting form.
    endif.
  endif.
endform.                    " EVENT_INV


*&---------------------------------------------------------------------*
*&      Form  top_ekko
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form top_inv.

  clear wa_top_inv.
  refresh it_top_inv.

  data date type char12.

  call function 'CONVERT_DATE_TO_EXTERNAL'
    exporting
      date_internal            sy-datum
    importing
      date_external            date
    exceptions
      date_internal_is_invalid 1
      others                   2.

  wa_top_inv-typ 'H'.
  wa_top_inv-info 'Stock Availability Report'.
  append wa_top_inv to it_top_inv.
  clear wa_top_inv.

*  wa_top_inv-typ = 'S'.
*  wa_top_inv-info = 'Report: '.
*  CONCATENATE wa_top_inv-info v_prog
*  INTO wa_top_inv-info.
*  APPEND wa_top_inv TO it_top_inv.
*  CLEAR wa_top_inv.

  wa_top_inv-typ 'S'.
  wa_top_inv-info 'User Name: '.
  concatenate wa_top_inv-info v_name
  into wa_top_inv-info.
  append wa_top_inv to it_top_inv.
  clear wa_top_inv.

  wa_top_inv-typ 'S'.
  wa_top_inv-info 'Date: '.
  concatenate wa_top_inv-info date
  into wa_top_inv-info.
  append wa_top_inv to it_top_inv.
  clear wa_top_inv.

  call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
      it_list_commentary       it_top_inv
*     I_LOGO                   =
*     I_END_OF_LIST_GRID       =
*     I_ALV_FORM               =
            .

endform.                    "top_ekko
*&---------------------------------------------------------------------*
*&      Form  UCOMM_INV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_R_UCOMM  text
*      <--P_RS_SELFIELD  text
*----------------------------------------------------------------------*
form ucomm_inv using      r_ucomm_inv     type sy-ucomm
                changing rs_selfield_inv type slis_selfield.

  case r_ucomm_inv.
    when '&IC1'.
      if rs_selfield_inv-tabindex > and
       rs_selfield_inv-sumindex le 0.
        refresh invcol.
        read table inv into invcol index rs_selfield_inv-tabindex.
        append invcol.
        perform second_grid.
      endif.
    when '&DWN'.
      clearp_pdirp,psavep.
      call screen 0101 starting at 10 05.
  endcase.

endform.                    " UCOMM_INV
*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_data .
  perform get_mard.

  table_n 0.
  describe table inv lines table_n.
  if table_n eq 0.
    call function 'C14A_POPUP_NO_HITS'.
    exit.
  endif.
  perform get_lips.   " Deatail DO
  perform get_vbbe.
  perform get_mdbs.  " On Order Stock
  perform get_price.

*    Append Data to Itab.
  refresh it_datah.
  it_datah-matnr 'Material'.
  it_datah-werks 'Plant'.
  it_datah-lgort 'Sloc'.
  it_datah-labst 'Unrestricted Use'.
  it_datah-lfires 'DO Reserved (87***)'.
  it_datah-lfisto 'DO STO (80***)'.
  it_datah-lfisls 'DO Sales (40***)'.
*    IT_DATAH-LFIMG = 'Schd. for Delivery'.
  it_datah-avail =  'Available'.
  it_datah-outfak =  'Outstanding Factory'.
  append it_datah.
  clear it_datah.

endform.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Form  TOP_VBBE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form top_vbbe .
  clear wa_top_vbbe.
  refresh it_top_vbbe.

  wa_top_vbbe-typ 'H'.
  wa_top_vbbe-info 'Stock Availability Detail Display'.
  append wa_top_vbbe to it_top_vbbe.
  clear wa_top_vbbe.

  call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
      it_list_commentary       it_top_vbbe
*   I_LOGO                   =
*   I_END_OF_LIST_GRID       =
*   I_ALV_FORM               =
.
endform.                    " TOP_VBBE
*&---------------------------------------------------------------------*
*&      Form  EVENT_VBBE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form event_vbbe .

  refresh it_event_vbbe.
  call function 'REUSE_ALV_EVENTS_GET'
* EXPORTING
*   I_LIST_TYPE           = 0
   importing
     et_events             it_event_vbbe
   exceptions
     list_type_wrong       1
     others                2.

  if it_event_vbbe is not initial.
    clear wa_event_vbbe.
    read table it_event_vbbe into wa_event_vbbe
    with key name 'USER_COMMAND'.

    if sy-subrc 0.
      wa_event_vbbe-form 'UCOMM_VBBE'.
      modify it_event_vbbe from wa_event_vbbe
      index sy-tabix transporting form.
    endif.
  endif.
endform.                    " EVENT_VBBE
*&---------------------------------------------------------------------*
*&      Form  GRID_VBBE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form grid_vbbe .

  if    it_fcat_vbbe is not initial.
    call function 'REUSE_ALV_GRID_DISPLAY'
     exporting
        i_callback_program                v_prog
*       i_callback_pf_status_set          = ' '
        i_callback_user_command           'UCOMM_VBBE'
        i_callback_top_of_page            'TOP_VBBE'
        is_layout                         x_layout
        it_fieldcat                       it_fcat_vbbe
        it_events                         it_event_vbbe
      tables
        t_outtab                          t_vbbe[]
      exceptions
        program_error                     1
        others                            2.
  endif.
endform.                    " GRID_VBBE
*&---------------------------------------------------------------------*
*&      Form  UCOMM_EKPO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_R_UCOM  text
*      <--P_RS_SELFIELD  text
*----------------------------------------------------------------------*
form ucomm_vbbe  using    r_ucomm_vbbe      type sy-ucomm
                 changing rs_selfield_vbbe  type slis_selfield.
  case r_ucomm_vbbe.
    when '&IC1'.        "SAP standard code for double-clicking
      if rs_selfield_vbbe-fieldname 'VBELN'.
        if rs_selfield_vbbe-value(1'5'.
          set parameter id 'BES' field rs_selfield_vbbe-value.
          call transaction 'ME23N' and skip first screen.
        else.
          set parameter id 'VL' field rs_selfield_vbbe-value.
          call transaction 'VL03N' and skip first screen.
        endif.
      else.
        message 'Invalid Field' type 'S'.
      endif.
  endcase.
endform.                    "ucomm_vbbe
*
module cancel input.
  leave program.
endmodule.                 " CANCEL  INPUT
*&---------------------------------------------------------------------*
*&      Module  STATUS_0102  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module status_0102 output.
  set pf-status 'ZALVV'.
  set titlebar  'ZHEAD201'.
  describe table inv lines lines.
  tbl_ctr_inv-lines lines.

endmodule.                 " STATUS_0102  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0102  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module user_command_0102 input.

  datag_colname(10),
        g_value(2)." LIKE VBELN.

  dataws_field(30),
        ws_line type i,
        v_index type sy-index,
        popup_title(30),
        returncode(1),
        v_curr_line like sy-tabix,
        v_tot_line type i.
  datal_line type i.
  data l_tc_new_top_line     type i.

  data it_fields type standard table of sval with header line.
  popup_title 'Choose Purchase Order Number'.

  save_ok ok_code.
  clear ok_code.
  case save_ok.
*    WHEN '&SCHR'.
*      CLEAR IT_FIELDS.
*      CALL FUNCTION 'POPUP_GET_VALUES'
*        EXPORTING
*         NO_VALUE_CHECK        = 'X'
*          POPUP_TITLE           = POPUP_TITLE
*         START_COLUMN           = '5'
*         START_ROW              = '25'
*       IMPORTING
*         RETURNCODE            = RETURNCODE
*        TABLES
*          FIELDS                = IT_FIELDS
*       EXCEPTIONS
*         ERROR_IN_FIELDS       = 1
*         OTHERS                = 2
*                .
*      IF SY-SUBRC <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
**         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*      ENDIF.
*
*
*      IF RETURNCODE = ' '.
*        SORT INV BY MATNR.
*        READ TABLE INV WITH KEY MATNR = IT_FIELDS-VALUE.
*        IF SY-SUBRC = 0.
*          TBL_CTR_INV-TOP_LINE = SY-TABIX.
*          V_CURR_LINE = sy-tabix.
*          V_TOT_LINE = TBL_CTR_INV-lines.
*          REFRESH IT_FIELDS.
*          CLEAR RETURNCODE.
*        ENDIF.
*      ENDIF.

    when '&F03'.
      leave to screen 0.
    when '&F15'.
      leave to screen 0.
    when '&F12'.
      leave to screen 0.
    when '&DWN'.
      clearp_pdirp,psavep.
      call screen 0101 starting at 10 05.
    when '&OUP'.
      clearcols,g_colname,cols-screen-name.
      read table tbl_ctr_inv-cols into cols with key selected 'X'.
      if sy-subrc 0.
        g_colname cols-screen-name+4(7).
        sort inv stable by (g_colnameascending.
        cols-selected ' '.
        modify tbl_ctr_inv-cols from cols index sy-tabix.
      endif.
    when '&ODN'.
      clearcols,g_colname,cols-screen-name.
      read table tbl_ctr_inv-cols into cols with key selected 'X'.
      if sy-subrc 0.
        g_colname cols-screen-name+4(7).
        sort inv stable by (g_colnamedescending.
        cols-selected ' '.
        modify tbl_ctr_inv-cols from cols index sy-tabix.
      endif.
    when '&IC1'.

*      Row Line
      refresh  invrow.
*      DATA: L_LINE TYPE I.
      get cursor line l_line.
      l_line tbl_ctr_inv-top_line + l_line 1.
      read table inv index l_line.
      if sy-subrc eq 0.
        read table inv into invrow index  l_line"rs_selfield-tabindex.
        append invrow.
      endif.

*      Coloumn LIne
      clear cols.
      read table tbl_ctr_inv-cols into cols with key selected 'X'.
      g_colname cols-screen-name+4(7).
      get cursor field ws_field line ws_line.

      if ws_field 'INV-LFIRESC'.
        refresh r_auart.
        r_auart-sign 'I'.
        r_auart-option 'EQ'.
        r_auart-low 'ZNL '.
        append r_auart.
        refresh invcol.
        read table inv into invcol index ws_line"rs_selfield-tabindex.
        append invcol.
        perform second_grid .

      elseif ws_field 'INV-LFISTOC'.
        refresh r_auart.
        r_auart-sign 'I'.
        r_auart-option 'EQ'.
        r_auart-low 'NL '.
        append r_auart.
        refresh invcol.
        read table inv into invcol index ws_line"rs_selfield-tabindex.
        append invcol.
        perform second_grid .

      elseif ws_field 'INV-LFISLSC'.
        refresh r_auart.
        r_auart-sign 'I'.
        r_auart-option 'EQ'.
        r_auart-low 'ZD01'.
        append r_auart.
        refresh invcol.
        read table inv into invcol index ws_line"rs_selfield-tabindex.
        append invcol.
        perform second_grid .

      elseif ws_field 'INV-OUTFAKC'.
        refresh invcol.
        read table inv into invcol index ws_line"rs_selfield-tabindex.
        append invcol.
        perform second_grid .
      endif.
      .
    when '&DWN'.
      clearp_pdirp,psavep.
      call screen 0101 starting at 10 05.

    when 'P+'.
      call function 'SCROLLING_IN_TABLE'
          exporting
               entry_act             tbl_ctr_inv-top_line
               entry_from            1
               entry_to              tbl_ctr_inv-lines
               last_page_full        'X'
               loops                 25
               ok_code               'P+'
               overlapping           'X'
          importing
               entry_new             l_tc_new_top_line
          exceptions
*              NO_ENTRY_OR_PAGE_ACT  = 01
*              NO_ENTRY_TO           = 02
*              NO_OK_CODE_OR_PAGE_GO = 03
               others                0.

      tbl_ctr_inv-top_line l_tc_new_top_line.
    when 'P-'.
      call function 'SCROLLING_IN_TABLE'
      exporting
           entry_act             tbl_ctr_inv-top_line
           entry_from            1
           entry_to              tbl_ctr_inv-lines
           last_page_full        'X'
           loops                 25
           ok_code               'P-'
           overlapping           'X'
      importing
           entry_new             l_tc_new_top_line
      exceptions
*              NO_ENTRY_OR_PAGE_ACT  = 01
*              NO_ENTRY_TO           = 02
*              NO_OK_CODE_OR_PAGE_GO = 03
           others                0.

      tbl_ctr_inv-top_line l_tc_new_top_line.

*    WHEN 'P++'.
*      TBL_CTR_INV-top_line =
*             TBL_CTR_INV-lines - l_line + 1.
*      IF TBL_CTR_INV-top_line LE 0.
*        TBL_CTR_INV-top_line = 1.
*      ENDIF.


  endcase.

endmodule.                 " USER_COMMAND_0102  INPUT
**&---------------------------------------------------------------------*
**&      Form  CHECK_DATA
**&---------------------------------------------------------------------*
**       text
**----------------------------------------------------------------------*
**      -->P_ER_DATA_CHANGED  text
**      -->P_INV  text
**----------------------------------------------------------------------*
*FORM CHECK_DATA  USING    P_ER_DATA_CHANGED
*                          P_INV.
*
*ENDFORM.                    " CHECK_DATA
*&---------------------------------------------------------------------*
*&      Module  READ_TABLE_CONTROL  INPUT
*&---------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
module read_table_control input.
  l_line sy-loopc.
*  TBL_CTR_INV-current_line = l_line + 1.
  modify inv index tbl_ctr_inv-current_line.
*    MODIFY INV FROM TBL_CTR_INV INDEX TBL_CTR_INV-current_line.
endmodule.                 " READ_TABLE_CONTROL  INPUT
*&---------------------------------------------------------------------*
*&      Module  PASS_DATA  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module pass_data output.
  read table inv index tbl_ctr_inv-current_line.
endmodule.                 " PASS_DATA  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  MODIFY_DATA  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module modify_data input.
  modify inv from inv index tbl_ctr_inv-current_line.
*  READ TABLE inv INDEX TBL_CTR_INV-current_line.
endmodule.                 " MODIFY_DATA  INPUT


*&---------------------------------------------------------------------*
*&      Form  SECOND_GRID
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form second_grid.

  refresh t_vbbe.
  select from vbbe into corresponding fields of table t_vbbe
    for all entries in invrow
    where werks eq invrow-werks
     and matnr  eq invrow-matnr
     and lgort eq invrow-lgort
     and vbtyp 'J'
     and auart in r_auart.


  if ws_field 'INV-OUTFAKC'.
    refresh t_vbbe.
    sort t_mdbs by werks matnr lgort.
    sort invrow by werks matnr lgort.

    select from mdbs into corresponding fields of table t_mdbs
    for all entries in invrow
    where werks eq invrow-werks
     and matnr eq invrow-matnr
     and  lgort eq invrow-lgort
     and  bstyp 'F'
     and  loekz ' ' and  elikz ' ' and retpo ' '
     and  ebeln like '5%'.

    if t_mdbs[] is not initial.
      loop at t_mdbs .
        t_mdbs-mengef =  t_mdbs-menge t_mdbs-wemng .
        t_vbbe-vbeln  t_mdbs-ebeln.
        t_vbbe-posnr  t_mdbs-ebelp.
        t_vbbe-omeng  t_mdbs-mengef.
        append t_vbbe.
      endloop.
    endif.
  endif.


  sort t_vbbe by vbeln matnr posnr.
*   Display Message Upload.
  perform bui_fieldcat.
  perform l_build_layout.
  perform event_vbbe.
  perform grid_vbbe.
  perform ucomm_vbbe using r_ucomm
                     changing rs_selfield.

endform.                    "SECOND_GRID

Visitor

Code Syntax Try...Endtry

  Code : Report Try. Parameters  NUMBER  type  I . data  RESULT  type  P  decimals  2 . data  OREF  type  ref  to  CX_ROOT . data  TEXT  typ...