Equipment anlegen

www.4AP.de - alles über ABAP  -  Syntaxbeispiel Equipment anlegen

Beispielcoding: Equipment mit BAPI_EQUI_CREATE anlegen (kopieren erlaubt aber auf eigene Gefahr :-))

 


Equipments anlegen:
*
* Coded by Thorsten Neubüser - www.4ap.de
*
* für den BAPI_EQUI_CREATE
data:
* Export
EXTERNAL_NUMBER LIKE BAPI_ITOB_PARMS-EQUIPMENT,
DATA_GENERAL LIKE BAPI_ITOB,
DATA_SPECIFIC LIKE BAPI_ITOB_EQ_ONLY,
VALID_DATE LIKE BAPI_ITOB_PARMS-INST_DATE,
DATA_INSTALL LIKE BAPI_ITOB_EQ_INSTALL,
* Import
EQUIPMENT LIKE BAPI_ITOB_PARMS-EQUIPMENT,
DATA_GENERAL_EXP LIKE BAPI_ITOB,
DATA_SPECIFIC_EXP LIKE BAPI_ITOB_EQ_ONLY,
RETURN LIKE BAPIRET2.

* für BAPI_OBJCL_CHANGE
data:
* export
OBJECTKEY LIKE BAPI1003_KEY-OBJECT, " Objektschlüssel,
* konkateniert
OBJECTTABLE LIKE BAPI1003_KEY-OBJECTTABLE, " Objekttabelle
CLASSNUM LIKE BAPI1003_KEY-CLASSNUM, " Klassennummer
CLASSTYPE LIKE BAPI1003_KEY-CLASSTYPE, " Klassenart
STATUS LIKE BAPI1003_KEY-STATUS, " '1' Status der
* Klassifizierung
STANDARDCLASS LIKE BAPI1003_KEY-STDCLASS, " Kennzeichen:
* Standardklasse
CHANGENUMBER LIKE BAPI1003_KEY-CHANGENUMBER, " Änderungsnummer
KEYDATE LIKE BAPI1003_KEY-KEYDATE, " SY-DATUM Stichtag
NO_DEFAULT_VALUES LIKE BAPI1003_KEY-FLAG, " SPACE Vorschlagswerte
* import
CLASSIF_STATUS LIKE BAPI1003_KEY-STATUS, " Status der
* Klassifizierung
* tables
* neue Bewertungen NUM,DATE,TIME
NUMNEW LIKE BAPI1003_ALLOC_VALUES_NUM
occurs 0 with header line,
* neue Bewertungen CHAR,BOOL
CHARNEW LIKE BAPI1003_ALLOC_VALUES_CHAR
occurs 0 with header line,
* neue Bewertungen CURR
CURRNEW LIKE BAPI1003_ALLOC_VALUES_CURR
occurs 0 with header line,
* Fehlermeldungen
RETURN_BAPI_OBJCL_CHANGE LIKE BAPIRET2 occurs 0 with header line.


* <SNIP>


PERFORM prepare_data_bapi_equi.
PERFORM bapi_equi_create.
PERFORM prepare_data_classification.
PERFORM bapi_objcl_change. " Klassifikation


* <SNIP>


*&---------------------------------------------------------------------*
*& Form prepare_data_bapi_equi
*&---------------------------------------------------------------------*
FORM prepare_data_bapi_equi.
* wir sind im loop at split_tab.

** Export
*~~~~~~~~~~~~~~~~~~~~~
* EXTERNAL_NUMBER LIKE BAPI_ITOB_PARMS-EQUIPMENT,
* EQUIPMENT EQUNR CHAR 18 0 Equipmentnummer
*Die Equipmentnummer setzt sich zusammen aus der Sachnummer und der
*Stücknummer. Die Stücknummer ist mit führenden Nullen auf 4 Stellen
*aufzufüllen. Damit ergeben sich für die Equipmentnummer 14 Stellen
*(ohne Punkte)
CLEAR: external_number.
UNPACK split_tab-stknr TO split_tab-stknr.
CONCATENATE split_tab-artnr split_tab-stknr INTO external_number.
* die Equipment-# muss 18-stellig sein wegen Textpflege
UNPACK external_number TO external_number.

