关闭

SAP 取出销售订单的Object Reason的相关信息

标签: SAP Sales Order InfoSAP Sales Order
424人阅读 评论(0) 收藏 举报
分类:
REPORT zsdrp301.

********************************
* INNITIALIZATION
********************************
TABLES : vbak,vbap,kna1,mara,tvagt,cdhdr,cdpos.

TYPES : BEGIN OF ltype_vbkp,
        vbeln  TYPE vbak-vbeln,
        erdat  TYPE vbak-erdat,
        ernam  TYPE vbak-ernam,
        vbtyp  TYPE vbak-vbtyp,
        auart  TYPE vbak-auart,
        vkorg  TYPE vbak-vkorg,
        vtweg  TYPE vbak-vtweg,
        spart  TYPE vbak-spart,
        vkgrp  TYPE vbak-vkgrp,
        vkbur  TYPE vbak-vkbur,
        ihrez  TYPE vbak-ihrez,
        bname  TYPE vbak-bname,
        kunnr  TYPE vbak-kunnr,
        zzoter TYPE vbak-zzoter,
        posnr  TYPE vbap-posnr,
        matnr  TYPE vbap-matnr,
        matkl  TYPE vbap-matkl,
        arktx  TYPE vbap-arktx,
        pstyv  TYPE vbap-pstyv,
        posar  TYPE vbap-posar,
        abgru  TYPE vbap-abgru,
        netwr  TYPE vbap-netwr,
        waerk  TYPE vbap-waerk,
        kwmeng TYPE vbap-kwmeng,
        vrkme  TYPE vbap-vrkme,
        END OF ltype_vbkp.

TYPES : BEGIN OF ltype_kna1,
        kunnr TYPE kna1-kunnr,
        name1 TYPE kna1-name1,
        END OF   ltype_kna1.

TYPES : BEGIN OF ltype_mara,
        matnr TYPE mara-matnr,
        normt TYPE mara-normt,
        END OF   ltype_mara.

TYPES : BEGIN OF ltype_tvagt,
        abgru TYPE tvagt-abgru,
        bezei TYPE tvagt-bezei,
        END OF   ltype_tvagt.

TYPES : BEGIN OF ltype_cdpos,
        objectid TYPE cdpos-objectid,
        changenr TYPE cdpos-changenr,
        END OF   ltype_cdpos.

TYPES : BEGIN OF ltype_cdhdr,
        objectid TYPE cdhdr-objectid,
        udate    TYPE cdhdr-udate,
        END OF   ltype_cdhdr.

TYPES : BEGIN OF ltype_middle,
        objectid TYPE cdpos-objectid,
        END OF   ltype_middle.

DATA : lt_middle TYPE TABLE OF ltype_middle,
        ls_middle LIKE LINE OF  lt_middle.

DATA : lt_vbkp TYPE TABLE OF ltype_vbkp,
       ls_vbkp LIKE LINE OF  lt_vbkp.

DATA : lt_kna1 TYPE TABLE OF ltype_kna1,
       ls_kna1 LIKE LINE OF  lt_kna1.

DATA : lt_mara TYPE TABLE OF ltype_mara,
       ls_mara LIKE LINE OF  lt_mara.

DATA : lt_tvagt TYPE TABLE OF ltype_tvagt,
       ls_tvagt LIKE LINE OF  lt_tvagt.

DATA : lt_cdpos TYPE TABLE OF ltype_cdpos,
       ls_cdpos LIKE LINE OF  lt_cdpos.

DATA : lt_cdhdr TYPE TABLE OF ltype_cdhdr,
       ls_cdhdr LIKE LINE OF  lt_cdhdr.

DATA : lt_display TYPE TABLE OF zssdrp301_struc_list,
       ls_display LIKE  LINE OF lt_display.

********************************
* SELECTION-SCREEN
********************************
SELECTION-SCREEN BEGIN OF BLOCK blk01 WITH FRAME.

SELECT-OPTIONS :

m_vbeln FOR vbap-vbeln,
m_posnr FOR vbap-posnr,
m_erdat FOR vbak-erdat,
m_vkorg FOR vbak-vkorg,
m_abgru FOR vbap-abgru.

SELECTION-SCREEN END OF BLOCK blk01.

IF m_vbeln IS INITIAL AND m_abgru IS INITIAL.

  MESSAGE 'Please input selection option' TYPE 'E'.

ELSE.

  PERFORM frm_get_data.

  PERFORM frm_alv_display.
ENDIF.

