库存月查询

 期间库存的余额查询报表的例子

 

*&---------------------------------------------------------------------*
*& Report  ZMM094
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zmm094.
TYPE-POOLS:slis.
TABLES:mbew,mbewh,makt,t001k.

DATA:BEGIN OF lt_itab OCCURS 0,
     matnr TYPE matnr,
     maktg TYPE maktg,
     bklas TYPE bklas,
     bwkey TYPE bwkey,
     salk3 TYPE salk3,
     lbkum TYPE lbkum,
     peinh TYPE peinh,
     lfgja TYPE lfgja,
     lfmon TYPE lfmon,
    END OF lt_itab.
**mbewh的数据
DATA:BEGIN OF lt_m OCCURS 0,
     matnr TYPE matnr,
     maktg TYPE maktg,
     bklas TYPE bklas,
     bwkey TYPE bwkey,
     salk3 TYPE salk3,
     lbkum TYPE lbkum,
     peinh TYPE peinh,
     lfgja TYPE lfgja,
     lfmon TYPE lfmon,
   END OF lt_m.
DATA:lt_mbewh1 LIKE STANDARD TABLE OF lt_m WITH HEADER LINE.
DATA:lt_mbewh2 LIKE STANDARD TABLE OF lt_m WITH HEADER LINE.
DATA:lt_mbewh3 LIKE STANDARD TABLE OF lt_m WITH HEADER LINE.
DATA:lt_mbewh4 LIKE STANDARD TABLE OF lt_m WITH HEADER LINE.
DATA:lt_ms LIKE  lt_m .
DATA:BEGIN OF lt_l OCCURS 0,
     matnr TYPE mbew-matnr,
     bwkey TYPE mbew-bwkey,
     END OF lt_l.
DATA:lt_mbew1 LIKE STANDARD TABLE OF lt_itab WITH HEADER LINE.
DATA:lt_mbew2 LIKE STANDARD TABLE OF lt_itab WITH HEADER LINE.
DATA:lt_out1 LIKE STANDARD TABLE OF lt_l WITH HEADER LINE.
DATA:lt_out2 LIKE STANDARD TABLE OF lt_l WITH HEADER LINE.
DATA:lt_out3 LIKE STANDARD TABLE OF lt_l WITH HEADER LINE.
DATA:lt_out4 LIKE STANDARD TABLE OF lt_l WITH HEADER LINE.

DATA: gt_fieldcat TYPE lvc_t_fcat,
      gr_alv TYPE REF TO cl_gui_alv_grid,
      gr_container TYPE REF TO cl_gui_custom_container,
      gs_layout TYPE lvc_s_layo.
DATA: gt_exclude      TYPE        ui_functions.
DATA :ls_variant TYPE disvariant.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text_01.
PARAMETERS: p_bukrs TYPE t001k-bukrs OBLIGATORY,
            p_lfgja TYPE mbewh-lfgja OBLIGATORY,
            p_lfmon TYPE mbewh-lfmon OBLIGATORY.
SELECT-OPTIONS:s_bklas FOR mbew-bklas OBLIGATORY,
               s_matnr FOR mbew-matnr,
               s_bwkey FOR mbewh-bwkey.
SELECTION-SCREEN END OF BLOCK b1.

INITIALIZATION.
  text_01 = '库存期间余额表显示'.

START-OF-SELECTION.

  PERFORM frm_stay.
  PERFORM get_data.
  CALL SCREEN 100.
*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data .
  CLEAR:lt_l,lt_l[],lt_m,lt_m[],lt_itab,lt_itab[].",lt_w,lt_w[].
  CLEAR:lt_out1,lt_out2,lt_out3,lt_out4,lt_out1[],lt_out2[],lt_out3[],lt_out4[].
**取评估类和物料 通过评估分类
  SELECT  matnr mbew~bwkey
     FROM mbew
     INNER JOIN t001k ON t001k~bwkey = mbew~bwkey
     INTO CORRESPONDING FIELDS OF TABLE lt_l
     WHERE vjbkl IN s_bklas
     AND matnr IN s_matnr
     AND  mbew~bwkey IN s_bwkey
     AND  t001k~bukrs = p_bukrs.
  SORT lt_l ASCENDING BY matnr bwkey.
  DELETE ADJACENT DUPLICATES FROM lt_l COMPARING ALL FIELDS.
  lt_out1[] = lt_l[].
  IF lt_l[] IS  NOT INITIAL.
