Skip to end of metadata
Go to start of metadata

Author: Bjoern Panter
Submitted: 26. Nov 2008
Related Links: Blog

 

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------\*
*& Report  ZCREATE_ART_MASS
*&
*&---------------------------------------------------------------------\*
*& Report  CREATE_ART_MASS                                         *
*&---------------------------------------------------------------------\*
*& Mit diesem Report ist es möglich einen existierenden Artikel als
*& Vorlage zu nehmen und auf Basis dieses Artikels neue Artikel
*& anzulegen. Für die neuen Artikel kann für den Postfix, der an die
*& Artikelnummer des Vorlageartikels drangehängt wird, eine Startzahl
*& vorgegeben werden und zusätzlich wird die Anzahl der anzulegenden
*& Artikelkopien benötigt.
*&---------------------------------------------------------------------\*


REPORT  ZCREATE_ART_MASS.

* Artikel, der als Vorlage dienen soll (MATNR sollte alphanum. sein
* und nicht länger als 10 Zeichen, damit noch Platz ist für den
* Postfix und für die laufende Nummer bei Varianten).
parameters: p_vorart(10).
* Startwert für den Postfix (laufende Nummer, die an die MATNR des
* Vorlageartikels angehängt wird)
parameters: p_art_nr   type i default 1.
* Alternativ: anstatt Postfix einen Präfix erzeugen
parameters: p_post RADIOBUTTON GROUP gr1,
            p_prae RADIOBUTTON GROUP gr1.
* Anzahl der Artikelkopien (nicht mehr als 99999, da Postfix nur
* 5-stellig)
parameters: p_anzart  type i default 10.
TABLES: BAPIE1MLTXRT,
        BAPIE1VARKEY,
        BAPIE1WRKKEY,
        BAPIE1MATHEAD,
        T001W,
        EDIDC,
        MARA,
        T100.
data: count type i.
data: char_count(5).
data: matnr_len type i.
data: vorl_matnr like mara-matnr.
data: new_matnr  like mara-matnr value '__________'.
data: hindex     like sy-index.
DATA: BEGIN OF HMARCKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMARCKEY.
DATA: END OF HMARCKEY.
check p_vorart cn '0123456789 '.   "keine rein numerischen Art.nr.
select single * from mara where matnr = p_vorart.
check sy-subrc = 0.
check p_anzart < 100000.    "höchstens 99999 Artikel
* Falls die MATNR des Vorlageartikels kürzer als 10 Stellen ist, wird
* mit '_' aufgefüllt.
matnr_len            = strlen( p_vorart ).
if not p_post is initial.
  new_matnr(matnr_len) = p_vorart.
elseif not p_prae is initial.
  shift new_matnr by 5 places right.
  new_matnr+5(matnr_len) = p_vorart.
endif.
vorl_matnr           = p_vorart.
count = p_art_nr.
do p_anzart times.
  hindex = sy-index.
  if count > 99999. exit. endif.
  move count to char_count.
  SHIFT char_count RIGHT DELETING TRAILING ' '.
  TRANSLATE char_count USING ' 0'.
  if not p_post is initial.
    new_matnr+10(5) = char_count.
  elseif not p_prae is initial.
    new_matnr(5) = char_count.
  endif.
  perform call_report_rbdartst using vorl_matnr new_matnr.
  write: / hindex, new_matnr.
  count = count + 1.
enddo.
*&---------------------------------------------------------------------*
*&      Form  call_report_rbdartst
*&---------------------------------------------------------------------*
*       Coding aus dem Report RBDARTST kopiert.
*       Damit das IDoc für die Kopiervorlage aus Performancegründen
*       nur einmal aufgebaut wird, konnte der Report RBDARTST nicht
*       mit SUBMIT aufgerufen werden.
*----------------------------------------------------------------------*
FORM call_report_rbdartst using P_MATNR  like mara-matnr  "Vorl.art.nr.
                                P_MATNRN like mara-matnr. "neue Art.nr.
