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: 

stock report with date range

Former Member
0 Kudos
185

Hi Experts.

Material stock report (unrestricted, blocked, quality) with in date range.

getting information in T-CODE: MB52 but not in date range.

In mard table i did't find the date for unrestricted, blocked and quality.

from where can i get that information and how should i link all

Need a psudo code for it.

If any one worked on this kind of object plz send me the code.

Points assured..

Regards..

Ravi Reddy.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
47

Hi

Check this sample code hope it will helpfull for you

 *DATA: ED TYPE F.
DATA : ED(15) TYPE N .
TABLES: EKKO, EKBE, EKPO, KONH , KONV ,LFA1 ,ESLL.
TYPE-POOLS: SLIS.

DATA: val1  like konh-vakey.



Data:GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
     G_REPID LIKE SY-REPID,
     G_GRID_TITLE TYPE LVC_TITLE.

Data:G_USER_COMMAND TYPE SLIS_FORMNAME VALUE 'USER_COMMAND'.

DATA:G_TABNAME TYPE SLIS_TABNAME VALUE 'ITAB1',
G_SAVE .

DATA:GS_VARIANT LIKE DISVARIANT.
DATA:LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DATA:GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
     G_SAVE = 'A'.



DATA: BEGIN OF ITAB OCCURS 10,
          EBELN LIKE EKKO-EBELN,
*          LIFNR  like p_vendor,
          LIFNR LIKE EKKO-LIFNR,
          NAME1 LIKE LFA1-NAME1,
          NAME2 LIKE LFA1-NAME2,
*          EBELP LIKE EKBE-EBELP,
          BELNR LIKE EKBE-BELNR,
          VGABE LIKE EKBE-VGABE,
          GJAHR LIKE EKBE-GJAHR,
          KNUMV LIKE EKKO-KNUMV,
          EKORG LIKE EKKO-EKORG,
          BEDAT LIKE EKKO-BEDAT,
*          VAKEY LIKE KONH-VAKEY,

     END OF ITAB.

DATA: BEGIN OF ITAB1 OCCURS 10,
          NAME1 LIKE LFA1-NAME1,
          NAME2 LIKE LFA1-NAME2,
          EBELN LIKE EKPO-EBELN,
          LIFNR LIKE EKKO-LIFNR,
          EBELP LIKE EKPO-EBELP,
*          EBELP LIKE EKBE-EBELP,
          KNUMH LIKE KONH-KNUMH,
          BELNR LIKE EKBE-BELNR,
          MATNR LIKE EKPO-MATNR,
          TXZ01 LIKE EKPO-TXZ01,
          PS_PSP_PNR LIKE EKKN-PS_PSP_PNR,
          EXTROW LIKE ESLL-EXTROW,
          SRVPOS LIKE ESLL-SRVPOS,
          KTEXT1 LIKE ESLL-KTEXT1,
          KOSTL LIKE EKKN-KOSTL,
          NETPR LIKE EKPO-NETPR,
          NETWR LIKE EKPO-NETWR,
          ED1  TYPE p decimals 2,
          KBETR2 LIKE KONV-KBETR,
          KBETR1 LIKE KONV-KBETR,
          KBETR LIKE KONV-KBETR,
*          KBETR3 LIKE KONV-KBETR,
          KWERT LIKE KONV-KWERT, " THIS IS FOR FREIGHT
          KWERT1 LIKE KONV-KWERT, " THIS IS FOR PBXX OR PB00
          KWERT2 LIKE KONV-KWERT, " THIS FOR OTHER CONDITION
          MENGE LIKE EKPO-MENGE,
*          TOTAL(15) type  .
          TOTAL TYPE p decimals 2,
          VAKEY LIKE KONH-VAKEY,
          WERKS LIKE EKPO-WERKS,

          MWSKZ LIKE EKPO-MWSKZ,
          PACKNO LIKE EKPO-PACKNO,
          KNUMV LIKE KONV-KNUMV,

          SUB_PACKNO LIKE ESLL-SUB_PACKNO,



          GJAHR LIKE RSEG-GJAHR,

      END OF ITAB1.


DATA: BEGIN OF ITAB2 OCCURS 10,
         EBELN LIKE EKKN-EBELN,
         EBELP LIKE EKKN-EBELP,
         PS_PSP_PNR LIKE EKKN-PS_PSP_PNR,
         KOSTL      LIKE EKKN-KOSTL,
      END OF ITAB2.

data: begin of itab3 occurs 10,
        KNUMH LIKE KONH-KNUMH,
        KSCHL LIKE KONH-KSCHL,
     end of itab3.

data: begin of itab4 occurs 10,
        KBETR LIKE KONP-KBETR,
      end of itab4.

data: begin of itab5 occurs 10,
        KPOSN LIKE KONV-KPOSN,
        KNUMV LIKE KONV-KNUMV,
        KSCHL LIKE KONV-KSCHL,
        KBETR LIKE KONV-KBETR,
        KWERT LIKE KONV-KWERT, " THIS IS FOR FREIGHT
*          KAWRT LIKE KONV-KAWRT,

     end of itab5.
 DATA: BEGIN OF ITAB6 OCCURS 10,
*          PACKNO LIKE EKPO-PACKNO,
          SUB_PACKNO LIKE ESLL-SUB_PACKNO,
        END OF ITAB6.

 DATA: BEGIN OF ITAB7 OCCURS 10,

       BELNR LIKE RSEG-BELNR,
       GJAHR LIKE RSEG-GJAHR,

 END OF ITAB7.

 DATA: BEGIN OF ITAB8 OCCURS 10,

       SUB_PACKNO LIKE ESLL-SUB_PACKNO,
       SRVPOS LIKE ESLL-SRVPOS,
       EXTROW LIKE ESLL-EXTROW,
       KTEXT1 LIKE ESLL-KTEXT1,

 END OF ITAB8.


******************
*selection-screen
******************
*SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
*SELECTION-SCREEN SKIP 2.
*SELECTION-SCREEN BEGIN OF LINE.
*SELECTION-SCREEN COMMENT 25(23) text-002.
**SELECT-OPTIONS: s_lifnr FOR ekko-lifnr.
*PARAMETERS:p_lifnr LIKE ekko-lifnr obligatory.
*SELECTION-SCREEN END OF LINE.
*
*SELECTION-SCREEN END OF BLOCK b1.
*
START-OF-SELECTION.
  PERFORM get_data.
*  PERFORM field_catalog.
*  PERFORM display_data.

END-OF-SELECTION.

**&---------------------------------------------------------------------
**
**&      Form  display_data
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
*

*
*FORM display_data.
*data: new(15) TYPE N.
*
*
*
*  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
*    EXPORTING
*      i_callback_program = sy-repid
*      it_fieldcat        = int_cat[]
*
*    TABLES
*      t_outtab           = int_out
*    EXCEPTIONS
*      program_error      = 1
*      OTHERS             = 2.
*ENDFORM.                    "display_data





PERFORM GET_DATA.
PERFORM CALL_ALV_GRID.

FORM CALL_ALV_GRID.

PERFORM FIELDCAT_INIT USING GT_FIELDCAT[].

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM                = G_repid


      I_CALLBACK_USER_COMMAND           = G_USER_COMMAND
      I_GRID_TITLE                      = G_GRID_TITLE
      IT_FIELDCAT                       = GT_FIELDCAT[]
      I_DEFAULT                         = 'X'
      I_SAVE                            =  G_SAVE
      IS_VARIANT                        =  Gs_VARIANT
    TABLES
      T_OUTTAB                          = ITAB1.
