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

Creating / Changing an order for the notification



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

PostPosted: Tue Oct 09, 2007 10:19 am    Post subject: Creating / Changing an order for the notification Reply with quote

Creation of an Order

Use
Process an order by creating an order in the system.

Integration
In order that you can create orders for notifications, the application component Maintenance Notifications (PM-WOC-MN) must be used in your company.

Prerequisites
The different options are only available if the necessary settings have been made in your system in the Customizing of Plant Maintenance.

Code:
DATA wa_methods TYPE bapi_alm_order_method.
DATA itab_methods TYPE TABLE OF bapi_alm_order_method.

DATA wa_header TYPE bapi_alm_order_headers_i.
DATA itab_header TYPE TABLE OF bapi_alm_order_headers_i.

DATA wa_header_up TYPE bapi_alm_order_headers_up.
DATA itab_header_up TYPE TABLE OF bapi_alm_order_headers_up.

DATA wa_operation TYPE bapi_alm_order_operation.
DATA itab_operation TYPE TABLE OF bapi_alm_order_operation.

DATA wa_operation_up TYPE bapi_alm_order_operation_up.
DATA itab_operation_up TYPE TABLE OF bapi_alm_order_operation_up.

DATA wa_text TYPE bapi_alm_text.
DATA itab_text TYPE TABLE OF bapi_alm_text.

DATA wa_text_lines TYPE bapi_alm_text_lines.
DATA itab_text_lines TYPE TABLE OF bapi_alm_text_lines.

DATA itab_return TYPE TABLE OF bapiret2.
DATA itab_numbers TYPE TABLE OF bapi_alm_numbers.

BREAK-POINT.

* IT_METHODS - HEADER
wa_methods-refnumber = 1.
wa_methods-objecttype = 'HEADER'.
wa_methods-method = 'CREATE'.
wa_methods-objectkey = '%00000000001'.
APPEND wa_methods TO itab_methods.

* IT_METHODS - OPERATION
wa_methods-refnumber = 1.
wa_methods-objecttype = 'OPERATION'.
wa_methods-method = 'CREATE'.
wa_methods-objectkey = '%00000000001'.
APPEND wa_methods TO itab_methods.

* IT_METHODS - TEXT
wa_methods-refnumber = 1.
wa_methods-objecttype = 'TEXT'.
wa_methods-method = 'CREATE'.
wa_methods-objectkey = '%000000000010010'.
APPEND wa_methods TO itab_methods.

* IT_METHODS - SAVE
wa_methods-refnumber = 1.
wa_methods-objecttype = ' '.
wa_methods-method = 'SAVE'.
wa_methods-objectkey = '%00000000001'.
APPEND wa_methods TO itab_methods.

* IT_HEADER
wa_header-orderid = '%00000000001'.
wa_header-order_type = 'PM01'. <-- according to customizing
wa_header-planplant = 1000. <-- according to customizing
wa_header-mn_wk_ctr = 'MINMC'. <-- according to customizing
wa_header-plant = 1000.
wa_header-pmacttype = '001'.
wa_header-start_date = '20041019'. "se colocan al reves de como son
wa_header-finish_date = '20041020'.
wa_header-short_text = 'HEADER'.
APPEND wa_header TO itab_header.

* IT_HEADER_UP
wa_header-mn_wk_ctr = 'X'.
wa_header-plant = 'X'.
wa_header-pmacttype = 'X'.
wa_header-start_date = 'X'.
wa_header-finish_date = 'X'.
wa_header-short_text = 'X'.
APPEND wa_header_up TO itab_header_up.

* IT_OPERATION
wa_operation-activity = '0010'.
wa_operation-control_key = 'PM01'.
wa_operation-plant = 1000.
APPEND wa_operation TO itab_operation.

* IT_OPERATION_UP
wa_operation-activity = 'X'.
wa_operation-control_key = 'X'.
wa_operation-plant = 'X'.
APPEND wa_operation_up TO itab_operation_up.

