Skip to Content
0
Jan 29, 2021 at 03:55 AM

Adding separate column to display subtotal

41 Views

Hi..

I need to add separate column to display the subtotal of netprice field Not in the Net price field.
Can anyone please sugggest me to solve this issue.

Thanks!
Regards
Prashanth





*&---------------------------------------------------------------------*
*& Report YALVREPORT1_1

1107
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT yalvreport1_11107  .



TYPE-POOLS : slis.

TABLES : ekko,ekpo.



TYPES : BEGIN OF ty_ekko,
        ebeln TYPE ekko-ebeln,
        aedat TYPE ekko-aedat,
        bsart TYPE ekko-bsart,
        lifnr TYPE ekko-lifnr,
       END OF ty_ekko.

TYPES : BEGIN OF ty_ekpo,
        ebeln TYPE ekpo-ebeln,
        ebelp TYPE ekpo-ebelp,
        matnr TYPE ekpo-matnr,
        werks TYPE ekpo-werks,
        lgort TYPE ekpo-lgort,
        netwr TYPE ekpo-netwr,
        menge TYPE ekpo-menge,
      END OF ty_ekpo.


TYPES : BEGIN OF ty_final,
        ebeln TYPE ekko-ebeln,
        aedat TYPE ekko-aedat,
        bsart TYPE ekko-bsart,
        lifnr TYPE ekko-lifnr,
        ebelp TYPE ekpo-ebelp,
        matnr TYPE ekpo-matnr,
        werks TYPE ekpo-werks,
        lgort TYPE ekpo-lgort,
        netwr TYPE ekpo-netwr,
       menge TYPE ekpo-menge,
       total_net type ekpo-menge,
  END OF ty_final.

*
DATA : it_ekko TYPE TABLE OF ty_ekko,
       ls_ekko TYPE ty_ekko.

DATA : it_ekpo TYPE TABLE OF ty_ekpo,
       ls_ekpo TYPE ty_ekpo.

DATA : it_final TYPE TABLE OF ty_final,
       ls_final TYPE ty_final.

DATA : it_fcat  TYPE slis_t_fieldcat_alv,

      it_fcat1 type slis_t_fieldcat_alv,
      wa_fcat1 type slis_fieldcat_alv,

       wa_fcat  TYPE slis_fieldcat_alv,
       ls_layout TYPE slis_layout_alv.

DATA: it_event TYPE slis_t_event,
      wa_event LIKE LINE OF it_event.


DATA: it_list TYPE slis_t_listheader,
      wa_list LIKE LINE OF it_list .

 DATA : lt_sort TYPE slis_t_sortinfo_alv,
         ls_sort TYPE slis_sortinfo_alv.
*.
*DATA vc_date(10).
*WRITE sy-datum USING EDIT MASK '23/01/2021    ' TO vc_date.



