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

Equipment creation



 
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: 1640

PostPosted: Sun Oct 14, 2007 8:29 pm    Post subject: Equipment creation Reply with quote

Sending the total code of equipment creation through bapi. it includes class , charactries, and address details.

Code:

REPORT Z_IPSG_BAPI_IEO1 MESSAGE-ID Z3 LINE-SIZE 185 NO STANDARD PAGE
HEADING.

*"----------------------------------------------------------------------
* Program Name: Z_IPSG_BAPI_IEO1
* Ref:
* Author: saleem.shaik
* Date: 04/01/06
* Source Code Type: using bapi function modules
*-------------------------------------------------------------------
* PROGRAM DESCRIPTION:
*-------------------------------------------------------------------
*This Program is used to upload the Equipment details to SAP
*-------------------------------------------------------------------

INCLUDE ZIPSGIEBAPITOP.



SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME TITLE TEXT-018 .
PARAMETERS: FLATFILE LIKE RLGRAP-FILENAME DEFAULT 'C:\Equipment.txt'.
SELECTION-SCREEN END OF BLOCK BL1.

SELECTION-SCREEN BEGIN OF BLOCK BL2 WITH FRAME TITLE TEXT-027 .
PARAMETERS: P_EMAIL(50). "D0086
SELECTION-SCREEN END OF BLOCK BL2.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR FLATFILE.
PERFORM GET_FILENAME.

START-OF-SELECTION.
* To upload data from flat file into internal table:
IF SY-BATCH = 'X'.
PERFORM READ_FILE. " for background
ELSE.
PERFORM UPLOAD_FILE. " for foreground
DESCRIBE TABLE ITAB LINES SY-TFILL.
* Files with more than 10 records should not be processed online
IF SY-TFILL > 10.
MESSAGE E398(00) WITH TEXT-030.
ENDIF.
ENDIF.

CHECK NOT ITAB[] IS INITIAL.
PERFORM SET_CHANGE_FLAG.
SORT ITAB .
PERFORM CREATE_EQUIPMENT.
PERFORM CHANGE_EQUIPMENT.
PERFORM DISPLAYDATA.

TOP-OF-PAGE.
WRITE :/60 C_HEAD.

WRITE :/10 'DATE:', SY-DATUM, 120 'Program Name:', SY-CPROG.
WRITE :/10 'TIME:', SY-UZEIT, 120 'USER:', SY-UNAME.

ULINE: /1(185).
WRITE :/ SPACE COLOR 4.
WRITE : 1 SY-VLINE,
2 'Equipment',
13 SY-VLINE,
14 'Material Number' COLOR 4,
35 SY-VLINE,
36 'Serial Number' COLOR 4,
67 SY-VLINE,
68 'Functional Location' COLOR 4,
103 SY-VLINE,
104 'Success/Exception' COLOR 4,
145 SY-VLINE,
146 'Status',
185 SY-VLINE.
ULINE:/1(185).



**********************************************************************
* FORM UPLOAD_FILE *
**********************************************************************
FORM UPLOAD_FILE.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = FLATFILE
FILETYPE = 'DAT'
TABLES
DATA_TAB = ITAB
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5
NO_BATCH = 6
UNKNOWN_ERROR = 7
OTHERS = 8.

* write : 'WS_UPLOAD return code : ',sy-subrc.
IF SY-SUBRC <> 0.
CASE SY-SUBRC.
WHEN 1.
MESSAGE A099 WITH TEXT-010.
WHEN 2.
MESSAGE A099 WITH TEXT-011.
WHEN 3.
MESSAGE A099 WITH TEXT-012.
WHEN 4.
MESSAGE A099 WITH TEXT-013.
WHEN 5.
MESSAGE A099 WITH TEXT-014.
WHEN 6.
MESSAGE A099 WITH TEXT-015.
WHEN 7.
MESSAGE A099 WITH TEXT-016.
WHEN 8.
MESSAGE A099 WITH TEXT-017.
ENDCASE.
WRITE :/ 'ERROR' .
ENDIF.

ENDFORM. " UPLOAD_FILE
***********************************************************************

***********************************************************************
*---------------------------------------------------------------------*
FORM GET_FILENAME.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_FILENAME = SPACE
DEF_PATH = FLATFILE
MASK = ',*.*,*.*.'
MODE = 'O'
TITLE = 'Choose file'
IMPORTING
FILENAME = FLATFILE
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.

ENDFORM. "get_filename
*&---------------------------------------------------------------------*
*& Form set_change_flag
*&---------------------------------------------------------------------*
FORM SET_CHANGE_FLAG .
* Select all the equipment numbers for the material number serial number
* Combination
SELECT EQUNR MATNR SERGE TPLNR DATBI EQUNR
FROM V_EQUI
INTO TABLE GT_EQUI
FOR ALL ENTRIES IN ITAB
WHERE MATNR = ITAB-REFMA AND
SERGE = ITAB-SERGE AND
EQTYP = 'Z' AND
DATBI GT SY-DATUM.

