sap note

9
1/ 10/ 13 Di spl ay sour ce f or cor r ect i on 1/ 9 ht t ps: / / websm p230. sap- ag. de/ sap( bD1l bi Zj PTAwM Q ==) / bc/ bsp/ spn/ cor r _i nst r / cor r ect i on_det ai l . ht m ?_… Print PROGRAM Z_SIMPLE_EWB Delta001 Context Block * ================================================ * demo program * using the EWB-API for changing the * short text of an operation * and creating a new task list * ================================================ REPORT z_simple_ewb . * global fields, declarations * ================================================ INCLUDE fc27date. INCLUDE cp_cs_const_message. TYPE-POOLS: cc01, cpsc, cpcl, cmcl, czcl, cssc, cscl. * selection parameters TYPES: BEGIN OF create_parameter_type, matnr TYPE mapl-matnr, werks TYPE mapl-werks, verwe TYPE plko-verwe, statu TYPE plko-statu, plnme TYPE plko-plnme, steus TYPE plpo-steus, steuf TYPE plfhd-steuf, fhmat TYPE plfhd-matnr, sttag TYPE plko-datuv, number(4) TYPE n. TYPES: END OF create_parameter_type. DATA g_parameter TYPE create_parameter_type. * selection screen * ================================================ SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01. PARAMETERS: p_plnty TYPE plko-plnty DEFAULT 'N', "task list type p_plnnr TYPE plko-plnnr DEFAULT '50001192', "task list group number p_plnal TYPE plko-plnal DEFAULT '1', "group counter p_sttag TYPE plko-datuv DEFAULT sy-datum. "keydate

Upload: niroop-raj

Post on 16-Apr-2015

160 views

Category:

Documents


8 download

DESCRIPTION

SAP NOTE

TRANSCRIPT

Page 1: SAP NOTE

1/ 10/ 13 Display sour ce f or cor r ect ion

1/ 9ht t ps: / / websm p230. sap- ag. de/ sap( bD1lbiZjPTAwM Q ==) / bc/ bsp/ spn/ cor r _inst r / cor r ect ion_det ail. ht m ?_…

Print

PROGRAM Z_SIMPLE_EWB

Delta001

Context Block

* ================================================* demo program* using the EWB-API for changing the* short text of an operation* and creating a new task list* ================================================

REPORT z_simple_ewb .

* global fields, declarations* ================================================INCLUDE fc27date.INCLUDE cp_cs_const_message.TYPE-POOLS: cc01, cpsc, cpcl, cmcl, czcl, cssc, cscl.

* selection parametersTYPES: BEGIN OF create_parameter_type, matnr TYPE mapl-matnr, werks TYPE mapl-werks, verwe TYPE plko-verwe, statu TYPE plko-statu, plnme TYPE plko-plnme, steus TYPE plpo-steus, steuf TYPE plfhd-steuf, fhmat TYPE plfhd-matnr, sttag TYPE plko-datuv, number(4) TYPE n.TYPES: END OF create_parameter_type.

DATA g_parameter TYPE create_parameter_type.

* selection screen* ================================================SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.PARAMETERS: p_plnty TYPE plko-plnty DEFAULT 'N', "task list type p_plnnr TYPE plko-plnnr DEFAULT '50001192', "task list group number p_plnal TYPE plko-plnal DEFAULT '1', "group counter p_sttag TYPE plko-datuv DEFAULT sy-datum. "keydate

Page 2: SAP NOTE

1/ 10/ 13 Display sour ce f or cor r ect ion

