ABAP-取物料批次特性值

物料批次特性值

*&---------------------------------------------------------------------*
*& Report  ZMMR085
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZMMR085.

TABLES:MARA.

DATA:BEGIN OF GT_DATA OCCURS 0,
       CHARG TYPE MCH1-CHARG,
       MATNR TYPE MARA-MATNR,
       MAKTX TYPE MAKT-MAKTX,
       CLASS TYPE KLAH-CLASS,
       OBJEK TYPE INOB-OBJEK,
       SCRQ  TYPE SY-DATUM,
       LIFNR TYPE LFA1-LIFNR,
       SHRQ  TYPE SY-DATUM,
       LAENG TYPE STRING,
       BREIT TYPE STRING,
       HOEHE TYPE STRING,
       LRENG TYPE STRING,
     END OF GT_DATA.
FIELD-SYMBOLS  LIKE LINE OF GT_DATA.

DATA:GT_MARA LIKE TABLE OF GT_DATA WITH HEADER LINE.

DATA:BEGIN OF GT_INOB OCCURS 0,
       CUOBJ  TYPE INOB-CUOBJ,
       OBJEK  TYPE INOB-OBJEK,
       OBJEK2 TYPE KSSK-OBJEK,
       MATNR  TYPE MARA-MATNR,
       CHARG  TYPE MCH1-CHARG,
     END OF GT_INOB.

DATA:GT_KSSK TYPE TABLE OF KSSK WITH HEADER LINE.
DATA:GT_KLAH TYPE TABLE OF KLAH WITH HEADER LINE.
DATA:GT_AUSP TYPE TABLE OF AUSP WITH HEADER LINE.

FIELD-SYMBOLS  LIKE LINE OF GT_INOB.

SELECT-OPTIONS:S_MATNR FOR MARA-MATNR.

START-OF-SELECTION.

  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      TEXT = '正在取物料数据...'.

  SELECT
    A~MATNR,
    B~MAKTX
    INTO CORRESPONDING FIELDS OF TABLE @GT_MARA
    FROM MARA AS A
    JOIN MAKT AS B
    ON A~MATNR EQ B~MATNR AND B~SPRAS EQ '1'
    WHERE A~MATNR IN @S_MATNR
    ORDER BY A~MATNR.

  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      TEXT = '正在取在内部编号和对象之间的链接...'.

  "在内部编号和对象之间的链接
  SELECT
  CUOBJ,
  OBJEK
  INTO  TABLE @GT_INOB
  FROM INOB
  WHERE KLART EQ '023'
  AND   OBTAB EQ 'MCH1'.

  SORT GT_INOB BY OBJEK.

  LOOP AT GT_INOB ASSIGNING .
    -OBJEK2 = -CUOBJ.

    -MATNR = -OBJEK+0(18).
    -CHARG = -OBJEK+18(10).

  ENDLOOP.

  DELETE GT_INOB WHERE MATNR NOT IN S_MATNR.

  IF GT_INOB[] IS NOT INITIAL.

    SELECT *
      INTO TABLE @GT_AUSP
      FROM AUSP
      FOR ALL ENTRIES IN @GT_INOB
      WHERE OBJEK EQ @GT_INOB-OBJEK2
      AND   KLART EQ '023'.

    SORT GT_AUSP BY OBJEK.
  ENDIF.

  DATA:GV_LINE    TYPE I,
       GV_COUNT   TYPE I,
       GV_PERCENT TYPE P,
       GV_R_FLD   TYPE CHAR10.

  GV_LINE = LINES( GT_INOB ).

  CLEAR:GT_DATA[],GT_DATA.

  LOOP AT GT_INOB ASSIGNING .

    GV_COUNT = SY-TABIX.

    GV_PERCENT = GV_COUNT * 100 / GV_LINE .

    READ TABLE GT_AUSP WITH KEY OBJEK = -OBJEK2 BINARY SEARCH TRANSPORTING NO FIELDS.
    IF SY-SUBRC EQ 0.
      LOOP AT GT_AUSP FROM SY-TABIX.
        IF GT_AUSP-OBJEK NE -OBJEK2.
          EXIT.
        ENDIF.

        CLEAR GV_R_FLD.

        CASE GT_AUSP-ATINN.
          WHEN '0000000818'."生产日期

            CALL FUNCTION 'MC_FLTP_CHAR'
              EXPORTING
                FC_A_FLD = GT_AUSP-ATFLV
              IMPORTING
                FC_R_FLD = GV_R_FLD.
            CONDENSE GV_R_FLD NO-GAPS.
            GT_DATA-SCRQ = GV_R_FLD.
          WHEN '0000000819'."供应商帐户号
            GT_DATA-LIFNR = GT_AUSP-ATWRT.

            CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
              EXPORTING
                INPUT  = GT_DATA-LIFNR
              IMPORTING
                OUTPUT = GT_DATA-LIFNR.

          WHEN '0000000820'."最近的收货日期
            CALL FUNCTION 'MC_FLTP_CHAR'
              EXPORTING
                FC_A_FLD = GT_AUSP-ATFLV
              IMPORTING
                FC_R_FLD = GV_R_FLD.
            CONDENSE GV_R_FLD NO-GAPS.
            GT_DATA-SHRQ = GV_R_FLD.
          WHEN '0000000859'."Z_LAENG
            CALL FUNCTION 'MC_FLTP_CHAR'
              EXPORTING
                FC_A_FLD = GT_AUSP-ATFLV
              IMPORTING
                FC_R_FLD = GV_R_FLD.
            CONDENSE GV_R_FLD NO-GAPS.
            GT_DATA-LAENG = GV_R_FLD.
          WHEN '0000000860'."Z_BREIT
            CALL FUNCTION 'MC_FLTP_CHAR'
              EXPORTING
                FC_A_FLD = GT_AUSP-ATFLV
              IMPORTING
                FC_R_FLD = GV_R_FLD.
            CONDENSE GV_R_FLD NO-GAPS.
            GT_DATA-BREIT = GV_R_FLD.
          WHEN '0000000861'."Z_HOEHE
            CALL FUNCTION 'MC_FLTP_CHAR'
              EXPORTING
                FC_A_FLD = GT_AUSP-ATFLV
              IMPORTING
                FC_R_FLD = GV_R_FLD.
            CONDENSE GV_R_FLD NO-GAPS.
            GT_DATA-HOEHE = GV_R_FLD.
          WHEN '0000000862'."Z_LRENG
            CALL FUNCTION 'MC_FLTP_CHAR'
              EXPORTING
                FC_A_FLD = GT_AUSP-ATFLV
              IMPORTING
                FC_R_FLD = GV_R_FLD.
            CONDENSE GV_R_FLD NO-GAPS.
            GT_DATA-LRENG = GV_R_FLD.
        ENDCASE.

        GT_DATA-MATNR = -MATNR.
        GT_DATA-CHARG = -CHARG.

      ENDLOOP.
      IF GT_DATA IS NOT INITIAL.

        READ TABLE GT_MARA WITH KEY MATNR = GT_DATA-MATNR BINARY SEARCH.
        IF SY-SUBRC EQ 0.
          GT_DATA-MAKTX = GT_MARA-MAKTX.
        ENDIF.

        APPEND GT_DATA.
        CLEAR  GT_DATA.
      ENDIF.
    ENDIF.


    IF GV_PERCENT MOD 25 EQ 0.
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
        EXPORTING
