ABAP 获取批次特性

Posted 想发财的小夏

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ABAP 获取批次特性相关的知识,希望对你有一定的参考价值。

按照table获取批次特性,传入ct_data为表内容,动态读取批次特性数据,填入表行
( 注意:批次特性传入名称要和维护的批次特性值名称一致 )

FUNCTION zmm01_get_batch_objcl_table.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  TABLES
*"      CT_DATA
*"----------------------------------------------------------------------

  DATA:lr_atnam TYPE rseloption,
       lr_atinn TYPE rseloption,
       BEGIN OF ls_ausp,
         objek TYPE ausp-objek,
         atinn TYPE ausp-atinn,
         atwrt TYPE ausp-atwrt,
       END OF ls_ausp,
       lt_ausp LIKE STANDARD TABLE OF ls_ausp
               WITH NON-UNIQUE SORTED KEY key COMPONENTS objek,
       BEGIN OF ls_inob,
         cuobj TYPE inob-cuobj,
         objek TYPE inob-objek,
         matnr TYPE matnr,
         werks TYPE werks_d,
         charg TYPE charg_d,
       END OF ls_inob,
       lt_inob LIKE TABLE OF ls_inob.

  LOOP AT ct_data ASSIGNING FIELD-SYMBOL(<fs_data>).

    ASSIGN COMPONENT 'MATNR'  OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<lfs_matnr>).   " 物料
    ASSIGN COMPONENT 'CHARG'  OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<lfs_charg>).   " 批次
    ASSIGN COMPONENT 'WERKS'  OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<lfs_werks>).   " 工厂

    CLEAR ls_inob.
    ls_inob-objek+0(40)  = <lfs_matnr>.
    ls_inob-objek+40(4)  = <lfs_werks>.
    ls_inob-objek+44(10) = <lfs_charg>.
    ls_inob-cuobj  = ''.
    ls_inob-matnr  = <lfs_matnr>.
    ls_inob-werks  = <lfs_werks>.
    ls_inob-charg  = <lfs_charg>.
    APPEND ls_inob TO lt_inob.

  ENDLOOP.
  SORT lt_inob BY matnr werks charg.
  DELETE ADJACENT DUPLICATES FROM lt_inob COMPARING matnr werks charg.

  CHECK lt_inob IS NOT INITIAL.

  SELECT atnam,atinn
    FROM cabn
    INTO TABLE @DATA(lt_cabn)
   WHERE atnam LIKE 'Z%'. " Z开头的批次特性
  SORT lt_cabn BY atinn.

  SELECT 'I' AS sign ,'EQ' AS option, a~atinn AS low
    FROM cabn AS a
   INNER JOIN @lt_cabn AS b
      ON a~atnam = b~atnam
    INTO CORRESPONDING FIELDS OF TABLE @lr_atinn.

  " 获取 coubj-> objek
  SELECT a~objek,CAST( a~cuobj AS CHAR ) AS cuobj
    FROM inob AS a
   INNER JOIN @lt_inob AS b
      ON a~objek = b~objek
   WHERE a~klart = '022'
    INTO TABLE @DATA(lt_coubj).
  SORT lt_coubj BY objek.

  IF lt_coubj IS NOT INITIAL.

    SELECT a~objek,a~atinn,a~atwrt
      FROM ausp AS a
     INNER JOIN @lt_coubj AS b
        ON a~objek = b~cuobj
     WHERE a~mafid = 'O'
       AND a~atinn IN @lr_atinn
      INTO CORRESPONDING FIELDS OF TABLE @lt_ausp.

  ENDIF.

  LOOP AT ct_data ASSIGNING <fs_data>.

    ASSIGN COMPONENT 'MATNR'  OF STRUCTURE <fs_data> TO <lfs_matnr>.   " 物料
    ASSIGN COMPONENT 'CHARG'  OF STRUCTURE <fs_data> TO <lfs_charg>.   " 批次
    ASSIGN COMPONENT 'WERKS'  OF STRUCTURE <fs_data> TO <lfs_werks>.   " 工厂

    READ TABLE lt_inob INTO ls_inob WITH KEY matnr = <lfs_matnr>
                                             werks = <lfs_werks>
                                             charg = <lfs_charg> BINARY SEARCH.
    CHECK sy-subrc EQ 0.

    READ TABLE lt_coubj INTO DATA(ls_coubj) WITH KEY objek = ls_inob-objek BINARY SEARCH.

    CHECK sy-subrc EQ 0.

    LOOP AT lt_ausp INTO ls_ausp USING KEY key WHERE objek = ls_coubj-cuobj.

      READ TABLE lt_cabn INTO DATA(ls_cabn) WITH KEY atinn = ls_ausp-atinn BINARY SEARCH.
      CHECK sy-subrc EQ 0.

      ASSIGN COMPONENT ls_cabn-atnam OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<fs_atwrt>).
      IF <fs_atwrt> IS ASSIGNED.
        <fs_atwrt> = ls_ausp-atwrt.
      ENDIF.

      UNASSIGN <fs_atwrt>.
    ENDLOOP.

  ENDLOOP.

ENDFUNCTION.

以上是关于ABAP 获取批次特性的主要内容,如果未能解决你的问题,请参考以下文章

ABAP 获取批次特性

ABAP 获取批次特性

如何利用ABAP查物料的批次

MM系列SAP MM模块-关于批次特性的查看和获取

ABAP QM 生产完工入库的质量检验 的增强怎么做求参考案例

更改物料批次特性值问题请教