Skip to Content
author's profile photo Former Member
Former Member

SD Flow program using For all entries.

using simple ALV grid: I have the urgent requirement of changing the following program using 'For all entries' instead of joins and I should not use 'TABLES' -- For top-of-page I need to get dynamic fields like if I select company code in the selection screen then I need to get 'This report is base on COMPANY CODE'.

This program is about sales flow where i shud get only those records that have ebeln in vbak, delivery, invoice.

The original program is as follows:

*&---------------------------------------------------------------------*
*& Report  ZSD_DOCU_FLOW                                               *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  zsd_docu_flow  NO STANDARD PAGE HEADING                    .

************************************************************************
*                                                                      *
* Program     : ZCOS_SALES                                           *
*                                                                      *
* Dev. Class  :  ZSD
*
*                                                                      *
* Functional  :
*                                                                      *
*

*                                                                      *
* Created on  :                                                        *
*                                                                      *
* Project     :

*                                                                      *
* CR Number   :
*                                                                      *
* Transaction :  ZSDCSUT                                               *
*                                                                       *
* Description :   * Sales document life cylce for given customer
*                  to declaired period displaying the sales document
*                  details ,with relevant del details and corresponding
*                  Invocie Details
*                                                                      *
************************************************************************

*-----------------------------------------------------------*
*-----------     Tables Declaration      -----------*
*-----------------------------------------------------------*

TABLES: vbak,vbap,vbfa,kna1,vbrk,vbrp,likp,lips,t001.
TYPE-POOLS : slis.

*-----------------------------------------------------------*
*-----------    Internal Tables Declaration      -----------*
*-----------------------------------------------------------*


*      Internal Table for Sales Order data                   *
DATA: BEGIN OF it_so OCCURS 0,
        vbeln LIKE vbak-vbeln,
        kunnr LIKE vbak-kunnr,
        posnr LIKE vbap-posnr,
        matnr LIKE vbap-matnr,
        kwmeng LIKE vbap-kwmeng,
        netwr LIKE vbap-netwr,
     END OF it_so.

*      Internal Table for Delivery Order data                   *

DATA: BEGIN OF it_del OCCURS 0,
        delnum  LIKE likp-vbeln,
        lfdat LIKE likp-lfdat,
        delitem LIKE lips-posnr,
        lfimg LIKE lips-lfimg,
      END OF it_del.

*      Internal Table for Invoice data                          *

DATA: BEGIN OF  it_inv OCCURS 0,
        invnum LIKE vbrk-vbeln,
        invitem LIKE vbrp-posnr,
        fkimg LIKE vbrp-fkimg,
        amount LIKE vbrp-netwr,
     END OF it_inv.

*      Internal Table for Final data                            *

DATA: BEGIN OF it_final OCCURS 0,

        vbeln LIKE vbak-vbeln,
        posnr LIKE vbap-posnr,
        kunnr LIKE vbak-kunnr,
        name LIKE kna1-name1,
        matnr LIKE vbap-matnr,
        kwmeng LIKE vbap-kwmeng,
        netwr LIKE vbap-netwr,
        delnum  LIKE likp-vbeln,
        lfdat LIKE likp-lfdat,
        delitem LIKE lips-posnr,
        lfimg LIKE lips-lfimg,
        invnum LIKE vbrk-vbeln,
        invitem LIKE vbrp-posnr,
        fkimg LIKE vbrp-fkimg,
        amount LIKE vbrp-netwr,

     END OF it_final.
*-----------------------------------------------------------*
*-----------    Variables Declaration      -----------*
*-----------------------------------------------------------*


DATA: v_name LIKE kna1-kunnr," variable for customer name
      v_delnum LIKE likp-vbeln," variable for delivery number
      v_invnum LIKE vbrk-vbeln." variable for invoce number

DATA : ls_layout TYPE slis_layout_alv,
       it_fcat TYPE slis_t_fieldcat_alv ,
       wa_fcat TYPE slis_fieldcat_alv,
       lh TYPE slis_t_listheader,
       ls TYPE slis_listheader,
       it_events TYPE slis_t_event  ,
       ls_event TYPE slis_alv_event ,
       i_sort     TYPE slis_t_sortinfo_alv,
       w_var TYPE i.

DATA : l_date(10).
DATA : l_date1(20).
DATA : l_repid LIKE trdir-name.
l_repid = 'ZSD_DOCU_FLOW1'.


*-----------------------------------------------------------*
*-----------    Select-options & parameters Declaration  ---*
*-----------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_bukrs LIKE vbak-bukrs_vf,
             p_vkorg LIKE vbak-vkorg,
            p_vtweg LIKE vbak-vtweg,
            p_spart LIKE vbak-spart.
SELECT-OPTIONS: s_kunnr FOR vbak-kunnr,
                s_audat FOR vbak-audat.

