SAP PM BAPI HOJARUTA
From SapWiki
Leer Hoja de Ruta de Equipo (IA01)
FORM select_data. DATA ld_lines_o TYPE i. DATA ld_lines_m TYPE i. * data para puesto de trabajo (ARBPL) SELECT DISTINCT objid arbpl FROM crhd INTO TABLE lt_crhd FOR ALL ENTRIES IN gt_plpo WHERE objid = gt_plpo-arbid. SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_eapl FROM eapl WHERE iwerk = p_werks AND equnr IN s_equnr AND plnty = p_plnty AND loekz <> 'X'. CLEAR: gt_plko[], gt_plpo[], gt_plmk[]. DESCRIBE TABLE gt_eapl LINES lin. LOOP AT gt_eapl INTO gs_eapl. succ = 100 / lin * sy-tabix. CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = succ text = text-001. gs_data_h-code = '1'. gs_data_h-equnr = gs_eapl-equnr. gs_data_h-werks = gs_eapl-iwerk. gs_data_h-plnal = gs_eapl-plnal. CALL FUNCTION 'CP_EX_PLAN_READ' EXPORTING plnty_imp = gs_eapl-plnty plnnr_imp = gs_eapl-plnnr plnal_imp = gs_eapl-plnal sttag_imp = sy-datum TABLES plko_exp = gt_plko plmz_exp = gt_plmz plpo_exp = gt_plpo pltx_exp = gt_pltxd plmk_exp = gt_plmk EXCEPTIONS not_found = 1 plnal_initial = 2 OTHERS = 3 . IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. LOOP AT gt_plko INTO gs_plko WHERE plnty = gs_eapl-plnty AND plnnr = gs_eapl-plnnr AND plnal = gs_eapl-plnal. gs_data_h-sttag = gs_plko-datuv. gs_data_h-ktext = gs_plko-ktext. gs_data_h-werks = gs_plko-werks. READ TABLE lt_crhd INTO ls_crhd WITH KEY objid = gs_plko-arbid. IF sy-subrc = 0. gs_data_h-arbpl = ls_crhd-arbpl. ENDIF. gs_data_h-verwe = gs_plko-verwe. gs_data_h-vagrp = gs_plko-vagrp. gs_data_h-statu = gs_plko-statu. gs_data_h-anlzu = gs_plko-anlzu. gs_data_h-strat = gs_plko-strat. gs_data_h-istru = gs_plko-istru. PERFORM set_nuevos_valores_h. APPEND gs_data_h TO gt_salida. DATA ls_stpo TYPE stpo. DATA gt_stpo TYPE TABLE OF stpo. DATA gt_plwp TYPE TABLE OF plwp. DATA gs_stpo LIKE LINE OF gt_stpo. DATA gs_plwp LIKE LINE OF gt_plwp. DATA ld_equi(8) TYPE n. DATA ld_name LIKE thead-tdname. DATA lt_lines LIKE TABLE OF tline. DATA ls_lines LIKE LINE OF lt_lines. ld_equi = gs_eapl-equnr. LOOP AT gt_plpo INTO gs_plpo. CLEAR: gt_stpo[], gt_plwp[]. gs_data_d-code = '2'. MOVE-CORRESPONDING gs_plpo TO gs_data_d. READ TABLE lt_crhd INTO ls_crhd WITH KEY objid = gs_plpo-arbid. IF sy-subrc = 0. gs_data_d-arbpl = ls_crhd-arbpl. ENDIF. PERFORM set_nuevos_valores_d. APPEND gs_data_d TO gt_salida. ENDLOOP. "operaciones ENDLOOP. "grupo hoja ruta ENDLOOP. "EAPL ==Leer Hoja de Ruta Materiales (CA01)== <nowiki>FORM select_data. DATA: BEGIN OF lt_hoja, plnnr LIKE mapl-plnnr, werks LIKE mapl-werks, matnr LIKE mapl-matnr, END OF lt_hoja. DATA ld_lines_o TYPE i. DATA ld_lines_m TYPE i. SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_mapl FROM mapl WHERE werks = p_werks AND matnr IN s_matnr AND plnty = p_plnty AND loekz <> 'X'. CLEAR: gt_plko[], gt_plpo[], gt_plmk[]. DESCRIBE TABLE gt_mapl LINES lin. LOOP AT gt_mapl INTO gs_mapl. succ = 100 / lin * sy-tabix. CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = succ text = text-001. CLEAR gs_data. gs_data-datuv = gs_mapl-datuv. gs_data-material = gs_mapl-matnr. gs_data-plant = gs_mapl-werks. gs_data-task_list_group = gs_mapl-plnnr. gs_data-group_counter = gs_mapl-plnal. CALL FUNCTION 'CP_EX_PLAN_READ' EXPORTING plnty_imp = gs_mapl-plnty plnnr_imp = gs_mapl-plnnr plnal_imp = gs_mapl-plnal sttag_imp = sy-datum TABLES plko_exp = gt_plko = plpo_exp = gt_plpo plmk_exp = gt_plmk EXCEPTIONS not_found = 1 plnal_initial = 2 OTHERS = 3 . IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. LOOP AT gt_plko INTO gs_plko WHERE plnty = gs_mapl-plnty AND plnnr = gs_mapl-plnnr AND plnal = gs_mapl-plnal. gs_data-ident_key = gs_plko-slwbez. gs_data-insppoint_partiallot_assgnmt = gs_plko-ppkztlzu. gs_data-dyn_modif_level = gs_plko-qdynhead. gs_data-dyn_modif_rule = gs_plko-qdynregel. gs_data-quantonce = gs_plko-ppkztlzu. gs_data-task_measure_unit = gs_plko-plnme. ENDLOOP. "PLKO ENDLOOP. "MAPL LOOP AT gt_data INTO gs_data. MOVE gs_data-task_list_group TO gs_data_o-group. MOVE gs_data-group_counter TO gs_data_o-grcnt. MOVE gs_data-datuv TO gs_data_o-date. MOVE gs_data-ident_key TO gs_data_o-insp_point. MOVE gs_data-quantonce TO gs_data_o-part_lot. MOVE gs_data-dyn_modif_level TO gs_data_o-dm_level. MOVE gs_data-dyn_modif_rule TO gs_data_o-dm_rule. APPEND gs_data_o TO gt_data_o. ENDLOOP. ENDFORM. "select_data