*
ENDFORM.

FORM FIELDCAT_INIT
       USING RT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.


  CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-seltext_l     = 'Vendo No'.
  LS_FIELDCAT-FIELDNAME     = 'LIFNR'.
  LS_FIELDCAT-REF_FIELDNAME = 'LIFNR'.
  LS_FIELDCAT-REF_TABNAME   = 'EKKO'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.

*
   CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-SELTEXT_L  = 'Vendor Name'.
  LS_FIELDCAT-FIELDNAME     = 'NAME1'.
  LS_FIELDCAT-REF_FIELDNAME = 'NAME1'.
  LS_FIELDCAT-REF_TABNAME   = 'LFA1'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.

* CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-FIELDNAME     = 'NAME2'.
*  LS_FIELDCAT-REF_FIELDNAME = 'NAME2'.
*  LS_FIELDCAT-REF_TABNAME   = 'LFA1'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.
*


  CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-seltext_l   = 'Purchase Document No'.
  LS_FIELDCAT-FIELDNAME     = 'EBELN'.
  LS_FIELDCAT-REF_FIELDNAME = 'EBELN'.
  LS_FIELDCAT-REF_TABNAME   = 'EKKO'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.


*  CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-FIELDNAME     = 'VGABE'.
*  LS_FIELDCAT-REF_FIELDNAME = 'VGABE'.
*  LS_FIELDCAT-REF_TABNAME   = 'EKBE'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.

  CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-SELTEXT_L     = 'Item No'.
  LS_FIELDCAT-FIELDNAME     = 'EBELP'.
  LS_FIELDCAT-REF_FIELDNAME = 'EBELP'.
  LS_FIELDCAT-REF_TABNAME   = 'EKPO'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.
*
*  CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-FIELDNAME     = 'BELNR'.
*  LS_FIELDCAT-REF_FIELDNAME = 'BELNR'.
*  LS_FIELDCAT-REF_TABNAME   = 'EKBE'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.
*

   CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-SELTEXT_L     = 'Document Con'.
  LS_FIELDCAT-FIELDNAME     = 'KNUMH'.
  LS_FIELDCAT-REF_FIELDNAME = 'KNUMH'.
  LS_FIELDCAT-REF_TABNAME   = 'KONH'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.



*   CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-SELTEXT_L = 'Service/Material No'.
*  LS_FIELDCAT-FIELDNAME     = 'MATNR'.
*  LS_FIELDCAT-REF_FIELDNAME = 'MATNR'.
*  LS_FIELDCAT-REF_TABNAME   = 'EKPO'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.
*
*   CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-SELTEXT_L = 'Service / Material description' .
*  LS_FIELDCAT-FIELDNAME     = 'TXZ01'.
*  LS_FIELDCAT-REF_FIELDNAME = 'TXZ01'.
*  LS_FIELDCAT-REF_TABNAME   = 'EKPO'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.

*   CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-SELTEXT_L =  'WBS Element' .
*  LS_FIELDCAT-FIELDNAME     = 'PS_PSP_PNR'.
*  LS_FIELDCAT-REF_FIELDNAME = 'PS_PSP_PNR'.
*  LS_FIELDCAT-REF_TABNAME   = 'EKKN'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.
*

*
*   CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-SELTEXT_L =  'Serial Number' .
*  LS_FIELDCAT-FIELDNAME     = 'EXTROW'.
*  LS_FIELDCAT-REF_FIELDNAME = 'PACKNO'.
*  LS_FIELDCAT-REF_TABNAME   = 'ESLL'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.
*


*
*  CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-SELTEXT_L =  'Service Number' .
*  LS_FIELDCAT-FIELDNAME     = 'SRVPOS'.
*  LS_FIELDCAT-REF_FIELDNAME = 'SRVPOS'.
*  LS_FIELDCAT-REF_TABNAME   = 'ESLL'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.
*

*   CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-SELTEXT_L =  'Dscription' .
*  LS_FIELDCAT-FIELDNAME     = 'KTEXT1'.
*  LS_FIELDCAT-REF_FIELDNAME = 'KTEXT1'.
*  LS_FIELDCAT-REF_TABNAME   = 'ESLL'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.
*




*   CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*    LS_FIELDCAT-SELTEXT_L = 'Cost Center'.
*  LS_FIELDCAT-FIELDNAME     = 'KOSTL'.
*  LS_FIELDCAT-REF_FIELDNAME = 'KOSTL'.
*  LS_FIELDCAT-REF_TABNAME   = 'EKKN'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.

  CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-FIELDNAME     = 'NETWR'.
  LS_FIELDCAT-FIELDNAME     = 'NETPR'.
  LS_FIELDCAT-reptext_ddic = 'Basic'.
*  LS_FIELDCAT-SELTEXT_L    = 'Basic'.
   LS_FIELDCAT-REF_FIELDNAME = 'NETPR'.
  LS_FIELDCAT-REF_TABNAME   = 'EKPO'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.


  CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-FIELDNAME     = 'NETWR'.
*  LS_FIELDCAT-FIELDNAME     = 'NETPR'.
*  LS_FIELDCAT-reptext_ddic = ''.
*  LS_FIELDCAT-SELTEXT_L    = 'Basic'.
   LS_FIELDCAT-REF_FIELDNAME = 'NETWR'.
  LS_FIELDCAT-REF_TABNAME   = 'EKPO'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.


 CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
    LS_FIELDCAT-SELTEXT_L = 'Excise'.
  LS_FIELDCAT-FIELDNAME     = 'ED1'.
  LS_FIELDCAT-REF_FIELDNAME = 'ED1'.
*  LS_FIELDCAT-REF_TABNAME   = 'EKKN'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.

   CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-SELTEXT_L = 'Insurance'.
  LS_FIELDCAT-FIELDNAME     = 'KBETR2'.
    LS_FIELDCAT-REF_FIELDNAME = 'KBETR'.
  LS_FIELDCAT-REF_TABNAME   = 'KONV'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.


CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-SELTEXT_L     = 'Frieght'.
  LS_FIELDCAT-FIELDNAME     = 'KWERT'.
  LS_FIELDCAT-REF_FIELDNAME = 'KWERT'.
  LS_FIELDCAT-REF_TABNAME   = 'KONV'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.



*
* CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-SELTEXT_L     = '' .
*  LS_FIELDCAT-FIELDNAME     = 'KBETR1'.
*  LS_FIELDCAT-REF_FIELDNAME = 'KBETR'.
*  LS_FIELDCAT-REF_TABNAME   = 'KONV'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.

*CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-SELTEXT_L     = 'PBXX'.
*  LS_FIELDCAT-FIELDNAME     = 'KWERT1'.
*  LS_FIELDCAT-REF_FIELDNAME = 'KWERT'.
*  LS_FIELDCAT-REF_TABNAME   = 'KONV'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.



  CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-SELTEXT_L     = 'VAT/ST '.
  LS_FIELDCAT-FIELDNAME     = 'KBETR'.
  LS_FIELDCAT-REF_FIELDNAME = "KBETR".
  LS_FIELDCAT-REF_TABNAME   = 'KONV'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.


 CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-SELTEXT_L     = 'OTHER '.
  LS_FIELDCAT-FIELDNAME     = 'KWERT2'.
  LS_FIELDCAT-REF_FIELDNAME = "KWERT".
  LS_FIELDCAT-REF_TABNAME   = 'KONV'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.


  CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-SELTEXT_L = 'TOTAL'.
  LS_FIELDCAT-FIELDNAME     = 'TOTAL'.
  LS_FIELDCAT-REF_FIELDNAME = 'TOTAL'.
