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

PP-PDC-выгрузка заказов



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



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Fri Apr 11, 2008 10:48 pm    Post subject: PP-PDC-выгрузка заказов Reply with quote

Code:
REPORT MJ_DOWN_OPERAS .
TYPES:
  EXIM_DATA_ITEM(1024)       TYPE C,
  EXIM_GENERAL_PROJECT(40)   TYPE C,
  EXIM_GENERAL_FOLDER(128)   TYPE C,
  EXIM_GENERAL_EXTENSION(4)  TYPE C,
  EXIM_GENERAL_FILENAME(128) TYPE C,
  EXIM_GENERAL_TODO(1)       TYPE C,


  BEGIN OF EXIM_PROJECT_ITEM,
     PROJECT        TYPE EXIM_GENERAL_PROJECT,
     OBJECTTYPE(4)  TYPE C,
     OBJECTNAME(40) TYPE C,
     KEYWORD(10)    TYPE C,
  END OF EXIM_PROJECT_ITEM,

  BEGIN OF EXIM_TABLE_FIELDNAME,
     TEXT(60) TYPE C,
  END OF EXIM_TABLE_FIELDNAME.

DATA:
* file i/o
  EXIM_DATA_ITEM        TYPE EXIM_DATA_ITEM,
  EXIM_DATA_TABLE       TYPE EXIM_DATA_ITEM OCCURS 0,
  EXIM_TABLE_FIELDNAME  TYPE EXIM_TABLE_FIELDNAME,
  EXIM_TABLE_FIELDNAMES TYPE EXIM_TABLE_FIELDNAME OCCURS 0,

* transparent tables
  EXIM_PROJECT_FILENAME TYPE EXIM_GENERAL_FILENAME,
  EXIM_PROJECT_ITEM     TYPE EXIM_PROJECT_ITEM,
  EXIM_PROJECT_TABLE    TYPE EXIM_PROJECT_ITEM OCCURS 0,
* general prefereneces
  EXIM_GENERAL_PROJECT   TYPE EXIM_GENERAL_PROJECT,
  EXIM_GENERAL_FILENAME  TYPE EXIM_GENERAL_FILENAME,
  EXIM_GENERAL_FOLDER    TYPE EXIM_GENERAL_FOLDER,
  EXIM_GENERAL_EXTENSION TYPE EXIM_GENERAL_EXTENSION,
  EXIM_GENERAL_TODO      TYPE EXIM_GENERAL_TODO,
  EXIM_GENERAL_PLANT     LIKE MAST-WERKS,
  EXIM_GENERAL_DATE      LIKE SY-DATUM,
  EXIM_GENERAL_VKORG     LIKE MVKE-VKORG,
  EXIM_GENERAL_VTWEG     LIKE MVKE-VTWEG,
  EXIM_GENERAL_LANGU     LIKE LTX1-TDSPRAS.

data: lt_ap_ord_pre LIKE ap_ord_pre OCCURS 0 WITH HEADER LINE,
      lt_aufpl      like arbpl_afvc occurs 0 with header line,
      lt_ordcom     like ordcom     occurs 0 with header line,
      lt_t399x      like t399x      occurs 0 with header line,
      lt_work       like dwn14      occurs 0 with header line.
data: begin of lt_objid occurs 0,
        objid like crhd-objid,
      end   of lt_objid.
data: l_autyp       like caufvd-autyp,
      l_delete      like rc27x-flg_sel,
      l_enq_key     like RSTABLE-VARKEY,
      l_tcode       like sy-tcode,
      l_text(62)    type c,
      l_tstamp      TYPE timestamp.
data  lt_ORDER_RNG like BAPI_PP_ORDERRANGE occurs 0 with header line.

  parameters p_file(128) obligatory.
  select-options p_werk for lt_t399x-werks NO INTERVALS no-extension.
* aktuellen Zeitstempel bereitstellen (fќr Delete ORDCOM)
  get time.                       "Synchronisation ABAP-/ DB-Zeit
  GET TIME STAMP FIELD l_tstamp.  "aktueller Timestamp (Kurzversion)
  l_autyp = '10'.
* nur Auftragsarten fќr relevanten Typ und 'PDC_ACTIVE'='X'
  SELECT * FROM T399X INTO TABLE lt_T399X
                      WHERE AUTYP      = l_AUTYP
                      AND   PDC_ACTIVE = 'X'.
  check not lt_T399X[] IS INITIAL.
  SORT lt_T399X BY WERKS AUART.
* Selektion der subsystemrelavanten Arbeitsplфtze, ohne Details und
* ohne Berќcksichtigung der BDE-Gruppen
  CALL FUNCTION 'SEL_WORK_CENTER_FOR_DOWNLOAD'
       TABLES
            IDWN14 = lt_work
       EXCEPTIONS
            others = 1.
  check sy-subrc = 0.
  check not lt_work[] is initial.
  free: lt_objid.