2/ 9ht t ps: / / websm p230. sap- ag. de/ sap( bD1lbiZjPTAwM Q ==) / bc/ bsp/ spn/ cor r _inst r / cor r ect ion_det ail. ht m ?_…

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t02.PARAMETERS: p_matnr TYPE mapl-matnr DEFAULT 'OS_M1', "material p_werks TYPE mapl-werks DEFAULT '0001', "plant p_verwe TYPE plko-verwe DEFAULT '1', "usage p_statu TYPE plko-statu DEFAULT '4', "status p_plnme TYPE plko-plnme DEFAULT 'ST', "base quantity p_steus TYPE plpo-steus DEFAULT 'PP01', "control key p_steuf TYPE plfhd-steuf DEFAULT '1', "control key prt p_fhmat TYPE plfhd-matnr DEFAULT 'OS_FHM1', "material number prt p_number(4) TYPE n DEFAULT '10'. "number of operationsSELECTION-SCREEN END OF BLOCK b2.

g_parameter-matnr = p_matnr.g_parameter-werks = p_werks.g_parameter-verwe = p_verwe.g_parameter-statu = p_statu.g_parameter-plnme = p_plnme.g_parameter-steus = p_steus.g_parameter-steuf = p_steuf.g_parameter-fhmat = p_fhmat.g_parameter-sttag = p_sttag.g_parameter-number = p_number.

* main program* ================================================

* 1. load task list into internal EWB-bufferPERFORM load_task_list USING p_plnty p_plnnr p_plnal p_sttag.

* 2. change the loaded task listPERFORM change_task_list USING p_sttag.

* 3. create a new task listPERFORM create_task_list USING g_parameter.

* 4. save changed task list to database

Page 3: SAP NOTE

1/ 10/ 13 Display sour ce f or cor r ect ion

3/ 9ht t ps: / / websm p230. sap- ag. de/ sap( bD1lbiZjPTAwM Q ==) / bc/ bsp/ spn/ cor r _inst r / cor r ect ion_det ail. ht m ?_…

PERFORM save_to_database.

COMMIT WORK.WRITE: /'program ready.'.

*&---------------------------------------------------------------------**& Form LOAD_TASK_LIST*&---------------------------------------------------------------------** load task listr into internal EWB-BUFFER*----------------------------------------------------------------------** -->I_PLNTY task list type* -->I_PLNNR task list number = group number* -->I_PLNAL group counter* -->I_STTAG keydate*----------------------------------------------------------------------*FORM load_task_list USING i_plnty LIKE plko-plnty i_plnnr LIKE plko-plnnr i_plnal LIKE plko-plnal i_sttag LIKE plko-datuv.

DATA: l_classes_in_workarea LIKE classes_in_workarea, l_tsk_plnty_selection TYPE cpsc_plnty_type, lt_tsk_plnty_selection TYPE cpsc_plnty_type OCCURS 0, l_tsk_plnnr_selection TYPE cpsc_plnnr_type, lt_tsk_plnnr_selection TYPE cpsc_plnnr_type OCCURS 0, l_tsk_plnal_selection TYPE cpsc_plnal_type, lt_tsk_plnal_selection TYPE cpsc_plnal_type OCCURS 0, l_tsk_selection TYPE cpsc_tsk_sel_type.

* objects for loading l_classes_in_workarea-mtk_inarea = 'X'. l_classes_in_workarea-tsk_inarea = 'X'. l_classes_in_workarea-seq_inarea = 'X'. l_classes_in_workarea-opr_inarea = 'X'. l_classes_in_workarea-suo_inarea = 'X'. l_classes_in_workarea-prt_inarea = 'X'.

* fill selection conditions - PLNTY CONCATENATE 'I' 'EQ' i_plnty INTO l_tsk_plnty_selection. APPEND l_tsk_plnty_selection TO lt_tsk_plnty_selection. l_tsk_selection-plnty = lt_tsk_plnty_selection.

CONCATENATE 'I' 'EQ' i_plnnr INTO l_tsk_plnnr_selection. APPEND l_tsk_plnnr_selection TO lt_tsk_plnnr_selection. l_tsk_selection-plnnr = lt_tsk_plnnr_selection.

CONCATENATE 'I' 'EQ' i_plnal INTO l_tsk_plnal_selection. APPEND l_tsk_plnal_selection TO lt_tsk_plnal_selection. l_tsk_selection-plnal = lt_tsk_plnal_selection.