*         percentage = gv_percent     "百分比的数值,用来控制秒表的指针。
          TEXT = '正在匹配特性值...' && GV_PERCENT && '%'.   "状态栏显示的文本。
    ENDIF.

  ENDLOOP.






  DATA:GT_FCAT TYPE LVC_T_FCAT,
       GS_FCAT TYPE LVC_S_FCAT.
  FIELD-SYMBOLS  TYPE LVC_S_FCAT.

  DATA:LS_LAYOUT TYPE LVC_S_LAYO.

  GS_FCAT-FIELDNAME = 'MATNR'.
  GS_FCAT-COLTEXT   = '物料编码'.
  GS_FCAT-REF_TABLE = 'MARA'.
  APPEND GS_FCAT TO GT_FCAT.
  CLEAR  GS_FCAT.
  GS_FCAT-FIELDNAME = 'MAKTX'.
  GS_FCAT-COLTEXT   = '物料描述'.
  APPEND GS_FCAT TO GT_FCAT.
  CLEAR  GS_FCAT.
  GS_FCAT-FIELDNAME = 'CHARG'.
  GS_FCAT-COLTEXT   = '批次'.
  APPEND GS_FCAT TO GT_FCAT.
  CLEAR  GS_FCAT.
  GS_FCAT-FIELDNAME = 'SCRQ'.
  GS_FCAT-COLTEXT   = '生产日期'.
  APPEND GS_FCAT TO GT_FCAT.
  CLEAR  GS_FCAT.
  GS_FCAT-FIELDNAME = 'LIFNR'.
  GS_FCAT-COLTEXT   = '供应商帐户号'.
  APPEND GS_FCAT TO GT_FCAT.
  CLEAR  GS_FCAT.
  GS_FCAT-FIELDNAME = 'SHRQ'.
  GS_FCAT-COLTEXT   = '最近的收货日期'.
  APPEND GS_FCAT TO GT_FCAT.
  CLEAR  GS_FCAT.
  GS_FCAT-FIELDNAME = 'LAENG'.
  GS_FCAT-COLTEXT   = '长(Z_LAENG)'.
  APPEND GS_FCAT TO GT_FCAT.
  CLEAR  GS_FCAT.
  GS_FCAT-FIELDNAME = 'BREIT'.
  GS_FCAT-COLTEXT   = '宽(Z_BREIT)'.
  APPEND GS_FCAT TO GT_FCAT.
  CLEAR  GS_FCAT.
  GS_FCAT-FIELDNAME = 'HOEHE'.
  GS_FCAT-COLTEXT   = '高(Z_HOEHE)'.
  APPEND GS_FCAT TO GT_FCAT.
  CLEAR  GS_FCAT.
  GS_FCAT-FIELDNAME = 'LRENG'.
  GS_FCAT-COLTEXT   = '直径(Z_LRENG)'.
  APPEND GS_FCAT TO GT_FCAT.
  CLEAR  GS_FCAT.

  DATA(LV_LINE) = LINES( GT_DATA ).
  LS_LAYOUT-GRID_TITLE = '条目:' && LV_LINE.

  LS_LAYOUT-ZEBRA      = ABAP_TRUE.
  LS_LAYOUT-CWIDTH_OPT = ABAP_TRUE.

  DATA(LO_ALV) = NEW CL_GUI_ALV_GRID( CL_GUI_CONTAINER=>SCREEN0 ).

  CALL METHOD LO_ALV->SET_TABLE_FOR_FIRST_DISPLAY
    EXPORTING
      IS_LAYOUT       = LS_LAYOUT
    CHANGING
      IT_FIELDCATALOG = GT_FCAT
      IT_OUTTAB       = GT_DATA[].

  WRITE ''.

你可能感兴趣的:(ABAP-取物料批次特性值)