ABAP源码--当前及可用库存查询

ABAP源码--当前及可用库存查询_第1张图片

ABAP源码--当前及可用库存查询_第2张图片

*& REPORT  ZCOK_MM_RINVINQ12.
*     System        : ******** ERP项目
*     Module        : MM
*     Program      : 库存查询
*     Author         : 大树
*     Description  : 当前库存以及可用库存查询,可对行项目双击弹出明细窗口
********************************************************************************************************        
REPORT  zcok_mm_rinvinq12 MESSAGE-ID zcok_mes01.
*Define tables
TABLES : mchb,mara,t001w,t001l.
*for alv
TYPE-POOLS: slis,vrm.
DATA:
  i_fieldcat_alv  TYPE slis_t_fieldcat_alv, "Define the fieldcat
  i_layout          TYPE slis_layout_alv,     "alv format
  i_fieldcat        TYPE slis_fieldcat_alv,   "
  i_events        TYPE slis_t_event,        "alv event
  i_title             TYPE lvc_title,
  w_events        LIKE LINE OF i_events,
  i_list_comments TYPE slis_t_listheader,   "alv listheader
  w_list_comments LIKE LINE OF i_list_comments,
  w_repid LIKE sy-repid.                    " current program
*Define the fields of internal table
DATA:
  BEGIN OF hd_itab OCCURS 0,
    werks LIKE mchb-werks,   "工厂
    lgort LIKE mchb-lgort,   "库存地点
    lgobe LIKE t001l-lgobe,  "库存地点描述
    matnr LIKE mchb-matnr,   "物料
    maktx LIKE makt-maktx,   "物料描述
    matkl LIKE mara-matkl,   "物料组
    spart LIKE mara-spart,   "产品组
    vtext LIKE tspat-vtext,  "产品组描述
    xchpf LIKE marc-xchpf,   "批次管理是否启用
    charg LIKE mchb-charg,   "批号
    sobkz LIKE msku-sobkz,   "特殊库存标示
    clabs LIKE mchb-clabs,   "基本计量单位下的库存数量 当xchpf为'X'时取值
    meins LIKE mara-meins,   "基本计量单位
    zkcsl LIKE mchb-clabs,   "kg单位下的库存数量(可用)
    zkcjs LIKE mchb-clabs,   "库存件数
    zmeinh LIKE marm-meinh,  "件数对应单位 显示用
    xmeinh LIKE marm-meinh,  "件数对应单位
    kunnr LIKE msku-kunnr,   "客户号
    name1 LIKE kna1-name1,   "客户名称
    lifnr LIKE mslb-lifnr,   "供应商号
    name2 LIKE lfa1-name1,   "供应商名称
    vbeln LIKE mska-vbeln,   "销售订单号
    posnr LIKE mska-posnr,   "销售订单项目号
    mng01 LIKE mdez-mng01,   "可用库存 md04 事物码 PLAAB = '02' 时数量
    mng01js LIKE mchb-clabs,   "可用库存件数 md04 事物码 PLAAB = '02' 时件数
    color(4) TYPE c,
  END OF hd_itab.
DATA:pop_data LIKE TABLE OF hd_itab WITH HEADER LINE.
DATA:ltd_data LIKE HASHED TABLE OF hd_itab WITH HEADER LINE
       WITH UNIQUE KEY werks lgort lgobe matnr maktx matkl spart vtext xchpf charg
                       sobkz meins zmeinh xmeinh kunnr name1 lifnr name2 vbeln posnr color.
