Posted: Sun Oct 14, 2007 8:29 pm Post subject: Equipment creation
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.
* 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. "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.
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.
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.
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.