<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: program to generate ALV (using 3 tables) in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/program-to-generate-alv-using-3-tables/m-p/3613615#M870580</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN __jive_emoticon_name="shocked"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 17 Mar 2008 15:40:57 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-03-17T15:40:57Z</dc:date>
    <item>
      <title>program to generate ALV (using 3 tables)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/program-to-generate-alv-using-3-tables/m-p/3613611#M870576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello ppl,&lt;/P&gt;&lt;P&gt;              I need a good and complete example of ALV, which follows good amount of standard conventions.&lt;/P&gt;&lt;P&gt;the details of fields and tables are as follows:-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;table: &lt;STRONG&gt;KNA1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;fields: KUNNR (&lt;EM&gt;Customer Number 1&lt;/EM&gt;)&lt;/P&gt;&lt;P&gt;         ORT01 (&lt;EM&gt;City&lt;/EM&gt;)&lt;/P&gt;&lt;P&gt;         PSTLZ (&lt;EM&gt;Postal Code&lt;/EM&gt;)&lt;/P&gt;&lt;P&gt;         REGIO (&lt;EM&gt;Region (State, Province, County&lt;/EM&gt;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; table:  &lt;STRONG&gt;KNB1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt; fields:BUKRS(&lt;EM&gt;Company Code&lt;/EM&gt;)&lt;/P&gt;&lt;P&gt;          ZTERM(&lt;EM&gt;Terms of payment key&lt;/EM&gt;)&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; table: &lt;STRONG&gt;KNVP&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt; fields:VKORG(&lt;EM&gt;Sales Organization&lt;/EM&gt;)&lt;/P&gt;&lt;P&gt;         VTWEG(&lt;EM&gt;Distribution Channel&lt;/EM&gt;)&lt;/P&gt;&lt;P&gt;         SPART(&lt;EM&gt;Division&lt;/EM&gt;)&lt;/P&gt;&lt;P&gt;         KUNN2(&lt;EM&gt;Customer number of business partner&lt;/EM&gt;)&lt;/P&gt;&lt;P&gt;         LIFNR(&lt;EM&gt;Account Number of Vendor or Creditor&lt;/EM&gt;)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Mar 2008 13:06:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/program-to-generate-alv-using-3-tables/m-p/3613611#M870576</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-17T13:06:20Z</dc:date>
    </item>
    <item>
      <title>Re: program to generate ALV (using 3 tables)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/program-to-generate-alv-using-3-tables/m-p/3613612#M870577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Go to this site [ALVrobot|http://www.alvrobot.com.ar/home.php] &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Mar 2008 13:25:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/program-to-generate-alv-using-3-tables/m-p/3613612#M870577</guid>
      <dc:creator>RaymondGiuseppi</dc:creator>
      <dc:date>2008-03-17T13:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: program to generate ALV (using 3 tables)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/program-to-generate-alv-using-3-tables/m-p/3613613#M870578</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Faisal&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a look at my sample reports &lt;STRONG&gt;ZUS_SDN_TWO_ALV_GRIDS&lt;/STRONG&gt; and &lt;STRONG&gt;ZUS_SDN_THREE_ALV_GRIDS&lt;/STRONG&gt; in threads:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN __jive_macro_name="thread" id="384685"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN __jive_macro_name="thread" id="286895"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;   Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Mar 2008 14:06:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/program-to-generate-alv-using-3-tables/m-p/3613613#M870578</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2008-03-17T14:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: program to generate ALV (using 3 tables)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/program-to-generate-alv-using-3-tables/m-p/3613614#M870579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi friend! You can take as a sample the standard program BCALV_GRID_01. Take a look on it's code, it'll surely help you!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