*  LS_FIELDCAT-REF_TABNAME   = 'EKKN'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.



   ENDFORM.                    " FIELDCAT_INIT


   FORM GET_DATA.




   SELECT  A~EBELN A~LIFNR  A~EKORG A~KNUMV B~VGABE  B~GJAHR B~BELNR
           L~NAME1 L~NAME2
        FROM  EKKO AS A
                      INNER JOIN EKBE  AS B ON  B~EBELN = A~EBELN
                      INNER JOIN LFA1 AS L ON L~LIFNR = A~LIFNR
                      INTO  CORRESPONDING
                      FIELDS OF TABLE ITAB.
*                      WHERE B~VGABE = '2'.

SELECT EKPO~EBELN EKPO~EBELP EKPO~MATNR EKPO~TXZ01 EKPO~WERKS
          EKPO~NETWR EKPO~MENGE EKPO~MWSKZ  EKPO~NETPR EKPO~PACKNO
          FROM EKPO
                    INTO CORRESPONDING FIELDS OF TABLE ITAB1
                    FOR ALL ENTRIES IN ITAB
                    WHERE EKPO~EBELN = ITAB-EBELN and
                          EKPO~BUKRS = 'company code'.


   SELECT EKKN~EBELN EKKN~EBELP EKKN~KOSTL EKKN~PS_PSP_PNR
      FROM EKKN
               INTO CORRESPONDING FIELDS OF TABLE ITAB2
               FOR ALL ENTRIES IN ITAB1
               WHERE EKKN~EBELN = ITAB1-EBELN  AND
                     EKKN~EBELP = ITAB1-EBELP.


   SELECT KONV~KNUMV KONV~KSCHL KONV~KBETR KONV~KWERT KONV~KWERT
              KONV~KPOSN
      FROM KONV
          INTO CORRESPONDING FIELDS OF TABLE ITAB5
          WHERE KONV~KNUMV =   ITAB1-KNUMV AND
                KONV~KPOSN = ITAB1-EBELP.



*    SELECT LFA1~NAME1 LFA1~NAME2 FROM LFA1
*    INTO CORRESPONDING FIELDS OF TABLE ITAB1
*    WHERE  LFA1~LIFNR = ITAB-LIFNR.


*  SELECT ESLL~SUB_PACKNO ESLL~SRVPOS
*           ESLL~EXTROW  ESLL~KTEXT1 FROM ESLL
*
*       INTO CORRESPONDING FIELDS OF TABLE ITAB6
*       FOR ALL ENTRIES IN ITAB1
*       WHERE ESLL~PACKNO = ITAB1-PACKNO .

**         SELECT ESLL~SUB_PACKNO FROM ESLL
**       INTO CORRESPONDING FIELDS OF TABLE ITAB6
**       FOR ALL ENTRIES IN ITAB1
**       WHERE ESLL~PACKNO = ITAB1-PACKNO.
*
*        SELECT ESLL~SUB_PACKNO ESLL~SRVPOS
*           ESLL~EXTROW  ESLL~KTEXT1 FROM ESLL
*       INTO CORRESPONDING FIELDS OF TABLE ITAB8
*       FOR ALL ENTRIES IN ITAB6
*       WHERE ESLL~PACKNO = ITAB6-SUB_PACKNO .
*




* SELECT RSEG~BELNR RSEG~GJAHR FROM RSEG
*        INTO CORRESPONDING FIELDS OF TABLE  ITAB7
*        FOR ALL ENTRIES IN ITAB
*        WHERE RSEG~BELNR = ITAB-BELNR AND
*              RSEG~GJAHR = ITAB-GJAHR.
*


*LOOP AT ITAB1.
 LOOP AT ITAB.

              READ TABLE ITAB1 WITH KEY EBELN = ITAB-EBELN.

*         IF ITAB1-EBELN = ITAB-EBELN.
                IF sy-subrc eq 0.

*                          ITAB1-EBELN = ITAB-EBELN.
                          ITAB1-LIFNR = ITAB-LIFNR.
*                          ITAB1-EBELP = ITAB-EBELP.
                          ITAB1-BELNR = ITAB-BELNR.
                          ITAB1-KNUMV = ITAB-KNUMV.
                          ITAB1-NAME1  = ITAB-NAME1.
                          ITAB-NAME2 = ITAB-NAME2.
                          ITAB1-GJAHR = ITAB-GJAHR.

                modify itab1 index   sy-tabix.

        ENDIF.

ENDLOOP.

*LOOP AT ITAB2.
*
*         READ TABLE ITAB1 WITH KEY EBELN = ITAB2-EBELN.
*          IF sy-subrc eq 0.
*              ITAB1-EBELN = ITAB2-EBELN.
*              ITAB1-PS_PSP_PNR = ITAB2-PS_PSP_PNR.
*              ITAB1-KOSTL = ITAB2-KOSTL.
*
*               modify itab1 transporting ps_psp_pnr kostl
*               where ebeln = Itab2-ebeln AND EBELP = ITAB2-EBELP.
*          ENDIF.
*
*ENDLOOP.


LOOP AT ITAB1.

**ON CHANGE OF   ITAB1-ebeln or itab1-ebelp.
*
*     concatenate itab1-werks itab1-lifnr itab1-matnr
*         into val1.
*
*   MOVE VAL1 TO ITAB1-VAKEY.
*   MODIFY ITAB1.
*
*
*
*
*
*
*    SELECT KONH~KNUMH KONH~KSCHL FROM KONH
*        INTO  CORRESPONDING FIELDS OF TABLE ITAB3
*        FOR ALL ENTRIES IN ITAB1
*        WHERE KONH~VAKEY = ITAB1-VAKEY.
*
*
**endon.
**        sort Itab3 by kschl descending.
*
*
**        Select konp-kbetr  from konp into itab4 where
**        KONP~KNUMH = ITAB3-KNUMH AND KONP~KSCHL = ITAB3-KSCHL.
*
*
*
**ON CHANGE OF  ITAB1-ebelp.
*
*
*
**LOOP AT ITAB3
*
*
*
*
**  ON CHANGE OF  ITAB1-ebelp.
*
*              itab1-knumh = itab3-knumh.
*
*
*
**
**              SELECT  KONP~KBETR FROM KONP INTO CORRESPONDING FIELDS
**              OF  TABLE  ITAB4
**              FOR ALL ENTRIES IN ITAB3   WHERE
**              KONP~KNUMH = ITAB3-KNUMH AND KONP~KSCHL = ITAB3-KSCHL .
**
*
*
**              IF ITAB3-KSCHL = 'JMOP' .
**               ED = ITAB4-KBETR / 1000 * ITAB1-NETWR .
**              ENDIF.
**
**             IF ITAB3-KSCHL = 'JEC1'.
**              Itab1-ed1 = ITAB4-KBETR / 1000 * ED.
**              ADD ED TO ITAB1-ED1.
**             modify  ITAB1 transporting ed1.
**             ENDIF.
**
*
*
*
*              IF ITAB3-KSCHL = 'JMOP' .
*               ED = 16 / 100 * ITAB1-NETWR .
*              ENDIF.
*
*
*             IF ITAB3-KSCHL = 'JEC1'.
*              Itab1-ed1 = 2 / 100 * ED.
*              ADD ED TO ITAB1-ED1.
*             modify  ITAB1 transporting ed1.
*             ENDIF.
*
*
*
**
**        ENDLOOP.
*
**endon.

 modify  ITAB1.