* IT_TEXT
wa_text-orderid = '%00000000001'.
wa_text-activity = '0010'.
wa_text-textstart = '00000001'.
wa_text-textend = '00000002'.
APPEND wa_text TO itab_text.

* IT_TEXT_LINES
wa_text_lines-tdformat = '*'.
wa_text_lines-tdline = 'line 1'.
APPEND wa_text_lines TO itab_text_lines.
wa_text_lines-tdformat = '*'.
wa_text_lines-tdline = 'line 2'.
APPEND wa_text_lines TO itab_text_lines.



CALL FUNCTION 'BAPI_ALM_ORDER_MAINTAIN'
TABLES
it_methods = itab_methods
it_header = itab_header
it_header_up = itab_header_up
* IT_HEADER_SRV =
* IT_HEADER_SRV_UP =
* IT_USERSTATUS =
* IT_PARTNER =
* IT_PARTNER_UP =
it_operation = itab_operation
it_operation_up = itab_operation_up
* IT_RELATION =
* IT_RELATION_UP =
* IT_COMPONENT =
* IT_COMPONENT_UP =
it_text = itab_text
it_text_lines = itab_text_lines
* EXTENSION_IN =
return = itab_return
et_numbers = itab_numbers.


CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
* IMPORTING
* RETURN =
.


Example 2
Code:

REPORT ZORDERTEST_BAPI .

**&---------------------------------------------------------------------*
**& Report Z_BAPI_ALM_ORDER_MAINTAIN_TEST *
**& *
**&---------------------------------------------------------------------*
**& *
**& *
**&---------------------------------------------------------------------*
*
*REPORT z_bapi_alm_order_maintain_test.

DATA: it_methods LIKE STANDARD TABLE OF bapi_alm_order_method,
wa_methods LIKE LINE OF it_methods.

DATA: it_header LIKE STANDARD TABLE OF bapi_alm_order_headers_i,
wa_header LIKE LINE OF it_header.

DATA: it_operation LIKE STANDARD TABLE OF bapi_alm_order_operation,
wa_operation LIKE LINE OF it_operation.

DATA: it_text LIKE STANDARD TABLE OF bapi_alm_text,
wa_text LIKE LINE OF it_text.

DATA: et_numbers LIKE STANDARD TABLE OF bapi_alm_numbers,
wa_numbers LIKE LINE OF et_numbers.

data: it_return LIKE STANDARD TABLE OF BAPIRET2.

START-OF-SELECTION.

* METHODS SECTION
MOVE '1' TO wa_methods-REFNUMBER.
MOVE 'HEADER' TO wa_methods-objecttype.
*MOVE 'CREATE' TO wa_methods-method.
MOVE 'CHANGE' TO wa_methods-method.
*MOVE '%00000000001' TO wa_methods-objectkey.
MOVE '000006000065' TO wa_methods-objectkey.
*INSERT wa_methods INTO TABLE it_methods.
APPEND wa_methods TO it_methods.

MOVE '1' TO wa_methods-REFNUMBER.
MOVE 'OPERATION' TO wa_methods-objecttype.
*MOVE 'CREATE' TO wa_methods-method.
MOVE 'CHANGE' TO wa_methods-method.
*MOVE '%000000000010010' TO wa_methods-objectkey.
MOVE '000006000065' TO wa_methods-objectkey.
*INSERT wa_methods INTO TABLE it_methods.
APPEND wa_methods TO it_methods.

wa_text-ORDERID = '000006000065'.
wa_text-LANGU = 'EN'.
wa_text-LANGU_ISO = 'EN'.
*wa_text-TEXTSTART = '0001'.
*wa_text-TEXTEND = '0002'.
append wa_text to it_text.



MOVE '1' TO wa_methods-REFNUMBER.
MOVE '' TO wa_methods-objecttype.
MOVE 'SAVE' TO wa_methods-method.
*MOVE '%00000000001' TO wa_methods-objectkey.
MOVE '000006000065' TO wa_methods-objectkey.
*INSERT wa_methods INTO TABLE it_methods.
APPEND wa_methods TO it_methods.