SELECTION-SCREEN END OF BLOCK b1.

*-----------------------------------------------------------*
*----------- AT SELECTION-SCREEN  --------------------------*
*-----------------------------------------------------------*


AT SELECTION-SCREEN.

  SELECT SINGLE * FROM  t001 INTO t001
                            WHERE bukrs = p_bukrs.

  IF sy-subrc <> 0.
    MESSAGE e000(8i) WITH 'Enter a Valid Company Code'.
  ENDIF.

  SELECT SINGLE * FROM vbak INTO vbak
                          WHERE vkorg = p_vkorg.

  IF sy-subrc <> 0.
    MESSAGE e000(8i) WITH 'Enter a Valid Sales Organization'.
  ENDIF.


  SELECT SINGLE * FROM vbak INTO vbak
                            WHERE vtweg = p_vtweg.

  IF sy-subrc <> 0.
    MESSAGE e000(8i) WITH 'Enter a Valid distribution channel'.
  ENDIF.

  SELECT SINGLE * FROM vbak INTO vbak
                            WHERE spart = p_spart.

  IF sy-subrc <> 0.
    MESSAGE e000(8i) WITH 'Enter a Valid Division'.
  ENDIF.


  SELECT SINGLE * FROM kna1 INTO kna1
                            WHERE kunnr IN s_kunnr.

  IF sy-subrc <> 0.
    MESSAGE e000(8i) WITH 'Enter a Valid Customer Number'.
  ENDIF.
*-----------------------------------------------------------*
*----------- START-OF-SELECTION-----------------------------*
*-----------------------------------------------------------*


START-OF-SELECTION.

  ls-typ = 'H'.
  ls-info = 'Sales Document Flow'.
  APPEND ls TO lh.

  ls-typ = 'S'.
  WRITE: sy-datum TO l_date USING EDIT MASK '__/__/____'.
  CONCATENATE 'DATE :' l_date INTO l_date1 SEPARATED BY space.
  ls-info = l_date1.
  APPEND ls TO lh.

  PERFORM field_cat.
  PERFORM t_sort_build USING i_sort.
  PERFORM get-data.
*-----------------------------------------------------------*
*----------- END-OF-SELECTION-----------------------------*
*-----------------------------------------------------------*

END-OF-SELECTION.

IF it_final[] IS INITIAL.
    MESSAGE i000(8i) WITH 'No data Found'.
    EXIT.
  ENDIF.

PERFORM print-data.
*&---------------------------------------------------------------------*
*&      Form  get-data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get-data .

*  Accesing Sales Data

  SELECT a~vbeln a~kunnr b~posnr b~matnr b~kwmeng b~netwr
   INTO CORRESPONDING FIELDS OF TABLE it_so
   FROM vbak AS a INNER JOIN vbap AS b
                         ON a~vbeln = b~vbeln
                          WHERE a~bukrs_vf = p_bukrs
                             AND a~vkorg = p_vkorg
                             AND  a~vtweg = p_vtweg
                                AND a~spart = p_spart
                                 AND a~kunnr IN s_kunnr
                                      AND a~audat IN s_audat.


  LOOP AT it_so.

    SELECT SINGLE name1 FROM kna1 INTO v_name
                                     WHERE kunnr = it_so-kunnr.

    SELECT SINGLE vbeln FROM vbfa INTO v_delnum
                                      WHERE vbelv = it_so-vbeln
                                        AND  vbtyp_n = 'J'.

    IF sy-subrc = 0.

      SELECT SINGLE  vbeln FROM vbfa INTO v_invnum
                            WHERE vbelv = v_delnum
                              AND  vbtyp_n = 'M'.
    ENDIF.

    MOVE-CORRESPONDING it_so TO it_final.

    it_final-name = v_name.
    it_final-delnum = v_delnum.
    it_final-invnum = v_invnum.

    APPEND it_final.
    CLEAR it_final.

    CLEAR v_delnum.
    CLEAR v_invnum.

  ENDLOOP.

  LOOP AT it_final.

    IF it_final-delnum NE ' '.

* Reading Del Data.

      SELECT SINGLE  a~vbeln  a~lfdat b~posnr b~lfimg   INTO
                (it_del-delnum, it_del-lfdat, it_del-delitem,
                 it_del-lfimg ) FROM
                    likp AS a INNER JOIN lips AS b ON a~vbeln = b~vbeln
                               WHERE a~vbeln = it_final-delnum
                               AND b~posnr = it_final-posnr.

      MOVE-CORRESPONDING it_del TO it_final.
      MODIFY it_final.
    ENDIF.


    IF it_final-invnum NE ' '.

