Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

SHP_GET_SD_DATA - Function module for Extracting Sales order Details

Summary

This Function module can be used to extract the details of a list of sales orders.  This function module returns the details of Order Header, Order Line Item, Line Item schedule Line, Item Status, Header Status, Header& Item Partners,Communication data & Document flow.

Author(s):  Vinod Kumar T

   
Company:     NIIT Technologies Limited
Created on:    22.07.2010
Author(s) Bio
Vinod Kumar is an ABAP Consultant working with NIIT Technologies Limited.

Sample Program using SHP_GET_SD_DATA for extracting Sales Order Details

Error rendering macro 'code': Invalid value specified for parameter 'lang'
 *&---------------------------------------------------------------------*
*& Report  ZVK_SHP_GET_SD_DATA
*&---------------------------------------------------------------------*
*& Purpose : To extract data from All sales order related Tables
*&---------------------------------------------------------------------*
REPORT  ZVK_SHP_GET_SD_DATA.
TABLES : VBAK.
** Type declaration for Order Header Data
TYPES : BEGIN OF TY_VBAK,
          VBELN TYPE VBELN,
        END OF TY_VBAK.
** Internal table & Work area definitions
DATA : IT_VBAK_KEY    TYPE SHP_SALES_KEY_T,
       IS_VBAK_KEY    TYPE SALES_KEY,
       IS_ORDER_VIEW  TYPE ORDER_VIEW,
       CX_SD_ORDER    TYPE SHP_VL10_SD_ORDER.
DATA : IT_VBAK        TYPE STANDARD TABLE OF TY_VBAK,
       WA_VBAK        TYPE TY_VBAK.
DATA : IS_VBAK        TYPE VBAK,
       IS_VBAP        TYPE VBAPVB,
       IS_VBEP        TYPE VBEPVB,
       IS_VBUK        TYPE VBUKVB,
       IS_VBUP        TYPE VBUPVB,
       IS_VBKD        TYPE VBKDVB,
       IS_VBFA        TYPE VBFAVB,
       IS_VBPA        TYPE VBPAVB.
SELECTION-SCREEN BEGIN OF BLOCK B1.
SELECT-OPTIONS : P_VBELN FOR VBAK-VBELN.
SELECTION-SCREEN END OF BLOCK B1.
START-OF-SELECTION.
  PERFORM EXTRACT_ORDER_HEADER.
  PERFORM EXTRACT_ORDER_DETAILS.
  PERFORM PROCESS_ORDER_DETAILS.
*&---------------------------------------------------------------------*
*&      Form  extract_order_header
*&---------------------------------------------------------------------*
FORM EXTRACT_ORDER_HEADER.
  REFRESH : IT_VBAK, IT_VBAK_KEY.
  IF P_VBELN[] IS NOT INITIAL.
    SELECT VBELN
      FROM VBAK
      INTO TABLE IT_VBAK
      WHERE VBELN IN P_VBELN.
  ENDIF.
ENDFORM.                    "extract_order_header
*&---------------------------------------------------------------------*
*&      Form  extract_order_details
*&---------------------------------------------------------------------*
FORM EXTRACT_ORDER_DETAILS.
  IF IT_VBAK[] IS NOT INITIAL.
** Fill FM Input structures.
    LOOP AT IT_VBAK INTO WA_VBAK.
      CLEAR : IS_VBAK_KEY.
      MOVE WA_VBAK-VBELN TO IS_VBAK_KEY-VBELN.
      APPEND IS_VBAK_KEY TO IT_VBAK_KEY.
    ENDLOOP.
    CLEAR : IS_ORDER_VIEW.
    MOVE 'X' TO IS_ORDER_VIEW-HEADER.
    MOVE 'X' TO IS_ORDER_VIEW-ITEM.
    MOVE 'X' TO IS_ORDER_VIEW-SDSCHEDULE.
    MOVE 'X' TO IS_ORDER_VIEW-BUSINESS.
    MOVE 'X' TO IS_ORDER_VIEW-PARTNER.
    MOVE 'X' TO IS_ORDER_VIEW-STATUS_H.
    MOVE 'X' TO IS_ORDER_VIEW-STATUS_I.
    MOVE 'X' TO IS_ORDER_VIEW-FLOW.
** Call Function module
    CLEAR : CX_SD_ORDER.
    CALL FUNCTION 'SHP_GET_SD_DATA'
      EXPORTING
        IT_VBAK_KEY   = IT_VBAK_KEY
        IS_ORDER_VIEW = IS_ORDER_VIEW
      CHANGING
        CX_SD_ORDER   = CX_SD_ORDER.
  ENDIF.
ENDFORM.                    "extract_order_details
*&---------------------------------------------------------------------*
*&      Form  process_order_details
*&---------------------------------------------------------------------*
FORM PROCESS_ORDER_DETAILS.
  IF CX_SD_ORDER IS NOT INITIAL.
    IF CX_SD_ORDER-VBAK[] IS NOT INITIAL.
      LOOP AT CX_SD_ORDER-VBAK INTO IS_VBAK.
**@@ Processing Start of Item details @@**
        LOOP AT CX_SD_ORDER-VBAP INTO IS_VBAP
                                 WHERE VBELN = IS_VBAK-VBELN.
**         Process required columns related to Item.
          LOOP AT CX_SD_ORDER-VBEP INTO IS_VBEP
                                   WHERE VBELN = IS_VBAP-VBELN
                                   AND   POSNR = IS_VBAP-POSNR.
**            Process required columns related to Schedule line.
          ENDLOOP.
          LOOP AT CX_SD_ORDER-VBUP INTO IS_VBUP
                                   WHERE VBELN = IS_VBAP-VBELN
                                   AND   POSNR = IS_VBAP-POSNR.
**            Process required columns related to Item Status.
          ENDLOOP.
          LOOP AT CX_SD_ORDER-VBKD INTO IS_VBKD
                                   WHERE VBELN = IS_VBAP-VBELN
                                   AND   POSNR = IS_VBAP-POSNR.
**            Process required columns related to Item Comm Data.
          ENDLOOP.
          LOOP AT CX_SD_ORDER-VBPA INTO IS_VBPA
                                   WHERE VBELN = IS_VBAP-VBELN
                                   AND   POSNR = IS_VBAP-POSNR.
**            Process required columns related to Item partner.
          ENDLOOP.
        ENDLOOP.
**@@ Processing End of Item details @@**
**@@ Processing Start of Header details @@**
        LOOP AT CX_SD_ORDER-VBUK INTO IS_VBUK
                                 WHERE VBELN = IS_VBAK-VBELN.
**            Process required columns related to Header Status.
        ENDLOOP.
        LOOP AT CX_SD_ORDER-VBKD INTO IS_VBKD
                                 WHERE VBELN = IS_VBAK-VBELN
                                 AND   POSNR = '000000'.
**            Process required columns related to Header Comm Data.
        ENDLOOP.
        LOOP AT CX_SD_ORDER-VBPA INTO IS_VBPA
                                 WHERE VBELN = IS_VBAK-VBELN
                                 AND   POSNR = '000000'.
**            Process required columns related to Header partner.
        ENDLOOP.
        LOOP AT CX_SD_ORDER-VBFA INTO IS_VBFA
                                 WHERE VBELN = IS_VBAK-VBELN.
**            Process required columns related to Document flow.
        ENDLOOP.
**@@ Processing End of Header details @@**
      ENDLOOP.
    ENDIF.
  ENDIF.
ENDFORM.                    "Process_order_details
 
 

SHP_GET_SD_DATA, Function Module, Sales Order Data