*~~~~~~~~~~~~~~~~~~~~~
* DATA_GENERAL LIKE BAPI_ITOB,
* Berechtigungsgruppe zum Technischen Objekt IAUTG CHAR4
* data_general-AUTHGRP =
* Art des technischen Objekts EQART CHAR10
* data_general-OBJECTTYPE =
* Inventarnummer INVNR CHAR25
* data_general-INVENTORY =
* Größe/Abmessung GROSS CHAR18
* data_general-OBJ_SIZE =
* Gewicht des Objekts OBJ_WEIGHT QUAN13
* data_general-OBJ_WEIGHT =
* Gewichtseinheit WEIGHT_UNIT UNIT3
* data_general-UNIT_OF_WT =
* ISO-Code Maßeinheit ISOCD_UNIT CHAR3
* data_general-UNIT_ISO =
* Anschaffungsdatum ANDTI DATS8
* data_general-ACQDATE =
* Anschaffungswert ANSWT CURR13
* data_general-ACQUISVAL =
* Währungsschlüssel WAERS CUKY5
* data_general-CURRENCY =
* Iso-Code Währung ISOCD CHAR3
* data_general-CURR_ISO =
* Hersteller der Anlage HERST CHAR30
data_general-manfacture = split_tab-herst.
* Herstellerland HERLD CHAR3
* data_general-MANCOUNTRY =
* ISO-Code des Landes INTCA CHAR2
* data_general-COUNTR_ISO =
* Serialnummer gemäß Hersteller SERGE CHAR30
* data_general-MANSERNO =
* Typenbezeichnung des Herstellers TYPBZ CHAR20
* data_general-MANMODEL =
* Baujahr BAUJJ CHAR4
* data_general-CONSTYEAR =
* Baumonat BAUMM CHAR2
* data_general-CONSTMONTH =
* Datum der Inbetriebnahme des Technischen Objekts ILOM_DATAB DATS8
data_general-start_from = sy-datum.
* Instandhaltungsplanungswerk IWERK CHAR4
data_general-planplant = '06'.
* Bautypmaterial des technischen Objekts SUBMT CHAR18
* data_general-CONSTTYPE =
* Herstellerteilnummer MAPAR CHAR30
* data_general-MANPARNO =
* Planergruppe für Kundenservice und Instandhaltung INGRP CHAR3
* data_general-PLANGROUP =
* Berichtsschema RBNR CHAR9
* data_general-CATPROFILE =
* Objekt-ID des Arbeitsplatzes LGWID NUMC8
select * from crhd
where objty eq 'A'
and arbpl eq 'QLEHR'.
data_general-WORK_CTR = crhd-objid.
exit.
endselect.
* Bezeichnung technisches Objekt KTX01 CHAR40
data_general-descript = split_tab-ktx01.
* ABC-Kennzeichen zum technischen Objekt ABCKZ CHAR1
* data_general-ABCINDIC =
* Sortierfeld EQFNR CHAR30
* data_general-SORTFIELD =

* Standortwerk SWERK CHAR4
data_general-maintplant = '0001'.
* Standort der Anlage STORT CHAR10
data_general-maintloc = 'BESTAND'.

* Raum RAUMNR CHAR8
* data_general-MAINTROOM =
* Betriebsbereich BEBER CHAR3
* data_general-PLSECTN =
* Objekt-ID des PPS-Arbeitsplatzes PPSID NUMC8
* data_general-PP_WKCTR =
* Geschäftsbereich GSBER CHAR4
* data_general-BUS_AREA =

* Kostenstelle KOSTL CHAR10
data_general-COSTCENTER = '972'.
UNPACK data_general-costcenter TO data_general-costcenter.