* Reading Invoice Data.

      SELECT SINGLE vbeln posnr fkimg netwr INTO
     (it_inv-invnum, it_inv-invitem, it_inv-fkimg, it_inv-amount )
                   FROM vbrp  WHERE vbeln = it_final-invnum
                              AND   posnr = it_final-posnr.

      MOVE-CORRESPONDING it_inv TO it_final.

      MODIFY it_final.


    ENDIF.

  ENDLOOP.

ENDFORM.                    " get-data
*&---------------------------------------------------------------------*
*&      Form  print-data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM print-data .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
*     I_INTERFACE_CHECK                 = ' '
*     I_BYPASSING_BUFFER                = ' '
*     I_BUFFER_ACTIVE                   = ' '
     i_callback_program                = l_repid
*     I_CALLBACK_PF_STATUS_SET          = ' '
*     I_CALLBACK_USER_COMMAND           = ' '
     i_callback_top_of_page            = 'TOP'
*     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                       = it_fcat
*     IT_EXCLUDING                      =
*     IT_SPECIAL_GROUPS                 =
     IT_SORT                           = i_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
*     IT_ALV_GRAPHICS                   =
*     IT_HYPERLINK                      =
*     IT_ADD_FIELDCAT                   =
*     IT_EXCEPT_QINFO                   =
*     I_HTML_HEIGHT_TOP                 =
*     I_HTML_HEIGHT_END                 =
*   IMPORTING
*     E_EXIT_CAUSED_BY_CALLER           =
*     ES_EXIT_CAUSED_BY_USER            =
    TABLES
      t_outtab                          = it_final.
*   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.                    " print-data
*&---------------------------------------------------------------------*
*&      Form  field_cat
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM field_cat .
  wa_fcat-col_pos = w_var.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-fieldname = 'VBELN'.
  wa_fcat-key = 'X'.
  wa_fcat-ref_fieldname = 'VBELN'.
  wa_fcat-ref_tabname = 'VBAK'.
  wa_fcat-seltext_m = 'Sales Order NO'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.
  ADD 1 TO w_var.

  wa_fcat-col_pos = w_var.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-fieldname = 'POSNR'.
  wa_fcat-ref_fieldname = 'POSNR'.
  wa_fcat-ref_tabname = 'VBAP'.
  wa_fcat-seltext_m = 'SalesItemNO'.
  wa_fcat-fix_column = 'X'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.
  ADD 1 TO w_var.

  wa_fcat-col_pos = w_var.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-fieldname = 'KUNNR'.
  wa_fcat-seltext_m = 'CUSTNUM'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.
  ADD 1 TO w_var.

  wa_fcat-col_pos = w_var.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-fieldname = 'NAME'.
  wa_fcat-seltext_m = 'CUSTNAME'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.
  ADD 1 TO w_var.

  wa_fcat-col_pos = w_var.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-fieldname = 'MATNR'.
  wa_fcat-seltext_m = 'MATNUM'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.
  ADD 1 TO w_var.

  wa_fcat-col_pos = w_var.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-fieldname = 'KWMENG'.
  wa_fcat-seltext_m = 'Sales Quantity'.
  wa_fcat-do_sum = 'X'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.
  ADD 1 TO w_var.

  wa_fcat-col_pos = w_var.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-fieldname = 'NETWR'.
  wa_fcat-seltext_m = 'Value'.
  wa_fcat-do_sum = 'X'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.
  ADD 1 TO w_var.

  wa_fcat-col_pos = w_var.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-fieldname = 'DELNUM'.
  wa_fcat-seltext_m = 'DeloveryNum'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.
  ADD 1 TO w_var.

  wa_fcat-col_pos = w_var.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-fieldname = 'DELITEM'.
  wa_fcat-seltext_m = 'DelItemNO'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.
  ADD 1 TO w_var.

  wa_fcat-col_pos = w_var.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-fieldname = 'LFDAT'.
  wa_fcat-seltext_m = 'DelDate'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.
  ADD 1 TO w_var.

  wa_fcat-col_pos = w_var.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-fieldname = 'LFIMG'.
  wa_fcat-seltext_m = 'DelQuantity'.
  wa_fcat-do_sum = 'X'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.
  ADD 1 TO w_var.

  wa_fcat-col_pos = w_var.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-fieldname = 'INVNUM'.
  wa_fcat-seltext_m = 'InvoiceNum'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.
  ADD 1 TO w_var.

  wa_fcat-col_pos = w_var.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-fieldname = 'INVITEM'.
  wa_fcat-seltext_m = 'InvoiceItem'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.
  ADD 1 TO w_var.

  wa_fcat-col_pos = w_var.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-fieldname = 'FKIMG'.
  wa_fcat-seltext_m = 'INVQuantity'.
  wa_fcat-do_sum = 'X'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.
  ADD 1 TO w_var.

  wa_fcat-col_pos = w_var.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-fieldname = 'AMOUNT'.
  wa_fcat-seltext_m = 'INVvalue'.
  wa_fcat-do_sum = 'X'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.
  ADD 1 TO w_var.