STATICS: NOT_FIRST_CALL LIKE SY-DATAR.
INCLUDE MMMGXV37.
DATA: P_MESTY LIKE EDIDC-MESTYP VALUE 'ARTMAS'.
DATA: P_NUMALL(10).                     "nicht genutzt!
DATA: P_NUMACT(10).                     "nicht genutzt!
DATA: P_BEFORE(5).                      "nicht genutzt!
DATA: P_KEYLI LIKE SY-DATAR VALUE 'X'.  "Keylisten verwenden (Perf.)
DATA: P_NEWWRK TYPE I.                  "nicht genutzt!
RANGES: S_WERKS FOR T001W-WERKS.        "nicht genutzt!
DATA: P_NOLOG LIKE SY-DATAR VALUE 'X'.  "kein Anwendungslog
*ATA: P_NOBEL LIKE SY-DATAR VALUE 'X'.  "keine Änderungsbelege
DATA: P_NOBEL LIKE SY-DATAR VALUE ' '.  "Änderungsbelege wg. Änd.zeigern
DATA: P_SHLOG LIKE SY-DATAR.            "keinen Anwendungslog anzeigen
DATA: P_DETAIL LIKE SY-DATAR.           "nicht genutzt!
DATA: CR_IDOC LIKE SY-DATAR.            "nicht genutzt!
DATA: P_RUNTI LIKE SY-DATAR.            "nicht genutzt!
DATA: HMATNR LIKE MARA-MATNR.
DATA: BEGIN OF SEGMENTDATA,
      FUNCTION LIKE BAPIE1MARART-FUNCTION,
      MATERIAL LIKE BAPIE1MARART-MATERIAL,
      TAIL(979).                       " = 1000 - 3 - 18
DATA: END OF SEGMENTDATA.
* Data for the call of the function
DATA: BEGIN OF T_IDOC_DATA OCCURS 0.
        INCLUDE STRUCTURE EDIDD.
DATA: END OF T_IDOC_DATA.
DATA: H_IDOC_DATA like EDIDD.
DATA: TT001W      like t001w occurs 0 with header line.
DATA: BEGIN OF F_IDOC_HEADER.
        INCLUDE STRUCTURE EDIDC.
DATA: END OF F_IDOC_HEADER.
DATA: BEGIN OF T_EDIDC OCCURS 0.
        INCLUDE STRUCTURE EDIDC.
DATA: END OF T_EDIDC.
DATA: BEGIN OF T_SELECTED_EDIDC OCCURS 0.
        INCLUDE STRUCTURE EDIDC.
DATA: END OF T_SELECTED_EDIDC.
DATA: BEGIN OF T_STATUS OCCURS 0.
        INCLUDE STRUCTURE BDIDOCSTAT.
DATA: END OF T_STATUS.
DATA: BEGIN OF T_RETVARS OCCURS 0.
        INCLUDE STRUCTURE BDWFRETVAR.
DATA: END OF T_RETVARS.
DATA: BEGIN OF T_SER OCCURS 0.
        INCLUDE STRUCTURE BDI_SER.
DATA: END OF T_SER.
* Data for finding the keys of the material
DATA: BEGIN OF T_MARAKEY OCCURS 0.
        INCLUDE STRUCTURE BDIMARAKEY.
DATA: END OF T_MARAKEY.
DATA: IHEAD_MATNR LIKE PRE03-MATNR.
DATA: TVAR_TAB LIKE PRE03 OCCURS 0 WITH HEADER LINE.
DATA: TMARAKEY LIKE BDIMARAKEY OCCURS 0 WITH HEADER LINE.
DATA: TAUSPKEY LIKE BDIAUSPKEY OCCURS 0 WITH HEADER LINE.
DATA: TMAW1KEY LIKE BDIMAW1KEY OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF TMAKTKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMAKTKEY.
DATA: END OF TMAKTKEY.
DATA: BEGIN OF TMARCKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMARCKEY.
DATA: END OF TMARCKEY.
DATA: HREFPLANTS LIKE MREFPLANT OCCURS 20 WITH HEADER LINE.
DATA: BEGIN OF TMARDKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMARDKEY.
DATA: END OF TMARDKEY.
DATA: BEGIN OF TMFHMKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMFHMKEY.
DATA: END OF TMFHMKEY.
DATA: BEGIN OF TMPGDKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMPGDKEY.
DATA: END OF TMPGDKEY.
DATA: BEGIN OF TMPOPKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMPOPKEY.
DATA: END OF TMPOPKEY.
DATA: BEGIN OF TMPRWKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMPRWKEY.
DATA: END OF TMPRWKEY.
DATA: BEGIN OF TMVEGKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMVEGKEY.
DATA: END OF TMVEGKEY.
DATA: BEGIN OF TMVEUKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMVEUKEY.
DATA: END OF TMVEUKEY.
DATA: BEGIN OF TMKALKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMKALKEY.
DATA: END OF TMKALKEY.
DATA: BEGIN OF TMARMKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMARMKEY.
DATA: END OF TMARMKEY.
DATA: TMAMTKEY LIKE BDIMAMTKEY OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF TMEANKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMEANKEY.
DATA: END OF TMEANKEY.
DATA: TMLEAKEY LIKE BDIMLEAKEY OCCURS 0 WITH HEADER LINE.
DATA: TMALGKEY LIKE BDIMALGKEY OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF TMVKEKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMVKEKEY.
DATA: END OF TMVKEKEY.
DATA: TWLK2KEY LIKE BDIWLK2KEY OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF TMLANKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMLANKEY.
DATA: END OF TMLANKEY.
DATA: BEGIN OF TMBEWKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMBEWKEY.
DATA: END OF TMBEWKEY.
DATA: BEGIN OF TMLGNKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMLGNKEY.
DATA: END OF TMLGNKEY.
DATA: BEGIN OF TMLGTKEY OCCURS 10.
        INCLUDE STRUCTURE BDIMLGTKEY.