*       lv_var1(10),
"--->>>>>DATE
    DATA:
          lv_var,
           lv_date(20),
       lv_day(20),
       lv_mon(20),
       lv_year(20),
       lv_out(20),

  """--->>>Time          20210127
      lv_time(20),
      lv_hr(10),
      lv_min(10),
      lv_sec(10),
      lv_out1(10).


"----->>>>>>DATE
lv_date = sy-datum.
lv_day = lv_date+6(2).
lv_mon = lv_date+4(2).
lv_year = lv_date+0(4).
CLEAR lv_date.
CONCATENATE lv_day lv_mon lv_year INTO lv_out SEPARATED BY '-'.

""---->>>>>TIME


lv_time = sy-uzeit.
lv_hr = lv_time+0(2).
lv_min = lv_time+2(2).
lv_sec = lv_time+4(2).
CLEAR lv_time.
CONCATENATE lv_hr lv_min lv_sec INTO lv_out1 SEPARATED BY '-'.
*


*
*  lv_var = 'Developed by : 11107'.




SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.




  SELECT-OPTIONS : s_ebeln FOR ekko-ebeln,
                   s1_aedat FOR ekko-aedat.

  PARAMETERS s2_bsart TYPE ekko-bsart OBLIGATORY.


SELECTION-SCREEN END OF BLOCK b1.


.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-002.
SELECTION-SCREEN BEGIN OF LINE .
SELECTION-SCREEN COMMENT 1(31) TEXT-023 .

SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b2.



INITIALIZATION.
 s_ebeln-sign = 'I'.
  s_ebeln-option = 'BT'.
  s_ebeln-low = '4500000354'.
  s_ebeln-high = '4500000358'.

  APPEND s_ebeln.


   AT SELECTION-SCREEN.

  START-OF-SELECTION.

  PERFORM data_fetch.


  END-OF-SELECTION.

  PERFORM loop.

  PERFORM fcat.

  PERFORM events.

  PERFORM display.







*&---------------------------------------------------------------------*
*&      Form  DATA_FETCH
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM data_fetch .

SELECT
  ebeln
  aedat
  bsart
  lifnr
       FROM ekko INTO TABLE it_ekko WHERE ebeln  IN s_ebeln
                                      AND aedat IN  s1_aedat
                                      AND bsart = s2_bsart.

   IF it_ekko IS NOT INITIAL.
   SELECT
        ebeln
        ebelp
        matnr
        werks
        lgort
        netwr
        menge
          FROM ekpo INTO TABLE it_ekpo
          FOR ALL ENTRIES IN it_ekko
          WHERE ebeln = it_ekko-ebeln.
  ENDIF.


ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  LOOP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM loop .
*   LOOP AT it_ekpo INTO ls_ekpo.
*    ls_final-ebeln = ls_ekpo-ebeln.
*
*
**    ls_final-ebeln = ls_ekpo-ebeln.
*       ls_final-ebelp = ls_ekpo-ebelp.
*       ls_final-matnr = ls_ekpo-matnr.
*       ls_final-netwr = ls_ekpo-netwr.
*       ls_final-lgort = ls_ekpo-lgort.
*       ls_final-menge = ls_ekpo-menge.
*
*    READ TABLE it_ekko INTO ls_ekko WITH KEY ebeln = ls_ekpo-ebeln.
*     IF sy-subrc = 0.
*       ls_final-aedat = ls_ekko-aedat.
*       ls_final-bsart = ls_ekko-bsart.
*        ls_final-lifnr = ls_ekko-lifnr.
*       ENDIF.
*
*       APPEND : ls_final TO it_final.
*       CLEAR :   ls_ekko, ls_ekpo.
*       ENDLOOP.
  "--->>>>>>>>>>>>>>>>
  LOOP AT it_ekko INTO ls_ekko.
    data : lv_total type c,
            lv_total1 type c.

  LOOP AT it_ekpo INTO ls_ekpo WHERE ebeln = ls_ekko-ebeln.
    ls_final-ebeln = ls_ekpo-ebeln.
    ls_final-ebelp = ls_ekpo-ebelp.
    ls_final-matnr = ls_ekpo-matnr.
    ls_final-werks = ls_ekpo-werks.
*    ls_final-netwr = ls_ekpo-netwr.
    ls_final-menge = ls_ekpo-menge.


      ls_final-netwr = ls_ekpo-netwr.
*    ls_final-netwr =   ls_final-netwr + ls_ekpo-netwr.

     lv_total = ls_final-netwr.

*    READ TABLE it_ekko INTO ls_ekko WITH KEY ebeln = ls_ekpo-ebeln.
*    IF sy-subrc = 0.
      ls_final-ebeln = ls_ekko-ebeln.
      ls_final-aedat = ls_ekko-aedat.
      ls_final-bsart = ls_ekko-bsart.
      ls_final-lifnr = ls_ekko-lifnr.

*      ENDIF.
  ENDLOOP.
  endloop.
   APPEND ls_final TO it_final.

   lv_total1 = lv_total.

  clear lv_total.


   lv_total1 =  lv_total1.
   CLEAR: ls_ekpo , ls_final.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fcat .
*DATA : WA_LAYOUT TYPE SLIS_LAYOUT_ALV .

  wa_fcat-col_pos = '1'.

     wa_fcat-fieldname = 'EBELN'.
     wa_fcat-tabname = 'IT_FINAL'.
     wa_fcat-seltext_m = 'PURCHASE DOC.NO'.
      wa_fcat-outputlen = 20.
      wa_fcat-hotspot = 'X'.
     APPEND wa_fcat TO it_fcat.
     CLEAR : wa_fcat.

  wa_fcat-col_pos = '2'.
  wa_fcat-fieldname = 'EBELP'.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-seltext_m = 'ITEM'.
  APPEND wa_fcat TO it_fcat.
  CLEAR : wa_fcat.

  wa_fcat-col_pos = '3'.
  wa_fcat-fieldname = 'MATNR'.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-seltext_m = 'MATERIAL NO'.
   wa_fcat-outputlen = 13.
  APPEND wa_fcat TO it_fcat.
  CLEAR : wa_fcat.


  wa_fcat-col_pos = '4'.
  wa_fcat-fieldname = 'WERKS'.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-seltext_m = 'PLANT'.
  APPEND wa_fcat TO it_fcat.
  CLEAR : wa_fcat.


  wa_fcat-col_pos = '5'.
  wa_fcat-fieldname = 'LGORT'.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-seltext_m = 'STORAGE LOCATION'.
   wa_fcat-outputlen = 20.
  APPEND wa_fcat TO it_fcat.
  CLEAR : wa_fcat.

  wa_fcat-col_pos = '6'.
  wa_fcat-fieldname = 'NETWR'.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-seltext_m = 'NET VALUE'.
*-do_sum = 'X' .    wa_fcat  "NETPRICE
  APPEND wa_fcat TO it_fcat.
  CLEAR : wa_fcat.

  wa_fcat-col_pos = '7'.

  wa_fcat-fieldname = 'MENGE'.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-seltext_m = 'PO QUANTITY'.
   wa_fcat-outputlen = 20.
  APPEND wa_fcat TO it_fcat.
  CLEAR : wa_fcat.

*---->>>>>>>>>.
    wa_fcat-col_pos = '8'.
  wa_fcat-fieldname = 'AEDAT'.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-seltext_m = 'CREATED ON'.
   wa_fcat-outputlen = 20.
  APPEND wa_fcat TO it_fcat.
  CLEAR : wa_fcat.


    wa_fcat-col_pos = '9'.
  wa_fcat-fieldname = 'BSART'.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-seltext_m = 'DOC.TYPE'.
   wa_fcat-outputlen = 20.
  APPEND wa_fcat TO it_fcat.
  CLEAR : wa_fcat.

    wa_fcat-col_pos = '10'.
  wa_fcat-fieldname = 'LIFNR'.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-seltext_m = 'VENDOR'.
   wa_fcat-outputlen = 20.
  APPEND wa_fcat TO it_fcat.
  CLEAR : wa_fcat.


"  -->>>>>>>>>.
    wa_fcat-col_pos = '11'.
  wa_fcat-fieldname = 'NETWR'.
  wa_fcat-tabname = 'IT_FINAL'.
  wa_fcat-seltext_m = 'SUB TOTAL'.
* wa_fcat-emphasize = 'C601'.
 wa_fcat-do_sum = 'X'.
   wa_fcat-outputlen = 20.

  APPEND wa_fcat TO it_fcat.
  CLEAR : wa_fcat.
**
  ls_sort-spos      = 1.
  ls_sort-fieldname = 'EBELN'.

  ls_sort-up       = 'X'.    "ascending order document no.
  ls_sort-subtot    = 'X'.
  APPEND ls_sort TO lt_sort.
  CLEAR : ls_sort.


ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  EVENTS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM events .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
* EXPORTING
*   I_LIST_TYPE           = 0
 IMPORTING
   et_events             = it_event
* EXCEPTIONS
*   LIST_TYPE_WRONG       = 1
*   OTHERS                = 2
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.


  READ TABLE it_event INTO wa_event WITH KEY name = 'TOP_OF_PAGE' .
  wa_event-form = 'TOP' .
  MODIFY  it_event FROM wa_event INDEX sy-tabix .


READ TABLE it_event INTO wa_event WITH KEY name = 'END_OF_LIST' .
  wa_event-form = 'FORM_END_OF_LIST' .
  MODIFY  it_event FROM wa_event INDEX sy-tabix .






ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  TOP
*&---------------------------------------------------------------------*
*       text

*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM top .

  wa_list-info = 'Purchase Order Report'.
  wa_list-typ = 'H' .
  APPEND wa_list TO it_list.

  wa_list-key = 'DATE'.
 wa_list-info =  lv_out .
 wa_list-typ = 'S' .
 APPEND wa_list TO it_list.

 wa_list-key = 'T-C0DE '.
 wa_list-info = 'ZALV_REPORT1' .
  wa_list-typ = 'S' .
  APPEND wa_list TO it_list.


  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary       = it_list
     i_logo                   =  'LOGO4'
*     I_END_OF_LIST_GRID       =
*     I_ALV_FORM               =
            .
REFRESH it_list.


ENDFORM.


FORM form_end_of_list .

  wa_list-key = 'Developed By'.
  wa_list-info =  sy-uname.
  wa_list-typ = 'S' .
  APPEND wa_list TO it_list.


 wa_list-key = 'Last Changed by'.
  wa_list-info = lv_out1.
  wa_list-typ = 'S' .
  APPEND wa_list TO it_list.


  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary       = it_list
*     I_LOGO                   =
*     I_END_OF_LIST_GRID       =
*     I_ALV_FORM               =
            .




ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
    i_callback_program                =  sy-repid
*   I_CALLBACK_PF_STATUS_SET          = ' '
    i_callback_user_command           = 'DISPLAY1'
*   i_callback_top_of_page            = ' top'
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
* i_callback_html_end_of_list       = 'form_end_of_list '
*   I_STRUCTURE_NAME                  =
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
    is_layout                         =  ls_layout
    it_fieldcat                       = it_fcat
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS                 =
   IT_SORT                           = LT_SORT
*   IT_FILTER                         =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*  I_SAVE                            = ' X'
*   IS_VARIANT                        =
    it_events                         =  it_event
*   IT_EVENT_EXIT                     =
*   IS_PRINT                          =
*   IS_REPREP_ID                      =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 = 0
*   I_HTML_HEIGHT_END                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    t_outtab                          = it_final
 EXCEPTIONS
   program_error                     = 1
   OTHERS                            = 2
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.



ENDFORM.



FORM display1 USING r_ucomm  TYPE sy-ucomm
   selfield TYPE slis_selfield.


* IF selfield = 'EBELN'.
  CASE r_ucomm.
    WHEN '&IC1'. "for double click
      READ TABLE it_final INTO ls_final INDEX selfield-tabindex.
*      if selfield-fieldname = 'ebeln'.

*      IF selfield = LS_final-ebeln.

        SET PARAMETER ID 'POD' FIELD ls_final-ebeln.
        CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.

*        ELSEIF selfield = ls_final-matnr.

          SET PARAMETER ID 'MAT' FIELD ls_final-matnr.
        CALL TRANSACTION 'MM02'AND SKIP FIRST SCREEN.



ENDCASE.
ENDFORM.

Attachments