Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Finding no.of open sales orders using SD_SELECT_SALES_DOCUMENTS

Former Member
0 Kudos

Dear All, I am new to SAP SD . I here being asked to use  SD_SELECT_SALES_DOCUMENTS to find out the no.of open sales orders , where my input is customer and material number.

Can you pls help.

I apologise if this is posted already and request you to kindly give me the links to check the same.

1 ACCEPTED SOLUTION

Sijin_Chandran
Active Contributor
0 Kudos

Hello Swapna ,

Standard Report for viewing Open Sales Order is VA05N , ( Source Code SD_SALES_ORDERS_VIEW ).

Put a breakpoint at line number 232

While Providing the Selections for VA05N don't forget to Click on Open Sales Orders.

See in debugger how Parameters are passed to this FM.

13 REPLIES 13

former_member209120
Active Contributor
0 Kudos

Hi Swapna Lalitha,

See this sample code

REPORT  sd_sales_orders_view NO STANDARD PAGE HEADING MESSAGE-ID vr

        LINE-SIZE 112.

***********************************************************************

*                  DATENDEKLARATIONSTEIL                              *

***********************************************************************

* ALV

TYPE-POOLS: slis.

TABLES:  vbcom, vbpa.

* ------ Tabelle der Belegzeilen ---------------------------------------

TYPES BEGIN OF zt_postab.                                   "WF20120918

        INCLUDE TYPE svbmtv_trvog.                          "WF20120918

TYPES END OF zt_postab.                                     "WF20120918

DATA postab TYPE STANDARD TABLE OF zt_postab.               "WF20120918

*ATA:    BEGIN OF postab OCCURS 200.

*       INCLUDE STRUCTURE svbmtv_trvog.     " Listanzeigen-Struktur

*ATA:    END   OF postab.

*ATA:    lv_trvog                 TYPE c  VALUE '0'.

*----------------- Deklarationen für ALV ------------------------------*

CONSTANTS: er_formname_top_of_page TYPE slis_formname       "#EC NEEDED

                        VALUE 'TOP_OF_PAGE'.                "#EC NEEDED

*----------------------- Data to be displayed--------------------------*

DATA:   e_repid LIKE sy-repid,

        er_list_top_of_page TYPE slis_t_listheader,

        er_fieldcat TYPE slis_t_fieldcat_alv,

        er_layout TYPE slis_layout_alv,

        e_status TYPE slis_formname VALUE 'SET_STATUS',

        e_user_command TYPE slis_formname VALUE 'USER_COMMAND'.

*------------------PARAMETER------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK kopf WITH FRAME TITLE text-s03.

SELECT-OPTIONS:  svbeln FOR vbcom-vbeln,

                 sauart FOR vbcom-auart MEMORY ID aat,

                 skunnr FOR vbcom-kunnr MEMORY ID kun,

                 saudat FOR vbcom-audat,

                 smatnr FOR vbcom-matnr MEMORY ID mat.

PARAMETERS:      pbstkd TYPE vbkd-bstkd.

PARAMETERS:      pbsark TYPE vbkd-bsark.                    "WF20120918

SELECTION-SCREEN END OF BLOCK kopf.

SELECTION-SCREEN BEGIN OF BLOCK partnerdata WITH FRAME TITLE text-s04.

PARAMETERS: pzpavw TYPE parvw MATCHCODE OBJECT sh_tpar_pe.

SELECT-OPTIONS: szpers FOR vbpa-pernr MATCHCODE OBJECT prem,

                sernam FOR vbcom-ernam.

SELECTION-SCREEN END OF BLOCK partnerdata.

SELECTION-SCREEN BEGIN OF BLOCK orgdaten WITH FRAME TITLE text-s01.

SELECT-OPTIONS: svkorg FOR  vbcom-vkorg MEMORY ID vko,

                svtweg FOR  vbcom-vtweg MEMORY ID stw DEFAULT '01',

                sspart FOR  vbcom-spart MEMORY ID spa,

                svkbur FOR  vbcom-vkbur,

                svkgrp FOR  vbcom-vkgrp.

SELECTION-SCREEN END OF BLOCK orgdaten.

SELECTION-SCREEN BEGIN OF BLOCK selumfang WITH FRAME TITLE text-s02.

PARAMETERS: pvboff RADIOBUTTON GROUP sel.

PARAMETERS: pvball RADIOBUTTON GROUP sel DEFAULT 'X'.

SELECTION-SCREEN END OF BLOCK selumfang.

***********************************************************************

*                  VERARBEITUNGSTEIL                                  *

***********************************************************************

***********************************************************************

*                  HAUPTPROGRAMM                                      *

***********************************************************************

*-------------------  ALV Verarbeitungsblock   ------------------------*