DATA: END OF TMLGTKEY.
DATA: BEGIN OF TSTXHKEY OCCURS 10.
        INCLUDE STRUCTURE BDISTXHKEY.
DATA: END OF TSTXHKEY.
* Help-Data
DATA: STRING(400).
DATA: OUT_STRING(200).
* Interface data
DATA: IF_STATUS(200).
* Unterstützung Massenaufruf -> nur beim ersten Aufruf die Daten lesen
* -> danach das IDoc aus dem Memory verwenden
if not_first_call is initial.
  not_first_call = 'X'.
* Matnr auf Existenz prüfen
CALL FUNCTION 'MARA_SINGLE_READ'
     EXPORTING
*         KZRFB             = ' '
*         MAXTZ             = 0
          MATNR             = P_MATNR
*         SPERRMODUS        = ' '
*         STD_SPERRMODUS    = ' '
*    IMPORTING
*         WMARA             =
     EXCEPTIONS
          LOCK_ON_MATERIAL  = 1
          LOCK_SYSTEM_ERROR = 2
          WRONG_CALL        = 3
          NOT_FOUND         = 4
          OTHERS            = 5.
IF SY-SUBRC = 4.
  SY-MSGTY = 'I'.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  EXIT.
ENDIF.
* Select all the keys for the material to create idoc
REFRESH T_MARAKEY.
CLEAR T_MARAKEY.
T_MARAKEY-MANDT = SY-MANDT.
T_MARAKEY-MATNR = P_MATNR.
APPEND T_MARAKEY.
CALL FUNCTION 'MASTERIDOC_CREATE_REQ_ARTMAS'
     EXPORTING
          RCVPFC                      = ''
          RCVPRN                      = ''
          RCVPRT                      = ''
          SNDPFC                      = ''
          SNDPRN                      = ''
          SNDPRT                      = ''
          MESSAGE_TYPE                = P_MESTY
          FLAG_TESTMODE               = 'X'
*         SUPPRESS_PROGRESS_INDICATOR = ' '
*         SUPPRESS_BUFFER_REFRESH     = ' '
*         OUTPUT_TOTAL_INIT           = 0
*         OUTPUT_COUNTER_INIT         = 0
*    IMPORTING
*         CREATED_COMM_IDOCS          =
*         CREATED_MASTER_IDOCS        =
     TABLES
          MARAKEY                     = T_MARAKEY
     EXCEPTIONS
          OTHERS                      = 1.
IF SY-SUBRC <> 0.
  CHECK 0 = 1.
ENDIF.
* .....Import Key data from memory
IMPORT
  IHEAD_MATNR                          "  RT
  TVAR_TAB                             "  RT
  TMARAKEY                             "  RT
  TAUSPKEY                             "  RT
  TMAW1KEY                             "  RT
  TMAKTKEY
  TMARCKEY
  TMARDKEY
  TMARMKEY
  TMAMTKEY                             "  RT
  TMEANKEY
  TMLEAKEY                             "  RT
  TMALGKEY                             "  RT
  TMVKEKEY
  TWLK2KEY                             "  RT
  TMLANKEY
  TMBEWKEY
  TMLGNKEY
  TMLGTKEY
  TSTXHKEY
  TMFHMKEY
  TMPGDKEY
  TMPOPKEY
  TMPRWKEY
  TMVEGKEY
  TMVEUKEY
  TMKALKEY
FROM MEMORY
ID 'MGVDATA'.
* Create IDOC data
IF NOT P_KEYLI IS INITIAL.
* Vorlagebetriebe ermitteln
  CALL FUNCTION 'READ_REFERENCE_PLANTS'