*
*endon.





*
  LOOP AT ITAB5.



     IF ITAB5-KSCHL = 'NAVS' OR ITAB5-KSCHL = 'NAVM'.

            ITAB1-KBETR = ITAB5-KBETR.

             modify  ITAB1 transporting KBETR
             where  KNUMV =  ITAB1-KNUMV AND EBELP = ITAB1-EBELP .


           ELSEIF ITAB5-KSCHL = 'FRA1' OR ITAB5-KSCHL = 'FRC1' OR
                ITAB5-KSCHL = 'FRB1'.

                   ITAB1-KWERT = ITAB5-KWERT .

                   modify  ITAB1 transporting KWERT
                   where  KNUMV =  ITAB1-KNUMV AND EBELP = ITAB1-EBELP
.



*               IF ITAB5-KSCHL = 'FRA1'.
*
*                    ITAB1-KBETR1 = ITAB5-KBETR / 1000 * ITAB1-NETWR .
*
*                   modify  ITAB1 transporting KBETR1
*                   where  KNUMV =  ITAB1-KNUMV AND EBELP = ITAB1-EBELP
*.
*
*                 ELSEIF ITAB5-KSCHL = 'FRC1' .
*
*                   ITAB1-KBETR1 = ITAB5-KBETR * ITAB1-MENGE .
*                   modify  ITAB1 transporting KBETR1
*                   where  KNUMV =  ITAB1-KNUMV AND EBELP = ITAB1-EBELP
*.
*
*                 ELSEIF ITAB5-KSCHL = 'FRB1' .
*
*                    ITAB1-KBETR1 = ITAB5-KBETR .
*                   modify  ITAB1 transporting KBETR1
*                   where  KNUMV =  ITAB1-KNUMV AND EBELP = ITAB1-EBELP
*.
*


*              ENDIF.


*           **THIS  CODE IS FOR iNSURANCE  CONDITION


           ELSEIF ITAB5-KSCHL = 'ZGIN' OR ITAB5-KSCHL = 'ZIN2'.


                   ITAB1-KBETR2 = ITAB5-KBETR.
                   modify  ITAB1 transporting KBETR2
                   where  KNUMV =  ITAB1-KNUMV AND EBELP = ITAB1-EBELP
.


*           **THIS  CODE IS FOR PBXX OR PB00  CONDITION

*          ELSEIF ITAB5-KSCHL = 'PBXX' OR ITAB5-KSCHL = 'PB00'.
*
*                   ITAB1-KWERT1 = ITAB5-KWERT1.
*                   modify  ITAB1 transporting KWERT1
*                   where  KNUMV =  ITAB1-KNUMV AND EBELP = ITAB1-EBELP




**          ELSEIF ITAB5-KSCHL = 'JOCM' OR ITAB5-KSCHL = 'RA00' OR
**                 ITAB5-KSCHL = 'RA01' OR ITAB5-KSCHL = 'RB00' OR
**                 ITAB5-KSCHL = 'RC00' OR

**THIS  CODE IS FOR OTHER CONDITION

           ELSEIF ITAB5-KSCHL = 'RL01' OR ITAB5-KSCHL = 'ZA00' OR
                 ITAB5-KSCHL = 'ZA01' OR ITAB5-KSCHL = 'ZAE1' OR
                 ITAB5-KSCHL = 'ZAED' OR

                 ITAB5-KSCHL = 'ZAFR' OR ITAB5-KSCHL = 'ZB00' OR
                 ITAB5-KSCHL = 'ZBCH' OR ITAB5-KSCHL = 'ZBED' OR
                 ITAB5-KSCHL = 'ZC00' OR

                 ITAB5-KSCHL = 'ZCEX' OR ITAB5-KSCHL = 'ZCIF' OR
                 ITAB5-KSCHL = 'ZHC1' OR ITAB5-KSCHL = 'ZHC2' OR
                 ITAB5-KSCHL = 'ZHCT' OR

                 ITAB5-KSCHL = 'ZHCV' OR ITAB5-KSCHL = 'ZJOC' OR
                 ITAB5-KSCHL = 'ZOTH' OR ITAB5-KSCHL = 'ZOTP' OR
                 ITAB5-KSCHL = 'ZOTT' OR

                 ITAB5-KSCHL = 'ZPK1' OR ITAB5-KSCHL = 'ZPK2' OR
                 ITAB5-KSCHL = 'ZPK3' OR ITAB5-KSCHL = 'ZPK4' OR
                 ITAB5-KSCHL = 'ZRPO' OR

                 ITAB5-KSCHL = 'ZSE1' OR ITAB5-KSCHL = 'ZSED' OR
                 ITAB5-KSCHL = 'ZSFR' OR ITAB5-KSCHL = 'ZSTX' OR
                 ITAB5-KSCHL = 'ZTPI' OR

                 ITAB5-KSCHL = 'ZTPV' OR ITAB5-KSCHL = 'ZTRD' OR
                 ITAB5-KSCHL = 'ZWCT'.

                   ITAB1-KWERT2 = ITAB5-KWERT.
                   modify  ITAB1 transporting KWERT2
                   where  KNUMV =  ITAB1-KNUMV AND EBELP = ITAB1-EBELP
.

          modify itab1.
       ENDIF.



 ENDLOOP .



 ITAB1-TOTAL = ITAB1-NETWR + ITAB1-KWERT2 + ITAB1-KWERT + ITAB1-KBETR.



*              ITAB1-TOTAL = ITAB1-NETWR + ITAB1-ED1 + ITAB1-KBETR2 +
*                     ITAB1-KBETR1 + ITAB1-KBETR + ITAB1-KWERT   .
*
                 modify  ITAB1 transporting TOTAL.



LOOP AT ITAB6.

          ITAB1-SUB_PACKNO = ITAB6-SUB_PACKNO.
*           modify  ITAB1.
ENDLOOP.

LOOP AT ITAB7.
        ITAB1-BELNR = ITAB7-BELNR.
        ITAB1-GJAHR = ITAB7-GJAHR.

  ENDLOOP.



LOOP AT ITAB8.
          ITAB1-SUB_PACKNO = ITAB8-SUB_PACKNO.
          ITAB1-SRVPOS  = ITAB8-SRVPOS.
          ITAB1-EXTROW = ITAB8-EXTROW.
          ITAB1-KTEXT1 = ITAB8-KTEXT1.
          modify  ITAB1.
ENDLOOP.


* SELECT ESLL~PACKNO ESLL~SUB_PACKNO ESLL~SRVPOS ESLL~KTEXT1
*          FROM ESLL
*          INTO CORRESPONDING FIELDS OF TABLE ITAB6
*          WHERE ESLL~PACKNO = ITAB1-PACKNO.
*

*
** delete  adjacent  duplicates  from itab1 comparing EBELN .
*
*
*


 modify  ITAB1.



endloop.

sort Itab1 by EBELN Ascending.




        SELECT KONV~KBETR FROM KONV
        INTO ITAB1-KBETR
        WHERE KONV~KSCHL =  'NAVS' OR KONV~KSCHL = 'NAVM'.
        ENDSELECT.

        ITAB1-KBETR = ITAB5-KBETR.



*ENDLOOP.

*ENDLOOP.
*ENDLOOP.

ENDFORM.

Reward all helpfull answers

Regards

Pavan

3 REPLIES 3

Former Member
0 Kudos
47

Hi,

You can try it from MBEWH, MARDH, MCHBH tables.

<b>Reward points</b>