***①输入屏幕条件相同的
    SELECT mbewh~matnr makt~maktg mbewh~bklas mbewh~bwkey mbewh~salk3 lbkum
        mbewh~peinh mbewh~lfgja mbewh~lfmon
        FROM mbewh
        INNER JOIN makt ON makt~matnr = mbewh~matnr AND makt~spras = '1'
        INTO TABLE lt_itab
        FOR ALL ENTRIES IN lt_l
        WHERE mbewh~matnr = lt_l-matnr
        AND   bwkey = lt_l-bwkey
*      and   bukrs = p_bukrs
        AND   lfgja = p_lfgja
        AND   lfmon = p_lfmon
        AND   bklas IN s_bklas.
    SORT lt_itab ASCENDING BY matnr bwkey lfgja lfmon.
    DELETE ADJACENT DUPLICATES FROM lt_itab COMPARING  matnr bwkey lfgja lfmon.
** 把物料转移到新的内表做数据的删减
    LOOP AT lt_itab.
      MOVE-CORRESPONDING lt_itab TO lt_out2.
      APPEND lt_out2.
    ENDLOOP.
    SORT lt_out2 ASCENDING BY matnr bwkey.
    DELETE ADJACENT DUPLICATES FROM lt_out2 COMPARING ALL FIELDS.
**去掉已经用掉的物料
    LOOP AT lt_out2.
      DELETE lt_out1[] WHERE bwkey = lt_out2-bwkey AND matnr = lt_out2-matnr .
    ENDLOOP.
**②不满足屏幕条件,取出所有的数据
*  lt_out4[] = lt_out1[].
    LOOP AT lt_out1.
      CLEAR:lt_mbewh1,lt_mbewh1[],lt_mbewh2,lt_mbewh2[],lt_mbewh3,lt_mbewh3[],
      lt_mbew1,lt_mbew1[],lt_mbew2,lt_mbew2[].
      SELECT mbewh~matnr maktg bklas bwkey salk3 lbkum  peinh lfgja lfmon
          FROM mbewh
          INNER JOIN makt ON makt~matnr = mbewh~matnr AND makt~spras = '1'
          INTO  TABLE lt_mbewh1
*        FOR ALL ENTRIES IN lt_out1
          WHERE mbewh~matnr = lt_out1-matnr
          AND   bwkey = lt_out1-bwkey
          AND   ( ( lfgja = p_lfgja AND lfmon <> p_lfmon ) OR ( lfgja <> p_lfgja AND lfmon <> p_lfmon )
                OR ( lfgja <> p_lfgja AND lfmon = p_lfmon ) ).
**进行排序(lfgja ,lfmon)
      SORT lt_mbewh1 ASCENDING BY lfgja lfmon.
      IF lt_mbewh1[] IS NOT INITIAL.
** 取出mbewh表里满足屏幕条件上一行的数据兵判断是否存在屏幕条件的上一条数据
        LOOP AT  lt_mbewh1 WHERE  matnr = lt_out1-matnr AND
                                   ( ( lfgja = p_lfgja AND lfmon < p_lfmon ) OR
                                    lfgja < p_lfgja   ).
          APPEND lt_mbewh1 TO lt_mbewh2.
        ENDLOOP.
        SORT lt_mbewh2 ASCENDING BY lfgja lfmon.
**判断是否有存在上一条数据
        IF lt_mbewh2[] IS NOT INITIAL .
** 取出下一条的数据
          LOOP AT  lt_mbewh1 WHERE matnr = lt_out1-matnr AND
                                    ( ( lfgja = p_lfgja AND lfmon > p_lfmon ) OR
                                       lfgja > p_lfgja  ).
            APPEND lt_mbewh1 TO lt_mbewh3.
          ENDLOOP.
          SORT lt_mbewh3 ASCENDING BY lfgja lfmon.
**判断是否存在下一条数据
          IF lt_mbewh3[] IS NOT INITIAL.
*      READ TABLE lt_mbewh3 INTO lt_ms INDEX 1.
            READ TABLE lt_mbewh3 INDEX 1.
            "1 有下一条,取出大于屏幕条件的下一条数据存表
            IF lt_mbewh3 IS NOT INITIAL.
              APPEND lt_mbewh3 TO lt_itab.
            ENDIF.
          ELSE.
            "2 没有下一条,从mbew里取值
            SELECT mbew~matnr maktg bklas bwkey salk3  lbkum  peinh lfgja lfmon
              FROM mbew
              INNER JOIN makt ON makt~matnr = mbew~matnr AND makt~spras = '1'
              INTO TABLE lt_mbew1
              WHERE mbew~matnr = lt_out1-matnr
*         and   bukrs = p_bukrs
              AND   bwkey = lt_out1-bwkey
              AND   ( lfgja =< p_lfgja OR ( lfgja = p_lfgja AND lfmon <= p_lfmon ) )