*      EXPORTING
*           KZRFB     = ' '
       TABLES
            REFPLANT  = HREFPLANTS
       EXCEPTIONS
            NOT_FOUND = 1
            OTHERS    = 2
            .
  SORT HREFPLANTS BY WERKS.
* Keys zu Vorlagebetrieb und Nichtvorlagebetrieb extrahieren:
* - In den T....KEY-Tabellen nur die Vorlagebetriebe belassen
* - Die Nichtvorlagebetriebe auf Basis der MARC-Keys sammeln
  LOOP AT TMARCKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMARCKEY-WERKS
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMARCKEY.
      APPEND TMARCKEY TO HMARCKEY.
    ENDIF.
  ENDLOOP.
  LOOP AT TMBEWKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMBEWKEY-BWKEY
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMBEWKEY.
    ENDIF.
  ENDLOOP.
  LOOP AT TMARDKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMARDKEY-WERKS
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMARDKEY.
    ENDIF.
  ENDLOOP.
  LOOP AT TMPOPKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMPOPKEY-WERKS
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMPOPKEY.
    ENDIF.
  ENDLOOP.
  LOOP AT TMFHMKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMFHMKEY-WERKS
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMFHMKEY.
    ENDIF.
  ENDLOOP.
  LOOP AT TMPGDKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMPGDKEY-WERKS
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMPGDKEY.
    ENDIF.
  ENDLOOP.
  LOOP AT TMPRWKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMPRWKEY-WERKS
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMPRWKEY.
    ENDIF.
  ENDLOOP.
  LOOP AT TMVEGKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMVEGKEY-WERKS
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMVEGKEY.
    ENDIF.
  ENDLOOP.
  LOOP AT TMVEUKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMVEUKEY-WERKS
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMVEUKEY.
    ENDIF.
  ENDLOOP.
  LOOP AT TMKALKEY.
    READ TABLE HREFPLANTS WITH KEY WERKS = TMKALKEY-WERKS
                          BINARY SEARCH.
    IF SY-SUBRC NE 0.
*     Kein Vorlagebetrieb
      DELETE TMKALKEY.
    ENDIF.
  ENDLOOP.
ENDIF.
CALL FUNCTION 'MASTERIDOC_CREATE_ARTMAS'
     EXPORTING
          HEAD_MATNR         = IHEAD_MATNR
          RCVPFC             = ''
          RCVPRN             = ''
          RCVPRT             = ''
          SNDPFC             = ''
          SNDPRN             = ''
          SNDPRT             = ''
          MESSAGE_TYPE       = P_MESTY
          FLAG_TESTMODE      = 'X'
*    IMPORTING
*         CREATED_COMM_IDOCS =
     TABLES
          VAR_TAB            = TVAR_TAB
          MARAKEY            = TMARAKEY
          AUSPKEY            = TAUSPKEY
          MAW1KEY            = TMAW1KEY
          MAKTKEY            = TMAKTKEY
          MARCKEY            = TMARCKEY
          MARDKEY            = TMARDKEY
          MARMKEY            = TMARMKEY
          MAMTKEY            = TMAMTKEY
          MEANKEY            = TMEANKEY
          MLEAKEY            = TMLEAKEY
          MALGKEY            = TMALGKEY
          MVKEKEY            = TMVKEKEY
          WLK2KEY            = TWLK2KEY
          MLANKEY            = TMLANKEY
          MBEWKEY            = TMBEWKEY
          MLGNKEY            = TMLGNKEY
          MLGTKEY            = TMLGTKEY
          STXHKEY            = TSTXHKEY
          MFHMKEY            = TMFHMKEY
          MPGDKEY            = TMPGDKEY
          MPOPKEY            = TMPOPKEY
          MPRWKEY            = TMPRWKEY
          MVEGKEY            = TMVEGKEY
          MVEUKEY            = TMVEUKEY
          MKALKEY            = TMKALKEY
     EXCEPTIONS
          OTHERS             = 1.
IF SY-SUBRC <> 0.
  CHECK 0 = 1.
ENDIF.
endif.     "not_first_call is initial
* .....Import IDOC data from memory
IMPORT
  F_IDOC_HEADER
  T_IDOC_DATA
FROM MEMORY
ID 'MGVIDOC'.