* load objects into EWB CALL FUNCTION 'CP_CC_S_LOAD_COMPLEX_BY_TSK' EXPORTING i_class = 'P' i_classes_in_workarea = l_classes_in_workarea

Page 4: SAP NOTE

1/ 10/ 13 Display sour ce f or cor r ect ion

4/ 9ht t ps: / / websm p230. sap- ag. de/ sap( bD1lbiZjPTAwM Q ==) / bc/ bsp/ spn/ cor r _inst r / cor r ect ion_det ail. ht m ?_…

i_cpsc_tsk_sel = l_tsk_selection i_date_from = i_sttag i_date_to = i_sttag EXCEPTIONS workarea_not_found = 1 workarea_wrong_type = 2 class_in_workarea_inconsistent = 3 workarea_not_specified = 4 opr_not_found = 5 no_selection_criteria = 6 invalid_selection_period = 7 key_date_required_for_ecm = 8 OTHERS = 9.

ENDFORM. " LOAD_TASK_LIST

*---------------------------------------------------------------------** FORM change_task_list **---------------------------------------------------------------------** changes the short text of all operations to* 'SIMPLE_EWB_TEST'*---------------------------------------------------------------------** --> i_sttag keydate **---------------------------------------------------------------------*FORM change_task_list USING i_sttag LIKE plko-datuv.

DATA: lt_opr_class_data LIKE opr_class_data OCCURS 0, l_opr_class_data LIKE opr_class_data, lt_opr_ident TYPE cpcl_opr_tab_type, l_opr_ident TYPE cpcl_opr_type, lt_opr_lock TYPE cpcl_opr_lock_tab_type.

* provide all operations from EWB buffer CALL FUNCTION 'CP_CL_S_OPR_PROVIDE' TABLES e_opr_class_data = lt_opr_class_data EXCEPTIONS wrong_key = 1 OTHERS = 2.

* lock the operations and reload operations LOOP AT lt_opr_class_data INTO l_opr_class_data. MOVE-CORRESPONDING l_opr_class_data TO l_opr_ident. APPEND l_opr_ident TO lt_opr_ident. ENDLOOP. CALL FUNCTION 'CP_CC_S_RELOAD_BY_OPR' EXPORTING i_flg_set_lock = 'X' IMPORTING e_opr_lock = lt_opr_lock CHANGING c_opr_ident = lt_opr_ident EXCEPTIONS reloading_not_allowed = 1 OTHERS = 2.

Page 5: SAP NOTE

1/ 10/ 13 Display sour ce f or cor r ect ion

5/ 9ht t ps: / / websm p230. sap- ag. de/ sap( bD1lbiZjPTAwM Q ==) / bc/ bsp/ spn/ cor r _inst r / cor r ect ion_det ail. ht m ?_…

IF NOT lt_opr_lock[] IS INITIAL. WRITE: /'error: some operations are already locked'. EXIT. ENDIF.

* again: provide all operations from EWB buffer* reason: between first providing and locking another user can can* change the operations CALL FUNCTION 'CP_CL_S_OPR_PROVIDE' TABLES e_opr_class_data = lt_opr_class_data EXCEPTIONS wrong_key = 1 OTHERS = 2.

* change operations LOOP AT lt_opr_class_data INTO l_opr_class_data.

l_opr_class_data-ltxa1 = 'SIMPLE_EWB_TEST'.

CALL FUNCTION 'CP_CL_S_OPR_CHANGE' EXPORTING i_key_date_s = i_sttag i_flg_opr_check = 'X' i_opr_class_data = l_opr_class_data EXCEPTIONS operation_not_consistent = 1 no_authority = 2 wrong_operation_type = 3 no_valid_operation = 4 operation_not_locked = 5 wrong_operation_number = 6 ecm_data_not_suitable = 7 OTHERS = 8.

ENDLOOP.

ENDFORM. " CHANGE_TASK_LIST

*&---------------------------------------------------------------------**& Form SAVE_TO_DATABASE*&---------------------------------------------------------------------** save to database*----------------------------------------------------------------------*FORM save_to_database. CALL FUNCTION 'CP_CC_S_SAVE'.ENDFORM. " SAVE_TO_DATABASE