Regards

Former Member
0 Kudos
48

Hi

Check this sample code hope it will helpfull for you

 *DATA: ED TYPE F.
DATA : ED(15) TYPE N .
TABLES: EKKO, EKBE, EKPO, KONH , KONV ,LFA1 ,ESLL.
TYPE-POOLS: SLIS.

DATA: val1  like konh-vakey.



Data:GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
     G_REPID LIKE SY-REPID,
     G_GRID_TITLE TYPE LVC_TITLE.

Data:G_USER_COMMAND TYPE SLIS_FORMNAME VALUE 'USER_COMMAND'.

DATA:G_TABNAME TYPE SLIS_TABNAME VALUE 'ITAB1',
G_SAVE .

DATA:GS_VARIANT LIKE DISVARIANT.
DATA:LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DATA:GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
     G_SAVE = 'A'.



DATA: BEGIN OF ITAB OCCURS 10,
          EBELN LIKE EKKO-EBELN,
*          LIFNR  like p_vendor,
          LIFNR LIKE EKKO-LIFNR,
          NAME1 LIKE LFA1-NAME1,
          NAME2 LIKE LFA1-NAME2,
*          EBELP LIKE EKBE-EBELP,
          BELNR LIKE EKBE-BELNR,
          VGABE LIKE EKBE-VGABE,
          GJAHR LIKE EKBE-GJAHR,
          KNUMV LIKE EKKO-KNUMV,
          EKORG LIKE EKKO-EKORG,
          BEDAT LIKE EKKO-BEDAT,
*          VAKEY LIKE KONH-VAKEY,

     END OF ITAB.

DATA: BEGIN OF ITAB1 OCCURS 10,
          NAME1 LIKE LFA1-NAME1,
          NAME2 LIKE LFA1-NAME2,
          EBELN LIKE EKPO-EBELN,
          LIFNR LIKE EKKO-LIFNR,
          EBELP LIKE EKPO-EBELP,
*          EBELP LIKE EKBE-EBELP,
          KNUMH LIKE KONH-KNUMH,
          BELNR LIKE EKBE-BELNR,
          MATNR LIKE EKPO-MATNR,
          TXZ01 LIKE EKPO-TXZ01,
          PS_PSP_PNR LIKE EKKN-PS_PSP_PNR,
          EXTROW LIKE ESLL-EXTROW,
          SRVPOS LIKE ESLL-SRVPOS,
          KTEXT1 LIKE ESLL-KTEXT1,
          KOSTL LIKE EKKN-KOSTL,
          NETPR LIKE EKPO-NETPR,
          NETWR LIKE EKPO-NETWR,
          ED1  TYPE p decimals 2,
          KBETR2 LIKE KONV-KBETR,
          KBETR1 LIKE KONV-KBETR,
          KBETR LIKE KONV-KBETR,
*          KBETR3 LIKE KONV-KBETR,
          KWERT LIKE KONV-KWERT, " THIS IS FOR FREIGHT
          KWERT1 LIKE KONV-KWERT, " THIS IS FOR PBXX OR PB00
          KWERT2 LIKE KONV-KWERT, " THIS FOR OTHER CONDITION
          MENGE LIKE EKPO-MENGE,
*          TOTAL(15) type  .
          TOTAL TYPE p decimals 2,
          VAKEY LIKE KONH-VAKEY,
          WERKS LIKE EKPO-WERKS,

          MWSKZ LIKE EKPO-MWSKZ,
          PACKNO LIKE EKPO-PACKNO,
          KNUMV LIKE KONV-KNUMV,

          SUB_PACKNO LIKE ESLL-SUB_PACKNO,



          GJAHR LIKE RSEG-GJAHR,

      END OF ITAB1.


DATA: BEGIN OF ITAB2 OCCURS 10,
         EBELN LIKE EKKN-EBELN,
         EBELP LIKE EKKN-EBELP,
         PS_PSP_PNR LIKE EKKN-PS_PSP_PNR,
         KOSTL      LIKE EKKN-KOSTL,
      END OF ITAB2.

data: begin of itab3 occurs 10,
        KNUMH LIKE KONH-KNUMH,
        KSCHL LIKE KONH-KSCHL,
     end of itab3.

data: begin of itab4 occurs 10,
        KBETR LIKE KONP-KBETR,
      end of itab4.

data: begin of itab5 occurs 10,
        KPOSN LIKE KONV-KPOSN,
        KNUMV LIKE KONV-KNUMV,
        KSCHL LIKE KONV-KSCHL,
        KBETR LIKE KONV-KBETR,
        KWERT LIKE KONV-KWERT, " THIS IS FOR FREIGHT
*          KAWRT LIKE KONV-KAWRT,

     end of itab5.
 DATA: BEGIN OF ITAB6 OCCURS 10,
*          PACKNO LIKE EKPO-PACKNO,
          SUB_PACKNO LIKE ESLL-SUB_PACKNO,
        END OF ITAB6.

 DATA: BEGIN OF ITAB7 OCCURS 10,

       BELNR LIKE RSEG-BELNR,
       GJAHR LIKE RSEG-GJAHR,

 END OF ITAB7.

 DATA: BEGIN OF ITAB8 OCCURS 10,

       SUB_PACKNO LIKE ESLL-SUB_PACKNO,
       SRVPOS LIKE ESLL-SRVPOS,
       EXTROW LIKE ESLL-EXTROW,
       KTEXT1 LIKE ESLL-KTEXT1,

 END OF ITAB8.


******************
*selection-screen
******************
*SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
*SELECTION-SCREEN SKIP 2.
*SELECTION-SCREEN BEGIN OF LINE.
*SELECTION-SCREEN COMMENT 25(23) text-002.
**SELECT-OPTIONS: s_lifnr FOR ekko-lifnr.
*PARAMETERS:p_lifnr LIKE ekko-lifnr obligatory.
*SELECTION-SCREEN END OF LINE.
*
*SELECTION-SCREEN END OF BLOCK b1.
*
START-OF-SELECTION.
  PERFORM get_data.
*  PERFORM field_catalog.
*  PERFORM display_data.

END-OF-SELECTION.

**&---------------------------------------------------------------------
**
**&      Form  display_data
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
*

*
*FORM display_data.
*data: new(15) TYPE N.
*
*
*
*  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
*    EXPORTING
*      i_callback_program = sy-repid
*      it_fieldcat        = int_cat[]
*
*    TABLES
*      t_outtab           = int_out
*    EXCEPTIONS
*      program_error      = 1
*      OTHERS             = 2.
*ENDFORM.                    "display_data





PERFORM GET_DATA.
PERFORM CALL_ALV_GRID.

FORM CALL_ALV_GRID.

PERFORM FIELDCAT_INIT USING GT_FIELDCAT[].

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM                = G_repid


      I_CALLBACK_USER_COMMAND           = G_USER_COMMAND
      I_GRID_TITLE                      = G_GRID_TITLE
      IT_FIELDCAT                       = GT_FIELDCAT[]
      I_DEFAULT                         = 'X'
      I_SAVE                            =  G_SAVE
      IS_VARIANT                        =  Gs_VARIANT
    TABLES
      T_OUTTAB                          = ITAB1.
*
ENDFORM.

FORM FIELDCAT_INIT
       USING RT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.


  CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-seltext_l     = 'Vendo No'.
  LS_FIELDCAT-FIELDNAME     = 'LIFNR'.
  LS_FIELDCAT-REF_FIELDNAME = 'LIFNR'.
  LS_FIELDCAT-REF_TABNAME   = 'EKKO'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.