* Nun auch komplette Artikelnummer als Eingabe unterstützen -> Probleme
* gab es bisher bei Variantenartikelnummern, denn diese dürfen nicht
* 1:1 ersetzt werden wegen Suffix.
DATA: FLEN TYPE I.
FLEN = STRLEN( P_MATNR ).
* Change material number in all IDOC segments adding the new prefix
LOOP AT T_IDOC_DATA.
* Sonderlogik Langtexte, da keine Komponente 'MATERIAL'
* Vgl. FB: BAPI_MATERIAL_MAINTAINDATA_RT und Form FORM MLTX_UEBERGEBEN.
  IF T_IDOC_DATA-SEGNAM = 'E1BPE1MLTXRT'.
    BAPIE1MLTXRT = T_IDOC_DATA-SDATA.
    IF P_MATNRN IS INITIAL.
      STRING = '&&'.
      REPLACE '&' WITH P_BEFORE INTO STRING.
      CLEAR HMATNR.
      HMATNR = BAPIE1MLTXRT-TEXT_NAME. " schneidet korrekt ab ...
      REPLACE '&' WITH HMATNR INTO STRING.
    ELSE.
* JH/28.07.99/4.6C (Anfang)
*     STRING = P_MATNRN.
      STRING = BAPIE1MLTXRT-TEXT_NAME.
      REPLACE P_MATNR WITH P_MATNRN INTO STRING LENGTH FLEN.
* JH/28.07.99/4.6C (Ende)
    ENDIF.
    CONDENSE STRING NO-GAPS.
* cfo/4.6B-A
* AHE: 28.07.99 - A (4.6c)
* Modifikation getuned
    DATA: HNUM TYPE I.
    HNUM = STRLEN( STRING ).
    WHILE HNUM GT 18.
      REPLACE '0' WITH SPACE INTO STRING.
      HNUM = HNUM - 1.
    ENDWHILE.
    CONDENSE STRING NO-GAPS.
*   DATA: HNUM TYPE I.
*   HNUM = STRLEN( STRING ).
*   WHILE HNUM GT 18.
*     REPLACE '0' WITH SPACE INTO STRING.
*     CONDENSE STRING NO-GAPS.
*     HNUM = STRLEN( STRING ).
*   ENDWHILE.
* AHE: 28.07.99 - E
* cfo/4.6B-E
    CLEAR BAPIE1MLTXRT-TEXT_NAME.
    BAPIE1MLTXRT-TEXT_NAME = STRING(18).
    T_IDOC_DATA-SDATA = BAPIE1MLTXRT.
* Sonderlogik VARKEY's -> auch Variantennummern müssen ersetzt werden
  ELSEIF T_IDOC_DATA-SEGNAM = 'E1BPE1VARKEY'.
    BAPIE1VARKEY = T_IDOC_DATA-SDATA.
*   Sammelartikelnummer ersetzen
    IF P_MATNRN IS INITIAL.
      STRING = '&&'.
      REPLACE '&' WITH P_BEFORE INTO STRING.
      CLEAR HMATNR.
      HMATNR = BAPIE1VARKEY-MATERIAL.
      REPLACE '&' WITH HMATNR INTO STRING.
    ELSE.
* JH/28.07.99/4.6C (Anfang)
*     STRING = P_MATNRN.
      STRING = BAPIE1VARKEY-MATERIAL.
      REPLACE P_MATNR WITH P_MATNRN INTO STRING LENGTH FLEN.
* JH/28.07.99/4.6C (Ende)
    ENDIF.
    CONDENSE STRING NO-GAPS.
* cfo/4.6B-A
* AHE: 28.07.99 - A (4.6c)
* Modifikation getuned
    HNUM = STRLEN( STRING ).
    WHILE HNUM GT 18.
      REPLACE '0' WITH SPACE INTO STRING.
      HNUM = HNUM - 1.
    ENDWHILE.
    CONDENSE STRING NO-GAPS.
*   HNUM = STRLEN( STRING ).
*   WHILE HNUM GT 18.
*     REPLACE '0' WITH SPACE INTO STRING.
*     CONDENSE STRING NO-GAPS.
*     HNUM = STRLEN( STRING ).
*   ENDWHILE.
* AHE: 28.07.99 - E
* cfo/4.6B-E
    CLEAR BAPIE1VARKEY-MATERIAL.
    BAPIE1VARKEY-MATERIAL = STRING.
*   Variantennummer ersetzen
    IF P_MATNRN IS INITIAL.
      STRING = '&&'.
      REPLACE '&' WITH P_BEFORE INTO STRING.
      CLEAR HMATNR.
      HMATNR = BAPIE1VARKEY-VARIANT.
      REPLACE '&' WITH HMATNR INTO STRING.
    ELSE.