SELECT OBJEK FROM KSSK
INTO TABLE GT_KSSK
FOR ALL ENTRIES IN GT_EQUI
WHERE OBJEK = GT_EQUI-OBJEK.

SORT GT_EQUI BY EQUNR DATBI.
LOOP AT ITAB.
READ TABLE GT_EQUI WITH KEY MATNR = ITAB-REFMA
SERGE = ITAB-SERGE.
IF SY-SUBRC = 0.
ITAB-CHGFLG = 'X'.
MODIFY ITAB.
ENDIF.
ENDLOOP.
ENDFORM. " set_change_flag
*&--------------------------------------------------------------------*
*& Form SENDING
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->ZMAIL text
*---------------------------------------------------------------------*
FORM SENDING USING ZMAIL .

CHECK NOT SY-BATCH IS INITIAL.
IF NOT ZMAIL IS INITIAL.
GT_RECLIST-LINE = ZMAIL.
ELSE.
GT_RECLIST-LINE = P_EMAIL.
ENDIF.
APPEND GT_RECLIST.
CLEAR GT_RECLIST.
DESCRIBE TABLE GT_OBJTXT LINES SY-TFILL.
CHECK SY-TFILL > 2.
CALL FUNCTION 'Z_SEND_EMAIL_FROM_APP_SERVER_1'
EXPORTING
I_SUBJECT = C_HEAD
I_SUPPRESS_COMM = 'X'
TABLES
RECIPIENTS = GT_RECLIST
BODY_TEXT = GT_OBJTXT
EXCEPTIONS
NO_RECIPIENTS = 1
NO_TEXT = 2
IO_ERROR = 3
SEND_ERROR = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
REFRESH GT_OBJTXT.
REFRESH GT_RECLIST.
ENDFORM. "sendmail

*&---------------------------------------------------------------------*
*& Form read_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM READ_FILE .

CLEAR LT_FILES.
REFRESH LT_FILES.
CONCATENATE 'ls -t' GV_SOURCE INTO LV_TCOM SEPARATED BY SPACE.
* Read the directory for files
CALL 'SYSTEM' ID 'COMMAND' FIELD LV_TCOM ID 'TAB'
FIELD LT_FILES-*SYS*.
DELETE LT_FILES WHERE FILE_NAME_PATH = 'archive'.

IF LT_FILES[] IS INITIAL.
EXIT.
ENDIF.
* read the files
LOOP AT LT_FILES.
CLEAR GV_FILEPATH.
CONCATENATE GV_SOURCE LT_FILES-FILE_NAME_PATH INTO GV_FILEPATH.
* Check if right files are there in right servers
CASE SY-SYSID.
WHEN 'P01' OR 'NT2'. " EMEA
IF LT_FILES-FILE_NAME_PATH+0(2) NE 'EM'.
CONCATENATE LT_FILES-FILE_NAME_PATH TEXT-024 SY-SYSID TEXT-029
INTO GT_OBJTXT SEPARATED BY SPACE
.
APPEND GT_OBJTXT.
CLEAR GT_OBJTXT.
CONTINUE.
ENDIF.
WHEN 'PN1' OR 'NT1'. " Americas.
IF LT_FILES-FILE_NAME_PATH+0(2) NE 'AM'.
CONCATENATE LT_FILES-FILE_NAME_PATH TEXT-024 SY-SYSID TEXT-029
INTO GT_OBJTXT SEPARATED BY SPACE
.
APPEND GT_OBJTXT.
CLEAR GT_OBJTXT.
CONTINUE.
ENDIF.
WHEN 'PJ1' OR 'NT3'. " Asia Pacific.
IF LT_FILES-FILE_NAME_PATH+0(2) NE 'AP'.
CONCATENATE LT_FILES-FILE_NAME_PATH TEXT-024 SY-SYSID TEXT-029
INTO GT_OBJTXT SEPARATED BY SPACE
.
APPEND GT_OBJTXT.
CLEAR GT_OBJTXT.
CONTINUE.
ENDIF.
ENDCASE.
* Move the file contents to internal table
OPEN DATASET GV_FILEPATH IN TEXT MODE FOR INPUT.
IF SY-SUBRC <> 0.
CONCATENATE TEXT-028 GV_FILEPATH INTO GT_OBJTXT
SEPARATED BY SPACE.
APPEND GT_OBJTXT.
CONTINUE.
ENDIF.
DO.
READ DATASET GV_FILEPATH INTO GV_STRING.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
SPLIT GV_STRING AT GV_TAB_LIMIT INTO
ITAB-REFMA
ITAB-IWERK
ITAB-BEGRU
ITAB-INVNR
ITAB-EQART
ITAB-HERST
ITAB-TYPBZ
ITAB-BAUJJ
ITAB-BAUMM
ITAB-MAPAR
ITAB-SUBMT
ITAB-TIDNR
ITAB-SERGE
ITAB-TPLNR
ITAB-KLART
ITAB-CLASS
ITAB-MNAME
ITAB-MWERT
ITAB-STATUS
ITAB-NAME1
ITAB-NAME2
ITAB-ZMAIL.
APPEND ITAB.
CLEAR ITAB.
ENDDO.
CONCATENATE 'mv' GV_FILEPATH GV_DEST INTO LV_TCOM SEPARATED BY
SPACE.
CALL 'SYSTEM' ID 'COMMAND' FIELD LV_TCOM.
ENDLOOP.
* Send mail to generic id if there are any errors.
IF NOT GT_OBJTXT[] IS INITIAL.
PERFORM SENDING USING P_EMAIL.
ENDIF.
ENDFORM. " read_file
*&---------------------------------------------------------------------*
*& Form create_equipment
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM CREATE_EQUIPMENT .