program bcalvc_print.
*&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;
* Purpose:
* ~~~~~~~~
* This program illustrates how the events for print processing
*   - PRINT_TOP_OF_PAGE
*   - PRINT_END_OF_PAGE
*   - PRINT_TOP_OF_LIST
*   - PRINT_END_OF_LIST
*
* are handled. The corresponding handler methods control the
* appearance of the list printed.
*-----------------------------------------------------------------
* To check program behavior
* ~~~~~~~~~~~~~~~~~~~~~~~~~
* Print the list shown (It has got only three pages).
* Remark: If you choose "Druckansicht" (preview?!) before printing,
*         the output for event PRINT_END_OF_PAGE is left out due
*         to scrolling.
*         Create a spool entry and preview your printout by calling
*         TA sp01 to reduce paper output please.
*-----------------------------------------------------------------
* Essential steps (Search for '§')
* ~~~~~~~~~~~~~~~
* 1. Define a (local) class for event handling
* 2. Define a method for each print event you need.
* 3. Implement your event handler methods. Use WRITE to provide output.
* 4. Link used print events and event handler methods.
* 5. In case of PRINT_END_OF_PAGE, you must set 'reservelns' to
*    the number of reserved lines at the end of a page.
*&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;

*********
* Predefine a local class for event handling to allow the
* declaration of a reference variable.
class lcl_event_receiver definition deferred.
*
*********


data: ok_code like sy-ucomm,
      g_max type i value 100,
      gt_sflight type table of sflight,
      g_repid like sy-repid,
      gs_print    type lvc_s_prnt,
      gs_layout   type lvc_s_layo,
      mycontainer type scrfname value 'BCALVC_EVENT1_CONT1',
* reference to custom container: neccessary to bind ALV Control
  custom_container type ref to cl_gui_custom_container,
      grid1  type ref to cl_gui_alv_grid,
      event_receiver type ref to lcl_event_receiver.


* § Step 1. Define a (local) class for event handling
****************************************************************
* LOCAL CLASSES: Definition
****************************************************************
*===============================================================
* class c_event_receiver: local class to handle print events...
*    - PRINT_TOP_OF_PAGE (page header)
*    - PRINT_END_OF_PAGE (page footer)
*    - PRINT_TOP_OF_LIST (list header)
*    - PRINT_END_OF_LIST (list footer)
*
* Definition:
* ~~~~~~~~~~~
class lcl_event_receiver definition.

  public section.
* § 2. Define a method for each print event you need.
    methods:
    handle_top_of_page
        for event print_top_of_page of cl_gui_alv_grid,

    handle_end_of_page
        for event print_end_of_page of cl_gui_alv_grid,

    handle_top_of_list
        for event print_top_of_list of cl_gui_alv_grid,

    handle_end_of_list
        for event print_end_of_list of cl_gui_alv_grid.

  private section.
    data: pagenum type i.

endclass.
*
* c_event_receiver (Definition)
*===============================================================


****************************************************************
* LOCAL CLASSES: Implementation
****************************************************************
*===============================================================
* class c_event_receiver (Implementation)
*
class lcl_event_receiver implementation.
*§ 3. Implement your event handler methods. Use WRITE to provide output.
  method handle_top_of_page.
    data: tablename(30) type c.
    perform get_tablename changing tablename.
    write: /,'Event: PRINT_TOP_OF_PAGE'(001),
             'Table: '(002),tablename.

  endmethod.                           "handle_top_of_page
*-------------------------------------------
  method handle_end_of_page.
    data: tablename(30) type c.

    perform get_tablename changing tablename.
    add 1 to pagenum.
    write: /,'Event: PRINT_END_OF_PAGE'(003),
             text-002,tablename,
             'Number of pages so far: '(004), pagenum.

  endmethod.                           "handle_end_of_page
*-------------------------------------------
  method handle_top_of_list.
    data: tablename(30) type c.
    clear pagenum.
    perform get_tablename changing tablename.
    write: /,'Event: PRINT_TOP_OF_LIST'(005),
             text-002,tablename.

  endmethod.                           "handle_top_of_list
*-------------------------------------------
  method handle_end_of_list.
    data: tablename(30) type c.
    perform get_tablename changing tablename.
    write: /,'Event: PRINT_END_OF_LIST'(006),
             text-002,tablename.

  endmethod.                           "handle_end_of_list
*-------------------------------------------
endclass.
*
* c_event_receiver (Implementation)
*===================================================================

start-of-selection.
  select * from sflight into table gt_sflight up to g_max rows.
*
end-of-selection.
  g_repid = sy-repid.
  call screen 100.

*---------------------------------------------------------------------*
*       MODULE PBO OUTPUT                                             *
*---------------------------------------------------------------------*
module pbo output.
  set pf-status 'MAIN100'.
  set titlebar 'MAIN100'.
  if custom_container is initial.