"定义统计结果内表(必须是哈希内表)
DATA:
  BEGIN OF pop_itab OCCURS 0,
    werks LIKE mchb-werks,   "工厂
    lgort LIKE mchb-lgort,   "库存地点
    lgobe LIKE t001l-lgobe,  "库存地点描述
    matnr LIKE mchb-matnr,   "物料
    charg LIKE mchb-charg,   "批号
    clabs LIKE mchb-clabs,   "基本计量单位下的库存数量 当xchpf为'X'时取值
    meins LIKE mara-meins,   "基本计量单位
    zmeinh LIKE marm-meinh,  "件数对应单位 显示用
    xmeinh LIKE marm-meinh,  "件数对应单位
    zkcjs LIKE mchb-clabs,   "库存件数
    sort0 LIKE mdez-sort0,                                  "md04日期
    delb0 LIKE mdez-delb0,                                  "md04 mrp元素
    extra LIKE mdez-extra,   "MD04 MRP元素数据
    mng01 LIKE mdez-mng01,   "可用库存收货/需求
    mng02 LIKE mdez-mng02,   "可用库存数量
    mngjs LIKE mdez-mng01,   "可用库存件数
    md4li LIKE mdez-md4li,   "供应商
    md4kd LIKE mdez-md4kd,   "客户
    kunli TYPE c LENGTH 35,  "客户/供应商整合至一列
  END OF pop_itab.
DATA:
  BEGIN OF mara_itab OCCURS 0,
    matnr LIKE mara-matnr,
    meins LIKE mara-meins,
  END OF mara_itab.
DATA:
  BEGIN OF unit_itab OCCURS 0,
    matnr LIKE marm-matnr,
    meinh LIKE marm-meinh,
  END OF unit_itab.
DATA:
  BEGIN OF unit_count_itab OCCURS 0,
    matnr LIKE marm-matnr,
    vcount TYPE i,
  END OF unit_count_itab.
*-----------------------------------------------------------------------*
*                             Define for list_box
*-----------------------------------------------------------------------*
DATA: name1 TYPE vrm_id,
      list1 TYPE vrm_values,
      value1 LIKE LINE OF list1.
*-----------------------------------------------------------------------*
*                             Define for 进度条
*-----------------------------------------------------------------------*
DATA: i_prog TYPE i,
i_prog2 TYPE i.
*修改选择屏,增加单选按钮,控制用户进入当前库存查询界面或者是可用库存查询界面
SELECTION-SCREEN BEGIN OF BLOCK 001 WITH FRAME TITLE text-001.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 10.
PARAMETERS:
p_po RADIOBUTTON GROUP rad1 USER-COMMAND p_po DEFAULT 'X'.             "P_PO当前库存查询
SELECTION-SCREEN COMMENT 13(18) stext-02 FOR FIELD p_po.
SELECTION-SCREEN POSITION 37.
PARAMETERS:
p_mr RADIOBUTTON GROUP rad1.
SELECTION-SCREEN COMMENT 40(18) stext-03 FOR FIELD p_mr.               "P_MR可用库存查询
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK 001 .
*Define selecltion screen
SELECTION-SCREEN BEGIN OF BLOCK 002 WITH FRAME TITLE t1.
SELECT-OPTIONS:s_matnr FOR mchb-matnr MEMORY ID matnr.                 "物料编码
SELECT-OPTIONS:s_werks FOR t001w-werks MEMORY ID werks OBLIGATORY.     "工厂 为必填项目
SELECT-OPTIONS:s_lgort FOR t001l-lgort  MEMORY ID lgort OBLIGATORY.     "库存地点 为必填项目
SELECT-OPTIONS:s_charg FOR mchb-charg  MEMORY ID charg.                 "批号
SELECT-OPTIONS:s_matkl FOR mara-matkl MEMORY ID matkl.                 "物料组
SELECT-OPTIONS:s_spart FOR mara-spart MEMORY ID spart.                 "产品组
SELECT-OPTIONS:s_sort0 FOR mchb-ersda NO INTERVALS NO-EXTENSION MEMORY ID ersda DEFAULT sy-datum.                 "可用日期
PARAMETERS:s_sobkz LIKE msku-sobkz AS LISTBOX VISIBLE LENGTH 20  DEFAULT '*'.                 "特殊库存标识
SELECTION-SCREEN END OF BLOCK 002.
AT SELECTION-SCREEN OUTPUT.                   "初始化选择屏幕中类型下拉菜单项
  stext-02 = '当前库存查询'.
  stext-03 = '可用库存查询'.
  REFRESH list1.