LOOP AT ITAB WHERE CHGFLG NE 'X'.
*****Create Equipment with Address Details

SELECT SINGLE PLTXT FROM IFLOTX INTO V_PLTXT WHERE TPLNR = ITAB-TPLNR.

SELECT SINGLE MAKTX FROM MAKT INTO V_EQKTX
WHERE MATNR = ITAB-REFMA.

V_TPLNR = ITAB-TPLNR.
WA_EQUIP-EQKTX = V_EQKTX.
WA_EQUIP-MATNR = ITAB-REFMA.
WA_EQUIP-IWERK = ITAB-IWERK.
WA_EQUIP-TIDNR = ITAB-TIDNR.
WA_EQUIP-SERGE = ITAB-SERGE.
WA_EQUIP-EQTYP = C_EQTYP.
APPEND WA_EQUIP TO IT_EQUIP.

IF ITAB-NAME1 IS NOT INITIAL OR ITAB-NAME2 IS NOT INITIAL.

* select single land1 from t001w into v_country
* where werks = itab-iwerk. "Get Country Key
*


IT_ADDR1-DATA-NAME1 = ITAB-NAME1.
IT_ADDR1-DATA-NAME2 = ITAB-NAME2.
IT_ADDR1-DATA-COUNTRY = V_COUNTRY.
APPEND IT_ADDR1.

WA_ADDR-ADDR1_DATA[] = IT_ADDR1[].
WA_ADDR-ADTEL_DATA[] = IT_ADTEL[].
APPEND WA_ADDR TO IT_ADDR.
ENDIF.

CALL FUNCTION 'Z_CREATE_EQUIP'
EXPORTING
I_FL = V_TPLNR
IT_EQUIP = IT_EQUIP
IT_ADDR = IT_ADDR
IMPORTING
ET_MESSAGES = IT_MESSAGES.

LOOP AT IT_MESSAGES INTO WA_MESSAGE.
V_EQUNR = WA_MESSAGE-NEW_EQUIP.
WA_MESSAGE1[] = WA_MESSAGE-MESSAGES[].
GT_EQUTAB-EQUNR = V_EQUNR.
GT_EQUTAB-ZMAIL = P_EMAIL.
GT_EQUTAB-REFMA = WA_MESSAGE-MATNR.
GT_EQUTAB-SERGE = WA_MESSAGE-SERIAL.
GT_EQUTAB-TPLNR = ITAB-TPLNR.
GT_EQUTAB-PLTXT = V_PLTXT.
GT_EQUTAB-MODE = V_CRE.
IF WA_MESSAGE1[] IS NOT INITIAL.
LOOP AT WA_MESSAGE1 INTO WA_MESSAGE2.
GT_EQUTAB-EXCEPT = WA_MESSAGE2-MESSAGE.
APPEND GT_EQUTAB.
CLEAR GT_EQUTAB.
ENDLOOP.
ELSE.
APPEND GT_EQUTAB.
CLEAR GT_EQUTAB.
ENDIF.


ENDLOOP.


IF V_EQUNR IS NOT INITIAL.
*********Ext The Equipment with Genral Details ***************


WA_DATA_GENERAL-AUTHGRP = ITAB-BEGRU.
WA_GENERAL_DATAX-AUTHGRP = TRUE.

WA_DATA_GENERAL-INVENTORY = ITAB-INVNR.
WA_GENERAL_DATAX-INVENTORY = TRUE.

WA_DATA_GENERAL-OBJECTTYPE = ITAB-EQART.
WA_GENERAL_DATAX-OBJECTTYPE = TRUE.

WA_DATA_GENERAL-MANFACTURE = ITAB-HERST.
WA_GENERAL_DATAX-MANFACTURE = TRUE.

WA_DATA_GENERAL-MANMODEL = ITAB-TYPBZ.
WA_GENERAL_DATAX-MANMODEL = TRUE.