* create a custom container control for our ALV Control
    create object custom_container
        exporting
            container_name = mycontainer
        exceptions
            cntl_error = 1
            cntl_system_error = 2
            create_error = 3
            lifetime_error = 4
            lifetime_dynpro_dynpro_link = 5.
    if sy-subrc ne 0.
* add your handling, for example
      call function 'POPUP_TO_INFORM'
           exporting
                titel = g_repid
                txt2  = sy-subrc
                txt1  = 'The control could not be created'(010).
    endif.
* create an instance of alv control
    create object grid1
          exporting i_parent = custom_container.
*
* Set a titlebar for the grid control
*
    gs_layout-grid_title = 'Flights'(100).

* § 5. In case of PRINT_END_OF_PAGE, you must set 'reservelns' to
*      the number of reserved lines at the end of a page.
*
* reserve two lines for the PRINT_END_OF_PAGE event
*
    gs_print-reservelns = 2.


********
* -&amp;gt;Create Object to receive events and link them to handler methods.
* When the ALV Control raises the event for the specified instance
* the corresponding method is automatically called.
*

********

* § 4. Link used print events and event handler methods.
    create object event_receiver.
    set handler event_receiver-&amp;gt;handle_top_of_list for grid1.
    set handler event_receiver-&amp;gt;handle_top_of_page for grid1.
    set handler event_receiver-&amp;gt;handle_end_of_list for grid1.
    set handler event_receiver-&amp;gt;handle_end_of_page for grid1.
*
  call method grid1-&amp;gt;set_table_for_first_display
         exporting i_structure_name = 'SFLIGHT'
                   is_print         = gs_print
                   is_layout        = gs_layout
         changing  it_outtab        = gt_sflight.

  endif.
* Controls are not integrated into the TAB-Order
* Call "set_focus" if you want to make sure that 'the cursor'
* is active in your control.
  call method cl_gui_control=&amp;gt;set_focus exporting control = grid1.

* Control Framework flushes at the end of PBO automatically!
endmodule.
*---------------------------------------------------------------------*
*       MODULE PAI INPUT                                              *
*---------------------------------------------------------------------*
module pai input.
  case ok_code.
    when 'EXIT'.
      perform exit_program.
  endcase.
  clear ok_code.
endmodule.
*---------------------------------------------------------------------*
*       FORM EXIT_PROGRAM                                             *
*---------------------------------------------------------------------*
form exit_program.
  call method custom_container-&amp;gt;free.
  call method cl_gui_cfw=&amp;gt;flush.
  if sy-subrc ne 0.
* add your handling, for example
    call function 'POPUP_TO_INFORM'
         exporting
              titel = g_repid
              txt2  = sy-subrc
              txt1  = 'Error in Flush'(009).
  endif.
  leave program.
endform.
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  GET_TABLENAME
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      &amp;lt;--P_TABLENAME  text
*----------------------------------------------------------------------*
form get_tablename changing p_tablename.
  data: lt_fieldcat type standard table of lvc_s_fcat,
        ls_fieldcat type lvc_s_fcat.

  call method grid1-&amp;gt;get_frontend_fieldcatalog
                importing et_fieldcatalog = lt_fieldcat.


  call method cl_gui_cfw=&amp;gt;flush.
  if sy-subrc &amp;lt;&amp;gt; 0.
    p_tablename = 'No tablename in fieldcatalog!'(008).
    call function 'POPUP_TO_INFORM'
         exporting
              titel = g_repid
              txt2  = p_tablename
              txt1  = 'Error in Flush'(011).
  else.
    read table lt_fieldcat index 1 into ls_fieldcat.
    p_tablename = ls_fieldcat-ref_table.
  endif.

endform.                               " GET_TABLENAME
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Mar 2008 14:51:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/program-to-generate-alv-using-3-tables/m-p/3613614#M870579</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-17T14:51:29Z</dc:date>
    </item>
    <item>
      <title>Re: program to generate ALV (using 3 tables)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/program-to-generate-alv-using-3-tables/m-p/3613615#M870580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN __jive_emoticon_name="shocked"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Mar 2008 15:40:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/program-to-generate-alv-using-3-tables/m-p/3613615#M870580</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-17T15:40:57Z</dc:date>
    </item>
  </channel>
</rss>

