Turning Tables in ABAP for ALV Display

Dear all,
I am running in a (for me) tricky problem:
I read any table definitions from the dictionary with function "DDIF_TABL_GET". In the next step I want to build a ALV Grid that displays some of the read data but not in rows but in lines.
Ok how does this look like:
For example use funktion DDIF_TABL_GET and use table MAKT as table parameter:
Result:
                                                                                TABNAME                        FIELDNAME                      DD POSI K M ROLLNAME                       CHECKTABLE                     A I INTLEN REFTABLE                                                                               
MAKT                           MANDT                          DE 0001 X   MANDT                          T000                           0 C 000003                 
MAKT                           MATNR                          DE 0002 X   MATNR                          MARA                           0 C 000018                 
MAKT                           SPRAS                          DE 0003 X   SPRAS                          T002                           0 C 000001                 
MAKT                           MAKTX                          DE 0004     MAKTX                                                         0 C 000040                 
MAKT                           MAKTG                          DE 0005     MAKTG                                                         0 C 000040
Ok what I want to do now is dynamically create a alv-Grid that shows the entries from the result above as list:
Example:
MAKT     MAKT     MAKT     MAKT     MAKT
MANDT     MATNR     SPRAS     MAKTX     MAKTG
DE     DE     DE     DE     DE
0001     0002     0003     0004     0005
X     X     X          
MANDT     MATNR     SPRAS     MAKTX     MAKTG
There is a funktion in Excel called "Transponieren" (transpond) that does the same I search.
So the secret question is how to do this with ALV and dynamically???
Any idea?
Kind reagard for any hints and helps
Roman Becker

Hi Roman,
my answer is kind of abstract: I implemented just the internal tables transposal.
I defined a structure of 99 string components, si you can put in whatever you want.
For illustration I fill the table with identifiers for row and column and the do the exel-like transposal.
The original table is lt_itab, the transposed one lt_trsp.
I used the string component's structure a couple of times now. This is smart because it won't waste more memory than needed.
Just cut&paste to get an idea, hope you like it!
FORM tab_transpose.
  TYPES:
    BEGIN OF ty_compstr,
    f01                         TYPE string,
    f02                         TYPE string,
    f03                         TYPE string,
    f04                         TYPE string,
    f05                         TYPE string,
    f06                         TYPE string,
    f07                         TYPE string,
    f08                         TYPE string,
    f09                         TYPE string,
    f10                         TYPE string,
    f11                         TYPE string,
    f12                         TYPE string,
    f13                         TYPE string,
    f14                         TYPE string,
    f15                         TYPE string,
    f16                         TYPE string,
    f17                         TYPE string,
    f18                         TYPE string,
    f19                         TYPE string,
    f20                         TYPE string,
    f21                         TYPE string,
    f22                         TYPE string,
    f23                         TYPE string,
    f24                         TYPE string,
    f25                         TYPE string,
    f26                         TYPE string,
    f27                         TYPE string,
    f28                         TYPE string,
    f29                         TYPE string,
    f30                         TYPE string,
    f31                         TYPE string,
    f32                         TYPE string,
    f33                         TYPE string,
    f34                         TYPE string,
    f35                         TYPE string,
    f36                         TYPE string,
    f37                         TYPE string,
    f38                         TYPE string,
    f39                         TYPE string,
    f40                         TYPE string,
    f41                         TYPE string,
    f42                         TYPE string,
    f43                         TYPE string,
    f44                         TYPE string,
    f45                         TYPE string,
    f46                         TYPE string,
    f47                         TYPE string,
    f48                         TYPE string,
    f49                         TYPE string,
    f50                         TYPE string,
    f51                         TYPE string,
    f52                         TYPE string,
    f53                         TYPE string,
    f54                         TYPE string,
    f55                         TYPE string,
    f56                         TYPE string,
    f57                         TYPE string,
    f58                         TYPE string,
    f59                         TYPE string,
    f60                         TYPE string,
    f61                         TYPE string,
    f62                         TYPE string,
    f63                         TYPE string,
    f64                         TYPE string,
    f65                         TYPE string,
    f66                         TYPE string,
    f67                         TYPE string,
    f68                         TYPE string,
    f69                         TYPE string,
    f70                         TYPE string,
    f71                         TYPE string,
    f72                         TYPE string,
    f73                         TYPE string,
    f74                         TYPE string,
    f75                         TYPE string,
    f76                         TYPE string,
    f77                         TYPE string,
    f78                         TYPE string,
    f79                         TYPE string,
    f80                         TYPE string,
    f81                         TYPE string,
    f82                         TYPE string,
    f83                         TYPE string,
    f84                         TYPE string,
    f85                         TYPE string,
    f86                         TYPE string,
    f87                         TYPE string,
    f88                         TYPE string,
    f89                         TYPE string,
    f90                         TYPE string,
    f91                         TYPE string,
    f92                         TYPE string,
    f93                         TYPE string,
    f94                         TYPE string,
    f95                         TYPE string,
    f96                         TYPE string,
    f97                         TYPE string,
    f98                         TYPE string,
    f99                         TYPE string,
    END OF ty_compstr.
  DATA:
    lt_itab TYPE TABLE OF ty_compstr,
    lt_trsp TYPE TABLE OF ty_compstr,
    ls_irec TYPE ty_compstr,
    lv_num2 TYPE num2,
    lv_num2_i TYPE num2.
  FIELD-SYMBOLS:
    <anyfield> TYPE ANY,
    <anyrec> TYPE ANY,
    <anyfield_t> TYPE ANY,
    <anyrec_t> TYPE ANY.
random fill
  DO 99 TIMES.
    lv_num2 = sy-index.
    DO 99 TIMES.
      ASSIGN COMPONENT sy-index OF STRUCTURE ls_irec TO <anyfield>.
      lv_num2_i = sy-index.
      CONCATENATE 'ROW' lv_num2 'COL' lv_num2_i ':' <anyfield>
        INTO <anyfield> SEPARATED BY space.
    ENDDO.
    APPEND ls_irec TO lt_itab.
  ENDDO.
Transposal
  LOOP AT lt_itab ASSIGNING <anyrec>.
    lv_num2 = sy-tabix.
    DO.
      lv_num2_i = sy-index.
      ASSIGN COMPONENT sy-index OF STRUCTURE <anyrec> TO <anyfield>.
      IF sy-subrc <> 0.
        EXIT.
      ENDIF.
      READ TABLE lt_trsp INDEX lv_num2_i ASSIGNING <anyrec_t>.
      IF sy-subrc <> 0.
        APPEND INITIAL LINE TO lt_trsp.
        READ TABLE lt_trsp INDEX sy-tfill ASSIGNING <anyrec_t>.
      ENDIF.
      ASSIGN COMPONENT lv_num2 OF STRUCTURE <anyrec_t> TO <anyfield_t>.
      <anyfield_t> = <anyfield>.
    ENDDO.
  ENDLOOP." at lt_itab assigning <anyrec>.
ENDFORM.                    " tab_transpose
C.