* Vorgфnge bereitstellen
  SELECT * FROM ARBPL_AFVC INTO TABLE lt_AUFPL
                           FOR ALL ENTRIES IN lt_work
                           WHERE ARBID = lt_WORK-OBJID.
  free lt_work.
  check not lt_AUFPL[] IS INITIAL.
  sort lt_aufpl by aufpl aplzl.
* Parallelisiertes Bereitstellen der geфnderten Vorgangsdaten
  clear l_delete.
  PERFORM select_data TABLES lt_AUFPL
                             lt_ORDER_RNG
                      using  l_autyp
                             l_delete.



FORM select_data TABLES IT_AUFPL STRUCTURE ARBPL_AFVC
                        IT_ORDER_RNG STRUCTURE BAPI_PP_ORDERRANGE
                 USING  I_AUTYP  LIKE CAUFVD-AUTYP
                        I_DELETE LIKE RC27X-FLG_SEL.

DATA: LT_AP_ORD_PRE LIKE AP_ORD_PRE OCCURS 0 WITH HEADER LINE,
      LT_AUFNR      LIKE ORD_PRE    OCCURS 0 WITH HEADER LINE,
      LT_AUFPL_TTL  LIKE ARBPL_AFVC OCCURS 0 WITH HEADER LINE,
      LT_AUFPL_TASK LIKE ARBPL_AFVC OCCURS 0 WITH HEADER LINE.
DATA: L_CNT_AUFNR   LIKE SY-TABIX,
      L_OBJNR       LIKE CAUFVD-OBJNR,
      L_OPEN_EVENTS LIKE RC27X-FLG_SEL.
DATA: LT_OPERAS         LIKE BAPI_PP_PDC_OPERA2
                             OCCURS 0 WITH HEADER LINE,
      LT_OPENEVENTS     LIKE BAPI_PP_PDC_OPENEVENT
                             OCCURS 0 WITH HEADER LINE,
      LT_ORDCOM_NOT_DEL LIKE ARBPL_AFVC
                             OCCURS 0 WITH HEADER LINE.

* Bei Grundversorgung sind die offenen Zeitereignisse bereitzustellen
  IF I_DELETE IS INITIAL.
    L_OPEN_EVENTS = 'X'.
  ELSE.
    CLEAR L_OPEN_EVENTS.
  ENDIF.
* Auftrфge bereitstellen
  SELECT * FROM AP_ORD_PRE INTO TABLE LT_AP_ORD_PRE
                           FOR ALL ENTRIES IN IT_AUFPL
                           WHERE AUFPL = IT_AUFPL-AUFPL.
  CHECK NOT LT_AP_ORD_PRE[] IS INITIAL.

* Sortieren der Tabellen
  SORT IT_AUFPL  BY AUFPL APLZL.
  SORT LT_AP_ORD_PRE BY AUFPL.
  CLEAR   LT_AP_ORD_PRE.
  CLEAR   LT_AUFPL_TASK.
  REFRESH LT_AUFPL_TASK.
*
  LOOP AT IT_AUFPL.
    IF IT_AUFPL-AUFPL <> LT_AP_ORD_PRE-AUFPL.
      READ TABLE LT_AP_ORD_PRE WITH KEY AUFPL = IT_AUFPL-AUFPL
                                        BINARY SEARCH.
*     Bei der Deltaversorgung mќsste bei SUBRC <> 0 ein DELETE-Satz
*     geschrieben werden                                           "QTB
      CHECK SY-SUBRC = 0.
      SELECT SINGLE OBJNR FROM AUFK
                          INTO L_OBJNR
                          WHERE AUFNR = LT_AP_ORD_PRE-AUFNR
                          AND   AUTYP = I_AUTYP.
      IF SY-SUBRC <> 0.
*       Auftrag nicht vorhanden bzw. ungќltiger Auftragstyp
*       Alle Eintrфge zu diesem Auftrag entfernen
        DELETE IT_AUFPL WHERE AUFPL = LT_AP_ORD_PRE-AUFPL.
        CONTINUE.
      ENDIF.
*     Prќfen, ob Auftrag den Downloadanforderungen laut Statusver-
*     waltung genќgt: Betriebswirtschaftlicher Vorgang = "PDCH"
      CALL FUNCTION 'STATUS_CHANGE_FOR_ACTIVITY'
           EXPORTING
                CHECK_ONLY = 'X'
                OBJNR      = L_OBJNR
                VRGNG      = 'PDCH'
           EXCEPTIONS
                OTHERS     = 1.
      IF SY-SUBRC <> 0.
*       Auftrag darf laut Statusverwaltung nicht berќcksichtigt werden
*       Alle Eintrфge zu diesem Auftrag entfernen
        DELETE IT_AUFPL WHERE AUFPL = LT_AP_ORD_PRE-AUFPL.
        CONTINUE.
      ENDIF.