* JH/28.07.99/4.6C (Anfang)
*     STRING = P_MATNRN.
      STRING = BAPIE1VARKEY-VARIANT.
      REPLACE P_MATNR WITH P_MATNRN INTO STRING LENGTH FLEN.
* JH/28.07.99/4.6C (Ende)
    ENDIF.
    CONDENSE STRING NO-GAPS.
* cfo/4.6B-A
* AHE: 28.07.99 - A (4.6c)
* Modifikation getuned
    HNUM = STRLEN( STRING ).
    WHILE HNUM GT 18.
      REPLACE '0' WITH SPACE INTO STRING.
      HNUM = HNUM - 1.
    ENDWHILE.
    CONDENSE STRING NO-GAPS.
*   HNUM = STRLEN( STRING ).
*   WHILE HNUM GT 18.
*     REPLACE '0' WITH SPACE INTO STRING.
*     CONDENSE STRING NO-GAPS.
*     HNUM = STRLEN( STRING ).
*   ENDWHILE.
* AHE: 28.07.99 - E
* cfo/4.6B-E
    CLEAR BAPIE1VARKEY-VARIANT.
    BAPIE1VARKEY-VARIANT = STRING.
    T_IDOC_DATA-SDATA = BAPIE1VARKEY.
* JH/25.09.97 (Ende)
  ELSE.
*   Normalfall für alle anderen Segmente
    IF T_IDOC_DATA-SEGNAM = 'E1BPE1MATHEAD'.
      BAPIE1MATHEAD = T_IDOC_DATA-SDATA.
      BAPIE1MATHEAD-NO_APPL_LOG   = P_NOLOG.
      BAPIE1MATHEAD-NO_CHANGE_DOC = P_NOBEL.
      T_IDOC_DATA-SDATA = BAPIE1MATHEAD.
    ENDIF.
    CLEAR SEGMENTDATA.
    SEGMENTDATA = T_IDOC_DATA-SDATA.
    IF P_MATNRN IS INITIAL.
      STRING = '&&'.
      REPLACE '&' WITH P_BEFORE INTO STRING.
      REPLACE '&' WITH SEGMENTDATA-MATERIAL INTO STRING.
    ELSE.
*  (Anfang)
*     STRING = P_MATNRN.
      STRING = SEGMENTDATA-MATERIAL.
      REPLACE P_MATNR WITH P_MATNRN INTO STRING LENGTH FLEN.
*  (Ende)
    ENDIF.
    CONDENSE STRING NO-GAPS.
* cfo/4.6B-A
* AHE: 28.07.99 - A (4.6c)
* Modifikation getuned
    HNUM = STRLEN( STRING ).
    WHILE HNUM GT 18.
      REPLACE '0' WITH SPACE INTO STRING.
      HNUM = HNUM - 1.
    ENDWHILE.
    CONDENSE STRING NO-GAPS.
*   HNUM = STRLEN( STRING ).
*   WHILE HNUM GT 18.
*     REPLACE '0' WITH SPACE INTO STRING.
*     CONDENSE STRING NO-GAPS.
*     HNUM = STRLEN( STRING ).
*   ENDWHILE.
* AHE: 28.07.99 - E
* cfo/4.6B-E
    SEGMENTDATA-MATERIAL = STRING.
    T_IDOC_DATA-SDATA = SEGMENTDATA.
  ENDIF.
  MODIFY T_IDOC_DATA.
ENDLOOP.
*JH/02.03.99/4.6A (Anfang)
IF NOT P_KEYLI IS INITIAL.
* Keyliste aufbauen
  CLEAR BAPIE1WRKKEY.
  LOOP AT HMARCKEY.
    IF P_MATNRN IS INITIAL.
      STRING = '&&'.
      REPLACE '&' WITH P_BEFORE INTO STRING.
      REPLACE '&' WITH HMARCKEY-MATNR INTO STRING.
    ELSE.
* JH/22.03.00/5.0A (Anfang)
*     STRING = P_MATNRN.
      STRING = HMARCKEY-MATNR.
      REPLACE P_MATNR WITH P_MATNRN INTO STRING LENGTH FLEN.
* JH/22.03.00/5.0A (Ende)
    ENDIF.
    CONDENSE STRING NO-GAPS.
* JH/22.03.00/5.0A (Anfang)
    HNUM = STRLEN( STRING ).
    WHILE HNUM GT 18.
      REPLACE '0' WITH SPACE INTO STRING.
      HNUM = HNUM - 1.
    ENDWHILE.
    CONDENSE STRING NO-GAPS.