* Projektstrukturplanelement (PSP-Element) PS_PSP_PNR NUMC8
* data_general-WBS_ELEM =
* Buchungskreis BUKRS CHAR4
data_general-comp_code = 'Firma'.
* Anlagen-Hauptnummer ANLN1 CHAR12
* data_general-ASSET_NO =
* Anlagenunternummer ANLN2 CHAR4
* data_general-SUB_NUMBER =
* Dauerauftragsnummer DAUFN CHAR12
* data_general-STANDORDER =
* Abrechnungsauftrag ILOM_ORDST CHAR12
* data_general-SETTLORDER =
* Verkaufsorganisation VKORG CHAR4
* data_general-SALES_ORG =
* Vertriebsweg VTWEG CHAR2
* data_general-DISTR_CHAN =
* Sparte SPART CHAR2
* data_general-DIVISION =
* Verkaufsbüro VKBUR CHAR4
* data_general-SALES_OFF =
* Verkäufergruppe VKGRP CHAR3
* data_general-SALES_GRP =
* Datum, an dem der Satz hinzugefügt wurde ERDAT DATS8
data_general-read_crdat = sy-datum.
* Name des Sachbearbeiters, der d Objekt hinzugefügt hat ERNAM CHAR12
data_general-read_crnam = sy-uname.
* Datum der letzten Änderung AEDAT DATS8
* data_general-READ_CHDAT =
* Name des Sachbearbeiters, der das Objekt geändert hat. AENAM CHAR12
* data_general-READ_CHNAM =
* Adreßnummer AD_ADDRNUM CHAR10
* data_general-READ_ADRNR =


*~~~~~~~~~~~~~~~~~~~~~
* DATA_SPECIFIC LIKE BAPI_ITOB_EQ_ONLY,
* Konfigurierbares Material KMATN CHAR18
* data_specific-CONFIGMAT =
* Materialnummer MATNR CHAR18
* data_specific-MATERIAL =
* Serialnummer GERNR CHAR18
* data_specific-SERIALNO =
* Equipmenttyp EQTYP CHAR1
data_specific-equicatgry = 'E'.
* Chargennummer CHARG_D CHAR10
* data_specific-BATCH =
* Zeichnungsnummer laut Hersteller HZEIN CHAR30
* data_specific-MANDRAWNO =
* Erstes Auslieferungsdatum des Equipments AULDT DATS8
* data_specific-DELIVDATE =
* Datum, für SAP-interne Nutzung vorgesehen EQDAT DATS8
* data_specific-FREE_DATE1 =
* Technische Informationen, für SAP-interne Nutzung vorges EQBER CHAR30
* data_specific-FREE_NOTE1 =
* Numerisches Feld, für SAP-interne Nutzung vorgesehen EQNUM NUMC9
* data_specific-FREE_NUM1 =
* Technische Identnummer TIDNR CHAR25
* data_specific-TECHID =
* Lizenznummer des Equipments LIZNR CHAR20
* data_specific-LICENSE =
* Datum, für SAP-interne Nutzung vorgesehen EQDAT DATS8
* data_specific-FREE_DATE2 =
* Technische Informationen, für SAP-interne Nutzung vorges EQBER CHAR30
* data_specific-FREE_NOTE2 =
* Numerisches Feld, für SAP-interne Nutzung vorgesehen EQNUM NUMC9
* data_specific-FREE_NUM2 =
* Konfiguration (interne Objektnummer) CUOBJ NUMC18
* data_specific-READ_CUOBJ =
* Referenzierte Konfiguration KRFKZ CHAR1
* data_specific-READ_CUREF =
* Übergeordnetes Equipment HEQUI CHAR18
* data_specific-READ_SUPEQ =
* Kennzeichnung des Technischen Platzes ILOM_STRNO CHAR40
* data_specific-READ_FLOC =


*~~~~~~~~~~~~~~~~~~~~~
* VALID_DATE LIKE BAPI_ITOB_PARMS-INST_DATE,
* Gültig-Ab-Datum für anzulegendes Equipment


*~~~~~~~~~~~~~~~~~~~~~
* DATA_INSTALL LIKE BAPI_ITOB_EQ_INSTALL,
* Kennzeichnung des Technischen Platzes ILOM_STRNO CHAR40
* data_install-FUNCLOC =
* Übergeordnetes Equipment HEQUI CHAR18
* data_install-SUPEQUI =
* Equipmentposition am Einbauort (überg.Eqmt/Techn.Platz) INSTALLPOS C4
* data_install-INST_POS =

ENDFORM. " prepare_data_bapi_equi