ENDFORM.     " field_cat


*&--------------------------------------------------------------------*
*&      Form  top
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*

FORM t_sort_build USING l_sort TYPE slis_t_sortinfo_alv.

  DATA: ls_sort TYPE slis_sortinfo_alv.

  ls_sort-fieldname = 'VBELN'.
  ls_sort-spos      = 1.
  ls_sort-up        = 'X'.
  ls_sort-subtot    = 'X'.
  APPEND ls_sort TO l_sort.

  ls_sort-fieldname = 'KUNNR'.
  ls_sort-spos      = 2.
  ls_sort-up        = 'X'.
  APPEND ls_sort TO l_sort.

ENDFORM.                    "t_sort_bui
FORM top.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary       = lh
*   I_LOGO                   =
*   I_END_OF_LIST_GRID       =
            .

ENDFORM.                    "TOP

-


===========================================================================

I have started the new program but i have trouble with the final internal table. Since i'm using For all entries I have declared internal tables for each table. My incomplete new program is as follows(not sure if the logic is correct till what I have coded):

*&---------------------------------------------------------------------*
*& Report  Z_SDFLOW                                                    *
*&                                                                     *
*&---------------------------------------------------------------------*


REPORT  Z_SDFLOW  NO STANDARD PAGE HEADING.

********* TABLES TO BE USED ***********************
**** VBAK - SALES DOCUMENT HEADER
* VBAP - SALES ITEM
* VBFA - SALES DOCUMENT FLOW
* KNA1- CUSTOMER MASTER
* VBRK - BILLING DOCUMENT HEADER
* VBRP - BLLING DOCUMENT ITEM
* LIKP - DELIVERY HEADER
* LIPS - DELIVERY ITEM
* TOO1 - COMPANY CODES
* SLIS.

TYPE-POOLS: SLIS.

** STRUCTURE DECLARATIONS ********

**STRUCTURE FOR ENQUIRY.

**STRUCTURE FOR QUOTATION.

**STRUCTURE FOR SALES ORDER HEADER- VBAK.
TYPES: BEGIN OF XT_VBAK,
VBELN TYPE VBAK-VBELN,     "SALES DOCUMENT NUMBER
KUNNR TYPE VBAK-KUNNR,     " SOLD-TO-PARTY
END OF XT_VBAK.

**STRUCTURE FOR SALES ORDER  ITEM-VBAP
TYPES: BEGIN OF XT_VBAP,
POSNR TYPE VBAP-POSNR,     " SALES ITEM NUMBER
MATNR TYPE VBAP-MATNR,     " MATERIAL NUMBER
KWMENG TYPE VBAP-KWMENG,   " CUMMULATIVE ORDER QUANTITY IN SALES UNITS
NETWR TYPE VBAP-NETWR,     " NET VALUE OF THE ORDER ITEM
END OF XT_VBAP.


** STRUCTURE FOR DELIVERY HEADER -LIKP
TYPES: BEGIN OF XT_LIKP,
DELVBELN TYPE LIKP-VBELN,           "DELIVERY DOCUMENT NUMBER
LFDAT TYPE LIKP-LFDAT,           " DELIVERY DATE
END OF XT_LIKP.

**STRUCTURE FOR DELIVERY ITEM - LIPS
TYPES: BEGIN OF XT_LIPS,
DELPOSNR TYPE LIPS-POSNR,           " DELIVERY ITEM NUMBER
LFIMG TYPE LIPS-LFIMG,           " ACTUAL QUANTITY DELIVERED
END OF XT_LIPS.

**STRUCTURE FOR BILLING DOCUMENT HEADER -VBRK
TYPES: BEGIN OF XT_VBRK,
INVVBELN TYPE VBRK-VBELN,          "BILLING DOCUMENT NUMBER
END OF XT_VBRK.

**STRUCTURE FOR BILLING DOCUMENT ITEM - VBRP
TYPES: BEGIN OF XT_VBRP,
INVPOSNR TYPE VBRP-POSNR,          "BILLING ITEM NUMBER
FKIMG TYPE VBRP-FKIMG,          "ACTUAL INVOICED QUANTITY
INVNETWR TYPE VBRP-NETWR,          "NET VALUE OF THE BILLING ITEM
END OF XT_VBRP.

**STRUCTURE FOR FINAL INTERNAL TABLE.
TYPES: BEGIN OF XT_FINAL,
VBELN TYPE VBAK-VBELN,
DELVBELN TYPE LIKP-VBELN,
INVBELN TYPE VBRK-VBELN,
KUNNR TYPE VBAK-KUNNR,
POSNR TYPE VBAP-POSNR,
DELPOSNT TYPE LIPS-POSNR,
INVPOSNR TYPE VBRP-POSNR,
MATNR TYPE VBAP-MATNR,
KWMENG TYPE VBAP-KWMENG,
NETWR TYPE VBAP-NETWR,
INVNETWR TYPE VBRP-NETWR,
LFDAT TYPE LIKP-LFDAT,
LFIMG TYPE LIPS-LFIMG,
FKIMG TYPE VBRP-FKIMG,
NAME1 TYPE KNA1-NAME1,
END OF XT_FINAL.