*
   CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-SELTEXT_L  = 'Vendor Name'.
  LS_FIELDCAT-FIELDNAME     = 'NAME1'.
  LS_FIELDCAT-REF_FIELDNAME = 'NAME1'.
  LS_FIELDCAT-REF_TABNAME   = 'LFA1'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.

* CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-FIELDNAME     = 'NAME2'.
*  LS_FIELDCAT-REF_FIELDNAME = 'NAME2'.
*  LS_FIELDCAT-REF_TABNAME   = 'LFA1'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.
*


  CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-seltext_l   = 'Purchase Document No'.
  LS_FIELDCAT-FIELDNAME     = 'EBELN'.
  LS_FIELDCAT-REF_FIELDNAME = 'EBELN'.
  LS_FIELDCAT-REF_TABNAME   = 'EKKO'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.


*  CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-FIELDNAME     = 'VGABE'.
*  LS_FIELDCAT-REF_FIELDNAME = 'VGABE'.
*  LS_FIELDCAT-REF_TABNAME   = 'EKBE'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.

  CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-SELTEXT_L     = 'Item No'.
  LS_FIELDCAT-FIELDNAME     = 'EBELP'.
  LS_FIELDCAT-REF_FIELDNAME = 'EBELP'.
  LS_FIELDCAT-REF_TABNAME   = 'EKPO'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.
*
*  CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-FIELDNAME     = 'BELNR'.
*  LS_FIELDCAT-REF_FIELDNAME = 'BELNR'.
*  LS_FIELDCAT-REF_TABNAME   = 'EKBE'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.
*

   CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-SELTEXT_L     = 'Document Con'.
  LS_FIELDCAT-FIELDNAME     = 'KNUMH'.
  LS_FIELDCAT-REF_FIELDNAME = 'KNUMH'.
  LS_FIELDCAT-REF_TABNAME   = 'KONH'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.



*   CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-SELTEXT_L = 'Service/Material No'.
*  LS_FIELDCAT-FIELDNAME     = 'MATNR'.
*  LS_FIELDCAT-REF_FIELDNAME = 'MATNR'.
*  LS_FIELDCAT-REF_TABNAME   = 'EKPO'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.
*
*   CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-SELTEXT_L = 'Service / Material description' .
*  LS_FIELDCAT-FIELDNAME     = 'TXZ01'.
*  LS_FIELDCAT-REF_FIELDNAME = 'TXZ01'.
*  LS_FIELDCAT-REF_TABNAME   = 'EKPO'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.

*   CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-SELTEXT_L =  'WBS Element' .
*  LS_FIELDCAT-FIELDNAME     = 'PS_PSP_PNR'.
*  LS_FIELDCAT-REF_FIELDNAME = 'PS_PSP_PNR'.
*  LS_FIELDCAT-REF_TABNAME   = 'EKKN'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.
*

*
*   CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-SELTEXT_L =  'Serial Number' .
*  LS_FIELDCAT-FIELDNAME     = 'EXTROW'.
*  LS_FIELDCAT-REF_FIELDNAME = 'PACKNO'.
*  LS_FIELDCAT-REF_TABNAME   = 'ESLL'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.
*


*
*  CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-SELTEXT_L =  'Service Number' .
*  LS_FIELDCAT-FIELDNAME     = 'SRVPOS'.
*  LS_FIELDCAT-REF_FIELDNAME = 'SRVPOS'.
*  LS_FIELDCAT-REF_TABNAME   = 'ESLL'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.
*

*   CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-SELTEXT_L =  'Dscription' .
*  LS_FIELDCAT-FIELDNAME     = 'KTEXT1'.
*  LS_FIELDCAT-REF_FIELDNAME = 'KTEXT1'.
*  LS_FIELDCAT-REF_TABNAME   = 'ESLL'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.
*




*   CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*    LS_FIELDCAT-SELTEXT_L = 'Cost Center'.
*  LS_FIELDCAT-FIELDNAME     = 'KOSTL'.
*  LS_FIELDCAT-REF_FIELDNAME = 'KOSTL'.
*  LS_FIELDCAT-REF_TABNAME   = 'EKKN'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.

  CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-FIELDNAME     = 'NETWR'.
  LS_FIELDCAT-FIELDNAME     = 'NETPR'.
  LS_FIELDCAT-reptext_ddic = 'Basic'.
*  LS_FIELDCAT-SELTEXT_L    = 'Basic'.
   LS_FIELDCAT-REF_FIELDNAME = 'NETPR'.
  LS_FIELDCAT-REF_TABNAME   = 'EKPO'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.


  CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-FIELDNAME     = 'NETWR'.
*  LS_FIELDCAT-FIELDNAME     = 'NETPR'.
*  LS_FIELDCAT-reptext_ddic = ''.
*  LS_FIELDCAT-SELTEXT_L    = 'Basic'.
   LS_FIELDCAT-REF_FIELDNAME = 'NETWR'.
  LS_FIELDCAT-REF_TABNAME   = 'EKPO'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.


 CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
    LS_FIELDCAT-SELTEXT_L = 'Excise'.
  LS_FIELDCAT-FIELDNAME     = 'ED1'.
  LS_FIELDCAT-REF_FIELDNAME = 'ED1'.
*  LS_FIELDCAT-REF_TABNAME   = 'EKKN'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.

   CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-SELTEXT_L = 'Insurance'.
  LS_FIELDCAT-FIELDNAME     = 'KBETR2'.
    LS_FIELDCAT-REF_FIELDNAME = 'KBETR'.
  LS_FIELDCAT-REF_TABNAME   = 'KONV'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.


CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-SELTEXT_L     = 'Frieght'.
  LS_FIELDCAT-FIELDNAME     = 'KWERT'.
  LS_FIELDCAT-REF_FIELDNAME = 'KWERT'.
  LS_FIELDCAT-REF_TABNAME   = 'KONV'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.



*
* CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-SELTEXT_L     = '' .
*  LS_FIELDCAT-FIELDNAME     = 'KBETR1'.
*  LS_FIELDCAT-REF_FIELDNAME = 'KBETR'.
*  LS_FIELDCAT-REF_TABNAME   = 'KONV'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.

*CLEAR LS_FIELDCAT.
*  LS_FIELDCAT-TABNAME       = G_TABNAME.
*  LS_FIELDCAT-SELTEXT_L     = 'PBXX'.
*  LS_FIELDCAT-FIELDNAME     = 'KWERT1'.
*  LS_FIELDCAT-REF_FIELDNAME = 'KWERT'.
*  LS_FIELDCAT-REF_TABNAME   = 'KONV'.
*  APPEND LS_FIELDCAT TO  RT_FIELDCAT.



  CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-SELTEXT_L     = 'VAT/ST '.
  LS_FIELDCAT-FIELDNAME     = 'KBETR'.
  LS_FIELDCAT-REF_FIELDNAME = "KBETR".
  LS_FIELDCAT-REF_TABNAME   = 'KONV'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.


 CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-SELTEXT_L     = 'OTHER '.
  LS_FIELDCAT-FIELDNAME     = 'KWERT2'.
  LS_FIELDCAT-REF_FIELDNAME = "KWERT".
  LS_FIELDCAT-REF_TABNAME   = 'KONV'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.


  CLEAR LS_FIELDCAT.
  LS_FIELDCAT-TABNAME       = G_TABNAME.
  LS_FIELDCAT-SELTEXT_L = 'TOTAL'.
  LS_FIELDCAT-FIELDNAME     = 'TOTAL'.
  LS_FIELDCAT-REF_FIELDNAME = 'TOTAL'.