*  APPEND VALUE1 TO LIST1.
  name1 = 'S_SOBKZ'.
  value1-key = '*'.
  value1-text = '公司库存'.
  APPEND value1 TO list1.
  name1 = 'S_SOBKZ'.
  value1-key = 'W'.
  value1-text = '客户库存'.
  APPEND value1 TO list1.
  value1-key = 'E'.
  value1-text = '销售订单库存'.
  APPEND value1 TO list1.
  value1-key = 'O'.
  value1-text = '供应商库存'.
  APPEND value1 TO list1.
  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id     = name1
      values = list1.
  PERFORM set_screen.
*Program initialization
INITIALIZATION.
*Select data
START-OF-SELECTION.
  PERFORM getdata.      "Read data
  PERFORM processdata.
  PERFORM events_build. "alv event
  PERFORM layout_build. "define alv format attribute
  PERFORM fields_build. "define information of fieldcat
  PERFORM display_data.
END-OF-SELECTION.
  DATA:
    pagenum TYPE i VALUE 1. "report number
END-OF-PAGE.
  pagenum = pagenum + 1.
*double click event of row item
AT LINE-SELECTION.
**&---------------------------------------------------------------------*
**& FORM SET_SCREEN
**&---------------------------------------------------------------------*
** SET SCREEN ELEMENT DISPLAY
**----------------------------------------------------------------------*
FORM set_screen.
  IF p_po EQ 'X'.
    LOOP AT SCREEN.
      IF screen-name = 'S_LGORT' OR
         screen-name = '%_S_LGORT_%_APP_%-TEXT' OR
         screen-name = '%_S_LGORT_%_APP_%-OPTI_PUSH' OR
         screen-name = 'S_LGORT-LOW' OR
         screen-name = '%_S_LGORT_%_APP_%-TO_PUSH' OR
         screen-name = 'S_LGORT-HIGH' OR
         screen-name = '%_S_LGORT_%_APP_%-VALU_PUSH'.
        screen-active = 1.
        MODIFY SCREEN.
        CONTINUE.
      ENDIF.
      IF screen-name = 'S_CHARG' OR
         screen-name = '%_S_CHARG_%_APP_%-TEXT' OR
         screen-name = '%_S_CHARG_%_APP_%-OPTI_PUSH' OR
         screen-name = 'S_CHARG-LOW' OR
         screen-name = '%_S_CHARG_%_APP_%-TO_PUSH' OR
         screen-name = 'S_CHARG-HIGH' OR
         screen-name = '%_S_CHARG_%_APP_%-VALU_PUSH'.
        screen-active = 1.
        MODIFY SCREEN.
        CONTINUE.
      ENDIF.
      IF screen-name = 'S_SOBKZ' OR
         screen-name = '%_S_SOBKZ_%_APP_%-TEXT' OR
         screen-name = '%_S_SOBKZ_%_APP_%-OPTI_PUSH' OR
         screen-name = 'S_SOBKZ-LOW' OR
         screen-name = '%_S_SOBKZ_%_APP_%-TO_PUSH' OR
         screen-name = 'S_SOBKZ-HIGH' OR
         screen-name = '%_S_SOBKZ_%_APP_%-VALU_PUSH'.
        screen-active = 1.
        MODIFY SCREEN.
        CONTINUE.
      ENDIF.
      IF screen-name = 'S_SORT0' OR
         screen-name = '%_S_SORT0_%_APP_%-TEXT' OR
         screen-name = '%_S_SORT0_%_APP_%-OPTI_PUSH' OR
         screen-name = 'S_SORT0-LOW' OR
         screen-name = '%_S_SORT0_%_APP_%-TO_PUSH' OR
         screen-name = 'S_SORT0-HIGH' OR
         screen-name = '%_S_SORT0_%_APP_%-VALU_PUSH'.
        screen-active = 0.
        MODIFY SCREEN.
        CONTINUE.
      ENDIF.
    ENDLOOP.
  ELSEIF p_mr EQ 'X'.
    LOOP AT SCREEN.
      IF screen-name = 'S_LGORT' OR
         screen-name = '%_S_LGORT_%_APP_%-TEXT' OR
         screen-name = '%_S_LGORT_%_APP_%-OPTI_PUSH' OR
         screen-name = 'S_LGORT-LOW' OR
         screen-name = '%_S_LGORT_%_APP_%-TO_PUSH' OR
         screen-name = 'S_LGORT-HIGH' OR
         screen-name = '%_S_LGORT_%_APP_%-VALU_PUSH'.
        screen-active = 0.
        MODIFY SCREEN.
        CONTINUE.
      ENDIF.
      IF screen-name = 'S_CHARG' OR
         screen-name = '%_S_CHARG_%_APP_%-TEXT' OR
         screen-name = '%_S_CHARG_%_APP_%-OPTI_PUSH' OR
         screen-name = 'S_CHARG-LOW' OR
         screen-name = '%_S_CHARG_%_APP_%-TO_PUSH' OR
         screen-name = 'S_CHARG-HIGH' OR
         screen-name = '%_S_CHARG_%_APP_%-VALU_PUSH'.
        screen-active = 0.
        MODIFY SCREEN.
        CONTINUE.
      ENDIF.
      IF screen-name = 'S_SOBKZ' OR
         screen-name = '%_S_SOBKZ_%_APP_%-TEXT' OR
         screen-name = '%_S_SOBKZ_%_APP_%-OPTI_PUSH' OR
         screen-name = 'S_SOBKZ-LOW' OR
         screen-name = '%_S_SOBKZ_%_APP_%-TO_PUSH' OR
         screen-name = 'S_SOBKZ-HIGH' OR
         screen-name = '%_S_SOBKZ_%_APP_%-VALU_PUSH'.
        screen-active = 0.
        MODIFY SCREEN.
        CONTINUE.
      ENDIF.
      IF screen-name = 'S_SORT0' OR
         screen-name = '%_S_SORT0_%_APP_%-TEXT' OR
         screen-name = '%_S_SORT0_%_APP_%-OPTI_PUSH' OR
         screen-name = 'S_SORT0-LOW' OR
         screen-name = '%_S_SORT0_%_APP_%-TO_PUSH' OR
         screen-name = 'S_SORT0-HIGH' OR
         screen-name = '%_S_SORT0_%_APP_%-VALU_PUSH'.
        screen-active = 1.
        MODIFY SCREEN.
        CONTINUE.
      ENDIF.
    ENDLOOP.
    FREE:  s_lgort, s_charg, s_sobkz.            "当切换到可用库存查询界面时候   初始化这三个变量
  ENDIF.