* JH/22.03.00/5.0A (Ende)
    BAPIE1WRKKEY-MATERIAL = STRING.
    BAPIE1WRKKEY-PLANT    = HMARCKEY-WERKS.
    CLEAR T_IDOC_DATA.
    T_IDOC_DATA-SEGNAM = 'E1BPE1WRKKEY'.
    T_IDOC_DATA-SDATA  = BAPIE1WRKKEY.
    APPEND T_IDOC_DATA.
  ENDLOOP.
ENDIF.
*JH/02.03.99/4.6A (Ende)
* (Anfang)
if p_newwrk > 0.
  select * from t001w into table tt001w up to p_newwrk rows
                      where werks in s_werks
                        and vlfkz <> ' '.
  CLEAR BAPIE1WRKKEY.
  loop at t_idoc_data into h_idoc_data where segnam = 'E1BPE1MARART'.
    SEGMENTDATA = H_IDOC_DATA-SDATA.
    loop at tt001w.
      BAPIE1WRKKEY-MATERIAL = SEGMENTDATA-MATERIAL.
      BAPIE1WRKKEY-PLANT    = tt001w-WERKS.
      CLEAR T_IDOC_DATA.
      T_IDOC_DATA-SEGNAM = 'E1BPE1WRKKEY'.
      T_IDOC_DATA-SDATA  = BAPIE1WRKKEY.
      APPEND T_IDOC_DATA.
    endloop.
  endloop.
endif.
*  (Ende)
* Call inbound module
OUT_STRING = '(& von &) Materialstamm wird eingebucht'(001).
REPLACE '&' WITH P_NUMACT INTO OUT_STRING.
REPLACE '&' WITH P_NUMALL INTO OUT_STRING.
CONDENSE OUT_STRING.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
     EXPORTING
          TEXT   = OUT_STRING
     EXCEPTIONS
          OTHERS = 1.
REFRESH T_EDIDC.
T_EDIDC = F_IDOC_HEADER.
APPEND T_EDIDC.
REFRESH T_STATUS.
*JH/02.03.99/4.6A Laufzeit messen (Anfang)
IF NOT P_RUNTI IS INITIAL.
  DATA RUN_TIME TYPE I.
  GET RUN TIME FIELD RUN_TIME.  "Laufzeit initialisieren -> RUN_TIME = 0
ENDIF.
*JH/02.03.99/4.6A Laufzeit messen (Ende)
IF CR_IDOC IS INITIAL.    "
* Einbuchen
CALL FUNCTION 'IDOC_INPUT_ARTMAS'
     EXPORTING
          INPUT_METHOD          = ' '
          MASS_PROCESSING       = ' '
*    IMPORTING
*         WORKFLOW_RESULT       =
*         APPLICATION_VARIABL   =
*         IN_UPDATE_TASK        =
*         CALL_TRANSACTION_DONE =
     TABLES
          IDOC_CONTRL           = T_EDIDC
          IDOC_DATA             = T_IDOC_DATA
          IDOC_STATUS           = T_STATUS
          RETURN_VARIABLES      = T_RETVARS
          SERIALIZATION_INFO    = T_SER
     EXCEPTIONS
          WRONG_FUNCTION_CALLED = 1
          OTHERS                = 2.
COMMIT WORK.
*  Laufzeit messen (Anfang)
IF NOT P_RUNTI IS INITIAL.
  GET RUN TIME FIELD RUN_TIME.   "seit dem Initialisierungszeitpunkt
                                       "verstrichene Zeit ermitteln
  WRITE / 'Laufzeit f. das reine Einbuchen der Daten:'.  "#EC NOTEXT
  WRITE: RUN_TIME USING EDIT MASK 'RR___.___,___' NO-GAP, ' ms '.
ENDIF.
*  Laufzeit messen (Ende)
* zur Zeit nicht ....
*CALL FUNCTION 'APPL_LOG_DISPLAY_INTERN'
*     EXPORTING
*          OBJECT                         = OBJECT_MATU
**         SUBOBJECT                      = ' '
**         TITLE_LIST_SCREEN              = ' '
**         COLUMN_SELECTION               = '11112221122   '
**         COLUMN_SELECTION_MSG_JUMP      = '1'
*          EXTERNAL_NUMBER_DISPLAY_LENGTH = 20
**    IMPORTING
**         NUMBER_OF_PROTOCOLS            =
**    EXCEPTIONS
**         object_not_found               = 1
**         subobject_not_found            = 2
**         others                         = 3
*     .
*  /4.0A
* Applikation Log anzeigen über direkten Report-Aufruf (TA MM90)
READ TABLE T_STATUS INDEX 1.
IF NOT T_STATUS-MSGV2 IS INITIAL.
  IF NOT P_SHLOG IS INITIAL.      "JH/22.03.00/5.0A
    SUBMIT RMVAPLSH WITH EXTNO = T_STATUS-MSGV2
                    AND RETURN.
  ENDIF.                          "JH/22.03.00/5.0A