********************************
* START OF SELECTION
********************************
FORM frm_get_data.
  CLEAR lt_display[].
  SELECT
      t1~vbeln
      t1~erdat
      t1~ernam
      t1~vbtyp
      t1~auart
      t1~vkorg
      t1~vtweg
      t1~spart
      t1~vkgrp
      t1~vkbur
      t1~ihrez
      t1~bname
      t1~kunnr
      t1~zzoter
      t2~posnr
      t2~matnr
      t2~matkl
      t2~arktx
      t2~pstyv
      t2~posar
      t2~abgru
      t2~netwr
      t2~waerk
      t2~kwmeng
      t2~vrkme
    FROM vbak AS t1 INNER JOIN vbap AS t2 ON t1~vbeln = t2~vbeln
    INTO CORRESPONDING FIELDS OF TABLE lt_display
    WHERE  t1~vbeln IN m_vbeln
    AND   t1~erdat  IN m_erdat
    AND   t1~vkorg  IN m_vkorg
    AND   t2~posnr  IN m_posnr
    AND   t2~abgru  IN m_abgru.

  IF lt_display IS NOT INITIAL.

    CLEAR lt_kna1[].
    SELECT
      kunnr
      name1
    FROM kna1
    INTO CORRESPONDING FIELDS OF TABLE lt_kna1
    FOR ALL ENTRIES IN lt_display
    WHERE kunnr = lt_display-kunnr.

    CLEAR lt_mara[].
    SELECT
      matnr
      normt
    FROM mara
    INTO CORRESPONDING FIELDS OF TABLE lt_mara
    FOR ALL ENTRIES IN lt_display
    WHERE matnr = lt_display-matnr.

    CLEAR lt_tvagt[].
    SELECT
     abgru
     bezei
    FROM tvagt
    INTO CORRESPONDING FIELDS OF TABLE lt_tvagt
    FOR ALL ENTRIES IN lt_display
    WHERE abgru = lt_display-abgru
    AND   spras = sy-langu.

    LOOP AT lt_display INTO ls_display.

      ls_middle-objectid = ls_display-vbeln.

      APPEND ls_middle TO lt_middle.

    ENDLOOP.

    IF lt_middle IS NOT INITIAL .

      CLEAR lt_cdpos.
      SELECT
        objectid
        changenr
      FROM cdpos
      INTO CORRESPONDING FIELDS OF TABLE lt_cdpos
      FOR ALL ENTRIES IN lt_middle
      WHERE objectid = lt_middle-objectid
      AND fname = 'ABGRU'.

    ENDIF.

    IF lt_cdpos IS NOT INITIAL.
      SELECT
        objectid
        udate
      FROM cdhdr
      INTO CORRESPONDING FIELDS OF TABLE lt_cdhdr
      FOR ALL ENTRIES IN lt_cdpos
      WHERE objectid = lt_cdpos-objectid.

    ENDIF.

  ENDIF.

  CLEAR ls_display.
  LOOP AT lt_display INTO ls_display.

    CLEAR ls_kna1.
    READ TABLE lt_kna1 INTO ls_kna1 WITH  KEY kunnr = ls_display-kunnr.
    ls_display-name1 = ls_kna1-name1.

    CLEAR ls_mara.
    READ TABLE lt_mara INTO ls_mara WITH  KEY matnr = ls_display-matnr.
    ls_display-normt = ls_mara-normt.

    CLEAR ls_tvagt.
    READ TABLE lt_tvagt INTO ls_tvagt WITH KEY abgru = ls_display-abgru.
    ls_display-bezei = ls_tvagt-bezei.

    CLEAR ls_cdhdr.
    CLEAR ls_middle.
*  ls_middle-objectid = ls_display-vbeln.
    READ TABLE lt_cdhdr INTO ls_cdhdr WITH KEY objectid = ls_display-vbeln.
    IF ls_display-abgru IS NOT INITIAL.
    ls_display-udate = ls_cdhdr-udate.
    ENDIF.

    MODIFY lt_display FROM ls_display.

  ENDLOOP.
ENDFORM.                    "frm_get_data
*&---------------------------------------------------------------------*
*&      Form  frm_alv_display
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_alv_display .


  DATA : ls_layout   TYPE slis_layout_alv.
  DATA : lt_fieldcat TYPE slis_t_fieldcat_alv.
  DATA : l_repid     TYPE sy-repid.
  PERFORM frm_build_fieldcat CHANGING lt_fieldcat.
  PERFORM frm_build_layout CHANGING ls_layout.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = sy-repid
      it_fieldcat              = lt_fieldcat
      is_layout                = ls_layout
*      i_callback_user_command  = 'FRM_USER_COMMAND'
*     i_callback_pf_status_set = 'FRM_PF_STATUS_SET'
    TABLES
      t_outtab                 = lt_display.

ENDFORM.                    " FRM_ALV_DISPLAY
*&---------------------------------------------------------------------*
*&      Form  frm_build_fieldcat
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->CT_FIELDCAT  text
*----------------------------------------------------------------------*
FORM frm_build_fieldcat  CHANGING ct_fieldcat TYPE slis_t_fieldcat_alv.

  DATA : ls_fieldcat LIKE LINE OF ct_fieldcat.
  REFRESH ct_fieldcat.

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name = 'ZSSDRP301_STRUC_LIST'
    CHANGING
      ct_fieldcat      = ct_fieldcat.


*  DELETE ct_fieldcat WHERE fieldname = 'PLANR'.

*  LOOP AT ct_fieldcat INTO ls_fieldcat.
*
*    CASE ls_fieldcat-fieldname.
*      WHEN 'MNG01'.
*        IF sy-langu = '1'.
*          ls_fieldcat-seltext_l = '工单数量'.
*        ELSE.
*          ls_fieldcat-seltext_l = 'Order quantity'.
*          ls_fieldcat-seltext_m = 'Order quantity'.
*          ls_fieldcat-seltext_s = 'Order quantity'.
*        ENDIF.
*    ENDCASE.
*
*    MODIFY ct_fieldcat FROM ls_fieldcat TRANSPORTING seltext_l seltext_m seltext_s.
*
*  ENDLOOP.
ENDFORM.                    "frm_build_fieldcat
*&---------------------------------------------------------------------*
*&      Form  frm_build_layout
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->CS_LAYOUT  text
*----------------------------------------------------------------------*
FORM frm_build_layout  CHANGING cs_layout TYPE slis_layout_alv.

  CLEAR cs_layout.
  MOVE 'X' TO cs_layout-detail_popup.
  MOVE 'X' TO cs_layout-colwidth_optimize.
  MOVE 'COLOR' TO cs_layout-info_fieldname.
*  MOVE 'SELECTED' TO cs_layout-box_fieldname.

ENDFORM.                    " FRM_BUILD_LAYOUT

1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:17225次
    • 积分:376
    • 等级:
    • 排名:千里之外
    • 原创:21篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条