**DATA DECLARATIONS
DATA: V_NAME1 TYPE KNA1-NAME1,  "#EC *
      V_DELVBELN TYPE LIKP-VBELN,
      V_INVVBELN TYPE VBRK-VBELN,
      V_BUKRS TYPE T001-BUKRS,    "COMPANY CODE "#EC *
      V_AUDAT TYPE VBAK-AUDAT,
      V_VKORG TYPE VBAK-VKORG,
      V_VKGRP TYPE VBAK-VKGRP,
      V_SPART TYPE VBAK-SPART.


**INTERNAL TABLE DECLARATIONS
DATA: IT_VBAK TYPE STANDARD TABLE OF XT_VBAK,
      WA_VBAK TYPE XT_VBAK,
      IT_VBAP TYPE STANDARD TABLE OF XT_VBAP,
      WA_VBAP TYPE XT_VBAP,

      IT_LIKP TYPE STANDARD TABLE OF XT_LIKP,
      WA_LIKP TYPE XT_LIKP,
      IT_LIPS TYPE STANDARD TABLE OF XT_LIPS,
      WA_LIPS TYPE XT_LIPS,

      IT_VBRK TYPE STANDARD TABLE OF XT_VBRK,
      WA_VBRK TYPE XT_VBRK,
      IT_VBRP TYPE STANDARD TABLE OF XT_VBRP,
      WA_VBRP TYPE XT_VBRP,


      IT_FINAL TYPE STANDARD TABLE OF XT_FINAL,
      WA_FINAL TYPE XT_FINAL.


**ALV DECLARATIONS
DATA: IT_FLDCAT TYPE SLIS_T_FIELDCAT_ALV,
      WA_FLDCAT TYPE SLIS_FIELDCAT_ALV,
      IT_LSTHDR TYPE SLIS_T_LISTHEADER,
      WA_LSTHDR TYPE SLIS_LISTHEADER,
      IT_EVENTS TYPE SLIS_T_EVENT,
      WA_EVENTS TYPE SLIS_ALV_EVENT,
      IT_SORT TYPE SLIS_T_SORTINFO_ALV,
      IT_LAYOUT TYPE SLIS_LAYOUT_ALV.


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: S_BUKRS FOR V_BUKRS NO INTERVALS NO-EXTENSION,
                S_VBELN FOR WA_VBAK-VBELN,  "SALES DOCUMENT NUMBER
                S_KUNNR FOR WA_VBAK-KUNNR,  "SOLD-TO-PARTY
                S_AUDAT FOR V_AUDAT,      "SALES DOCUMENT DATE
                S_VKORG FOR V_VKORG,      "SALES ORGANISATION
                S_VKGRP FOR V_VKGRP,      "SALES GROUP
                S_SPART FOR V_SPART.      "DIVISION
SELECTION-SCREEN END OF BLOCK b1.



*****************SCREEN VALIDATION***************

AT SELECTION-SCREEN.


SELECT SINGLE BUKRS FROM T001 INTO V_BUKRS WHERE BUKRS IN S_BUKRS."#EC *
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER A VALID COMPANY CODE'.
ENDIF.

SELECT SINGLE VBELN FROM VBAK INTO
          CORRESPONDING FIELDS OF WA_VBAK WHERE VBELN IN S_VBELN.

IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER VALID SALES DOCUMENT NUMBER'.
ENDIF.

SELECT SINGLE KUNNR FROM VBAK INTO
          CORRESPONDING FIELDS OF WA_VBAK WHERE KUNNR IN S_KUNNR. "EC *

IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER A VALID CUSTOMER NUMBER'.
ENDIF.

SELECT SINGLE AUDAT FROM VBAK INTO V_AUDAT WHERE AUDAT IN S_AUDAT."#EC *
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES DOCUMENT DATE'.
ENDIF.

SELECT SINGLE VKORG FROM VBAK INTO V_VKORG WHERE VKORG IN S_VKORG."#EC *
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES ORGANISATION'.
ENDIF.

SELECT SINGLE VKGRP FROM VBAK INTO V_VKGRP WHERE VKGRP IN S_VKGRP."#EC *
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES GROUP'.
ENDIF.

SELECT SINGLE SPART FROM VBAK INTO V_SPART WHERE SPART IN S_SPART."#EC *
IF SY-SUBRC <> 0.
MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES DIVISION'.
ENDIF.

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

PERFORM GET_DATA.