*&---------------------------------------------------------------------*

*&   Event INITIALIZATION

*&---------------------------------------------------------------------*

INITIALIZATION.

*

  e_repid = sy-repid.

  PERFORM fieldcat_init  USING er_fieldcat[].

  PERFORM layout_build USING er_layout.

  PERFORM comment_build  USING er_list_top_of_page[].

*&---------------------------------------------------------------------*

*&   Event START-OF-SELECTION

*&---------------------------------------------------------------------*

START-OF-SELECTION.

*

  PERFORM selektion_ausfuehren.

*&---------------------------------------------------------------------*

*&   Event END-OF-SELECTION

*&---------------------------------------------------------------------*

END-OF-SELECTION.

*

  PERFORM liste_anzeigen.

*----------------------------------------------------------------------

*    FORM SET_STATUS

*----------------------------------------------------------------------

*     Statussetzen

*     Status set

*----------------------------------------------------------------------

*    --> EXTAB

*----------------------------------------------------------------------

FORM set_status USING  extab TYPE slis_t_extab.             "#EC CALLED

*

  DELETE extab WHERE fcode = '&AVE'.

  DELETE extab WHERE fcode = '&OAD'.

  DELETE extab WHERE fcode = '&ERW'.

  SET PF-STATUS 'STATUS_DOCLIST_1' EXCLUDING extab.

*

ENDFORM.                    "SET_STATUS

*---------------------------------------------------------------------*

*       FORM TOP_OF_PAGE                                              *

*---------------------------------------------------------------------*

*       Ereigniss TOP_OF_PAGE                                       *

*       event     TOP_OF_PAGE

*---------------------------------------------------------------------*

FORM top_of_page.                                           "#EC CALLED

*

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

    EXPORTING

      i_logo             = 'ENJOYSAP_LOGO'

      it_list_commentary = er_list_top_of_page.

*

ENDFORM.                    "TOP_OF_PAGE

*&---------------------------------------------------------------------*

*&      Form  fieldcat_init

*&---------------------------------------------------------------------*

*       Initialisieren des FeldKatalogs

*----------------------------------------------------------------------*

*      -->U_ER_FIELDCAT[]  text

*----------------------------------------------------------------------*

*

FORM fieldcat_init  USING u_er_fieldcat TYPE slis_t_fieldcat_alv.

* local data

* DATA: ls_fieldcat TYPE slis_fieldcat_alv.

  FIELD-SYMBOLS <fs_field> LIKE LINE OF u_er_fieldcat.      "WF20120918

  DATA wa_field LIKE LINE OF u_er_fieldcat.                 "WF20120918

*

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

      i_structure_name = 'SERPSLS_GENDOC'

    CHANGING

      ct_fieldcat      = u_er_fieldcat[].

*

  DELETE u_er_fieldcat WHERE fieldname = 'AWAHR'.

  DELETE u_er_fieldcat WHERE fieldname = 'DATAB'.

  DELETE u_er_fieldcat WHERE fieldname = 'DATBI'.

*

  LOOP AT u_er_fieldcat ASSIGNING <fs_field>                "WF20120918

    WHERE col_pos GE 10.                                    "WF20120918

    <fs_field>-col_pos = <fs_field>-col_pos + 1.            "WF20120918

  ENDLOOP.                                                  "WF20120918

*

  wa_field-row_pos = 0.                                     "WF20120918

  wa_field-col_pos = 10.                                    "WF20120918

  wa_field-fieldname = 'ZZBSARK'.                           "WF20120918

  wa_field-seltext_l = 'Bestellart des Kunden'.             "#EC NOTEXT

  wa_field-seltext_m = 'Bestellart'.                        "#EC NOTEXT

  wa_field-seltext_s = 'BesArt'.                            "#EC NOTEXT

  APPEND wa_field TO u_er_fieldcat.                         "WF20120918

  SORT u_er_fieldcat BY col_pos.                            "WF20120918

*

ENDFORM.                    " fieldcat_init

*&---------------------------------------------------------------------*

*&      Form  comment_build

*&---------------------------------------------------------------------*

*        Bearbeitung des Listenkopfes

*        Processing of listheader

*----------------------------------------------------------------------*

*      -->U_ER_LIST_TOP_OF_PAGE[]  text

*----------------------------------------------------------------------*

FORM comment_build USING u_er_list_top_of_page TYPE slis_t_listheader.

*

  DATA: ls_line TYPE slis_listheader.

* Listenüberschrift: Typ H

  CLEAR ls_line.

  ls_line-typ  = 'H'.

  ls_line-info = text-001.

  APPEND ls_line TO u_er_list_top_of_page.

* Kopfinfo: Typ S

  CLEAR ls_line.

  ls_line-typ  = 'S'.

  ls_line-key  = text-002.

  APPEND ls_line TO u_er_list_top_of_page.

