Friday, September 23, 2011

Purchase Requisition Status Report

This report is developed to get the current status of the PRs..This might be helpful for the similar requirement. REPORT z_0000__2_1_3_1___0003. *Include for Data declaration INCLUDE z_0000__2_1_3_1___0003_top. *Include for selection screen INCLUDE z_0000__2_1_3_1___0003_scr. *Include for Calculations INCLUDE z_0000__2_1_3_1___0003_f01. *----------------------------------------------------------------------* * Initialization * *----------------------------------------------------------------------* INITIALIZATION. PERFORM refresh_data. *----------------------------------------------------------------------* * Start of selection * *----------------------------------------------------------------------* START-OF-SELECTION. * Fetching the required Data PERFORM fetch_data. *Build Output internal table PERFORM build_output. **Build Layout PERFORM build_layout. *Build Field catalog. PERFORM build_field_catalog. *----------------------------------------------------------------------* * End of selection * *----------------------------------------------------------------------* END-OF-SELECTION. IF t_output[] IS INITIAL. MESSAGE text-001 TYPE 'I'. ELSE. *Display report output PERFORM display_alv. ENDIF. *&---------------------------------------------------------------------* *& Include Z_0000__2_1_3_1___0003_TOP *&---------------------------------------------------------------------* *Declaration of Tables TYPE-POOLS : slis. TABLES: eban, ebkn, lfa1. *Declaration of Struture TYPES: BEGIN OF x_eban, banfn LIKE eban-banfn, bnfpo LIKE eban-bnfpo , statu LIKE eban-statu , frgkz LIKE eban-frgkz , frgzu like eban-frgzu , frgst LIKE eban-frgst, ekgrp LIKE eban-ekgrp , ernam LIKE eban-ernam , afnam LIKE eban-afnam , TXZ01 like eban-TXZ01 , matnr LIKE eban-matnr , werks LIKE eban-werks , menge LIKE eban-menge , meins LIKE eban-meins , badat LIKE eban-badat , lfdat LIKE eban-lfdat , preis LIKE eban-preis, "Price in Purchase Requisition peinh LIKE eban-peinh, "Price Unit knttp LIKE eban-knttp , lifnr LIKE eban-lifnr , flief LIKE eban-flief , ebeln LIKE eban-ebeln, ebelp LIKE eban-ebelp , frggr LIKE eban-frggr, "release group waers LIKE eban-waers , rlwrt LIKE eban-rlwrt , kostl LIKE ebkn-kostl, aufnr LIKE ebkn-aufnr, END OF x_eban. TYPES: BEGIN OF x_lfa1, lifnr LIKE lfa1-lifnr, name1 LIKE lfa1-name1, END OF x_lfa1. TYPES : BEGIN OF x_t16fv, frggr LIKE t16fv-frggr, frgsx LIKE t16fv-frgsx, frgco LIKE t16fv-frgco, frgct LIKE t16fd-frgct, END OF x_t16fv. DATA : t_eban TYPE STANDARD TABLE OF x_eban WITH HEADER LINE . DATA : BEGIN OF t_output OCCURS 0, ernam LIKE eban-ernam , "Created By badat LIKE eban-badat , "Created On banfn LIKE eban-banfn, "PR bnfpo LIKE eban-bnfpo , "Item matnr LIKE eban-matnr , "Material maktx LIKE makt-maktx, "Material Description knttp LIKE eban-knttp , "A/c Assignment kostl LIKE ebkn-kostl, "Cost Centre aufnr LIKE ebkn-aufnr, "Order menge LIKE eban-menge , "Quantity meins LIKE eban-meins , "UOM rlwrt LIKE eban-rlwrt , "Total Value of Item waers LIKE eban-waers , "Curency lfdat LIKE eban-lfdat , "Delivery date werks LIKE eban-werks , "Plant ekgrp LIKE eban-ekgrp , "Purchasing group afnam LIKE eban-afnam , "Requisitioner * lifnr LIKE eban-lifnr , "Vendor * flief LIKE eban-flief , "Vendor flief LIKE lfa1-lifnr , "Vendor name1 LIKE lfa1-name1, "Vendor name approved1 LIKE adrp-name_text, approved2 LIKE adrp-name_text, approved3 LIKE adrp-name_text, approved4 LIKE adrp-name_text, approved5 LIKE adrp-name_text, approved6 LIKE adrp-name_text, approved7 LIKE adrp-name_text, approved8 LIKE adrp-name_text, appr1 LIKE t16fd-frgct, "Next approver1 appr2 LIKE t16fd-frgct, "Next approver2 appr3 LIKE t16fd-frgct, "Next approver3 appr4 LIKE t16fd-frgct, "Next approver4 appr5 LIKE t16fd-frgct, "Next approver5 appr6 LIKE t16fd-frgct, "Next approver6 appr7 LIKE t16fd-frgct, "Next approver7 appr8 LIKE t16fd-frgct, "Next approver8 ebeln LIKE eban-ebeln, "PO ebelp LIKE eban-ebelp , "PO Item END OF t_output. TYPES : BEGIN OF x_cdhdr, objectclas LIKE cdhdr-objectclas, objectid LIKE cdhdr-objectid, changenr LIKE cdhdr-changenr, username LIKE cdhdr-username, tcode LIKE cdhdr-tcode, END OF x_cdhdr. TYPES : BEGIN OF x_cdpos, objectclas LIKE cdpos-objectclas, objectid LIKE cdpos-objectid, changenr LIKE cdpos-changenr, tabkey LIKE cdpos-tabkey, END OF x_cdpos. DATA : t_cdhdr TYPE STANDARD TABLE OF x_cdhdr, t_cdpos TYPE STANDARD TABLE OF x_cdpos, wa_cdhdr TYPE x_cdhdr, l_objid LIKE cdhdr-objectid, wa_address TYPE bapiaddr3, l_tabix TYPE sy-tabix, l_frgkx LIKE t16fk-frgkx. DATA : t_lfa1 TYPE STANDARD TABLE OF x_lfa1, t_t16fv TYPE STANDARD TABLE OF x_t16fv, t_t16fv1 TYPE STANDARD TABLE OF x_t16fv, wa_eban TYPE x_eban, wa_lfa1 TYPE x_lfa1, wa_t16fv TYPE x_t16fv. DATA: BEGIN OF t_posted OCCURS 1. INCLUDE STRUCTURE bapirlcorq. DATA: END OF t_posted. DATA: BEGIN OF t_general OCCURS 1. INCLUDE STRUCTURE bapirlgnrq. DATA: END OF t_general. *Field catalog data declaration DATA : g_repid LIKE sy-repid, t_fieldcat TYPE slis_t_fieldcat_alv, wa_fieldcat LIKE LINE OF t_fieldcat, gs_layout TYPE slis_layout_alv. *Global data declaration for Flag DATA : g_flag1 TYPE c, g_flag2 type c, g_flag3 type c, g_flag4 type c, g_flag5 type c, g_flag6 type c, g_flag7 type c, g_flag8 type c, g_flag9 type c, g_flag10 type c, g_flag11 type c, g_flag12 type c, g_flag13 type c, g_flag14 type c, g_flag15 type c, g_flag16 type c. *&---------------------------------------------------------------------* *& Include Z_0000__2_1_3_1___0003_SCR *&---------------------------------------------------------------------* SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME. SELECT-OPTIONS: s_banfn FOR eban-banfn , "Purchase Requisition Number s_matnr FOR eban-matnr, "Material Number s_werks FOR eban-werks, "Plant s_lifnr FOR eban-lifnr, "Vendor s_ekgrp FOR eban-ekgrp, "Purchasing Group s_badat FOR eban-badat, "Requisition (Request) Date s_ernam FOR eban-ernam DEFAULT sy-uname, "Name of Person who Created the Object s_knttp FOR eban-knttp, "Account Assignment Category s_kostl FOR ebkn-kostl, "Cost Center s_aufnr FOR ebkn-aufnr, "Order Number s_lfdat FOR eban-lfdat, "Item Delivery Date s_statu FOR eban-statu. "Processing status of purchase requisition SELECTION-SCREEN END OF BLOCK b1 . *&---------------------------------------------------------------------* *& Include Z_0000__2_1_3_1___0003_F01 *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form FETCH_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM fetch_data . DATA l_count TYPE n. *Select Header Data SELECT a~banfn a~bnfpo a~statu a~frgkz a~frgzu a~frgst a~ekgrp a~ernam a~afnam a~txz01 a~matnr a~werks a~menge a~meins a~badat a~lfdat a~preis a~peinh a~knttp a~lifnr a~flief a~ebeln a~ebelp a~frggr a~waers a~rlwrt k~kostl k~aufnr INTO CORRESPONDING FIELDS OF TABLE t_eban FROM eban AS a INNER JOIN ebkn AS k ON k~banfn = a~banfn AND k~bnfpo = a~bnfpo WHERE a~banfn IN s_banfn AND a~matnr IN s_matnr AND a~werks IN s_werks AND a~lifnr IN s_lifnr AND a~ekgrp IN s_ekgrp AND a~badat IN s_badat AND a~ernam IN s_ernam AND a~knttp IN s_knttp AND a~statu IN s_statu AND k~kostl IN s_kostl AND k~aufnr IN s_aufnr AND a~lfdat IN s_lfdat. *Select Vendor names SELECT lifnr name1 INTO TABLE t_lfa1 FROM lfa1 FOR ALL ENTRIES IN t_eban WHERE lifnr = t_eban-lifnr OR lifnr = t_eban-flief. IF sy-subrc EQ 0. SORT t_lfa1 BY lifnr. DELETE ADJACENT DUPLICATES FROM t_lfa1. ENDIF. SORT t_eban BY banfn bnfpo. ENDFORM. " FETCH_DATA *&---------------------------------------------------------------------* *& Form BUILD_FIELD_CATALOG *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM build_field_catalog . CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING i_program_name = g_repid i_internal_tabname = 'T_OUTPUT' i_inclname = g_repid CHANGING ct_fieldcat = t_fieldcat EXCEPTIONS inconsistent_interface = 1 program_error = 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 t_fieldcat INTO wa_fieldcat. CASE wa_fieldcat-fieldname. WHEN 'BADAT'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-002. MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'NAME1'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-003. MODIFY t_fieldcat FROM wa_fieldcat. * WHEN 'FRGCT'. * wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = * wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic * = text-004. * MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'EBELP'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-005. MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'RLWRT'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-006. MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'APPR1'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-007. IF g_flag9 IS INITIAL. wa_fieldcat-no_out = 'X'. ENDIF. MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'APPR2'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-007. IF g_flag10 IS INITIAL. wa_fieldcat-no_out = 'X'. ENDIF. MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'APPR3'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-007. IF g_flag11 IS INITIAL. wa_fieldcat-no_out = 'X'. ENDIF. MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'APPR4'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-007. IF g_flag12 IS INITIAL. wa_fieldcat-no_out = 'X'. ENDIF. MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'APPR5'.. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-007. IF g_flag13 IS INITIAL. wa_fieldcat-no_out = 'X'. ENDIF. MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'APPR6'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-007. IF g_flag14 IS INITIAL. wa_fieldcat-no_out = 'X'. ENDIF. MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'APPR7'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-007. IF g_flag15 IS INITIAL. wa_fieldcat-no_out = 'X'. ENDIF. MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'APPR8'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-007. IF g_flag16 IS INITIAL. wa_fieldcat-no_out = 'X'. ENDIF. MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'APPROVED1'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-008. IF g_flag1 IS INITIAL. wa_fieldcat-no_out = 'X'. ENDIF. MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'APPROVED2'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-008. IF g_flag2 IS INITIAL. wa_fieldcat-no_out = 'X'. ENDIF. MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'APPROVED3'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-008. IF g_flag3 IS INITIAL. wa_fieldcat-no_out = 'X'. ENDIF. MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'APPROVED4'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-008. IF g_flag4 IS INITIAL. wa_fieldcat-no_out = 'X'. ENDIF. MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'APPROVED5'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-008. IF g_flag5 IS INITIAL. wa_fieldcat-no_out = 'X'. ENDIF. MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'APPROVED6'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-008. IF g_flag6 IS INITIAL. wa_fieldcat-no_out = 'X'. ENDIF. MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'APPROVED7'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-008. IF g_flag7 IS INITIAL. wa_fieldcat-no_out = 'X'. ENDIF. MODIFY t_fieldcat FROM wa_fieldcat. WHEN 'APPROVED8'. wa_fieldcat-seltext_s = wa_fieldcat-seltext_m = wa_fieldcat-seltext_l = wa_fieldcat-reptext_ddic = text-008. IF g_flag8 IS INITIAL. wa_fieldcat-no_out = 'X'. ENDIF. MODIFY t_fieldcat FROM wa_fieldcat. ENDCASE. ENDLOOP. ENDFORM. " BUILD_FIELD_CATALOG *&---------------------------------------------------------------------* *& Form DISPLAY_ALV *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM display_alv . CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING * I_INTERFACE_CHECK = ' ' * I_BYPASSING_BUFFER = ' ' * I_BUFFER_ACTIVE = ' ' i_callback_program = g_repid * I_CALLBACK_PF_STATUS_SET = ' ' i_callback_user_command = 'USER_COMMAND' * I_CALLBACK_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_END_OF_LIST = ' ' * I_STRUCTURE_NAME = * I_BACKGROUND_ID = ' ' * I_GRID_TITLE = * I_GRID_SETTINGS = is_layout = gs_layout it_fieldcat = t_fieldcat[] * IT_EXCLUDING = * IT_SPECIAL_GROUPS = * IT_SORT = * IT_FILTER = * IS_SEL_HIDE = * I_DEFAULT = 'X' * I_SAVE = ' ' * IS_VARIANT = * IT_EVENTS = * IT_EVENT_EXIT = * IS_PRINT = * IS_REPREP_ID = * I_SCREEN_START_COLUMN = 0 * I_SCREEN_START_LINE = 0 * I_SCREEN_END_COLUMN = 0 * I_SCREEN_END_LINE = 0 * I_HTML_HEIGHT_TOP = 0 * I_HTML_HEIGHT_END = 0 * IT_ALV_GRAPHICS = * IT_HYPERLINK = * IT_ADD_FIELDCAT = * IT_EXCEPT_QINFO = * IR_SALV_FULLSCREEN_ADAPTER = * IMPORTING * E_EXIT_CAUSED_BY_CALLER = * ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = t_output EXCEPTIONS program_error = 1 OTHERS = 2 . IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. ENDFORM. " DISPLAY_ALV *&---------------------------------------------------------------------* *& Form BUILD_LAYOUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM build_layout . * ls_layout-f2code = p_f2code. * ls_layout-zebra = p_zebra. gs_layout-zebra = 'X'. gs_layout-colwidth_optimize = 'X'. * ls_layout-cell_merge = p_merge. * ls_layout-no_input = p_noinpt. * ls_layout-no_vline = p_novlin. * ls_layout-no_colhead = p_nocolh. * ls_layout-lights_condense = p_lightc. * gs_layout-totals_text = 'X'. * ls_layout-subtotals_text = p_sttext. * ls_layout-totals_only = p_totonl. * ls_layout-key_hotspot = p_keyhot. * ls_layout-detail_popup = p_detpop. * ls_layout-group_change_edit = p_groups. * ls_layout-group_buttons = space. ENDFORM. " BUILD_LAYOUT *&---------------------------------------------------------------------* *& Form REFRESH_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM refresh_data . REFRESH : t_output, t_eban, t_lfa1, * t_makt, t_t16fv. CLEAR : wa_eban, wa_lfa1, * wa_makt, wa_t16fv. g_repid = sy-repid. ENDFORM. " REFRESH_DATA *User command. *Display the ME53N tcode whenever any PO is double clicked on report *output FORM user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield . IF rs_selfield-fieldname = 'BANFN'. READ TABLE t_output INDEX rs_selfield-tabindex. SET PARAMETER ID 'BAN' FIELD t_output-banfn. CALL TRANSACTION 'ME53N' AND SKIP FIRST SCREEN. ENDIF. ENDFORM. " USER_COMMAND *&---------------------------------------------------------------------* *& Form BUILD_OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM build_output . DATA l_tabix TYPE sy-tabix. *Build Output internal table. LOOP AT t_eban INTO wa_eban. t_output-ernam = wa_eban-ernam . "Created By t_output-badat = wa_eban-badat . "Created On t_output-banfn = wa_eban-banfn. "PR t_output-bnfpo = wa_eban-bnfpo . "Item t_output-matnr = wa_eban-matnr . "Material t_output-maktx = wa_eban-txz01 . "Material Description t_output-knttp = wa_eban-knttp . "A/c Assignment t_output-kostl = wa_eban-kostl. "Total Value of Item t_output-aufnr = wa_eban-aufnr. "Order t_output-menge = wa_eban-menge . "Quantity t_output-meins = wa_eban-meins . "UOM IF wa_eban-rlwrt IS NOT INITIAL. t_output-rlwrt = wa_eban-rlwrt . ELSEIF wa_eban-peinh = 1. t_output-rlwrt = wa_eban-preis * wa_eban-menge. ELSEIF wa_eban-peinh GT 1. wa_eban-preis = wa_eban-preis / wa_eban-peinh. t_output-rlwrt = wa_eban-preis * wa_eban-menge. ENDIF. t_output-waers = wa_eban-waers . "Curency t_output-lfdat = wa_eban-lfdat . "Delivery date t_output-werks = wa_eban-werks . "Plant t_output-ekgrp = wa_eban-ekgrp . "Purchasing group t_output-afnam = wa_eban-afnam . "Requisitioner IF wa_eban-flief IS NOT INITIAL. t_output-flief = wa_eban-flief . "Vendor READ TABLE t_lfa1 INTO wa_lfa1 WITH KEY lifnr = wa_eban-flief. IF sy-subrc EQ 0. t_output-name1 = wa_lfa1-name1. "Vendor name ENDIF. ELSE. t_output-flief = wa_eban-lifnr . "Vendor READ TABLE t_lfa1 INTO wa_lfa1 WITH KEY lifnr = wa_eban-lifnr. IF sy-subrc EQ 0. t_output-name1 = wa_lfa1-name1. "Vendor name ENDIF. ENDIF. t_output-ebeln = wa_eban-ebeln. "PO t_output-ebelp = wa_eban-ebelp . "PO Item *Begin of for approver names *Select Approved by names l_objid = wa_eban-banfn. *Check Release indicator for Approved by names IF ( wa_eban-frgkz = 'Z' OR wa_eban-frgkz = '2' OR wa_eban-frgkz = 'Y' ). SELECT objectclas objectid changenr username tcode FROM cdhdr INTO CORRESPONDING FIELDS OF TABLE t_cdhdr WHERE objectclas = 'BANF' AND objectid = l_objid AND ( tcode = 'ME54N' OR tcode = 'ME55N' OR tcode = 'ME54' OR tcode = 'ME55'). IF sy-subrc EQ 0. "Begin If for Approved by SELECT objectclas objectid changenr FROM cdpos INTO CORRESPONDING FIELDS OF TABLE t_cdpos FOR ALL ENTRIES IN t_cdhdr WHERE objectclas = t_cdhdr-objectclas AND objectid = t_cdhdr-objectid AND changenr = t_cdhdr-changenr. IF sy-subrc EQ 0. DATA l_username LIKE adrp-name_text. LOOP AT t_cdhdr INTO wa_cdhdr. l_tabix = sy-tabix. *Get Full name of Approved by PERFORM get_user_name USING wa_cdhdr-username CHANGING l_username. CASE l_tabix. WHEN '1'. t_output-approved1 = l_username. g_flag1 = 1. WHEN '2'. t_output-approved2 = l_username. g_flag2 = 1. WHEN '3'. t_output-approved3 = l_username. g_flag3 = 1. WHEN '4'. t_output-approved4 = l_username. g_flag4 = 1. WHEN '5'. t_output-approved5 = l_username. g_flag5 = 1. WHEN '6'. t_output-approved6 = l_username. g_flag6 = 1. WHEN '7'. t_output-approved7 = l_username. g_flag7 = 1. WHEN '8'. t_output-approved8 = l_username. g_flag8 = 1. ENDCASE. CLEAR l_tabix. ENDLOOP. ENDIF. ENDIF. "End of IF for Approved by ELSE. ENDIF. *Select Next approver names *Check PR is Released or not IF ( wa_eban-frgkz = 'Z' OR wa_eban-frgkz = '2' ). "Begin of IF for Next Approver APPEND t_output. CLEAR : wa_eban, wa_lfa1, wa_t16fv, t_output, t_t16fv1. ELSE. *Select Release code. REFRESH t_t16fv. CLEAR wa_t16fv. SELECT v~frggr v~frgsx v~frgco d~frgct FROM t16fv AS v INNER JOIN t16fd AS d ON d~frggr = v~frggr AND d~frgco = v~frgco INTO TABLE t_t16fv WHERE v~frggr = wa_eban-frggr AND v~frgsx = wa_eban-frgst AND d~spras = sy-langu. IF sy-subrc EQ 0. SORT t_t16fv BY frggr frgsx frgco. DELETE ADJACENT DUPLICATES FROM t_t16fv. *Applying BAPI to get Approver names. CALL FUNCTION 'BAPI_REQUISITION_GETRELINFO' EXPORTING number = wa_eban-banfn item = wa_eban-bnfpo * REL_CODE = TABLES general_release_info = t_general * release_prerequisites = r_prereq release_already_posted = t_posted * release_final = r_final * RETURN = . LOOP AT t_t16fv INTO wa_t16fv WHERE frggr = wa_eban-frggr AND frgsx = wa_eban-frgst. READ TABLE t_posted WITH KEY rel_code1 = wa_t16fv-frgco. IF sy-subrc EQ 0. APPEND wa_t16fv TO t_t16fv1. DELETE t_t16fv. ELSEIF sy-subrc NE 0. READ TABLE t_posted WITH KEY rel_code2 = wa_t16fv-frgco. IF sy-subrc EQ 0. APPEND wa_t16fv TO t_t16fv1. DELETE t_t16fv. ELSEIF sy-subrc NE 0. READ TABLE t_posted WITH KEY rel_code3 = wa_t16fv-frgco. IF sy-subrc EQ 0. APPEND wa_t16fv TO t_t16fv1. DELETE t_t16fv. ELSEIF sy-subrc NE 0. READ TABLE t_posted WITH KEY rel_code4 = wa_t16fv-frgco. IF sy-subrc EQ 0. APPEND wa_t16fv TO t_t16fv1. DELETE t_t16fv. ELSEIF sy-subrc NE 0. READ TABLE t_posted WITH KEY rel_code5 = wa_t16fv-frgco. IF sy-subrc EQ 0. IF sy-subrc EQ 0. APPEND wa_t16fv TO t_t16fv1. DELETE t_t16fv. ELSEIF sy-subrc NE 0. READ TABLE t_posted WITH KEY rel_code6 = wa_t16fv-frgco. IF sy-subrc EQ 0. IF sy-subrc EQ 0. APPEND wa_t16fv TO t_t16fv1. DELETE t_t16fv. ELSEIF sy-subrc NE 0. READ TABLE t_posted WITH KEY rel_code7 = wa_t16fv-frgco. IF sy-subrc EQ 0. IF sy-subrc EQ 0. APPEND wa_t16fv TO t_t16fv1. DELETE t_t16fv. ELSEIF sy-subrc NE 0. READ TABLE t_posted WITH KEY rel_code8 = wa_t16fv-frgco. IF sy-subrc EQ 0. APPEND wa_t16fv TO t_t16fv1. DELETE t_t16fv. ENDIF. ENDIF. ENDIF. ENDIF. ENDIF. ENDIF. ENDIF. ENDIF. ENDIF. ENDIF. ENDIF. ENDLOOP. CLEAR wa_t16fv. LOOP AT t_t16fv INTO wa_t16fv. CASE sy-tabix . WHEN '1'. t_output-appr1 = wa_t16fv-frgco. g_flag9 = 1. WHEN '2'. t_output-appr2 = wa_t16fv-frgco. g_flag10 = 1. WHEN '3'. t_output-appr3 = wa_t16fv-frgco. g_flag11 = 1. WHEN '4'. t_output-appr4 = wa_t16fv-frgco. g_flag12 = 1. WHEN '5'. t_output-appr5 = wa_t16fv-frgco. g_flag13 = 1. WHEN '6'. t_output-appr6 = wa_t16fv-frgco. g_flag14 = 1. WHEN '7'. t_output-appr7 = wa_t16fv-frgco. g_flag15 = 1. WHEN '8'. t_output-appr8 = wa_t16fv-frgco. g_flag16 = 1. ENDCASE. ENDLOOP. APPEND t_output. CLEAR : wa_eban, wa_lfa1, wa_t16fv, t_output, t_t16fv1. ELSE. APPEND t_output. CLEAR : wa_eban, wa_lfa1, wa_t16fv, t_output, t_t16fv1. ENDIF. *End of for approver names ENDIF. "End of IF for Next Approver ENDLOOP. ENDFORM. " BUILD_OUTPUT *&---------------------------------------------------------------------* *& Form GET_USER_NAME *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_WA_CDHDR_USERNAME text * <--P_L_USERNAME text *----------------------------------------------------------------------* FORM get_user_name USING p_userid CHANGING p_username. DATA address TYPE bapiaddr3. DATA BEGIN OF return OCCURS 0. INCLUDE TYPE bapiret2. DATA END OF return. CALL FUNCTION 'BAPI_USER_GET_DETAIL' EXPORTING username = p_userid IMPORTING address = address TABLES return = return. IF address-fullname IS NOT INITIAL. p_username = address-fullname. ELSE. p_username = p_userid. ENDIF. ENDFORM. " GET_USER_NAME

No comments:

Post a Comment