*  LS_FIELDCAT-REF_TABNAME   = 'EKKN'.
  APPEND LS_FIELDCAT TO  RT_FIELDCAT.



   ENDFORM.                    " FIELDCAT_INIT


   FORM GET_DATA.




   SELECT  A~EBELN A~LIFNR  A~EKORG A~KNUMV B~VGABE  B~GJAHR B~BELNR
           L~NAME1 L~NAME2
        FROM  EKKO AS A
                      INNER JOIN EKBE  AS B ON  B~EBELN = A~EBELN
                      INNER JOIN LFA1 AS L ON L~LIFNR = A~LIFNR
                      INTO  CORRESPONDING
                      FIELDS OF TABLE ITAB.
*                      WHERE B~VGABE = '2'.

SELECT EKPO~EBELN EKPO~EBELP EKPO~MATNR EKPO~TXZ01 EKPO~WERKS
          EKPO~NETWR EKPO~MENGE EKPO~MWSKZ  EKPO~NETPR EKPO~PACKNO
          FROM EKPO
                    INTO CORRESPONDING FIELDS OF TABLE ITAB1
                    FOR ALL ENTRIES IN ITAB
                    WHERE EKPO~EBELN = ITAB-EBELN and
                          EKPO~BUKRS = 'company code'.


   SELECT EKKN~EBELN EKKN~EBELP EKKN~KOSTL EKKN~PS_PSP_PNR
      FROM EKKN
               INTO CORRESPONDING FIELDS OF TABLE ITAB2
               FOR ALL ENTRIES IN ITAB1
               WHERE EKKN~EBELN = ITAB1-EBELN  AND
                     EKKN~EBELP = ITAB1-EBELP.


   SELECT KONV~KNUMV KONV~KSCHL KONV~KBETR KONV~KWERT KONV~KWERT
              KONV~KPOSN
      FROM KONV
          INTO CORRESPONDING FIELDS OF TABLE ITAB5
          WHERE KONV~KNUMV =   ITAB1-KNUMV AND
                KONV~KPOSN = ITAB1-EBELP.



*    SELECT LFA1~NAME1 LFA1~NAME2 FROM LFA1
*    INTO CORRESPONDING FIELDS OF TABLE ITAB1
*    WHERE  LFA1~LIFNR = ITAB-LIFNR.


*  SELECT ESLL~SUB_PACKNO ESLL~SRVPOS
*           ESLL~EXTROW  ESLL~KTEXT1 FROM ESLL
*
*       INTO CORRESPONDING FIELDS OF TABLE ITAB6
*       FOR ALL ENTRIES IN ITAB1
*       WHERE ESLL~PACKNO = ITAB1-PACKNO .

**         SELECT ESLL~SUB_PACKNO FROM ESLL
**       INTO CORRESPONDING FIELDS OF TABLE ITAB6
**       FOR ALL ENTRIES IN ITAB1
**       WHERE ESLL~PACKNO = ITAB1-PACKNO.
*
*        SELECT ESLL~SUB_PACKNO ESLL~SRVPOS
*           ESLL~EXTROW  ESLL~KTEXT1 FROM ESLL
*       INTO CORRESPONDING FIELDS OF TABLE ITAB8
*       FOR ALL ENTRIES IN ITAB6
*       WHERE ESLL~PACKNO = ITAB6-SUB_PACKNO .
*




* SELECT RSEG~BELNR RSEG~GJAHR FROM RSEG
*        INTO CORRESPONDING FIELDS OF TABLE  ITAB7
*        FOR ALL ENTRIES IN ITAB
*        WHERE RSEG~BELNR = ITAB-BELNR AND
*              RSEG~GJAHR = ITAB-GJAHR.
*


*LOOP AT ITAB1.
 LOOP AT ITAB.

              READ TABLE ITAB1 WITH KEY EBELN = ITAB-EBELN.

*         IF ITAB1-EBELN = ITAB-EBELN.
                IF sy-subrc eq 0.

*                          ITAB1-EBELN = ITAB-EBELN.
                          ITAB1-LIFNR = ITAB-LIFNR.
*                          ITAB1-EBELP = ITAB-EBELP.
                          ITAB1-BELNR = ITAB-BELNR.
                          ITAB1-KNUMV = ITAB-KNUMV.
                          ITAB1-NAME1  = ITAB-NAME1.
                          ITAB-NAME2 = ITAB-NAME2.
                          ITAB1-GJAHR = ITAB-GJAHR.

                modify itab1 index   sy-tabix.

        ENDIF.

ENDLOOP.

*LOOP AT ITAB2.
*
*         READ TABLE ITAB1 WITH KEY EBELN = ITAB2-EBELN.
*          IF sy-subrc eq 0.
*              ITAB1-EBELN = ITAB2-EBELN.
*              ITAB1-PS_PSP_PNR = ITAB2-PS_PSP_PNR.
*              ITAB1-KOSTL = ITAB2-KOSTL.
*
*               modify itab1 transporting ps_psp_pnr kostl
*               where ebeln = Itab2-ebeln AND EBELP = ITAB2-EBELP.
*          ENDIF.
*
*ENDLOOP.


LOOP AT ITAB1.

**ON CHANGE OF   ITAB1-ebeln or itab1-ebelp.
*
*     concatenate itab1-werks itab1-lifnr itab1-matnr
*         into val1.
*
*   MOVE VAL1 TO ITAB1-VAKEY.
*   MODIFY ITAB1.
*
*
*
*
*
*
*    SELECT KONH~KNUMH KONH~KSCHL FROM KONH
*        INTO  CORRESPONDING FIELDS OF TABLE ITAB3
*        FOR ALL ENTRIES IN ITAB1
*        WHERE KONH~VAKEY = ITAB1-VAKEY.
*
*
**endon.
**        sort Itab3 by kschl descending.
*
*
**        Select konp-kbetr  from konp into itab4 where
**        KONP~KNUMH = ITAB3-KNUMH AND KONP~KSCHL = ITAB3-KSCHL.
*
*
*
**ON CHANGE OF  ITAB1-ebelp.
*
*
*
**LOOP AT ITAB3
*
*
*
*
**  ON CHANGE OF  ITAB1-ebelp.
*
*              itab1-knumh = itab3-knumh.
*
*
*
**
**              SELECT  KONP~KBETR FROM KONP INTO CORRESPONDING FIELDS
**              OF  TABLE  ITAB4
**              FOR ALL ENTRIES IN ITAB3   WHERE
**              KONP~KNUMH = ITAB3-KNUMH AND KONP~KSCHL = ITAB3-KSCHL .
**
*
*
**              IF ITAB3-KSCHL = 'JMOP' .
**               ED = ITAB4-KBETR / 1000 * ITAB1-NETWR .
**              ENDIF.
**
**             IF ITAB3-KSCHL = 'JEC1'.
**              Itab1-ed1 = ITAB4-KBETR / 1000 * ED.
**              ADD ED TO ITAB1-ED1.
**             modify  ITAB1 transporting ed1.
**             ENDIF.
**
*
*
*
*              IF ITAB3-KSCHL = 'JMOP' .
*               ED = 16 / 100 * ITAB1-NETWR .
*              ENDIF.
*
*
*             IF ITAB3-KSCHL = 'JEC1'.
*              Itab1-ed1 = 2 / 100 * ED.
*              ADD ED TO ITAB1-ED1.
*             modify  ITAB1 transporting ed1.
*             ENDIF.
*
*
*
**
**        ENDLOOP.
*
**endon.

 modify  ITAB1.