ENDFORM.                    " comment_build

*&---------------------------------------------------------------------*

*&      Form  SELEKTION_AUSFUEHREN

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM selektion_ausfuehren .

* local data

  TYPES: BEGIN OF zt_vbak,

           vbeln TYPE vbeln,

         END OF zt_vbak.

  DATA lt_vbak TYPE STANDARD TABLE OF zt_vbak.              "WF20120918

  DATA lwa_vbak LIKE LINE OF lt_vbak.                       "WF20120918

* DATA srch_bstkd TYPE c LENGTH 37.                         "WF20120918

  DATA srch_bsark TYPE c LENGTH 6.                          "WF20120918

* CONCATENATE '%' pbstkd '%' INTO srch_bstkd.               "WF20120918

  CONCATENATE '%' pbsark '%' INTO srch_bsark.               "WF20120918

  DATA lwa_vbeln LIKE LINE OF svbeln.

*

  SELECT vbeln FROM vbak INTO TABLE lt_vbak                 "WF20120918

    WHERE vbeln IN svbeln                                   "WF20120918

    AND   audat IN saudat                                   "WF20120918

    AND   ernam IN sernam                                   "WF20120918

    AND   auart IN sauart                                   "WF20120918

    AND   vkorg IN svkorg                                   "WF20120918

    AND   vtweg IN svtweg                                   "WF20120918

    AND   spart IN sspart                                   "WF20120918

    AND   vkgrp IN svkgrp                                   "WF20120918

    AND   vkbur IN svkbur                                   "WF20120918

*   AND   bstnk LIKE srch_bstkd                             "WF20120918

    AND   bsark LIKE srch_bsark .                           "WF20120918

*

  LOOP AT lt_vbak INTO lwa_vbak.                            "WF20120918

    CLEAR lwa_vbeln.                                        "WF20120918

    lwa_vbeln-sign = 'I'.                                   "WF20120918

    lwa_vbeln-option = 'EQ'.                                "WF20120918

    lwa_vbeln-low = lwa_vbak-vbeln.                         "WF20120918

    APPEND lwa_vbeln TO svbeln.                             "WF20120918

  ENDLOOP.                                                  "WF20120918

*

  CALL FUNCTION 'SD_SELECT_SALES_DOCUMENTS'

    EXPORTING

      iv_trvog    = '0'

      iv_bstkd    = pbstkd

      iv_zpavw    = pzpavw

      iv_vboff    = pvboff

      iv_vball    = pvball

    TABLES

      t_vbmtv     = postab

      i_vkorg_rt  = svkorg

      i_vtweg_rt  = svtweg

      i_spart_rt  = sspart

      i_matnr_rt  = smatnr               " Material Number

      i_kunnr1_rt = skunnr               " Customer Number 1

      i_vkbur_rt  = svkbur

      i_vkgrp_rt  = svkgrp

      i_auart_rt  = sauart

      i_ernam_rt  = sernam

      i_vbeln_rt  = svbeln

      i_audat_rt  = saudat

      i_zpers_rt  = szpers.

*

ENDFORM.                    " SELEKTION_AUSFUEHREN

*&---------------------------------------------------------------------*

*&      Form  LISTE_ANZEIGEN

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM liste_anzeigen .

*

  DESCRIBE TABLE postab LINES sy-tfill.

  IF sy-tfill = 0.

    MESSAGE s490.

    RETURN.

  ENDIF.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

      i_callback_program       = e_repid

      i_callback_pf_status_set = e_status

      i_callback_user_command  = e_user_command

      is_layout                = er_layout

      it_fieldcat              = er_fieldcat[]

    TABLES

      t_outtab                 = postab

    EXCEPTIONS

      program_error            = 1

      OTHERS                   = 2.

  IF sy-subrc <> 0.

    MESSAGE e047.

  ENDIF.

*

ENDFORM.                    " LISTE_ANZEIGEN

*&---------------------------------------------------------------------*

*&      Form  layout_build

*&---------------------------------------------------------------------*

*       Default layout settings

*----------------------------------------------------------------------*

*      -->P_ER_LAYOUT[]  text

*----------------------------------------------------------------------*

FORM layout_build  USING  p_er_layout TYPE slis_layout_alv.

*

  p_er_layout-colwidth_optimize = 'X'.

  p_er_layout-detail_initial_lines = 'X'.

  p_er_layout-zebra = 'X'.                                  "WF20120918

*

ENDFORM.                    " layout_build

*&---------------------------------------------------------------------*

*&      Form  user_command

*&---------------------------------------------------------------------*

FORM user_command USING r_ucomm TYPE sy-ucomm               "#EC CALLED

                        rs_selfield TYPE slis_selfield.     "#EC CALLED