*&---------------------------------------------------------------------**& Form CREATE_TASK_LIST*&---------------------------------------------------------------------** create a new task list*----------------------------------------------------------------------** --> i_parameter parameter for task list creation*----------------------------------------------------------------------*FORM create_task_list USING

Page 6: SAP NOTE

1/ 10/ 13 Display sour ce f or cor r ect ion

6/ 9ht t ps: / / websm p230. sap- ag. de/ sap( bD1lbiZjPTAwM Q ==) / bc/ bsp/ spn/ cor r _inst r / cor r ect ion_det ail. ht m ?_…

i_parameter TYPE create_parameter_type.

DATA: l_tsk LIKE tsk_class_data, l_opr LIKE opr_class_data, l_vornr(4) TYPE n, l_mtk LIKE mtk_class_data, l_max_vornr(4) TYPE n.

* create task list header* ===============================================

CLEAR l_tsk. l_tsk-plnty = 'N'. "task list type CLEAR l_tsk-plnnr. "task list group "initial because "internal number assignment l_tsk-plnal = '1'. "group counter l_tsk-werks = i_parameter-werks. "plant l_tsk-verwe = i_parameter-verwe. "usage l_tsk-statu = i_parameter-statu. "status l_tsk-plnme = i_parameter-plnme. "base unit

CALL FUNCTION 'CP_CL_S_TSK_CREATE' EXPORTING i_key_date_s = i_parameter-sttag CHANGING c_tsk_class_data = l_tsk EXCEPTIONS task_not_consistent = 1 no_authority = 2 task_type_not_defined = 3 task_not_locked = 4 sequence_std_not_locked = 5 counter_overflow = 6 ident_already_exists = 7 ecm_data_not_suitable = 8 group_number_not_allowed = 9 group_number_not_in_range = 10 number_range_not_exists = 11 OTHERS = 12.

* the standard sequence is automatically created by* cp_cl_s_tsk_create

* material task list allocation* =============================================== l_mtk-plnty = l_tsk-plnty. "task list type l_mtk-plnnr = l_tsk-plnnr. "task list group l_mtk-plnal = l_tsk-plnal. "group counter l_mtk-matnr = i_parameter-matnr. "material l_mtk-werks = i_parameter-werks. "plant

CALL FUNCTION 'CZ_CL_S_MTK_CREATE' EXPORTING i_key_date_s = i_parameter-sttag i_mtk_class_data = l_mtk EXCEPTIONS

Page 7: SAP NOTE

1/ 10/ 13 Display sour ce f or cor r ect ion

7/ 9ht t ps: / / websm p230. sap- ag. de/ sap( bD1lbiZjPTAwM Q ==) / bc/ bsp/ spn/ cor r _inst r / cor r ect ion_det ail. ht m ?_…

allocation_not_consistent = 1 no_authority = 2 no_authority_for_material = 3 task_not_locked = 4 no_valid_material = 5 no_valid_sales_document = 6 counter_overflow = 7 ident_already_exists = 8 no_valid_task = 9 path_incomplete = 10 ecm_data_not_suitable = 11 OTHERS = 12.

* create operations* =============================================== l_vornr = 10. l_max_vornr = 10 * i_parameter-number. WHILE l_vornr <= l_max_vornr.

CLEAR l_opr. l_opr-plnty = l_tsk-plnty. "task list type l_opr-plnnr = l_tsk-plnnr. "task list group l_opr-plnal = l_tsk-plnal. "group counter l_opr-plnfl = '000000'. "standard sequence l_opr-vornr = l_vornr. "operation number l_opr-steus = i_parameter-steus. "control key l_opr-umrez = '1'. "conversion factor l_opr-umren = '1'. "conversion factor l_opr-bmsch = '1'. "base quantity l_opr-meinh = i_parameter-plnme. "unit l_opr-werks = i_parameter-werks. "plant l_opr-datuv = i_parameter-sttag. "keydate