*
*endon.





*
  LOOP AT ITAB5.



     IF ITAB5-KSCHL = 'NAVS' OR ITAB5-KSCHL = 'NAVM'.

            ITAB1-KBETR = ITAB5-KBETR.

             modify  ITAB1 transporting KBETR
             where  KNUMV =  ITAB1-KNUMV AND EBELP = ITAB1-EBELP .


           ELSEIF ITAB5-KSCHL = 'FRA1' OR ITAB5-KSCHL = 'FRC1' OR
                ITAB5-KSCHL = 'FRB1'.

                   ITAB1-KWERT = ITAB5-KWERT .

                   modify  ITAB1 transporting KWERT
                   where  KNUMV =  ITAB1-KNUMV AND EBELP = ITAB1-EBELP
.



*               IF ITAB5-KSCHL = 'FRA1'.
*
*                    ITAB1-KBETR1 = ITAB5-KBETR / 1000 * ITAB1-NETWR .
*
*                   modify  ITAB1 transporting KBETR1
*                   where  KNUMV =  ITAB1-KNUMV AND EBELP = ITAB1-EBELP
*.
*
*                 ELSEIF ITAB5-KSCHL = 'FRC1' .
*
*                   ITAB1-KBETR1 = ITAB5-KBETR * ITAB1-MENGE .
*                   modify  ITAB1 transporting KBETR1
*                   where  KNUMV =  ITAB1-KNUMV AND EBELP = ITAB1-EBELP
*.
*
*                 ELSEIF ITAB5-KSCHL = 'FRB1' .
*
*                    ITAB1-KBETR1 = ITAB5-KBETR .
*                   modify  ITAB1 transporting KBETR1
*                   where  KNUMV =  ITAB1-KNUMV AND EBELP = ITAB1-EBELP
*.
*


*              ENDIF.


*           **THIS  CODE IS FOR iNSURANCE  CONDITION


           ELSEIF ITAB5-KSCHL = 'ZGIN' OR ITAB5-KSCHL = 'ZIN2'.


                   ITAB1-KBETR2 = ITAB5-KBETR.
                   modify  ITAB1 transporting KBETR2
                   where  KNUMV =  ITAB1-KNUMV AND EBELP = ITAB1-EBELP
.


*           **THIS  CODE IS FOR PBXX OR PB00  CONDITION

*          ELSEIF ITAB5-KSCHL = 'PBXX' OR ITAB5-KSCHL = 'PB00'.
*
*                   ITAB1-KWERT1 = ITAB5-KWERT1.
*                   modify  ITAB1 transporting KWERT1
*                   where  KNUMV =  ITAB1-KNUMV AND EBELP = ITAB1-EBELP




**          ELSEIF ITAB5-KSCHL = 'JOCM' OR ITAB5-KSCHL = 'RA00' OR
**                 ITAB5-KSCHL = 'RA01' OR ITAB5-KSCHL = 'RB00' OR
**                 ITAB5-KSCHL = 'RC00' OR

**THIS  CODE IS FOR OTHER CONDITION

           ELSEIF ITAB5-KSCHL = 'RL01' OR ITAB5-KSCHL = 'ZA00' OR
                 ITAB5-KSCHL = 'ZA01' OR ITAB5-KSCHL = 'ZAE1' OR
                 ITAB5-KSCHL = 'ZAED' OR

                 ITAB5-KSCHL = 'ZAFR' OR ITAB5-KSCHL = 'ZB00' OR
                 ITAB5-KSCHL = 'ZBCH' OR ITAB5-KSCHL = 'ZBED' OR
                 ITAB5-KSCHL = 'ZC00' OR

                 ITAB5-KSCHL = 'ZCEX' OR ITAB5-KSCHL = 'ZCIF' OR
                 ITAB5-KSCHL = 'ZHC1' OR ITAB5-KSCHL = 'ZHC2' OR
                 ITAB5-KSCHL = 'ZHCT' OR

                 ITAB5-KSCHL = 'ZHCV' OR ITAB5-KSCHL = 'ZJOC' OR
                 ITAB5-KSCHL = 'ZOTH' OR ITAB5-KSCHL = 'ZOTP' OR
                 ITAB5-KSCHL = 'ZOTT' OR

                 ITAB5-KSCHL = 'ZPK1' OR ITAB5-KSCHL = 'ZPK2' OR
                 ITAB5-KSCHL = 'ZPK3' OR ITAB5-KSCHL = 'ZPK4' OR
                 ITAB5-KSCHL = 'ZRPO' OR

                 ITAB5-KSCHL = 'ZSE1' OR ITAB5-KSCHL = 'ZSED' OR
                 ITAB5-KSCHL = 'ZSFR' OR ITAB5-KSCHL = 'ZSTX' OR
                 ITAB5-KSCHL = 'ZTPI' OR

                 ITAB5-KSCHL = 'ZTPV' OR ITAB5-KSCHL = 'ZTRD' OR
                 ITAB5-KSCHL = 'ZWCT'.

                   ITAB1-KWERT2 = ITAB5-KWERT.
                   modify  ITAB1 transporting KWERT2
                   where  KNUMV =  ITAB1-KNUMV AND EBELP = ITAB1-EBELP
.

          modify itab1.
       ENDIF.



 ENDLOOP .



 ITAB1-TOTAL = ITAB1-NETWR + ITAB1-KWERT2 + ITAB1-KWERT + ITAB1-KBETR.



*              ITAB1-TOTAL = ITAB1-NETWR + ITAB1-ED1 + ITAB1-KBETR2 +
*                     ITAB1-KBETR1 + ITAB1-KBETR + ITAB1-KWERT   .
*
                 modify  ITAB1 transporting TOTAL.



LOOP AT ITAB6.

          ITAB1-SUB_PACKNO = ITAB6-SUB_PACKNO.
*           modify  ITAB1.
ENDLOOP.

LOOP AT ITAB7.
        ITAB1-BELNR = ITAB7-BELNR.
        ITAB1-GJAHR = ITAB7-GJAHR.

  ENDLOOP.



LOOP AT ITAB8.
          ITAB1-SUB_PACKNO = ITAB8-SUB_PACKNO.
          ITAB1-SRVPOS  = ITAB8-SRVPOS.
          ITAB1-EXTROW = ITAB8-EXTROW.
          ITAB1-KTEXT1 = ITAB8-KTEXT1.
          modify  ITAB1.
ENDLOOP.


* SELECT ESLL~PACKNO ESLL~SUB_PACKNO ESLL~SRVPOS ESLL~KTEXT1
*          FROM ESLL
*          INTO CORRESPONDING FIELDS OF TABLE ITAB6
*          WHERE ESLL~PACKNO = ITAB1-PACKNO.
*

*
** delete  adjacent  duplicates  from itab1 comparing EBELN .
*
*
*


 modify  ITAB1.



endloop.

sort Itab1 by EBELN Ascending.




        SELECT KONV~KBETR FROM KONV
        INTO ITAB1-KBETR
        WHERE KONV~KSCHL =  'NAVS' OR KONV~KSCHL = 'NAVM'.
        ENDSELECT.

        ITAB1-KBETR = ITAB5-KBETR.



*ENDLOOP.

*ENDLOOP.
*ENDLOOP.

ENDFORM.

Reward all helpfull answers

Regards

Pavan

kesavadas_thekkillath
Active Contributor
0 Kudos
47

Try MB5B...Hope so it solves

reward if useful