*&---------------------------------------------------------------------*
*& Form bapi_equi_create
*----------------------------------------------------------------------*
FORM bapi_equi_create.
* wir sind im loop at split_tab.

CALL FUNCTION 'BAPI_EQUI_CREATE'
EXPORTING
external_number = external_number
data_general = data_general
data_specific = data_specific
valid_date = valid_date
data_install = data_install
IMPORTING
equipment = equipment
data_general_exp = data_general_exp
data_specific_exp = data_specific_exp
return = return
. " PUNKT!!!!
* Fehlerauswertung
IF NOT return-type IS INITIAL. " an error occurs
IF return-type = 'A'.
return-type = 'E'. " no abortion!!!
WRITE: / external_number,
split_tab-lgort,
'ID', return-id(2),
'TYPE', return-type,
'NUMBER', return-number,
return-message,
return-message_v1,
return-message_v2,
return-message_v3.
MESSAGE
ID return-id(2)
TYPE return-type
NUMBER return-number
WITH return-message
return-message_v1
return-message_v2
return-message_v3.

* ELSEIF return-type = 'S'.
** nothing to do
* perform bapi_commit using 'BAPI_EQUI_CREATE'.
ELSE. " return-type = 'A'
WRITE: / external_number,
split_tab-lgort,
'ID', return-id(2),
'TYPE', return-type,
'NUMBER', return-number,
return-message,
return-message_v1,
return-message_v2,
return-message_v3.

* MESSAGE
* ID return-id(2)
* TYPE return-type
* NUMBER return-number
* WITH return-message
* return-message_v1
* return-message_v2
* return-message_v3.
ENDIF. " return-type = 'A'
ELSE. " NOT return-type IS INITIAL
* Alles ging gut!
** Import
* EQUIPMENT LIKE BAPI_ITOB_PARMS-EQUIPMENT,
* DATA_GENERAL_EXP LIKE BAPI_ITOB,
* DATA_SPECIFIC_EXP LIKE BAPI_ITOB_EQ_ONLY,
* RETURN LIKE BAPIRET2,
IF NOT split_tab-bemer IS INITIAL.
PERFORM equi_langtext.
ENDIF. " split_tab-bemer is initial
IF NOT ( split_tab-prfer IS INITIAL
AND split_tab-prfbm IS INITIAL
AND split_tab-prfdt IS INITIAL
AND split_tab-prfnm IS INITIAL ).
PERFORM equi_vermerk.
ENDIF. " ( 4 Felder initial)
PERFORM bapi_commit USING 'BAPI_EQUI_CREATE'.
ENDIF. " NOT return-type IS INITIAL
ENDFORM. " bapi_equi_create


*&---------------------------------------------------------------------*
*& Form bapi_commit
*&---------------------------------------------------------------------*
FORM bapi_commit USING aufrufer.
DATA:
bapi_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = bapi_return.
* save_subrc = sy-subrc.
IF NOT bapi_return[] IS INITIAL.
LOOP AT bapi_return.
WRITE: / bapi_return-message.
ENDLOOP.
ELSE. " not bapi_return[] is initial
** Import
* EQUIPMENT LIKE BAPI_ITOB_PARMS-EQUIPMENT,
* DATA_GENERAL_EXP LIKE BAPI_ITOB,
* DATA_SPECIFIC_EXP LIKE BAPI_ITOB_EQ_ONLY,
* RETURN LIKE BAPIRET2,
CASE aufrufer.
WHEN 'BAPI_EQUI_CREATE'.
WRITE: /
'Equipment erfolgreich angelegt:'(011), equipment.
WHEN 'CLAF_CLASSIFICATION_OF_OBJECTS'.
WRITE: /
'Klassifikation erfolgreich angelegt:'(012), equipment.
ENDCASE.
ENDIF. " not bapi_return[] is initial
ENDFORM. " bapi_commit


*&---------------------------------------------------------------------*
*& Form equi_langtext
*&---------------------------------------------------------------------*
FORM equi_langtext.
* wir sind im loop at split_tab.
* split_tab-bemer (70)
CLEAR: text_header, text_lines.
REFRESH: text_lines.
text_header-tdname = external_number. " Equipment
text_header-tdid = 'LTXT'.
text_header-tdspras = sy-langu.
text_header-tdobject = 'EQUI'.
text_header-tdfuser = sy-uname.
text_header-tdfdate = sy-datum.
text_header-tdftime = sy-uzeit.