ENDFORM.                    "SET_SCREEN
*&--------------------------------------------------------------------*
*&      Form  getdata
*&--------------------------------------------------------------------*
*      Get data and select relevant fields form database table
*---------------------------------------------------------------------*
FORM getdata.
  CLEAR hd_itab.
  CLEAR hd_itab[].
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      text = '数据处理中,请等待...'.
  PERFORM sub_get_packing.         "获取物料可用于进行件数换算的内表--包含物料编码以及件数换算单位
  IF s_sobkz <> 'W' AND s_sobkz <> 'E' AND s_sobkz <> 'O'.
    "如果没有选择特殊库存标识
    SELECT mchb~werks mchb~lgort mchb~charg mchb~matnr mara~matkl mara~spart marc~xchpf mchb~clabs      "取批次库存数量                                  "取批次库存数量
    INTO CORRESPONDING FIELDS OF TABLE hd_itab
    FROM mchb
    INNER JOIN marc ON mchb~matnr = marc~matnr AND mchb~werks = marc~werks
    INNER JOIN mara ON mchb~matnr = mara~matnr
      WHERE mchb~matnr IN s_matnr
        AND mchb~werks IN s_werks
        AND mchb~lgort IN s_lgort
        AND mchb~charg IN s_charg
        AND mara~matkl IN s_matkl
        AND mara~spart IN s_spart
        AND marc~xchpf = 'X'.
    SELECT mard~werks mard~lgort mard~matnr mara~matkl mara~spart marc~xchpf mard~labst AS clabs     "取非批次库存数量
    APPENDING CORRESPONDING FIELDS OF TABLE hd_itab
    FROM mard
    INNER JOIN marc ON mard~matnr = marc~matnr AND mard~werks = marc~werks
    INNER JOIN mara ON mard~matnr = mara~matnr
      WHERE mard~matnr IN s_matnr
        AND mard~werks IN s_werks
        AND mard~lgort IN s_lgort
        AND mara~matkl IN s_matkl
        AND mara~spart IN s_spart
        AND marc~xchpf <> 'X'.
    IF s_sobkz = ' '.   "如果选择了企业库存标识'*' 则不再去获取三种特殊库存数量
      "如果没有选择特殊库存标识 也没有选择企业库存标识,则依次再获取三种特殊库存库存量
      PERFORM sub_getdata_msku.
      PERFORM sub_getdata_mska.
      PERFORM sub_getdata_mslb.
    ENDIF.
  ELSEIF s_sobkz = 'W'.          "获取客户库存数量
    PERFORM sub_getdata_msku.
  ELSEIF s_sobkz = 'E'.          "获取供应商库存数量
    PERFORM sub_getdata_mska.
  ELSEIF s_sobkz = 'O'.          "获取销售订单库存数量
    PERFORM sub_getdata_mslb.
  ENDIF.
  SELECT matnr meins
  INTO CORRESPONDING FIELDS OF TABLE mara_itab
  FROM mara.
  SORT mara_itab ASCENDING BY matnr.
  SORT hd_itab ASCENDING BY matnr.
  DELETE hd_itab WHERE clabs = 0.   "排除库存数量为零的记录