*&---------------------------------------------------------------------
*
*&      Form  GET_DATA
*&---------------------------------------------------------------------
*

FORM GET_DATA .


SELECT VBELN KUNNR
        INTO TABLE IT_VBAK
        FROM VBAK
        WHERE VBELN IN S_VBELN.
*        BUKRS_VF IN S_BUKRS AND
*        VKORG IN S_VKORG AND
*        VKGRP IN S_VKGRP AND
*        SPART IN S_SPART AND
*        KUNNR IN S_KUNNR AND
*        AUDAT IN S_AUDAT.



IF IT_VBAK[] IS NOT INITIAL.
SELECT POSNR MATNR KWMENG NETWR
        INTO TABLE IT_VBAP
        FROM VBAP
        FOR ALL ENTRIES IN IT_VBAK
        WHERE VBELN = IT_VBAK-VBELN.
ENDIF.

IF IT_VBAK[] IS NOT INITIAL.
SELECT VBELN LFDAT
        INTO TABLE IT_LIKP
        FROM LIKP
        FOR ALL ENTRIES IN IT_VBAK
        WHERE VBELN = IT_VBAK-VBELN.
ENDIF.

IF IT_VBAP[] IS NOT INITIAL.
SELECT POSNR LFIMG
        INTO TABLE IT_LIPS
        FROM LIPS
        FOR ALL ENTRIES IN IT_VBAP
        WHERE POSNR = IT_VBAP-POSNR.
ENDIF.

IF IT_LIKP[] IS NOT INITIAL.
SELECT VBELN
        INTO TABLE IT_VBRK
        FROM VBRK
        FOR ALL ENTRIES IN IT_LIKP
        WHERE VBELN = IT_LIKP-DELVBELN.
ENDIF.

IF IT_LIPS[] IS NOT INITIAL.
SELECT POSNR FKIMG NETWR
        INTO TABLE IT_VBRP
        FROM VBRP
        FOR ALL ENTRIES IN IT_LIPS
        WHERE POSNR = IT_LIPS-DELPOSNR.
ENDIF.


ENDFORM.                    " GET_DATA

Edited by: srk s on Jan 29, 2008 7:33 PM