WA_DATA_GENERAL-CONSTYEAR = ITAB-BAUJJ.
WA_GENERAL_DATAX-CONSTYEAR = TRUE.

WA_DATA_GENERAL-CONSTMONTH = ITAB-BAUMM.
WA_GENERAL_DATAX-CONSTMONTH = TRUE.

WA_DATA_GENERAL-MANPARNO = ITAB-MAPAR.
WA_GENERAL_DATAX-MANPARNO = TRUE.

WA_DATA_GENERAL-CONSTTYPE = ITAB-SUBMT.
WA_GENERAL_DATAX-CONSTTYPE = TRUE.


CALL FUNCTION 'BAPI_EQUI_CHANGE'
EXPORTING
EQUIPMENT = V_EQUNR
DATA_GENERAL = WA_DATA_GENERAL
DATA_GENERALX = WA_GENERAL_DATAX
DATA_SPECIFIC = WA_SPECIFIC_DATA
DATA_SPECIFICX = WA_SPECIFIC_DATAX
IMPORTING
RETURN = IT_RETURN.

APPEND IT_RETURN.


IF IT_RETURN[] IS NOT INITIAL.

LOOP AT IT_RETURN.
GT_EQUTAB1-EQUNR = V_EQUNR.
GT_EQUTAB1-ZMAIL = ITAB-ZMAIL.
GT_EQUTAB1-REFMA = ITAB-REFMA.
GT_EQUTAB1-SERGE = ITAB-SERGE.
GT_EQUTAB1-TPLNR = ITAB-TPLNR.
GT_EQUTAB1-EXCEPT = IT_RETURN-MESSAGE.
GT_EQUTAB1-TYPE = IT_RETURN-TYPE.
GT_EQUTAB1-PLTXT = V_PLTXT.
GT_EQUTAB1-MODE = V_CRE.
APPEND GT_EQUTAB1.
CLEAR GT_EQUTAB.
ENDLOOP.

ENDIF.


READ TABLE IT_RETURN WITH KEY TYPE = 'E' .

IF SY-SUBRC IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.

ENDIF.

WAIT UP TO 2 SECONDS.
IF ITAB-CLASS IS NOT INITIAL.

V_OBJECT = V_EQUNR.
V_CLASS_NEW = ITAB-CLASS.
V_CLASS_TYP = ITAB-KLART.

IF ITAB-MNAME = 'INST_DATE'.
V_DATE = ITAB-MWERT.
WRITE V_DATE TO IT_CHAR-VALUE_CHAR..

IT_CHAR-CHARACT = ITAB-MNAME.

APPEND IT_CHAR.
ENDIF.


CALL FUNCTION 'BAPI_OBJCL_CREATE'
EXPORTING
OBJECTKEYNEW = V_OBJECT
OBJECTTABLENEW = V_TABLE
CLASSNUMNEW = V_CLASS_NEW
CLASSTYPENEW = V_CLASS_TYP
STATUS = ' '
TABLES
ALLOCVALUESCHAR = IT_CHAR
RETURN = IT_RETCAL.

READ TABLE IT_RETCAL WITH KEY TYPE = 'E' .
IF SY-SUBRC IS NOT INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
.
ELSE .
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
LOOP AT IT_RETCAL.
GT_EQUTAB1-EQUNR = V_EQUNR.
GT_EQUTAB1-ZMAIL = ITAB-ZMAIL.
GT_EQUTAB1-REFMA = ITAB-REFMA.
GT_EQUTAB1-SERGE = ITAB-SERGE.
GT_EQUTAB1-TPLNR = ITAB-TPLNR.
GT_EQUTAB1-EXCEPT = IT_RETCAL-MESSAGE.
GT_EQUTAB1-TYPE = IT_RETCAL-TYPE.
GT_EQUTAB1-PLTXT = V_PLTXT.
GT_EQUTAB1-MODE = V_CRE.
APPEND GT_EQUTAB1.
CLEAR GT_EQUTAB1.


ENDLOOP.
ENDIF.
CLEAR : WA_DATA_GENERAL,
WA_GENERAL_DATAX,
WA_SPECIFIC_DATA,
WA_SPECIFIC_DATAX,
WA_ADDR,
WA_EQUIP,
V_OBJECT,
V_EQKTX,
V_EQUNR,
V_DATE,
V_CLASS_NEW,
V_CLASS_TYP,
IT_CHAR,
IT_RETCAL,
IT_RETURN,
V_TPLNR,
IT_EQUIP,
IT_ADDR,
IT_ADDR1.

REFRESH : IT_CHAR,
IT_RETCAL,
IT_RETURN,
IT_EQUIP,
IT_ADDR,
IT_ADDR1.
ENDIF.







ENDLOOP.

