ALV report with internal in field symbol

Hi Shifu ABAP,
I have ALV report.
My problem is when I tried to do sum using the sum icon. I got a message 'desired operation cannot be performed for column 'Dignostic delay'. Is it because I used field symbol, then when I clicked on the column it didn't recorgnise the field.
FYI.
1)The internal table for my ALV report is stored in field symbol.
2)I dont have a problem to display the report.
3)I had to set 'do_sum' at ALV field category, still doesn't work
My source code to define ALV category.
loop at i_qpcd into wa_qpcd.
CLEAR ls_fieldcat2.
ls_fieldcat2-col_pos = pos2.
ls_fieldcat2-fieldname = wa_qpcd-code.
ls_fieldcat2-reptext_ddic = wa_qpcd-desc.
ls_fieldcat2-just = 'C'.
ls_fieldcat2-do_sum = 'X'.
APPEND ls_fieldcat2 TO gt_fieldcat2.
endloop.
My source code call the ALV FM
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
     i_callback_program         = 'ZMPMR001_Q1OOT'
     i_callback_pf_status_set = 'PF_STATUS_SET'
     is_layout                        = ls_layout
     it_fieldcat                       = gt_fieldcat2[]
     is_print                          = ls_print
TABLES
     t_outtab                         = <l_table>
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.
Thanks a lot in advance for your attention.

my situation is like this, declare the internal tble
1) data : begin of itab occurs 0,          
            code like qpcd-code,
            desc like QPCT-KURZTEXT,
          end of itab.
2) populate the itab like this
code           desc
01              desc 1
02              desc 2
03              desc 3
3) take the selected record converted it into new dynamic internal table using field symbol declare as table, now the component of this new table are 01, 02 and 03.
4) populate the new table with some data, so technically my new table structure will be like this
01         02         03
1           0          1
0           0          3
2           2          2
5) display the new table in ALV report, in ALV I tried to sum-up each of column.
6) Question : HOW can I convert the componet 01, 02 and 03 as an integer/numeric field.
Regards
Nislina

