Friday, September 23, 2011

Report on Open and Shipped Orders

This report provides the information about Open orders and Shipped Orders.
REPORT z_0000__1_3_1_1___0023. *Include for Data declaration INCLUDE z_0000__1_3_1_1___0023_top. *Include for selection screen INCLUDE z_0000__1_3_1_1___0023_scr. *Include for Calculations INCLUDE z_0000__1_3_1_1___0023_f01. *----------------------------------------------------------------------* * Initialization * *----------------------------------------------------------------------* INITIALIZATION. PERFORM refresh_data. *----------------------------------------------------------------------* * Start of selection * *----------------------------------------------------------------------* START-OF-SELECTION. * Fetching the required Data PERFORM fetch_data. *Build Field catalog. PERFORM build_field_catalog. *----------------------------------------------------------------------* * End of selection * *----------------------------------------------------------------------* END-OF-SELECTION. IF t_output IS NOT INITIAL. *Display report output PERFORM display_alv. ELSE. MESSAGE 'No data found' TYPE 'I'. ENDIF. *&---------------------------------------------------------------------* *& Include Z_0000__1_3_1_1___0023_TOP *&---------------------------------------------------------------------* TYPE-POOLS: slis. *----------------------------------------------------------------------* * Table-declaration * *----------------------------------------------------------------------* TABLES: vbrk,vbak,likp,lips,vbap,kna1,knvv. *----------------------------------------------------------------------* * Structure declaration * *----------------------------------------------------------------------* TYPES : BEGIN OF x_vbak, vbeln LIKE vbak-vbeln, END OF x_vbak. TYPES : BEGIN OF x_vbap, vbeln LIKE vbak-vbeln, "Sales document kunnr LIKE vbak-kunnr, "Sold-to-Party * kvgr4 LIKE vbak-kvgr4, "Cust Grp A kdgrp LIKE knvv-kdgrp, "Cust Group posnr LIKE vbap-posnr, "Sales Document Item matnr LIKE vbap-matnr, "Material Number arktx LIKE vbap-arktx, "Product description kwmeng LIKE vbap-kwmeng, "Cumulative Order Quantity in Sales Units werks LIKE vbap-werks, "Plant netwr LIKE vbap-netwr, "Total Value Sales order line END OF x_vbap. TYPES : BEGIN OF x_lips, vbeln LIKE likp-vbeln, lfdat LIKE likp-lfdat, wadat_ist LIKE likp-wadat_ist, posnr LIKE lips-posnr, lfimg LIKE lips-lfimg, END OF x_lips. TYPES : BEGIN OF x_kna1, kunnr LIKE kna1-kunnr, name1 LIKE kna1-name1, END OF x_kna1. TYPES : BEGIN OF x_vbfa, vbelv LIKE vbfa-vbelv, posnv LIKE vbfa-posnv, vbeln LIKE vbfa-vbeln, posnn LIKE vbfa-posnn, vbtyp_n LIKE vbfa-vbtyp_n, matnr LIKE vbfa-matnr, rfmng LIKE vbfa-rfmng, END OF x_vbfa. TYPES : BEGIN OF x_output, kunnr LIKE vbak-kunnr, name1 LIKE kna1-name1, vbeln LIKE vbak-vbeln, arktx LIKE vbap-arktx, kwmeng LIKE vbap-kwmeng, netwr LIKE vbap-netwr, "Inserted Ver 03.00 lfimg LIKE lips-lfimg, wadat_ist LIKE likp-wadat_ist, open_unit LIKE vbap-kwmeng, mbdat like vbep-mbdat, END OF x_output. TYPES: BEGIN OF x_vbep, vbeln LIKE vbep-vbeln, posnr LIKE vbep-posnr, etenr LIKE vbep-etenr, mbdat LIKE vbep-mbdat, END OF x_vbep. *----------------------------------------------------------------------* * Internal table declaration * *----------------------------------------------------------------------* DATA : t_vbak TYPE STANDARD TABLE OF x_vbak, t_vbap TYPE STANDARD TABLE OF x_vbap, t_lips TYPE STANDARD TABLE OF x_lips, t_kna1 TYPE STANDARD TABLE OF x_kna1, t_vbfa TYPE STANDARD TABLE OF x_vbfa, t_output TYPE STANDARD TABLE OF x_output, t_fieldcat TYPE TABLE OF slis_fieldcat_alv WITH HEADER LINE, t_vbep TYPE STANDARD TABLE OF x_vbep. DATA : wa_vbap TYPE x_vbap, wa_kna1 TYPE x_kna1, wa_lips TYPE x_lips, wa_vbfa TYPE x_vbfa, wa_output TYPE x_output, wa_vbep TYPE x_vbep. *----------------------------------------------------------------------* * Declaration for Email processing * *----------------------------------------------------------------------* DATA: docdata LIKE sodocchgi1, objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE, objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE, objbin1 LIKE solisti1 OCCURS 10 WITH HEADER LINE, objbin2 LIKE solisti1 OCCURS 10 WITH HEADER LINE, objbin_final LIKE solisti1 OCCURS 10 WITH HEADER LINE, reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE, tab_lines TYPE sy-tabix. DATA: gd_sender_type LIKE soextreci1-adr_typ. DATA: c_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab, c_ret TYPE c VALUE cl_abap_char_utilities=>cr_lf. DATA: c_dev TYPE sy-sysid. *&---------------------------------------------------------------------* *& Include Z_0000__1_3_1_1___0023_SCR *&---------------------------------------------------------------------* SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME. SELECT-OPTIONS: s_vbeln FOR vbak-vbeln, "Sales Document s_kunnr FOR kna1-kunnr, "Customer Number s_land1 FOR kna1-land1, "Country of Destination * s_kvgr4 FOR vbak-kvgr4, "Customer Group s_KDGRP for knvv-KDGRP, "Customer Group * s_GPC, *Begin of change Ver 02.00 * s_lfdat FOR likp-lfdat. "Date of Delivery s_vdatu for vbak-vdatu. "Req Delivery date *End of change Ver 02.00 SELECTION-SCREEN END OF BLOCK b1. *&---------------------------------------------------------------------* *& Include Z_0000__1_3_1_1___0023_F01 *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form REFRESH_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM refresh_data . *Refresh internal table data. REFRESH : t_vbak , t_vbap , t_lips , t_kna1 , t_vbfa , t_output, t_fieldcat, t_vbep. ENDFORM. " REFRESH_DATA *&---------------------------------------------------------------------* *& Form FETCH_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM fetch_data . DATA l_index TYPE sy-index. *Select Sales Item data. SELECT k~vbeln k~kunnr v~kdgrp p~posnr p~matnr p~arktx p~kwmeng p~werks p~netwr "Inserted Ver 03.00 INTO CORRESPONDING FIELDS OF TABLE t_vbap FROM ( ( ( vbak AS k INNER JOIN vbap AS p ON k~vbeln = p~vbeln ) INNER JOIN kna1 AS a ON a~kunnr = k~kunnr ) INNER JOIN knvv AS v ON v~kunnr = a~kunnr AND k~vkorg = v~vkorg AND k~vtweg = v~vtweg AND k~spart = v~spart ) WHERE k~vbeln IN s_vbeln AND a~kunnr IN s_kunnr AND v~kdgrp IN s_kdgrp *Begin of insert Ver 02.00 and k~vdatu in s_vdatu. *End of insert Ver 02.00 IF t_vbap IS NOT INITIAL. SORT t_vbap BY vbeln posnr. *Select Sales Document Flow data from VBFA SELECT vbelv posnv vbeln posnn vbtyp_n matnr rfmng FROM vbfa INTO TABLE t_vbfa FOR ALL ENTRIES IN t_vbap WHERE vbelv = t_vbap-vbeln AND vbtyp_n = 'J'. IF t_vbfa IS NOT INITIAL. *Select Delivery based on Sales order on selection screen. SELECT p~vbeln p~lfdat p~wadat_ist s~posnr s~lfimg FROM ( likp AS p INNER JOIN lips AS s ON p~vbeln = s~vbeln ) INTO TABLE t_lips FOR ALL ENTRIES IN t_vbfa WHERE p~vbeln = t_vbfa-vbeln AND s~posnr = t_vbfa-posnn. *Begin of commenting Ver 02.00 * AND p~lfdat IN s_lfdat. *End of commenting Ver 02.00 ENDIF. * SORT t_lips BY vbeln posnr. *Select Customer name SELECT kunnr name1 FROM kna1 INTO TABLE t_kna1 FOR ALL ENTRIES IN t_vbap WHERE kunnr = t_vbap-kunnr AND land1 IN s_land1. SORT t_kna1 BY kunnr. DELETE ADJACENT DUPLICATES FROM t_kna1. *Select Product availability date from VBEP table SELECT vbeln posnr etenr mbdat FROM vbep INTO TABLE t_vbep FOR ALL ENTRIES IN t_vbap WHERE vbeln = t_vbap-vbeln AND posnr = t_vbap-posnr. *Create Output Internal table for Display ALV report LOOP AT t_vbap INTO wa_vbap. wa_output-kunnr = wa_vbap-kunnr. "Customer # READ TABLE t_kna1 INTO wa_kna1 WITH KEY kunnr = wa_vbap-kunnr. wa_output-name1 = wa_kna1-name1. "Customer Name wa_output-vbeln = wa_vbap-vbeln. "Sales Order # wa_output-arktx = wa_vbap-arktx. "Product description wa_output-kwmeng = wa_vbap-kwmeng. "Total Value of sales order quantity wa_output-netwr = wa_vbap-netwr. "Total Value of sales order line "Inserted Ver 03.00 *Read sales doc data for sales order READ TABLE t_vbfa INTO wa_vbfa WITH KEY vbelv = wa_vbap-vbeln posnv = wa_vbap-posnr. *Read delivery data READ TABLE t_lips INTO wa_lips WITH KEY vbeln = wa_vbfa-vbeln posnr = wa_vbfa-posnn. *Selecting Delivered unit of SO line SELECT SUM( DISTINCT rfmng ) INTO wa_output-lfimg FROM vbfa WHERE vbelv = wa_vbap-vbeln AND posnv = wa_vbap-posnr AND vbtyp_n = 'J'. *Begin of Change Ver 02.00 * IF s_lfdat IS NOT INITIAL AND wa_lips IS INITIAL. IF s_vdatu IS NOT INITIAL AND wa_lips IS INITIAL. *End of change Ver 02.00 CONTINUE. ELSE. wa_output-wadat_ist = wa_lips-wadat_ist. "When shipped (GI date) wa_output-open_unit = ( wa_vbap-kwmeng - wa_output-lfimg ). "Open unit of sales. ENDIF. READ TABLE t_vbep INTO wa_vbep WITH KEY vbeln = wa_vbap-vbeln posnr = wa_vbap-posnr. IF sy-subrc EQ 0. wa_output-mbdat = wa_vbep-mbdat. "Product Availability date ENDIF. APPEND wa_output TO t_output. CLEAR : wa_output,wa_lips,wa_vbfa,wa_vbap,wa_kna1. ENDLOOP. ENDIF. ENDFORM. " FETCH_DATA *&---------------------------------------------------------------------* *& Form BUILD_FIELD_CATALOG *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM build_field_catalog . PERFORM fieldcat_add USING 'KUNNR' 15 'Customer' 'Customer' '' '' '' '' ''. PERFORM fieldcat_add USING 'NAME1' 15 'Customer Name' 'Customer Name' '' '' '' '' ''. PERFORM fieldcat_add USING 'VBELN' 15 'Sales Order Number' 'Sales Order Number' '' '' '' '' ''. PERFORM fieldcat_add USING 'ARKTX' 15 'Product Discription' 'Product Discription' '' '' '' '' ''. PERFORM fieldcat_add USING 'KWMENG' 15 'Total Units of Sales Order Line' 'Total Units of Sales Order Line' '' '' '' '' ''. *Begin of insert Ver 03.00 PERFORM fieldcat_add USING 'NETWR' 15 'Total Value of Sales Order Line' 'Total Value of Sales Order Line' '' '' '' '' ''. *End of insert Ver 03.00 PERFORM fieldcat_add USING 'LFIMG' 15 'Delivered Unit of Sales Order Line' 'Delivered Unit of Sales Order Line' '' '' '' '' ''. PERFORM fieldcat_add USING 'WADAT_IST' 15 'When Shipped(GI date)' 'When Shipped(GI date)' '' '' '' '' ''. PERFORM fieldcat_add USING 'OPEN_UNIT' 15 'Open Units of sales Order line' 'Open Units of sales Order line' '' '' '' '' ''. PERFORM fieldcat_add USING 'MBDAT' 20 'Prdct Availability Date' 'Prdct Avail Date' '' '' '' '' ''. 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 = sy-repid * I_CALLBACK_PF_STATUS_SET = ' ' * I_CALLBACK_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 = 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 FIELDCAT_ADD *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_0250 text * -->P_15 text * -->P_C_CMP text * -->P_C_CMP text * -->P_0254 text * -->P_0255 text * -->P_0256 text * -->P_0257 text * -->P_0258 text *----------------------------------------------------------------------* FORM fieldcat_add USING lp_fieldname lp_outputlen lp_seltext_s lp_seltext_m lp_seltext_l lp_cfieldname lp_do_sum lp_key lp_no_zero. CLEAR: t_fieldcat. t_fieldcat-fieldname = lp_fieldname. t_fieldcat-outputlen = lp_outputlen. t_fieldcat-no_zero = lp_no_zero. t_fieldcat-seltext_s = lp_seltext_s. t_fieldcat-seltext_l = lp_seltext_l. IF lp_seltext_m IS INITIAL. t_fieldcat-seltext_m = t_fieldcat-seltext_s. ELSE. t_fieldcat-seltext_m = lp_seltext_m. ENDIF. IF t_fieldcat-seltext_l IS INITIAL. t_fieldcat-seltext_l = t_fieldcat-seltext_m. ELSE. t_fieldcat-seltext_l = lp_seltext_l. ENDIF. t_fieldcat-cfieldname = lp_cfieldname. t_fieldcat-do_sum = lp_do_sum. t_fieldcat-key = lp_key. APPEND t_fieldcat. ENDFORM. " FIELDCAT_ADD .

No comments:

Post a Comment