* local data

  DATA wa_postab LIKE LINE OF postab.                       "WF20120918

*

  CASE r_ucomm.

    WHEN  'DISPLAY'.

      CHECK rs_selfield-tabindex > 0.

      READ TABLE postab INTO wa_postab INDEX rs_selfield-tabindex.

      CALL FUNCTION 'RV_CALL_DISPLAY_TRANSACTION'

        EXPORTING

          vbeln = wa_postab-vbeln.

    WHEN  'CHANGE'.

      CHECK rs_selfield-tabindex > 0.

      READ TABLE postab INTO wa_postab INDEX rs_selfield-tabindex.

      CALL FUNCTION 'RV_CALL_CHANGE_TRANSACTION'

        EXPORTING

          vbeln = wa_postab-vbeln.

  ENDCASE.

*

ENDFORM.                    "user_command

0 Kudos

Dear Ramesh,

Thanku for the quick reply. But I request you to gimme a simple code instead of ALV

0 Kudos

Hi Swapna Lalitha,

You can see this Function module in  VA45N - List of Contracts

Program name SD_SALES_CONTRACTS_VIEW

Sijin_Chandran
Active Contributor
0 Kudos

Hello Swapna ,

Standard Report for viewing Open Sales Order is VA05N , ( Source Code SD_SALES_ORDERS_VIEW ).

Put a breakpoint at line number 232

While Providing the Selections for VA05N don't forget to Click on Open Sales Orders.

See in debugger how Parameters are passed to this FM.

0 Kudos

Thanku sijin... I will check the same and come back in any case

0 Kudos

By the way by looking at the functional module it seems that it is meant for Internal Purposes.

By applying some conditions and logic you can fetch it easily.

Sales Order table is VBAK and its successor Sale Document is Delivery now if Delivery's Status is "Partially Completed" or "Not Yet Processed" then it means that Sale Order document is also still open.

Sale Document Header Status table is VBUK and there is a field LFSTK ( Delivery status ) which can have the following values :

Blank = Not relevant

A       = Not yet processed

B       = Partially processed

C       = Completely processed

So go through the Data in this table corresponding to the Sale Order ( VBELN ) number and analyse accordingly.

ELSE

If you want to Stick with this FM only , Do not forget to Set the EXPORT Parameter Field iv_vboff = 'X' ( for fetching Open Orders only ) and also pass

TABLE Parameters i_matnr_rt ( for Material Code ) and i_kunnr1_rt ( for SOLD-TO-PARTY i.e Customer ) and also i_audat_r ( For Sale Document Date , if required ) while Calling this FM.

TABLE Parameter t_vbmtv will give  all the Relevant Sale Orders after Execution of this FM.

0 Kudos

Friends..

Pls try to give me a simple solution like using inner join between VBAP\VBAK tables to retrieve no.of open sales orders

0 Kudos

First of All its not possible to Select Open Sales Order by only using VBAP and VBAK.

You need to link VBUK also ( table for status ).

0 Kudos

REPORT  ZSAMPLE030.

TABLESvbcom, vbpa.

SELECT-OPTIONS:

                  skunnr FOR  vbcom-kunnr ,

                  saudat FOR vbcom-audat,

                  smatnr FOR  vbcom-matnr .

DATA:    BEGIN OF postab OCCURS 200.

         INCLUDE STRUCTURE svbmtv_trvog.     " Listanzeigen-Struktur

DATA:    END   OF postab.

   CALL FUNCTION 'SD_SELECT_SALES_DOCUMENTS'

     EXPORTING

       iv_trvog    = '0'

       iv_vboff    = 'X' " for fetching open

     TABLES

       t_vbmtv     = postab

       i_matnr_rt  = smatnr

       i_kunnr1_rt = skunnr

       i_audat_rt  = saudat.

Table postab will contain all the Open Sale order.

OR

Write a query like below ,

SELECT VBAK~VBELN

   FROM VBAK INNER JOIN VBUK

     ON VBAK~VBELN = VBUK~VBELN

   INTO CORRESPONDING FIELDS OF TABLE IT_VBAK

   WHERE VBAK~KUNNR IN SO_KUNNR

     AND VBUK~LFGSK NOT IN ('A','B') . " for Open Sale Order

And after this use FOR ALL ENTRIES to Select FROM VBAP connecting with IT_VBAK and maintain a WHERE Clause for MATNR as well.


Message was edited by: Sijin Sij

0 Kudos

Thanku....I will try and get back to u

0 Kudos

AND VBUK~LFGSK NOT IN ('A','B')

should be


AND VBUK~GBSTK IN ('A','B') instead .


0 Kudos

ok

Former Member
0 Kudos

Thanku all !!!