Similar Messages

  • Create a Procedural ALV Report with editable fields and save the changes

    Hi,
    I am new to ABAP. I have created a Procedural ALV Report with 3 fields. I want to make 2 fields editable. When executed, if the fields are modified, I want to save the changes. All this I want to do without using OO concepts. Please help . Also, I checked out the forum and also the examples
    BCALV_TEST_GRID_EDIT_01
    BCALV_TEST_GRID_EDIT_02
    BCALV_TEST_GRID_EDIT_04_FORMS
    BCALV_TEST_GRID_EDITABLE
    BCALV_EDIT_01
    BCALV_EDIT_02
    BCALV_EDIT_03
    BCALV_EDIT_04
    BCALV_EDIT_05
    BCALV_EDIT_06
    BCALV_EDIT_07
    BCALV_EDIT_08
    BCALV_FULLSCREEN_GRID_EDIT
    But all these are using OO Concepts.
    Please help.
    Regards,
    Smruthi

    TABLES:     ekko.
    TYPE-POOLS: slis.                                 "ALV Declarations
    *Data Declaration
    TYPES: BEGIN OF t_ekko,
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      statu TYPE ekpo-statu,
      aedat TYPE ekpo-aedat,
      matnr TYPE ekpo-matnr,
      menge TYPE ekpo-menge,
      meins TYPE ekpo-meins,
      netpr TYPE ekpo-netpr,
      peinh TYPE ekpo-peinh,
      line_color(4) TYPE c,     "Used to store row color attributes
    END OF t_ekko.
    DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
          wa_ekko TYPE t_ekko.
    *ALV data declarations
    DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
          gd_tab_group TYPE slis_t_sp_group_alv,
          gd_layout    TYPE slis_layout_alv,
          gd_repid     LIKE sy-repid.
    START-OF-SELECTION.
      PERFORM data_retrieval.
      PERFORM build_fieldcatalog.
      PERFORM build_layout.
      PERFORM display_alv_report.
    *&      Form  BUILD_FIELDCATALOG
          Build Fieldcatalog for ALV Report
    FORM build_fieldcatalog.
      fieldcatalog-fieldname   = 'EBELN'.
      fieldcatalog-seltext_m   = 'Purchase Order'.
      fieldcatalog-col_pos     = 0.
      fieldcatalog-outputlen   = 10.
      fieldcatalog-emphasize   = 'X'.
      fieldcatalog-key         = 'X'.
    fieldcatalog-do_sum      = 'X'.
    fieldcatalog-no_zero     = 'X'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'EBELP'.
      fieldcatalog-seltext_m   = 'PO Item'.
      fieldcatalog-col_pos     = 1.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'STATU'.
      fieldcatalog-seltext_m   = 'Status'.
      fieldcatalog-col_pos     = 2.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'AEDAT'.
      fieldcatalog-seltext_m   = 'Item change date'.
      fieldcatalog-col_pos     = 3.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MATNR'.
      fieldcatalog-seltext_m   = 'Material Number'.
      fieldcatalog-col_pos     = 4.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MENGE'.
      fieldcatalog-seltext_m   = 'PO quantity'.
    fieldcatalog-edit             = 'X'
      fieldcatalog-col_pos     = 5.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MEINS'.
      fieldcatalog-seltext_m   = 'Order Unit'.
      fieldcatalog-col_pos     = 6.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'NETPR'.
      fieldcatalog-seltext_m   = 'Net Price'.
      fieldcatalog-col_pos     = 7.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-datatype     = 'CURR'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'PEINH'.
      fieldcatalog-seltext_m   = 'Price Unit'.
      fieldcatalog-col_pos     = 8.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
    ENDFORM.                    " BUILD_FIELDCATALOG
    *&      Form  BUILD_LAYOUT
          Build layout for ALV grid report
    FORM build_layout.
      gd_layout-no_input          = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-totals_text       = 'Totals'(201).
      gd_layout-info_fieldname =      'LINE_COLOR'.
    ENDFORM.                    " BUILD_LAYOUT
    *&      Form  DISPLAY_ALV_REPORT
          Display report using ALV grid
    FORM display_alv_report.
      gd_repid = sy-repid.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                i_callback_program      = gd_repid
                i_callback_pf_status_set = 'STATUS'
                i_callback_top_of_page   = 'TOP-OF-PAGE'
               i_callback_user_command = 'USER_COMMAND'
               i_grid_title           = outtext
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
               it_special_groups       = gd_tabgroup
               IT_EVENTS                = GT_XEVENTS
                i_save                  = 'X'
               is_variant              = z_template
           TABLES
                t_outtab                = it_ekko
           EXCEPTIONS
                program_error           = 1
                OTHERS                  = 2.
    ENDFORM.                    " DISPLAY_ALV_REPORT
    *&      Form  DATA_RETRIEVAL
          Retrieve data form EKPO table and populate itab it_ekko
    FORM data_retrieval.
      DATA: ld_color(1) TYPE c.
      SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
       UP TO 10 ROWS
        FROM ekpo
        INTO TABLE it_ekko.
      LOOP AT it_ekko INTO wa_ekko.
        ld_color = ld_color + 1.
        IF ld_color = 8.
          ld_color = 1.
        ENDIF.
        CONCATENATE 'C' ld_color '10' INTO wa_ekko-line_color.
        MODIFY it_ekko FROM wa_ekko.
      ENDLOOP.
    ENDFORM.                    " DATA_RETRIEVAL
          FORM top-of-page                                              *
    FORM top-of-page.
      WRITE:/ 'This is First Line of the Page'.
    ENDFORM.
          FORM status                                                   *
    FORM status USING rt_extab TYPE slis_t_extab.  .
      SET PF-STATUS 'ALV'.
    ENDFORM.
          FORM USER_COMMAND                                          *
    -->  RF_UCOMM                                                      *
    -->  RS                                                            *
    FORM user_command USING rf_ucomm LIKE sy-ucomm
                             rs TYPE slis_selfield.            
      DATA ref1 TYPE REF TO cl_gui_alv_grid.
      CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
        IMPORTING
          e_grid = ref1.
      CALL METHOD ref1->check_changed_data.
      CASE rf_ucomm.
    when 'SAVE'.
    get all the modified entries and store them in an internal table and udpate them in to the required transaction or your custom table.
    endcase.
    endform.
    ENDFORM.
    here u need to 2 performs for PF status and USER_COMMAND in the ALV parameters.
    create a custom PF status and create push buttons and assign your ok codes in your PF status.
    if the field has to be edited in the ALV then pass EDIT = 'X' for that field in the fieldcatlog preparation.
    Hope this will help you.
    Regards,
    phani.

  • Print or download ALV report with sort options

    Dear friends,
    How i can download into excel or print ALV report with sort options, like customer name column with similar values should not repeat in the print out or download file.
    Regards,
    Praveen Lobo

    Hi Praveen,
    Use this code, its working:-
    *FOR SORTING DATA
    DATA : it_sort TYPE slis_t_sortinfo_alv,
           wa_sort TYPE slis_sortinfo_alv.
    *          SORT W.R.T. CUSTOMER NAME
      wa_sort-spos = 1.
      wa_sort-fieldname = 'NAME1'. "field customer name
      wa_sort-tabname = 'IT_KNA1'. "internal table with records
      wa_sort-up = 'X'.
      APPEND wa_sort TO it_sort.
      CLEAR wa_sort.
    "this will sort the ALV o/p for customer with same name
    "now the name will not be repeated
    "records with same name will be grouped
    *          DISPLAY RECORDS IN ALV GRID
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
        i_callback_program                = sy-repid "report id
        it_fieldcat                       = it_field "field catalog
        it_sort                           = it_sort "sort info
      TABLES
        t_outtab                          = it_kna1 "internal table
      EXCEPTIONS
        program_error                     = 1
        OTHERS                            = 2.
      IF sy-subrc <> 0.
      ENDIF.
    Hope this solves your problem.
    Thanks & Regards,
    Tarun Gambhir
    Edited by: Tarun Gambhir on Dec 31, 2008 1:13 PM

  • ALV Reporting with drill down capabillities

    I'm creating a abap custom report using the ALV.  I want to drill down to CJ03 which is projects.  I know how to do it in regular custom reporting, but I don't seem to be able to get it to work using the ALV.  Can anyone help?
    Thanks.
    Linda

    Hi Linda,
    Take a look at this sample program. The logic to handle any interaction with the user is in my "PORCESS_USER_COMMANDS" routine.
    This is defined in the "I_CALLBACK_USER_COMMAND" parameter in the ALV FM.
    Hope this helps.
    Cheers,
    Pat.
    [code]
    Modification History
    Date      | Author    | Chg Req #     | Description
    15.08.2001| Pat Yee   | $TMP          | Program Creation
    This program is an example of how the ALV Display works.
    It will display Customer Data.
    This report will also show how to display an ALV report with different
    colored lines and icons
    REPORT zpat.
    Include Programs
    INCLUDE <icon>.
    Database Tables
    TABLES: kna1.                  "Customer Master
    Types
    TYPE-POOLS: kkblo.
    Structures
    Structure to hold the Color Information
    DATA: BEGIN OF st_color,
            color(3) TYPE c,
          END OF st_color.
    Structure to hold the Icon Information
    DATA: BEGIN OF st_icon,
            icon(4) TYPE c,
          END OF st_icon.
    ALV Field Catalog Structure
    DATA: st_fieldcat   TYPE slis_fieldcat_alv.
    ALV Layout Structure
    DATA: st_layout     TYPE slis_layout_alv.
    Internal Tables
    Output Table
    DATA: BEGIN OF tbl_kna1 OCCURS 0.
            INCLUDE STRUCTURE st_icon.   "Icon Structure
            INCLUDE STRUCTURE kna1.      "Customer Master Structure
            INCLUDE STRUCTURE st_color.  "Color Structure
    DATA: END OF tbl_kna1.
    ALV Field Catalog Table
    DATA: tbl_fieldcat  TYPE slis_t_fieldcat_alv.
    Variables
    DATA: fieldname(30) TYPE c,
          g_repid       LIKE sy-repid.
    Start of Selection
    START-OF-SELECTION.
      g_repid = sy-repid.
      PERFORM get_data.
    End of Selection
    END-OF-SELECTION.
      PERFORM do_fancy_stuff.
      PERFORM get_layout.
      PERFORM get_fieldcat.
      PERFORM create_report.
    *&      Form  CREATE_REPORT
          Learn to read the subroutine name!
    FORM create_report.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
           EXPORTING
                i_interface_check       = ' '
                i_callback_program      = g_repid
                i_callback_user_command = 'PROCESS_USER_COMMANDS'
                it_fieldcat             = tbl_fieldcat
                i_default               = 'X'
                i_save                  = ' '
                is_layout               = st_layout
           TABLES
                t_outtab                = tbl_kna1
           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.                               " CREATE_REPORT
    *&      Form  GET_FIELDCAT
          Build the Field Catalog
    FORM get_fieldcat.
    Here the field catalog is created. To display more fields simply
    'uncomment' the additional lines and add the field name. Also note
    that the field catalog is much more powerful than this. You can
    intensify fields, change the colour, assign reference fields, etc.
    Look at type slis_fieldcat_alv for more options.
      PERFORM write_fieldcat USING 'ICON'  'TBL_KNA1' '    ' 'X' 1 '2' 'X'
      PERFORM write_fieldcat USING 'KUNNR' 'TBL_KNA1' 'KNA1' 'X' 2 ' ' ' '
      PERFORM write_fieldcat USING 'NAME1' 'TBL_KNA1' 'KNA1' ' ' 3 '10' ' '
                                   'X'.
      PERFORM write_fieldcat USING 'STRAS' 'TBL_KNA1' 'KNA1' ' ' 4 ' ' ' '
      PERFORM write_fieldcat USING 'TELF1' 'TBL_KNA1' 'KNA1' ' ' 5 ' ' ' '
      PERFORM write_fieldcat USING 'ORT01' 'TBL_KNA1' 'KNA1' ' ' 6 ' ' ' '
      PERFORM write_fieldcat USING 'PSTLZ' 'TBL_KNA1' 'KNA1' ' ' 7 ' ' ' '
      PERFORM write_fieldcat USING 'SORTL' 'TBL_KNA1' 'KNA1' ' ' 8 ' ' ' '
      PERFORM write_fieldcat USING 'ERNAM' 'TBL_KNA1' 'KNA1' ' ' 9 ' ' ' '
      PERFORM write_fieldcat USING 'SPRAS' 'TBL_KNA1' 'KNA1' ' ' 10 ' ' ' '
    perform write_fieldcat using '     ' 'TBL_KNA1' 'KNA1' ' ' 10 ' '.
    perform write_fieldcat using '     ' 'TBL_KNA1' 'KNA1' ' ' 11 ' '.
    perform write_fieldcat using '     ' 'TBL_KNA1' 'KNA1' ' ' 12 ' '.
    ENDFORM.                               " GET_FIELDCAT
    *&      Form  WRITE_FIELDCAT
          Write the Field Catalog data to the Field Catalog Table
         -->name   Field name
         -->tab    Table name
         -->st     Structure Name
         -->key    Is this field a Key?
         -->pos    Position Number
         -->length Field Length
         -->icon   Display as Icon
         -->hot    Hotspot
    FORM write_fieldcat USING name tab st key pos length icon hot.
      st_fieldcat-fieldname   = name.
      st_fieldcat-tabname     = tab.
      st_fieldcat-ref_tabname = st.
      st_fieldcat-key         = key.
      st_fieldcat-col_pos     = pos.
      st_fieldcat-outputlen   = length.
      st_fieldcat-icon        = icon.
      st_fieldcat-hotspot     = hot.
      APPEND st_fieldcat TO tbl_fieldcat.
      CLEAR st_fieldcat.
    ENDFORM.                               " WRITE_FIELDCAT
    *&      Form  PROCESS_USER_COMMANDS
          Interactive Reporting Commands
    FORM process_user_commands USING syst-ucomm LIKE syst-ucomm
                                     selfield TYPE slis_selfield.
    This subroutine is called when there is user interaction in the output
    In this case if the user double clicks the Customer Number then the
    program will call transaction XD03 and display the Customer Master
    Data
      CASE syst-ucomm.
        WHEN '&IC1'.
    get cursor field fieldname.
          READ TABLE tbl_kna1 INDEX selfield-tabindex.
          SET PARAMETER ID 'KUN' FIELD tbl_kna1-kunnr.
          CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
      ENDCASE.
    ENDFORM.                               " PROCESS_USER_COMMANDS
    *&      Form  GET_LAYOUT
      set the layout of the ALV.
      add color to the row?
    FORM get_layout.
      st_layout-info_fieldname    = 'COLOR'.
      st_layout-colwidth_optimize = 'X'.
      st_layout-get_selinfos      = 'X'.
    ENDFORM.                    " GET_LAYOUT
    *&      Form  get_data
          Get some data to play with
    FORM get_data.
      SELECT * FROM kna1 INTO CORRESPONDING FIELDS OF TABLE tbl_kna1
             UP TO 30 ROWS.
    ENDFORM.                    " get_data
    *&      Form  do_fancy_stuff
          Do some fancy pants stuff for example changing the color of
          lines and adding icons
    FORM do_fancy_stuff.
    Here we will demonstrate changing the color of ALV Record lines as
    well as displaying Icons
      LOOP AT tbl_kna1.
    All records where NAME1 begins with 'M', will be displayed in Bluish
    Green
        IF tbl_kna1-name1(1) EQ 'M'.
          tbl_kna1-color = 'C41'.  "Bluish Green
          MODIFY tbl_kna1 TRANSPORTING color.
        ENDIF.
    All records with no TELF1 will be displayed in White and have a
    Warning Icon
        IF tbl_kna1-telf1 IS INITIAL.
          tbl_kna1-color = 'C00'.  "White
          tbl_kna1-icon  = '@AH@'. "Warning Icon
          MODIFY tbl_kna1 TRANSPORTING icon color.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    " do_fancy_stuff[/code]

  • Coloring of Particular Cells in a dynamic internal table(field symbols)

    Hi,
         I have a requirement to introduce color into some particular cells in a dynamic internal table(Field symbol) based on some conditions.I know that color can be introduced at cell level in the case of static internal table.But, can anybody tell me whether it is possible to introduce color to particular cells in the dynamic internal table(Field Symbol) .Please suggest me on this issue.
    Thanks in advance,
    Rajesh

    Hi,
    This is the sample coding for the colour cell report.
    Kindly go through it. It will helps u.
    REPORT YMS_COLOURTEST .
    DATA: BEGIN OF TP OCCURS 10, ID, NR(8), TEXT(255), END OF TP.
    DATA: LENGTH TYPE I VALUE 8, " Length of list
    TESTSTRING(15) TYPE C VALUE '012345678901234',
    WIDTH TYPE I. " Width of list
    DATA: TXT_REPORT LIKE DOKHL-OBJECT.
    START-OF-SELECTION.
    PERFORM HEADING.
    PERFORM OUTPUT_BODY.
    FORM HEADING.
    FORMAT INTENSIFIED OFF. " Remove any INTENSIFIED
    ULINE AT (WIDTH). " Upper frame border
    FORMAT COLOR COL_HEADING INTENSIFIED." Title color
    WRITE: / SY-VLINE. " Left border
    WRITE: 'No |Colour |intensified |intensified off|',
    'inverse' NO-GAP.
    WRITE: AT WIDTH SY-VLINE. " Right border
    ULINE AT (WIDTH). " Line below titles
    FORMAT COLOR OFF.
    ENDFORM.
    FORM OUTPUT_BODY.
    DO LENGTH TIMES.
    PERFORM WRITE_LINE USING SY-INDEX.
    ENDDO.
    ENDFORM.
    FORM WRITE_LINE USING COUNT TYPE I.
    DATA: HELP(14) TYPE C,
    COUNT1 TYPE I.
    COUNT1 = SY-INDEX - 1.
    WRITE: / SY-VLINE NO-GAP.
    WRITE: (4) COUNT1 COLOR COL_KEY INTENSIFIED NO-GAP.
    WRITE: SY-VLINE NO-GAP.
    CASE COUNT1.
    WHEN '0'.
    HELP = 'COL_BACKGROUND'.
    WHEN '1'.
    HELP = 'COL_HEADING'.
    WHEN '2'.
    HELP = 'COL_NORMAL'.
    WHEN '3'.
    HELP = 'COL_TOTAL'.
    WHEN '4'.
    HELP = 'COL_KEY'.
    WHEN '5'.
    HELP = 'COL_POSITIVE'.
    WHEN '6'.
    HELP = 'COL_NEGATIVE'.
    WHEN '7'.
    HELP = 'COL_GROUP'.
    ENDCASE.
    WRITE: HELP COLOR COL_KEY INTENSIFIED NO-GAP.
    WRITE: SY-VLINE NO-GAP.
    WRITE: TESTSTRING COLOR = COUNT1 INTENSIFIED NO-GAP.
    WRITE: SY-VLINE NO-GAP.
    WRITE: TESTSTRING COLOR = COUNT1 INTENSIFIED OFF NO-GAP.
    WRITE: SY-VLINE NO-GAP.
    WRITE: TESTSTRING COLOR = COUNT1 INVERSE NO-GAP.
    WRITE AT WIDTH SY-VLINE NO-GAP.
    ENDFORM.
    Thanks,
    Shankar

  • Billing report with due date field

    Dear Friends,
    Can you please tell the logic of Billing report with due date field.
    Input.  billing document no, date range, sales organisation
    Output : billing document no, sales organisation, Amount. Due date.
    If any clarification required, Please let me know.
    Thanks in advance
    Ranjan

    Is it VF05 is suffiant for your purpose?
    use further selection criteria tab.
    Amit.

  • I need a report with the following fields

    Hi All,
    I need a report with the following fields & G/L "Expenses" only.
    1)G/L Code.
    2) G/L Name.
    3) G/L Balance
    & Selection Criteria From Date, To Date , & Location(for me locations is PROFITCENTRE).
    Please some body suggest me an SQL Querry to fetch this result.
    Thanks in Advance,
    S. Mobin

    Hi!
    Individual G/L means i didn't understand
    check this for only Expence Acc
    Declare @FromDate Datetime
    Declare @ToDate Datetime
    Declare @Location nvarchar(20)
    set @FromDate = (Select min(S0.RefDate) from jdt1 s0 where s0.Refdate >='[%0]')
    set @ToDate = (Select max(S1.RefDate) from jdt1 s1 where s1.Refdate >='[%1]')
    set @Location = (Select max(s2.ProfitCode) from jdt1 s2 where s2.ProfitCode  = '[%2]')
    select
    J1.Account,
    max(A0.AcctName) as Name,
    j1.ProfitCode as Location,
    sum(J1.debit-j1.credit) as Balance
    From
    JDT1 J1,OACT A0
    Where
    J1.Account=A0.AcctCode and
    J1.RefDate >=@FromDate and
    J1.RefDate<= @ToDate and
    j1.ProfitCode=@Location and
    A0.GroupMask = 5
    Group By
    J1.Account,j1.ProfitCode

  • Create a ALV report with fields editable and  entry to be saved in ztable

    Hello Experts,
    I have created the ALV report which has two of the fields editable. Now whenever user puts an entry in the ALV it has to be saved in the ZTABLE.
    The report is displayed with editable fields but i'm not sure what has to be written in the 'USER COMMAND' subroutine to save the entries in ztable.
    Please see my code belwo:-
      gd_repid = sy-repid.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                i_callback_program      = gd_repid
               i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
                i_callback_user_command = 'ALV_USER_COMM'
               i_grid_title           = outtext
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
               it_special_groups       = gd_tabgroup
               it_events               = gt_events
               is_print                = gd_prntparams
                 i_save                  = 'X'
               is_variant              = z_template
           TABLES
                t_outtab                = it_bg2
           EXCEPTIONS
                program_error           = 1
                OTHERS                  = 2.
      IF sy-subrc <> 0.
    Thanks,
    Naveen
    Edited by: jaikrishna on Sep 4, 2010 8:13 AM

    Hi,
    I have worked on similar requirement. You can do that on sy-ucomm value only and you have to call a FM and a method. For that end user has to click on a button which you need to create in the application toolbar. Say that button function code is 'SAVE'. Write the following code in your user command :
    *&      Form  USER_COMMAND
    FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
            RS_SELFIELD TYPE SLIS_SELFIELD.
    *Code to reflect the changes done in the internal table
      DATA : REF_GRID TYPE REF TO CL_GUI_ALV_GRID.
      DATA: L_VALID TYPE C.
      IF REF_GRID IS INITIAL.
        CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
          IMPORTING
            E_GRID = REF_GRID.
      ENDIF.
      IF NOT REF_GRID IS INITIAL.
        CALL METHOD REF_GRID->CHECK_CHANGED_DATA
          IMPORTING
            E_VALID = L_VALID.
      ENDIF.
      CASE SY-UCOMM.
        WHEN 'SAVE'.
    *Data will come with the edited values from ALV
    *Here you write your code to save entries into Z table
    ENDCASE.
    ENDFORM. "USER_COMMAND
    Thanks & Regards,
    Rock.

  • ALV print problems for reports with two sort fields and subtotal at each

    When a report has two sort fields and subtotal at each of them, the print function is not working correctly. Please see the report below.
    The second "" (single star) record (the 10 RL record) and the '*' (double star) record (the 12 RL record)  are not printing.
    This is happening for any standard SAP reports. Any resolution? Any OSS Notes?
         Material/Stock Code          Grade       Units Count     Unit Type     Set Position     LFT
         520085V000          7818     1     RL     A     19,682 LF
         520085V000          7818     1     RL     A     19,682 LF
    *     520085V000               2     RL          
         599098V000               1     RL          
         599098V000               1     RL          
         599098V000               1     RL          
         599098V000               1     RL          
         599098V000               1     RL          
         599098V000               1     RL          
         599098V000               1     RL          
         599098V000               1     RL          
         599098V000               1     RL          
         599098V000          7717     1     RL     A     36,167 LF
    *     599098V000               10     RL          
    **                    12     RL          
    ***                    12               
    Thanks
    Anand
    Edited by: Anand Velayudhan on Feb 9, 2009 11:50 PM

    Hi,
    Check these OSS Notes..
    Note 975777 - ALV total: Subtotals disappear from printout
    Note 1039655 - ALV total: Subtotals disappear from printout II
    Thanks
    Naren

  • ALV report with dynamic columns, and repeated structure rows

    Hey Guys,
    I've done some ALV programming, but most of the reports were straight forward. This one is a little interesting. So here go the questions...
    Q1: Regarding Columns:
    What is the best way to code a report with columns being dynamic. This is one of the parameters the user is going to enter in his input.
    Q2: Regarding Rows:
    I want to repeat a structure(say it contains f1, f2, f3) multiple time in rows. What is the best way to do it? The labels for these fields have to appear in the first column.
    Below is the visual representation of the questions.
    Jan 06  , Feb 06, Mar 06....(dynamic)
       material 1
    Current Stock
    current required
    $Value of stock
       material 2
    Current Stock
    current required
    $Value of stock
       material 3
    Current Stock
    current required
    $Value of stock
    Thanks for your help.
    Sumit.

    Hi Sumit,
    Just check this sample from one of the SAP site
    ABAP Code Sample for Dynamic Table for ALV with Cell Coloring
    Applies To:
    ABAP / ALV Grid
    Article Summary
    ABAP Code Sample that uses dynamic programming techniques to build a dynamic internal table for display in an ALV Grid with Cell Coloring.
    Code Sample
    REPORT zcdf_dynamic_table.
    * Dynamic ALV Grid with Cell Coloring.
    * Build a field catalog dynamically and provide the ability to color
    * the cells.
    * To test, copy this code to any program name and create screen 100
    * as described in the comments. After the screen is displayed, hit
    * enter to exit the screen.
    * Tested in 4.6C and 6.20
    * Charles Folwell - [email protected] - Feb 2, 2005
    DATA:
    r_dyn_table TYPE REF TO data,
    r_wa_dyn_table TYPE REF TO data,
    r_dock_ctnr TYPE REF TO cl_gui_docking_container,
    r_alv_grid TYPE REF TO cl_gui_alv_grid,
    t_fieldcat1 TYPE lvc_t_fcat, "with cell color
    t_fieldcat2 TYPE lvc_t_fcat, "without cell color
    wa_fieldcat LIKE LINE OF t_fieldcat1,
    wa_cellcolors TYPE LINE OF lvc_t_scol,
    wa_is_layout TYPE lvc_s_layo.
    FIELD-SYMBOLS:
    <t_dyn_table> TYPE STANDARD TABLE,
    <wa_dyn_table> TYPE ANY,
    <t_cellcolors> TYPE lvc_t_scol,
    <w_field> TYPE ANY.
    START-OF-SELECTION.
    * Build field catalog based on your criteria.
    wa_fieldcat-fieldname = 'FIELD1'.
    wa_fieldcat-inttype = 'C'.
    wa_fieldcat-outputlen = '10'.
    wa_fieldcat-coltext = 'My Field 1'.
    wa_fieldcat-seltext = wa_fieldcat-coltext.
    APPEND wa_fieldcat TO t_fieldcat1.
    wa_fieldcat-fieldname = 'FIELD2'.
    wa_fieldcat-inttype = 'C'.
    wa_fieldcat-outputlen = '10'.
    wa_fieldcat-coltext = 'My Field 2'.
    wa_fieldcat-seltext = wa_fieldcat-coltext.
    APPEND wa_fieldcat TO t_fieldcat1.
    * Before adding cell color table, save fieldcatalog to pass
    * to ALV call. The ALV call needs a fieldcatalog without
    * the internal table for cell coloring.
    t_fieldcat2[] = t_fieldcat1[].
    * Add cell color table.
    * CALENDAR_TYPE is a structure in the dictionary with a
    * field called COLTAB of type LVC_T_SCOL. You can use
    * any structure and field that has the type LVC_T_SCOL.
    wa_fieldcat-fieldname = 'T_CELLCOLORS'.
    wa_fieldcat-ref_field = 'COLTAB'.
    wa_fieldcat-ref_table = 'CALENDAR_TYPE'.
    APPEND wa_fieldcat TO t_fieldcat1.
    * Create dynamic table including the internal table
    * for cell coloring.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
    it_fieldcatalog = t_fieldcat1
    IMPORTING
    ep_table = r_dyn_table
    EXCEPTIONS
    generate_subpool_dir_full = 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.
    * Get access to new table using field symbol.
    ASSIGN r_dyn_table->* TO <t_dyn_table>.
    * Create work area for new table.
    CREATE DATA r_wa_dyn_table LIKE LINE OF <t_dyn_table>.
    * Get access to new work area using field symbol.
    ASSIGN r_wa_dyn_table->* TO <wa_dyn_table>.
    * Get data into table from somewhere. Field names are
    * known at this point because field catalog is already
    * built. Read field names from the field catalog or use
    * COMPONENT <number> in a DO loop to access the fields. A
    * simpler hard coded approach is used here.
    ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    <w_field> = 'ABC'.
    ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    <w_field> = 'XYZ'.
    APPEND <wa_dyn_table> TO <t_dyn_table>.
    ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    <w_field> = 'TUV'.
    ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    <w_field> = 'DEF'.
    APPEND <wa_dyn_table> TO <t_dyn_table>.
    * Color cells based on your criteria. In this example, a test on
    * FIELD2 is used to decide on color.
    LOOP AT <t_dyn_table> INTO <wa_dyn_table>.
    ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_dyn_table> TO <w_field>.
    * Get access to internal table used to color cells.
    ASSIGN COMPONENT 'T_CELLCOLORS'
    OF STRUCTURE <wa_dyn_table> TO <t_cellcolors>.
    CLEAR wa_cellcolors.
    wa_cellcolors-fname = 'FIELD2'.
    IF <w_field> = 'DEF'.
    wa_cellcolors-color-col = '7'.
    ELSE.
    wa_cellcolors-color-col = '5'.
    ENDIF.
    APPEND wa_cellcolors TO <t_cellcolors>.
    MODIFY <t_dyn_table> FROM <wa_dyn_table>.
    ENDLOOP.
    * Display screen. Define screen 100 as empty, with next screen
    * set to 0 and flow logic of:
    * PROCESS BEFORE OUTPUT.
    * MODULE initialization.
    * PROCESS AFTER INPUT.
    CALL SCREEN 100.
    * MODULE initialization OUTPUT
    MODULE initialization OUTPUT.
    * Set up for ALV display.
    IF r_dock_ctnr IS INITIAL.
    CREATE OBJECT r_dock_ctnr
    EXPORTING
    side = cl_gui_docking_container=>dock_at_left
    ratio = '90'.
    CREATE OBJECT r_alv_grid
    EXPORTING i_parent = r_dock_ctnr.
    * Set ALV controls for cell coloring table.
    wa_is_layout-ctab_fname = 'T_CELLCOLORS'.
    * Display.
    CALL METHOD r_alv_grid->set_table_for_first_display
    EXPORTING
    is_layout = wa_is_layout
    CHANGING
    it_outtab = <t_dyn_table>
    it_fieldcatalog = t_fieldcat2.
    ELSE. "grid already prepared
    * Refresh display.
    CALL METHOD r_alv_grid->refresh_table_display
    EXPORTING
    i_soft_refresh = ' '
    EXCEPTIONS
    finished = 1
    OTHERS = 2.
    ENDIF.
    ENDMODULE. " initialization OUTPUT
    Regards
    vijay

  • Subtotals in ALV report for ALPHA-NUMERIC field

    Hi Experts,
    I have problem while subtotalling values in ALV report.
    I have 8 fields in my fieldcatalog. Now, I have to do the subtotal based on 3rd field having name 'ABC'. This field is having type CHAR & having lenght 3.
    Now I wanted to do subtotalling for field 7 & 8 as 'NETWR' & 'MENGE' based on 3rd field.
    How we can do the subtotal?

    Hi,
    Refer this code
    *&      Form  sub_display_data
          text
    FORM sub_display_data .
    *--To sort the output through material number
      DATA : lwa_sort TYPE slis_sortinfo_alv.
      DATA : lit_sort TYPE slis_t_sortinfo_alv.
    *--Pass the values to the table
      lwa_sort-fieldname = 'PERNR'.             "Field name in o/p inttable
      lwa_sort-tabname   = 'it_final2'.         "Output Internal table
      lwa_sort-spos      = '1'.                 "Sort  sequence
      lwa_sort-up        = 'X'.                 "Sort in ascending order
      lwa_sort-down      = ' '.                 "Sort in descending order
      lwa_sort-subtot    = 'X'.                 "Subtotal
      APPEND lwa_sort TO lit_sort.
    *--Pass the values to the table
      lwa_sort-fieldname = 'WORKDATE'.          "Field name in o/p inttable
      lwa_sort-tabname   = 'it_final2'.         "Output Internal table
      lwa_sort-spos      = '2'.                 "Sort  sequence
      lwa_sort-up        = 'X'.                 "Sort in ascending order
      lwa_sort-down      = ' '.                 "Sort in descending order
      lwa_sort-subtot    = ' '.                 "Subtotal
      APPEND lwa_sort TO lit_sort.
    *--Pass the values to the table
      lwa_sort-fieldname = 'WEKLY'.             "Field name in o/p inttable
      lwa_sort-tabname   = 'it_final2'.         "Output Internal table
      lwa_sort-spos      = '3'.                 "Sort  sequence
      lwa_sort-up        = 'X'.                 "Sort in ascending order
      lwa_sort-down      = ' '.                 "Sort in descending order
      lwa_sort-subtot    = ' '.                 "Subtotal
      APPEND lwa_sort TO lit_sort.
      wa_layout-colwidth_optimize = 'X'.
      IF NOT it_final2[] IS INITIAL.
    *--Call the function module to display the ALV report
        CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
          EXPORTING
            is_layout          = wa_layout
            i_callback_program = v_repid
            it_fieldcat        = it_fieldcat1[]
            i_default          = c_chk
            i_save             = c_save
            it_sort            = lit_sort
          TABLES
            t_outtab           = it_final2
          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.
      ELSE.
    *--Message No data found
        MESSAGE i888 WITH text-017.
        LEAVE LIST-PROCESSING.
      ENDIF.
    ENDFORM.                    " sub_display_data
    Regards,
    Prashant

  • How to filter standard ALV report with custom UI element?

    Hello Expert,
    I got a requirement to filter standard ALV report based on the custom UI element (which is created in the screen before displaying the ALV report). Upon entering the values in the Custom field, the ALV report is displayed accordingly.
    Any ideas how to approach it?
    Thanks,
    Mohammed

    Hi,
    Okay, let me explain the steps in detail
    Let us say you have alv table with 10 records and alv table is shown first time with all 10 records
    Create an internal table in component controller's attribute GT_ORIGINAL_DATA and save all 10 records into this table first time
    Now, user enters value in FILTER_MATNR field 123 and press apply_filter button or press enter key
    Read the value of field filter_matnr and get the only matching records from global internal table GT_ORIGINAL_DATA into local internal table as below
              data lv_matnr type matnr.
              data lt_data   like wd_comp_controller->gt_original_data.
                   " read the value from context attribute of filter_matnr
                        lv_matnr = ???
                   " copy all data into local table
                        lt_data[] = wd_comp_controller->gt_original_data.
                   "delete the records which does not match
                     delete lt_data where matnr NP lv_matnr.
    Now, bind the data lt_data to context node of alv table
    Hope this helps you.
    Regards,
    Rama

  • ALV REPORT WITH MULTIPLE BLOCKS - COLUM TOTAL

    Hi friends,
    In the following code, I am not getting the column total.
    --- SAMPLE 1--
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
           EXPORTING
                i_callback_program      = sy-cprog
                i_callback_user_command = 'USER_COMMAND'.
      PERFORM list_append TABLES IT_CTV
                           USING '1'
                                 'IT_CTV'.
      PERFORM list_append TABLES IT_APP
                           USING '2'
                                 'IT_APP'.
      PERFORM f_list_display.
          FORM USER_COMMAND                                             *
    FORM user_command USING i_ucomm     LIKE sy-ucomm
                            is_selfield TYPE slis_selfield.     "#EC CALLED
    ENDFORM.                               " USER_COMMAND
          Form  list_append
    FORM list_append TABLES ut_table
                     USING  u_no      TYPE char1
                            u_tabname TYPE slis_tabname.
      DEFINE m_fieldcat.
        ls_fieldcat-fieldname = &1.
        ls_fieldcat-ref_tabname = &2.
        append ls_fieldcat to lt_fieldcat.
      END-OF-DEFINITION.
    DATA: GT_ZSUM TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE.
      DEFINE m_sort.
        ls_sort-fieldname = &1.
        ls_sort-up        = 'X'.
        append ls_sort to lt_sort.
      END-OF-DEFINITION.
      DATA :
        ls_fieldcat TYPE slis_fieldcat_alv,
        lt_fieldcat TYPE slis_t_fieldcat_alv, " Field catalog
        ls_sort     TYPE slis_sortinfo_alv,
        lt_sort     TYPE slis_t_sortinfo_alv. " Sort table
      DATA:
        lt_events TYPE slis_t_event,
        ls_event  TYPE slis_alv_event,
        ls_layout TYPE slis_layout_alv.
      ls_layout-group_change_edit = 'X'.
      ls_layout-colwidth_optimize = 'X'.
      ls_layout-zebra             = 'X'.
      ls_layout-cell_merge        = 'X'.
      ls_layout-detail_popup      = 'X'.
      ls_layout-get_selinfos      = 'X'.
      ls_layout-max_linesize      = '300'.
      CASE u_no.
        WHEN '1'.
          ls_fieldcat-SELTEXT_L = ' REGION'.
          m_fieldcat  'BZIRK' 'IT_CTV'.
          ls_fieldcat-just = 'R'.
          ls_fieldcat-SELTEXT_L = ' CTV STOCK'.
          m_fieldcat  'CTVST' 'IT_CTV'.
          ls_fieldcat-just = 'R'.
          ls_fieldcat-SELTEXT_L = ' CTV VALUE'.
          m_fieldcat  'CTVVL' 'IT_CTV'.
          ls_fieldcat-DO_SUM = 'X'.
          m_sort  'BZIRK'.
        WHEN '2'.
          ls_fieldcat-SELTEXT_L = ' REGION'.
          m_fieldcat  'BZIRK' 'IT_APP'.
          ls_fieldcat-just = 'R'.
          ls_fieldcat-SELTEXT_L = ' RFG STK'.
          m_fieldcat  'RFGST' 'IT_APP'.
          ls_fieldcat-just = 'R'.
          ls_fieldcat-SELTEXT_L = ' RFG VAL'.
          m_fieldcat  'RFGVL' 'IT_APP'.
          ls_fieldcat-just = 'R'.
          ls_fieldcat-SELTEXT_L = ' WM STK'.
          m_fieldcat  'WMCST' 'IT_APP'.
          ls_fieldcat-just = 'R'.
          ls_fieldcat-SELTEXT_L = ' WM VAL'.
          m_fieldcat  'WMCVL' 'IT_APP'.
          ls_fieldcat-just = 'R'.
          ls_fieldcat-SELTEXT_L = ' MCCS STK'.
          m_fieldcat  'MOVST' 'IT_APP'.
          ls_fieldcat-just = 'R'.
          ls_fieldcat-SELTEXT_L = ' MCCS VAL'.
          m_fieldcat  'MOVVL' 'IT_APP'.
          ls_fieldcat-just = 'R'.
          ls_fieldcat-SELTEXT_L = ' APP STK'.
          m_fieldcat  'APPST' 'IT_APP'.
          ls_fieldcat-just = 'R'.
          ls_fieldcat-SELTEXT_L = ' APP VAL'.
          m_fieldcat  'APPVL' 'IT_APP'.
          ls_fieldcat-just = 'R'.
          ls_fieldcat-DO_SUM = 'X'.
         m_sort  'BZIRK'.
      ENDCASE.
    ls_fieldcat-COL_POS = 1.
    ls_fieldcat-FIELDNAME = 'BZIRK'.
    ls_fieldcat-DO_SUM = 'X'.
    ls_fieldcat-FIX_COLUMN = 'X'.
    APPEND ls_fieldcat TO lT_fieldcat.
      IF u_no CA '13'.
        MOVE        'TOP_OF_PAGE'        TO ls_event-name.
        CONCATENATE 'TOP_OF_PAGE' u_no INTO ls_event-form.
        APPEND ls_event TO lt_events.
      ELSE.
        MOVE        'TOP_OF_LIST'        TO ls_event-name.
        CONCATENATE 'TOP_OF_LIST' u_no INTO ls_event-form.
        APPEND ls_event TO lt_events.
      ENDIF.
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
           EXPORTING
                it_fieldcat                = lt_fieldcat
                is_layout                  = ls_layout
                i_tabname                  = u_tabname
                it_events                  = lt_events
                it_sort                    = lt_sort
           TABLES
                t_outtab                   = ut_table
           EXCEPTIONS
                program_error              = 1
                maximum_of_appends_reached = 2
                OTHERS                     = 3.
      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.                               " LIST_APPEND
          Form  f_list_display
    FORM f_list_display.
      DATA ls_print TYPE slis_print_alv.
      ls_print-no_print_selinfos  = 'X'.   " Display no selection infos
      ls_print-no_print_listinfos = 'X'.   " Display no listinfos
      ls_print-reserve_lines      = 2.     " Lines reserved for end of page
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
           EXPORTING
                i_interface_check = ' '
                is_print          = ls_print
           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.                               " F_LIST_DISPLAY
          FORM top_of_page1                                             *
    FORM top_of_page1.                                          "#EC CALLED
      WRITE 'SALES REPORT'.
      PERFORM TOP_LIST1.
    ENDFORM.
          FORM top_of_list2                                             *
    FORM top_of_list2.                                          "#EC CALLED
      WRITE 'STOCK REPORT'.
      PERFORM top_of_page.
    ENDFORM.
    *-----END OF SAMPLE 1 -
    Could any help me.
    Thanx in advance.
    Regards,
    A S VINCENT

    Hai Vincent
    Check & Run the follow ABAP Code
    *& Report  ZALV_Block                                               *
    REPORT  ZALV_block NO STANDARD PAGE HEADING
                                    MESSAGE-ID ZZ.
    *..Type Definitions for ALV Report
    TYPE-POOLS SLIS.
    Table Declarations.                                        *
    TABLES: MARA,        "Material Master
            MARC,        "Plant Data for Material
            MARD,        "Storage Location Data for Material
            VBAP,        "Sales Document: Item Data
            VBUP.        "Sales Document: Item Status
    Internal table to store sales orders.......
    DATA: BEGIN OF IT_VBAP OCCURS 0,
            VBELN LIKE VBAP-VBELN,    "Sales Document
            POSNR LIKE VBAP-POSNR,    "Sales Document Item
            KWMENG LIKE VBAP-KWMENG,  "Cumulative order quantity in sales
                                       "                        Units
          END OF IT_VBAP.
    internal table to store final data
    DATA: BEGIN OF IT_FINAL OCCURS 0,
            WERKS LIKE MARD-WERKS,    "Plant
            MATNR LIKE MARD-MATNR,    "Material Number
            LGORT LIKE MARD-LGORT,    "Storage Location
            LABST LIKE MARD-LABST,    "Valuated stock with unrestricted use
            INSME LIKE MARD-INSME,    "Stock in quality inspection
            RETME LIKE MARD-RETME,    "Blocked Stock Returns
            UMLME LIKE MARD-UMLME,    "Stock in transfer
            MAKTX LIKE MAKT-MAKTX,    "Material description
            VBELN LIKE VBAP-VBELN,    "Sales Document
            POSNR LIKE VBAP-POSNR,    "Sales Document Item
            KWMENG LIKE VBAP-KWMENG,  "Cumulative order quantity in sales
                                       "                        Units
          END OF IT_FINAL.
    ALV Type declaration                                                 *
    *..Field Catalog for Basic List.
    DATA : IT_FIELDCAT  TYPE SLIS_T_FIELDCAT_ALV,
           WA_FIELDCAT  TYPE SLIS_FIELDCAT_ALV.
    *..Events For Basic List.
    DATA : IT_EVENTS TYPE SLIS_T_EVENT,
           WA_EVENTS TYPE SLIS_ALV_EVENT.
    *..Layout For Basic List
    DATA : WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
    *..Sort Table For Basic List
    DATA: IT_SORT TYPE SLIS_SORTINFO_ALV OCCURS 0 WITH HEADER LINE.
               DATA DECLARATIONS                                         *
    DATA: V_FLAG,
          VINDEX TYPE SY-TABIX,
          TOTAL TYPE VBAP-KWMENG.     "Open order quantity
    *..To Store Program Name
    DATA: V_REPID  TYPE SYREPID.
    *..To know whether basic list contains any data
    Selection Screen.                                                    *
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-H01.
    SELECT-OPTIONS: S_MATNR FOR MARA-MATNR,
                    S_WERKS FOR MARC-WERKS,
                    S_LGORT FOR MARD-LGORT.
    SELECTION-SCREEN END OF BLOCK B1.
    Event:Initialization                                                 *
    INITIALIZATION.
      V_REPID = SY-REPID.
    AT Selection Screen.                                                 *
    AT SELECTION-SCREEN.
      PERFORM VALIDATIONS.
    Event: Start-of-Selection                                            *
    START-OF-SELECTION.
         To get data from vbap into internal table IT_VBAP
      PERFORM FETCH_OPEN_DATA.
          To get data into final internal table IT_FINAL
      IF V_FLAG = 'X'.
        PERFORM FETCH_FINAL_DATA.
      ENDIF.
      IF V_FLAG = ''.
        MESSAGE I010 WITH 'NO DATA TO BE DISPLAYED'.
        EXIT.
      ELSE.
      --Setting the FIELD CATALOG for ALV
        PERFORM FILL_FIELDCAT_HEADER.
    *-----Setting the LAYOUT for ALV
        PERFORM GET_LAYOUT.
    *-----Getting the ALV Events
        PERFORM GET_EVENT.
    *---- To Sort the list
        PERFORM DO_SORT.
      ENDIF.
    Event: End-of-Selection                                            *
    END-OF-SELECTION.
    *--Generating the ALV LIST DISPLAY
      PERFORM DISPLAY_LIST.
                             FORM DEFINITIONS                            *
    *&      Form  VALIDATIONS
          To validate data in selection screen
    -->  p1        text
    <--  p2        text
    FORM VALIDATIONS.
      PERFORM VALIDATE_MATNR.
      PERFORM VALIDATE_WERKS.
      PERFORM VALIDATE_LGORT.
      IF NOT ( ( MARA-MATNR IS INITIAL ) AND
              ( MARC-WERKS IS INITIAL ) AND
              ( MARD-LGORT IS INITIAL ) ).
        SELECT SINGLE MATNR
                      WERKS
                      LGORT
                      FROM MARD
          INTO (MARD-MATNR, MARD-WERKS, MARD-LGORT)
          WHERE MATNR = MARA-MATNR
            AND WERKS = MARC-WERKS
            AND LGORT = MARD-LGORT.
      ENDIF.
    ENDFORM.                    " VALIDATIONS
    *&      Form  VALIDATE_MATNR
          To validate MATNR
    -->  p1        text
    <--  p2        text
    FORM VALIDATE_MATNR.
      IF NOT S_MATNR[] IS INITIAL.
        SELECT MATNR
               UP TO 1 ROWS
               INTO (MARD-MATNR)
               FROM MARA
               WHERE MATNR IN S_MATNR.
        ENDSELECT.
      ENDIF.
      IF SY-SUBRC NE 0.
        MESSAGE E000 WITH TEXT-001.
      ENDIF.
    ENDFORM.                    " VALIDATE_MATNR
    *&      Form  VALIDATE_WERKS
          To validate plant
    -->  p1        text
    <--  p2        text
    FORM VALIDATE_WERKS.
      IF NOT S_WERKS[] IS INITIAL.
        SELECT WERKS
               UP TO 1 ROWS
               INTO (MARD-WERKS)
               FROM MARC
               WHERE WERKS IN S_WERKS.
        ENDSELECT.
      ENDIF.
      IF SY-SUBRC NE 0.
        MESSAGE E000 WITH TEXT-002.
      ENDIF.
    ENDFORM.                    " VALIDATE_WERKS
    *&      Form  VALIDATE_LGORT
          To validate storage
    -->  p1        text
    <--  p2        text
    FORM VALIDATE_LGORT.
      IF NOT S_LGORT[] IS INITIAL.
        SELECT LGORT
               UP TO 1 ROWS
               INTO (MARD-LGORT)
               FROM MARD
               WHERE LGORT IN S_LGORT.
        ENDSELECT.
      ENDIF.
      IF SY-SUBRC NE 0.
        MESSAGE E000 WITH TEXT-003.
      ENDIF.
    ENDFORM.                    " VALIDATE_LGORT
    *&      Form  FETCH_OPEN_DATA
          To get data into internal table IT_VBAP
    -->  p1        text
    <--  p2        text
    FORM FETCH_OPEN_DATA.
      IF NOT ( ( MARA-MATNR IS INITIAL ) AND
               ( MARC-WERKS IS INITIAL ) AND
               ( MARD-LGORT IS INITIAL ) ).
        SELECT VBELN
               POSNR
               KWMENG
               INTO CORRESPONDING FIELDS OF TABLE IT_VBAP
               FROM VBAP
               WHERE MATNR IN S_MATNR
                 AND WERKS IN S_WERKS
                 AND LGORT IN S_LGORT.
      ENDIF.
      LOOP AT IT_VBAP.
        SELECT * FROM VBUP
                 INTO VBUP
                 WHERE VBELN = IT_VBAP-VBELN
                   AND POSNR = IT_VBAP-POSNR
                   AND LFSTA NE 'C'.
        ENDSELECT.
      ENDLOOP.
      IF SY-SUBRC NE 0.
        REFRESH IT_VBAP.
        MESSAGE E000 WITH TEXT-004.
        EXIT.
      ELSE.
        V_FLAG = 'X'.
      ENDIF.
          To get sum of all quantities as open order quantity
      LOOP AT IT_VBAP.
        TOTAL = TOTAL + IT_VBAP-KWMENG.
      ENDLOOP.
    ENDFORM.                    " FETCH_OPEN_DATA
    *&      Form  FETCH_FINAL_DATA
         To get data into final internal table IT_FINAL
    -->  p1        text
    <--  p2        text
    FORM FETCH_FINAL_DATA.
      SELECT A~MATNR
             A~WERKS
             A~LGORT
             MAKTX
             LABST
             INSME
             RETME
             UMLME
             VBELN
             POSNR
             KWMENG
             INTO CORRESPONDING FIELDS OF TABLE IT_FINAL
             FROM MARD AS A
             INNER JOIN MAKT AS B
             ON AMATNR = BMATNR
              AND SPRAS = 'E'
             INNER JOIN VBAP AS C
             ON AMATNR = CMATNR
             FOR ALL ENTRIES IN IT_VBAP
             WHERE VBELN = IT_VBAP-VBELN
               AND POSNR = IT_VBAP-POSNR
               AND KWMENG = IT_VBAP-KWMENG
               AND A~MATNR IN S_MATNR
               AND A~WERKS IN S_WERKS
               AND A~LGORT IN S_LGORT.
      IF SY-SUBRC NE 0.
        V_FLAG = SPACE.
        MESSAGE E001 WITH 'No data found IN the selection criteria'.
        EXIT.
      ELSE.
        V_FLAG = 'X'.
      ENDIF.
    ENDFORM.                    " FETCH_FINAL_DATA
    *&      Form  FILL_FIELDCAT_HEADER
          text
    -->  p1        text
    <--  p2        text
    FORM FILL_FIELDCAT_HEADER .
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
       EXPORTING
         I_PROGRAM_NAME               = V_REPID
         I_INTERNAL_TABNAME           = 'IT_FINAL'
      I_STRUCTURE_NAME             =
      I_CLIENT_NEVER_DISPLAY       = 'X'
         I_INCLNAME                   = V_REPID
      I_BYPASSING_BUFFER           =
      I_BUFFER_ACTIVE              =
        CHANGING
          CT_FIELDCAT                  = IT_FIELDCAT
       EXCEPTIONS
         INCONSISTENT_INTERFACE       = 1
         PROGRAM_ERROR                = 2
         OTHERS                       = 3
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      LOOP AT IT_FIELDCAT INTO WA_FIELDCAT.
        CASE WA_FIELDCAT-FIELDNAME.
          WHEN 'KWMENG'.
           WA_FIELDCAT-COL_POS = '11'.
           WA_FIELDCAT-OUTPUTLEN = '22'.
           WA_FIELDCAT-SELTEXT_L = 'Net Value'.
            WA_FIELDCAT-DO_SUM    = 'X'.
        ENDCASE.
        MODIFY IT_FIELDCAT FROM WA_FIELDCAT INDEX SY-TABIX.
      ENDLOOP.
    ENDFORM.                    " FILL_FIELDCAT_HEADER
    *&      Form  GET_LAYOUT
          text
    -->  p1        text
    <--  p2        text
    FORM GET_LAYOUT .
      WA_LAYOUT-TOTALS_TEXT = 'TOTAL'.
    ENDFORM.                    " GET_LAYOUT
    *&      Form  GET_EVENT
          text
    -->  p1        text
    <--  p2        text
    FORM GET_EVENT .
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          I_LIST_TYPE     = 0
        IMPORTING
          ET_EVENTS       = IT_EVENTS
        EXCEPTIONS
          LIST_TYPE_WRONG = 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.
      LOOP AT IT_EVENTS INTO WA_EVENTS.
        CASE WA_EVENTS-NAME.
          WHEN 'TOP_OF_PAGE'.
            WA_EVENTS-FORM = 'FILL_LIST_HEADER'.
          WHEN 'USER_COMMAND'.
            WA_EVENTS-FORM = 'PROCESS_BASIC_LIST'.
        ENDCASE.
        MODIFY IT_EVENTS FROM WA_EVENTS INDEX SY-TABIX.
      ENDLOOP.
    ENDFORM.                    " GET_EVENT
          FORM FILL_LIST_HEADER                                         *
    FORM FILL_LIST_HEADER.
      WRITE:2'Report :' ,   SY-REPID,
           : 85 '         Intelligroup Asia Pvt Ltd' CENTERED,
           : 159 'Date  :' ,SY-DATUM,
           :/2'User   :',   SY-UNAME,
           : 82 '               Hyderabad         ' CENTERED ,
           : 159 'Pg.No :' ,SY-PAGNO,
           :/86 '           Stock Report    ' CENTERED.
      SKIP 2.
    ENDFORM.                    "FILL_LIST_HEADER
    *&      Form  DISPLAY_LIST
          text
    -->  p1        text
    <--  p2        text
    FORM DISPLAY_LIST .
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
       EXPORTING
      I_INTERFACE_CHECK              = ' '
      I_BYPASSING_BUFFER             =
      I_BUFFER_ACTIVE                = ' '
         I_CALLBACK_PROGRAM             = V_REPID
      I_CALLBACK_PF_STATUS_SET       = ' '
      I_CALLBACK_USER_COMMAND        = ' '
      I_STRUCTURE_NAME               =
         IS_LAYOUT                      = WA_LAYOUT
         IT_FIELDCAT                    = IT_FIELDCAT
      IT_EXCLUDING                   =
      IT_SPECIAL_GROUPS              =
         IT_SORT                        = IT_SORT[]
      IT_FILTER                      =
      IS_SEL_HIDE                    =
      I_DEFAULT                      = 'X'
      I_SAVE                         = ' '
      IS_VARIANT                     =
         IT_EVENTS                      = 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
    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.                    " DISPLAY_LIST
    *&      Form  do_sort
          text
    -->  p1        text
    <--  p2        text
    FORM DO_SORT .
    *-- Populating the sort table
      IT_SORT-FIELDNAME = 'MATNR'.
      IT_SORT-TABNAME = 'IT_FINAL'.
      IT_SORT-UP = 'X'.
    it_sort-subtot = 'X'.
      APPEND IT_SORT.
    ENDFORM.                    " do_sort
    Thanks & Regards
    Sreenivasulu P

  • ALV REPORT WITH MULTIPLE BLOCKS

    To print two blocks in a single ALV report, I have taken the sample and modified to my requirement.  I am having the following problems in this code.
          1.  Columnwise total not appearing.
          2.  Amount and numbers in all the columns are 
              left justified instead of right justified.
    The code written is given below.  Kindly check the same and suggest for corrections.
    --- SAMPLE 1--
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
           EXPORTING
                i_callback_program      = sy-cprog
                i_callback_user_command = 'USER_COMMAND'.
      PERFORM list_append TABLES IT_CTV
                           USING '1'
                                 'IT_CTV'.
      PERFORM list_append TABLES IT_APP
                           USING '2'
                                 'IT_APP'.
      PERFORM f_list_display.
          FORM USER_COMMAND                                             *
    FORM user_command USING i_ucomm     LIKE sy-ucomm
                            is_selfield TYPE slis_selfield.     "#EC CALLED
    ENDFORM.                               " USER_COMMAND
          Form  list_append
    FORM list_append TABLES ut_table
                     USING  u_no      TYPE char1
                            u_tabname TYPE slis_tabname.
      DEFINE m_fieldcat.
        ls_fieldcat-fieldname = &1.
        ls_fieldcat-ref_tabname = &2.
        append ls_fieldcat to lt_fieldcat.
      END-OF-DEFINITION.
      DEFINE m_sort.
        ls_sort-fieldname = &1.
        ls_sort-up        = 'X'.
        append ls_sort to lt_sort.
      END-OF-DEFINITION.
      DATA :
        ls_fieldcat TYPE slis_fieldcat_alv,
        lt_fieldcat TYPE slis_t_fieldcat_alv, " Field catalog
        ls_sort     TYPE slis_sortinfo_alv,
        lt_sort     TYPE slis_t_sortinfo_alv. " Sort table
      DATA:
        lt_events TYPE slis_t_event,
        ls_event  TYPE slis_alv_event,
        ls_layout TYPE slis_layout_alv.
      ls_layout-group_change_edit = 'X'.
      ls_layout-colwidth_optimize = 'X'.
      ls_layout-zebra             = 'X'.
      ls_layout-cell_merge        = 'X'.
      ls_layout-detail_popup      = 'X'.
      ls_layout-get_selinfos      = 'X'.
      ls_layout-max_linesize      = '300'.
      CASE u_no.
        WHEN '1'.
          ls_fieldcat-SELTEXT_L = ' REGION'.
          ls_fieldcat-DO_SUM = 'X'.
          m_fieldcat  'BZIRK' 'IT_CTV'.
          ls_fieldcat-SELTEXT_L = ' CTV STOCK'.
          m_fieldcat  'CTVST' 'IT_CTV'.
          ls_fieldcat-SELTEXT_L = ' CTV VALUE'.
          m_fieldcat  'CTVVL' 'IT_CTV'.
          m_sort  'BZIRK'.
          ls_fieldcat-DO_SUM = 'X'.
        WHEN '2'.
          ls_fieldcat-SELTEXT_L = ' REGION'.
          m_fieldcat  'BZIRK' 'IT_APP'.
          ls_fieldcat-SELTEXT_L = ' RFG STK'.
          m_fieldcat  'RFGST' 'IT_APP'.
          ls_fieldcat-SELTEXT_L = ' RFG VAL'.
          m_fieldcat  'RFGVL' 'IT_APP'.
          ls_fieldcat-SELTEXT_L = ' WM STK'.
          m_fieldcat  'WMCST' 'IT_APP'.
          ls_fieldcat-SELTEXT_L = ' WM VAL'.
          m_fieldcat  'WMCVL' 'IT_APP'.
          ls_fieldcat-SELTEXT_L = ' MCCS STK'.
          m_fieldcat  'MOVST' 'IT_APP'.
          ls_fieldcat-SELTEXT_L = ' MCCS VAL'.
          m_fieldcat  'MOVVL' 'IT_APP'.
          ls_fieldcat-SELTEXT_L = ' APP STK'.
          m_fieldcat  'APPST' 'IT_APP'.
         ls_fieldcat-SELTEXT_L = ' APP VAL'.
         m_fieldcat  'APPVL' 'IT_APP'.
          m_sort  'BZIRK'.
      ENDCASE.
    ls_fieldcat-COL_POS = 1.
    ls_fieldcat-FIELDNAME = 'BZIRK'.
    ls_fieldcat-DO_SUM = 'X'.
    ls_fieldcat-FIX_COLUMN = 'X'.
    APPEND ls_fieldcat TO lT_fieldcat.
      IF u_no CA '13'.
        MOVE        'TOP_OF_PAGE'        TO ls_event-name.
        CONCATENATE 'TOP_OF_PAGE' u_no INTO ls_event-form.
        APPEND ls_event TO lt_events.
      ELSE.
        MOVE        'TOP_OF_LIST'        TO ls_event-name.
        CONCATENATE 'TOP_OF_LIST' u_no INTO ls_event-form.
        APPEND ls_event TO lt_events.
      ENDIF.
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
           EXPORTING
                it_fieldcat                = lt_fieldcat
                is_layout                  = ls_layout
                i_tabname                  = u_tabname
                it_events                  = lt_events
                it_sort                    = lt_sort
           TABLES
                t_outtab                   = ut_table
           EXCEPTIONS
                program_error              = 1
                maximum_of_appends_reached = 2
                OTHERS                     = 3.
      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.                               " LIST_APPEND
          Form  f_list_display
    FORM f_list_display.
      DATA ls_print TYPE slis_print_alv.
      ls_print-no_print_selinfos  = 'X'.   " Display no selection infos
      ls_print-no_print_listinfos = 'X'.   " Display no listinfos
      ls_print-reserve_lines      = 2.     " Lines reserved for end of page
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
           EXPORTING
                i_interface_check = ' '
                is_print          = ls_print
           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.                               " F_LIST_DISPLAY
    Thanks in advance.
    A S VINCENT

    Hai Vincent
    Check the following Code
    *& Report  ZALV_BLOCK                                               *
    REPORT  ZALV_BLOCK NO STANDARD PAGE HEADING
                                    MESSAGE-ID ZZ.
    *..Type Definitions for ALV Report
    TYPE-POOLS SLIS.
    Table Declarations.                                        *
    TABLES: MARA,        "Material Master
            MARC,        "Plant Data for Material
            MARD,        "Storage Location Data for Material
            VBAP,        "Sales Document: Item Data
            VBUP.        "Sales Document: Item Status
    Internal table to store sales orders.......
    DATA: BEGIN OF IT_VBAP OCCURS 0,
            VBELN LIKE VBAP-VBELN,    "Sales Document
            POSNR LIKE VBAP-POSNR,    "Sales Document Item
            KWMENG LIKE VBAP-KWMENG,  "Cumulative order quantity in sales
                                       "                        Units
          END OF IT_VBAP.
    internal table to store final data
    DATA: BEGIN OF IT_FINAL OCCURS 0,
            WERKS LIKE MARD-WERKS,    "Plant
            MATNR LIKE MARD-MATNR,    "Material Number
            LGORT LIKE MARD-LGORT,    "Storage Location
            LABST LIKE MARD-LABST,    "Valuated stock with unrestricted use
            INSME LIKE MARD-INSME,    "Stock in quality inspection
            RETME LIKE MARD-RETME,    "Blocked Stock Returns
            UMLME LIKE MARD-UMLME,    "Stock in transfer
            MAKTX LIKE MAKT-MAKTX,    "Material description
            VBELN LIKE VBAP-VBELN,    "Sales Document
            POSNR LIKE VBAP-POSNR,    "Sales Document Item
            KWMENG LIKE VBAP-KWMENG,  "Cumulative order quantity in sales
                                       "                        Units
          END OF IT_FINAL.
    ALV Type declaration                                                 *
    *..Field Catalog for Basic List.
    DATA : IT_FIELDCAT  TYPE SLIS_T_FIELDCAT_ALV,
           WA_FIELDCAT  TYPE SLIS_FIELDCAT_ALV.
    *..Events For Basic List.
    DATA : IT_EVENTS TYPE SLIS_T_EVENT,
           WA_EVENTS TYPE SLIS_ALV_EVENT.
    *..Layout For Basic List
    DATA : WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
    *..Sort Table For Basic List
    DATA: IT_SORT TYPE SLIS_SORTINFO_ALV OCCURS 0 WITH HEADER LINE.
               DATA DECLARATIONS                                         *
    DATA: V_FLAG,
          VINDEX TYPE SY-TABIX,
          TOTAL TYPE VBAP-KWMENG.     "Open order quantity
    *..To Store Program Name
    DATA: V_REPID  TYPE SYREPID.
    *..To know whether basic list contains any data
    Selection Screen.                                                    *
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-H01.
    SELECT-OPTIONS: S_MATNR FOR MARA-MATNR,
                    S_WERKS FOR MARC-WERKS,
                    S_LGORT FOR MARD-LGORT.
    SELECTION-SCREEN END OF BLOCK B1.
    Event:Initialization                                                 *
    INITIALIZATION.
      V_REPID = SY-REPID.
    AT Selection Screen.                                                 *
    AT SELECTION-SCREEN.
      PERFORM VALIDATIONS.
    Event: Start-of-Selection                                            *
    START-OF-SELECTION.
         To get data from vbap into internal table IT_VBAP
      PERFORM FETCH_OPEN_DATA.
          To get data into final internal table IT_FINAL
      IF V_FLAG = 'X'.
        PERFORM FETCH_FINAL_DATA.
      ENDIF.
      IF V_FLAG = ''.
        MESSAGE I010 WITH 'NO DATA TO BE DISPLAYED'.
        EXIT.
      ELSE.
      --Setting the FIELD CATALOG for ALV
        PERFORM FILL_FIELDCAT_HEADER.
    *-----Setting the LAYOUT for ALV
        PERFORM GET_LAYOUT.
    *-----Getting the ALV Events
        PERFORM GET_EVENT.
    *---- To Sort the list
        PERFORM DO_SORT.
      ENDIF.
    Event: End-of-Selection                                            *
    END-OF-SELECTION.
    *--Generating the ALV LIST DISPLAY
      PERFORM DISPLAY_LIST.
                             FORM DEFINITIONS                            *
    *&      Form  VALIDATIONS
          To validate data in selection screen
    -->  p1        text
    <--  p2        text
    FORM VALIDATIONS.
      PERFORM VALIDATE_MATNR.
      PERFORM VALIDATE_WERKS.
      PERFORM VALIDATE_LGORT.
      IF NOT ( ( MARA-MATNR IS INITIAL ) AND
              ( MARC-WERKS IS INITIAL ) AND
              ( MARD-LGORT IS INITIAL ) ).
        SELECT SINGLE MATNR
                      WERKS
                      LGORT
                      FROM MARD
          INTO (MARD-MATNR, MARD-WERKS, MARD-LGORT)
          WHERE MATNR = MARA-MATNR
            AND WERKS = MARC-WERKS
            AND LGORT = MARD-LGORT.
      ENDIF.
    ENDFORM.                    " VALIDATIONS
    *&      Form  VALIDATE_MATNR
          To validate MATNR
    -->  p1        text
    <--  p2        text
    FORM VALIDATE_MATNR.
      IF NOT S_MATNR[] IS INITIAL.
        SELECT MATNR
               UP TO 1 ROWS
               INTO (MARD-MATNR)
               FROM MARA
               WHERE MATNR IN S_MATNR.
        ENDSELECT.
      ENDIF.
      IF SY-SUBRC NE 0.
        MESSAGE E000 WITH TEXT-001.
      ENDIF.
    ENDFORM.                    " VALIDATE_MATNR
    *&      Form  VALIDATE_WERKS
          To validate plant
    -->  p1        text
    <--  p2        text
    FORM VALIDATE_WERKS.
      IF NOT S_WERKS[] IS INITIAL.
        SELECT WERKS
               UP TO 1 ROWS
               INTO (MARD-WERKS)
               FROM MARC
               WHERE WERKS IN S_WERKS.
        ENDSELECT.
      ENDIF.
      IF SY-SUBRC NE 0.
        MESSAGE E000 WITH TEXT-002.
      ENDIF.
    ENDFORM.                    " VALIDATE_WERKS
    *&      Form  VALIDATE_LGORT
          To validate storage
    -->  p1        text
    <--  p2        text
    FORM VALIDATE_LGORT.
      IF NOT S_LGORT[] IS INITIAL.
        SELECT LGORT
               UP TO 1 ROWS
               INTO (MARD-LGORT)
               FROM MARD
               WHERE LGORT IN S_LGORT.
        ENDSELECT.
      ENDIF.
      IF SY-SUBRC NE 0.
        MESSAGE E000 WITH TEXT-003.
      ENDIF.
    ENDFORM.                    " VALIDATE_LGORT
    *&      Form  FETCH_OPEN_DATA
          To get data into internal table IT_VBAP
    -->  p1        text
    <--  p2        text
    FORM FETCH_OPEN_DATA.
      IF NOT ( ( MARA-MATNR IS INITIAL ) AND
               ( MARC-WERKS IS INITIAL ) AND
               ( MARD-LGORT IS INITIAL ) ).
        SELECT VBELN
               POSNR
               KWMENG
               INTO CORRESPONDING FIELDS OF TABLE IT_VBAP
               FROM VBAP
               WHERE MATNR IN S_MATNR
                 AND WERKS IN S_WERKS
                 AND LGORT IN S_LGORT.
      ENDIF.
      LOOP AT IT_VBAP.
        SELECT * FROM VBUP
                 INTO VBUP
                 WHERE VBELN = IT_VBAP-VBELN
                   AND POSNR = IT_VBAP-POSNR
                   AND LFSTA NE 'C'.
        ENDSELECT.
      ENDLOOP.
      IF SY-SUBRC NE 0.
        REFRESH IT_VBAP.
        MESSAGE E000 WITH TEXT-004.
        EXIT.
      ELSE.
        V_FLAG = 'X'.
      ENDIF.
          To get sum of all quantities as open order quantity
      LOOP AT IT_VBAP.
        TOTAL = TOTAL + IT_VBAP-KWMENG.
      ENDLOOP.
    ENDFORM.                    " FETCH_OPEN_DATA
    *&      Form  FETCH_FINAL_DATA
         To get data into final internal table IT_FINAL
    -->  p1        text
    <--  p2        text
    FORM FETCH_FINAL_DATA.
      SELECT A~MATNR
             A~WERKS
             A~LGORT
             MAKTX
             LABST
             INSME
             RETME
             UMLME
             VBELN
             POSNR
             KWMENG
             INTO CORRESPONDING FIELDS OF TABLE IT_FINAL
             FROM MARD AS A
             INNER JOIN MAKT AS B
             ON AMATNR = BMATNR
              AND SPRAS = 'E'
             INNER JOIN VBAP AS C
             ON AMATNR = CMATNR
             FOR ALL ENTRIES IN IT_VBAP
             WHERE VBELN = IT_VBAP-VBELN
               AND POSNR = IT_VBAP-POSNR
               AND KWMENG = IT_VBAP-KWMENG
               AND A~MATNR IN S_MATNR
               AND A~WERKS IN S_WERKS
               AND A~LGORT IN S_LGORT.
      IF SY-SUBRC NE 0.
        V_FLAG = SPACE.
        MESSAGE E001 WITH 'No data found IN the selection criteria'.
        EXIT.
      ELSE.
        V_FLAG = 'X'.
      ENDIF.
    ENDFORM.                    " FETCH_FINAL_DATA
    *&      Form  FILL_FIELDCAT_HEADER
          text
    -->  p1        text
    <--  p2        text
    FORM FILL_FIELDCAT_HEADER .
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
       EXPORTING
         I_PROGRAM_NAME               = V_REPID
         I_INTERNAL_TABNAME           = 'IT_FINAL'
      I_STRUCTURE_NAME             =
      I_CLIENT_NEVER_DISPLAY       = 'X'
         I_INCLNAME                   = V_REPID
      I_BYPASSING_BUFFER           =
      I_BUFFER_ACTIVE              =
        CHANGING
          CT_FIELDCAT                  = IT_FIELDCAT
       EXCEPTIONS
         INCONSISTENT_INTERFACE       = 1
         PROGRAM_ERROR                = 2
         OTHERS                       = 3
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      LOOP AT IT_FIELDCAT INTO WA_FIELDCAT.
        CASE WA_FIELDCAT-FIELDNAME.
          WHEN 'KWMENG'.
           WA_FIELDCAT-COL_POS = '11'.
           WA_FIELDCAT-OUTPUTLEN = '22'.
           WA_FIELDCAT-SELTEXT_L = 'Net Value'.
            WA_FIELDCAT-DO_SUM    = 'X'.
        ENDCASE.
        MODIFY IT_FIELDCAT FROM WA_FIELDCAT INDEX SY-TABIX.
      ENDLOOP.
    ENDFORM.                    " FILL_FIELDCAT_HEADER
    *&      Form  GET_LAYOUT
          text
    -->  p1        text
    <--  p2        text
    FORM GET_LAYOUT .
      WA_LAYOUT-TOTALS_TEXT = 'TOTAL'.
    ENDFORM.                    " GET_LAYOUT
    *&      Form  GET_EVENT
          text
    -->  p1        text
    <--  p2        text
    FORM GET_EVENT .
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          I_LIST_TYPE     = 0
        IMPORTING
          ET_EVENTS       = IT_EVENTS
        EXCEPTIONS
          LIST_TYPE_WRONG = 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.
      LOOP AT IT_EVENTS INTO WA_EVENTS.
        CASE WA_EVENTS-NAME.
          WHEN 'TOP_OF_PAGE'.
            WA_EVENTS-FORM = 'FILL_LIST_HEADER'.
          WHEN 'USER_COMMAND'.
            WA_EVENTS-FORM = 'PROCESS_BASIC_LIST'.
        ENDCASE.
        MODIFY IT_EVENTS FROM WA_EVENTS INDEX SY-TABIX.
      ENDLOOP.
    ENDFORM.                    " GET_EVENT
          FORM FILL_LIST_HEADER                                         *
    FORM FILL_LIST_HEADER.
      WRITE:2'Report :' ,   SY-REPID,
           : 85 '         Intelligroup Asia Pvt Ltd' CENTERED,
           : 159 'Date  :' ,SY-DATUM,
           :/2'User   :',   SY-UNAME,
           : 82 '               Hyderabad         ' CENTERED ,
           : 159 'Pg.No :' ,SY-PAGNO,
           :/86 '           Stock Report    ' CENTERED.
      SKIP 2.
    ENDFORM.                    "FILL_LIST_HEADER
    *&      Form  DISPLAY_LIST
          text
    -->  p1        text
    <--  p2        text
    FORM DISPLAY_LIST .
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
       EXPORTING
      I_INTERFACE_CHECK              = ' '
      I_BYPASSING_BUFFER             =
      I_BUFFER_ACTIVE                = ' '
         I_CALLBACK_PROGRAM             = V_REPID
      I_CALLBACK_PF_STATUS_SET       = ' '
      I_CALLBACK_USER_COMMAND        = ' '
      I_STRUCTURE_NAME               =
         IS_LAYOUT                      = WA_LAYOUT
         IT_FIELDCAT                    = IT_FIELDCAT
      IT_EXCLUDING                   =
      IT_SPECIAL_GROUPS              =
         IT_SORT                        = IT_SORT[]
      IT_FILTER                      =
      IS_SEL_HIDE                    =
      I_DEFAULT                      = 'X'
      I_SAVE                         = ' '
      IS_VARIANT                     =
         IT_EVENTS                      = 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
    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.                    " DISPLAY_LIST
    *&      Form  do_sort
          text
    -->  p1        text
    <--  p2        text
    FORM DO_SORT .
    *-- Populating the sort table
      IT_SORT-FIELDNAME = 'MATNR'.
      IT_SORT-TABNAME = 'IT_FINAL'.
      IT_SORT-UP = 'X'.
    it_sort-subtot = 'X'.
      APPEND IT_SORT.
    ENDFORM.                    " do_sort
    Thanks & Regards
    Sreenivasulu P

  • ALV Report with hierarchy

    hi guys,
    i am new to this forum. and need your help.
    i am developing a alv report for bom explosion.
    now the requirement is to show the material number node and the details like price, qty etc. in front of that.
    if the user clicks on the node he will see next level of materials nodes with similar details and so on. there can be more than 50 levels so manually adding nodes is not possible.
    i have checked bcalvtree programs but those programs wont help.
    Please suggest me any classes and methods to solve this problem......
    regards
    aj

    Hi,
    If u want to present ur report in tree format, u can use the following function module.
    U can go with ur normal query for selecting the data from database. While presenting it use the following fun. module.
    DATA : WA_KEYINFO TYPE SLIS_KEYINFO_ALV,
           WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
    DATA : IT_SALES_ITEM LIKE TABLE OF STRU WITH HEADER LINE.
    DATA : BEGIN OF  STRU_HEADER,
             EXPAND,
             ICONS(4),
             KUNNR LIKE VBAK-KUNNR, "Header field
            END OF STRU_HEADER.
    DATA :IT_SALES_HEADER LIKE TABLE OF STRU_HEADER WITH HEADER LINE.
      WA_KEYINFO-HEADER01 = 'KUNNR'. " Specify field eg.KUNNR
      WA_KEYINFO-ITEM01   = 'KUNNR'. " Specify field eg.KUNNR
      WA_LAYOUT-LIGHTS_FIELDNAME = 'ICONS'.
      WA_LAYOUT-EXPAND_FIELDNAME = 'EXPAND'.
      WA_LAYOUT-LIGHTS_TABNAME   = 'IT_Sales_Item'. "Specify Internal Table name
      WA_LAYOUT-BOX_TABNAME      = 'IT_Sales_Item'. "Specify Internal Table name
      CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
        EXPORTING
         I_CALLBACK_PROGRAM             = SY-REPID
         IS_LAYOUT                      = WA_LAYOUT
         IT_FIELDCAT                    = FCAT
          I_TABNAME_HEADER              = 'IT_Sales_Header'
          I_TABNAME_ITEM                = 'IT_Sales_Item'
          IS_KEYINFO                    = WA_KEYINFO
        TABLES
          T_OUTTAB_HEADER               = IT_SALES_HEADER
          T_OUTTAB_ITEM                 = IT_SALES_ITEM.
    Try with the above code.
    U can define ur own structure instead of IT_Sales_Item.

Maybe you are looking for

  • How to get hierarchy of a handling unit in delivery

    Hi All, We have a requirement of displaying in the form output highest level handling unit details(measurements length width and all). After that we want to display lower level handling units materials that has been packed.In the transaction Vl03n I

  • File to Idoc Scenario -- No Pipeline steps in Moni

    Hi, I have created a File2Idoc scenario. I have done all the configurations & finally dropped the file in source directory. File got picked up and deleted from source directory, But I could see in Moni only for the Inbound message but not able to see

  • Moving or zooming the canvas crashes my system.

    Been having this problem for a while now, and I just cannot seem to fix it. It also seems like nobody asked the exact same question before. All previous forum posts seem to be about photoshop itself crashing, while in my case my entire system locks u

  • BSOD Vista x64 After Waking from Sleep

    Hi. I recently re-installed my OS after purchasing a new MB (ASUS P8277-M LGA 1155). I in stalled a fresh (/mbr format) copy of WIN Vista x64. After my computer awakens from sleep mode a BSOD occurs. I've tried troubleshooting the issue with winDBg;

  • HT5622 Can I download free apps without putting in credit card information

    I've created an Apple ID but every time I go to download a free app it wants me to put in billing info