ENDIF.
* Output data
*READ TABLE T_STATUS INDEX 1.
IF_STATUS = T_STATUS-STATUS.
IF_STATUS+2 = '|'.
IF_STATUS+3 = T_STATUS-MSGID.
IF_STATUS+8 = '|'.
IF_STATUS+9 = T_STATUS-MSGNO.
IF_STATUS+14 = '|'.
IF_STATUS+15 = STRING.
IF_STATUS+33 = '|'.
IF T_STATUS-STATUS <> '53'.
  IF_STATUS+34 = '&'.
  SELECT SINGLE * FROM T100 WHERE SPRSL = SY-LANGU
                              AND ARBGB = T_STATUS-MSGID
                              AND MSGNR = T_STATUS-MSGNO.
  REPLACE '&' WITH T100-TEXT INTO IF_STATUS.
  REPLACE '&' WITH T_STATUS-MSGV1 INTO IF_STATUS. CONDENSE IF_STATUS+34.
  REPLACE '&' WITH T_STATUS-MSGV2 INTO IF_STATUS. CONDENSE IF_STATUS+34.
  REPLACE '&' WITH T_STATUS-MSGV3 INTO IF_STATUS. CONDENSE IF_STATUS+34.
  REPLACE '&' WITH T_STATUS-MSGV4 INTO IF_STATUS. CONDENSE IF_STATUS+34.
ENDIF.
EXPORT IF_STATUS TO MEMORY
       ID 'MGVSTAT'.
CHECK P_DETAIL = 'X'.
IF T_STATUS-STATUS <> '53'.
  FORMAT COLOR 6.
ENDIF.
WRITE: /(100) IF_STATUS.
FORMAT RESET.
ULINE.
LOOP AT T_IDOC_DATA.
  WRITE: / T_IDOC_DATA-SEGNAM,
           '|',
          T_IDOC_DATA-SDATA(180).
ENDLOOP.
*   (Anfang)
ELSE.
  DATA: RECEIVERS     LIKE BDI_LOGSYS OCCURS 0 WITH HEADER LINE.
  DATA: IDOC_CONTROL  LIKE BDIDOCCONTROL.
  DATA: NEW_IDOCS     LIKE BDIDOCS    OCCURS 0 WITH HEADER LINE.
  MOVE-CORRESPONDING F_IDOC_HEADER TO IDOC_CONTROL.
  RECEIVERS-LOGSYS = 'DUMMY'.    "Dummy-Empfänger
  APPEND RECEIVERS.
  CALL FUNCTION 'ALE_IDOCS_CREATE'
       EXPORTING
            IDOC_CONTROL                = IDOC_CONTROL
       TABLES
            IDOC_DATA                   = T_IDOC_DATA
            RECEIVERS                   = RECEIVERS
            CREATED_IDOCS               = NEW_IDOCS
       EXCEPTIONS
            IDOC_INPUT_WAS_INCONSISTENT = 1
            OTHERS                      = 2.
  IF SY-SUBRC <> 0.
    ROLLBACK WORK.
    EXIT.
  ELSE.
    COMMIT WORK.
  ENDIF.
  IF NOT P_RUNTI IS INITIAL.
    GET RUN TIME FIELD RUN_TIME.   "seit dem Initialisierungszeitpunkt
                                   "verstrichene Zeit ermitteln
    WRITE / 'Runtime for pure data inbound:'.  "#EC NOTEXT
    WRITE: RUN_TIME USING EDIT MASK 'RR___.___,___' NO-GAP, ' ms '.
  ENDIF.
* Erzeugtes IDOC anzeigen
  READ TABLE NEW_IDOCS INDEX 1.
  IF SY-SUBRC = 0.
    SUBMIT RSEIDOC2 WITH DOCNUM = NEW_IDOCS-DOCNUM AND RETURN.
  ENDIF.
ENDIF.
*   (Ende)
ENDFORM.                    " call_report_rbdartst
  • No labels