* HEADER SECTION
*MOVE '%00000000001' TO wa_header-orderid.
MOVE '000006000065' TO wa_header-orderid.
MOVE 'ZDIS' TO wa_header-order_type.
MOVE '1001' TO wa_header-planplant.
*MOVE '1001' TO wa_header-mn_wk_ctr.
MOVE '1001' TO wa_header-plant.
*MOVE 'CUV-SZV-CSUR-ATEM-I...' TO wa_header-funct_loc.
MOVE '' TO wa_header-equipment.
MOVE '' TO wa_header-material.
MOVE '8000001022' TO wa_header-funct_loc.
MOVE '20071212' TO wa_header-finish_date.
MOVE SYST-UZEIT TO WA_HEADER-BASIC_FIN.
MOVE 'Changed by manohar from BAPI' TO wa_header-short_text.
*INSERT wa_header INTO TABLE it_header.
APPEND wa_header TO it_header.

* OPERATION SECTION
MOVE '10' TO wa_operation-activity.
MOVE '' TO wa_operation-sub_activity.
MOVE '' TO wa_operation-standard_text_key.
MOVE 'This is what i need ' TO wa_operation-description.
MOVE '' TO wa_operation-vendor_no.
MOVE 3 TO wa_operation-quantity.
MOVE 'KG' TO wa_operation-base_uom.
MOVE '00000015' TO wa_operation-pers_no.
*INSERT wa_operation INTO TABLE it_operation.
APPEND wa_operation TO it_operation.

REFRESH et_numbers.

data: it_text_line type table of BAPI_ALM_TEXT_LINES,
I_TEXTLINE TYPE STANDARD TABLE OF TLINE,
w_text_line type BAPI_ALM_TEXT_LINES.

*Use function module 'READ TEXT'
CALL FUNCTION 'READ_TEXT'
EXPORTING
* CLIENT = SY-MANDT
id = 'KOPF'
language = SYST-LANGU
name = '120000006000065'
object = 'AUFK'
* ARCHIVE_HANDLE = 0
* LOCAL_CAT = ' '
* IMPORTING
* HEADER =
tables
lines = IT_TEXT_LINE
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
break mdubbaka.
w_text_line-TDFORMAT = '*'.
w_text_line-TDLINE = 'Manohar has changed this from program'.
append w_text_line to it_text_line.


data: it_header_serv TYPE TABLE OF BAPI_ALM_ORDER_SRVDAT_E,
WA_HEADER_SERV TYPE BAPI_ALM_ORDER_SRVDAT_E,
IT_HEADER_SERVX TYPE TABLE OF BAPI_ALM_ORDER_SRVDAT_UP,
IT_USERSTATUS type table of BAPI_ALM_ORDER_USRSTAT,
wa_userstatus TYPE BAPI_ALM_ORDER_USRSTAT,
WA_HEADER_SERVX TYPE BAPI_ALM_ORDER_SRVDAT_UP.

* wa_USERSTATUS-USER_ST_TEXT = 'TECO'.
* append wa_userstatus TO it_userstatus.
*The following BAPIs can be made used to get the details of operation,
*Use the function module ALM_ME_ORDER_GETDETAIL as in the program ZORDERLIST_FM
*and pass the corresponding values to th structures and internal tables of the
*BAPI Used below 'BAPI_ALM_ORDER_MAINTAIN' to update PERNR, COMPLETION DATE AND TIME
*The text as of now we will only use the one given in header structure by INSERTING
*The text we want to enter in the internal table IT_TEXT_LINE(NEED TO TEST THIS).