ENDFORM.     "getdata
*&---------------------------------------------------------------------*
*&      Form  PROCESSDATA
*&---------------------------------------------------------------------*
FORM processdata .
  DATA: l_serno TYPE i,
        s_serno TYPE string.
  LOOP AT hd_itab.
    IF hd_itab-lgort IS NOT INITIAL.
      SELECT SINGLE lgobe INTO hd_itab-lgobe FROM t001l
        WHERE werks = hd_itab-werks AND lgort = hd_itab-lgort.
    ENDIF.
    SELECT SINGLE maktx INTO hd_itab-maktx FROM makt
      WHERE matnr = hd_itab-matnr AND spras = '1'.
    SELECT SINGLE vtext INTO hd_itab-vtext FROM tspat
      WHERE spart = hd_itab-spart AND spras = '1'.
    READ TABLE mara_itab INTO mara_itab WITH KEY matnr = hd_itab-matnr   "用内表代替select语句,意图提高性能
    BINARY SEARCH.
    IF sy-subrc = 0.
      hd_itab-meins = mara_itab-meins.
    ENDIF.
**基本计量单位换算公斤数量
**每基本单位等于多少KG,如果kzmeinh = 'X'则为每KG等于多少基本单位
**如果基本单位为KG,则直接将基本单位库存数量赋值给公斤计库存数量
    CASE hd_itab-meins.
      WHEN 'KG'.
        hd_itab-zkcsl = hd_itab-clabs.
      WHEN OTHERS.
        CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
          EXPORTING
            input                = hd_itab-clabs      "clabs--基本计量单位下库存数量,为传入参数
            kzmeinh              = ' '
            matnr                = hd_itab-matnr
            meinh                = 'KG'
          IMPORTING
            output               = hd_itab-zkcsl      "输出值赋值给zkcsl--公斤计库存数量
          EXCEPTIONS
            conversion_not_found = 1
            input_invalid        = 2
            material_not_found   = 3
            meinh_not_found      = 4
            meins_missing        = 5
            no_meinh             = 6
            output_invalid       = 7
            overflow             = 8
            OTHERS               = 9.
        IF sy-subrc <> 0.
* Implement suitable error handling here
        ENDIF.
    ENDCASE.
    READ TABLE unit_itab INTO unit_itab WITH KEY matnr = hd_itab-matnr   "用内表代替select语句,意图提高性能
    BINARY SEARCH.
    hd_itab-xmeinh = unit_itab-meinh.
**调用函数,进行当前库存件数换算
    CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
      EXPORTING
        i_matnr              = hd_itab-matnr
        i_in_me              = hd_itab-meins
        i_out_me             = hd_itab-xmeinh
        i_menge              = hd_itab-clabs
      IMPORTING
        e_menge              = hd_itab-zkcjs
      EXCEPTIONS
        error_in_application = 1
        error                = 2
        OTHERS               = 3.
    MODIFY hd_itab.
    CLEAR hd_itab.
  ENDLOOP.
  IF p_mr = 'X'.                    "根据判断标识决定是否进行可用库存数量计算
    PERFORM sub_get_stock_requirements.  "可用库存数量
    LOOP AT hd_itab.
