SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Sales Order Changed History Display



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SD
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Tue Sep 11, 2007 6:40 pm    Post subject: Sales Order Changed History Display Reply with quote

Code:
* You can execute the report by :
* 1.  Change Date
* 2.  User Name
* 3.  Sales Order Number
*
REPORT ZSDCHANGE LINE-SIZE 132 NO STANDARD PAGE HEADING
                 LINE-COUNT 065(001)
                 MESSAGE-ID VR.

TABLES: DD04T,
        CDHDR,
        CDPOS,
        DD03L,
        DD41V,
        T685T,
        VBPA,
        TPART,
        KONVC,
        VBUK.

DATA: BEGIN OF ICDHDR OCCURS 50.
        INCLUDE STRUCTURE CDHDR.
DATA: END OF ICDHDR.

SELECT-OPTIONS: XUDATE FOR ICDHDR-UDATE,
                XNAME  FOR ICDHDR-USERNAME,
                XVBELN FOR VBUK-VBELN.

SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
PARAMETERS: SUDATE RADIOBUTTON GROUP R1,
            SNAME  RADIOBUTTON GROUP R1,
            SOBID  RADIOBUTTON GROUP R1.
SELECTION-SCREEN END OF BLOCK BLK1.

DATA: WFLAG,
      WCHANGENR LIKE CDHDR-CHANGENR,
      WUDATE LIKE CDHDR-UDATE,
      WNAME  LIKE CDHDR-USERNAME,
      WVBELN LIKE VBUK-VBELN,
      WDEC1 TYPE P DECIMALS 3,
      WDEC2 TYPE P DECIMALS 3,
      WDEC3 TYPE P DECIMALS 3,
      WDEC4 TYPE P DECIMALS 3.

DATA: UTEXT(16) VALUE 'has been changed',
      ITEXT(16) VALUE 'has been created',
      DTEXT(16) VALUE 'has been deleted'.

DATA: BEGIN OF ICDSHW OCCURS 50.
        INCLUDE STRUCTURE CDSHW.
DATA: END OF ICDSHW.

DATA: BEGIN OF ITAB OCCURS 10.
        INCLUDE STRUCTURE CDSHW.
DATA:   UDATE LIKE CDHDR-UDATE,
        USERNAME LIKE CDHDR-USERNAME,
        CHANGENR LIKE CDHDR-CHANGENR,
        VBELN(10),
        POSNR(6),
        ETENR(4),
        INDTEXT(200),
  END OF ITAB.

SELECT * FROM VBUK WHERE VBELN IN XVBELN.
  CLEAR CDHDR.
  CLEAR CDPOS.
  CDHDR-OBJECTCLAS = 'VERKBELEG'.
  CDHDR-OBJECTID   = VBUK-VBELN.
  PERFORM READHEADER.
  PERFORM READPOS.
  LOOP AT ITAB.
    CASE ITAB-TABNAME.
      WHEN 'VBPA'.
        IF ITAB-FNAME = 'KUNNR' OR
           ITAB-FNAME = 'LIFNR' OR
           ITAB-FNAME = 'PARNR' OR
           ITAB-FNAME = 'PERNR' OR
           ITAB-FNAME IS INITIAL.
         MOVE ITAB-TABKEY TO VBPA.
         SELECT SINGLE * FROM TPART WHERE SPRAS = SY-LANGU
                                   AND   PARVW = VBPA-PARVW.
         IF SY-SUBRC = 0.
           REPLACE '&' WITH TPART-VTEXT INTO ITAB-INDTEXT.
         ENDIF.
       ENDIF.
     WHEN 'VBAP'.
       IF ITAB-FNAME IS INITIAL.
         REPLACE '&' WITH 'Item' INTO ITAB-INDTEXT.
       ENDIF.
     WHEN 'KONVC'.
       MOVE ITAB-TABKEY TO KONVC.
       SELECT SINGLE * FROM T685T WHERE SPRAS = SY-LANGU
                                 AND   KVEWE = 'A'
                                 AND   KAPPL = 'V'
                                 AND   KSCHL = KONVC-KSCHL.
       IF SY-SUBRC = 0.
         REPLACE '&' WITH T685T-VTEXT INTO ITAB-INDTEXT.
       ENDIF.
     ENDCASE.
     IF ITAB-INDTEXT(1) EQ '&'.
       REPLACE '&' WITH ITAB-FTEXT(40) INTO ITAB-INDTEXT.
     ENDIF.
     IF ITAB-CHNGIND = 'I'.
       REPLACE '%' WITH ITEXT INTO ITAB-INDTEXT.
     ELSEIF ITAB-CHNGIND = 'U'.
       REPLACE '%' WITH UTEXT INTO ITAB-INDTEXT.
     ELSE.
       REPLACE '%' WITH DTEXT INTO ITAB-INDTEXT.
     ENDIF.
     CONDENSE ITAB-INDTEXT.
     MODIFY ITAB.
   ENDLOOP.
ENDSELECT.

IF SUDATE = 'X'.
  SORT ITAB BY UDATE VBELN POSNR ETENR.
ELSEIF SOBID = 'X'.
  SORT ITAB BY VBELN POSNR ETENR UDATE.
ELSE.
  SORT ITAB BY USERNAME VBELN POSNR ETENR UDATE.
ENDIF.