ENDFORM. " create_equipment
*&---------------------------------------------------------------------*
*& Form change_equipment
*&---------------------------------------------------------------------*
* Change the Equipment data
*----------------------------------------------------------------------*
FORM CHANGE_EQUIPMENT .
DELETE ITAB WHERE CHGFLG NE 'X'.
CHECK NOT ITAB[] IS INITIAL.
SORT ITAB .
LOOP AT ITAB.

* * For the material and serial number combination from the file
* Select the equipment
READ TABLE GT_EQUI WITH KEY MATNR = ITAB-REFMA
SERGE = ITAB-SERGE.
*** Equipment Number
V_EQUNR = GT_EQUI-EQUNR.


****************** New Address Details( Building & Grid)

IF ITAB-NAME1 IS NOT INITIAL OR ITAB-NAME2 IS NOT INITIAL.

* select single iloan from equz into v_iloan where equnr = v_equnr
* and EQLFN = c_eqlfn.
*
*
* select single adrnr from iloa into v_address
* where iloan = v_iloan.

SELECT EQUNR ILOAN FROM EQUZ INTO TABLE IT_ILOAN
WHERE EQUNR = V_EQUNR.

LOOP AT IT_ILOAN.
SELECT SINGLE ADRNR FROM ILOA INTO V_ADDRESS
WHERE ILOAN = IT_ILOAN-ILOAN.
IF V_ADDRESS IS NOT INITIAL.
EXIT.
ENDIF.
ENDLOOP.
IF V_ADDRESS IS INITIAL.

SELECT SINGLE OBJNR FROM ITOB INTO
V_NEW_OBJNR WHERE EQUNR = V_EQUNR.


MOVE: V_TABLE TO IT_AD_HANDLE_STR-TABLE,
V_NEW_OBJNR TO IT_AD_HANDLE_STR-OBJNR.

MOVE IT_AD_HANDLE_STR TO V_ADDRESS_HANDLE.

V_UPDATE_FLAG = 'I'.

* select single land1 from t001w into v_country
* where werks = itab-iwerk. "Get Country Key
IT_ADDR1-DATA-NAME1 = ITAB-NAME1.
IT_ADDR1-DATA-NAME2 = ITAB-NAME2.
IT_ADDR1-DATA-COUNTRY = V_COUNTRY.
APPEND IT_ADDR1.

WA_ADDR-ADDR1_DATA[] = IT_ADDR1[].
WA_ADDR-ADTEL_DATA[] = IT_ADTEL[]. "Dummy structure

WA_COMPLETE_ADDRESS-ADDRHANDLE = V_ADDRESS_HANDLE.
WA_COMPLETE_ADDRESS-ADDR1_TAB[] = WA_ADDR-ADDR1_DATA[].
WA_COMPLETE_ADDRESS-ADTEL_TAB[] = WA_ADDR-ADTEL_DATA[].



CALL FUNCTION 'ADDR_MAINTAIN_COMPLETE'
EXPORTING
UPDATEFLAG = V_UPDATE_FLAG
ADDR1_COMPLETE = WA_COMPLETE_ADDRESS
ADDRESS_GROUP = V_PM01
IMPORTING
RETURNCODE = V_RECODE
TABLES
ERROR_TABLE = IT_ERROR_TAB
EXCEPTIONS
PARAMETER_ERROR = 1
ADDRESS_NOT_EXIST = 2
HANDLE_EXIST = 3
INTERNAL_ERROR = 4
OTHERS = 5.



MOVE: SY-MANDT TO IT_AD_REFKEY-MANDT,
V_EQUNR TO IT_AD_REFKEY-ID.


MOVE: V_TABLE TO IT_AD_REF-APPL_TABLE,
V_EQUNR1 TO IT_AD_REF-APPL_FIELD,
IT_AD_REFKEY TO IT_AD_REF-APPL_KEY.

IT_AD_REF-ADDR_GROUP = V_PM01.
IT_AD_REF-OWNER = TRUE.

MOVE IT_AD_HANDLE_STR TO V_AD_HANDLE.


CALL FUNCTION 'ADDR_NUMBER_GET'
EXPORTING
ADDRESS_HANDLE = V_AD_HANDLE
ADDRESS_REFERENCE = IT_AD_REF
IMPORTING
ADDRESS_NUMBER = V_NEW_ADDRESS
EXCEPTIONS
ADDRESS_HANDLE_NOT_EXIST = 1
INTERNAL_ERROR = 2
PARAMETER_ERROR = 3
OTHERS = 4.

IF SY-SUBRC = 0.

CALL FUNCTION 'ADDR_MEMORY_SAVE'
EXPORTING
EXECUTE_IN_UPDATE_TASK = TRUE
EXCEPTIONS
ADDRESS_NUMBER_MISSING = 1
PERSON_NUMBER_MISSING = 2
INTERNAL_ERROR = 3
DATABASE_ERROR = 4
REFERENCE_MISSING = 5
OTHERS = 6.