Similar Messages

  • DIfference between Reusable FM for ALV display and ALV display using class

    Hi,
    Is there any difference between alv display using Resuable FM and ALV display using classes except the later one uses OO concept.??
    One mere thing i want to clarify is that is there any difference exist between REUSE_ALV_GRID_DISPLAY and REUSE_ALV_LIST_DISPLAY? If so, then let me know.
    It could be easier to understand me if yuo give scenario where these FM comes into picture
    Regards,
    Parag

    Hi,
    (1) REUSE_ALV_LIST_DISPLAY
    Display an ALV list as per parameters defined in the function call
    (2) REUSE_ALV_GRID_DISPLAY
    Display an ALV grid as per parameters defined in the function call
    (3) REUSE_ALV_COMMENTARY_WRITE
    List header information is output according to its type. The output information is put in an internal table. Output attributes are assigned to each line via the TYP field.This module outputs formatted simple header information at TOP-OF-PAGE.
    (4) REUSE_ALV_HIERSEQ_LIST_DISPLAY
    This module outputs two internal tables as a formated hierarchical-sequential list.
    (5) REUSE_ALV_VARIANT_F4
    Display variant selection dialog box.
    (6) REUSE_ALV_VARIANT_EXISTENCE
    Checks whether a display variant exists.
    Other Useful Link :
    Customize ALV grid layout at run time
    Download ALV grid Control Tutorial
    Understand ALV report ( Just Copy and paste )
    Dynamic selection on ALV at run time
    Dynamic selection on ALV at run time
    Regards
    Kiran

  • How to use filter for alv display in webdynpro

    hi,
         i have use select-options and what ever data is coming from the data base i display it using alv.
    i also want to include functionality like filter and all that , that comes in normal alv.please guide me how can i do it.
    thanks

    hi please remind  that this is not the proper forum for this ...go to this
    Expert Forums » ABAP Development » UI Programming

  • Help for alv display

    HI experts,
    I have a requiment to display in ALV out put, for the TEXT COLUMM i need to display in single cell  not in multiple cells.
    please find below sceens for ref. so please help me how to proceeed its very urjent..
    As is
    To BE

    Hi Raghu,
    Please use word wrap functionality.
    Refer to the link below for more information:
    Word Wrap Functionality in ALV
    Regards,
    Ashvin

  • Code for hr-abap report in alv display

    Hi Gurus,
    I am new to hr-abap and I want some sample code to display a hr report in an alv.
    Thanks,
    Raj.

    This is one such...
    REPORT yh_rep_hr_certified_instructor MESSAGE-ID yh_messages NO STANDARD
    PAGE
    HEADING .
    Program      : YH_REP_HR_CERTIFIED_INSTRUCTOR                        *
    Description  : Certified Instructor Eligibility Criteria             *
                       TABLES                                       *
    TABLES :hrp1000 ,hrp1001, pa0000.
                          TYPE-POOLS                                 *
    *Type Pool for ALV display
    TYPE-POOLS :slis.  " Global types for generic cunning components
                    INTERNAL TABLES                                 *
    *Internal Table to keep Selection Screen field values
    DATA : BEGIN OF t_validation OCCURS 0.
            INCLUDE STRUCTURE dynpread.
    DATA END OF t_validation.
    *Internal Table for Business Event Groups
    DATA : BEGIN OF t_bgrp OCCURS 0,
            objid TYPE hrobjid,
            blank(1),
            stext TYPE stext,
           END OF t_bgrp.
    *Internal Table for Business Event Type IDs with text for selected Event
    *GROUPS
    DATA : BEGIN OF t_btyp OCCURS 0,
            objid TYPE hrobjid,
            blank(1),
            stext TYPE stext,
           END OF t_btyp.
    *Internal Table for Business Event Type IDs for selected Event Groups
    DATA : BEGIN OF t_eventtypelist OCCURS 0,
            objid TYPE hrobjid,
           END OF t_eventtypelist.
    *Internal table to store the business Groups
    DATA : BEGIN OF t_group OCCURS 0,
            objid LIKE hrp1001-objid,
            sobid LIKE hrp1001-sobid,
            sclas LIKE hrp1001-sclas,
           END OF t_group.
    *Internal table to hold the business event group and/or bus. event types
    DATA : BEGIN OF t_eventgroup OCCURS 0,
            objid LIKE hrp1001-objid,
           END OF t_eventgroup.
    *Internal Table for FieldCatalog used for ALV Display
    DATA: t_fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE.
    *Work Area for Checking Business Event Group Validity
    DATA: BEGIN OF wa_bgrp,
           objid TYPE hrobjid,
           stext TYPE stext,
          END OF wa_bgrp.
    *Internal table to fetch object id for Qualification
    DATA: BEGIN OF t_objid OCCURS 0,
           objid TYPE hrp1000-objid,
           sobid TYPE hrp1001-sobid,
           sobid_copy TYPE hrp1001-objid,
          END OF t_objid.
    *Internal table to fetch Id of related object
    *Fetches Pernr of Certified Instructors
    DATA: BEGIN OF t_sobid OCCURS 0,
           objid TYPE hrp1000-objid,
           sobid TYPE hrp1001-sobid,
           adatanr TYPE hrpad31-adatanr,
           sobid_copy TYPE hrp1001-objid,
         END OF t_sobid.
    *Internal table to fetch skill rating
    *of the Instructor
    DATA: BEGIN OF t_prof OCCURS 0,
            adatanr TYPE hrpad31-adatanr,
            chara TYPE hrpad31-chara,
          END OF t_prof.
    *Internal table to fetch grade
    *of the Insturctor
    DATA: BEGIN OF t_grade OCCURS 0,
           pernr TYPE pa0008-pernr,
           yysalgr TYPE pa0008-yysalgr,
          END OF t_grade.
    *Internal table which contains all information about the Person like
    *Name Project Project Manager Name Account and Vertical Name
    DATA: t_projdetails TYPE zbapi_projdetails OCCURS 0 WITH HEADER LINE.
    *Final Internal table which contains all information
    *about the Instructors
    DATA: BEGIN OF t_final OCCURS 0,
             empid TYPE pa0000-pernr,
             empname(84) TYPE c,
             grade TYPE pa0008-yysalgr,
             atndttt(3) TYPE c,
             sklrate TYPE hrpad31-chara,
             pgmng TYPE pa0001-ename,
             accname TYPE hrp1000-stext,
             vertname TYPE hrp1000-stext,
           END OF t_final.
                         VARIABLES                                  *
    *ALV layout
    DATA: gs_layout TYPE slis_layout_alv, "alvtot test
          gt_events TYPE slis_t_event,
          gt_list_top_of_page TYPE slis_t_listheader,
          gs_variant LIKE disvariant,     "For Layout
          g_save.                         "For Layout Save
    DATA: w_pos TYPE i VALUE 1,            " Position of Fields in ALV
          w_sort TYPE slis_t_sortinfo_alv, "ITab for Sorting Options
          w_flag TYPE i,
          w_repid TYPE sy-repid,
          w_lineno TYPE sy-tabix.
    DATA: l_short TYPE hrp1000-short. "variable to check the heirarchy
                     SELECTION-SCREEN DESIGN                            *
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. "NO INTERVALS .
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 1(20) text-009 MODIF ID xyz.
    PARAMETERS : p_bgrp TYPE hrobjid OBLIGATORY,
                 p_bgrp1 TYPE stext .
    SELECTION-SCREEN END OF LINE.
    SELECT-OPTIONS :s_btyp FOR hrp1000-objid OBLIGATORY NO INTERVALS.
    SELECTION-SCREEN END OF BLOCK b1.
                            INITIALIZATION                               *
    INITIALIZATION.
    *Assign Program Name into a variable
      w_repid = sy-repid.
    *Build layout for list display
      gs_layout-detail_popup      = 'X'.
    *To get All Events in TOP-OF-PAGE
    perform eventtab_build using gt_events[].
      gs_variant-report = w_repid.
      g_save           = 'A'.
                         AT SELECTION SELECTION                          *
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_bgrp.
      PERFORM get_bgrp.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_btyp-low.
      IF NOT p_bgrp IS INITIAL .
        PERFORM get_btyp USING 'l'.
      ELSE .
        MESSAGE s999 WITH text-e09.
      ENDIF.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_btyp-high.
      IF NOT p_bgrp IS INITIAL .
        PERFORM get_btyp USING 'h'.
      ELSE .
        MESSAGE s999 WITH text-e09.
      ENDIF.
    AT SELECTION-SCREEN ON p_bgrp.
      SELECT SINGLE objid stext
             FROM hrp1000
             INTO wa_bgrp
             WHERE objid = p_bgrp AND
             otype = 'L' AND
             plvar = '01' AND
             ( short = 'ROLE' OR
             short = 'TECH_PROGRAM' ).
      IF sy-subrc EQ 0.
        p_bgrp1 = wa_bgrp-stext.
      ELSE.
        MESSAGE e999 WITH text-e09.
      ENDIF.
    AT SELECTION-SCREEN ON s_btyp.
      CLEAR : t_eventtypelist, t_group, t_eventgroup.
      REFRESH : t_eventtypelist, t_group, t_eventgroup.
      CLEAR : w_flag.
    *Fetch all the subordinates under given Event Group - L/D
      SELECT objid
             sobid
             sclas
                 FROM hrp1001
                 INTO TABLE t_group
                 WHERE objid = p_bgrp
                 AND plvar = '01'
                 AND rsign = 'B'
                 AND relat = '003'
                 AND ( sclas = 'L' OR sclas = 'D' ).
      WHILE w_flag <> 1.
        PERFORM get_objids.
      ENDWHILE.
      IF NOT t_eventtypelist[] IS INITIAL.
    *Get only valid Event Types from input Event Types, for given Event
    *Group - by deleting others..
        LOOP AT t_eventtypelist.
          IF t_eventtypelist-objid IN s_btyp.
            EXIT.
          ELSE.
            DELETE t_eventtypelist.
          ENDIF.
          AT LAST.
    *since we r checking Event Types, All other fields will be locked
    *but we need Event Group field to be unlocked to edit again,
    *if theres no theres no valid Event Types in given input
            LOOP AT SCREEN.
              CHECK screen-name = 'P_bgrp'.
              screen-input = '1'.
              MODIFY SCREEN.
            ENDLOOP.
            MESSAGE e999 WITH text-e04.
            EXIT.
          ENDAT.
        ENDLOOP.
      ELSE.
        LOOP AT SCREEN.
          CHECK screen-name = 'P_bgrp'.
          screen-input = '1'.
          MODIFY SCREEN.
        ENDLOOP.
        MESSAGE e999 WITH text-e03.
      ENDIF.
          FORM get_bgrp                                                 *
    FORM get_bgrp .
      SELECT objid stext
             FROM hrp1000
             INTO CORRESPONDING FIELDS OF TABLE t_bgrp
             WHERE plvar = '01' AND
                   otype = 'L' AND
                   short = 'ROLE' OR
                   short = 'TECH_PROGRAM' .
      CALL FUNCTION 'POPUP_WITH_TABLE_DISPLAY'
        EXPORTING
          endpos_col   = 75
          endpos_row   = 20
          startpos_col = 30
          startpos_row = 05
          titletext    = 'Select Business Event Group'
        IMPORTING
          choise       = w_lineno
        TABLES
          valuetab     = t_bgrp
        EXCEPTIONS
          break_off    = 1
          OTHERS       = 2.
      IF sy-subrc EQ 0 .
        READ TABLE t_bgrp INDEX w_lineno.
        IF sy-subrc EQ 0.
          p_bgrp = t_bgrp-objid.
          p_bgrp1 = t_bgrp-stext.
        ENDIF .
        CLEAR t_bgrp .
        REFRESH  t_bgrp .
      ENDIF .
    ENDFORM .                    "get_bgrp
    ****subroutine for business eventtype input criteria
    FORM get_btyp USING f_range.
      CLEAR :   t_validation,
                t_btyp,
                t_eventtypelist,
                t_group,
                t_eventgroup,
                w_flag.
      REFRESH : t_validation,
                t_btyp,
                t_eventtypelist,
                t_group,
                t_eventgroup.
      t_validation-fieldname = 'P_BGRP'.
      APPEND t_validation.
      CLEAR t_validation.
    *Getting Screen Values
      CALL FUNCTION 'DYNP_VALUES_READ'
        EXPORTING
          dyname               = w_repid
          dynumb               = '1000'
        TABLES
          dynpfields           = t_validation
        EXCEPTIONS
          invalid_abapworkarea = 1
          invalid_dynprofield  = 2
          invalid_dynproname   = 3
          invalid_dynpronummer = 4
          invalid_request      = 5
          no_fielddescription  = 6
          invalid_parameter    = 7
          undefind_error       = 8
          double_conversion    = 9
          stepl_not_found      = 10
          OTHERS               = 11.
      IF sy-subrc NE 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      READ TABLE t_validation WITH KEY fieldname = 'P_BGRP'.
      IF NOT t_validation-fieldname IS INITIAL.
    *Getting Event Group ID that entered
        LOOP AT t_validation.
          IF t_validation-fieldname = 'P_BGRP'.
            p_bgrp = t_validation-fieldvalue.
          ENDIF.
        ENDLOOP.
        CLEAR t_validation.
        REFRESH t_validation.
    *To fetch the business event groups and business event types that belong
    to the input business event group.Since a business group can have a
    *business groups as well as business event types we have pick all of
    *them
    *Getting all subordinates - Event Group/Type under given Event Group
        SELECT objid
               sobid
               sclas
                   FROM hrp1001
                   INTO TABLE t_group
                   WHERE objid = p_bgrp
                   AND plvar = '01'
                   AND rsign = 'B'
                   AND relat = '003'
                   AND endda = '99991231'
                   AND ( sclas = 'L' OR sclas = 'D' ).
    *Getting all Event Types
        WHILE w_flag <> 1.
          PERFORM get_objids.
        ENDWHILE.
        IF NOT t_eventtypelist[] IS INITIAL.
          SORT t_eventtypelist BY objid.
    *Getting Names of Event Types
          SELECT objid
                 stext
                      FROM hrp1000
                      INTO CORRESPONDING FIELDS OF TABLE t_btyp
                      FOR ALL ENTRIES IN t_eventtypelist
                      WHERE objid = t_eventtypelist-objid
                      AND otype = 'D' AND plvar = '01'
                      AND endda = '99991231'.
          IF sy-subrc = 0.
    *PopUp Display for Event Types
            CALL FUNCTION 'POPUP_WITH_TABLE_DISPLAY'
              EXPORTING
                endpos_col   = 75
                endpos_row   = 20
                startpos_col = 30
                startpos_row = 05
                titletext    = 'Select Business Event Type ID'
              IMPORTING
                choise       = w_lineno
              TABLES
                valuetab     = t_btyp
              EXCEPTIONS
                break_off    = 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.
            ELSE.
    *Since the Table returned by function module will have data in Header,
    *clear the Header
    *Retreive Selected Event Type into Select Option
              READ TABLE t_btyp INDEX w_lineno.
              IF sy-subrc EQ 0.
                IF f_range = 'l'.
                  s_btyp-low = t_btyp-objid.
                ELSE.
                  s_btyp-high = t_btyp-objid.
                ENDIF.
              ENDIF.
            ENDIF.
          ELSE.
            MESSAGE s999 WITH text-e03.
          ENDIF.
        ELSE.
          MESSAGE s999 WITH text-e01.
        ENDIF.
      ENDIF.
    ENDFORM.                    " EVNTTY
          FORM get_objids                                               *
    FORM get_objids.
    *To delete the business event types that are found and push it in
    *another table
      IF NOT t_group[] IS INITIAL.
        LOOP AT t_group.
    *If event type
          IF t_group-sclas = 'D'.
            t_eventtypelist-objid = t_group-sobid.
            APPEND t_eventtypelist.
            CLEAR t_eventtypelist.
            DELETE t_group.
    *If event group
          ELSEIF t_group-sclas = 'L'.
            t_eventgroup-objid = t_group-sobid.
            APPEND t_eventgroup.
            CLEAR t_eventgroup.
            DELETE t_group.
            CLEAR t_group.
          ENDIF.
        ENDLOOP.
      ELSE.
        w_flag = 1.
      ENDIF.
      IF NOT t_eventgroup[] IS INITIAL.
    *To get the second level of business groups and business event type
        SELECT objid sobid sclas
               FROM hrp1001
               INTO TABLE t_group
               FOR ALL ENTRIES IN t_eventgroup
               WHERE objid = t_eventgroup-objid
               AND plvar = '01'
               AND rsign = 'B'
               AND relat = '003'
               AND endda = '99991231'
               AND ( sclas = 'L' OR sclas = 'D' ).
        CLEAR t_eventgroup.
        REFRESH t_eventgroup.
      ENDIF.
    ENDFORM.                    " GET_OBJIDS
                           Start of Selection                            *
    START-OF-SELECTION.
    *Pass the Event Type and fetch the Related Id
    *for the Qualification imparted by the Event
      SELECT objid sobid
             FROM hrp1001
             INTO TABLE t_objid
             WHERE objid IN s_btyp AND
                   otype = 'D' AND
                   plvar = '01' AND
                   relat = '028' AND
                   rsign = 'A' AND
                   sclas = 'Q'.
      IF sy-subrc EQ 0.
    *Pass the Qualification Id and fetch Object Id of the
    *person who fulfills this Qualification
        SELECT objid sobid adatanr
           FROM hrp1001
           INTO TABLE t_sobid FOR ALL ENTRIES IN t_objid
           WHERE sobid = t_objid-sobid AND
                 otype = 'P' AND
                 plvar = '01' AND
                 relat = '032' AND
                 rsign = 'A' AND
                 sclas = 'Q' .
        IF sy-subrc = 0.
    *Fetch only the Person along with the skillrating
    *who has skill rating as '0001' or '0003'
          SELECT adatanr chara
                 FROM hrpad31
                 INTO TABLE t_prof
                 FOR ALL ENTRIES IN t_sobid
                 WHERE adatanr = t_sobid-adatanr AND
                ( chara = '0001' OR chara = '0003' ).
          IF sy-subrc NE 0.
            MESSAGE s999 WITH text-s01.
            EXIT .
          ELSE .
    *Fetch only Employee Id's who meets the required skill rating
    *which inturn has the EMPID who are all are Certified Instructors
            LOOP AT t_sobid.
              READ TABLE t_prof WITH KEY adatanr = t_sobid-adatanr.
              IF sy-subrc NE 0.
                DELETE t_sobid .
              ENDIF.
            ENDLOOP.
            SORT t_sobid BY objid.
            DELETE ADJACENT DUPLICATES FROM t_sobid.
          ENDIF.
        ENDIF.
      ENDIF.
      IF NOT t_sobid[] IS INITIAL.
    data: begin of it_trgpernr occurs 0,
             objid type hrp1000-objid,
             sobid type hrp1001-sobid,
           end of it_trgpernr.
    select objid sobid
            from hrp1001
            into table it_trgpernr for all entries in t_sobid
            where  otype ='P' and
                  objid = t_sobid-objid and
                  sclas = 'D' and
                  sobid = '50008220'.
    *Fetch Grade of the Certified Instructors by passing their EmpId's
        SELECT pernr yysalgr
                     FROM pa0008
                     INTO TABLE t_grade
                     FOR ALL ENTRIES IN t_sobid
                     WHERE pernr = t_sobid-objid AND endda = '99991231'.
      ENDIF.
    For Heading in the Output Display Layout
      PERFORM heading USING gt_list_top_of_page[].
                           End of Selection                              *
    END-OF-SELECTION.
    Populating data into Final Table which contains all information aboutthe Certified Instructors
    *Retrieve Employee Id for the Certified Instructors  only if he is active
      LOOP AT t_sobid.
        SELECT SINGLE *
               FROM pa0000
               WHERE pernr = t_sobid-objid  AND
                     begda <= sy-datum AND
                     endda >= sy-datum AND
                     stat2 ='3'.
        IF sy-subrc = 0.
          t_final-empid = t_sobid-objid.
          SELECT  SINGLE *
                FROM hrp1001
                WHERE otype = 'P' AND
                      objid = t_sobid-objid AND
                      rsign = 'B' AND
                      relat = '25' AND
                      sclas = 'D' AND
                      sobid = '50008220'.
    *DATA:W_SOBID TYPE HRP1001-SOBID.
    *W_SOBID = t_sobid-objid.                 .
         SELECT  SINGLE *
               FROM hrp1001
               WHERE otype = 'D' AND
                     objid = '50008220' AND
                     rsign = 'B' AND
                     relat = '25' AND
                     sclas = 'P' AND
                     sobid = W_SOBID.
          IF sy-subrc EQ 0.
            t_final-atndttt = 'YES'.
          ELSE.
            t_final-atndttt = 'NO'.
          ENDIF.
    *Retrieve Employee SkillRating for the Certified Instructors
    *by passing the adatanr value which inturn is fetched based on the empid
          READ TABLE t_prof WITH KEY adatanr = t_sobid-adatanr.
          IF sy-subrc EQ 0.
            t_final-sklrate = t_prof-chara.
          ENDIF.
    *Retrieve Employee Grade for the given id
          READ TABLE t_grade WITH KEY pernr = t_sobid-objid.
          IF sy-subrc EQ 0.
            t_final-grade = t_grade-yysalgr.
          ENDIF.
          REFRESH t_projdetails.
          CLEAR t_projdetails.
    *function which fetches the name project name account and
    *vertical name of the person for the given empid
          CALL FUNCTION 'ZBAPI_PROJDETAILS'
            EXPORTING
              pernr       = t_sobid-objid
            TABLES
              it_finaltab = t_projdetails.
          IF NOT t_projdetails[] IS INITIAL.
            SHIFT t_sobid-objid LEFT DELETING LEADING '0'.
            READ TABLE t_projdetails WITH KEY pernr = t_sobid-objid.
            IF sy-subrc EQ 0.
              t_final-empname = t_projdetails-ename.
              IF NOT t_projdetails-proj IS INITIAL.
                t_final-pgmng = t_projdetails-pmname.
              ELSE.
                t_final-pgmng = t_projdetails-gmname.
              ENDIF.
              t_final-accname = t_projdetails-accname.
              t_final-vertname = t_projdetails-vertname.
            ENDIF.
          ENDIF.
          APPEND t_final.
        ENDIF.
        CLEAR t_final.
      ENDLOOP.
      SORT t_final BY empid.
      DELETE ADJACENT DUPLICATES FROM t_final.
    *Enabling Sort by PERNR & Global ID in ALV display
      PERFORM sub_sort_info.
    *Form to Populate Field Catalog
      PERFORM populate_fieldcatalog.
    For the ALV ROW Optimize Width
      gs_layout-colwidth_optimize = 'X' .
    *perform alv_display tables final fieldcatalog.
      IF NOT t_final[] IS INITIAL.
        CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
          EXPORTING
            i_callback_program = w_repid
            is_layout          = gs_layout
            it_fieldcat        = t_fieldcatalog[]
            it_sort            = w_sort
            i_save             = 'A'
            it_events          = gt_events[]
          TABLES
            t_outtab           = t_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.
      ELSE.
        MESSAGE s000(vz) WITH 'No Records found for Given Input Criteria'.
      ENDIF.
                             TOP OF PAGE                                 *
    *Outputs formatted simple header information at TOP-OF-PAGE.
    TOP-OF-PAGE.
      PERFORM top_of_page.
                             Subroutines                                 *
    *&      Form  eventtab_build
          text`
         -->P_GT_EVENTS[]  text
    FORM eventtab_build USING  rt_events  TYPE slis_t_event.
      DATA: ls_event TYPE slis_alv_event.
      DATA: g_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type = 0
        IMPORTING
          et_events   = rt_events.
      READ TABLE rt_events WITH KEY name = slis_ev_top_of_page
                               INTO ls_event.
      IF sy-subrc = 0.
        MOVE g_top_of_page TO ls_event-form.
        APPEND ls_event TO rt_events.
      ENDIF.
    ENDFORM.                    " eventtab_build
    *&      Form  HEADING
          text
    FORM heading USING lt_top_of_page TYPE slis_t_listheader.
      DATA: ls_line TYPE slis_listheader.
    *Layout Display Text - "Caritor ( India ) Pvt.Ltd "
      CLEAR ls_line.
      ls_line-typ  = 'H'.
      ls_line-info = text-h01.
      APPEND ls_line TO lt_top_of_page.
    *Layout Display Text - "Certified Instructor Eligibility List     "
      CLEAR ls_line.
      ls_line-typ  = 'H'.
      ls_line-info = text-h02.
      APPEND ls_line TO lt_top_of_page.
    ENDFORM.                    " HEADING
    *&      Form  top_of_page
          text
    -->  p1        text
    <--  p2        text
    FORM top_of_page.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary = gt_list_top_of_page.
    ENDFORM.                    " top_of_page
    *&      Form  sub_sort_info
          text
    -->  p1        text
    <--  p2        text
    FORM sub_sort_info.
      DATA : l_sort TYPE slis_sortinfo_alv .
      CLEAR l_sort.
    Employee ID
      l_sort-fieldname = 'EMPID'.
      l_sort-up        = 'X'.
      APPEND l_sort TO w_sort.
    ENDFORM.                    " sub_sort_info
    *&      Form  populate_fieldcatalog
          text
    -->  p1        text
    <--  p2        text
    FORM populate_fieldcatalog.
      PERFORM fill_fields_of_fieldcatalog
               TABLES t_fieldcatalog
               USING 'T_FINAL' 'EMPID' ' ' text-011 20 w_pos.
      PERFORM fill_fields_of_fieldcatalog
               TABLES t_fieldcatalog
               USING 'T_FINAL' 'EMPNAME' ' ' text-002 20 w_pos.
      PERFORM fill_fields_of_fieldcatalog
              TABLES t_fieldcatalog
              USING 'T_FINAL' 'GRADE' ' ' text-003 20 w_pos.
      PERFORM fill_fields_of_fieldcatalog
              TABLES t_fieldcatalog
              USING 'T_FINAL' 'ATNDTTT' ' ' text-004 20 w_pos.
      PERFORM fill_fields_of_fieldcatalog
              TABLES t_fieldcatalog
              USING 'T_FINAL' 'PGMNG' ' ' text-006 20 w_pos.
      PERFORM fill_fields_of_fieldcatalog
              TABLES t_fieldcatalog
              USING 'T_FINAL' 'ACCNAME' ' ' text-007 20 w_pos.
      PERFORM fill_fields_of_fieldcatalog
              TABLES t_fieldcatalog
              USING 'T_FINAL' 'VERTNAME' ' ' text-008 20 w_pos.
      PERFORM fill_fields_of_fieldcatalog
              TABLES t_fieldcatalog
              USING 'T_FINAL' 'SKLRATE' ' ' text-005 20 w_pos.
    ENDFORM.                    " populate_fieldcatalog
    *&      Form  FILL_FIELDS_OF_FIELDCATALOG
          text
         -->P_T_FIELDCATALOG  text
         -->P_0870   text
         -->P_0871   text
         -->P_0872   text
         -->P_TEXT_001  text
         -->P_20     text
         -->P_W_POS  text
    FORM fill_fields_of_fieldcatalog TABLES fp_t_fieldcatalog STRUCTURE
                                                         t_fieldcatalog
                                     USING    fp_table
                                              fp_field
                                              fp_key
                                              fp_text
                                              fp_out_len
                                              fp_pos.
      fp_t_fieldcatalog-tabname    = fp_table.
      fp_t_fieldcatalog-fieldname  = fp_field.
      fp_t_fieldcatalog-seltext_l  = fp_text.
      fp_t_fieldcatalog-key        = fp_key.
      fp_t_fieldcatalog-outputlen  = fp_out_len.
      fp_t_fieldcatalog-col_pos    = fp_pos.
      APPEND fp_t_fieldcatalog.
      CLEAR:  fp_t_fieldcatalog.
      fp_pos = fp_pos + 1.
    ENDFORM.                    " FILL_FIELDS_OF_FIELDCATALOG
    10.249.11.136\SAP-StudyMaterial

  • ALV display using dynamic field catalog and dynamic internal table

    hi ,
    please guide me for ALV display using dynamic field catalog and dynamic internal table.
    Thank you.

    Hi Rahul,
    maybe thread dynamic program for alv is helpful for you. More information about the [SAP List Viewer (ALV)|http://help.sap.com/saphelp_nw70/helpdata/EN/5e/88d440e14f8431e10000000a1550b0/frameset.htm]. Also have a look into the example programs SALV_DEMO_TABLE*.
    Regards Rudi

  • Help needed for ALV report

    Hi,
    i need to add coloums for the existing report which picks from G/L account.
    in this report I need to add some more columns from COSP-KSTAR, which shows the cost element details from G/L account.
    I need to restrict that cost element number according to the company code.
    Plz see this and let me know the things.
    1. I need to add FISCAL YEAR(COEP-GJAHR) in selection screen.
    2. I need to add column: Employee Cost (CSKS-KOSTL)
    3. add a column Staff Welfare (COSP-KSTAR) this is to restrict for the cost element 3000200 from G/L account
    4. add a column Recruitment restrict for the cost element(COSP-KSTAR) 3100040 from G/L account
    5. add a column Travels (suppressing some cost elements(COSP-KSTAR) and putting into Travels)
    6. add a column Subcontracts restrict for the cost element (COSP-KSTAR)3100360 from G/L account
    7. add a column Communication suppressing some cost elements and putting into Communication)
    8. add a column Rent restrict for the cost element (COSP-KSTAR)3100055 from G/L account
    9. add a column Back end Cost restrict for the cost element (COSP-KSTAR)3100065 from G/L account
    i can hardcode these cost elements.
    i did according to some of our sdn friends guidence but it is going to dump.
    hear i am sending the code what i changed.
    it is giving the error with the select.
    SELECT BUKRS KOKRS gjahr kstar OBJNR OBJNR_N1 PERIO  BEKNZ WKGBTR WOGBTR  FROM
    COEP  INTO TABLE
    IT_COEP FOR ALL ENTRIES IN IT_AUFK WHERE OBJNR = IT_AUFK-OBJNR and
    perio in S_PERIO.
    plz try to help me out in this issue.
    hear i am sending the complete code what i worte.
    *& Report  ZPROJECT_PROFIT2
    REPORT  ZPROJECT_PROFIT2.
    *********************MAIN DOCUMENTATION BLOCK*************************
    Project Code           :
    Program Name           :Zproject_profit1.
    Purpose of program     :This report will give the gross margin for a project as
    *a whole based on some selected input criteria.
    Author of program      :JAYA KRISHNA .B.
    INPUT/OUTPUT FILE      :nil
    TYPE-POOLS : SLIS."For ALV display.
    TABLES : COEP,  "CO Object: Line Items  (by period).
             AUFK,   "Order master data.
             csks,    "Cost center master data
             cosp.    "CO Objects
    *&  Include           ZSTRUCTURE
    types:    BEGIN OF TY_COEP ,            "structure of table COEP.
              BUKRS LIKE COEP-BUKRS,
              KOKRS LIKE COEP-KOKRS,
              OBJNR LIKE COEP-OBJNR,
               gjahr like coep-gjahr,
              kstar like coep-kstar,
              OBJNR_N1 LIKE COEP-OBJNR_N1,
              PERIO LIKE COEP-PERIO,
              BEKNZ LIKE COEP-BEKNZ,
              WKGBTR LIKE COEP-WKGBTR,
              WOGBTR LIKE COEP-WOGBTR,
              BELNR LIKE COEP-BELNR,
              END OF TY_COEP,
             BEGIN OF TY_AUFK ,             "structure of table AUFK.
             BUKRS LIKE AUFK-BUKRS,
             KOKRS LIKE AUFK-KOKRS,
             OBJNR LIKE AUFK-OBJNR,
             KTEXT LIKE AUFK-KTEXT,
             ANFAUFNR LIKE AUFK-ANFAUFNR,
             AUFEX LIKE AUFK-AUFEX,
             USER2 LIKE AUFK-USER2,
             USER0 LIKE AUFK-USER0,
             USER1 LIKE AUFK-USER1,
             USER3 LIKE AUFK-USER3,
             USER6 LIKE AUFK-USER6,
             USER7 LIKE AUFK-USER7,
             USER8 LIKE AUFK-USER8,
             ABKRS(10) TYPE C,
             USER9 LIKE AUFK-USER9,
             AUFNR LIKE AUFK-AUFNR,
           END OF TY_AUFK,
           begin of ty_csks,
           kokrs like csks-kokrs,
            kostl like csks-kostl,
            bukrs like csks-bukrs,
            objnr like csks-objnr,
                 end of ty_csks.
    DATA :   BEGIN OF IT_COSP occurs 100,
           OBJNR LIKE COSP-OBJNR,
           GJAHR LIKE COSP-GJAHR,
           KSTAR LIKE COSP-KSTAR,
           END OF IT_COSP.
    DATA : IT_COEP TYPE TABLE OF TY_COEP,     " Declaraton of tables COEP and AUFK.
           IT_AUFK TYPE TABLE OF TY_AUFK,
           IT_CSKS TYPE TABLE OF TY_CSKS.
          IT_COSP TYPE TABLE OF TY_COSP.
    DATA : WA_COEP LIKE LINE OF IT_COEP,      " Declaration of work areas for tables COEP and AUFK.
           WA_AUFK LIKE LINE OF IT_AUFK,
           WA_CSKS LIKE LINE OF IT_CSKS.
          WA_COSP LIKE LINE OF IT_COSP.
    DATA : BEGIN OF IT_DISPLAY OCCURS 0,      " Declaration of display table.
            OBJNR_N1 LIKE COEP-OBJNR_N1,
            OBJNR_N12 LIKE COEP-OBJNR_N1,
            KTEXT1 LIKE AUFK-KTEXT,
            WKGBTR LIKE COEP-WKGBTR,
            WOGBTR LIKE COEP-WOGBTR,
            WKGBTR1  LIKE COEP-WTGBTR,
            WOGBTR1 LIKE COEP-WOGBTR,
            ADDK LIKE COEP-WOGBTR,
            ADDO LIKE COEP-WOGBTR,
            ADDK1 LIKE COEP-WOGBTR,
            ADDO1 LIKE COEP-WOGBTR,
            PROFIT1 LIKE COEP-WOGBTR,
            PROFIT2 LIKE COEP-WOGBTR,
            BEKNZ LIKE COEP-BEKNZ,
            BUKRS LIKE AUFK-BUKRS,
            anfaufnr LIKE AUFK-anfaufnr,
            aufex like aufk-aufex,
            OBJNR LIKE AUFK-OBJNR,
            USER2 LIKE AUFK-USER2,
            USER0 LIKE AUFK-USER0,
            USER1 LIKE AUFK-USER1,
            USER3 LIKE AUFK-USER3,
            USER6 LIKE AUFK-USER6,
            USER7 LIKE AUFK-USER7,
            USER8 LIKE AUFK-USER8,
            ABKRS LIKE AUFK-ABKRS,
            USER9 LIKE AUFK-USER9,
            PERIO LIKE COEP-PERIO,
            AUFNR LIKE AUFK-AUFNR,
            STR(5) TYPE C,
            WORK(10) TYPE C,
           END OF IT_DISPLAY,
      : BEGIN OF IT_DISPLAY1 OCCURS 0,      " Declaration of second display table.
         OBJNR_N1 LIKE COEP-OBJNR_N1,
         OBJNR_N12 LIKE COEP-OBJNR_N1,
         KTEXT1 LIKE AUFK-KTEXT,
         WKGBTR LIKE COEP-WKGBTR,
         WOGBTR LIKE COEP-WOGBTR,
         WKGBTR1  LIKE COEP-WTGBTR,
         WOGBTR1 LIKE COEP-WOGBTR,
         ADDK LIKE COEP-WOGBTR,
         ADDO LIKE COEP-WOGBTR,
         ADDK1 LIKE COEP-WOGBTR,
         ADDO1 LIKE COEP-WOGBTR,
         PROFIT1 LIKE COEP-WOGBTR,
         PROFIT2 LIKE COEP-WOGBTR,
         BEKNZ LIKE COEP-BEKNZ,
         BUKRS LIKE AUFK-BUKRS,
         anfaufnr like aufk-anfaufnr,
         aufex like aufk-aufex,
         OBJNR LIKE AUFK-OBJNR,
         USER2 LIKE AUFK-USER2,
         USER0 LIKE AUFK-USER0,
         USER1 LIKE AUFK-USER1,
         USER3 LIKE AUFK-USER3,
         USER6 LIKE AUFK-USER6,
         USER7 LIKE AUFK-USER7,
         USER8 LIKE AUFK-USER8,
         ABKRS LIKE AUFK-ABKRS,
         USER9 LIKE AUFK-USER9,
         PERIO LIKE COEP-PERIO,
         AUFNR LIKE AUFK-AUFNR,
         STR(5) TYPE C,
         WORK(10) TYPE C,
        END OF IT_DISPLAY1.
    data : it_field type slis_fieldcat_alv,        " Declaration of ALV variables
           it_field_t type slis_t_fieldcat_alv,
            xlayout    TYPE slis_layout_alv.
    data : it_event type slis_t_event,
          wa_event like line of it_event.
    DATA : WA_TOP TYPE SLIS_LISTHEADER,
           IT_TOP TYPE SLIS_T_LISTHEADER.
    data:w_lines type i,
          w_occurs type i,
          STR(5) TYPE C,
          WORK(10) TYPE C.
          constants : c_selection type char20 value 'Selection based on'. " Declaration of a constant.
    selection-screen BEGIN OF BLOCK BLK WITH FRAME TITLE TEXT-000.
    SELECT-OPTIONS S_BUKRS FOR AUFK-BUKRS OBLIGATORY.
    SELECT-OPTIONS S_OBJNR FOR AUFK-AUFNR.
    SELECT-OPTIONS S_ANF FOR AUFK-ANFAUFNR.
    SELECT-OPTIONS S_AUFEX FOR AUFK-AUFEX.
    SELECT-OPTIONS S_USER2 FOR AUFK-USER2.
    SELECT-OPTIONS S_USER0 FOR AUFK-USER0.
    SELECT-OPTIONS S_USER1 FOR AUFK-USER1.
    SELECT-OPTIONS S_USER3 FOR AUFK-USER3.
    SELECT-OPTIONS S_USER6 FOR AUFK-USER6.
    SELECT-OPTIONS S_ABKRS FOR AUFK-ABKRS.
    SELECT-options s_gjahr for coep-gjahr obligatory.
    SELECT-OPTIONS S_PERIO FOR COEP-PERIO OBLIGATORY.
    SELECTION-SCREEN END OF BLOCK BLK .
    SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
    PARAMETERS : ONSITE RADIOBUTTON GROUP RADI.
    PARAMETERS : OFFSHORE RADIOBUTTON GROUP RADI.
    PARAMETERS : BOTH RADIOBUTTON GROUP RADI.
    SELECTION-SCREEN END OF BLOCK BLK1 .
    start-of-selection.
    *ZAUFK
                                  " Selection of records from aufk to internal table.
    IF ONSITE EQ 'X' .
    SELECT
    BUKRS
    KOKRS
    OBJNR
    KTEXT
    anfaufnr
    aufex
    USER2
    USER0
    USER1
    USER3
    USER6
    USER7
    USER8
    ABKRS
    USER9
    AUFNR
    FROM AUFK INTO TABLE IT_AUFK WHERE BUKRS IN S_BUKRS AND
    anfaufnr IN s_anf AND
    aufex in s_aufex and
    aufnr IN S_OBJNR AND
    USER2 IN S_USER2 AND
    USER0 IN S_USER0 AND
    USER1 IN S_USER1 AND
    USER3 IN S_USER3 AND
    USER6 IN S_USER6 AND
    ABKRS IN S_ABKRS AND
    USER9 EQ 'X' .
    ENDIF.
    IF OFFSHORE EQ 'X'.
    SELECT
    BUKRS
    KOKRS
    OBJNR
    KTEXT
    anfaufnr
    aufex
    USER2
    USER0
    USER1
    USER3
    USER6
    USER7
    USER8
    ABKRS
    USER9
    AUFNR
    FROM AUFK INTO TABLE IT_AUFK WHERE BUKRS IN S_BUKRS AND
    anfaufnr IN S_anf AND
    aufex in s_aufex and
    aufnR IN S_OBJNR AND
    USER2 IN S_USER2 AND
    USER0 IN S_USER0 AND
    USER1 IN S_USER1 AND
    USER3 IN S_USER3 AND
    USER6 IN S_USER6 AND
    ABKRS IN S_ABKRS AND
    USER9 <> 'X'.
    ENDIF.
    IF BOTH EQ 'X'.
    SELECT
    BUKRS
    KOKRS
    OBJNR
    KTEXT
    anfaufnr
    aufex
    USER2
    USER0
    USER1
    USER3
    USER6
    USER7
    USER8
    ABKRS
    USER9
    AUFNR
    FROM AUFK INTO TABLE IT_AUFK WHERE BUKRS IN S_BUKRS AND
    anfaufnr IN S_anf AND
    aufex in s_aufex and
    aufNR IN S_OBJNR AND
    USER2 IN S_USER2 AND
    USER0 IN S_USER0 AND
    USER1 IN S_USER1 AND
    USER3 IN S_USER3 AND
    USER6 IN S_USER6 AND
    ABKRS IN S_ABKRS.
    ENDIF.
    *&  Include           ZCOEP
                                  " Selection of records from coep to internal table.
    SELECT BUKRS KOKRS gjahr kstar OBJNR OBJNR_N1 PERIO  BEKNZ WKGBTR WOGBTR  FROM
    COEP  INTO TABLE
    IT_COEP FOR ALL ENTRIES IN IT_AUFK WHERE OBJNR = IT_AUFK-OBJNR and
    perio in S_PERIO.
    *&  Include           ZPROFIT_CALC
                                 " Calculations for income and Profit of the employee.
    if not it_coep[] is initial.
        select objnr gjahr wrttp versn kstar from cosp into TABLE It_cosp for
    all entries in it_coep where objnr = IT_COEP-objnr .
    endif.
      LOOP AT IT_coep INTO WA_coep.
        read table IT_aufk into WA_aufk with key OBJNR = wa_coep-OBJNR.
    case it_cosp-kstar.
    when '3000200'.
    it_cosp-kstar = cosp-kstar.
    when '3100040'.
    it_cosp-kstar = cosp-kstar.
    when '3100360'.
    it_cosp-kstar = cosp-kstar.
    when '3100055'.
    it_cosp-kstar = cosp-kstar.
    when '3100065'.
    it_cosp-kstar = cosp-kstar.
    when '3100115'.
    it_cosp-kstar = cosp-kstar.
    when '3100120'.
    it_cosp-kstar = cosp-kstar.
    when '3100130'.
    it_cosp-kstar = cosp-kstar.
    when '3100135'.
    it_cosp-kstar = cosp-kstar.
    when '3100140'.
    it_cosp-kstar = cosp-kstar.
    when '3100145'.
    it_cosp-kstar = cosp-kstar.
    when '3100150'.
    it_cosp-kstar = cosp-kstar.
    when '3100155'.
    it_cosp-kstar = cosp-kstar.
    when '3100160'.
    it_cosp-kstar = cosp-kstar.
    when '3100165'.
    it_cosp-kstar = cosp-kstar.
    when '3100170'.
    it_cosp-kstar = cosp-kstar.
    endcase.
        IT_DISPLAY-BUKRS = WA_AUFK-BUKRS.
        IT_DISPLAY-anfaufnr = WA_AUFK-anfaufnr.
        it_display-aufex  = wa_aufk-aufex.
        IT_DISPLAY-OBJNR = WA_AUFK-OBJNR.
        IT_DISPLAY-USER2 = WA_AUFK-USER2.
        IT_DISPLAY-USER0 = WA_AUFK-USER0.
        IT_DISPLAY-USER1 = WA_AUFK-USER1.
        IT_DISPLAY-USER3 = WA_AUFK-USER3.
        IT_DISPLAY-USER6 = WA_AUFK-USER6.
        IT_DISPLAY-USER7 = WA_AUFK-USER7.
        IT_DISPLAY-USER8 = WA_AUFK-USER8.
        IT_DISPLAY-ABKRS = WA_AUFK-ABKRS.
        IT_DISPLAY-USER9 = WA_AUFK-USER9.
        IT_DISPLAY-KTEXT1 =  WA_AUFK-KTEXT.
        if WA_AUFK-abkrs = 01.
          IT_DISPLAY-STR = 'TM'.
        ENDIF.
        IF WA_AUFK-ABKRS = 02.
          IT_DISPLAY-STR = 'FP'.
        ENDIF.
        IF WA_AUFK-USER9 = 'X'.
          IT_DISPLAY-WORK = 'ONSITE'.
        ENDIF.
        IF WA_AUFK-USER9 <> 'X'.
          IT_DISPLAY-WORK = 'OFFSHORE'.
        ENDIF.
        it_display-ABKRS = it_display-user7.
        IF wa_coep-BEKNZ = 'S'.
          IT_DISPLAY-WKGBTR = WA_COEP-WKGBTR.
          IT_DISPLAY-WOGBTR = WA_COEP-WOGBTR.
          IT_DISPLAY-ADDK = IT_DISPLAY-ADDK + IT_DISPLAY-WKGBTR.
          IT_DISPLAY-ADDO = IT_DISPLAY-ADDO + IT_DISPLAY-WOGBTR.
          IT_DISPLAY-ADDK1 = 0.
          IT_DISPLAY-ADDO1 = 0.
          IT_DISPLAY-PROFIT1 = IT_DISPLAY-ADDK1 +  IT_DISPLAY-ADDK.
          IT_DISPLAY-PROFIT2 = IT_DISPLAY-ADDO1 +  IT_DISPLAY-ADDO.
          APPEND IT_DISPLAY.
        ENDIF.
        IF WA_COEP-BEKNZ = 'H'.
          IT_DISPLAY-WKGBTR1 = WA_COEP-WKGBTR.
          IT_DISPLAY-WOGBTR1 = WA_COEP-WOGBTR.
          IT_DISPLAY-ADDK1 = IT_DISPLAY-ADDK + IT_DISPLAY-WKGBTR1.
          IT_DISPLAY-ADDO1 = IT_DISPLAY-ADDO + IT_DISPLAY-WOGBTR1.
          IT_DISPLAY-ADDK = 0.
          IT_DISPLAY-ADDO = 0.
          IT_DISPLAY-PROFIT1 = IT_DISPLAY-ADDK1 +  IT_DISPLAY-ADDK.
          IT_DISPLAY-PROFIT2 = IT_DISPLAY-ADDO1 +  IT_DISPLAY-ADDO.
          APPEND IT_DISPLAY.
        ENDIF.
        collect it_display into it_display1.
        clear it_display.
      ENDLOOP.
                        "calc
    *&  Include           ZPROFIT_DISPLAY
      LOOP AT IT_DISPLAY1.                                         "it_display.
        read table IT_COEP into WA_COEP with key OBJNR =
        IT_DISPLAY-OBJNR.
        read table IT_AUFK into WA_AUFK with key aufnr = IT_DISPLAY-aufnr.
        if WA_AUFK-abkrs = 01.
          STR = 'TM'.
        ENDIF.
        IF WA_AUFK-ABKRS = 02.
          STR = 'FP'.
        ENDIF.
        IF WA_AUFK-USER9 = 'X'.
          WORK = 'ONSITE'.
        ENDIF.
        IF WA_AUFK-USER9 <> 'X'.
          WORK = 'OFFSHORE'.
        ENDIF.
      endloop.
      clear it_field.
      it_field-col_pos = 1.
      it_field-fieldname = 'AUFNR'.
      it_field-seltext_l = 'project id.'.
      it_field-outputlen = 15.
      append it_field to it_field_t.
      CLEAR it_field.
      clear it_field.
      it_field-col_pos = 2.
      it_field-fieldname = 'KTEXT1'.
      it_field-seltext_l = 'Project Name'.
      it_field-outputlen = 20.
      append it_field to it_field_t.
      CLEAR it_field.
      clear it_field.
      it_field-col_pos = 3.
      it_field-fieldname = 'USER7'.
      it_field-seltext_l = 'Start Date'.
      it_field-do_sum = 'X'.
      it_field-outputlen = 20.
      append it_field to it_field_t.
      CLEAR it_field.
      clear it_field.
      it_field-col_pos = 4.
      it_field-fieldname = 'USER8'.
      it_field-seltext_l = 'End Date'.
      it_field-do_sum = 'X'.
      it_field-outputlen = 20.
      append it_field to it_field_t.
      CLEAR it_field.
      clear it_field.
      it_field-col_pos = 5.
      it_field-fieldname = 'USER2'.
      it_field-seltext_l = 'Location'.
      it_field-do_sum = 'X'.
      it_field-outputlen = 20.
      append it_field to it_field_t.
      CLEAR it_field.
      clear it_field.
      it_field-col_pos = 6.
      it_field-fieldname = 'USER0'.
      it_field-seltext_l = 'Vertical'.
      it_field-do_sum = 'X'.
      it_field-outputlen = 20.
      append it_field to it_field_t.
      CLEAR it_field.
      it_field-col_pos = 7.
      it_field-fieldname = 'USER1'.
      it_field-seltext_l = 'Sub_vertical'.
      it_field-outputlen = 20.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
      it_field-col_pos = 8.
      it_field-fieldname = 'USER3'.
      it_field-seltext_l = 'Technology'.
      it_field-outputlen = 20.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
      it_field-col_pos = 9.
      it_field-fieldname = 'USER6'.
      it_field-seltext_l = 'Department'.
      it_field-outputlen = 20.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
      it_field-col_pos = 10.
      it_field-fieldname = 'WORK'.
      it_field-seltext_l = 'Onsite/Offshore'.
      it_field-outputlen = 20.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
      it_field-col_pos = 11.
      it_field-fieldname = 'STR'.
      it_field-seltext_l = 'T&M/FP'.
      it_field-outputlen = 20.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
    it_field-col_pos = 12.
      it_field-fieldname = 'KOSTL'.
      it_field-seltext_l = 'EMP COST'.
      it_field-outputlen = 10.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
    it_field-col_pos = 13.
      it_field-fieldname = 'KSTAR'.
      it_field-seltext_l = 'STAFF WELFARE'.
      it_field-outputlen = 10.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
    it_field-col_pos = 14.
      it_field-fieldname = 'KSTAR'.
      it_field-seltext_l = 'RECRUITMENT'.
      it_field-outputlen = 10.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
    it_field-col_pos = 15.
      it_field-fieldname = 'KSTAR'.
      it_field-seltext_l = 'TRAVELS'.
      it_field-outputlen = 10.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
    it_field-col_pos = 16.
      it_field-fieldname = 'KSTAR'.
      it_field-seltext_l = 'SUBCONTRACT'.
      it_field-outputlen = 10.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
    it_field-col_pos = 17.
      it_field-fieldname = 'KSTAR'.
      it_field-seltext_l = 'COMMUNICATION'.
      it_field-outputlen = 10.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
    it_field-col_pos = 18.
      it_field-fieldname = 'KSTAR'.
      it_field-seltext_l = 'RENT'.
      it_field-outputlen = 10.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
    it_field-col_pos = 19.
      it_field-fieldname = 'KSTAR'.
      it_field-seltext_l = 'BACKEND COST (PROJECT EXP)'.
      it_field-outputlen = 10.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
    it_field-col_pos = 20.
      it_field-fieldname = 'ADDO'.
      it_field-seltext_l = 'Direct costs'.
      it_field-outputlen = 20.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
      it_field-col_pos = 21.
      it_field-fieldname = 'ADDO1'.
      it_field-seltext_l = 'Income'.
      it_field-outputlen = 20.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
      it_field-col_pos = 22.
      it_field-fieldname = 'PROFIT2'.
      it_field-seltext_l = 'Profit(income-costs)'.
      it_field-outputlen = 20.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
      it_field-col_pos = 23.
      it_field-fieldname = 'ADDK'.
      it_field-seltext_l = 'Direct costs(Grp cur)'.
      it_field-outputlen = 20.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
      it_field-col_pos = 24.
      it_field-fieldname = 'ADDK1'.
      it_field-seltext_l = 'Income(Grp Cur)'.
      it_field-outputlen = 20.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
      it_field-col_pos = 25.
      it_field-fieldname = 'PROFIT1'.
      it_field-seltext_l = 'Profit(income-costs)'.
      it_field-outputlen = 20.
      it_field-do_sum = 'X'.
      append it_field to it_field_t.
      CLEAR it_field.
      xlayout-zebra = 'X'.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
         I_CALLBACK_PROGRAM                = 'ZPROJECT_PROFIT1'
      I_CALLBACK_PF_STATUS_SET          = ' '
         I_CALLBACK_USER_COMMAND           = 'USER_COMMAND'
         I_CALLBACK_TOP_OF_PAGE            = 'TOP_OF_PAGE_PROFIT'
      I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      I_CALLBACK_HTML_END_OF_LIST       = ' '
      I_STRUCTURE_NAME                  =
      I_BACKGROUND_ID                   = ' '
      I_GRID_TITLE                      =
      I_GRID_SETTINGS                   =
         IS_LAYOUT                         = xlayout
         IT_FIELDCAT                       =  it_field_t
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
      IT_SORT                           =
      IT_FILTER                         =
      IS_SEL_HIDE                       =
         I_DEFAULT                         = 'X'
         I_SAVE                            = ' '
      IS_VARIANT                        =
      IT_EVENTS                         =
      IT_EVENT_EXIT                     =
      IS_PRINT                          =
      IS_REPREP_ID                      =
      I_SCREEN_START_COLUMN             = 0
      I_SCREEN_START_LINE               = 0
      I_SCREEN_END_COLUMN               = 0
      I_SCREEN_END_LINE                 = 0
      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_DISPLAY1
    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.
      clear it_field_t.
      "it_display.
    FORM USER_COMMAND using r_ucomm like sy-ucomm rs type slis_selfield.
      include zinteractive_profit."Secondary list for calling KO03.
    ENDFORM.                    "USER_COMMAND.
    Thanks & Regards,
    Lakshmi..

    Hi,
    i did according to ur suggession.
    now it is going dump.
    and it is telling like this.
    2629               i_event_name      = 'SUBTOTAL_TEXT'
    2630               is_subtottxt_info = ls_subtot_info
    2631               ip_subtot_line    = lr_data
    2632             changing
    2633               c_subtottxt       = l_subtottxt.
    2634           ls_lvc_data-value = l_subtottxt.
    2635
    2636           append ls_lvc_data to ct_lvc_data.
    2637         endif.
    2638
    2639 ************************************
    2640 * Column per Fieldcat Entry
    2641 ************************************
    2642         clear ls_lvc_data-style.
    2643         loop at it_fcat_local assigning <ls_fcat>
    2644                 where tech ne 'X' and no_out ne 'X'.
    2645           if l_invisible eq 'X'.
    2646             clear l_invisible.
    2647             if <ls_fcat>-do_sum is initial.
    2648               continue.
    2649             else.
    2650               clear ls_lvc_data-col_pos.
    2651             endif.
    2652           endif.
    2653
    2654           add 1 to ls_lvc_data-col_pos.
    2655
    2656           assign component <ls_fcat>-fieldname
    2657                            of structure <ls_data> to <l_field_val
    2658           if sy-subrc ne 0.
    >>>>>             message x000(0k).
    2660           endif.
    2661
    2662 *... work on average
    2663           if <ls_fcat>-do_sum eq 'C'.
    2664             clear l_entries.
    2665
    2666             assign space to <l_unit>.
    2667             if not <ls_fcat>-cfieldname is initial.
    2668               assign component <ls_fcat>-cfieldname
    2669                      of structure <ls_data> to <l_unit>.
    2670             endif.
    2671             if not <ls_fcat>-qfieldname is initial.
    2672               assign component <ls_fcat>-qfieldname
    2673                      of structure <ls_data> to <l_unit>.
    2674             endif.
    2675
    2676             l_from = ls_grpl-index_from.
    2677             l_to   = ls_grpl-index_to.
    2678             if ls_grpl-index_from is initial and
    plz any of u help me to come out with solution.
    Thanks & Regards,
    Lakshmi..

  • In ALV display model ,how to accept the ENTER key event?

    Dear All,
    I have used ALV by  GRID DISPLAY model ,not class model.
        CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program       = sy-repid
          i_callback_pf_status_set = 'SET_PF_STATUS'
          i_callback_user_command  = 'USER_COMMAND'
          i_structure_name         = 'T_ITAB'
          is_layout                = gs_layout
          it_fieldcat              = t_fieldcat[]
          i_default                = 'X'
          i_save                   = 'A'
        TABLES
          t_outtab                 = t_itab
        EXCEPTIONS
          program_error            = 1
          OTHERS                   = 2.
    For example :
    IN ALV DISPLAY, there are two fields, one is MATNR, the other is MAKTX.
    When user input the material value in MATNR field and press ENTER, then ALV can run my code to select the MAKTX into MAKTX field and display it synchronization.
    Now I have realized update edit in ALV,but I found only I double click ALV row, then the MAKTX can update.
    Please give me help,
    Thanks
    Sun

    This is the document written by me on Interactive ALV.. hope this maybe helpful for u..
    When an Interactive Report is needed in Classical Display, we go for AT LINE-SELECTION. But when the same is needed in ALV Display, this method won't work. Instead, we need to use other way which is explained below:
    We use REUSE_ALV_GRID_DISPLAY for ALV Display. Now, normally we call that FM in the following way:
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                i_callback_program      = 'PROGRAM_NAME'
                it_fieldcat             = tb_fieldcat
           TABLES
                t_outtab                = tb_output.
    When it is needed to get an Interactive ALV, call the same FM in the following manner:
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                i_callback_program      = 'ZTEST75599_1'
                it_fieldcat             = tb_fieldcat
                i_callback_user_command = 'USER_COMMAND'
           TABLES
                t_outtab                = tb_output.
    Now, in the report, create a subroutine with the name USER_COMMAND as follows:
    FORM user_command  USING p_ucomm    LIKE sy-ucomm
                             p_selfield TYPE slis_selfield.
      CASE p_ucomm.
        WHEN '&IC1'.   " &IC1 - SAP standard code for double-clicking
    Based on the requirement, write the logic                          *
      ENDCASE.
    ENDFORM.
    No need to call the subroutine as PERFORM user_command. This will be takane care by REUSE_ALV_GRID_DISPLAY. We need to just write the subroutine in the report. That suffices.
    Some more useful points for Interactive ALV:
    1. If Hotspot is needed, then that should be done by declaring hotspot (one field in slis_t_fieldcat_alv) as 'X' in tb_fieldcat which is of type slis_t_fieldcat_alv. When hotspot is active, single click will be enough or else you should double click on the output data.
    2. In Classical Display, when it is needed to read the record on which we double clicked, we do that in following way:
       AT LINE-SELECTION.
           GET CURSOR LINE wf_line. " wf_line gives the line number on which it has been clicked
             READ LINE wf_line OF CURRENT PAGE.
      But this won't work for ALV. Instead, the following logic can be used:
    FORM user_command  USING p_ucomm    LIKE sy-ucomm
                             p_selfield TYPE slis_selfield.
      CASE p_ucomm.
        WHEN '&IC1'.   " &IC1 - SAP standard code for double-clicking
          READ TABLE tb_output INTO wa_output INDEX p_selfield-tabindex.
          IF sy-subrc EQ 0.
    Based on the requirement, write the logic                          *
          ENDIF.
      ENDCASE.
    ENDFORM.

  • Column headings are missing in the output for ALV?

    Hi all,
    i have coded a small report in ALV mode. i am getting the data but the column headings are missing.
    iam not getting the column headings in the output. it is coming as blank. Could you all please help me out in this?
    below is the code of my program:
                     Includes                                            *
    *---Standard header and footer routines
    INCLUDE zsrepthd.
    *--- ALV Routines
    INCLUDE zvsdi_alv_routines_ver3.
    *--- Authorization Check
    INCLUDE z_selection_auth_check.
                     Types Declarations                                  *
    tables : ekpo.
                     Types Declarations                                  *
    TYPES: BEGIN OF ty_ekpo,
            EBELN(18) TYPE C,
            EBELP(20) TYPE C,
            MATNR(18) TYPE C,
            WERKS(11) TYPE C,
          END OF ty_ekpo.
    *-Output field name
    TYPES: BEGIN OF ty_output,
            EBELN(18) TYPE C,
            EBELP(20) TYPE C,
            MATNR(18) TYPE C,
            WERKS(11) TYPE C,
          END OF ty_output.
    *-Output field name
    TYPES: BEGIN OF ty_fields,
            fname(60) TYPE c,
           END OF ty_fields.
                     Internal Table Declarations                         *
    DATA:it_ekpo TYPE STANDARD TABLE OF ty_ekpo,
    *--- Alv parameters
        it_out_alvp TYPE typ_alv_form_params, "for alv parameters
    *-Field catalog  for ALV display
        it_fcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
    *-Field names for Excel column headings
    it_ekpo_fields TYPE STANDARD TABLE OF ty_fields WITH HEADER LINE.
    **--To store output for Principial Pegging data
    DATA: BEGIN OF it_output occurs 0,
            EBELN(18) TYPE C,
            EBELP(20) TYPE C,
            MATNR(18) TYPE C,
            WERKS(11) TYPE C,
          END OF it_output.
    **--To store output for 2nd
    DATA: BEGIN OF it_output1 occurs 0,
            text(2000),
           END OF it_output1.
                     Data Declarations                                   *
    data: v_ebeln TYPE ekpo-ebeln,
          v_ebelp TYPE ekpo-ebelp,
          v_matnr TYPE ekpo-matnr,
          v_werks TYPE ekpo-werks.
                     Constants Declarations                              *
    CONSTANTS:
         c_0    TYPE i     VALUE  0,
         c_x    TYPE char1 VALUE  'X',
         c_i    TYPE char1 VALUE  'I',
         c_eq   TYPE char2 VALUE  'EQ',
         c_ekpo  TYPE char4 VALUE 'EKPO',
         c_hyfn  TYPE char1 VALUE '-'.
                     Work Area Declarations                              *
    DATA: x_output_ekpo type ty_output,
          x_ekpo type ty_ekpo.
                     Selection Screen                                    *
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-f01.
    SELECT-OPTIONS:
          s_ebeln FOR v_ebeln OBLIGATORY,
          s_ebelp FOR v_ebelp,
          s_matnr FOR v_matnr,
          s_werks FOR v_werks.
    SELECTION-SCREEN END OF BLOCK b1.
                     At Selection Screen                                 *
    AT SELECTION-SCREEN.
                     Start-of-Selection                                  *
    START-OF-SELECTION.
    *--- Check Authorizations for Selection-screen
      PERFORM  z_selection_auth_check.
    *--- Fetch Purchasing Document Item data
      PERFORM  fetch_status_pp.
                     End-of-Selection                                    *
    END-OF-SELECTION.
    **-- Download data to final internal table.
      PERFORM data_output.
      IF NOT it_output[] IS INITIAL.
    *--- Fill the structure for calling the ALV form
        PERFORM initialize_alv_params.
    **-- Display ALV Report
        PERFORM setup_and_display_alv_ver2
           USING
         it_out_alvp        "Parameter structure
         it_output[]        "Internal Data table(header table)
         it_output[].       "Dummy table for Hierarchical ALV!!(item table)
        ENDIF.
      IF it_output[] IS INITIAL.
        MESSAGE i999(zi) WITH 'No data found for selection'(i02).
      ENDIF.
    *&      Form  FETCH_STATUS_PP
    Get data from ekpo table
    FORM FETCH_STATUS_PP .
    *-Fetch PP Data from ekpo table
      REFRESH it_ekpo.
      SELECT EBELN
             EBELP
             MATNR
             WERKS
             FROM ekpo
             INTO TABLE it_ekpo
             WHERE ebeln IN s_ebeln
               AND ebelp IN s_ebelp.
      IF sy-subrc = c_0.
        SORT it_ekpo BY ebeln ebelp.
      ENDIF.
    ENDFORM.                    " FETCH_STATUS_PP
    *&      Form  f_top_of_page
    *This is to write the top of page
    FORM top_of_page.
      DATA:  lt_list TYPE slis_t_listheader,
             lx_list TYPE slis_listheader.
    *--- Title name
      CLEAR lx_list.
      lx_list-typ  = 'S'.
      lx_list-key  = 'Title name'(t13).
      lx_list-info = sy-title.
      APPEND lx_list TO lt_list.
      IF NOT lt_list IS INITIAL.
        CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
          EXPORTING
            it_list_commentary = lt_list.
      ENDIF.
    ENDFORM.                    "top_of_page
    *&      Form  init_page_head
    Description : This subroutine initializes the fields in table BHDGD  *
                  for printing the report heading.                       *
    FORM init_page_head.
      bhdgd-line1  = 'SLA Status Report'(h04).
      bhdgd-line2  = sy-title.
      bhdgd-lines  = sy-linsz.
      bhdgd-fcpyrt = sy-uline.
      bhdgd-inifl  = '0'.
    ENDFORM.                    "init_page_head
    *&      Form  initialize_alv_params
    Description : Form to initialize ALV Params
    FORM initialize_alv_params.
      CONSTANTS: lc_alv_grid  TYPE char1 VALUE 'G',  "Grid
                 lc_u         TYPE char1 VALUE 'U'.
      MOVE 'IT_OUTPUT' TO   it_out_alvp-tablname.   "final table
      MOVE sy-repid    TO   it_out_alvp-repid.
      MOVE lc_alv_grid TO   it_out_alvp-alvtype.
      MOVE c_x         TO   it_out_alvp-bringdefaultvar.
      MOVE lc_u        TO   it_out_alvp-variantsavetype.
    ENDFORM.                    " initialize_alv_params
          FORM it_out_init_events                                       *
    -->this is form is to modify the events
    FORM it_out_init_events
          CHANGING
           alevnts TYPE slis_t_event.
      FIELD-SYMBOLS <alevnt> TYPE slis_alv_event.
      LOOP AT alevnts ASSIGNING <alevnt>.
        CASE <alevnt>-name.
          WHEN  slis_ev_top_of_page.
            MOVE 'TOP_OF_PAGE'  TO <alevnt>-form.
        ENDCASE.
      ENDLOOP.
    ENDFORM.                    "it_out_init_events
    *&      Form  DATA_OUTPUT
    Download data to final internal table
    FORM DATA_OUTPUT .
      loop at it_ekpo into x_ekpo.
        x_output_ekpo-ebeln = x_ekpo-ebeln.
        x_output_ekpo-ebelp = x_ekpo-ebelp.
        x_output_ekpo-matnr = x_ekpo-matnr.
        x_output_ekpo-werks = x_ekpo-werks.
        append x_output_ekpo to it_output.
      endloop.
    ENDFORM.                    " DATA_OUTPUT
          FORM it_out_alv_fieldcat_before                               *
    -->  PT_FCAT                                                       *
    -->  ALVP                                                          *
    FORM it_out_alv_fieldcat_before  CHANGING
        pt_fcat TYPE slis_t_fieldcat_alv
        alvp TYPE typ_alv_form_params.
      DATA: lx_fcat TYPE slis_fieldcat_alv.
      CLEAR lx_fcat.
      lx_fcat-tabname        = 'IT_OUTPUT'.
      lx_fcat-fieldname      = 'EBELN'.
      lx_fcat-col_pos        = '1'.
      lx_fcat-ddictxt        = 'M'.
      lx_fcat-seltext_l      = 'Purchasing Doc No'(018).
      lx_fcat-seltext_m      = 'Purchasing Doc No'(018).
      lx_fcat-seltext_s      = 'Purchasing Doc No'(018).
      lx_fcat-reptext_ddic   = 'Purchasing Doc No'(018).
      APPEND lx_fcat TO pt_fcat.
      CLEAR lx_fcat.
      lx_fcat-tabname        = 'IT_OUTPUT'.
      lx_fcat-fieldname      = 'EBELP'.
      lx_fcat-col_pos        = '1'.
      lx_fcat-ddictxt        = 'M'.
      lx_fcat-seltext_l      = 'Item No Purchasing Doc'(020).
      lx_fcat-seltext_m      = 'Item No Purchasing Doc'(020).
      lx_fcat-seltext_s      = 'Item No Purchasing Doc'(020).
      lx_fcat-reptext_ddic   = 'Item No Purchasing Doc'(020).
      APPEND lx_fcat TO pt_fcat.
      CLEAR lx_fcat.
      lx_fcat-tabname        = 'IT_OUTPUT'.
      lx_fcat-fieldname      = 'MATNR'.
      lx_fcat-col_pos        = '1'.
      lx_fcat-ddictxt        = 'M'.
      lx_fcat-seltext_l      = 'Material'(010).
      lx_fcat-seltext_m      = 'Material'(010).
      lx_fcat-seltext_s      = 'Material'(010).
      lx_fcat-reptext_ddic   = 'Material'(010).
      APPEND lx_fcat TO pt_fcat.
      CLEAR lx_fcat.
      lx_fcat-tabname        = 'IT_OUTPUT'.
      lx_fcat-fieldname      = 'WERKS'.
      lx_fcat-col_pos        = '1'.
      lx_fcat-ddictxt        = 'M'.
      lx_fcat-seltext_l      = 'Supply plant'(013).
      lx_fcat-seltext_m      = 'Supply plant'(013).
      lx_fcat-seltext_s      = 'Supply plant'(013).
      lx_fcat-reptext_ddic   = 'Supply plant'(013).
      APPEND lx_fcat TO pt_fcat.
    ENDFORM.                    " it_out_alv_fieldcat_before.
    Regards,
    Shalini
    Edited by: shalini reddy on Oct 7, 2008 5:08 PM

    Hi,
    The heading are in the table pt_fcat - you don't seem to be passing that in form....
    PERFORM setup_and_display_alv_ver2
    USING
    it_out_alvp "Parameter structure
    it_output[] "Internal Data table(header table)
    it_output[]. "Dummy table for Hierarchical ALV!!(item table)
    which I guessing in in one of the includes?
    Saying that the extract pof code does not show where you are calling form it_out_alv_fieldcat_before ...which populates the headings...
    Regards
    Stu

  • ALV Display - sub totals

    hi gurus,
    In my report program i have a monthly report displaying the data for that month.
    1. Now in my ALV grid i want The SUB-TOTALS for the work center wise data for a field of the alv.  there are many workcenters data in my report.  So after the end of each work center , i want the subtotal of a calculated TAT field.
    2. At the end of the report, I want the average TAT(field calculated by my report program) for that month.
    So how can i make the coding for the above.
    Iam a fresher to this field, so give me in detail.
    regards,
    chaitanya

    Hi
    i am giving a sample example for subtotals of alv.
    REPORT z_alv_subtotal.
    *& Table declaration
    TABLES: EKKO.
    *& Type pool declaration
    TYPE-POOLS: SLIS. " Type pool for ALV
    *& Selection screen
    SELECT-OPTIONS: S_EBELN FOR EKKO-EBELN.
    *& Type declaration
    Type declaration for internal table to store EKPO data
    TYPES: BEGIN OF X_DATA,
    EBELN TYPE CHAR30, " Document no.
    EBELP TYPE EBELP, " Item no
    MATNR TYPE MATNR, " Material no
    MATNR1 TYPE MATNR, " Material no
    WERKS TYPE WERKS_D, " Plant
    WERKS1 TYPE WERKS_D, " Plant
    NTGEW TYPE ENTGE, " Net weight
    GEWE TYPE EGEWE, " Unit of weight
    END OF X_DATA.
    *& Internal table declaration
    DATA:
    Internal table to store EKPO data
    I_EKPO TYPE STANDARD TABLE OF X_DATA INITIAL SIZE 0,
    Internal table for storing field catalog information
    I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
    Internal table for Top of Page info. in ALV Display
    I_ALV_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,
    Internal table for ALV Display events
    I_EVENTS TYPE SLIS_T_EVENT,
    Internal table for storing ALV sort information
    I_SORT TYPE SLIS_T_SORTINFO_ALV,
    I_EVENT TYPE SLIS_T_EVENT.
    *& Work area declaration
    DATA:
    WA_EKKO TYPE X_DATA,
    WA_LAYOUT TYPE SLIS_LAYOUT_ALV,
    WA_EVENTS TYPE SLIS_ALV_EVENT,
    WA_SORT TYPE SLIS_SORTINFO_ALV.
    *& Constant declaration
    CONSTANTS:
    C_HEADER TYPE CHAR1
    VALUE 'H', "Header in ALV
    C_ITEM TYPE CHAR1
    VALUE 'S'.
    *& Start-of-selection event
    START-OF-SELECTION.
    Select data from ekpo
    SELECT EBELN " Doc no
    EBELP " Item
    MATNR " Material
    MATNR " Material
    WERKS " Plant
    WERKS " Plant
    NTGEW " Quantity
    GEWEI " Unit
    FROM EKPO
    INTO TABLE I_EKPO
    WHERE EBELN IN S_EBELN
    AND NTGEW NE '0.00'.
    IF SY-SUBRC = 0.
    SORT I_EKPO BY EBELN EBELP MATNR .
    ENDIF.
    To build the Page header
    PERFORM SUB_BUILD_HEADER.
    To prepare field catalog
    PERFORM SUB_FIELD_CATALOG.
    Perform to populate the layout structure
    PERFORM SUB_POPULATE_LAYOUT.
    Perform to populate the sort table.
    PERFORM SUB_POPULATE_SORT.
    Perform to populate ALV event
    PERFORM SUB_GET_EVENT.
    END-OF-SELECTION.
    Perform to display ALV report
    PERFORM SUB_ALV_REPORT_DISPLAY.
    *& Form sub_build_header
    To build the header
    No Parameter
    FORM SUB_BUILD_HEADER .
    Local data declaration
    DATA: L_SYSTEM TYPE CHAR10 , "System id
    L_R_LINE TYPE SLIS_LISTHEADER, "Hold list header
    L_DATE TYPE CHAR10, "Date
    L_TIME TYPE CHAR10, "Time
    L_SUCCESS_RECORDS TYPE I, "No of success records
    L_TITLE(300) TYPE C. " Title
    Title Display
    L_R_LINE-TYP = C_HEADER. " header
    L_TITLE = 'Test report'(001).
    L_R_LINE-INFO = L_TITLE.
    APPEND L_R_LINE TO I_ALV_TOP_OF_PAGE.
    CLEAR L_R_LINE.
    Run date Display
    CLEAR L_DATE.
    L_R_LINE-TYP = C_ITEM. " Item
    WRITE: SY-DATUM TO L_DATE MM/DD/YYYY.
    L_R_LINE-KEY = 'Run Date :'(002).
    L_R_LINE-INFO = L_DATE.
    APPEND L_R_LINE TO I_ALV_TOP_OF_PAGE.
    CLEAR: L_R_LINE,
    L_DATE.ENDFORM. " sub_build_header
    *& Form sub_field_catalog
    Build Field Catalog
    No Parameter
    FORM SUB_FIELD_CATALOG .
    Build Field Catalog
    PERFORM SUB_FILL_ALV_FIELD_CATALOG USING:
    '01' '01' 'EBELN' 'I_EKPO' 'L' 'Doc No'(003) ' ' ' ' ' ' ' ',
    '01' '02' 'EBELP' 'I_EKPO' 'L' 'Item No'(004) 'X' 'X' ' ' ' ',
    '01' '03' 'MATNR' 'I_EKPO' 'L' 'Material No'(005) 'X' 'X' ' ' ' ',
    '01' '03' 'MATNR1' 'I_EKPO' 'L' 'Material No'(005) ' ' ' ' ' ' ' ',
    '01' '04' 'WERKS' 'I_EKPO' 'L' 'Plant'(006) 'X' 'X' ' ' ' ',
    '01' '04' 'WERKS1' 'I_EKPO' 'L' 'Plant'(006) ' ' ' ' ' ' ' ',
    '01' '05' 'NTGEW' 'I_EKPO' 'R' 'Net Weight'(007) ' ' ' ' 'GEWE' 'I_EKPO'
    ENDFORM. " sub_field_catalog
    *& Form sub_fill_alv_field_catalog
    *& For building Field Catalog
    *& p_rowpos Row position
    *& p_colpos Col position
    *& p_fldnam Fldname
    *& p_tabnam Tabname
    *& p_justif Justification
    *& p_seltext Seltext
    *& p_out no out
    *& p_tech Technical field
    *& p_qfield Quantity field
    *& p_qtab Quantity table
    FORM SUB_FILL_ALV_FIELD_CATALOG USING P_ROWPOS TYPE SYCUROW
    P_COLPOS TYPE SYCUCOL
    P_FLDNAM TYPE FIELDNAME
    P_TABNAM TYPE TABNAME
    P_JUSTIF TYPE CHAR1
    P_SELTEXT TYPE DD03P-SCRTEXT_L
    P_OUT TYPE CHAR1
    P_TECH TYPE CHAR1
    P_QFIELD TYPE SLIS_FIELDNAME
    P_QTAB TYPE SLIS_TABNAME.
    Local declaration for field catalog
    DATA: WA_LFL_FCAT TYPE SLIS_FIELDCAT_ALV.
    WA_LFL_FCAT-ROW_POS = P_ROWPOS. "Row
    WA_LFL_FCAT-COL_POS = P_COLPOS. "Column
    WA_LFL_FCAT-FIELDNAME = P_FLDNAM. "Field Name
    WA_LFL_FCAT-TABNAME = P_TABNAM. "Internal Table Name
    WA_LFL_FCAT-JUST = P_JUSTIF. "Screen Justified
    WA_LFL_FCAT-SELTEXT_L = P_SELTEXT. "Field Text
    WA_LFL_FCAT-NO_OUT = P_OUT. "No output
    WA_LFL_FCAT-TECH = P_TECH. "Technical field
    WA_LFL_FCAT-QFIELDNAME = P_QFIELD. "Quantity unit
    WA_LFL_FCAT-QTABNAME = P_QTAB . "Quantity table
    IF P_FLDNAM = 'NTGEW'.
    WA_LFL_FCAT-DO_SUM = 'X'.
    ENDIF.
    APPEND WA_LFL_FCAT TO I_FIELDCAT.
    CLEAR WA_LFL_FCAT.
    ENDFORM. " sub_fill_alv_field_catalog
    *& Form sub_populate_layout
    Populate ALV layout
    No Parameter
    FORM SUB_POPULATE_LAYOUT . CLEAR WA_LAYOUT.
    WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'." Optimization of Col width
    ENDFORM. " sub_populate_layout
    *& Form sub_populate_sort
    Populate ALV sort table
    No Parameter
    FORM SUB_POPULATE_SORT .
    Sort on material
    WA_SORT-SPOS = '01' .
    WA_SORT-FIELDNAME = 'MATNR'.
    WA_SORT-TABNAME = 'I_EKPO'.
    WA_SORT-UP = 'X'.
    WA_SORT-SUBTOT = 'X'.
    APPEND WA_SORT TO I_SORT .
    CLEAR WA_SORT.
    Sort on plant
    WA_SORT-SPOS = '02'.
    WA_SORT-FIELDNAME = 'WERKS'.
    WA_SORT-TABNAME = 'I_EKPO'.
    WA_SORT-UP = 'X'.
    WA_SORT-SUBTOT = 'X'.
    APPEND WA_SORT TO I_SORT .
    CLEAR WA_SORT.
    ENDFORM. " sub_populate_sort
    *& Form sub_get_event
    Get ALV grid event and pass the form name to subtotal_text
    event
    No Parameter
    FORM SUB_GET_EVENT .
    CONSTANTS : C_FORMNAME_SUBTOTAL_TEXT TYPE SLIS_FORMNAME VALUE
    'SUBTOTAL_TEXT'.
    DATA: L_S_EVENT TYPE SLIS_ALV_EVENT.
    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
    I_LIST_TYPE = 4
    IMPORTING
    ET_EVENTS = I_EVENT
    EXCEPTIONS
    LIST_TYPE_WRONG = 0
    OTHERS = 0.
    Subtotal
    READ TABLE I_EVENT INTO L_S_EVENT
    WITH KEY NAME = SLIS_EV_SUBTOTAL_TEXT.
    IF SY-SUBRC = 0.
    MOVE C_FORMNAME_SUBTOTAL_TEXT TO L_S_EVENT-FORM.
    MODIFY I_EVENT FROM L_S_EVENT INDEX SY-TABIX.
    ENDIF.
    ENDFORM. " sub_get_event
    *& Form sub_alv_report_display
    For ALV Report Display
    No Parameter
    FORM SUB_ALV_REPORT_DISPLAY .
    DATA: L_REPID TYPE SYREPID .
    L_REPID = SY-REPID .
    This function module for displaying the ALV report
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = L_REPID
    I_CALLBACK_TOP_OF_PAGE = 'SUB_ALV_TOP_OF_PAGE'
    IS_LAYOUT = WA_LAYOUT
    IT_FIELDCAT = I_FIELDCAT
    IT_SORT = I_SORT
    IT_EVENTS = I_EVENT
    I_DEFAULT = 'X'
    I_SAVE = 'A'
    TABLES
    T_OUTTAB = I_EKPO
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2.
    IF SY-SUBRC <> 0.
    MESSAGE i000 WITH 'Error in ALV report display'(055).
    ENDIF.ENDFORM. " sub_alv_report_display
    FORM sub_alv_top_of_page
    Call ALV top of page
    No parameter
    FORM SUB_ALV_TOP_OF_PAGE. "#EC CALLED
    To write header for the ALV
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
    IT_LIST_COMMENTARY = I_ALV_TOP_OF_PAGE.
    ENDFORM. "alv_top_of_page
    *& Form subtotal_text
    Build subtotal text
    P_total Total
    p_subtot_text Subtotal text info
    FORM SUBTOTAL_TEXT CHANGING
    P_TOTAL TYPE ANY
    P_SUBTOT_TEXT TYPE SLIS_SUBTOT_TEXT.
    Material level sub total
    IF P_SUBTOT_TEXT-CRITERIA = 'MATNR'.
    P_SUBTOT_TEXT-DISPLAY_TEXT_FOR_SUBTOTAL
    = 'Material level total'(009).
    ENDIF.
    Plant level sub total
    IF P_SUBTOT_TEXT-CRITERIA = 'WERKS'.
    P_SUBTOT_TEXT-DISPLAY_TEXT_FOR_SUBTOTAL = 'Plant level total'(010).
    ENDIF.

  • ALV display in report

    Hi All,
    I m trying to display ALV in report using classes but i m not able to do it. I have used following classes for alv display along with its method.
    1. cl_gui_custom_container
    2.  cl_gui_alv_grid and its method set_table_for_first_display
    I have tried to display in module pool using classes and i have succeeded but now i m trying wid report using the same classes but i m not able to display ALV
    Please provide me solution and if there exists another classes to display ALV along wid its methods.
    Regards,
    Parag

    Hi,
    in the report program also you have to call a screen and in the PBo write the code for display of ALV
    Please check the below program:
    REPORT  z271837_alv_grid_container              .
    Important Classes : CL_GUI_ALV_GRID and CL_GUI_CUSTOM_CONTAINER.
    *Steps To Use ALV Grid in a Program :
    *1. Declare reference variables for,
          Container (class CL_GUI_CUSTOM_CONTAINER) and
          Grid (class CL_GUI_ALV_GRID)
    *2. Create Standard Screen and a container on that screen
    *3. Call the screen which has been created
    *4. Instantiate the container control and the ALV Grid Control in PBO of the screen
    Tables
    TABLES : mara.
    TYPE-POOLS : slis.
    Data declarations
    DATA : fg_error TYPE flag.
    TYPES : BEGIN OF x_mara,
             matnr TYPE mara-matnr,
             erdda TYPE mara-ersda,
             ernam TYPE mara-ernam,
             mtart TYPE mara-mtart,
             matkl TYPE mara-matkl,
            END OF x_mara.
    Declare reference variables:
    DATA : cl_grid      TYPE REF TO cl_gui_alv_grid,
           cl_container TYPE REF TO cl_gui_custom_container.
    DATA : it_mara TYPE TABLE OF x_mara,
           wa_fieldcat TYPE lvc_s_fcat,  "  occurs 1.
           it_fieldcat TYPE TABLE OF lvc_s_fcat.
    Selection Screen.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS : s_matnr FOR mara-matnr.
    SELECTION-SCREEN END OF BLOCK b1.
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
    PARAMETER : rb_list TYPE char1 RADIOBUTTON GROUP r1,
                rb_grid TYPE char1 RADIOBUTTON GROUP r1 DEFAULT 'X'.
    SELECTION-SCREEN END OF BLOCK b2.
    START-OF-SELECTION.
      CLEAR fg_error.
      REFRESH it_mara.
    *Get the data which is to be displayed into one internal table
      SELECT matnr
             ersda
             ernam
             mtart
             matkl
       FROM mara
       INTO TABLE it_mara
       WHERE matnr IN s_matnr.
      IF sy-subrc NE 0.
        MESSAGE s000(zi) WITH text-s01.
        fg_error = 'X'.
        EXIT.
      ENDIF.
    END-OF-SELECTION.
      CHECK fg_error IS INITIAL.
    build the field catalog
      wa_fieldcat-fieldname = 'MATNR'.
      wa_fieldcat-row_pos = 1.
      wa_fieldcat-col_pos = 1.
      wa_fieldcat-SCRTEXT_M = 'Material'.
      wa_fieldcat-outputlen = 18.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname = 'ERSDA'.
      wa_fieldcat-row_pos = 1.
      wa_fieldcat-col_pos = 2.
      wa_fieldcat-SCRTEXT_M = 'ERSDA'.
      wa_fieldcat-outputlen = 18.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname = 'ERNAM'.
      wa_fieldcat-row_pos = 1.
      wa_fieldcat-col_pos = 3.
      wa_fieldcat-SCRTEXT_M = 'Creator'.
      wa_fieldcat-outputlen = 18.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname = 'MTART'.
      wa_fieldcat-row_pos = 1.
      wa_fieldcat-col_pos = 4.
      wa_fieldcat-SCRTEXT_M = 'Material Type'.
      wa_fieldcat-outputlen = 18.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname = 'MATKL'.
      wa_fieldcat-row_pos = 1.
      wa_fieldcat-col_pos = 5.
      wa_fieldcat-SCRTEXT_M = 'Material Desc'.
      wa_fieldcat-outputlen = 50.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR wa_fieldcat.
    Call the screen with container to display ALV
      CALL SCREEN 100.
    PBO and PAI modules code along with ALV container and display methods
      INCLUDE z271837_alv_grid_container_o01.
    ***INCLUDE Z271837_ALV_GRID_CONTAINER_O01 .
    *&      Module  STATUS_0100  OUTPUT
          text
    MODULE status_0100 OUTPUT.
      SET PF-STATUS '0100'.
    SET TITLEBAR 'xxx'.
    Instantiate the container control and the ALV Grid
    Control in PBO of the screen
      IF cl_container IS INITIAL.
    Instantiate the container control
        CREATE OBJECT cl_container
          EXPORTING
       PARENT                      =
            container_name              = 'C1_CONTAINER'
       STYLE                       =
       LIFETIME                    = lifetime_default
       REPID                       =
       DYNNR                       =
       NO_AUTODEF_PROGID_DYNNR     =
          EXCEPTIONS
            cntl_error                  = 1
            cntl_system_error           = 2
            create_error                = 3
            lifetime_error              = 4
            lifetime_dynpro_dynpro_link = 5
            OTHERS                      = 6
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
    Instantiate the ALV grid
        CREATE OBJECT cl_grid
          EXPORTING
       I_SHELLSTYLE      = 0
       I_LIFETIME        =
            i_parent          = cl_container  " Container object created above
       I_APPL_EVENTS     = space
       I_PARENTDBG       =
       I_APPLOGPARENT    =
       I_GRAPHICSPARENT  =
       I_NAME            =
          EXCEPTIONS
            error_cntl_create = 1
            error_cntl_init   = 2
            error_cntl_link   = 3
            error_dp_create   = 4
            OTHERS            = 5
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
    *For displaying the data, call the method "set_table_for_first_display"
    *of object reference of CL_GUI_ALV_GRID
        CALL METHOD cl_grid->set_table_for_first_display
    EXPORTING
       I_BUFFER_ACTIVE               =
       I_BYPASSING_BUFFER            =
       I_CONSISTENCY_CHECK           =
       I_STRUCTURE_NAME              =
       IS_VARIANT                    =
       I_SAVE                        =
       I_DEFAULT                     = 'X'
       IS_LAYOUT                     =
       IS_PRINT                      =
       IT_SPECIAL_GROUPS             =
       IT_TOOLBAR_EXCLUDING          =
       IT_HYPERLINK                  =
       IT_ALV_GRAPHICS               =
       IT_EXCEPT_QINFO               =
          CHANGING
            it_outtab                     = it_mara
            it_fieldcatalog               = it_fieldcat
       IT_SORT                       =
       IT_FILTER                     =
    EXCEPTIONS
       INVALID_PARAMETER_COMBINATION = 1
       PROGRAM_ERROR                 = 2
       TOO_MANY_LINES                = 3
       others                        = 4
        IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
      ENDIF.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
          text
    MODULE user_command_0100 INPUT.
    *Refresh grid display
      CALL METHOD cl_grid->refresh_table_display.
      CASE sy-ucomm.
        WHEN 'BACK'.
    Comes back to the previous screen
          SET SCREEN 0.
        WHEN 'EXIT'
        OR 'CANCEL'.
    Exit from the application/program
          LEAVE PROGRAM.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    Reward if useful
    Regards
    Shiva

  • Footer for ALV

    Hi,
    how we can create and display Footer for ALV Grid ,
    pls give me with some example

    Hi Chaaya,
    Here is the example.
    In the below code, TOP_OF_PAGE is used... similarly in your case END_OF_PAGE should be used. The way you define the event and handle it is similat to that of TOP_OF_PAGE event handled in the below code.
    * Description   : Automatic Condition records generation from Quotation*
    * Packages      : ZSPR                                                 *
    * Table Updates : VBAK, KONP and KONM                                  *
    * Parameters    : P_VKORG, P_VTWEG, P_SPART and P_VKAUS                *
    * Select Option : S_AUDAT, S_VBELN, S_KUNNR and S_MATNR                *
    * Input         : NA                                                   *
    * Output        : NA                                                   *
    * Return Codes  : SY-SUBRC                                             *
    * Special Logic : NA                                                   *
    * Includes      : NA                                                   *
    *             H I S T O R Y   O F   R E V I S I O N S                  *
    *  Date          Programmer      Request #        Description          *
    REPORT  ZSPRENH069 LINE-SIZE 1023 NO STANDARD PAGE HEADING.
    TYPE-POOLS : SLIS.                            "Global Type for ALV      
    *    T Y P E S                                                         *
    TYPES:
           BEGIN OF TY_VB_AKAP,
             VBELN      TYPE VBELN_VA,                       "Sales Document
             KUNNR      TYPE KUNAG,                          "Sold-to party
             POSNR      TYPE POSNR_VA,                       "Item Number
             MATNR      TYPE MATNR,                          "Material Number
             PMATN      TYPE PMATN,                          "Pricing Reference Material/Newly Created Material
             KWMENG     TYPE KWMENG,                         "Cumulative Order Qty. in Sales Units
             VRKME      TYPE VRKME,                          "Sales Unit
             KZWI1      TYPE KZWI1,                          "Sub Total 1 from pricing procedure for condition
             VKAUS      TYPE ABRVW,                          "Usage Indicator
             WAERK      TYPE WAERK,                          "SD Document Currency
           END   OF TY_VB_AKAP,
           BEGIN OF TY_MARA,
             MATNR      TYPE MATNR,                          "Material Number
             ZZTECHSPEC TYPE ZTECHSPEC,                      "Technical Specification
           END   OF TY_MARA,
           BEGIN OF TY_MVKE,
             MATNR      TYPE MATNR,                          "Material Number
             VKORG      TYPE VKORG,                          "Sales Organization
             VTWEG      TYPE VTWEG,                          "Distribution Channel
             KONDM      TYPE KONDM,                          "Material Pricing Group
    *-----------------Begin of changes for the change request 2007096------26th July 2007--------------------------------
             VRKME      TYPE VRKME,                          "Sales Unit according to the Material Master
    *-----------------End   of changes for the change request 2007096------26th July 2007--------------------------------
           END   OF TY_MVKE,
           BEGIN OF TY_VBKD,
             VBELN      TYPE VBELN_VA,                       "Sales Document
             POSNR      TYPE POSNR_VA,                       "Item Number
             BSTKD_E    TYPE BSTKD_E,                        "Used to capture New Material Number
           END   OF TY_VBKD,
           BEGIN OF TY_IHEADER,
             SELECT(1)  TYPE C,                              "Check Box
             VBELN      TYPE VBELN,                          "Sales Document
             KUNNR      TYPE KUNAG,                          "Sold-to Party
           END   OF TY_IHEADER,
           BEGIN OF TY_MESSAGE1,
            VKORG     TYPE VKORG,                            "Sales Organization
            VTWEG     TYPE VTWEG,                            "Distribution Channel
            KUNNR     TYPE KUNAG,                            "Customer number
            KONDM     TYPE KONDM,                            "Material pricing group
            ZCOUNT(2) TYPE N,                                "Zcount
            MSGTYP(1) TYPE C,                                "Message type
            TEXT      TYPE STRING,                           "Message text
           END   OF TY_MESSAGE1,
    *-----------------Begin of changes for the change request 2007106------25th July 2007--------------------------------
           BEGIN OF TY_MESSAGE1_2,
            VKORG     TYPE VKORG,                            "Sales Organization
            VTWEG     TYPE VTWEG,                            "Distribution Channel
            KUNNR     TYPE KUNAG,                            "Customer number
            KONDM     TYPE KONDM,                            "Material pricin
            MSGTYP(1) TYPE C,                                "Message type
            TEXT      TYPE STRING,                           "Message text
           END   OF TY_MESSAGE1_2,
    *-----------------End   of changes for the change request 2007106------25th July 2007--------------------------------
           BEGIN OF TY_MESSAGE2,
            VKORG     TYPE VKORG,                            "Sales Organization
            VTWEG     TYPE VTWEG,                            "Distribution Channel
            KUNNR     TYPE KUNAG,                            "Customer number
            MATNR     TYPE MATNR,                            "Material Number
            MSGTYP(1) TYPE C,                                "Message type
            TEXT      TYPE STRING,                           "Message text
           END   OF TY_MESSAGE2,
           BEGIN OF TY_IFINAL,
             VBELN      TYPE VBELN_VA,                       "Sales Document
             KWMENG     TYPE KWMENG,                         "Cumulative Order Qty. in Sales Units
             POSNR      TYPE POSNR_VA,                       "Item Number
             KUNNR      TYPE KUNAG,                          "Sold-to party
             MATNR      TYPE MATNR,                          "Material Number
             VRKME      TYPE VRKME,                          "Sales Unit
             KZWI1      TYPE KZWI1,                          "Sub Total 1 from pricing procedure for condition
             VKAUS      TYPE ABRVW,                          "Usage Indicator
             ZZTECHSPEC TYPE ZTECHSPEC,                      "Technical Specification
             PMATN      TYPE PMATN,                          "Pricing Reference Material/Newly Created Material
             KONDM      TYPE KONDM,                          "Material Pricing Group
    *-----------------Begin of changes for the change request 2007096------26th July 2007--------------------------------
             WAERK      TYPE WAERK,                          "SD Document Currency
    *-----------------End   of changes for the change request 2007096------26th July 2007--------------------------------
           END   OF TY_IFINAL,
           BEGIN OF TY_ACC1,
             VBELN      TYPE VBELN_VA,                       "Sales Document
             KUNNR      TYPE KUNAG,                          "Sold-to party
             KONDM      TYPE KONDM,                          "Material Pricing Group
             ZCOUNT(2)  TYPE N,                              "ZCount indicator
             KSTBM      TYPE KSTBM,                          "Quantity
             VRKME      TYPE VRKME,                          "Sales Unit
             ZZTECHSPEC TYPE ZTECHSPEC,                      "Technical Specification
             KZWI1      TYPE KZWI1,                          "Sub Total 1 from pricing procedure for condition
             ERROR(1)   TYPE N,                              "Error Field
    *-----------------Begin of changes for the change request 2007096------26th July 2007--------------------------------
             WAERK      TYPE WAERK,                          "SD Document Currency
    *-----------------End   of changes for the change request 2007096------26th July 2007--------------------------------
           END   OF TY_ACC1,
    * Important Note : Earlier there were only three accesses and hence this below type was coded as TY_ACC2 depicting
    * the type for internal table as a holder of data for second access sequence, but later a new access sequence was
    * introduced and was introduced as the second access by itself and hence the sequence which was previously considered
    * as second access is going to be third access sequence in reality. The naming standards that are going to be followed
    * for the newly introduced access sequence would be XXX_1_2. (For Change request 2007106)
           BEGIN OF TY_ACC2,
             VBELN      TYPE VBELN_VA,                       "Sales Document
             KUNNR      TYPE KUNAG,                          "Sold-to party
             MATNR      TYPE MATNR,                          "Material Number
             KSTBM      TYPE KSTBM,                          "Cumulative Order Qty. in Sales Units
             ZZTECHSPEC TYPE ZTECHSPEC,                      "Technical Specification
             VRKME      TYPE VRKME,                          "Sales Unit
             KZWI1      TYPE KZWI1,                          "Sub Total 1 from pricing procedure for condition
             ERROR(1)   TYPE N,                              "Error field
    *-----------------Begin of changes for the change request 2007096------26th July 2007--------------------------------
             WAERK      TYPE WAERK,                          "SD Document Currency
    *-----------------End   of changes for the change request 2007096------26th July 2007--------------------------------
           END   OF TY_ACC2,
    *-----------------Begin of changes for the change request 2007106------24th July 2007--------------------------------
           BEGIN OF TY_ACC1_2,
             VBELN      TYPE VBELN_VA,                       "Sales Document
             KUNNR      TYPE KUNAG,                          "Sold-to party
             KONDM      TYPE KONDM,                          "Material Pricing Group
             KSTBM      TYPE KSTBM,                          "Quantity
             VRKME      TYPE VRKME,                          "Sales Unit
             ZZTECHSPEC TYPE ZTECHSPEC,                      "Technical Specification
             KZWI1      TYPE KZWI1,                          "Sub Total 1 from pricing procedure for condition
             ERROR(1)   TYPE N,                              "Error field
    *-----------------Begin of changes for the change request 2007096------26th July 2007--------------------------------
             WAERK      TYPE WAERK,                          "SD Document Currency
    *-----------------End   of changes for the change request 2007096------26th July 2007--------------------------------
           END   OF TY_ACC1_2,
    *-----------------End   of changes for the change request 2007106------24th July 2007--------------------------------
    *-----------------Begin of changes for the change request 2007096------26th July 2007--------------------------------
           BEGIN OF TY_T006,
             MSEHI      TYPE MSEHI,                          "Unit of Measurement
             ZAEHL      TYPE DZAEHL,                         "Numerator for conversion to SI unit
             NENNR      TYPE NENNR,                          "Denominator for conversion into SI unit
           END   OF TY_T006,
    *-----------------End   of changes for the change request 2007096------26th July 2007--------------------------------
    *-----------------Begin of changes for the change request xxx------2nd Aug 2007--------------------------------
    *Types of MARM table
           BEGIN OF TY_MARM,
             MATNR TYPE MATNR,                               " Material Number
             MEINH TYPE LRMEI,                               " Alternative Unit of Measure
             UMREZ TYPE UMREZ,                               " Numerator for Conversion to Base UOM
             UMREN TYPE UMREN,                               " Denominator for Conversion to Base UOM
           END   OF TY_MARM.
    *-----------------End   of changes for the change request xxx------2nd Aug 2007--------------------------------
    *    D A T A                                                           *
    * Internal Table Declarations
    DATA: T_FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV,           "Fieldcatalog IT
          T_EVENTS       TYPE SLIS_T_EVENT,                  "Event IT
          T_HEADER       TYPE SLIS_T_LISTHEADER,             "Header IT
          T_VB_AKAP      TYPE STANDARD TABLE OF TY_VB_AKAP,  "To hold records from VBAK & VBAP Table
          T_MARA         TYPE STANDARD TABLE OF TY_MARA,     "To hold records from MARA Table
          T_MVKE         TYPE STANDARD TABLE OF TY_MVKE,     "To hold records from MVKE Table
          T_VBKD         TYPE STANDARD TABLE OF TY_VBKD,     "To hold records from VBKD Table
          T_IHEADER      TYPE STANDARD TABLE OF TY_IHEADER,  "To hold records from VBAK Table
          T_IFINAL       TYPE STANDARD TABLE OF TY_IFINAL,   "To hold cumulative data for ALV
          T_BDCDATA      TYPE STANDARD TABLE OF BDCDATA,     "IT for bdcdata
          T_BDCMSGCOLL   TYPE STANDARD TABLE OF BDCMSGCOLL,  "IT for error messages
          T_MESSAGE1     TYPE STANDARD TABLE OF TY_MESSAGE1, "IT for conditions1 messages
    *-----------------Begin of changes for the change request 2007106------25th July 2007--------------------------------
          T_MESSAGE1_2   TYPE STANDARD TABLE OF TY_MESSAGE1_2,"ITfor conditions1_2 messages
    *-----------------End   of changes for the change request 2007106------25th July 2007--------------------------------
          T_MESSAGE2     TYPE STANDARD TABLE OF TY_MESSAGE2, "IT for conditions2 messages
          T_ACC2         TYPE STANDARD TABLE OF TY_ACC2,     "IT for holding data for Second Access Sequence Processing
          T_ACC1         TYPE STANDARD TABLE OF TY_ACC1,     "IT for holding data for First Access Sequence Processing
          T_SELECT       TYPE STANDARD TABLE OF RSPARAMS,    "IT for holding data related to the selection screen
    *-----------------Begin of changes for the change request 2007106------24th July 2007--------------------------------
          T_ACC1_2       TYPE STANDARD TABLE OF TY_ACC1_2,   "IT for holding data for new intermediate Access Sequence
    *-----------------End   of changes for the change request 2007106------24th July 2007--------------------------------
    *-----------------Begin of changes for the change request 2007096------26th July 2007--------------------------------
          T_T006         TYPE STANDARD TABLE OF TY_T006,     "IT for holding T006 Entries
    *-----------------End   of changes for the change request 2007096------26th July 2007--------------------------------
    *-----------------Begin of changes for the change request xxx------2nd Aug 2007--------------------------------
          T_MARM         TYPE STANDARD TABLE OF TY_MARM,     "IT for holding entries from MARM
    *-----------------End   of changes for the change request xxx------2nd Aug 2007--------------------------------
    * Work area Declarations
          W_FIELDCATALOG TYPE SLIS_FIELDCAT_ALV,             "Fieldcatalog WA
          W_EVENT        TYPE SLIS_ALV_EVENT,                "Event WA
          W_HEADER       TYPE SLIS_LISTHEADER,               "Header WA
          W_LAYOUT       TYPE SLIS_LAYOUT_ALV,               "Layout WA
          W_KEYINFO      TYPE SLIS_KEYINFO_ALV,              "Key Information WA
          W_VB_AKAP      TYPE TY_VB_AKAP,                    "To hold records from T_VB_AKAP
          W_MARA         TYPE TY_MARA,                       "To hold records from T_MARA
          W_MVKE         TYPE TY_MVKE,                       "To hold records from T_MVKE
          W_VBKD         TYPE TY_VBKD,                       "To hold records from T_VBKD
          W_IHEADER      TYPE TY_IHEADER,                    "To hold records from T_IHEADER
          W_IFINAL       TYPE TY_IFINAL,                     "To hold records from T_IFINAL
          W_PARAMS       TYPE CTU_PARAMS,                    "CTU Params
          W_BDCDATA      TYPE BDCDATA,                       "Work Area for BDCDATA
          W_BDCMSGCOLL   TYPE BDCMSGCOLL,                    "Work Area to collect BDC Messages
          W_MESSAGE1     TYPE TY_MESSAGE1,                   "WA for price conditions1 messages
    *-----------------Begin of changes for the change request 2007106------25th July 2007--------------------------------
          W_MESSAGE1_2   TYPE TY_MESSAGE1_2,                 "WA for price conditions1_2 messages
    *-----------------End   of changes for the change request 2007106------25th July 2007--------------------------------
          W_MESSAGE2     TYPE TY_MESSAGE2,                   "WA for price conditions2 messages
          W_ACC2         TYPE TY_ACC2,                       "WA for holding records from T_ACC2
          W_ACC1         TYPE TY_ACC1,                       "WA for holding records from T_ACC1
    *-----------------Begin of changes for the change request 2007106------24th July 2007--------------------------------
          W_ACC1_2       TYPE TY_ACC1_2,                     "WA for holding records from T_ACC1_2
    *-----------------End   of changes for the change request 2007106------24th July 2007--------------------------------
    *-----------------Begin of changes for the change request 2007096------26th July 2007--------------------------------
          W_T006         TYPE TY_T006,                       "WA for holding T_T006 Entries
    *-----------------End   of changes for the change request 2007096------26th July 2007--------------------------------
    *-----------------Begin of changes for the change request xxx------2nd Aug 2007--------------------------------
          W_MARM         TYPE TY_MARM,                       "WA for holding entries of T_MARM
    *-----------------End   of changes for the change request xxx------2nd Aug 2007--------------------------------
    * Variable declarations
          G_VKORG       TYPE VKORG,                          "Sales Organization
          G_VTWEG       TYPE VTWEG,                          "Distribution Channel
          G_AUDAT       TYPE AUDAT,                          "Document Date (Date Received/Sent)
          G_VBELN       TYPE VBELN_VA,                       "Sales Document
          G_KUNNR       TYPE KUNAG,                          "Sold-to party
          G_MATNR       TYPE MATNR,                          "Material Number
          G_REPID       TYPE SY-REPID,                       "Program Name
          G_MESSAGE(73) TYPE C,                              "To Capture Message
          G_FLAG1(1)    TYPE C,                              "Flag
          G_ANSWER(1)   TYPE C,                              "Optional Button
    *-----------------Begin of changes for the change request 2007096------26th July 2007--------------------------------
          G_NUM_SOURCE  TYPE DZAEHL,                         "Holds Numerator value for Source Unit of Measure
          G_NUM_TARGET  TYPE DZAEHL,                         "Holds Numerator value for Target Unit of Measure
          G_DEN_SOURCE  TYPE NENNR,                          "Holds Denominator value for Source Unit of Measure
          G_DEN_TARGET  TYPE NENNR.                          "Holds Denominator value for Target Unit of Measure
    *-----------------End   of changes for the change request 2007096------26th July 2007--------------------------------
    * Constant declarations
    CONSTANTS:
          C_A(1)         TYPE C VALUE 'A',                    "Constant Value A
          C_S(1)         TYPE C VALUE 'S',                    "Constant Value S
          C_U(1)         TYPE C VALUE 'U',                    "Constant Value U
          C_X(1)         TYPE C VALUE 'X',                    "Constant Value X
          C_E(1)         TYPE C VALUE 'E',                    "Constant Value E
          C_I(1)         TYPE C VALUE 'I',                    "Constant Value I
          C_R(1)         TYPE C VALUE 'R',                    "Constant Value R
          C_C(1)         TYPE C VALUE 'C',                    "Constant Value C
          C_B(1)         TYPE C VALUE 'B',                    "Document Category is Quotation
          C_HTNAME(10)   TYPE C VALUE 'T_IHEADER',            "Internal table for Header Data
          C_ITNAME(10)   TYPE C VALUE 'T_IFINAL',             "Internal Table with processed data
          C_Q2(2)        TYPE C VALUE 'Q2',                   "Constant Order Reason Q2
          C_100(3)       TYPE C VALUE '100',                  "Popup screen
          C_25(2)        TYPE C VALUE '25',                   "Popup screen
          C_5(1)         TYPE C VALUE '5',                    "Popup screen
          C_1            TYPE I VALUE  1,                     "Value 1 for Error Denotion
          C_2            TYPE I VALUE  2,                     "Value 2 for Error Denotion
          C_3            TYPE I VALUE  3,                     "Value 3 for BDC Error Denotion
          C_1000(4)      TYPE N VALUE 1000,                     "Value 1000
          C_01(2)        TYPE N VALUE '01',                   "Value 01 for Zcount
          C_VK11(4)      TYPE C VALUE 'VK11',                 "Transaction VK11
          C_DYNBEGIN(1)  TYPE C VALUE 'X',                    "Indicator
          C_UPDATE(1)    TYPE C VALUE 'S',                    "Update
          C_DISMODE(1)   TYPE C VALUE 'N',                    "Display
          C_Q3(2)        TYPE C VALUE 'Q3',                   "Quotation Approved
          C_ZBPR(4)      TYPE C VALUE 'ZBPR',                 "Condition Type ZBPR
    *-----------------Begin of changes for the change request xxx------2nd Aug 2007--------------------------------
          C_ZBPN(4)      TYPE C VALUE 'ZBPN',                 "Condition Type ZBPN
    *-----------------End   of changes for the change request xxx------2nd Aug 2007--------------------------------
          C_ERROR(5)     TYPE C VALUE 'ERROR'.                "Error screen title
    *    S E L E C T   O P T I O N S  &  P A R A M E T E R S               *
    * Selection-screen Block 1
    SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
    PARAMETERS:     P_VKORG TYPE VKORG OBLIGATORY,           "Sales Organization
                    P_VTWEG TYPE VTWEG OBLIGATORY,           "Distribution Channel
                    P_SPART TYPE SPART DEFAULT '00'.         "Division
    SELECTION-SCREEN END OF BLOCK BLK1.
    SELECTION-SCREEN BEGIN OF BLOCK BLK2 WITH FRAME TITLE TEXT-002.
    SELECT-OPTIONS: S_AUDAT FOR G_AUDAT,                     "Document Date (Date Received/Sent)
                    S_VBELN FOR G_VBELN,                     "Sales Document
                    S_KUNNR FOR G_KUNNR,                     "Sold-to party
                    S_MATNR FOR G_MATNR.                     "Material Number
    PARAMETERS:     P_VKAUS(2) TYPE N.                       "Usage Indicator
    SELECTION-SCREEN END OF BLOCK BLK2.
    *   I N I T I A L I Z A T I O N                                        *
    INITIALIZATION.
      CLEAR : G_REPID.                                       "Program Name
      G_REPID = SY-REPID.                                    "Program Name
    *   A T   S E L E C T I O N   S C R E E N                              *
      CLEAR: G_VKORG,
             G_VTWEG.
    AT SELECTION-SCREEN ON P_VKORG.
      SELECT SINGLE VKORG INTO G_VKORG
                          FROM TVKO
                          WHERE VKORG EQ P_VKORG.
      IF SY-SUBRC NE 0.
        MESSAGE E000(ZS) WITH TEXT-021.
      ENDIF.
    AT SELECTION-SCREEN ON P_VTWEG.
      SELECT SINGLE VTWEG INTO G_VTWEG
                          FROM TVKOV
                          WHERE VKORG EQ P_VKORG
                            AND VTWEG EQ P_VTWEG.
      IF SY-SUBRC NE 0.
        MESSAGE E000(ZS) WITH TEXT-022.
      ENDIF.
      CLEAR: G_VKORG,
             G_VTWEG.
    *   S T A R T   O F   S E L E C T I O N                                *
    START-OF-SELECTION.
    * Data Selection
      PERFORM DATA_RETRIEVAL.
    * Build Field Catalog
      PERFORM BUILD_FIELDCATALOG.
    * Bulid layout
      PERFORM BUILD_LAYOUT.
    * Build Events
      PERFORM BUILD_EVENTS.
    * Captures the Values of Selection Screen
      PERFORM CAPTURE_SCREEN.
    *   E N D   O F   S E L E C T I O N                                    *
    END-OF-SELECTION.
    * Display List
      PERFORM DISPLAY_ALV_REPORT.
    *   F O R M S                                                          *
    *&      Form  DATA_RETRIEVAL
    *       Retrieves Data for ALV Display
    *-----------------Begin of changes for the change request 2007106------25th July 2007--------------------------------
    *-----------------End   of changes for the change request 2007106------25th July 2007--------------------------------
    FORM DATA_RETRIEVAL .
      DATA : L_VKAUS   TYPE VKAUS.            "Variable to hold Usage Indicator
      CLEAR L_VKAUS.
      SELECT VBELN
             KUNNR
        INTO CORRESPONDING FIELDS OF TABLE T_IHEADER
        FROM VBAK
        WHERE VBELN IN S_VBELN
          AND KUNNR IN S_KUNNR
          AND VKORG EQ P_VKORG
          AND AUDAT IN S_AUDAT
          AND VTWEG EQ P_VTWEG
          AND SPART EQ P_SPART
          AND AUGRU EQ C_Q2
          AND VBTYP EQ C_B.
      IF NOT T_IHEADER IS INITIAL.
        IF NOT P_VKAUS IS INITIAL.
    *-----------------Begin of changes for the change request 2007106------25th July 2007------COMMENTED FROM HERE-----
    *      IF P_VKAUS EQ C_1.    "IF Zcount is given as 1 then quotation without zcount should be picked
    *        "for whom Material Pricing Group should be given.
    *        SELECT A~VBELN
    *               A~KUNNR
    *               B~POSNR
    *               B~MATNR
    *               B~PMATN
    *               B~KWMENG
    *               B~VRKME
    *               B~KZWI1
    *               B~VKAUS
    *         INTO  TABLE T_VB_AKAP
    *         FROM  VBAK AS A
    *         JOIN  VBAP AS B
    *           ON  A~VBELN EQ B~VBELN
    *         FOR ALL ENTRIES IN T_IHEADER
    *         WHERE A~VBELN EQ T_IHEADER-VBELN
    *           AND B~MATNR IN S_MATNR.
    *      ELSE.
    *-----------------End   of changes for the change request 2007106------25th July 2007------COMMENTED TILL HERE-----
          CONCATENATE C_C P_VKAUS INTO L_VKAUS.
          SELECT A~VBELN
                 A~KUNNR
                 B~POSNR
                 B~MATNR
                 B~PMATN
                 B~KWMENG
                 B~VRKME
                 B~KZWI1
                 B~VKAUS
    *-----------------Begin of changes for the change request 2007096------26th July 2007--------------------------------
                 A~WAERK
    *-----------------End   of changes for the change request 2007096------26th July 2007--------------------------------
           INTO  TABLE T_VB_AKAP
           FROM  VBAK AS A
           JOIN  VBAP AS B
             ON  A~VBELN EQ B~VBELN
           FOR ALL ENTRIES IN T_IHEADER
            WHERE A~VBELN EQ T_IHEADER-VBELN
              AND B~MATNR IN S_MATNR
              AND B~VKAUS EQ L_VKAUS.
    *      ENDIF.
        ELSE.
          SELECT A~VBELN
                 A~KUNNR
                 B~POSNR
                 B~MATNR
                 B~PMATN
                 B~KWMENG
                 B~VRKME
                 B~KZWI1
                 B~VKAUS
    *-----------------Begin of changes for the change request 2007096------26th July 2007--------------------------------
                 A~WAERK
    *-----------------End   of changes for the change request 2007096------26th July 2007--------------------------------
           INTO  TABLE T_VB_AKAP
           FROM  VBAK AS A
           JOIN  VBAP AS B
             ON  A~VBELN EQ B~VBELN
           FOR ALL ENTRIES IN T_IHEADER
           WHERE A~VBELN EQ T_IHEADER-VBELN
             AND B~MATNR IN S_MATNR.
        ENDIF.
        IF NOT T_VB_AKAP IS INITIAL.
          SELECT  VBELN
                  POSNR
                  BSTKD_E
             INTO TABLE T_VBKD
             FROM VBKD
             FOR ALL ENTRIES IN T_VB_AKAP
             WHERE VBELN EQ T_VB_AKAP-VBELN
               AND POSNR EQ T_VB_AKAP-POSNR.
        ENDIF.
        SORT T_VBKD BY VBELN POSNR.
        CLEAR W_VB_AKAP.
    *   After much of coding was completed, Usage of PMATN was dropped and
    *   the first eighteen characters of the field BSTKD was proposed for usage
    *   Hence PMATN is overwritten by BSTKD value in the below loop
        LOOP AT T_VB_AKAP INTO W_VB_AKAP.
          CLEAR: W_VBKD,
                 W_VB_AKAP-PMATN.
          READ TABLE T_VBKD INTO W_VBKD
                            WITH KEY VBELN = W_VB_AKAP-VBELN
                                     POSNR = W_VB_AKAP-POSNR
                            BINARY SEARCH.
          IF SY-SUBRC EQ 0.
            W_VB_AKAP-PMATN = W_VBKD-BSTKD_E+0(18).
          ENDIF.
          MODIFY T_VB_AKAP FROM W_VB_AKAP TRANSPORTING PMATN.
          CLEAR W_VB_AKAP.
        ENDLOOP.
        IF NOT T_VB_AKAP IS INITIAL.
    *     Collecting all Material Numbers along with their Technical Spec data for all the materials available in T_VB_AKAP.
          SELECT    MATNR
                    ZZTECHSPEC
            INTO    TABLE T_MARA
            FROM    MARA
            FOR ALL ENTRIES IN T_VB_AKAP
            WHERE   MATNR EQ T_VB_AKAP-MATNR.
          IF SY-SUBRC EQ 0.
            SORT T_MARA BY MATNR.
          ENDIF.                     "Checking SY-SUBRC for T_MARA
          SELECT    MATNR
                    ZZTECHSPEC
            APPENDING TABLE T_MARA
            FROM    MARA
            FOR ALL ENTRIES IN T_VB_AKAP
            WHERE   MATNR EQ T_VB_AKAP-PMATN.
          IF SY-SUBRC EQ 0.
            SORT T_MARA BY MATNR.
          ENDIF.                     "Checking SY-SUBRC for T_MARA
    *-----------------Begin of changes for the change request xxx------2nd Aug 2007--------------------------------
    *     Collecting information into T_MARM for all the available materials so that it could be used for conversion into Alternate UOM
          SELECT MATNR                          " Material Number
                 MEINH                          " Alternate UOM
                 UMREZ                          " Numerator for conversion
                 UMREN                          " Denominator for conversion
            FROM MARM
            INTO TABLE T_MARM
            FOR ALL ENTRIES IN T_VB_AKAP
            WHERE MATNR EQ T_VB_AKAP-MATNR.
          IF SY-SUBRC = 0.
            SORT T_MARM BY MATNR MEINH.
          ENDIF.                     "Checking SY-SUBRC for T_MARM
          SELECT MATNR                          " Material Number
                 MEINH                          " Alternate UOM
                 UMREZ                          " Numerator for conversion
                 UMREN                          " Denominator for conversion
            FROM MARM
            APPENDING TABLE T_MARM
            FOR ALL ENTRIES IN T_VB_AKAP
            WHERE MATNR EQ T_VB_AKAP-PMATN.
          IF SY-SUBRC = 0.
            SORT T_MARM BY MATNR MEINH.
          ENDIF.                     "Checking SY-SUBRC for T_MARM
    *-----------------End   of changes for the change request xxx------2nd Aug 2007--------------------------------
          SELECT    MATNR
                    VKORG
                    VTWEG
                    KONDM
    *-----------------Begin of changes for the change request 2007096------26th July 2007--------------------------------
                    VRKME
    *-----------------End   of changes for the change request 2007096------26th July 2007--------------------------------
            INTO    TABLE T_MVKE
            FROM    MVKE
            FOR ALL ENTRIES IN T_VB_AKAP
            WHERE   MATNR EQ T_VB_AKAP-PMATN.
          IF SY-SUBRC EQ 0.
            SORT T_MVKE BY MATNR VKORG VTWEG.
          ENDIF.                     "Checking SY-SUBRC for T_MVKE
          SELECT    MATNR
                    VKORG
                    VTWEG
                    KONDM
    *-----------------Begin of changes for the change request 2007096------26th July 2007--------------------------------
                    VRKME
    *-----------------End   of changes for the change request 2007096------26th July 2007--------------------------------
            APPENDING TABLE T_MVKE
            FROM    MVKE
            FOR ALL ENTRIES IN T_VB_AKAP
            WHERE   MATNR EQ T_VB_AKAP-MATNR.
          IF SY-SUBRC EQ 0.
            SORT T_MVKE BY MATNR VKORG VTWEG.
          ENDIF.                     "Checking SY-SUBRC for T_MVKE
    *-----------------Begin of changes for the change request 2007096------26th July 2007--------------------------------
          SELECT    MSEHI
                    ZAEHL
                    NENNR
             INTO   TABLE T_T006
             FROM   T006
             FOR ALL ENTRIES IN T_VB_AKAP
             WHERE  MSEHI EQ T_VB_AKAP-VRKME.
          IF SY-SUBRC EQ 0.
            SORT T_T006 BY MSEHI.
          ENDIF.                     "Checking SY-SUBRC for T_T006
          IF NOT T_MVKE IS INITIAL.
            SELECT MSEHI
                   ZAEHL
                   NENNR
            APPENDING TABLE T_T006
            FROM   T006
            FOR ALL ENTRIES IN T_MVKE
            WHERE MSEHI EQ T_MVKE-VRKME.
            IF SY-SUBRC EQ 0.
              SORT T_T006 BY MSEHI.
            ENDIF.                  "Checking SY-SUBRC for T_T006
          ENDIF.                     "Checking for Initial status of internal table T_MVKE
    *-----------------End   of changes for the change request 2007096------26th July 2007--------------------------------
        ENDIF.                    " FOR T_VB_AKAP NOT INITIAL.
      ENDIF.                    " FOR T_IHEADER NOT INITIAL.
      CLEAR: W_VB_AKAP,
             W_IFINAL.
      LOOP AT T_VB_AKAP INTO W_VB_AKAP.
        W_IFINAL-VBELN  = W_VB_AKAP-VBELN.
        W_IFINAL-KUNNR  = W_VB_AKAP-KUNNR.
        W_IFINAL-POSNR  = W_VB_AKAP-POSNR.
        W_IFINAL-MATNR  = W_VB_AKAP-MATNR.
        W_IFINAL-PMATN  = W_VB_AKAP-PMATN.
        W_IFINAL-KWMENG = W_VB_AKAP-KWMENG.
        W_IFINAL-VRKME  = W_VB_AKAP-VRKME.
        W_IFINAL-KZWI1  = ( W_VB_AKAP-KZWI1 / W_VB_AKAP-KWMENG ) * 1000.
        W_IFINAL-VKAUS  = W_VB_AKAP-VKAUS.
    *-----------------Begin of changes for the change request 2007096------26th July 2007--------------------------------
        W_IFINAL-WAERK  = W_VB_AKAP-WAERK.
    *-----------------End   of changes for the change request 2007096------26th July 2007--------------------------------
    *   Populating Material Pricing Group from New Material Group, if such Group doesn't exist
    *   Population of Material Pricing Group from Material Number is tried.
    *   Similar condition does suit for Tech Spec too.
        SORT: T_MVKE BY MATNR VKORG VTWEG,
              T_MARA BY MATNR.
        IF NOT W_VB_AKAP-PMATN IS INITIAL.
          CLEAR W_MVKE.
          READ TABLE    T_MVKE
               INTO     W_MVKE
               WITH KEY MATNR = W_VB_AKAP-PMATN
                        VKORG = P_VKORG
                        VTWEG = P_VTWEG
               BINARY SEARCH.
          IF SY-SUBRC EQ 0.
            W_IFINAL-KONDM = W_MVKE-KONDM.
    *-----------------Begin of changes for the change request 2007096------26th July 2007--------------------------------
            IF ( W_IFINAL-VRKME NE W_MVKE-VRKME ) AND ( NOT W_MVKE-VRKME IS INITIAL ).
    *-----------------Begin of changes for the change request xxx------2nd Aug 2007--------------------------------
              CLEAR: W_MARM,
                     G_NUM_SOURCE,
                     G_DEN_SOURCE,
                     G_NUM_TARGET,
                     G_DEN_TARGET.
              READ TABLE T_MARM INTO W_MARM
                                WITH KEY MATNR = W_IFINAL-PMATN
                                MEINH = W_IFINAL-VRKME
                                BINARY SEARCH.
              IF SY-SUBRC EQ 0.
                G_NUM_SOURCE = W_MARM-UMREZ.
                G_DEN_SOURCE = W_MARM-UMREN.
                CLEAR W_MARM.
                READ TABLE T_MARM INTO W_MARM
                                  WITH KEY MATNR = W_IFINAL-PMATN
                                  MEINH = W_MVKE-VRKME
                                  BINARY SEARCH.
                IF SY-SUBRC EQ 0.
                  G_NUM_TARGET = W_MARM-UMREZ.
                  G_DEN_TARGET = W_MARM-UMREN.
                  CLEAR W_MARM.
                  W_IFINAL-KWMENG = W_IFINAL-KWMENG * ( G_NUM_SOURCE / G_DEN_SOURCE ) * ( G_DEN_TARGET / G_NUM_TARGET ).
                  CLEAR W_IFINAL-KZWI1.
                  W_IFINAL-KZWI1   = ( W_VB_AKAP-KZWI1 / W_IFINAL-KWMENG ) * 1000.
                  W_IFINAL-VRKME = W_MVKE-VRKME.
                ENDIF.              "Check SY-SUBRC for W_MARM using W_MVKE-VRKME (Sales UOM)
              ELSE.
    *-----------------End   of changes for the change request xxx------2nd Aug 2007--------------------------------
                CLEAR: W_T006,
                       G_NUM_SOURCE,
                       G_DEN_SOURCE,
                       G_NUM_TARGET,
                       G_DEN_TARGET.
                READ TABLE T_T006 INTO W_T006 WITH KEY MSEHI = W_IFINAL-VRKME
                                              BINARY SEARCH.
                IF SY-SUBRC EQ 0.
                  G_NUM_SOURCE = W_T006-ZAEHL.          "Numerator to convert specified UOM to SI UOM
                  G_DEN_SOURCE = W_T006-NENNR.          "Denominator to convert specified UOM to SI UOM
                  CLEAR W_T006.
                  READ TABLE T_T006 INTO W_T006 WITH KEY MSEHI = W_MVKE-VRKME
                                                BINARY SEARCH.
                  IF SY-SUBRC EQ 0.
                    G_NUM_TARGET = W_T006-ZAEHL.            "Numerator to convert specified UOM to SI UOM
                    G_DEN_TARGET = W_T006-NENNR.            "Denominator to convert specified UOM to SI UOM
                    CLEAR W_T006.
                    W_IFINAL-KWMENG = W_IFINAL-KWMENG * ( G_NUM_SOURCE / G_DEN_SOURCE ) * ( G_DEN_TARGET / G_NUM_TARGET ).
                    CLEAR W_IFINAL-KZWI1.
                    W_IFINAL-KZWI1   = ( W_VB_AKAP-KZWI1 / W_IFINAL-KWMENG ) * 1000.
                    W_IFINAL-VRKME = W_MVKE-VRKME.
                  ENDIF.          "Check for SY-SUBRC for READ TABLE T_T006 using W_MVKE-VRKME (Sales UOM)
                ENDIF.            "Check for SY-SUBRC for READ TABLE T_T006 using W_IFINAL-VRKME (Quotation UOM)
              ENDIF.              "Check SY-SUBRC for W_MARM using W_IFINAL-VRKME (Quotation UOM)
            ENDIF.              "Check for ( W_IFINAL-VRKME NE W_MVKE-VRKME ) AND ( NOT W_MVKE-VRKME IS INITIAL )
    *-----------------End   of changes for the change request 2007096------26th July 2007--------------------------------
          ENDIF.
          CLEAR W_MARA.
          READ TABLE     T_MARA
               INTO      W_MARA
               WITH KEY  MATNR = W_VB_AKAP-PMATN
               BINARY SEARCH.
          IF SY-SUBRC EQ 0.
            W_IFINAL-ZZTECHSPEC = W_MARA-ZZTECHSPEC.
          ENDIF.                              " SY-SUBRC FOR READ TABLE T_MARA
        ELSE.
          CLEAR W_MVKE.
          READ TABLE     T_MVKE
               INTO      W_MVKE
               WITH KEY  MATNR = W_VB_AKAP-MATNR
                         VKORG = P_VKORG
                         VTWEG = P_VTWEG
               BINARY SEARCH.
          IF SY-SUBRC EQ 0.
            W_IFINAL-KONDM = W_MVKE-KONDM.
    *-----------------Begin of changes for the change request 2007096------26th July 2007--------------------------------
            IF ( W_IFINAL-VRKME NE W_MVKE-VRKME ) AND ( NOT W_MVKE-VRKME IS INITIAL ).
    *-----------------Begin of changes for the change request xxx------2nd Aug 2007--------------------------------
              CLEAR: W_MARM,
                     G_NUM_SOURCE,
                     G_DEN_SOURCE,
                     G_NUM_TARGET,
                     G_DEN_TARGET.
              READ TABLE T_MARM INTO W_MARM
                                WITH KEY MATNR = W_IFINAL-MATNR
                                MEINH = W_IFINAL-VRKME
                                BINARY SEARCH.
              IF SY-SUBRC EQ 0.
                G_NUM_SOURCE = W_MARM-UMREZ.
                G_DEN_SOURCE = W_MARM-UMREN.
                CLEAR W_MARM.
                READ TABLE T_MARM INTO W_MARM
                                  WITH KEY MATNR = W_IFINAL-MATNR
                                  MEINH = W_MVKE-VRKME
                                  BINARY SEARCH.
                IF SY-SUBRC EQ 0.
                  G_NUM_TARGET = W_MARM-UMREZ.
                  G_DEN_TARGET = W_MARM-UMREN.
                  CLEAR W_MARM.
                  W_IFINAL-KWMENG = W_IFINAL-KWMENG * ( G_NUM_SOURCE / G_DEN_SOURCE ) * ( G_DEN_TARGET / G_NUM_TARGET ).
                  CLEAR W_IFINAL-KZWI1.
                  W_IFINAL-KZWI1   = ( W_VB_AKAP-KZWI1 / W_IFINAL-KWMENG ) * 1000.
                  W_IFINAL-VRKME = W_MVKE-VRKME.
                ENDIF.              "Check SY-SUBRC for W_MARM using W_MVKE-VRKME (Sales UOM)
              ELSE.
    *-----------------End   of changes for the change request xxx------2nd Aug 2007--------------------------------
                CLEAR: W_T006,
                       G_NUM_SOURCE,
                       G_DEN_SOURCE,
                       G_NUM_TARGET,
                       G_DEN_TARGET.
                READ TABLE T_T006 INTO W_T006 WITH KEY MSEHI = W_IFINAL-VRKME
                                              BINARY SEARCH.
                IF SY-SUBRC EQ 0.
                  G_NUM_SOURCE = W_T006-ZAEHL.          "Numerator to convert specified UOM to SI UOM
                  G_DEN_SOURCE = W_T006-NENNR.          "Denominator to convert specified UOM to SI UOM
                  CLEAR W_T006.
                  READ TABLE T_T006 INTO W_T006 WITH KEY MSEHI = W_MVKE-VRKME
                                                BINARY SEARCH.
                  IF SY-SUBRC EQ 0.
                    G_NUM_TARGET = W_T006-ZAEHL.            "Numerator to convert specified UOM to SI UOM
                    G_DEN_TARGET = W_T006-NENNR.            "Denominator to convert specified UOM to SI UOM
                    CLEAR W_T006.
                    W_IFINAL-KWMENG = W_IFINAL-KWMENG * ( G_NUM_SOURCE / G_DEN_SOURCE ) * ( G_DEN_TARGET / G_NUM_TARGET ).
                    CLEAR W_IFINAL-KZWI1.
                    W_IFINAL-KZWI1   = ( W_VB_AKAP-KZWI1 / W_IFINAL-KWMENG ) * 1000.
                    W_IFINAL-VRKME = W_MVKE-VRKME.
                  ENDIF.          "Check for SY-SUBRC for READ TABLE T_T006 using W_MVKE-VRKME (Sales UOM)
                ENDIF.            "Check for SY-SUBRC for READ TABLE T_T006 using W_IFINAL-VRKME (Quotation UOM)
              ENDIF.              "Check SY-SUBRC for W_MARM using W_IFINAL-VRKME (Quotation UOM)
            ENDIF.              "Check for ( W_IFINAL-VRKME NE W_MVKE-VRKME ) AND ( NOT W_MVKE-VRKME IS INITIAL )
    *-----------------End   of changes for the change request 2007096------26th July 2007--------------------------------
          ENDIF.
          CLEAR W_MARA.
          READ TABLE     T_MARA
               INTO      W_MARA
               WITH KEY  MATNR = W_VB_AKAP-MATNR
               BINARY SEARCH.
          IF SY-SUBRC EQ 0.
            W_IFINAL-ZZTECHSPEC = W_MARA-ZZTECHSPEC.
          ENDIF.                              " SY-SUBRC FOR READ TABLE T_MARA
        ENDIF.                              " IS INITIAL CHECK FOR W_MVKE-KONDM
    *-----------------Begin of changes for the change request 2007106------25th July 2007------COMMENTED FROM HERE-----
    **   This logic is written to avoid records without Material Pricing group whose
    **   Zcount is selected as 1.
    *    IF P_VKAUS EQ C_1.
    *      IF NOT W_IFINAL-KONDM IS INITIAL AND W_IFINAL-VKAUS IS INITIAL.
    *        APPEND W_IFINAL TO T_IFINAL.
    *      ENDIF.
    *    ELSE.
    *-----------------End   of changes for the change request 2007106------25th July 2007------COMMENTED TILL HERE-----
        APPEND W_IFINAL TO T_IFINAL.
    *    ENDIF.              Commented for the change request 2007106-----25th July 2007
        CLEAR: W_VB_AKAP,
               W_IFINAL.
      ENDLOOP.
      SORT T_IFINAL BY VBELN POSNR.
    *  Checking whether if there are any header quotations which does not have items against them in item internal table
    *  if such records exist then, ensuring that such records gets deleted from header too, so that inconsitency is removed.
      CLEAR W_IHEADER.
      LOOP AT T_IHEADER INTO W_IHEADER.
        CLEAR W_IFINAL.
        READ TABLE T_IFINAL INTO W_IFINAL
                            WITH KEY VBELN = W_IHEADER-VBELN
                            BINARY SEARCH.
        IF SY-SUBRC NE 0.
          W_IHEADER-SELECT = C_X.
          MODIFY T_IHEADER FROM W_IHEADER TRANSPORTING SELECT.
        ENDIF.
      ENDLOOP.
      DELETE T_IHEADER WHERE SELECT = C_X.
      SORT T_IFINAL BY VBELN POSNR.
    ENDFORM.                    " DATA_RETRIEVAL
    *&      Form  build_layout
    *       To build ALV Layout
    FORM BUILD_LAYOUT.
      CLEAR  : W_LAYOUT.
      W_LAYOUT-COLWIDTH_OPTIMIZE = C_X.
      W_LAYOUT-BOX_TABNAME       = C_HTNAME.      "tabname for checkbox
      W_LAYOUT-BOX_FIELDNAME     = 'SELECT'.      "fieldname for checkbox
      CLEAR  : W_KEYINFO.
      W_KEYINFO-HEADER01 = 'VBELN'.               "Header1 key information
      W_KEYINFO-ITEM01   = 'VBELN'.               "Item1 key information
    *  W_LAYOUT-no_min_linesize = C_X.
    *         W_LAYOUT-min_linesize  = 80.
    *         W_LAYOUT-max_linesize  = 400.
    ENDFORM.                                      "build_layout
    *&      Form  build_events
    *       To build ALV Events
    FORM BUILD_EVENTS.
      CONSTANTS: C_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE'.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          I_LIST_TYPE     = 1
        IMPORTING
          ET_EVENTS       = T_EVENTS
        EXCEPTIONS
          LIST_TYPE_WRONG = 1
          OTHERS          = 2.
      IF SY-SUBRC = 0.
        CLEAR W_EVENT.
        READ TABLE T_EVENTS INTO W_EVENT
                            WITH KEY NAME = C_TOP_OF_PAGE.
        IF SY-SUBRC = 0.
          MOVE C_TOP_OF_PAGE TO W_EVENT-FORM.
          MODIFY T_EVENTS INDEX SY-TABIX
                          FROM  W_EVENT
                          TRANSPORTING FORM.
        ENDIF.
      ELSE.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                                      "build_events
    *&      Form  top_of_page
    *       To display top of page in ALV Report
    FORM TOP_OF_PAGE.                                           "#EC CALLED
      DATA :
        L_VKORG(35) TYPE C,                        "Sales Organization
        L_VTWEG(35) TYPE C,                        "Distribution Channel
        L_SPART(35) TYPE C.                        "Division
    * Sales Organization
      CLEAR W_HEADER.
      W_HEADER-TYP  = C_S.
      CONCATENATE TEXT-004 P_VKORG INTO L_VKORG.
      W_HEADER-INFO = L_VKORG.
      APPEND W_HEADER TO T_HEADER.
    * Distribution Channel
      CLEAR W_HEADER.
      W_HEADER-TYP  = C_S.
      CONCATENATE TEXT-005 P_VTWEG INTO L_VTWEG.
      W_HEADER-INFO = L_VTWEG.
      APPEND W_HEADER TO T_HEADER.
    * Division
      CLEAR W_HEADER.
      W_HEADER-TYP  = C_S.
      CONCATENATE TEXT-006 P_SPART INTO L_SPART.
      W_HEADER-INFO = L_SPART.
      APPEND W_HEADER TO T_HEADER.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          IT_LIST_COMMENTARY = T_HEADER.
    ENDFORM.                                      "top_of_page
    *&      Form  pf_status
    *       To set PF-Status (user interface)
    *      -->EXTAB     The excluding table (function codes)
    FORM PF_STATUS                                              "#EC CALLED
              USING T_EXTAB TYPE SLIS_T_EXTAB.
      REFRESH T_EXTAB.
      SET PF-STATUS 'ZSTANDARD_FULLSCREEN' EXCLUDING T_EXTAB.
    ENDFORM.                                      "pf_status
    *&      Form  display_alv_report
    *       To display ALV report
    FORM DISPLAY_ALV_REPORT.
      CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM       = G_REPID
          I_CALLBACK_PF_STATUS_SET = 'PF_STATUS'
          I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
          IS_LAYOUT                = W_LAYOUT
          IT_FIELDCAT              = T_FIELDCATALOG
          I_DEFAULT                = C_X
          I_SAVE                   = C_A
          IT_EVENTS                = T_EVENTS[]
          I_TABNAME_HEADER         = 'T_IHEADER'
          I_TABNAME_ITEM           = 'T_IFINAL'
          IS_KEYINFO               = W_KEYINFO
        TABLES
          T_OUTTAB_HEADER          = T_IHEADER
          T_OUTTAB_ITEM            = T_IFINAL
        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_alv_report
    *&      Form  BUILD_FIELDCATALOG
    *       To build ALV Field Catalog
    FORM BUILD_FIELDCATALOG .
      DATA: L_COUNT TYPE I VALUE 0.
      CLEAR  W_FIELDCATALOG.
      L_COUNT = L_COUNT + 1.
      W_FIELDCATALOG-COL_POS     =  L_COUNT.
      W_FIELDCATALOG-TABNAME     =  C_HTNAME.
      W_FIELDCATALOG-FIELDNAME   = 'SELECT'.
      W_FIELDCATALOG-SELTEXT_M   =  TEXT-C01.
      W_FIELDCATALOG-CHECKBOX    =  C_X.
      W_FIELDCATALOG-EDIT        =  C_X.
      APPEND W_FIELDCATALOG TO T_FIELDCATALOG.
      CLEAR  W_FIELDCATALOG.
      L_COUNT = L_COUNT + 1.
      W_FIELDCATALOG-COL_POS     =  L_COUNT.
      W_FIELDCATALOG-TABNAME     =  C_HTNAME.
      W_FIELDCATALOG-FIELDNAME   = 'VBELN'.
      W_FIELDCATALOG-SELTEXT_M   =  TEXT-C02.
      W_FIELDCATALOG-KEY         =  C_X.   "Fixes the column for no-scroll
      APPEND W_FIELDCATALOG TO T_FIELDCATALOG.
      CLEAR  W_FIELDCATALOG.
      L_COUNT = L_COUNT + 1.
      W_FIELDCATALOG-COL_POS 

  • Setting the PF Status for ALV

    Hi all,
    How it would be possible to create a PF Status for ALV display. I want to add one button my ALV report.
    Thanks.
    Harshad.

    Hi ,
    You can create PF-status using the Statement :   set pf-status 'STATUS_NAME'  in a FORM as shown below:
    form frm_status using rt_extab type slis_t_extab.
      set pf-status 'STANDARD'.
    endform.
    Double click on the STATUS_NAME and it Navigates to the Screen Painter. There you can specify the Menu , Buttons as required.
    Instead of cretaing a new status you can also copy the existing Standard status as told above and use the required buttons / menu items.
    Now to handle the operations of these buttons :Include in a form as below
    form frm_usercommand using r_ucomm like sy-ucomm
                      rs_selfield type slis_selfield.
      case r_ucomm.
        when 'SUB'.
          <opertion as required>
        when 'SUB1'.
           <opertion as required>
      endcase.
    Endform.
    Pass these two form names to the FM REUSE_ALV_GRID_DISPLAY ( Parameters of FM : i_callback_pf_status_set   &  i_callback_user_command  ) and the result will be dispalyed with the new Status to the parameters  .
    call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
        I_INTERFACE_CHECK                 = ' '
        I_BYPASSING_BUFFER                = ' '
        I_BUFFER_ACTIVE                   = ' '
         i_callback_program                = v_repid
         i_callback_pf_status_set          = 'FRM_STATUS'
         i_callback_user_command           = 'FRM_USERCOMMAND'
        I_CALLBACK_TOP_OF_PAGE            = ' '
        I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
        I_CALLBACK_HTML_END_OF_LIST       = ' '
        I_STRUCTURE_NAME                  =
        I_BACKGROUND_ID                   = ' '
        I_GRID_TITLE                      =
        I_GRID_SETTINGS                   =
        IS_LAYOUT                         =
         it_fieldcat                       = it_fieldcat
        IT_EXCLUDING                      =
        IT_SPECIAL_GROUPS                 =
        IT_SORT                           =
        IT_FILTER                         =
        IS_SEL_HIDE                       =
        I_DEFAULT                         = 'X'
        I_SAVE                            = ' '
        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_vbak
       exceptions
         program_error                     = 1
         others                            = 2
    Regards,
    Radhika.

  • Ask split long text into two line into same cell for ALV

    Dear All,
    Is it possible split long text into two line into same cell for ALV display data?
    Regards,
    Luke
    Moderator message: please search for information before asking.
    Edited by: Thomas Zloch on Feb 24, 2011 10:12 AM

    Keep options: Select the paragraph, then CtrlAltK (Mac: CmdOptK, I
    think).
    If you want the paragraphs in pairs, create two paragraph styles. Style
    A has keep options set to start on a new page, and also, its Next Style
    is style B.
    Style B has no keep options, but it's Next Style is Style A.
    Select all the text.
    From the flyout menu of the paragraph styles palette, apply Style A
    "then next style."
    Now all paragraphs will be alternating -- style A, style B, style A, etc.
    Now do what I wrote initially, and you'll have pairs of paragraph in
    separate text frames.

  • For output display report is final_internal table or structure in wd ABAP?

    Hi all,
    for output display report is final_internal table or structure in wd ABAP?
    in wd java output display report -.> CALLING rfc and that RFC OUTPUT table
    finally in internal table is assigned to STRUCTURE .Same procdure?
    Thanks,
    RAMA

    Dear Madhu,
    thanks for guidence!
    its showing popup tht this BADI ( ME_CHANGE_OUTTAB_CUS ) is only use for "SAP Internal  use".
    Regards,
    Praphull

Maybe you are looking for

  • ORDER BY Clause in XMLAGG is throwing errors.

    Hi, I'm getting errors when generating the XML using the ORDER BY clause in the XMLAgg function. Although, running the SQL directly in SQL Plus doesn't have any problem. Here is the PL/SQL sample. DECLARE vX_XML SYS.XMLTYPE; vCL_XML CLOB; BEGIN SELEC

  • I am unable to install my Photoshop Elements II purchased October 2013?

    I tried unsuccessfully to install my Photoshop Elements II disk onto my computer. It says the serial number is invalid and the redemption code is also invalid.  Does Photoshop expire?  How can I activate this so that I may use my software? Thank you.

  • Cannot view high quality on external monitor - Prores 422?

    I am working on a music video and trying the Prores 422 codec for the first time. When I view the clips from the viewer in Final Cut pro I can insert in and outpoints as normal and watch the clips on my external monitor in full quality and that is al

  • Add new field in dynamic selections for transaction FAGLL03

    Hello experts, I'm trying to add field CPUDT (Entry Date) from table BKPF in the dynamic selections of logical database SDF. In fact, and referring to some hints posted in the forum, I copied the standard selection view 'SAP' to 'CUS' and then added

  • How may I change my slide labels?

    I would like to rename my slides, and I am sure there must be a very easy answer to this that I am overlooking. From all the online research I have done to find the answer to this question, it seems that while I am in filmstrip view, I should simply