LOOP AT ITAB.
  CLEAR WFLAG.
  IF SUDATE = 'X'.
    IF WUDATE NE ITAB-UDATE.
      SKIP.
      WRITE:/001 ITAB-UDATE,
             023 ITAB-USERNAME,
             037(10) ITAB-VBELN.
      WFLAG = 'X'.
      WUDATE = ITAB-UDATE.
      WCHANGENR = ITAB-CHANGENR.
    ENDIF.
  ELSEIF SOBID NE 'X'.
    IF WVBELN NE ITAB-VBELN.
      SKIP.
      WRITE:/001 ITAB-VBELN.
      WVBELN = ITAB-VBELN.
    ENDIF.
  ELSE.
    IF WNAME NE ITAB-USERNAME.
      SKIP.
      WRITE:/001 ITAB-USERNAME.
      WNAME = ITAB-USERNAME.
    ENDIF.
  ENDIF.
  IF WCHANGENR NE ITAB-CHANGENR.
    WRITE:/023 ITAB-USERNAME,
           037(10) ITAB-VBELN.
       WFLAG = 'X'.
       WCHANGENR = ITAB-CHANGENR.
    ENDIF.
    IF WFLAG = 'X'.
      WRITE: 013 ITAB-CHNGIND,
             049 ITAB-POSNR,
             057 ITAB-ETENR,
             065 ITAB-INDTEXT(60).
    ELSE.
      WRITE: /013 ITAB-CHNGIND,
              049 ITAB-POSNR,
              057 ITAB-ETENR,
              065 ITAB-INDTEXT(60).
    ENDIF.
  WRITE:/065 ITAB-F_OLD.
  WRITE:/065 ITAB-F_NEW.
ENDLOOP.

FORM READHEADER.
  CALL FUNCTION 'CHANGEDOCUMENT_READ_HEADERS'
       EXPORTING
            DATE_OF_CHANGE    = CDHDR-UDATE
            OBJECTCLASS       = CDHDR-OBJECTCLAS
            OBJECTID          = CDHDR-OBJECTID
            TIME_OF_CHANGE    = CDHDR-UTIME
            USERNAME          = CDHDR-USERNAME
       TABLES
            I_CDHDR           = ICDHDR
       EXCEPTIONS
            NO_POSITION_FOUND = 1
            OTHERS            = 2.

  CASE SY-SUBRC.
    WHEN '0000'.
    WHEN '0001'.
      MESSAGE S311.
      LEAVE.
    WHEN '0002'.
      MESSAGE S311.
      LEAVE.
  ENDCASE.
ENDFORM.

FORM READPOS.
  LOOP AT ICDHDR.
    CHECK ICDHDR-UDATE
                        IN XUDATE.
    CHECK ICDHDR-USERNAME
                          IN XNAME.
    CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS'
         EXPORTING
              CHANGENUMBER      = ICDHDR-CHANGENR
              TABLEKEY          = CDPOS-TABKEY
              TABLENAME         = CDPOS-TABNAME
         IMPORTING
              HEADER            = CDHDR
         TABLES
              EDITPOS           = ICDSHW
         EXCEPTIONS
              NO_POSITION_FOUND = 1
              OTHERS            = 2.
    CASE SY-SUBRC.
      WHEN '0000'.
        LOOP AT ICDSHW.
          CHECK ICDSHW-CHNGIND NE 'E'.
          CLEAR ITAB.
          MOVE-CORRESPONDING ICDHDR TO ITAB.
          MOVE-CORRESPONDING ICDSHW TO ITAB.
          CASE ITAB-TABNAME.
            WHEN 'KONVC'.
              MOVE ICDHDR-OBJECTID TO ITAB-VBELN.
              MOVE ICDSHW-TABKEY(6) TO ITAB-POSNR.
            WHEN OTHERS.
              MOVE ICDSHW-TABKEY+3(10)  TO ITAB-VBELN.
              MOVE ICDSHW-TABKEY+13(6)  TO ITAB-POSNR.
              MOVE ICDSHW-TABKEY+19(4)  TO ITAB-ETENR.
          ENDCASE.
          MOVE '& %' TO ITAB-INDTEXT.
          APPEND ITAB.
          CLEAR ITAB.
        ENDLOOP.
      WHEN OTHERS.
        MESSAGE S311.
        LEAVE.
    ENDCASE.
  ENDLOOP.
ENDFORM.


TOP-OF-PAGE.
WRITE:/ SY-DATUM,SY-UZEIT,
       50 'SALES ORDER CHANGE HISTORY',
      120 'Page', SY-PAGNO.
WRITE: / SY-REPID,
         60 'SALES ORDERS STATISTICS'.
SKIP.
ULINE.
IF SUDATE = 'X'.
  WRITE:/001 'Change Date',
         013 'Time',
         023 'User Name',
         037 'Sale Order',
         049 'Line',
         057 'Sch No',
         065 'Changes'.
ELSEIF SOBID = 'X'.
  WRITE:/001 'Sale Order',
         013 'Line',
         021 'Sch No',
         029 'Change Date',
         041 'Time',
         051 'User Name',
         065 'Comment'.
ELSE.
  WRITE:/001 'User Name',
         015 'Time',
         025 'Change Date',
         037 'Sale Order',
         049 'Line',
         057 'Sch No',
         065 'Changes'.
ENDIF.
ULINE.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SD All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.