**基本计量单位换算公斤数量
**每基本单位等于多少KG,如果kzmeinh = 'X'则为每KG等于多少基本单位
**如果基本单位为KG,则直接将基本单位库存数量赋值给公斤计库存数量
      CASE hd_itab-meins.
        WHEN 'KG'.
          hd_itab-zkcsl = hd_itab-mng01.
        WHEN OTHERS.
          CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
            EXPORTING
              input                = hd_itab-mng01      "mng01--基本计量单位下可用库存数量,为传入参数
              kzmeinh              = ' '
              matnr                = hd_itab-matnr
              meinh                = 'KG'
            IMPORTING
              output               = hd_itab-zkcsl      "输出值赋值给zkcsl--公斤计可用库存数量
            EXCEPTIONS
              conversion_not_found = 1
              input_invalid        = 2
              material_not_found   = 3
              meinh_not_found      = 4
              meins_missing        = 5
              no_meinh             = 6
              output_invalid       = 7
              overflow             = 8
              OTHERS               = 9.
          IF sy-subrc <> 0.
* Implement suitable error handling here
          ENDIF.
      ENDCASE.
**调用函数,进行可用库存件数换算
      CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
        EXPORTING
          i_matnr              = hd_itab-matnr
          i_in_me              = hd_itab-meins
          i_out_me             = hd_itab-xmeinh
          i_menge              = hd_itab-mng01
        IMPORTING
          e_menge              = hd_itab-mng01js
        EXCEPTIONS
          error_in_application = 1
          error                = 2
          OTHERS               = 3.
    MODIFY hd_itab.
    CLEAR hd_itab.
    ENDLOOP.
  ENDIF.
  LOOP AT hd_itab.
**调用函数,根据登录时候的语言显示条目单位采用何种语言显示“如中文 套、件 而英文 EA ST ”
    CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'   "新增功能
      EXPORTING
        input          = hd_itab-xmeinh
        language       = sy-langu
      IMPORTING
        output         = hd_itab-zmeinh
      EXCEPTIONS
        unit_not_found = 1
        OTHERS         = 2.
    MODIFY hd_itab.
    CLEAR hd_itab.
    l_serno = l_serno + 1.
  ENDLOOP.
  s_serno = l_serno .
  IF p_po = 'X'.
    CONCATENATE '当前库存查询:  '  s_serno ' 条记录' INTO i_title.
  ELSE.
    CONCATENATE '可用库存查询:  '  s_serno ' 条记录' INTO i_title.
  ENDIF.
ENDFORM.                    " PROCESSDATA
*&---------------------------------------------------------------------*
*&      Form  sub_get_packing
*&---------------------------------------------------------------------*
*       排除KG 和 L单位后,取唯一包装,输出物料编码和包装单位
*----------------------------------------------------------------------*
FORM sub_get_packing.
  CLEAR unit_itab.
  CLEAR unit_itab[].
  CLEAR unit_count_itab.
  CLEAR unit_count_itab[].
  SELECT matnr meinh
  INTO CORRESPONDING FIELDS OF TABLE unit_itab
  FROM marm
  WHERE meinh <> 'KG' AND meinh <> 'L'.
  SELECT DISTINCT matnr COUNT( * )
     INTO unit_count_itab
       FROM marm
       WHERE meinh <> 'L' AND meinh <> 'KG'
       GROUP BY matnr
       HAVING COUNT( * ) > 1.
    APPEND unit_count_itab.
  ENDSELECT.
  SORT unit_itab ASCENDING BY matnr.
  SORT unit_count_itab ASCENDING BY matnr.
  LOOP AT unit_itab INTO unit_itab.
    READ TABLE unit_count_itab INTO unit_count_itab WITH KEY matnr = unit_itab-matnr   "用内表代替select语句,意图提高性能
    BINARY SEARCH.
    IF sy-subrc = 0.
      DELETE TABLE unit_itab.
    ENDIF.
  ENDLOOP.