text_lines-tdformat = '*'. " Default-Absatz
text_lines-tdline = split_tab-bemer.
APPEND text_lines.

CALL FUNCTION 'SAVE_TEXT'
EXPORTING
client = sy-mandt
header = text_header
insert = ' '
savemode_direct = ' '
owner_specified = ' '
local_cat = ' '
* IMPORTING
* FUNCTION =
* NEWHEADER =
TABLES
lines = text_lines
EXCEPTIONS
id = 1
language = 2
name = 3
object = 4
OTHERS = 5
. " PUNKT!!
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE. " sy-subrc <> 0
PERFORM commit_text.
ENDIF. " sy-subrc <> 0
ENDFORM. " equi_langtext


*&---------------------------------------------------------------------*
*& Form equi_vermerk
*&---------------------------------------------------------------------*
FORM equi_vermerk.
* wir sind im loop at split_tab.
*1. Zeile = split_tab-PRFER (12)
*2. Zeile = split_tab-PRFBM (40)
*3. Zeile = split_tab-PRFDT (8)
*4. Zeile = split_tab-PRFNM (12)

CLEAR: text_header, text_lines.
REFRESH: text_lines.
text_header-tdname = external_number. " Equipment
text_header-tdid = 'INTV'.
text_header-tdspras = sy-langu.
text_header-tdobject = 'EQUI'.
text_header-tdfuser = sy-uname.
text_header-tdfdate = sy-datum.
text_header-tdftime = sy-uzeit.

text_lines-tdformat = '*'. " Default-Absatz
text_lines-tdline = split_tab-prfer.
APPEND text_lines.
text_lines-tdline = split_tab-prfbm.
APPEND text_lines.
text_lines-tdline = split_tab-prfdt.
APPEND text_lines.
text_lines-tdline = split_tab-prfnm.
APPEND text_lines.

CALL FUNCTION 'SAVE_TEXT'
EXPORTING
client = sy-mandt
header = text_header
insert = ' '
savemode_direct = ' '
owner_specified = ' '
local_cat = ' '
* IMPORTING
* FUNCTION =
* NEWHEADER =
TABLES
lines = text_lines
EXCEPTIONS
id = 1
language = 2
name = 3
object = 4
OTHERS = 5
. " PUNKT!!
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE. " sy-subrc <> 0
PERFORM commit_text.
ENDIF. " sy-subrc <> 0
ENDFORM. " equi_vermerk


*&---------------------------------------------------------------------*
*& Form COMMIT_TEXT
*&---------------------------------------------------------------------*
FORM commit_text.
CALL FUNCTION 'COMMIT_TEXT'
EXPORTING
object = 'EQUI'
name = '*'
id = '*'
language = '*'
* SAVEMODE_DIRECT = ' '
* KEEP = ' '
* LOCAL_CAT = ' '
* IMPORTING
* COMMIT_COUNT =
* TABLES
* T_OBJECT =
* T_NAME =
* T_ID =
* T_LANGUAGE =
. " PUNKT!!
ENDFORM. " COMMIT_TEXT



*&---------------------------------------------------------------------*
*& Form prepare_data_CLASSIFICATION
*&---------------------------------------------------------------------*
FORM prepare_data_classification.
* wir sind im loop at split_tab.

* Export
*OBJECTKEY LIKE BAPI1003_KEY-OBJECT Objektschlüssel,
*konkateniert
*OBJECTTABLE LIKE BAPI1003_KEY-OBJECTTABLE Objekttabelle
*CLASSNUM LIKE BAPI1003_KEY-CLASSNUM Klassennummer
*CLASSTYPE LIKE BAPI1003_KEY-CLASSTYPE Klassenart
*STATUS LIKE BAPI1003_KEY-STATUS '1' Status der
* Klassifizierung
*STANDARDCLASS LIKE BAPI1003_KEY-STDCLASS
* Kennzeichen: Standardklasse
*CHANGENUMBER LIKE BAPI1003_KEY-CHANGENUMBER Änderungsnummer
*KEYDATE LIKE BAPI1003_KEY-KEYDATE SY-DATUM Stichtag
*NO_DEFAULT_VALUES LIKE BAPI1003_KEY-FLAG SPACE Vorschlagswerte