**********Address Details
WA_DATA_GENERAL-ADRNR = V_NEW_ADDRESS.
WA_GENERAL_DATAX-ADRNR = TRUE.
WA_DATA_GENERAL-ADRNRI = 'D'.
WA_GENERAL_DATAX-ADRNRI = TRUE.
ENDIF.
ELSE.
** Existing address

WA_COMPLETE_ADDRESS-ADDRNUMBER = V_ADDRESS.

V_UPDATE_FLAG = 'U'.

* select single land1 from t001w into v_country
* where werks = itab-iwerk. "Get Country Key
IT_ADDR1-DATA-NAME1 = ITAB-NAME1.
IT_ADDR1-DATA-NAME2 = ITAB-NAME2.
IT_ADDR1-DATA-COUNTRY = V_COUNTRY.
APPEND IT_ADDR1.

WA_ADDR-ADDR1_DATA[] = IT_ADDR1[].
WA_ADDR-ADTEL_DATA[] = IT_ADTEL[]. "Dummy structure

WA_COMPLETE_ADDRESS-ADDRHANDLE = V_ADDRESS_HANDLE.
WA_COMPLETE_ADDRESS-ADDR1_TAB[] = WA_ADDR-ADDR1_DATA[].
WA_COMPLETE_ADDRESS-ADTEL_TAB[] = WA_ADDR-ADTEL_DATA[].



CALL FUNCTION 'ADDR_MAINTAIN_COMPLETE'
EXPORTING
UPDATEFLAG = V_UPDATE_FLAG
ADDR1_COMPLETE = WA_COMPLETE_ADDRESS
ADDRESS_GROUP = V_PM01
IMPORTING
RETURNCODE = V_RECODE
TABLES
ERROR_TABLE = IT_ERROR_TAB
EXCEPTIONS
PARAMETER_ERROR = 1
ADDRESS_NOT_EXIST = 2
HANDLE_EXIST = 3
INTERNAL_ERROR = 4
OTHERS = 5.

CALL FUNCTION 'ADDR_SINGLE_SAVE'
EXPORTING
ADDRESS_NUMBER = V_ADDRESS
EXECUTE_IN_UPDATE_TASK = TRUE
EXCEPTIONS
ADDRESS_NOT_EXIST = 1
PERSON_NOT_EXIST = 2
ADDRESS_NUMBER_MISSING = 3
REFERENCE_MISSING = 4
INTERNAL_ERROR = 5
DATABASE_ERROR = 6
PARAMETER_ERROR = 7
OTHERS = 8.

ENDIF.
ENDIF.
*********************Change Equipment
***** Genral Data

WA_DATA_GENERAL-AUTHGRP = ITAB-BEGRU.
WA_GENERAL_DATAX-AUTHGRP = TRUE.

WA_DATA_GENERAL-PLANPLANT = ITAB-IWERK.
WA_GENERAL_DATAX-PLANPLANT = TRUE.

WA_DATA_GENERAL-INVENTORY = ITAB-INVNR.
WA_GENERAL_DATAX-INVENTORY = TRUE.

WA_DATA_GENERAL-OBJECTTYPE = ITAB-EQART.
WA_GENERAL_DATAX-OBJECTTYPE = TRUE.

WA_DATA_GENERAL-MANFACTURE = ITAB-HERST.
WA_GENERAL_DATAX-MANFACTURE = TRUE.

WA_DATA_GENERAL-MANMODEL = ITAB-TYPBZ.
WA_GENERAL_DATAX-MANMODEL = TRUE.

WA_DATA_GENERAL-CONSTYEAR = ITAB-BAUJJ.
WA_GENERAL_DATAX-CONSTYEAR = TRUE.

WA_DATA_GENERAL-CONSTMONTH = ITAB-BAUMM.
WA_GENERAL_DATAX-CONSTMONTH = TRUE.

WA_DATA_GENERAL-MANPARNO = ITAB-MAPAR.
WA_GENERAL_DATAX-MANPARNO = TRUE.

WA_DATA_GENERAL-CONSTTYPE = ITAB-SUBMT.
WA_GENERAL_DATAX-CONSTTYPE = TRUE.

********* Technical identification number

WA_SPECIFIC_DATA-TECHID = ITAB-TIDNR.
WA_SPECIFIC_DATAX-TECHID = TRUE.




CALL FUNCTION 'BAPI_EQUI_CHANGE'
EXPORTING
EQUIPMENT = V_EQUNR
DATA_GENERAL = WA_DATA_GENERAL
DATA_GENERALX = WA_GENERAL_DATAX
DATA_SPECIFIC = WA_SPECIFIC_DATA
DATA_SPECIFICX = WA_SPECIFIC_DATAX
IMPORTING
RETURN = IT_RETURN.
APPEND IT_RETURN.
SELECT SINGLE PLTXT FROM IFLOTX INTO V_PLTXT WHERE TPLNR = ITAB-TPLNR.

IF IT_RETURN IS NOT INITIAL.

LOOP AT IT_RETURN.