ENDFORM.                    "sub_get_packing
*&---------------------------------------------------------------------*
*&      Form  sub_getdata_msku
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM sub_getdata_msku.
  SELECT  msku~werks msku~charg msku~sobkz msku~matnr mara~matkl mara~spart msku~kulab AS clabs  msku~kunnr kna1~name1
  APPENDING CORRESPONDING FIELDS OF TABLE hd_itab
  FROM msku
*  INNER JOIN mara ON msku~matnr = mara~matnr
  INNER JOIN kna1 ON msku~kunnr = kna1~kunnr
  INNER JOIN mara ON msku~matnr = mara~matnr
*  INNER JOIN makt ON msku~matnr = makt~matnr AND makt~spras = '1'    "取物料中文描述,'1'表示中文  'E'表示英文
    WHERE msku~matnr IN s_matnr
      AND msku~werks IN s_werks
      AND msku~charg IN s_charg
      AND mara~matkl IN s_matkl
      AND mara~spart IN s_spart.
*    ORDER BY msku~werks msku~matnr msku~charg.
ENDFORM.                    "sub_getdata_msku
*&---------------------------------------------------------------------*
*&      Form  sub_getdata_mska
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM sub_getdata_mska.
  SELECT  mska~werks mska~lgort mska~charg mska~sobkz mska~matnr mara~matkl mara~spart  mska~kalab AS clabs  mska~vbeln mska~posnr
  APPENDING CORRESPONDING FIELDS OF TABLE hd_itab
  FROM mska
  INNER JOIN mara ON mska~matnr = mara~matnr
*  INNER JOIN mara ON mska~matnr = mara~matnr
*  INNER JOIN t001l ON mska~lgort = t001l~lgort AND mska~werks = t001l~werks    "取库存地点描述
*  INNER JOIN makt ON mska~matnr = makt~matnr AND makt~spras = '1'    "取物料中文描述,'1'表示中文  'E'表示英文
    WHERE mska~matnr IN s_matnr
      AND mska~werks IN s_werks
      AND mska~charg IN s_charg
      AND mara~matkl IN s_matkl
      AND mara~spart IN s_spart.
*    ORDER BY mska~werks mska~lgort mska~matnr mska~charg.
ENDFORM.                    "sub_getdata_mska
*&---------------------------------------------------------------------*
*&      Form  sub_getdata_mslb
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM sub_getdata_mslb.
  SELECT  mslb~werks mslb~charg mslb~sobkz mslb~matnr mara~matkl mara~spart mslb~lblab AS clabs mslb~lifnr lfa1~name1 AS name2
  APPENDING CORRESPONDING FIELDS OF TABLE hd_itab
  FROM mslb
*  INNER JOIN mara ON mslb~matnr = mara~matnr
  INNER JOIN lfa1 ON mslb~lifnr = lfa1~lifnr
  INNER JOIN mara ON mslb~matnr = mara~matnr
*  INNER JOIN makt ON mslb~matnr = makt~matnr AND makt~spras = '1'    "取物料中文描述,'1'表示中文  'E'表示英文
    WHERE mslb~matnr IN s_matnr
      AND mslb~werks IN s_werks
      AND mslb~charg IN s_charg
      AND mara~matkl IN s_matkl
      AND mara~spart IN s_spart.
ENDFORM.                    "sub_getdata_mslb
*&--------------------------------------------------------------------*
*&      Form  layout_build
*&--------------------------------------------------------------------*
*      Define ALV layout attribute
*---------------------------------------------------------------------*
FORM layout_build .
  i_layout-zebra = 'X'.
*  i_layout-detail_popup = 'X'.
  i_layout-no_vline = ' '.
  i_layout-colwidth_optimize = 'X'.
*  i_layout-detail_initial_lines = 'X'.
*  i_layout-detail_titlebar = 'detail content'.
*  i_layout-box_fieldname  = 'LINE'.
*  i_layout-f2code = '&ETA'.
*  i_layout-f2code = '&IC1'.
  i_layout-info_fieldname = 'COLOR'.  "Color value
  i_layout-no_colhead = ' '.
  w_repid = sy-repid.
ENDFORM.                    " layout_build

你可能感兴趣的:(SAP&MM)