*            AND   lfmon =< p_lfmon
              AND   bklas IN s_bklas.
            SORT lt_mbew1 DESCENDING BY lfgja lfmon.
            READ TABLE lt_mbew1 INDEX 1.
            IF lt_mbew1 IS NOT INITIAL.
              APPEND lt_mbew1 TO lt_itab.

            ENDIF.
          ENDIF.
        ENDIF.
      ELSE.
**不存在 上一条数据取出大于屏幕的lfgja和 lfmon的数据
        SELECT mbew~matnr maktg bklas bwkey salk3 lbkum  peinh lfgja lfmon
          FROM mbew
          INNER JOIN makt ON makt~matnr = mbew~matnr AND makt~spras = '1'
          INTO TABLE lt_mbew2
          WHERE mbew~matnr = lt_out1-matnr
          AND   bwkey = lt_out1-bwkey
*  and   bukrs = p_bukrs
          AND   ( lfgja =< p_lfgja OR ( lfgja = p_lfgja AND lfmon <= p_lfmon ) )
*        AND   lfmon =< p_lfmon
          AND   bklas IN s_bklas.
        SORT lt_mbew2 DESCENDING BY lfgja lfmon.
        READ TABLE lt_mbew2 INDEX 1.
        IF lt_mbew2 IS NOT INITIAL.
          APPEND lt_mbew2 TO lt_itab.

        ENDIF.
      ENDIF.
    ENDLOOP.
    DELETE lt_itab[] WHERE lbkum = '0' AND salk3 = '0'.
  ENDIF.

ENDFORM.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS'.
  SET TITLEBAR 'TITLE'.
  IF gr_container IS BOUND.
    PERFORM refresh_alv IN PROGRAM zcommon
                      USING gr_alv
                      IF FOUND.
  ELSE.
    CREATE OBJECT gr_container
      EXPORTING
        container_name = 'CONTAINER'.
    CREATE OBJECT gr_alv
      EXPORTING
        i_parent = gr_container.
    "排除工具栏上不需要显示的按钮
    PERFORM alv_exclude_func_all CHANGING  gt_exclude.
*目录显示
    PERFORM frm_fcat CHANGING gt_fieldcat.
*布局
    PERFORM frm_layout CHANGING gs_layout.
    ls_variant-report = sy-repid.
*显示alv
    CALL METHOD gr_alv->set_table_for_first_display
      EXPORTING
        i_save                        = 'A'
*       I_DEFAULT                     = 'X'
        is_variant      = ls_variant
        is_layout                     = gs_layout
        it_toolbar_excluding          = gt_exclude  "隐藏工具栏上按钮
      CHANGING
        it_outtab                     = lt_itab[]
        it_fieldcatalog               = gt_fieldcat
      EXCEPTIONS
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        OTHERS                        = 4.

  ENDIF.
ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Form  ALV_EXCLUDE_FUNC_ALL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_GT_EXCLUDE  text
*----------------------------------------------------------------------*
FORM alv_exclude_func_all  CHANGING  pt_exclude TYPE ui_functions.
  DATA ls_exclude TYPE ui_func.
*
*  ls_exclude = cl_gui_alv_grid=>mc_mb_paste.
*  APPEND ls_exclude TO pt_exclude.
*
*  ls_exclude = cl_gui_alv_grid=>mc_mb_subtot.
*  APPEND ls_exclude TO pt_exclude.
*  ls_exclude = cl_gui_alv_grid=>mc_mb_sum.
*  APPEND ls_exclude TO pt_exclude.
*  ls_exclude = cl_gui_alv_grid=>mc_mb_variant.
*  APPEND ls_exclude TO pt_exclude.
*  ls_exclude = cl_gui_alv_grid=>mc_mb_view.
*  APPEND ls_exclude TO pt_exclude.
*  ls_exclude = cl_gui_alv_grid=>mc_fg_sort.
*  APPEND ls_exclude TO pt_exclude.
*  ls_exclude = cl_gui_alv_grid=>mc_fg_edit.
*  APPEND ls_exclude TO pt_exclude.
*
*
*  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
*  APPEND ls_exclude TO pt_exclude.