Edited by: Alvaro Tejada Galindo on Jan 29, 2008 9:49 AM

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 02:03 PM

    What is your Problem with this code?

    Regards,

    Satish

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Satish,

      I have started the new program but i have trouble with the final internal table. Since i'm using For all entries, I have declared internal tables for each table. My incomplete new program is as follows(not sure if the logic is correct till what I have coded):

      *&---------------------------------------------------------------------*
      *& Report  Z_SDFLOW                                                    *
      *&                                                                     *
      *&---------------------------------------------------------------------*
      
      
      REPORT  Z_SDFLOW  NO STANDARD PAGE HEADING.
      
      ********* TABLES TO BE USED ***********************
      **** VBAK - SALES DOCUMENT HEADER
      * VBAP - SALES ITEM
      * VBFA - SALES DOCUMENT FLOW
      * KNA1- CUSTOMER MASTER
      * VBRK - BILLING DOCUMENT HEADER
      * VBRP - BLLING DOCUMENT ITEM
      * LIKP - DELIVERY HEADER
      * LIPS - DELIVERY ITEM
      * TOO1 - COMPANY CODES
      * SLIS.
      
      TYPE-POOLS: SLIS.
      
      ** STRUCTURE DECLARATIONS ********
      
      **STRUCTURE FOR ENQUIRY.
      
      **STRUCTURE FOR QUOTATION.
      
      **STRUCTURE FOR SALES ORDER HEADER- VBAK.
      TYPES: BEGIN OF XT_VBAK,
      VBELN TYPE VBAK-VBELN,     "SALES DOCUMENT NUMBER
      KUNNR TYPE VBAK-KUNNR,     " SOLD-TO-PARTY
      END OF XT_VBAK.
      
      **STRUCTURE FOR SALES ORDER  ITEM-VBAP
      TYPES: BEGIN OF XT_VBAP,
      POSNR TYPE VBAP-POSNR,     " SALES ITEM NUMBER
      MATNR TYPE VBAP-MATNR,     " MATERIAL NUMBER
      KWMENG TYPE VBAP-KWMENG,   " CUMMULATIVE ORDER QUANTITY IN SALES UNITS
      NETWR TYPE VBAP-NETWR,     " NET VALUE OF THE ORDER ITEM
      END OF XT_VBAP.
      
      
      ** STRUCTURE FOR DELIVERY HEADER -LIKP
      TYPES: BEGIN OF XT_LIKP,
      DELVBELN TYPE LIKP-VBELN,           "DELIVERY DOCUMENT NUMBER
      LFDAT TYPE LIKP-LFDAT,           " DELIVERY DATE
      END OF XT_LIKP.
      
      **STRUCTURE FOR DELIVERY ITEM - LIPS
      TYPES: BEGIN OF XT_LIPS,
      DELPOSNR TYPE LIPS-POSNR,           " DELIVERY ITEM NUMBER
      LFIMG TYPE LIPS-LFIMG,           " ACTUAL QUANTITY DELIVERED
      END OF XT_LIPS.
      
      **STRUCTURE FOR BILLING DOCUMENT HEADER -VBRK
      TYPES: BEGIN OF XT_VBRK,
      INVVBELN TYPE VBRK-VBELN,          "BILLING DOCUMENT NUMBER
      END OF XT_VBRK.
      
      **STRUCTURE FOR BILLING DOCUMENT ITEM - VBRP
      TYPES: BEGIN OF XT_VBRP,
      INVPOSNR TYPE VBRP-POSNR,          "BILLING ITEM NUMBER
      FKIMG TYPE VBRP-FKIMG,          "ACTUAL INVOICED QUANTITY
      INVNETWR TYPE VBRP-NETWR,          "NET VALUE OF THE BILLING ITEM
      END OF XT_VBRP.
      
      **STRUCTURE FOR FINAL INTERNAL TABLE.
      TYPES: BEGIN OF XT_FINAL,
      VBELN TYPE VBAK-VBELN,
      DELVBELN TYPE LIKP-VBELN,
      INVBELN TYPE VBRK-VBELN,
      KUNNR TYPE VBAK-KUNNR,
      POSNR TYPE VBAP-POSNR,
      DELPOSNT TYPE LIPS-POSNR,
      INVPOSNR TYPE VBRP-POSNR,
      MATNR TYPE VBAP-MATNR,
      KWMENG TYPE VBAP-KWMENG,
      NETWR TYPE VBAP-NETWR,
      INVNETWR TYPE VBRP-NETWR,
      LFDAT TYPE LIKP-LFDAT,
      LFIMG TYPE LIPS-LFIMG,
      FKIMG TYPE VBRP-FKIMG,
      NAME1 TYPE KNA1-NAME1,
      END OF XT_FINAL.
      
      
      **DATA DECLARATIONS
      DATA: V_NAME1 TYPE KNA1-NAME1,  "#EC *
            V_DELVBELN TYPE LIKP-VBELN,
            V_INVVBELN TYPE VBRK-VBELN,
            V_BUKRS TYPE T001-BUKRS,    "COMPANY CODE "#EC *
            V_AUDAT TYPE VBAK-AUDAT,
            V_VKORG TYPE VBAK-VKORG,
            V_VKGRP TYPE VBAK-VKGRP,
            V_SPART TYPE VBAK-SPART.
      
      
      **INTERNAL TABLE DECLARATIONS
      DATA: IT_VBAK TYPE STANDARD TABLE OF XT_VBAK,
            WA_VBAK TYPE XT_VBAK,
            IT_VBAP TYPE STANDARD TABLE OF XT_VBAP,
            WA_VBAP TYPE XT_VBAP,
      
            IT_LIKP TYPE STANDARD TABLE OF XT_LIKP,
            WA_LIKP TYPE XT_LIKP,
            IT_LIPS TYPE STANDARD TABLE OF XT_LIPS,
            WA_LIPS TYPE XT_LIPS,
      
            IT_VBRK TYPE STANDARD TABLE OF XT_VBRK,
            WA_VBRK TYPE XT_VBRK,
            IT_VBRP TYPE STANDARD TABLE OF XT_VBRP,
            WA_VBRP TYPE XT_VBRP,
      
      
            IT_FINAL TYPE STANDARD TABLE OF XT_FINAL,
            WA_FINAL TYPE XT_FINAL.
      
      
      **ALV DECLARATIONS
      DATA: IT_FLDCAT TYPE SLIS_T_FIELDCAT_ALV,
            WA_FLDCAT TYPE SLIS_FIELDCAT_ALV,
            IT_LSTHDR TYPE SLIS_T_LISTHEADER,
            WA_LSTHDR TYPE SLIS_LISTHEADER,
            IT_EVENTS TYPE SLIS_T_EVENT,
            WA_EVENTS TYPE SLIS_ALV_EVENT,
            IT_SORT TYPE SLIS_T_SORTINFO_ALV,
            IT_LAYOUT TYPE SLIS_LAYOUT_ALV.
      
      
      SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
      SELECT-OPTIONS: S_BUKRS FOR V_BUKRS NO INTERVALS NO-EXTENSION,
                      S_VBELN FOR WA_VBAK-VBELN,  "SALES DOCUMENT NUMBER
                      S_KUNNR FOR WA_VBAK-KUNNR,  "SOLD-TO-PARTY
                      S_AUDAT FOR V_AUDAT,      "SALES DOCUMENT DATE
                      S_VKORG FOR V_VKORG,      "SALES ORGANISATION
                      S_VKGRP FOR V_VKGRP,      "SALES GROUP
                      S_SPART FOR V_SPART.      "DIVISION
      SELECTION-SCREEN END OF BLOCK b1.
      
      
      
      *****************SCREEN VALIDATION***************
      
      AT SELECTION-SCREEN.
      
      
      SELECT SINGLE BUKRS FROM T001 INTO V_BUKRS WHERE BUKRS IN S_BUKRS."#EC *
      IF SY-SUBRC <> 0.
      MESSAGE E000(Z_SD2) WITH 'ENTER A VALID COMPANY CODE'.
      ENDIF.
      
      SELECT SINGLE VBELN FROM VBAK INTO
                CORRESPONDING FIELDS OF WA_VBAK WHERE VBELN IN S_VBELN.
      
      IF SY-SUBRC <> 0.
      MESSAGE E000(Z_SD2) WITH 'ENTER VALID SALES DOCUMENT NUMBER'.
      ENDIF.
      
      SELECT SINGLE KUNNR FROM VBAK INTO
                CORRESPONDING FIELDS OF WA_VBAK WHERE KUNNR IN S_KUNNR. "EC *
      
      IF SY-SUBRC <> 0.
      MESSAGE E000(Z_SD2) WITH 'ENTER A VALID CUSTOMER NUMBER'.
      ENDIF.
      
      SELECT SINGLE AUDAT FROM VBAK INTO V_AUDAT WHERE AUDAT IN S_AUDAT."#EC *
      IF SY-SUBRC <> 0.
      MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES DOCUMENT DATE'.
      ENDIF.
      
      SELECT SINGLE VKORG FROM VBAK INTO V_VKORG WHERE VKORG IN S_VKORG."#EC *
      IF SY-SUBRC <> 0.
      MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES ORGANISATION'.
      ENDIF.
      
      SELECT SINGLE VKGRP FROM VBAK INTO V_VKGRP WHERE VKGRP IN S_VKGRP."#EC *
      IF SY-SUBRC <> 0.
      MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES GROUP'.
      ENDIF.
      
      SELECT SINGLE SPART FROM VBAK INTO V_SPART WHERE SPART IN S_SPART."#EC *
      IF SY-SUBRC <> 0.
      MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES DIVISION'.
      ENDIF.
      
      ****************************************************************
      
      PERFORM GET_DATA.
      
      *&---------------------------------------------------------------------
      *
      *&      Form  GET_DATA
      *&---------------------------------------------------------------------
      *
      
      FORM GET_DATA .
      
      
      SELECT VBELN KUNNR
              INTO TABLE IT_VBAK
              FROM VBAK
              WHERE VBELN IN S_VBELN.
      *        BUKRS_VF IN S_BUKRS AND
      *        VKORG IN S_VKORG AND
      *        VKGRP IN S_VKGRP AND
      *        SPART IN S_SPART AND
      *        KUNNR IN S_KUNNR AND
      *        AUDAT IN S_AUDAT.
      
      
      
      IF IT_VBAK[] IS NOT INITIAL.
      SELECT POSNR MATNR KWMENG NETWR
              INTO TABLE IT_VBAP
              FROM VBAP
              FOR ALL ENTRIES IN IT_VBAK
              WHERE VBELN = IT_VBAK-VBELN.
      ENDIF.
      
      IF IT_VBAK[] IS NOT INITIAL.
      SELECT VBELN LFDAT
              INTO TABLE IT_LIKP
              FROM LIKP
              FOR ALL ENTRIES IN IT_VBAK
              WHERE VBELN = IT_VBAK-VBELN.
      ENDIF.
      
      IF IT_VBAP[] IS NOT INITIAL.
      SELECT POSNR LFIMG
              INTO TABLE IT_LIPS
              FROM LIPS
              FOR ALL ENTRIES IN IT_VBAP
              WHERE POSNR = IT_VBAP-POSNR.
      ENDIF.
      
      IF IT_LIKP[] IS NOT INITIAL.
      SELECT VBELN
              INTO TABLE IT_VBRK
              FROM VBRK
              FOR ALL ENTRIES IN IT_LIKP
              WHERE VBELN = IT_LIKP-DELVBELN.
      ENDIF.
      
      IF IT_LIPS[] IS NOT INITIAL.
      SELECT POSNR FKIMG NETWR
              INTO TABLE IT_VBRP
              FROM VBRP
              FOR ALL ENTRIES IN IT_LIPS
              WHERE POSNR = IT_LIPS-DELPOSNR.
      ENDIF.
      
      
      ENDFORM.                    " GET_DATA
      

      Code Formatted by: Alvaro Tejada Galindo on Jan 29, 2008 9:48 AM

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 03:40 PM

    -

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 05:14 PM

    I strictly need help with regard to this program. If needed more information, please let me know. Thank you.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.