objectkey = external_number.
objecttable = 'EQUI'. " Name der Datenbanktabelle d. Objektes
classtype = '002'. " Fix
classnum = 'ZQM_MESSMITTEL'.
status = ''.
standardclass = ''.
keydate = sy-datum.

* Import
* CLASSIF_STATUS LIKE BAPI1003_KEY-STATUS Status der
* Klassifizierung


* Tabellen
*neue Bewertungen NUM,DATE,TIME
*ALLOCVALUESNUMNEW LIKE BAPI1003_ALLOC_VALUES_NUM
**
*CHARACT ATNAM CHAR 30 0 Merkmalname
*VALUE_FROM ATFLV FLTP 16 16 interner Fließkomma-Wert von
*VALUE_TO ATFLB FLTP 16 16 interner Fließkomma-Wert bis
*VALUE_RELATION ATCOD CHAR 1 0 Code für Wertebeziehung
*UNIT_FROM MEINS UNIT 3 0 Basismengeneinheit
*UNIT_TO MEINS UNIT 3 0 Basismengeneinheit
*UNIT_FROM_ISO MEINS_ISO CHAR 3 0
* Basismengeneinheit im ISO-Code
*UNIT_TO_ISO MEINS_ISO CHAR 3 0 Basismengeneinheit im
*ISO-Code
*INHERITED FLINH CHAR 1 0 Kennzeichen: Merkmal ererbt
*INSTANCE ATZIS NUMC 3 0 Instanzenzähler
*CHARACT_DESCR ATBEZ CHAR 30 0 Merkmalbezeichnung


* neue Bewertungen CHAR,BOOL
*ALLOCVALUESCHARNEW LIKE BAPI1003_ALLOC_VALUES_CHAR
**
*CHARACT ATNAM CHAR 30 0 Merkmalname
*VALUE_CHAR ATWRT CHAR 30 0 Merkmalwert
*INHERITED FLINH CHAR 1 0 Kennzeichen: Merkmal ererbt
*INSTANCE ATZIS NUMC 3 0 Instanzenzähler
*VALUE_NEUTRAL ATWRT CHAR 30 0 Merkmalwert
*CHARACT_DESCR ATBEZ CHAR 30 0 Merkmalbezeichnung


* neue Bewertungen CURR
*ALLOCVALUESCURRNEW LIKE BAPI1003_ALLOC_VALUES_CURR
**
*CHARACT ATNAM CHAR 30 0 Merkmalname
*VALUE_FROM ATFLV FLTP 16 16 interner Fließkomma-Wert von
*VALUE_TO ATFLB FLTP 16 16 interner Fließkomma-Wert bis
*VALUE_RELATION ATCOD CHAR 1 0 Code für Wertebeziehung
*CURRENCY_FROM WAERS CUKY 5 0 Währungsschlüssel
*CURRENCY_TO WAERS CUKY 5 0 Währungsschlüssel
*CURRENCY_FROM_ISO ISOCD CHAR 3 0 Iso-Code Währung
*CURRENCY_TO_ISO ISOCD CHAR 3 0 Iso-Code Währung
*INHERITED FLINH CHAR 1 0 Kennzeichen: Merkmal ererbt
*INSTANCE ATZIS NUMC 3 0 Instanzenzähler
*CHARACT_DESCR ATBEZ CHAR 30 0 Merkmalbezeichnung

CLEAR: charnew. REFRESH: charnew.
charnew-charact = 'ZQM_PERSONALNUMMER'. " Merkmalname
charnew-value_char = split_tab-prsnr. " Merkmalwert
APPEND charnew.
charnew-charact = 'ZQM_MASCHINENNUMMER'. " Merkmalname
charnew-value_char = split_tab-masnr. " Merkmalwert
APPEND charnew.
ENDFORM. " prepare_data_CLASSIFICATION