*     Auftrфge, fќr die zum Auftragskopf Rќckmeldungen erfasst wurden,
*     sind nicht zu berќcksichtigen
      CALL FUNCTION 'STATUS_CHECK'
           EXPORTING
                OBJNR  = L_OBJNR
                STATUS = 'I0236'
           EXCEPTIONS
                OTHERS = 1.
      IF SY-SUBRC = 0.
*       Fќr Auftrag wurde bereits zum Kopf rќckgemeldet
*       Alle Eintrфge zu diesem Auftrag entfernen
        DELETE IT_AUFPL WHERE AUFPL = LT_AP_ORD_PRE-AUFPL.
        CONTINUE.
      ENDIF.
      LT_AUFNR-AUFNR = LT_AP_ORD_PRE-AUFNR.
      APPEND LT_AUFNR.
    ENDIF.
    APPEND IT_AUFPL TO LT_AUFPL_TASK.
  ENDLOOP.
  CALL FUNCTION 'PP_C0_OPERAS_SEL_FOR_PDC_DOWN'
       EXPORTING
          I_CHANNEL         = '2'
          I_OPEN_EVENTS     = L_OPEN_EVENTS
       TABLES
          IT_ORDER          = LT_AUFNR
          IT_OPRKEY         = LT_AUFPL_TASK
          ET_OPERAS         = LT_OPERAS
          ET_OPENEVENTS     = LT_OPENEVENTS
          ET_ORDCOM_NOT_DEL = LT_ORDCOM_NOT_DEL.
*  Daten ggf. reduzieren
if not p_werk[] is initial.
  delete lt_operas where plant ne p_werk-low.
endif.

*  Daten auf Festplatte sichern
PERFORM FILE_DOWNLOAD_TABLE TABLES LT_OPERAS USING 'BAPI_PP_PDC_OPERA2'.


ENDFORM.

FORM FILE_DOWNLOAD_TABLE
     TABLES TABLE
     USING  TABLE_NAME.

  DATA: FILEPATH(128) TYPE C,
        FIELDNAMES TYPE EXIM_TABLE_FIELDNAME OCCURS 20 WITH HEADER LINE.

* read the structure of table
  PERFORM GET_STRUCTURE_INFO
          TABLES FIELDNAMES
          USING  TABLE_NAME.

* DON'T use quotes around filepath for the call - add them later
* Quotes work for NT but NOT FOR W95
* CONCATENATE EXIM_GENERAL_FOLDER
*             EXIM_GENERAL_PROJECT
*             '_'
*             TABLE_NAME
*             EXIM_GENERAL_EXTENSION
*        INTO FILEPATH.

  CALL FUNCTION 'WS_DOWNLOAD'
       EXPORTING
*           FILENAME            = FILEPATH
            FILENAME            = p_file
            FILETYPE            = 'DAT'
            MODE                = ' '  " Overwrite
       TABLES
            DATA_TAB            = TABLE
            FIELDNAMES          = FIELDNAMES
       EXCEPTIONS
            FILE_OPEN_ERROR     = 1
            FILE_WRITE_ERROR    = 2
            INVALID_FILESIZE    = 3
            INVALID_TABLE_WIDTH = 4
            INVALID_TYPE        = 5
            NO_BATCH            = 6
            UNKNOWN_ERROR       = 7
            OTHERS              = 8.

  IF SY-SUBRC <> 0.
    WRITE: / 'FILE_DOWNLOAD_TABLE: sy-subrc=', SY-SUBRC.

  ENDIF.

ENDFORM.                               " FILE_DOWNLOAD_TABLE


FORM GET_STRUCTURE_INFO
     TABLES DATATAB STRUCTURE EXIM_TABLE_FIELDNAME
     USING  TABNAME TYPE C.

  DATA:          NT LIKE X031L OCCURS 0 WITH HEADER LINE.
  FIELD-SYMBOLS: <F>.

  DATA:          L_TAB LIKE DD02L-TABNAME.

  L_TAB = TABNAME.
  CALL FUNCTION 'DD_GET_NAMETAB'
       EXPORTING
            TABNAME   = L_TAB
       TABLES
            X031L_TAB = NT
       EXCEPTIONS
            NOT_FOUND = 1
            NO_FIELDS = 2
            OTHERS    = 3.

  CLEAR   DATATAB.
  REFRESH DATATAB.

  LOOP AT NT.
    ASSIGN COMPONENT NT-FIELDNAME
        OF STRUCTURE DATATAB TO <F>.
*     WRITE: / NT-FIELDNAME, AT 22 <F>.

    DATATAB-TEXT = NT-FIELDNAME.
    APPEND DATATAB.

  ENDLOOP.

ENDFORM.
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 -> PP 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.