*  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
*  APPEND ls_exclude TO pt_exclude.
*
*  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
*  APPEND ls_exclude TO pt_exclude.

  ls_exclude = cl_gui_alv_grid=>mc_fc_refresh.
  APPEND ls_exclude TO pt_exclude.

  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
  APPEND ls_exclude TO pt_exclude.

  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
  APPEND ls_exclude TO pt_exclude.


  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
  APPEND ls_exclude TO pt_exclude.

  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
  APPEND ls_exclude TO pt_exclude.

  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
  APPEND ls_exclude TO pt_exclude.

  ls_exclude = cl_gui_alv_grid=>mc_fc_print .
  APPEND ls_exclude TO pt_exclude.

  ls_exclude = cl_gui_alv_grid=>mc_fc_print_prev .
  APPEND ls_exclude TO pt_exclude.

*  ls_exclude = cl_gui_alv_grid=>mc_fc_graph .
*  APPEND ls_exclude TO pt_exclude.

*  ls_exclude = cl_gui_alv_grid=>mc_mb_view .
*  APPEND ls_exclude TO pt_exclude.

*  ls_exclude = cl_gui_alv_grid=>mc_fc_detail .
*  APPEND ls_exclude TO pt_exclude.

*  ls_exclude = cl_gui_alv_grid=>mc_fc_help .
*  APPEND ls_exclude TO pt_exclude.
*
  ls_exclude = cl_gui_alv_grid=>mc_fc_info .
  APPEND ls_exclude TO pt_exclude.

*  ls_exclude = cl_gui_alv_grid=>mc_fc_average .
*  APPEND ls_exclude TO pt_exclude.
*
*  ls_exclude = cl_gui_alv_grid=>mc_mb_subtot .
*  APPEND ls_exclude TO pt_exclude.
*
*  ls_exclude = cl_gui_alv_grid=>mc_fc_save_variant.
*  APPEND ls_exclude TO pt_exclude.

*  ls_exclude = cl_gui_alv_grid=>mc_fc_load_variant.
*  APPEND ls_exclude TO pt_exclude.

*  ls_exclude = cl_gui_alv_grid=>mc_fc_maintain_variant.
*  APPEND ls_exclude TO pt_exclude.
*  ls_exclude = cl_gui_alv_grid=>mc_fc_find.
*  APPEND ls_exclude TO pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_filter.
  APPEND ls_exclude TO pt_exclude.

*  ls_exclude = cl_gui_alv_grid=>mc_mb_export.
*  APPEND ls_exclude TO pt_exclude.
ENDFORM.                    " ALV_EXCLUDE_FUNC_ALL
*&---------------------------------------------------------------------*
*&      Form  FRM_FCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_FIELDCAT  text
*----------------------------------------------------------------------*
FORM frm_fcat  CHANGING pt_fieldcat TYPE lvc_t_fcat.
  DATA:gs_fcat TYPE lvc_s_fcat.
  DEFINE add_fcat.
    gs_fcat-fieldname = &1.
    gs_fcat-outputlen = &2.
    gs_fcat-scrtext_l = &3.
    gs_fcat-ref_field = &4.
    gs_fcat-ref_table = &5.
    gs_fcat-drdn_hndl = &6.

    append gs_fcat to pt_fieldcat.
  END-OF-DEFINITION.
  add_fcat 'MATNR' '18' '物料编号' '' '' ''.
  add_fcat 'MAKTG' '30' '描述' '' '' ''.
  add_fcat 'BKLAS' '4' '评估类' '' '' ''.
  add_fcat 'BWKEY' '4' '评估范围' '' '' ''.
  add_fcat 'SALK3' '15' '总价值' 'SALK3' 'MBEW' ''.
  add_fcat 'LBKUM' '16' '总数量' 'LBKUM' 'MBEW' ''.
  add_fcat 'PEINH' '4' '价格单位' '' '' ''.
*  add_fcat 'LFGJA' '40' '物料描述' '' '' ''.
*  add_fcat 'LFMON' '3' '评估范围' '' '' ''.
ENDFORM.                    " FRM_FCAT
*&---------------------------------------------------------------------*
*&      Form  FRM_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GS_LAYOUT  text
*----------------------------------------------------------------------*
FORM frm_layout  CHANGING ps_layout TYPE lvc_s_layo."slis_layout_alv.
  ps_layout-zebra = 'X'."斑马纹
  ps_layout-cwidth_opt = 'X'.
*  ps_layout-box_fname = 'SEL'.
  ps_layout-sel_mode = 'D'.
ENDFORM.                    " FRM_LAYOUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  DATA:ok_code TYPE sy-ucomm.
  CASE ok_code.
    WHEN 'BACK'.
      LEAVE TO SCREEN 0.
*	WHEN .
    WHEN OTHERS.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*&      Form  FRM_STAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_stay .
***信息提示
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      percentage = 0
      text       = '数据正在查找中,请等待......'.
ENDFORM.                    " FRM_STAY

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值