GT_EQUTAB-EQUNR = V_EQUNR.
GT_EQUTAB-ZMAIL = ITAB-ZMAIL.
GT_EQUTAB-REFMA = ITAB-REFMA.
GT_EQUTAB-SERGE = ITAB-SERGE.
GT_EQUTAB-TPLNR = ITAB-TPLNR.
GT_EQUTAB-EXCEPT = IT_RETURN-MESSAGE.
GT_EQUTAB-TYPE = IT_RETURN-TYPE.
GT_EQUTAB-PLTXT = V_PLTXT.
GT_EQUTAB-MODE = V_CHAN.
APPEND GT_EQUTAB.
CLEAR GT_EQUTAB.

ENDLOOP.


ELSE.
GT_EQUTAB-EQUNR = V_EQUNR.
GT_EQUTAB-ZMAIL = P_EMAIL.
GT_EQUTAB-REFMA = ITAB-REFMA.
GT_EQUTAB-SERGE = ITAB-SERGE.
GT_EQUTAB-TPLNR = ITAB-TPLNR.
GT_EQUTAB-TYPE = 'S'.
GT_EQUTAB-PLTXT = V_PLTXT.
GT_EQUTAB-MODE = V_CHAN.
APPEND GT_EQUTAB.
CLEAR GT_EQUTAB.
ENDIF.
READ TABLE IT_RETURN WITH KEY TYPE = 'E' .

IF SY-SUBRC IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.

ENDIF.

* wait up to 2 seconds.
* Characteristics

* read table gt_kssk with key objek = gt_equi-objek.
* if sy-subrc = 0.

V_OBJECT = V_EQUNR.
V_CLASS_NEW = ITAB-CLASS.
V_CLASS_TYP = ITAB-KLART.

IF ITAB-MNAME = 'INST_DATE'.

V_DATE = ITAB-MWERT.
WRITE V_DATE TO IT_CHAR-VALUE_CHAR.
IT_CHAR-CHARACT = ITAB-MNAME.

APPEND IT_CHAR.


CALL FUNCTION 'BAPI_OBJCL_CHANGE'
EXPORTING
OBJECTKEY = V_OBJECT
OBJECTTABLE = V_TABLE
CLASSNUM = V_CLASS_NEW
CLASSTYPE = V_CLASS_TYP
STATUS = '1'
TABLES
ALLOCVALUESNUMNEW = ALLOCVAL_NUM
ALLOCVALUESCHARNEW = IT_CHAR
ALLOCVALUESCURRNEW = ALLOCVAL_CURR
RETURN = IT_RETCAL.

IF SY-SUBRC IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ENDIF.
ENDIF.
* endif.

LOOP AT IT_RETCAL.
GT_EQUTAB1-EQUNR = V_EQUNR.
GT_EQUTAB1-ZMAIL = ITAB-ZMAIL.
GT_EQUTAB1-REFMA = ITAB-REFMA.
GT_EQUTAB1-SERGE = ITAB-SERGE.
GT_EQUTAB1-TPLNR = ITAB-TPLNR.
GT_EQUTAB1-EXCEPT = IT_RETCAL-MESSAGE.
GT_EQUTAB1-TYPE = IT_RETCAL-TYPE.
GT_EQUTAB1-PLTXT = V_PLTXT.
APPEND GT_EQUTAB1.
CLEAR GT_EQUTAB1.

ENDLOOP.

CLEAR : WA_DATA_GENERAL,
WA_GENERAL_DATAX,
WA_SPECIFIC_DATA,
WA_SPECIFIC_DATAX,
WA_ADDR,
WA_EQUIP,
V_OBJECT,
V_EQKTX,
V_EQUNR,
V_DATE,
V_CLASS_NEW,
V_CLASS_TYP,
V_ILOAN,
V_NEW_ADDRESS,
V_AD_HANDLE,
IT_CHAR,
IT_RETCAL,
IT_RETURN,
V_TPLNR,
IT_EQUIP,
IT_ADDR,
IT_ADDR1.

REFRESH : IT_CHAR,
IT_RETCAL,
IT_RETURN,
IT_EQUIP,
IT_ADDR,
IT_ADDR1.





ENDLOOP.





ENDFORM. " change_equipment
*&---------------------------------------------------------------------*
*& Form displaydata
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM DISPLAYDATA .
LOOP AT GT_EQUTAB.

IF GT_EQUTAB-MODE = V_CRE.
READ TABLE GT_EQUTAB1 WITH KEY EQUNR = GT_EQUTAB-EQUNR
TYPE = 'E'.

IF SY-SUBRC IS NOT INITIAL.

IF GT_EQUTAB-TYPE NE 'E'.
GT_EQUTAB-STATUS = TEXT-036.
ELSE.
GT_EQUTAB-STATUS = TEXT-035.
ENDIF.