CALL FUNCTION 'CP_CL_S_OPR_CREATE' EXPORTING i_key_date_s = i_parameter-sttag i_opr_class_data = l_opr IMPORTING e_ident = l_opr-ident e_plnkn = l_opr-plnkn e_zaehl = l_opr-zaehl EXCEPTIONS operation_not_consistent = 1 no_authority = 2 operation_not_locked = 3 ident_already_exists = 4 wrong_ident_type = 5 no_valid_sequence = 6 path_incomplete = 7 ecm_data_not_suitable = 8 wrong_operation_type = 9 wrong_operation_number = 10 OTHERS = 11.

* create production resource tool PERFORM create_prt USING

Page 8: SAP NOTE

1/ 10/ 13 Display sour ce f or cor r ect ion

8/ 9ht t ps: / / websm p230. sap- ag. de/ sap( bD1lbiZjPTAwM Q ==) / bc/ bsp/ spn/ cor r _inst r / cor r ect ion_det ail. ht m ?_…

i_parameter l_opr.

l_vornr = l_vornr + 10. ENDWHILE.

WRITE: 'task list group ', l_tsk-plnnr, 'created'.

ENDFORM. " CREATE_TASK_LIST

*&---------------------------------------------------------------------**& Form CREATE_PRT*&---------------------------------------------------------------------** create production resource tool of type material*----------------------------------------------------------------------** -->I_PARAMETER* -->I_OPR operation*----------------------------------------------------------------------*FORM create_prt USING i_parameter TYPE create_parameter_type i_opr LIKE opr_class_data.

DATA l_prt TYPE prt_class_data.

l_prt-plnty = i_opr-plnty. "task list type l_prt-plnnr = i_opr-plnnr. "task list group l_prt-plnal = i_opr-plnal. "group counter l_prt-plnfl = i_opr-plnfl. "sequence l_prt-ident = i_opr-ident. "ewb-ident l_prt-plnkn = i_opr-plnkn. "operation node l_prt-steuf = i_parameter-steuf. "control key of prt l_prt-psnfh = '0010'. "position number prt l_prt-mgeinh = i_parameter-plnme. "base quantity l_prt-mgvgw = '1'. "quantity l_prt-fhmnr = i_parameter-fhmat. "material number prt l_prt-fhwrk = i_parameter-werks. "plant l_prt-matnr = i_parameter-fhmat. "material number prt l_prt-fhmar = 'M'. "type of prt M=material l_prt-objct = 'O'. "prt allocated to operation = O

* --------------------------------------------------------* start - only for release 46B DATA l_rcfky LIKE rcfky.* get objid for prt l_rcfky-fhwrk = l_prt-fhwrk. l_rcfky-matnr = l_prt-matnr. CALL FUNCTION 'CF_DB_CRVP_B_READ' EXPORTING fhmar_imp = 'M' rcfky_imp = l_rcfky IMPORTING objid_exp = l_prt-objid objty_exp = l_prt-objty EXCEPTIONS not_found_fhm = 01.

Page 9: SAP NOTE

1/ 10/ 13 Display sour ce f or cor r ect ion

9/ 9ht t ps: / / websm p230. sap- ag. de/ sap( bD1lbiZjPTAwM Q ==) / bc/ bsp/ spn/ cor r _inst r / cor r ect ion_det ail. ht m ?_…

* end - only for release 46B* --------------------------------------------------------

CALL FUNCTION 'CF_CL_S_PRT_CREATE' EXPORTING i_key_date_s = i_opr-datuv i_prt_class_data = l_prt EXCEPTIONS prt_not_consistent = 1 no_authority = 2 operation_not_locked = 3 counter_overflow = 4 no_valid_operation = 5 path_incomplete = 6 ecm_data_not_suitable = 7 link_to_ref_set_of_opr = 8 link_to_wc_ref_set_of_opr = 9 OTHERS = 10.

ENDFORM. " CREATE_PRT

Delete Block

Insert Block

Print