*Other related function modules in include LIBAPI_ALM_ORDERUXX (Don't need them anyways).

CALL FUNCTION 'BAPI_ALM_ORDER_MAINTAIN'
TABLES
it_methods = it_methods
it_header = it_header
* IT_HEADER_UP =
IT_HEADER_SRV = IT_HEADER_SERV
* IT_HEADER_SRV_UP =
* IT_USERSTATUS = IT_USERSTATUS "not working
* IT_PARTNER =
* IT_PARTNER_UP =
it_operation = it_operation
* IT_OPERATION_UP =
* IT_RELATION =
* IT_RELATION_UP =
* IT_COMPONENT =
* IT_COMPONENT_UP =
* IT_TEXT = it_text
IT_TEXT_LINES = it_text_line
* EXTENSION_IN =
RETURN = IT_RETURN
et_numbers = et_numbers
.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.


Example 3
Code:

*&---------------------------------------------------------------------*
*& Report ZSAN_BAPI_ORDER_MAINTAIN *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*

REPORT ZSAN_BAPI_ORDER_MAINTAIN .

PARAMETER: ODR_NO LIKE BAPI_ALM_ORDER_HEADERS_I-ORDERID. " Order Number

DATA: IT_METHODS LIKE BAPI_ALM_ORDER_METHOD OCCURS 0 WITH HEADER LINE,
" Processing methods

IT_HEADER LIKE BAPI_ALM_ORDER_HEADERS_I OCCURS 0 WITH HEADER LINE,
" Import Structure for ALM Order Headers

IT_HEADER_UP LIKE BAPI_ALM_ORDER_HEADERS_UP OCCURS 0 WITH HEADER LINE,
" Update Structure for ALM Order Headers

IT_OPERATION LIKE BAPI_ALM_ORDER_OPERATION OCCURS 0 WITH HEADER LINE,
" Input Structure for PM/CS BAPIs Operations

IT_OPERATION_UP LIKE BAPI_ALM_ORDER_OPERATION_UP OCCURS 0 WITH HEADER LINE,
" Update Structure for PM/CS BAPI Operations

IT_HEADER_SRV LIKE BAPI_ALM_ORDER_SRVDAT_E OCCURS 0 WITH HEADER LINE,
" Service-Specific Data, External Structure

IT_HEADER_SRV_UP LIKE BAPI_ALM_ORDER_SRVDAT_UP OCCURS 0 WITH HEADER LINE,
" Service-Specific Data, External Structure

IT_PARTNERS LIKE BAPI_ALM_ORDER_PARTN_MUL OCCURS 0 WITH HEADER LINE,
" Partner Data

IT_PARTNERS_UP LIKE BAPI_ALM_ORDER_PARTN_MUL_UP OCCURS 0 WITH HEADER LINE,
" Partner Data for Several Orders, Update

RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE,
" Table for return messages

*Tables to get deatils for Order
ES_HEADER LIKE BAPI_ALM_ORDER_HEADER_E OCCURS 0 WITH HEADER LINE,
" Export Structure for ALM Order Header

ES_SRVDATA LIKE BAPI_ALM_ORDER_SRVDAT_E OCCURS 0 WITH HEADER LINE,
" ALM Order BAPIs: Service-Specific Data, External Structure

ET_PARTNER LIKE BAPI_ALM_ORDER_PARTNER OCCURS 0 WITH HEADER LINE,
" Partner Data for Several Orders

ET_OPERATIONS LIKE BAPI_ALM_ORDER_OPERATION_E OCCURS 0 WITH HEADER LINE,
" Export Structure for PM/CS BAPIs Operations

ET_COMP LIKE BAPI_ALM_ORDER_COMPONENT_E OCCURS 0 WITH HEADER LINE,

ET_RELATIONS LIKE BAPI_ALM_ORDER_RELATION_EXPORT OCCURS 0 WITH HEADER LINE,
" BAPI Structure for ALM Order Relationships

ET_TEXTS LIKE BAPI_ALM_TEXT OCCURS 0 WITH HEADER LINE,
" Text Header for ALM Order BAPIs

ET_TEXT_LINES LIKE BAPI_ALM_TEXT_LINES OCCURS 0 WITH HEADER LINE,
" Text Lines for ALM BAPIs

ET_PRTS LIKE BAPI_ALM_ORDER_PRT_E OCCURS 0 WITH HEADER LINE,
" Structure for Production Resources/Tools

ET_COSTS_SUM LIKE BAPI_ALM_ORDER_COSTS_SUM_E OCCURS 0 WITH HEADER LINE,
" Structure for Order Costs Sum

ET_COST_DET LIKE BAPI_ALM_ORDER_COSTS_DETAIL_E OCCURS 0 WITH HEADER LINE,
" Structure for Order Costs Detail

RETURN1 LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE
" Table for return messages
.

*Get deatils for Order
CALL FUNCTION 'BAPI_ALM_ORDER_GET_DETAIL'
EXPORTING
NUMBER = ODR_NO
IMPORTING
ES_HEADER = ES_HEADER
ES_SRVDATA = ES_SRVDATA
TABLES
ET_PARTNER = ET_PARTNER
ET_OPERATIONS = ET_OPERATIONS
ET_COMPONENTS = ET_COMP
ET_RELATIONS = ET_RELATIONS
ET_TEXTS = ET_TEXTS
ET_TEXT_LINES = ET_TEXT_LINES
ET_PRTS = ET_PRTS
ET_COSTS_SUM = ET_COSTS_SUM
ET_COSTS_DETAILS = ET_COST_DET
RETURN = RETURN1.


*Fill values in IT_METHODS
IT_METHODS-METHOD = 'SAVE'.
IT_METHODS-OBJECTKEY = ODR_NO.
APPEND IT_METHODS.

*Fill values in IT_METHODS
IT_METHODS-METHOD = 'CHANGE'.
IT_METHODS-REFNUMBER = 1.
IT_METHODS-OBJECTTYPE = 'HEADER'.
IT_METHODS-OBJECTKEY = ODR_NO.
APPEND IT_METHODS.

*Fill values in IT_HEADER
IT_HEADER-ORDERID = ODR_NO.
IT_HEADER-MN_WK_CTR = '1114'.
*IT_HEADER-PLANT = ES_HEADER-PLANT.
*IT_HEADER-ORDER_TYPE = ES_HEADER-ORDER_TYPE.
*IT_HEADER-PLANPLANT = ES_HEADER-PLANPLANT.
*IT_HEADER-BUS_AREA = ES_HEADER-BUS_AREA.
IT_HEADER-MATERIAL = 'Y-352'.
APPEND IT_HEADER.

*Fill values in IT_HEADER_UP
IT_HEADER_UP-ORDERID = ODR_NO.
IT_HEADER_UP-MN_WK_CTR = 'X'.
IT_HEADER_UP-MATERIAL = 'X'.
APPEND IT_HEADER_UP.

*Maintain Order
CALL FUNCTION 'BAPI_ALM_ORDER_MAINTAIN'
TABLES
IT_METHODS = IT_METHODS
IT_HEADER = IT_HEADER
IT_HEADER_UP = IT_HEADER_UP
IT_PARTNER = IT_PARTNERS
IT_PARTNER_UP = IT_PARTNERS_UP
IT_OPERATION = IT_OPERATION
IT_OPERATION_UP = IT_OPERATION_UP
IT_HEADER_SRV = IT_HEADER_SRV
IT_HEADER_SRV_UP = IT_HEADER_SRV_UP
RETURN = RETURN.

*Commit BAPI
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.

*Display order status
FORMAT COLOR 6 INVERSE ON.

READ TABLE RETURN WITH KEY TYPE = 'E'.
IF SY-SUBRC = 0.
WRITE: /,'Order not maintained'.
LOOP AT RETURN.
WRITE: /,RETURN-MESSAGE.
ENDLOOP.
ELSE.
WRITE:/,RETURN-MESSAGE,/,'Order maintained with number',ODR_NO.
ENDIF.

FORMAT COLOR OFF INVERSE OFF.
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.