IF GT_EQUTAB1-EXCEPT IS INITIAL .
GT_EQUTAB1-EXCEPT = TEXT-036.
ENDIF.
ULINE: 1(185).
WRITE :/ SPACE COLOR 2.
WRITE : 1 SY-VLINE,
2 GT_EQUTAB-EQUNR COLOR 2,
13 SY-VLINE,
14 GT_EQUTAB-REFMA COLOR 2,
35 SY-VLINE,
36 GT_EQUTAB-SERGE COLOR 2,
67 SY-VLINE,
68 GT_EQUTAB-PLTXT COLOR 2,
103 SY-VLINE,
104 GT_EQUTAB-EXCEPT,
145 SY-VLINE,
146 GT_EQUTAB-STATUS COLOR 3 ,
185 SY-VLINE.
ULINE:/1(185).

ELSE.
GT_EQUTAB-STATUS = TEXT-035.
IF GT_EQUTAB1-EXCEPT IS INITIAL .
GT_EQUTAB1-EXCEPT = TEXT-035.
ENDIF.
LOOP AT GT_EQUTAB1 WHERE EQUNR = GT_EQUTAB-EQUNR.
ULINE: 1(185).
WRITE :/ SPACE COLOR 2.
WRITE : 1 SY-VLINE,
2 GT_EQUTAB1-EQUNR COLOR 2,
13 SY-VLINE,
14 GT_EQUTAB1-REFMA COLOR 2,
35 SY-VLINE,
36 GT_EQUTAB1-SERGE COLOR 2,
67 SY-VLINE,
68 GT_EQUTAB1-PLTXT COLOR 2,
103 SY-VLINE,
104 GT_EQUTAB1-EXCEPT,
145 SY-VLINE,
146 GT_EQUTAB1-STATUS COLOR 3 ,
185 SY-VLINE.
ULINE:/1(185).
ENDLOOP.

ENDIF.
ELSE.

READ TABLE GT_EQUTAB1 WITH KEY EQUNR = GT_EQUTAB-EQUNR
TYPE = 'E'.

IF SY-SUBRC IS NOT INITIAL.
IF GT_EQUTAB-TYPE NE 'E'.
GT_EQUTAB-STATUS = TEXT-038.
ELSE.
GT_EQUTAB-STATUS = TEXT-037.
ENDIF.
IF GT_EQUTAB-EXCEPT IS INITIAL .
GT_EQUTAB-EXCEPT = TEXT-038.
ENDIF.
ULINE: 1(185).
WRITE :/ SPACE COLOR 2.
WRITE : 1 SY-VLINE,
2 GT_EQUTAB-EQUNR COLOR 2,
13 SY-VLINE,
14 GT_EQUTAB-REFMA COLOR 2,
35 SY-VLINE,
36 GT_EQUTAB-SERGE COLOR 2,
67 SY-VLINE,
68 GT_EQUTAB-PLTXT COLOR 2,
103 SY-VLINE,
104 GT_EQUTAB-EXCEPT,
145 SY-VLINE,
146 GT_EQUTAB-STATUS COLOR 3 ,
185 SY-VLINE.
ULINE:/1(185).

ELSE.
GT_EQUTAB1-STATUS = TEXT-037.
GT_EQUTAB1-EXCEPT = TEXT-037.
LOOP AT GT_EQUTAB1 WHERE EQUNR = GT_EQUTAB-EQUNR.
ULINE: 1(185).
WRITE :/ SPACE COLOR 2.
WRITE : 1 SY-VLINE,
2 GT_EQUTAB1-EQUNR COLOR 2,
13 SY-VLINE,
14 GT_EQUTAB1-REFMA COLOR 2,
35 SY-VLINE,
36 GT_EQUTAB1-SERGE COLOR 2,
67 SY-VLINE,
68 GT_EQUTAB1-PLTXT COLOR 2,
103 SY-VLINE,
104 GT_EQUTAB1-EXCEPT,
145 SY-VLINE,
146 GT_EQUTAB1-STATUS COLOR 3 ,
185 SY-VLINE.
ULINE:/1(185).
ENDLOOP.

ENDIF.


ENDIF.

AT NEW ZMAIL.
GT_OBJTXT = TEXT-020.
APPEND GT_OBJTXT.
CLEAR GT_OBJTXT.
APPEND GT_OBJTXT.
ENDAT.

CONCATENATE GT_EQUTAB-EQUNR
TEXT-032 GT_EQUTAB-REFMA
TEXT-033 GT_EQUTAB-SERGE
TEXT-034 GT_EQUTAB-TPLNR '-'
GT_EQUTAB-EXCEPT
INTO GT_OBJTXT SEPARATED BY SPACE.

APPEND GT_OBJTXT.
CLEAR GT_OBJTXT.

AT END OF ZMAIL.
PERFORM SENDING USING GT_EQUTAB-ZMAIL.
ENDAT.
ENDLOOP.


ENDFORM. " displaydata
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.