"Implicit" Binding in ABAP OO?: the ALV method grid- check_changed_data

In this thread here:
Where/how would you add the actual DB update to BCALV_EDIT_03?
Uwe Schieferstein was kind enough to show that anyone can see the effect or outcome of the ALV check_changed_data method if they just add this code to the PAI of the SAP demo program BCALV_EDIT_03:
MODULE pai INPUT.
  TRANSLATE ok_code TO UPPER CASE.
  save_ok = ok_code.
  CLEAR ok_code.
  CASE save_ok.
    WHEN 'EXIT'.
      PERFORM exit_program.
    WHEN 'SAVE'.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
        EXPORTING
          I_STRUCTURE_NAME                  = 'SFLIGHT'
          I_GRID_TITLE                      =
              'Before CHECK_DATA_CHANGED -> changes not yet retrieved'
        TABLES
          t_outtab                          = gt_outtab
        EXCEPTIONS
          OTHERS                            = 99.
      g_grid->check_changed_data( ).
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
        EXPORTING
          I_STRUCTURE_NAME                  = 'SFLIGHT'
          I_GRID_TITLE                      =
              'After CHECK_DATA_CHANGED -> changes retrieved'
        TABLES
          t_outtab                          = gt_outtab
        EXCEPTIONS
          OTHERS                            = 99.
      PERFORM save_data.
    WHEN OTHERS.
*     do nothing
  ENDCASE.
ENDMODULE.                    "pai INPUT
When looking at this code, the following question occurred to me:
<b>Question: How does check_changed_data know the itab to bring the changed back to, since it is called in the PAI with no arguments.</b>
The only answer I can see is that when the grid is first loaded in the PBO of BCALV_EDIT_03 in the usual way:
  if g_custom_container is initial.
    perform create_and_init_alv changing gt_outtab
                                         gt_fieldcat
                                         gs_layout.
  endif.
the ABAP OO engine implicitly "binds" the back-end table gt_outtab to the ALV contol (i.e. the instance of CL_GUI_ALV_GRID that the program creates.)
So, if you answer this question, please do one of two things:
a) confirm that check_changed_data "knows" the correct itab to bring the data back to because the ABAP OO engine has, in fact, implicitly "bound" the control to the itab gt_outtab;
or
b) if this is not true, explain how check_changed_data knows what itab to bring the data back to.
Thanks very much in advance for whatever time anyone can afford to spend on this question.
djh

Hello David
I have modified my previous sample report again to +demonstrate +that the
grid instance knows exactly which itab is displayed. Unfortunately it is already a few years ago when I attended the excellent SAP course BC412 (Dialog Programming using EnjoyControls, held by a chinese SAP employee with a beautiful Palatine dialect). Thus, I +cannot explain +the technical details (which are somehow related to the automation queue and the control framework). 
Here are the new modifications:
(1) Inbetween the data definitions and the local class definition I have added two parameters:
DATA: gt_outtab TYPE TABLE OF sflight.
PARAMETERS:
  p_byref    RADIOBUTTON GROUP rad1,  " pass itab by reference
  p_byval    RADIOBUTTON GROUP rad1.  " pass itab by value
* LOCAL CLASS Definition
(2) The parameters are evaluated in PBO module PBO:
*       MODULE PBO OUTPUT                                             *
MODULE pbo OUTPUT.
  SET PF-STATUS 'MAIN100'.
  SET TITLEBAR 'MAIN100'.
  IF g_custom_container IS INITIAL.
    IF ( p_byval = 'X' ).
      PERFORM create_and_init_alv_byval
                           CHANGING gt_outtab
                                    gt_fieldcat
                                    gs_layout.
    ELSE.  " ( p_byref = 'X' ).
      PERFORM create_and_init_alv CHANGING gt_outtab
                                           gt_fieldcat
                                           gs_layout.
    ENDIF.
  ENDIF.
ENDMODULE.                    "pbo OUTPUT
(3) And here is the difference between the two routines:
*&      Form  create_and_init_alv_byval
*       text
*      <--P_GT_OUTTAB  text
*      <--P_GT_FIELDCAT  text
*      <--P_GS_LAYOUT  text
FORM create_and_init_alv_byval
                  CHANGING
                        value(pt_outtab)  LIKE gt_outtab[]  " by value
                        pt_fieldcat TYPE lvc_t_fcat
                        ps_layout TYPE lvc_s_layo.
  PERFORM create_and_init_alv CHANGING pt_outtab
                                       pt_fieldcat
                                       ps_layout.
ENDFORM.                    " create_and_init_alv_byval
*&      Form  CREATE_AND_INIT_ALV
*       text
*      <--P_GT_OUTTAB  text
*      <--P_GT_FIELDCAT  text
*      <--P_GS_LAYOUT  text
FORM create_and_init_alv
                  CHANGING
                        pt_outtab  LIKE gt_outtab[]  " by reference
                        pt_fieldcat TYPE lvc_t_fcat
                        ps_layout TYPE lvc_s_layo.
  DATA: lt_exclude TYPE ui_functions.
Now the crucial point is that the globally visible itab gt_outtab is passed
(a) by value to method g_grid->set_table_for_first_display (routine CREATE_AND_INIT_ALV_BYVAL)
(b) by reference to method g_grid->set_table_for_first_display (routine CREATE_AND_INIT_ALV_BYVAL)
If you run the report with the default (p_byref = 'X') then the report behave exactly like the original sample report.
However, if you choose p_byval = 'X' then the reports dumps as soon as you try to change the values of the ALV list (e.g. change a planetype and hit ENTER or even sorting is sufficient).
Why? The itab passed by value to the grid instance is not the same like gt_outtab!
Conclusion: Do not try to fool the grid instance...
Regards
  Uwe
PS: The entire coding of the adjusted sample reports is shown below:
report ZUS_SDN_BCALV_EDIT_03_SAVE_1.
**PROGRAM bcalv_edit_03.
* Purpose:
* ~~~~~~~~
* In this example the user may change values of fields
* SEATSOCC (occupied seats) and/or PLANETYPE. The report checks
* the input value(s) semantically and provides protocol
* messages in case of error.
* To check program behavior
* ~~~~~~~~~~~~~~~~~~~~~~~~~
* Change values of the column "occupied seats" or "Planetype" or
* both (in the same line). Try to provocate errors.
* Click on the check symbol or press return to initiate checking.
* (ALV also checks input before any functions like sorting,
* filtering or doubleclick are processed. These functions are
* only active if the input does not contain any errors).
* The ALV Grid Control first checks if the input is correct
* according to DDIC-Information (Type, lenght). Then semantic
* checks are made by the application using event handler method
* HANDLE_DATA_CHANGED.
* Essential steps (search for '§')
* ~~~~~~~~~~~~~~~
* 1.Set status of columns PLANETYPE and SEATSOCC to editable.
* 2.Optionally restrict generic functions to 'change only'.
*   (The user shall not be able to add new lines).
* 3.Optionally register ENTER to raise event DATA_CHANGED.
*   (Per default the user may check data by using the check icon).
* 4.Define and implement event handler to handle event DATA_CHANGED.
* 5.Loop over table MT_GOOD_CELLS to check all values that are
*   valid due to checks according to information of the DDIC.
* 6.Within a check cycle:
* 6a.Get new cell value to check it using method GET_CELL_VALUE.
*    (In this case SEATSOCC).
* 6b.If the value is valid you may want to change values of
*    other cells.
* 6c.If the value is not valid create an protocol entry in
*    the application log.
* 6d.To access old values (which where not changed in this check cycle)
*    use your output table GT_OUTTAB.
* 7.Display application log if an error has occured.
DATA: ok_code LIKE sy-ucomm,
      save_ok LIKE sy-ucomm,
      g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',
      g_grid  TYPE REF TO cl_gui_alv_grid,
      g_custom_container TYPE REF TO cl_gui_custom_container,
      gt_fieldcat TYPE lvc_t_fcat,
      gs_layout TYPE lvc_s_layo,
      g_max TYPE i VALUE 100.
* local class to handle semantic checks
CLASS lcl_event_receiver DEFINITION DEFERRED.
DATA: g_event_receiver TYPE REF TO lcl_event_receiver.
DATA: gt_outtab TYPE TABLE OF sflight.
PARAMETERS:
  p_byref    RADIOBUTTON GROUP rad1,  " pass itab by reference
  p_byval    RADIOBUTTON GROUP rad1.  " pass itab by value
* LOCAL CLASS Definition
*§4.Define and implement event handler to handle event DATA_CHANGED.
CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.
* This flag is set if any error occured in one of the
* following methods:
    DATA: error_in_data TYPE c  READ-ONLY.
    METHODS:
      handle_data_changed
         FOR EVENT data_changed OF cl_gui_alv_grid
             IMPORTING er_data_changed.
  PRIVATE SECTION.
*** This flag is set if any error occured in one of the
*** following methods:
**    DATA: error_in_data TYPE c.
* Methods to modularize event handler method HANDLE_DATA_CHANGED:
    METHODS: check_planetype
     IMPORTING
        ps_good_planetype TYPE lvc_s_modi
        pr_data_changed TYPE REF TO cl_alv_changed_data_protocol.
    METHODS: ch_new_plane_v_new_seatsocc
           IMPORTING
              psg_plane TYPE lvc_s_modi
              psg_socc TYPE lvc_s_modi
              ps_saplane TYPE saplane
              pr_data_changed TYPE REF TO cl_alv_changed_data_protocol.
    METHODS: ch_new_plane_v_old_seatsocc
           IMPORTING
              psg_plane TYPE lvc_s_modi
              ps_saplane TYPE saplane
              pr_data_changed TYPE REF TO cl_alv_changed_data_protocol.
    METHODS: check_seatsocc
           IMPORTING
              ps_good TYPE lvc_s_modi
              pr_data_changed TYPE REF TO cl_alv_changed_data_protocol.
* This is a suggestion how you could comment your checks in each method:
* CHECK: fieldname(old/new value) !<comp> fieldname(old/new value)
* IF NOT: (What to tell the user is wrong about the input)
* Remarks:
*  fieldname:       fieldname of table for the corresponding column
*  (old/new value): ckeck with value of GT_OUTTAB or MT_GOOD_CELLS.
*  !<comp>        : the value is valid if the condition <comp> holds.
* Example:
*  CHECK seatsocc(new) !>= seatsmax(old)
*  IF NOT: There are not enough number of seats according to this
*          planetype.
ENDCLASS.                    "lcl_event_receiver DEFINITION
CLASS lcl_event_receiver IMPLEMENTATION.
  METHOD handle_data_changed.
    DATA: ls_good TYPE lvc_s_modi.
    error_in_data = space.
* semantic checks
* Identify columns which were changed and check input
* against output table gt_outtab or other new input values of one row.
* Table er_data_changed->mt_good_cells holds all cells that
* are valid according to checks against their DDIC data.
* No matter in which order the input was made this table is
* ordered by rows (row_id). For each row, the entries are
* sorted by columns according to their order in the fieldcatalog
* (not the defined order using field COL_POS but the order
* given by the position of the record in the fieldcatalog).
* The order is relevant if new inputs in several columns of
* the same row are dependent. In this example,
* method 'ch_new_plane_v_new_seatsocc' needs only to be called
* once since we know that the corresponding check is already done
* when checking column PLANETYPE (see also method 'check_seatsocc').
*§5.Loop over table MT_GOOD_CELLS to check all values that are
*   valid due to checks according to information of the DDIC.
    LOOP AT er_data_changed->mt_good_cells INTO ls_good.
      CASE ls_good-fieldname.
* check if column PLANETYPE of this row was changed
        WHEN 'PLANETYPE'.
          CALL METHOD check_planetype
            EXPORTING
              ps_good_planetype = ls_good
              pr_data_changed   = er_data_changed.
* check if column SEATSOCC of this row was changed
        WHEN 'SEATSOCC'.
          CALL METHOD check_seatsocc
            EXPORTING
              ps_good         = ls_good
              pr_data_changed = er_data_changed.
      ENDCASE.
    ENDLOOP.
*§7.Display application log if an error has occured.
    IF error_in_data EQ 'X'.
      CALL METHOD er_data_changed->display_protocol.
    ENDIF.
  ENDMETHOD.                    "handle_data_changed
  METHOD check_planetype.
* Overview of checks according to field PLANETYPE
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* a) Does the Planetype exists? (check against check table SAPLANE)
* b) Are the number of seats (SEATSMAX) of the new planetype
*    sufficient to fullfill requested bookings (SEATSOCC)?
*    b1) SEATSOCC (occupied seats) also changed within
*        this check cycle.
*    b2) SEATSOCC has not changed within this cycle.
    DATA: l_planetype TYPE s_planetye,
          ls_saplane TYPE saplane,
          ls_good_seatsocc TYPE lvc_s_modi.
* Get new cell value to check it.
* (In this case: PLANETYPE).
    CALL METHOD pr_data_changed->get_cell_value
      EXPORTING
        i_row_id    = ps_good_planetype-row_id
        i_fieldname = ps_good_planetype-fieldname
      IMPORTING
        e_value     = l_planetype.
* existence check: Does the plane exists?
    SELECT SINGLE * FROM saplane INTO ls_saplane WHERE
                                     planetype = l_planetype.
    IF sy-subrc NE 0.
* In case of error, create a protocol entry in the application log.
* Possible values for message type ('i_msgty'):
*    'A': Abort (Stop sign)
*    'E': Error (red LED)
*    'W': Warning (yellow LED)
*    'I': Information (green LED)
      CALL METHOD pr_data_changed->add_protocol_entry
        EXPORTING
          i_msgid     = '0K'
          i_msgno     = '000'
          i_msgty     = 'E'
          i_msgv1     = text-m03           "Flugzeugtyp
          i_msgv2     = l_planetype
          i_msgv3     = text-m05           "exitstiert nicht
          i_fieldname = ps_good_planetype-fieldname
          i_row_id    = ps_good_planetype-row_id.
      error_in_data = 'X'.
      EXIT. "plane does not exit, so we're finished here!
    ENDIF.
* Check if other relevant fields of this row have been changed, too.
    READ TABLE pr_data_changed->mt_good_cells INTO ls_good_seatsocc
                       WITH KEY row_id    = ps_good_planetype-row_id
                                fieldname = 'SEATSOCC'.
    IF sy-subrc = 0.
      CALL METHOD ch_new_plane_v_new_seatsocc
        EXPORTING
          psg_plane       = ps_good_planetype
          psg_socc        = ls_good_seatsocc
          ps_saplane      = ls_saplane
          pr_data_changed = pr_data_changed.
    ELSE.
      CALL METHOD ch_new_plane_v_old_seatsocc
        EXPORTING
          psg_plane       = ps_good_planetype
          ps_saplane      = ls_saplane
          pr_data_changed = pr_data_changed.
    ENDIF.
  ENDMETHOD.                           " CHECK_PLANETYPE
  METHOD ch_new_plane_v_new_seatsocc.
    DATA: l_seatsocc TYPE s_seatsocc.
*§5a.Get new cell value to check it using method GET_CELL_VALUE.
* (In this case SEATSOCC).
    CALL METHOD pr_data_changed->get_cell_value
      EXPORTING
        i_row_id    = psg_socc-row_id
        i_fieldname = psg_socc-fieldname
      IMPORTING
        e_value     = l_seatsocc.
* CHECK:  SEATSMAX(of new planetype) !>= SEATSOCC(new value)
* IF NOT: Message for wrong planetype
    IF ps_saplane-seatsmax GE l_seatsocc.
*§5b.If the value is valid you may want to change values of
*    other cells.
      CALL METHOD pr_data_changed->modify_cell
        EXPORTING
          i_row_id    = psg_plane-row_id
          i_fieldname = 'SEATSMAX'
          i_value     = ps_saplane-seatsmax.
    ELSE.
*§5c.If the value is not valid create an protocol entry in
*    the application log.
* Possible values for message type ('i_msgty'):
*    'A': Abort (Stop sign)
*    'E': Error (red LED)
*    'W': Warning (yellow LED)
*    'I': Information (green LED)
      CALL METHOD pr_data_changed->add_protocol_entry
        EXPORTING
          i_msgid     = '0K'
          i_msgno     = '000'
          i_msgty     = 'E'
          i_msgv1     = text-m03               "Flugzeugtyp
          i_msgv2     = ps_saplane-planetype
          i_msgv3     = text-m04             "hat nicht genug Sitzplätze
          i_fieldname = psg_plane-fieldname
          i_row_id    = psg_plane-row_id.
      error_in_data = 'X'.
    ENDIF.
  ENDMETHOD.                    "ch_new_plane_v_new_seatsocc
  METHOD ch_new_plane_v_old_seatsocc.
    DATA: l_old_seatsocc TYPE s_seatsocc,
          ls_outtab TYPE sflight.
*§5d.To access old values (which where not changed in this check cycle)
*    use your output table GT_OUTTAB.
    READ TABLE gt_outtab INTO ls_outtab INDEX psg_plane-row_id.
    l_old_seatsocc = ls_outtab-seatsocc.
* CHECK:  SEATSMAX(of new planetype) !>= SEATSOCC(old value)
* IF NOT: Message for wrong planetype
    IF ps_saplane-seatsmax GE l_old_seatsocc.
* ok->field seatsmax can be changed
      CALL METHOD pr_data_changed->modify_cell
        EXPORTING
          i_row_id    = psg_plane-row_id
          i_fieldname = 'SEATSMAX'
          i_value     = ps_saplane-seatsmax.
    ELSE.
      CALL METHOD pr_data_changed->add_protocol_entry
        EXPORTING
          i_msgid     = '0K'
          i_msgno     = '000'
          i_msgty     = 'E'
          i_msgv1     = text-m03                "Flugzeugtyp
          i_msgv2     = ps_saplane-planetype
          i_msgv3     = text-m04             "hat nicht genug Sitzplätze
          i_fieldname = psg_plane-fieldname
          i_row_id    = psg_plane-row_id.
      error_in_data = 'X'.
    ENDIF.
  ENDMETHOD.                    "ch_new_plane_v_old_seatsocc
*&      Form  CHECK_SEATSOCC
*       text
*      -->P_LS_GOOD  text
*      -->P_ER_DATA_CHANGED  text
  METHOD check_seatsocc.
    DATA: l_seatsocc TYPE s_seatsocc,
          l_old_seatsmax TYPE s_seatsmax,
          ls_outtab TYPE sflight,
          ls_good TYPE lvc_s_modi.
* Check if the planetype has changed, too.
    READ TABLE pr_data_changed->mt_good_cells INTO ls_good
                       WITH KEY row_id    = ps_good-row_id
                                fieldname = 'PLANETYPE'.
    IF sy-subrc EQ 0.
* remark: the check
*   seatsocc (new value) <= seatsmax (new value)
* was already handled by form 'ch_new_plane_v_new_seatsocc'.
* so we are finished here.
      EXIT.
    ENDIF.
* CHECK: seatsocc (new value) <= seatsmax (old value)
* IF NOT: Message that SEATSOCC is to high.
* get new cell value of SEATSOCC.
    CALL METHOD pr_data_changed->get_cell_value
      EXPORTING
        i_row_id    = ps_good-row_id
        i_fieldname = ps_good-fieldname
      IMPORTING
        e_value     = l_seatsocc.
* get old cell value of SEATSMAX
    READ TABLE gt_outtab INTO ls_outtab INDEX ps_good-row_id.
    l_old_seatsmax = ls_outtab-seatsmax.
    IF l_seatsocc > l_old_seatsmax.
      CALL METHOD pr_data_changed->add_protocol_entry
        EXPORTING
          i_msgid     = '0K'
          i_msgno     = '000'
          i_msgty     = 'E'
          i_msgv1     = text-m01  "Die Anzahl der belegten Plätze
          i_msgv2     = text-m02 "übersteigt die Kapazität des Flugzeugs
          i_msgv3     = ls_outtab-planetype
          i_fieldname = ps_good-fieldname
          i_row_id    = ps_good-row_id.
      error_in_data = 'X'.
    ENDIF.
  ENDMETHOD.                           " CHECK_SEATSOCC
ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION
*       MAIN                                                          *
END-OF-SELECTION.
  CALL SCREEN 100.
*       MODULE PBO OUTPUT                                             *
MODULE pbo OUTPUT.
  SET PF-STATUS 'MAIN100'.
  SET TITLEBAR 'MAIN100'.
  IF g_custom_container IS INITIAL.
    IF ( p_byval = 'X' ).
      PERFORM create_and_init_alv_byval
                           CHANGING gt_outtab
                                    gt_fieldcat
                                    gs_layout.
    ELSE.  " ( p_byref = 'X' ).
      PERFORM create_and_init_alv CHANGING gt_outtab
                                           gt_fieldcat
                                           gs_layout.
    ENDIF.
  ENDIF.
ENDMODULE.                    "pbo OUTPUT
*       MODULE PAI INPUT                                              *
MODULE pai INPUT.
  TRANSLATE ok_code TO UPPER CASE.
  save_ok = ok_code.
  CLEAR ok_code.
  CASE save_ok.
    WHEN 'EXIT'.
      PERFORM exit_program.
    WHEN 'SAVE'.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
        EXPORTING
          i_structure_name                  = 'SFLIGHT'
          i_grid_title                      =
              'Before CHECK_DATA_CHANGED -> changes not yet retrieved'
        TABLES
          t_outtab                          = gt_outtab
        EXCEPTIONS
          OTHERS                            = 99.
      g_grid->check_changed_data( ).
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
        EXPORTING
          i_structure_name                  = 'SFLIGHT'
          i_grid_title                      =
              'After CHECK_DATA_CHANGED -> changes retrieved'
        TABLES
          t_outtab                          = gt_outtab
        EXCEPTIONS
          OTHERS                            = 99.
      PERFORM save_data.
    WHEN OTHERS.
*     do nothing
  ENDCASE.
ENDMODULE.                    "pai INPUT
*&      Form  SAVE_DATA
*       text
*  -->  p1        text
*  <--  p2        text
FORM save_data .
  IF ( g_event_receiver->error_in_data = 'X' ).
    MESSAGE 'Error in data -> saving not possible' TYPE 'S'.
  ELSE.
    MESSAGE 'Data saved' TYPE 'S'.  " simulates DB update
  ENDIF.
ENDFORM.                    " SAVE_DATA
*       FORM EXIT_PROGRAM                                             *
FORM exit_program.
  LEAVE PROGRAM.
ENDFORM.                    "exit_program
*&      Form  BUILD_FIELDCAT
*       text
*      <--P_GT_FIELDCAT  text
FORM build_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.
  DATA ls_fcat TYPE lvc_s_fcat.
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name = 'SFLIGHT'
    CHANGING
      ct_fieldcat      = pt_fieldcat.
  LOOP AT pt_fieldcat INTO ls_fcat.
    IF    ls_fcat-fieldname EQ 'PLANETYPE'
       OR ls_fcat-fieldname EQ 'SEATSOCC'.
*§1.Set status of columns PLANETYPE and SEATSOCC to editable.
      ls_fcat-edit = 'X'.
* Field 'checktable' is set to avoid shortdumps that are caused
* by inconsistend data in check tables. You may comment this out
* when the test data of the flight model is consistent in your system.
      ls_fcat-checktable = '!'.  "do not check foreign keys
      MODIFY pt_fieldcat FROM ls_fcat.
    ENDIF.
  ENDLOOP.
ENDFORM.                    "build_fieldcat
*&      Form  create_and_init_alv_byval
*       text
*      <--P_GT_OUTTAB  text
*      <--P_GT_FIELDCAT  text
*      <--P_GS_LAYOUT  text
FORM create_and_init_alv_byval
                  CHANGING
                        value(pt_outtab)  LIKE gt_outtab[]  " by value
                        pt_fieldcat TYPE lvc_t_fcat
                        ps_layout TYPE lvc_s_layo.
  PERFORM create_and_init_alv CHANGING pt_outtab
                                       pt_fieldcat
                                       ps_layout.
ENDFORM.                    " create_and_init_alv_byval
*&      Form  CREATE_AND_INIT_ALV
*       text
*      <--P_GT_OUTTAB  text
*      <--P_GT_FIELDCAT  text
*      <--P_GS_LAYOUT  text
FORM create_and_init_alv
                  CHANGING
                        pt_outtab  LIKE gt_outtab[]  " by reference
                        pt_fieldcat TYPE lvc_t_fcat
                        ps_layout TYPE lvc_s_layo.
  DATA: lt_exclude TYPE ui_functions.
  CREATE OBJECT g_custom_container
         EXPORTING container_name = g_container.
  CREATE OBJECT g_grid
         EXPORTING i_parent = g_custom_container.
* Build fieldcat and set columns PLANETYPE and SEATSOCC
* edit enabled.
  PERFORM build_fieldcat CHANGING pt_fieldcat.
*§2.Optionally restrict generic functions to 'change only'.
*   (The user shall not be able to add new lines).
  PERFORM exclude_tb_functions CHANGING lt_exclude.
  SELECT * FROM sflight INTO TABLE pt_outtab UP TO g_max ROWS.
  CALL METHOD g_grid->set_table_for_first_display
    EXPORTING
      is_layout            = ps_layout
      it_toolbar_excluding = lt_exclude
    CHANGING
      it_fieldcatalog      = pt_fieldcat
      it_outtab            = pt_outtab.
* set editable cells to ready for input
  CALL METHOD g_grid->set_ready_for_input
    EXPORTING
      i_ready_for_input = 1.
*§3.Optionally register ENTER to raise event DATA_CHANGED.
*   (Per default the user may check data by using the check icon).
  CALL METHOD g_grid->register_edit_event
    EXPORTING
      i_event_id = cl_gui_alv_grid=>mc_evt_enter.
  CREATE OBJECT g_event_receiver.
  SET HANDLER g_event_receiver->handle_data_changed FOR g_grid.
ENDFORM.                               "CREATE_AND_INIT_ALV
*&      Form  EXCLUDE_TB_FUNCTIONS
*       text
*      <--P_LT_EXCLUDE  text
FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions.
* Only allow to change data not to create new entries (exclude
* generic functions).
  DATA ls_exclude TYPE ui_func.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
  APPEND ls_exclude TO pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
  APPEND ls_exclude TO pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
  APPEND ls_exclude TO pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
  APPEND ls_exclude TO pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
  APPEND ls_exclude TO pt_exclude.
ENDFORM.                               " EXCLUDE_TB_FUNCTIONS

Similar Messages

  • How can i get the additional text fields in the ALV methods

    Hi all,
    I have 2 different layouts in the same screen, here i am using the 2 custom containers,for each container having the method called SET_TABLE_FOR_FIRST_DISPLAY, in this i have used the Title through the gridtitle field, now i need to display some more texts under the title OR in the top of the layouts.
    Please suggest me.
    Thanks
    Giridhar

    Hi,
    check this code, here i developed using splitter container, and implemented top of page event. check it. and i documented it also.
    REPORT  ZTEST1234_ALV_TOP    MESSAGE-ID ZZ                           .
    DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID.
    DATA: L_VALID TYPE C,
          V_FLAG,
          V_DATA_CHANGE,
          V_ROW TYPE LVC_S_ROW,
          V_COLUMN TYPE LVC_S_COL,
          V_ROW_NUM TYPE LVC_S_ROID.
    DATA: IT_ROW_NO TYPE LVC_T_ROID,
          X_ROW_NO TYPE LVC_S_ROID.
    DATA:BEGIN OF  ITAB OCCURS 0,
         VBELN LIKE LIKP-VBELN,
         POSNR LIKE LIPS-POSNR,
         CELLCOLOR TYPE LVC_T_SCOL, "required for color
         DROP(10),
         END OF ITAB.
    "The Below Definitions Must.....
    DATA:
    * Reference to document
           DG_DYNDOC_ID       TYPE REF TO CL_DD_DOCUMENT,
    * Reference to split container
           DG_SPLITTER          TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
    * Reference to grid container
           DG_PARENT_GRID     TYPE REF TO CL_GUI_CONTAINER,
    * Reference to html container
           DG_HTML_CNTRL        TYPE REF TO CL_GUI_HTML_VIEWER,
    * Reference to html container
           DG_PARENT_HTML     TYPE REF TO CL_GUI_CONTAINER.
    "up to here
    *       CLASS lcl_event_handler DEFINITION
    CLASS LCL_EVENT_HANDLER DEFINITION .
      PUBLIC SECTION .
        METHODS:
    **Hot spot Handler
        HANDLE_HOTSPOT_CLICK FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
                          IMPORTING E_ROW_ID E_COLUMN_ID ES_ROW_NO,
    **Double Click Handler
        HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
                                         IMPORTING E_ROW E_COLUMN ES_ROW_NO,
        TOP_OF_PAGE FOR EVENT TOP_OF_PAGE              "event handler
                             OF CL_GUI_ALV_GRID
                             IMPORTING E_DYNDOC_ID.
    *        END_OF_LIST FOR EVENT end_of_list              "event handler
    *                         OF CL_GUI_ALV_GRID
    *                         IMPORTING E_DYNDOC_ID.
    ENDCLASS.                    "lcl_event_handler DEFINITION
    *       CLASS lcl_event_handler IMPLEMENTATION
    CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
    *Handle Hotspot Click
      METHOD HANDLE_HOTSPOT_CLICK .
        CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.
        V_ROW  = E_ROW_ID.
        V_COLUMN = E_COLUMN_ID.
        V_ROW_NUM = ES_ROW_NO.
    *    MESSAGE I000 WITH V_ROW 'clicked'.
        CLEAR IT_ROW_NO[].
        X_ROW_NO-ROW_ID = V_ROW.
        APPEND X_ROW_NO TO IT_ROW_NO .
        CALL METHOD G_GRID->SET_SELECTED_ROWS
          EXPORTING
            IT_ROW_NO = IT_ROW_NO.
      ENDMETHOD.                    "lcl_event_handler
    *Handle Double Click
      METHOD  HANDLE_DOUBLE_CLICK.
        CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.
        V_ROW  = E_ROW.
        V_COLUMN = E_COLUMN.
        V_ROW_NUM = ES_ROW_NO.
        IF E_COLUMN = 'VBELN'.
          SET PARAMETER ID 'VL' FIELD ITAB-VBELN.
          CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.
        ENDIF.
        IF E_COLUMN = 'POSNR'.
          SET PARAMETER ID 'VL' FIELD ITAB-VBELN.
          CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN."
        ENDIF.
      ENDMETHOD.                    "handle_double_click
    *  METHOD END_OF_LIST.                   "implementation
    ** Top-of-page event
    *    PERFORM EVENT_TOP_OF_PAGE USING DG_DYNDOC_ID.
    *  ENDMETHOD.                            "top_of_page
        METHOD TOP_OF_PAGE.                   "implementation
    * Top-of-page event
        PERFORM EVENT_TOP_OF_PAGE USING DG_DYNDOC_ID.
      ENDMETHOD.                            "top_of_page
    ENDCLASS.                    "LCL_EVENT_HANDLER IMPLEMENTATION
    *&             Global Definitions
    DATA:      G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,"Container1
                G_HANDLER TYPE REF TO LCL_EVENT_HANDLER. "handler
    DATA: OK_CODE LIKE SY-UCOMM,
          SAVE_OK LIKE SY-UCOMM,
          G_CONTAINER1 TYPE SCRFNAME VALUE 'TEST',
          GS_LAYOUT TYPE LVC_S_LAYO.
    data: v_lines type i.
    data: v_line(3) type c.
    *- Fieldcatalog for First and second Report
    DATA: IT_FIELDCAT  TYPE  LVC_T_FCAT,
          X_FIELDCAT TYPE LVC_S_FCAT,
          LS_VARI  TYPE DISVARIANT.
    *                START-OF_SELECTION
    START-OF-SELECTION.
      SELECT VBELN
             POSNR
             FROM LIPS
             UP TO 20 ROWS
             INTO CORRESPONDING FIELDS OF TABLE ITAB.
    describe table itab lines v_lines.
    END-OF-SELECTION.
      IF NOT ITAB[] IS INITIAL.
        CALL SCREEN 100.
      ELSE.
        MESSAGE I002 WITH 'NO DATA FOR THE SELECTION'(004).
      ENDIF.
    *&      Form  CREATE_AND_INIT_ALV
    *       text
    FORM CREATE_AND_INIT_ALV .
      DATA: LT_EXCLUDE TYPE UI_FUNCTIONS.
      "attention.....from here
      "split your container here...into two parts
      "create the container
      CREATE OBJECT G_CUSTOM_CONTAINER
               EXPORTING CONTAINER_NAME = G_CONTAINER1.
      "this is for top of page
    * Create TOP-Document
      CREATE OBJECT DG_DYNDOC_ID
                       EXPORTING STYLE = 'ALV_GRID'.
    * Create Splitter for custom_container
      CREATE OBJECT DG_SPLITTER
                 EXPORTING PARENT  = G_CUSTOM_CONTAINER
                           ROWS    = 2
                           COLUMNS = 1.
    * Split the custom_container to two containers and move the reference
    * to receiving containers g_parent_html and g_parent_grid
      "i am allocating the space for grid and top of page
      CALL METHOD DG_SPLITTER->GET_CONTAINER
        EXPORTING
          ROW       = 1
          COLUMN    = 1
        RECEIVING
          CONTAINER = DG_PARENT_HTML.
      CALL METHOD DG_SPLITTER->GET_CONTAINER
        EXPORTING
          ROW       = 2
          COLUMN    = 1
        RECEIVING
          CONTAINER = DG_PARENT_GRID.
    *  CALL METHOD DG_SPLITTER->GET_CONTAINER
    *    EXPORTING
    *      ROW       = 2
    *      COLUMN    = 1
    *    RECEIVING
    *      CONTAINER = DG_PARENT_HTML.
    *  CALL METHOD DG_SPLITTER->GET_CONTAINER
    *    EXPORTING
    *      ROW       = 1
    *      COLUMN    = 1
    *    RECEIVING
    *      CONTAINER = DG_PARENT_GRID.
      "you can set the height of it
    * Set height for g_parent_html
      CALL METHOD DG_SPLITTER->SET_ROW_HEIGHT
        EXPORTING
          ID     = 1
          HEIGHT = 5.
      "from here as usual..you need to specify parent as splitter part
      "which we alloted for grid
      CREATE OBJECT G_GRID
             EXPORTING I_PARENT = DG_PARENT_GRID.
    * Set a titlebar for the grid control
      CLEAR GS_LAYOUT.
      GS_LAYOUT-GRID_TITLE = TEXT-003.
      GS_LAYOUT-ZEBRA = SPACE.
      GS_LAYOUT-CWIDTH_OPT = 'X'.
      GS_LAYOUT-NO_ROWMARK = 'X'.
      GS_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.
      CALL METHOD G_GRID->REGISTER_EDIT_EVENT
        EXPORTING
          I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER.
      CREATE OBJECT G_HANDLER.
      SET HANDLER G_HANDLER->HANDLE_DOUBLE_CLICK FOR G_GRID.
      SET HANDLER G_HANDLER->HANDLE_HOTSPOT_CLICK FOR G_GRID.
    *  SET HANDLER G_HANDLER->END_OF_LIST FOR G_GRID.
      SET HANDLER G_HANDLER->TOP_OF_PAGE FOR G_GRID.
      DATA: LS_CELLCOLOR TYPE LVC_S_SCOL. "required for color
      DATA: L_INDEX TYPE SY-TABIX.
      "Here i am changing the color of line 1,5,10...
      "so you can change the color of font conditionally
      LOOP AT ITAB.
        L_INDEX = SY-TABIX.
        IF L_INDEX = 1 OR L_INDEX = 5 OR L_INDEX = 10.
          LS_CELLCOLOR-FNAME = 'VBELN'.
          LS_CELLCOLOR-COLOR-COL = '6'.
          LS_CELLCOLOR-COLOR-INT = '0'.
          LS_CELLCOLOR-COLOR-INV = '1'.
          APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.
          MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.
          LS_CELLCOLOR-FNAME = 'POSNR'.
          LS_CELLCOLOR-COLOR-COL = '6'.
          LS_CELLCOLOR-COLOR-INT = '0'.
          LS_CELLCOLOR-COLOR-INV = '1'.
          APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.
          MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.
        ENDIF.
      ENDLOOP.
    * setting focus for created grid control
      CALL METHOD CL_GUI_CONTROL=>SET_FOCUS
        EXPORTING
          CONTROL = G_GRID.
    * Build fieldcat and set editable for date and reason code
    * edit enabled. Assign a handle for the dropdown listbox.
      PERFORM BUILD_FIELDCAT.
      PERFORM  SET_DRDN_TABLE.
    * Optionally restrict generic functions to 'change only'.
    *   (The user shall not be able to add new lines).
      PERFORM EXCLUDE_TB_FUNCTIONS CHANGING LT_EXCLUDE.
    **Vaiant to save the layout
      LS_VARI-REPORT      = SY-REPID.
      LS_VARI-HANDLE      = SPACE.
      LS_VARI-LOG_GROUP   = SPACE.
      LS_VARI-USERNAME    = SPACE.
      LS_VARI-VARIANT     = SPACE.
      LS_VARI-TEXT        = SPACE.
      LS_VARI-DEPENDVARS  = SPACE.
    **Calling the Method for ALV output
      CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY
        EXPORTING
          IT_TOOLBAR_EXCLUDING = LT_EXCLUDE
          IS_VARIANT           = LS_VARI
          IS_LAYOUT            = GS_LAYOUT
          I_SAVE               = 'A'
        CHANGING
          IT_FIELDCATALOG      = IT_FIELDCAT
          IT_OUTTAB            = ITAB[].
      "do these..{
    * Initializing document
      CALL METHOD DG_DYNDOC_ID->INITIALIZE_DOCUMENT.
    * Processing events
      CALL METHOD G_GRID->LIST_PROCESSING_EVENTS
        EXPORTING
          I_EVENT_NAME = 'TOP_OF_PAGE'
          I_DYNDOC_ID  = DG_DYNDOC_ID.
      "end }
    * Set editable cells to ready for input initially
      CALL METHOD G_GRID->SET_READY_FOR_INPUT
        EXPORTING
          I_READY_FOR_INPUT = 1.
    ENDFORM.                               "CREATE_AND_INIT_ALV
    *&      Form  EXCLUDE_TB_FUNCTIONS
    *       text
    *      -->PT_EXCLUDE text
    FORM EXCLUDE_TB_FUNCTIONS CHANGING PT_EXCLUDE TYPE UI_FUNCTIONS.
    * Only allow to change data not to create new entries (exclude
    * generic functions).
      DATA LS_EXCLUDE TYPE UI_FUNC.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_CUT.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_UNDO.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
    ENDFORM.                               " EXCLUDE_TB_FUNCTIONS
    *&      Form  build_fieldcat
    *       Fieldcatalog
    FORM BUILD_FIELDCAT .
      DATA: L_POS TYPE I.
      L_POS = L_POS + 1.
      X_FIELDCAT-SCRTEXT_M = 'Delivery'(024).
      X_FIELDCAT-FIELDNAME = 'VBELN'.
      X_FIELDCAT-TABNAME = 'IT_FINAL'.
      X_FIELDCAT-COL_POS    = L_POS.
      X_FIELDCAT-NO_ZERO    = 'X'.
      X_FIELDCAT-OUTPUTLEN = '10'.
      X_FIELDCAT-HOTSPOT = 'X'.
      APPEND X_FIELDCAT TO IT_FIELDCAT.
      CLEAR X_FIELDCAT.
      L_POS = L_POS + 1.
      X_FIELDCAT-SCRTEXT_M = 'Item'(025).
      X_FIELDCAT-FIELDNAME = 'POSNR'.
      X_FIELDCAT-TABNAME = 'IT_FINAL'.
      X_FIELDCAT-COL_POS    = L_POS.
      X_FIELDCAT-OUTPUTLEN = '5'.
      APPEND X_FIELDCAT TO IT_FIELDCAT.
      CLEAR X_FIELDCAT.
      L_POS = L_POS + 1.
      X_FIELDCAT-SCRTEXT_M = 'Drop'(025).
      X_FIELDCAT-FIELDNAME = 'DROP'.
      X_FIELDCAT-TABNAME = 'IT_FINAL'.
      X_FIELDCAT-COL_POS    = L_POS.
      X_FIELDCAT-OUTPUTLEN = '5'.
      X_FIELDCAT-EDIT = 'X'.
      X_FIELDCAT-DRDN_HNDL = '1'.
      X_FIELDCAT-DRDN_ALIAS = 'X'.
      APPEND X_FIELDCAT TO IT_FIELDCAT.
      CLEAR X_FIELDCAT.
    ENDFORM.                    " build_fieldcat
    *&      Module  STATUS_0100  OUTPUT
    *       text
    MODULE STATUS_0100 OUTPUT.
      SET PF-STATUS 'MAIN100'.
      SET TITLEBAR 'MAIN100'.
      IF G_CUSTOM_CONTAINER IS INITIAL.
    **Initializing the grid and calling the fm to Display the O/P
        PERFORM CREATE_AND_INIT_ALV.
      ENDIF.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
    *       text
    MODULE USER_COMMAND_0100 INPUT.
      CASE SY-UCOMM.
        WHEN 'BACK'.
          LEAVE TO SCREEN 0.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&      Form  SET_DRDN_TABLE
    *       text
    FORM SET_DRDN_TABLE.
      DATA:LT_DRAL TYPE LVC_T_DRAL,
            LS_DRAL TYPE LVC_S_DRAL.
      LOOP AT ITAB .
    * First listbox (handle '1').
        IF SY-INDEX = 1.
          LS_DRAL-HANDLE = '1'.
          LS_DRAL-VALUE =  ' '.
          LS_DRAL-INT_VALUE =  ' '.
        ELSE.
          LS_DRAL-HANDLE = '1'.
          LS_DRAL-VALUE =  ITAB-POSNR.
          LS_DRAL-INT_VALUE =  ITAB-POSNR.
        ENDIF.
        APPEND LS_DRAL TO LT_DRAL.
      ENDLOOP.
    **Setting the Drop down table for Reason Code
      CALL METHOD G_GRID->SET_DROP_DOWN_TABLE
        EXPORTING
          IT_DROP_DOWN_ALIAS = LT_DRAL.
    ENDFORM.                               " set_drdn_table
    *&      Form  EVENT_TOP_OF_PAGE
    *       text
    *      -->DG_DYNDOC_ID  text
    FORM EVENT_TOP_OF_PAGE USING   DG_DYNDOC_ID TYPE REF TO CL_DD_DOCUMENT.
      "this is more clear.....check it
      "first add text, then pass it to comentry write fm
      DATA : DL_TEXT(255) TYPE C.  "Text
    * Populating header to top-of-page
      CALL METHOD DG_DYNDOC_ID->ADD_TEXT
        EXPORTING
          TEXT      = 'Test Report'
          SAP_STYLE = CL_DD_AREA=>HEADING.
    * Add new-line
      CALL METHOD DG_DYNDOC_ID->NEW_LINE.
      CLEAR : DL_TEXT.
    * Move program ID
      CONCATENATE 'Program Name :' SY-REPID
             INTO DL_TEXT SEPARATED BY SPACE.
    * Add Program Name to Document
      PERFORM ADD_TEXT USING DL_TEXT.
    * Add new-line
      CALL METHOD DG_DYNDOC_ID->NEW_LINE.
      CLEAR : DL_TEXT.
    * Move User ID
      CONCATENATE 'User ID :' SY-UNAME INTO DL_TEXT SEPARATED BY SPACE
    * Add User ID to Document
      PERFORM ADD_TEXT USING DL_TEXT.
    * Add new-line
      CALL METHOD DG_DYNDOC_ID->NEW_LINE.
      CLEAR : DL_TEXT.
    * Move count (no of records).
      move v_lines to v_line.
      CONCATENATE 'No of records :' v_line INTO DL_TEXT SEPARATED BY SPACE.
    * Add Client to Document
      PERFORM ADD_TEXT USING DL_TEXT.
    * Add new-line
      CALL METHOD DG_DYNDOC_ID->NEW_LINE.
      CLEAR : DL_TEXT.
    * Move date
      WRITE SY-DATUM TO DL_TEXT.
      CONCATENATE 'Date :' DL_TEXT INTO DL_TEXT SEPARATED BY SPACE.
    * Add Date to Document
      PERFORM ADD_TEXT USING DL_TEXT.
    * Add new-line
      CALL METHOD DG_DYNDOC_ID->NEW_LINE.
      CLEAR : DL_TEXT.
    * Move time
      WRITE SY-UZEIT TO DL_TEXT.
      CONCATENATE 'Time :' DL_TEXT INTO DL_TEXT SEPARATED BY SPACE.
    * Add Time to Document
      PERFORM ADD_TEXT USING DL_TEXT.
    * Add new-line
      CALL METHOD DG_DYNDOC_ID->NEW_LINE.
    * Populating data to html control
      PERFORM HTML.
    ENDFORM.                    " EVENT_TOP_OF_PAGE
    *&      Form  ADD_TEXT
    *       To add Text
    FORM ADD_TEXT USING P_TEXT TYPE SDYDO_TEXT_ELEMENT.
    * Adding text
      CALL METHOD DG_DYNDOC_ID->ADD_TEXT
        EXPORTING
          TEXT         = P_TEXT
          SAP_EMPHASIS = CL_DD_AREA=>HEADING.
    ENDFORM.                    " ADD_TEXT
    *&      Form  HTML
    *       text
    FORM HTML.
      DATA : DL_LENGTH  TYPE I,                           " Length
             DL_BACKGROUND_ID TYPE SDYDO_KEY VALUE SPACE. " Background_id
    * Creating html control
      IF DG_HTML_CNTRL IS INITIAL.
        CREATE OBJECT DG_HTML_CNTRL
             EXPORTING
                  PARENT    = DG_PARENT_HTML.
      ENDIF.
    * Reuse_alv_grid_commentary_set
      CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'
        EXPORTING
          DOCUMENT = DG_DYNDOC_ID
          BOTTOM   = SPACE
        IMPORTING
          LENGTH   = DL_LENGTH.
    * Get TOP->HTML_TABLE ready
      CALL METHOD DG_DYNDOC_ID->MERGE_DOCUMENT.
    * Set wallpaper
      CALL METHOD DG_DYNDOC_ID->SET_DOCUMENT_BACKGROUND
        EXPORTING
          PICTURE_ID = DL_BACKGROUND_ID.
    * Connect TOP document to HTML-Control
      DG_DYNDOC_ID->HTML_CONTROL = DG_HTML_CNTRL.
    * Display TOP document
      CALL METHOD DG_DYNDOC_ID->DISPLAY_DOCUMENT
        EXPORTING
          REUSE_CONTROL      = 'X'
          PARENT             = DG_PARENT_HTML
        EXCEPTIONS
          HTML_DISPLAY_ERROR = 1.
      IF SY-SUBRC NE 0.
        MESSAGE I999 WITH 'Error in displaying top-of-page'(036).
      ENDIF.
    ENDFORM.                    " HTML
    Regards
    vijay

  • ALV - is there a way to automatically send the ALV via e-mail

    Hi,
    I have a requirement to automatically send the ALV to an e-mail address.
    Is this possible to do by just using the ALV methods available ?
    Cheers
    Colin.

    Hi Colin,
    Check the weblog:
    /people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface
    Check these link..
    http://www.sap-img.com/abap/sending-email-with-attachment.htm
    https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/789. [original link is broken] [original link is broken] [original link is broken] [original link is broken]
    Have a look at below code:
    REPORT ZSENDEXTERNAL.
    DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
    DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.
    DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
    DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
    DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
    DATA: DOC_CHNG LIKE SODOCCHGI1.
    DATA: TAB_LINES LIKE SY-TABIX.
    Creation of the document to be sent
    File Name
    DOC_CHNG-OBJ_NAME = 'SENDFILE'.
    Mail Subject
    DOC_CHNG-OBJ_DESCR = 'Send External Mail'.
    Mail Contents
    OBJTXT = 'Minimum bid : $250000'.
    APPEND OBJTXT.
    OBJTXT = 'A representation of the pictures up for auction'.
    APPEND OBJTXT.
    OBJTXT = 'was included as attachment.'.
    APPEND OBJTXT.
    DESCRIBE TABLE OBJTXT LINES TAB_LINES.
    READ TABLE OBJTXT INDEX TAB_LINES.
    DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
    Creation of the entry for the compressed document
    CLEAR OBJPACK-TRANSF_BIN.
    OBJPACK-HEAD_START = 1.
    OBJPACK-HEAD_NUM = 0.
    OBJPACK-BODY_START = 1.
    OBJPACK-BODY_NUM = TAB_LINES.
    OBJPACK-DOC_TYPE = 'RAW'.
    APPEND OBJPACK.
    Creation of the document attachment
    (Assume that the data in OBJBIN is in BMP format)
    *OBJBIN = ' O/ '. APPEND OBJBIN.
    *OBJBIN = ' | '. APPEND OBJBIN.
    *OBJBIN = ' /  '. APPEND OBJBIN.
    *DESCRIBE TABLE OBJBIN LINES TAB_LINES.
    *OBJHEAD = 'PICTURE.BMP'.
    *APPEND OBJHEAD.
    Creation of the entry for the compressed attachment
    *OBJPACK-TRANSF_BIN = 'X'.
    *OBJPACK-HEAD_START = 1.
    *OBJPACK-HEAD_NUM = 1.
    *OBJPACK-BODY_START = 1.
    *OBJPACK-BODY_NUM = TAB_LINES.
    *OBJPACK-DOC_TYPE = 'BMP'.
    *OBJPACK-OBJ_NAME = 'PICTURE'.
    *OBJPACK-OBJ_DESCR = 'Representation of object 138'.
    *OBJPACK-DOC_SIZE = TAB_LINES * 255.
    *APPEND OBJPACK.
    Completing the recipient list
    RECLIST-RECEIVER = '[email protected]'.
    RECLIST-REC_TYPE = 'U'.
    APPEND RECLIST.
    *RECLIST-RECEIVER = 'SAPUSERNAME'.
    *RECLIST-REC_TYPE = 'P'.
    *APPEND RECLIST.
    Sending the document
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
    DOCUMENT_DATA = DOC_CHNG
    PUT_IN_OUTBOX = 'X'
    TABLES
    PACKING_LIST = OBJPACK
    OBJECT_HEADER = OBJHEAD
    CONTENTS_BIN = OBJBIN
    CONTENTS_TXT = OBJTXT
    RECEIVERS = RECLIST
    EXCEPTIONS
    TOO_MANY_RECEIVERS = 1
    DOCUMENT_NOT_SENT = 2
    OPERATION_NO_AUTHORIZATION = 4
    OTHERS = 99.
    CASE SY-SUBRC.
    WHEN 0.
    WRITE: / 'Result of the send process:'.
    LOOP AT RECLIST.
    WRITE: / RECLIST-RECEIVER(48), ':'.
    IF RECLIST-RETRN_CODE = 0.
    WRITE 'The document was sent'.
    ELSE.
    WRITE 'The document could not be sent'.
    ENDIF.
    ENDLOOP.
    WHEN 1.
    WRITE: / 'No authorization for sending to the specified number',
    'of recipients'.
    WHEN 2.
    WRITE: / 'Document could not be sent to any recipient'.
    WHEN 4.
    WRITE: / 'No send authorization'.
    WHEN OTHERS.
    WRITE: / 'Error occurred while sending'.
    ENDCASE.
    Reward points if this Helps.
    Manish

  • Can i raise any event on the ALV  GRID row selection.

    Hi All ,
            Is there any way to trigger any event upon the selction of the ALV <b>GRID</b> rows?
    Suppose i have 2 grid controls  1 for Header and the other for corresponding line items . I would have already the header data (differnt document headers)  populated , upon selecting (i don't want any user click or button click) one of the header i want to do some changes to the corresponding line times for the header data selected...
    Please give me some tips on how to  go about on this .
    Thanks,
    ALFH

    <b>upon selecting ?</b>
    how the user will select , since you dont want user click or button click?
    one option is to have hotspot, but again user has to click .
    Regards
    Raja

  • Is it possible to make certain rows mandatory in ALV custom Grid display?

    Hi experts,
                    Is it possible to make certain columns mandatory in the ALV custom grid control just as we give in a selection screen ?
    Thanks in advance
    regards,
    Ashwin

    fieldcat-key = 'X'.
    Regards,
    Amit

  • Is "Enter" the only way to let an ABAP OO editable ALV know data's changed?

    In the past two years, I've coded numerous ABAP OO editable ALV's, and once Uwe set me straight about how ti use the canned "handle data changed" methods,. it's been very straightforward.
    But here's my question.
    I have a modal dialog box in a MIGO dialog exit (yes, there is one although it's in a very odd function group - XQSM.)
    In the modal dialog box, I have an editable ALV and an OK pushbutton underneath it.
    If the user enters data into the ALV and then presses OK immediately afterwards (without pressing ENTER first), the ALV doesn't recognize that data has been entered.  So the underlying itab winds up empty.
    What is the right way to handle this?
    Is there a way of forcing the ALV to do its thing from within the PAI that handles the OK pushbutton?
    At my last client, the customers were willing to live with this as a training issue - tell the users to hit ENTER at least once before pressing OK.
    But surely, SAP must have something else in mind here that I'm not yet aware of.
    Thanks for any advice anyone can provide.
    djh

    Hi Vijay -
    Thanks for both answers!
    Regarding your first answer, here's my current code:
    class lcl_event_receiver          definition deferred.
    data:
      o_event_receiver                  type ref to lcl_event_receiver.
    class lcl_event_receiver definition.
    public section.
        methods:
          handle_data_changed
             for event data_changed of cl_gui_alv_grid
                 importing er_data_changed.
    private section.
    endclass.
    And this:
      call method o_grid->register_edit_event
                   exporting
                      i_event_id = cl_gui_alv_grid=>mc_evt_enter.
      create object o_event_receiver.
      set handler o_event_receiver->handle_data_changed for o_grid
    Are you saying that instead of mc_evt_enter, I should use "mc_evt_modified" ????
    Please clarify if you have the time.
    Thanks
    djh

  • What is the difference b/w ALV Function Module and ALV Methods?

    Hello Friends,
          Can anybody help me in finding out the difference between ALV Function Modules and ALV methods?
    Thanks & Regards
    Sathish Kumar

    Hi Sathish,
    Plz go through this info. It is very useful.
    hi,
    chk these excellent links.
    http://www.geocities.com/mpioud/Abap_programs.html
    http://www.sapdevelopment.co.uk/reporting/reportinghome.htm
    Simple ALV report
    http://www.sapgenie.com/abap/controls/alvgrid.htm
    http://wiki.ittoolbox.com/index.php/Code:Ultimate_ALV_table_toolbox
    http://www.sapgenie.com/abap/controls/alvgrid.htm
    http://wiki.ittoolbox.com/index.php/Code:Ultimate_ALV_table_toolbox
    ALV
    1. Please give me general info on ALV.
    http://www.sapfans.com/forums/viewtopic.php?t=58286
    http://www.sapfans.com/forums/viewtopic.php?t=76490
    http://www.sapfans.com/forums/viewtopic.php?t=20591
    http://www.sapfans.com/forums/viewtopic.php?t=66305 - this one discusses which way should you use - ABAP Objects calls or simple function modules.
    2. How do I program double click in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=11601
    http://www.sapfans.com/forums/viewtopic.php?t=23010
    3. How do I add subtotals (I have problem to add them)...
    http://www.sapfans.com/forums/viewtopic.php?t=20386
    http://www.sapfans.com/forums/viewtopic.php?t=85191
    http://www.sapfans.com/forums/viewtopic.php?t=88401
    http://www.sapfans.com/forums/viewtopic.php?t=17335
    4. How to add list heading like top-of-page in ABAP lists?
    http://www.sapfans.com/forums/viewtopic.php?t=58775
    http://www.sapfans.com/forums/viewtopic.php?t=60550
    http://www.sapfans.com/forums/viewtopic.php?t=16629
    5. How to print page number / total number of pages X/XX in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=29597 (no direct solution)
    6. ALV printing problems. The favourite is: The first page shows the number of records selected but I don't need this.
    http://www.sapfans.com/forums/viewtopic.php?t=64320
    http://www.sapfans.com/forums/viewtopic.php?t=44477
    7. How can I set the cell color in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=52107
    8. How do I print a logo/graphics in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=81149
    http://www.sapfans.com/forums/viewtopic.php?t=35498
    http://www.sapfans.com/forums/viewtopic.php?t=5013
    9. How do I create and use input-enabled fields in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=84933
    http://www.sapfans.com/forums/viewtopic.php?t=69878
    10. How can I use ALV for reports that are going to be run in background?
    http://www.sapfans.com/forums/viewtopic.php?t=83243
    http://www.sapfans.com/forums/viewtopic.php?t=19224
    11. How can I display an icon in ALV? (Common requirement is traffic light icon).
    http://www.sapfans.com/forums/viewtopic.php?t=79424
    http://www.sapfans.com/forums/viewtopic.php?t=24512
    12. How can I display a checkbox in ALV?
    http://www.sapfans.com/forums/viewtopic.php?t=88376
    http://www.sapfans.com/forums/viewtopic.php?t=40968
    http://www.sapfans.com/forums/viewtopic.php?t=6919
    Go thru these programs they may help u to try on some hands on
    ALV Demo program
    BCALV_DEMO_HTML
    BCALV_FULLSCREEN_DEMO ALV Demo: Fullscreen Mode
    BCALV_FULLSCREEN_DEMO_CLASSIC ALV demo: Fullscreen mode
    BCALV_GRID_DEMO Simple ALV Control Call Demo Program
    BCALV_TREE_DEMO Demo for ALV tree control
    BCALV_TREE_SIMPLE_DEMO
    BC_ALV_DEMO_HTML_D0100
    OOPs:
    Check this for basic concepts of OOPS
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap%20code%20samples/abap%20objects/abap%20code%20sample%20to%20learn%20basic%20concept%20of%20object-oriented%20programming.doc
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap%20code%20samples/alv%20grid/abap%20code%20sample%20to%20display%20data%20in%20alv%20grid%20using%20object%20oriented%20programming.doc
    Tabstrip
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap%20code%20samples/alv%20grid/abap%20code%20sample%20for%20tab%20strip%20in%20alv.pdf
    Editable ALV
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap%20code%20samples/alv%20grid/abap%20code%20sample%20to%20edit%20alv%20grid.doc
    Tree
    http://www.sapdevelopment.co.uk/reporting/alv/alvtree/alvtree_usrint.htm
    General Tutorial for OOPS
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/an%20easy%20reference%20for%20alv%20grid%20control.pdf
    Rewords some points if it is helpful.
    Rgds,
    P.Naganjana Reddy

  • Overwriting the ALV refresh method

    Hello Gurus, i need to refresh my ALV after modifications in the database. Can i overwrite the refresh method ? because i have to refresh the internal table too.
    The refresh button won`t work.
    I will reward points.

    Hi,
    Use below code
    DATA : DATA ref1 TYPE REF TO cl_gui_alv_grid.
    CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
    e_grid = ref1.
    CALL METHOD ref1->check_changed_data.
    CALL METHOD ref1->refresh_
    OR
    do like this
    data: o_alv type ref to CL_SALV_TABLE.
    then use the method
    CALL METHOD o_alv->refresh
    EXPORTING
    refresh_mode = if_salv_c_refresh=>soft.
    Another method:
    If you are using the function module ALV, you need to set the REFRESH flag in the USER_COMMAND routine. HEre is an example.
    code
    Call ABAP List Viewer (ALV)
    call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
    i_callback_program = repid
    i_callback_user_command = 'HANDLE_USER_COMMAND'
    it_fieldcat = ifc
    tables
    t_outtab = itab.
    endform.
    FORM handle_User_Command *
    form handle_user_command using r_ucomm like sy-ucomm
    rs_selfield type slis_selfield.
    case r_ucomm.
    when '&IC1'.
    DO Something
    rs_selfield-refresh = 'X'.
    endcase.
    endform.
    Regards,
    Shiva K

  • CVI what is the best methods in binding graphs

    Hi all
    I have run into a roadblock of sorts. The question is what is the best, most prefered way for binding graph data.
    There are two ways of binding the graph data, one is the use of data sockets binding (easy), and the other is network variable binding(more complex) . I am trying to have only one protocol running for communication preferably network variable due to the systems manager, I would like curve away from the datasocket.
    When binding a networkvariable to the graph, don't you just copy the received data to a buffered writer variable and then bind the graph to that buffered writer?
    What are the benefits of using datasocket over network variables?
    Are there any performance differences between the two?

    Hi Iriddick
    I recommend using network shared variables to bind data to your graph since is a newer and more reliable technology than datasocket, the shared variable engine enables the network shared variables to transmit live measurement data. CVI configures the SVE as a service and launches it at start up.  This article explains the benefits of using network shared variables. 
    regards 
    Chris S.

  • In alv , dump occurs , while sorting the alv .

    Hi,
    In Alv , sorting is working fine before we  selecting a row . After seleting the row , if we are  sorting it is going to dump .
    Dump Message:
    The following error text was processed in the system xxx : Adapter error in &VIEW_ELEMENT_TYPE& "OJTXP" of view "Zzzzz.VW_TEST": Context binding of property TEXT cannot be resolved: Lead selection not set for context node VW_TEST.1.ALV_TRF_DET
    The error occurred on the application server plmdev_PLD_00 and in the work process 0 .
    The termination type was: RABAX_STATE
    The ABAP call stack was:
    Method: RAISE_FOR of program CX_WDR_ADAPTER_EXCEPTION======CP
    Method: RAISE_BINDING_EXCEPTION of program CL_WDR_VIEW_ELEMENT_ADAPTER===CP
    Method: GET_BOUND_ELEMENT of program CL_WDR_VIEW_ELEMENT_ADAPTER===CP
    How to resolve this error ?.
    Regars,
    Rani.

    Do you have child node under the context node that is bound to the ALV?  This is generally the most common cause of such an error. Structures such as this are not supported for the reasons supplied in this help link:
    http://help.sap.com/saphelp_nw70ehp1/helpdata/en/42/b9ea094f4a3118e10000000a1553f7/frameset.htm
    Be sure and read the section "Important Exception: Sorting"

  • Display/Print the Selection criteria entered by USER on the ALV Report o/p?

    Hi Experts,
    I hv a requirement of to print/display the Selection criteria entered by user in the selection screen.........on the top portion of the ALV report output lay out.
    There is a FM for this purpose, but, I forgot its name!!
    So, let me know the FM or FMs, so that, will choose, which is best one,
    or the piece of code, which covers all select-option entries..........appreciated.
    thanq
    Edited by: SAP ABAPer on Sep 3, 2008 6:35 PM

    Use the Function RS_REFRESH_FROM_SELECTOPTIONS get the selection details, now format the data accordingly in the TOP_OF_PAGE using the calss CL_DD_DOCUMENT.
    Check the below mention code.
    REPORT  ztest_page.
    TABLES: sflight.
    DATA : it_flight TYPE TABLE OF sflight WITH HEADER LINE.
    DATA BEGIN OF it_sel_opt OCCURS 0.
            INCLUDE STRUCTURE rsparams.
    DATA END   OF it_sel_opt.
    SELECT-OPTIONS: s_carrid FOR sflight-carrid.
    START-OF-SELECTION.
      SELECT * FROM sflight INTO TABLE it_flight
       WHERE carrid IN s_carrid.
    END-OF-SELECTION.
      CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
        EXPORTING
          curr_report     = sy-repid
        TABLES
          selection_table = it_sel_opt
        EXCEPTIONS
          not_found       = 01
          no_report       = 02.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program          = sy-repid
          i_callback_html_top_of_page = 'TOP_OF_PAGE'
          i_structure_name            = 'SFLIGHT'
        TABLES
          t_outtab                    = it_flight
        EXCEPTIONS
          program_error               = 1
          OTHERS                      = 2.
    *&      Form  top_of_page
    *       text
    *      -->DOCUMENT   text
    FORM top_of_page USING document TYPE REF TO cl_dd_document.
      DATA : dl_text(255) TYPE c.  "Text
    * Add new-line
      CALL METHOD document->new_line.
      CALL METHOD document->new_line.
      CLEAR : dl_text.
    * program ID
      dl_text = 'Program Name :'.
      CALL METHOD document->add_gap.
      CALL METHOD document->add_text
        EXPORTING
          text         = dl_text
          sap_emphasis = cl_dd_area=>heading
          sap_color    = cl_dd_area=>list_heading_int.
      CLEAR dl_text.
      dl_text = sy-repid.
      CALL METHOD document->add_text
        EXPORTING
          text         = dl_text
          sap_emphasis = cl_dd_area=>heading
          sap_color    = cl_dd_area=>list_negative_inv.
    * Add new-line
      CALL METHOD document->new_line.
      CLEAR : dl_text.
      dl_text = 'Selection Criteria'.
      CALL METHOD document->add_gap
        EXPORTING
          width = 34.
      CALL METHOD document->add_text
        EXPORTING
          text         = dl_text
          sap_emphasis = cl_dd_area=>heading
          sap_color    = cl_dd_area=>list_negative_inv.
    * Add new-line
      CALL METHOD document->new_line.
      CLEAR : dl_text.
      CONCATENATE 'SELECT Option' 'SIGN' 'OPTION' 'LOW' 'HIGH'
      INTO dl_text SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
      CALL METHOD document->add_gap
        EXPORTING
          width = 34.
      CALL METHOD document->add_text
        EXPORTING
          text         = dl_text
          sap_emphasis = cl_dd_area=>heading
          sap_color    = cl_dd_area=>list_negative_inv.
    * Add new-line
      CALL METHOD document->new_line.
      LOOP AT it_sel_opt.
        CLEAR : dl_text.
        CONCATENATE it_sel_opt-selname  it_sel_opt-sign
         it_sel_opt-option it_sel_opt-low it_sel_opt-high
        INTO dl_text SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
        CALL METHOD document->add_gap
          EXPORTING
            width = 34.
        CALL METHOD document->add_text
          EXPORTING
            text         = dl_text
            sap_emphasis = cl_dd_area=>heading
            sap_color    = cl_dd_area=>list_negative_inv.
    * Add new-line
        CALL METHOD document->new_line.
      ENDLOOP.
    ENDFORM.                    "top_of_page

  • Change of count on the header on filtering the ALV

    Hi Gurus!
    I have this ALV report which gives the sales order report, in the output right on the top the report shows the count of all the distinct sales order displayed when the report is run based ona  selection criteria. Is it possible to show the total count of teh sales order in the report to change and show teh number of distinct sales doc when we use filter on teh report. Suppose if we run the report based on a particular selection criteria and it gives a count of 30 . In the output if we put filter on a particular column and the report shows fewer lines , which will reduce the number of sales doc, is it possible to show this number which for eg will be say 20 , is it possible to show the number 20 after filetr on ALV instead of that 30 remainiung constant. I am wanting the report to show the change in count of distinct sales doc when I put filter on any columnh.
    report  zsales_orders message-id zsd no standard page heading.
    * For ALV usage
    type-pools: slis.
    data: gs_layout   type slis_layout_alv,
          ta_events   type slis_t_event_exit,
          tp_event    type slis_event_exit,
          tp_print    type slis_print_alv,
          gt_sort     type slis_t_sortinfo_alv,
          gt_events   type slis_t_event,
          t_fieldcat  type slis_t_fieldcat_alv with header line,
          repid       type syrepid,               " ABAP Program.
          gt_list_top_of_page type slis_t_listheader,     " Top of page text.
          gs_list_top_of_page type slis_listheader,
          alv_variant   type disvariant.           " Customize Disp. Variant
    data: w_field    type slis_fieldcat_alv.
    data: count type i.
    data: count1 type i.
    tables: vbak, vbap, vbpa, knvv.
    * Definition of selection screen                                       *
    *   By plant, storage location, sold-to customers, material and        *
    *   posting date of the sales orders                                   *
    selection-screen begin of block one with frame title text-001.
    parameters:     p_vkorg  type vkorg obligatory memory id vko,"DEVK906677
                    p_vtweg  type vtweg obligatory default '01',
                    p_spart  type spart obligatory default '01'.
    select-options: s_vkbur  for  vbak-vkbur,      " Sales Office     "DEVK906677
                    s_kunnr  for  vbak-kunnr.      " Sold-to customer number.
    select-options: s_shipto for  vbap-oid_ship,   " Ship-to customer number.
                    s_billto for  vbpa-kunnr,      " bill-to from S.O. header.
                    s_load   for  vbpa-kunnr,      " Load confirmation contact.
                    s_truck  for  vbap-oid_extbol. " Trucking ticket number.
    select-options: s_werks for vbap-werks obligatory no intervals. " Plant.
    select-options: s_lgort for vbap-lgort.        " Storage location.
    select-options: s_matnr for vbap-matnr.        " Material number.
    select-options: s_konda for knvv-konda.        " price group
    selection-screen skip 1.
    select-options: s_vdatu for vbak-vdatu default sy-datum.
    selection-screen end of block one.
    * ALV display layout
    selection-screen begin of block layout with frame title text-003.
    parameters: pa_vari type slis_vari default ' '. " Display variant.
    selection-screen end of block layout.
    selection-screen begin of block two with frame title text-028.
    selection-screen comment: /1(79) text-029.
    selection-screen comment: /1(79) text-030.
    selection-screen comment: /1(79) text-031.
    selection-screen comment: /1(79) text-032.
    selection-screen comment: /1(79) text-033.
    selection-screen comment: /1(79) text-034.
    selection-screen comment: /1(79) text-035.
    selection-screen comment: /1(79) text-036.
    selection-screen end of block two.
    * Data Definitions                                                     *
    * Storing Extracted Info.
    types: begin of t_extract,
             vbeln        type vbeln_va,   " Sales order number.
             augru        type augru,      " order reason
             vdatu        type edatu_vbak, " Requested delivery date.
             kunnr        type kunag,      " Sold-to customer number.
             soldto_name  type name1_gp,   " Sold-to name.
             posnr        type posnr_va,   " Item number.
             matnr        type matnr,      " Material number.
             vrkme        type vrkme,      " Sales UoM.
             mseh3        type mseh3,      " UoM text.
             netwr        type netwr_ap,   " Net value of the order item.
             kwmeng       type p length 13 decimals 1, " Quantity.
             werks        type werks_d,    " Plant.
             lgort        type lgort_d,    " Storage location.
             oid_extbol   type oid_extbol, " External BOL or truck ticker header.
             maktx        type maktx,      " Material description.
             oid_ship     type kunwe,      " Ship-to customer number.
             shipto_name  type name1_gp,   " Ship-to name.
             billto       type kunre,      " Bill-to customer number.
             billto_name  type name1_gp,   " Bill-to name.
             load_contact type kunnr,      " Load confirmation contact.
             load_name    type name1_gp,   " Load confirmation contact name.
             truck        type kunnr,      " Truck company number.
             truck_name   type name1_gp,   " Truck company name.
             bstkd        type bstkd,      " PO number.
             ihrez        type ihrez,      " AFE number per the contract/sales order.
             delivery     type vbeln_vl,   " Delivery number.
             posnr_vl     type posnr_vl,   " Delivery item number.
             bill_vbeln   type vbeln_vf,   " Invoice number.
             bill_posnr   type posnr_vf,   " Invoice item number.
             bill_netwr   type netwr_fp,   " Invoice net value.
             statu        type stats,      " Document status.
             auart        type auart,      " order type
             vkorg        type vkorg,      " sales org.
             vtweg        type vtweg,      " distrbtn channel
             spart        type spart,      " division
             vkbur        like vbak-vkbur, " Sales Office DEVK906677
             konda        type konda,      " price group
             tdline       type tdline,     " text for customer account reference
             count        type i,
           end of t_extract.
    data : it_extract  type table of t_extract with header line,
           it_extract2 type table of t_extract with header line.
    data:  it_text type table of tline with header line.
    data: w_index type sy-index,
          w_tdname type tdobname.
    constants: c_minus1       type netwr_ap value '1.00-'.
    *RANGES: r_auart FOR vbak-auart.
    data: r_auart type range of t_extract-auart,
          r_auart_line like line of r_auart.
    * initialization
    initialization.
      tp_event-ucomm = '&ILT'.  " Filter event.
      tp_event-after = 'X'.
      append tp_event to ta_events.
      gs_layout-colwidth_optimize = 'X'.
      tp_print-no_print_listinfos = 'X'.
      tp_print-no_coverpage = 'X'.
      perform set_fieldcat.
      perform alv_eventtab_build using:
    **    Event name     Form to execute     Event internal table
       'TOP_OF_PAGE'  'TOP_OF_PAGE'       gt_events[].
    * changed to exclude following order types
      r_auart_line-sign   = 'I'.
      r_auart_line-option = 'EQ'.
      r_auart_line-low    = 'ZEQ'.
      clear r_auart_line-high.
      append r_auart_line to r_auart.
    * credit memo
      r_auart_line-sign   = 'I'.
      r_auart_line-option = 'EQ'.
      r_auart_line-low    = 'ZPRC'.
      clear r_auart_line-high.
      append r_auart_line to r_auart.
    * debit memo
      r_auart_line-sign   = 'I'.
      r_auart_line-option = 'EQ'.
      r_auart_line-low    = 'ZPRD'.
      clear r_auart_line-high.
      append r_auart_line to r_auart.
      r_auart_line-sign   = 'I'.
      r_auart_line-option = 'EQ'.
      r_auart_line-low    = 'ZDR'.
      clear r_auart_line-high.
      append r_auart_line to r_auart.
    * Industry sales order correction
      r_auart_line-sign   = 'I'.
      r_auart_line-option = 'EQ'.
      r_auart_line-low    = 'ZSOC'.
      clear r_auart_line-high.
      append r_auart_line to r_auart.
    * oilfield FF correction
      r_auart_line-sign   = 'I'.
      r_auart_line-option = 'EQ'.
      r_auart_line-low    = 'ZOCF'.
      clear r_auart_line-high.
      append r_auart_line to r_auart.
    * oilfield WP correction
      r_auart_line-sign   = 'I'.
      r_auart_line-option = 'EQ'.
      r_auart_line-low    = 'ZOCW'.
      clear r_auart_line-high.
      append r_auart_line to r_auart.
    * Dropdown list for all created ALV layouts, global or user-specific
    at selection-screen on value-request for pa_vari.
      perform alv_variant_f4 changing pa_vari.
    * Main BODY of processing logic
    start-of-selection.
      perform extract_data.
    end-of-selection.
      if not it_extract[] is initial.
    * Build headings for report.
        perform build_top_of_page  using gt_list_top_of_page[].
        perform call_alv.
      endif.
    *&      Form  EXTRACT_KEY_DATA
    * Retreive the data for the report.
    form extract_data.
      clear: it_extract.  refresh: it_extract.
    * orders
      select vbak~vbeln vbak~auart vbak~augru vbak~vkorg vbak~vtweg
             vbak~spart vbak~vdatu vbak~kunnr vbak~vkbur
             vbap~posnr vbap~matnr vbap~vrkme vbap~netwr vbap~kwmeng
             vbap~werks vbap~lgort vbap~oid_extbol vbap~oid_ship
        into corresponding fields of table it_extract
        from vbak inner join vbap
             on  vbak~mandt = vbap~mandt
             and vbak~vbeln = vbap~vbeln where
        vbak~auart not in r_auart and
        vbak~vkorg eq p_vkorg and
        vbak~vtweg eq p_vtweg and
        vbak~spart eq p_spart and
        vbak~vkbur in s_vkbur and                               "DEVK906677
        vbak~vdatu in s_vdatu and
        vbak~kunnr in s_kunnr and
        vbap~matnr in s_matnr and
        vbap~werks in s_werks and
        vbap~lgort in s_lgort and
        vbap~oid_extbol in s_truck and
        vbap~oid_ship in s_shipto.
      if sy-subrc <> 0.
        message i000 with text-002 ' ' ' ' ' '.
      endif.
      sort it_extract by vbeln.
      check sy-subrc = 0.
      loop at it_extract.
    * Retrieve and select by load confirmation contacts from header
        select single kunnr from vbpa into it_extract-load_contact
         where vbeln = it_extract-vbeln
           and posnr = '000000'
           and parvw = 'ZB'.
        if it_extract-load_contact in s_load.
          it_extract-load_name = zcl_kna1=>get_name1( it_extract-load_contact ).
        else.
          delete it_extract.
          continue.
        endif.
    * Retrieve and select by sales order bill-to on header level
    * as well as lookup bill-to customer name/description
        select single kunnr from vbpa into it_extract-billto
         where vbeln = it_extract-vbeln
           and posnr = '000000'
           and parvw = 'RE'.
        if sy-subrc = 0.
          if s_billto is initial.
            it_extract-billto_name = zcl_kna1=>get_name1( it_extract-billto ).
          else.
            if it_extract-billto in s_billto.
              it_extract-billto_name = zcl_kna1=>get_name1( it_extract-billto ).
            else.
              delete it_extract.
              continue.
            endif.
          endif.
        else.
    * Newalta - always has bill-to, following will not occur but included
    *           as good programming practice.
          it_extract-billto_name = it_extract-billto.
        endif.
    * Retrieve and select by price group of sold-to
        select single konda from knvv into it_extract-konda
         where kunnr = it_extract-kunnr
           and vkorg = it_extract-vkorg
           and vtweg = it_extract-vtweg
           and spart = it_extract-spart.
        if sy-subrc = 0.
          if not ( it_extract-konda in s_konda ).
            delete it_extract.
            continue.
          endif.
        endif.
    * Retrieve trucking company customer
        select single kunnr from vbpa into it_extract-truck where
          vbeln = it_extract-vbeln and
          posnr = '000000' and
          parvw = 'ZT'.
        if sy-subrc = 0.
          it_extract-truck_name = zcl_kna1=>get_name1( it_extract-truck ).
        endif.
    * Retrieve sold-to name
        it_extract-soldto_name = zcl_kna1=>get_name1( it_extract-kunnr ).
    * Retrieve ship-to name
        it_extract-shipto_name = zcl_kna1=>get_name1( it_extract-oid_ship ).
    * lookup P.O.
        select single bstkd ihrez from vbkd into (it_extract-bstkd, it_extract-ihrez)
         where vbeln = it_extract-vbeln
           and posnr = '000000'.
    * Retreive the material description.
        it_extract-maktx = zcl_material=>get_maktx( it_extract-matnr ).
    * cosmetic change of material number, donot display leading zeros.
        shift it_extract-matnr left deleting leading '0'.
    * translate unit of measure
        it_extract-mseh3 = it_extract-vrkme.
        select single mseh3 from t006a into it_extract-mseh3
         where spras = sy-langu
           and msehi = it_extract-vrkme.
        w_tdname = it_extract-vbeln.
    * read customer account reference which is under 'text'
        call function 'READ_TEXT'
          exporting
            client                        = sy-mandt
            id                            = 'Z010'
            language                      = sy-langu
            name                          = w_tdname
            object                        = 'VBBK'
    *   ARCHIVE_HANDLE                = 0
    *   LOCAL_CAT                     = ' '
    * IMPORTING
    *   HEADER                        =
          tables
            lines                         = it_text
          exceptions
            id                            = 1
            language                      = 2
            name                          = 3
            not_found                     = 4
            object                        = 5
            reference_check               = 6
            wrong_access_to_archive       = 7
            others                        = 8.
        if sy-subrc = 0.
          read table it_text index 1.
          if sy-subrc = 0.
            it_extract-tdline = it_text-tdline.
          else.
            clear it_extract-tdline.
          endif.
        else.
          clear it_extract-tdline.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        endif.
    * Get the delivery item.
        call method zcl_vbap=>get_delivery
          exporting
            itp_vbeln = it_extract-vbeln
            itp_posnr = it_extract-posnr
          importing
            etp_vbeln = it_extract-delivery
            etp_posnr = it_extract-posnr_vl.
        if it_extract-delivery is not initial.
          perform process_deliveries.
        else.
          perform invoice_process.
        endif.
        it_extract-count = 1 .
        move-corresponding it_extract to it_extract2.
        append it_extract2.
        at new vbeln.
          count1 = count1 + 1.
        endat.
      endloop.
    endform.                    " EXTRACT_DATA
    *&      Form  SET_FIELDCAT
    * Create the field catalogue.
    form set_fieldcat .
      clear w_field.
      clear t_fieldcat.  refresh t_fieldcat.
      w_field-col_pos = 1 .
      w_field-fieldname = 'VBELN'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Document.Nbr'.
      w_field-emphasize = 'X'.
      w_field-hotspot   = 'X'.
      append w_field to t_fieldcat.
      clear w_field.
      w_field-col_pos = 2 .
      w_field-fieldname = 'POSNR'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Item'(023).
      append w_field to t_fieldcat.
      clear w_field.
      w_field-col_pos = 3 .
      w_field-fieldname = 'VDATU'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Req. Del. Date'(005).
      append w_field to t_fieldcat.
      w_field-col_pos = 4.                                      "DEVK909658
      w_field-fieldname = 'KUNNR'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Sold-to.'(038).
      append w_field to t_fieldcat.
      w_field-col_pos = 5 .
      w_field-fieldname = 'SOLDTO_NAME'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Sold-to'(006).
      append w_field to t_fieldcat.
      w_field-col_pos = 6 .
      w_field-fieldname = 'MATNR'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Material'(007).
      append w_field to t_fieldcat.
      w_field-col_pos = 7 .
      w_field-fieldname = 'KWMENG'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Quantity'(008).
      append w_field to t_fieldcat.
      w_field-col_pos = 8.
      w_field-fieldname = 'MSEH3'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'UOM'(009).
      append w_field to t_fieldcat.
      w_field-col_pos = 9 .
      w_field-fieldname = 'BILL_VBELN'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Invoice #'(010).
      w_field-emphasize = 'X'.
      w_field-hotspot   = 'X'.
      append w_field to t_fieldcat.
      clear w_field.
      w_field-col_pos = 10 .
      w_field-fieldname = 'BILL_NETWR'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Values'(011).
      append w_field to t_fieldcat.
      w_field-col_pos = 11.
      w_field-fieldname = 'WERKS'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Plant'(012).
      append w_field to t_fieldcat.
      w_field-col_pos = 12.
      w_field-fieldname = 'LGORT'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Storage Loc'(013).
      append w_field to t_fieldcat.
      w_field-col_pos = 13 .
      w_field-fieldname = 'MAKTX'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Description'(014).
      append w_field to t_fieldcat.
      w_field-col_pos = 14.                                     "DEVK909658
      w_field-fieldname = 'OID_SHIP'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Ship-to.'(039).
      append w_field to t_fieldcat.
      w_field-col_pos = 15 .
      w_field-fieldname = 'SHIPTO_NAME'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Ship-to'(015).
      append w_field to t_fieldcat.
      w_field-col_pos = 16.                                     "DEVK909658
      w_field-fieldname = 'BILLTO'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Bill-to .'(040).
      append w_field to t_fieldcat.
      w_field-col_pos = 17 .
      w_field-fieldname = 'BILLTO_NAME'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Bill-to'(016).
      append w_field to t_fieldcat.
      w_field-col_pos = 18 .
      w_field-fieldname = 'LOAD_NAME'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Load Contact'(017).
      append w_field to t_fieldcat.
      w_field-col_pos = 19 .
      w_field-fieldname = 'TRUCK_NAME'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Truck Comp.'(018).
      append w_field to t_fieldcat.
      w_field-col_pos = 20 .
      w_field-fieldname = 'BSTKD'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'P.O.'(019).
      append w_field to t_fieldcat.
      w_field-col_pos = 21 .
      w_field-fieldname = 'IHREZ'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'AFE Nbr'(020).
      append w_field to t_fieldcat.
      w_field-col_pos = 22 .
      w_field-fieldname = 'OID_EXTBOL'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Truck Ticket'(021).
      append w_field to t_fieldcat.
      w_field-col_pos = 23.
      w_field-fieldname = 'STATU'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Status'(022).
      append w_field to t_fieldcat.
      w_field-col_pos = 24.
      w_field-fieldname = 'AUGRU'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Ord.Reason'(024).
      append w_field to t_fieldcat.
      w_field-col_pos = 25.
      w_field-fieldname = 'TDLINE'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'cstmr.acct.ref.'(027).
      append w_field to t_fieldcat.
      w_field-col_pos = 26 .                                    "DEVK906678
      w_field-fieldname = 'VKBUR'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Sales Office'(037).
      append w_field to t_fieldcat.
      w_field-col_pos = 27.                                     "DEVK909658
      w_field-fieldname = 'COUNT'.
      w_field-tabname = 'IT_EXTRACT2'.
      w_field-seltext_l = 'Count'(041).
      w_field-do_sum = 'X'.
      append w_field to t_fieldcat.
    endform.                    " SET_FIELDCAT
    *&      Form  CALL_ALV
    * Call the ALV Grid function.
    form call_alv .
      sort it_extract by lgort vbeln.
    * repid is necessary since the ALV F.M. does not work properly with
    * sy-repid.
      repid = sy-repid.
      alv_variant-variant  = pa_vari.
      alv_variant-report   = sy-repid.
      alv_variant-username = sy-uname.
      call function 'REUSE_ALV_GRID_DISPLAY'
        exporting
          i_callback_program      = repid
          i_callback_user_command = 'USER_COMMAND'
          is_layout               = gs_layout
          it_fieldcat             = t_fieldcat[]
          it_sort                 = gt_sort[]
          i_default               = 'X'
          i_save                  = 'A'
          is_variant              = alv_variant
          it_events               = gt_events[]
          it_event_exit           = ta_events[]
          is_print                = tp_print
        tables
          t_outtab                = it_extract2
        exceptions
          program_error           = 1
          others                  = 2.
      if sy-subrc ne 0.
        message w000 with text-004 ' ' ' ' ' '.
      endif.
    endform.                    " CALL_ALV
    *&      Form  build_top_of_page
    * Build heading for report.                                            *
    *      -->P_GT_LIST_TOP_OF_PAGE[]  Header stuff for report
    form build_top_of_page using   e04_lt_top_of_page type slis_t_listheader.
      data: ls_line type slis_listheader.  "Header table for top of page
    * construct 'top of page' info. to display. In this case, one line.
      data: w_selections(40) type c,
            w_date_from(10) type c,
            w_date_to(10) type c.
      write: s_vdatu-low to w_date_from dd/mm/yyyy.
      if s_vdatu-high is not initial.
        write: s_vdatu-high to w_date_to dd/mm/yyyy.
        clear w_selections.
        concatenate 'Del.Req.Date: ' w_date_from 'To' w_date_to
          into w_selections separated by space.
        clear ls_line.
        ls_line-typ  = 'H'.
        ls_line-info = w_selections.
        append ls_line to e04_lt_top_of_page.
        gs_list_top_of_page-typ = 'S'.
        gs_list_top_of_page-info = ' Total Number of Sales Documents'.
        append gs_list_top_of_page to gt_list_top_of_page.
        gs_list_top_of_page-typ  = 'S'.
        gs_list_top_of_page-info = count1.
        append gs_list_top_of_page to gt_list_top_of_page.
      else.
        clear w_date_to.
        concatenate 'Del.Req.Date: ' w_date_from
             into w_selections separated by space.
        clear ls_line.
        ls_line-typ  = 'H'.
        ls_line-info = w_selections.
        append ls_line to e04_lt_top_of_page.
      endif.
    endform.                    " build_top_of_page
    *&      Form  alv_eventtab_build
    *     Pass list of events to be triggered by the ALV function module
    form alv_eventtab_build using  u_name  type slis_alv_event-name
                                   u_form  type slis_alv_event-form
                                   alv_lt_events  type slis_t_event.
      data: ls_event type slis_alv_event.   " structure for event handling
      ls_event-name = u_name.
      ls_event-form = u_form.
      append ls_event to alv_lt_events.
    endform.                    " alv_eventtab_build
    *       FORM TOP_OF_PAGE                                              *
    form top_of_page.
      call function 'REUSE_ALV_COMMENTARY_WRITE'
        exporting
          i_logo             = 'NEWALTA_LOGO'
          it_list_commentary = gt_list_top_of_page.
    endform.                    " TOP_OF_PAGE
    *&      Form  process_deliveries
    * Process the delivery related records.
    form process_deliveries .
      data:
        ltp_date  type wadat_ist, " Goods movement date.
        ltp_vbtyp type vbtyp_n,
        ltp_mtart type mtart, " Material type.
        w_lfimg   type lfimg, " Actual quantity delivered (in sales units).
        w_vrkme   type vrkme. " Sales unit of measure.
    * Read delivery quantity and uom.
      select single lfimg vrkme into (w_lfimg, w_vrkme)
        from lips where
        vbeln = it_extract-delivery and
        posnr = it_extract-posnr_vl.
    * these fields have values from vbap. override with lips values
      if sy-subrc = 0.
        it_extract-kwmeng = w_lfimg.
        it_extract-vrkme  = w_vrkme.
    * translate unit of measure
        it_extract-mseh3 = it_extract-vrkme.
        select single mseh3 from t006a into it_extract-mseh3
         where spras = sy-langu
           and msehi = it_extract-vrkme.
      endif.
    * Determine STATUS by reading 'service confirmation', R (goods movemt)
    * it is possible to have multiple 'service confirmation' records for
    * one item. ie. delivery 80010390 in PRD.
    * As long as there is at least one 'service confirmation' record,
    * status is considered 'complete'.
    * Validate the created on date of the goods movement or service confirmation.
      ltp_mtart = zcl_material=>get_mtart( it_extract-matnr ).
    *  ltp_date = zcl_lips=>get_goods_movement_date( itp_vbeln = it_extract-delivery
    *                           itp_posnr = it_extract-posnr_vl itp_mtart = ltp_mtart ).
      call method zcl_lips=>get_goods_mvt_info
        exporting
          itp_vbeln = it_extract-delivery
          itp_posnr = it_extract-posnr_vl
          itp_mtart = ltp_mtart
        importing
          rtp_date  = ltp_date
          rtp_vbtyp = ltp_vbtyp.
    * 'h' is cancel goods issue
      if ltp_vbtyp = 'h'.
        it_extract-statu = 'Incomplete'(025).
      else.
        if ltp_date is not initial.
          it_extract-statu = 'COMPLETE'(026).
        endif.
      endif.
    * Retrieve the invoice/billing document item.
      call method zcl_lips=>get_invoice
        exporting
          itp_vbeln = it_extract-delivery
          itp_posnr = it_extract-posnr_vl
        importing
          rtp_vbeln = it_extract-bill_vbeln
          rtp_posnr = it_extract-bill_posnr.
      if it_extract-bill_vbeln is not initial.
    * retrieve net value from the invoice.
        clear it_extract-bill_netwr.
        select single netwr into it_extract-bill_netwr from vbrp
         where vbeln = it_extract-bill_vbeln
           and posnr = it_extract-bill_posnr.
      else.
        it_extract-bill_netwr = it_extract-netwr. " Use order net value.
      endif.
    endform.                    " process_deliveries
    *&      Form  user_command
    * Process the user command.
    *      -->R_UCOMM      User command
    *      -->RS_SELFIELD  Field selected
    form user_command using r_ucomm     like sy-ucomm
                            rs_selfield type slis_selfield.
      data: ltp_vbeln type vbeln.  " Sales document number.
      case  r_ucomm.
        when '&IC1'.
          if ( rs_selfield-fieldname = 'VBELN'
            or rs_selfield-fieldname = 'BILL_VBELN' )
           and rs_selfield-value is not initial.        " Display sales document.
            ltp_vbeln = rs_selfield-value.
            zcl_sales_doc=>display( ltp_vbeln ).
          endif.
        when '&ILT'.
          data:
    lta_filt type slis_t_filtered_entries.
          break rdrury.
          call function 'REUSE_ALV_LIST_LAYOUT_INFO_GET'
    importing
    *      es_layout               = gs_layout
    *      et_fieldcat             = t_fieldcat[]
    *      et_sort                 = gt_sort[]
    *   ES_LAYOUT                        =
    *   ET_FIELDCAT                      =
    *   ET_SORT                          =
    *   ET_FILTER                        =
    *   ES_LIST_SCROLL                   =
    *   ES_VARIANT                       =
    *   E_WIDTH                          =
    *   ET_MARKED_COLUMNS                =
       et_filtered_entries              = lta_filt
    *   ET_FILTERED_ENTRIES_HEADER       =
    *   ET_FILTERED_ENTRIES_ITEM         =  lta_filt
    *       TABLES
    *   et_outtab                        =
    *   ET_OUTTAB_HEADER                 =
    *   et_outtab_item                   =
    *   ET_COLLECT00                     =
    *   ET_COLLECT01                     =
    *   ET_COLLECT02                     =
    *   ET_COLLECT03                     =
    *   ET_COLLECT04                     =
    *   ET_COLLECT05                     =
    *   ET_COLLECT06                     =
    *   ET_COLLECT07                     =
    *   ET_COLLECT08                     =
    *   ET_COLLECT09                     =
           exceptions
             no_infos                         = 1
             program_error                    = 2
      endcase.
    endform.                    "user_command
    *&      Form  invoice_process
    * Process for orders without deliveries.                               *
    form invoice_process .
    * Translate unit of measure.
      select single mseh3 from t006a into it_extract-mseh3
       where spras = sy-langu
         and msehi = it_extract-vrkme.
    * Retrieve the invoice/billing document item.
      call method zcl_vbap=>get_invoice
        exporting
          itp_vbeln = it_extract-vbeln
          itp_posnr = it_extract-posnr
        importing
          rtp_vbeln = it_extract-bill_vbeln
          rtp_posnr = it_extract-bill_posnr.
      if it_extract-bill_vbeln is not initial.
    * retrieve net value from the invoice.
        clear it_extract-bill_netwr.
        select single netwr into it_extract-bill_netwr from vbrp
         where vbeln = it_extract-bill_vbeln
           and posnr = it_extract-bill_posnr.
      else. " If no Invoice, then status becomes 'incomplete'.
        it_extract-bill_netwr = it_extract-netwr. " Use order net value.
        it_extract-statu = 'Incomplete'(025).
      endif.
    endform.                    " invoice_process
    *&      Form  alv_variant_f4
    * Get the display variant.
    *      <--CTP_VARI  Variant name
    form alv_variant_f4 changing ctp_vari type slis_vari.
      alv_variant-report   = sy-repid.             " Report ID
      alv_variant-username = sy-uname.             " User ID
      call function 'REUSE_ALV_VARIANT_F4'
        exporting
          is_variant = alv_variant
          i_save     = 'A'
        importing
          es_variant = alv_variant
        exceptions
          others     = 1.
      if sy-subrc = 0.
        ctp_vari = alv_variant-variant.
      endif.
    endform.                    " alv_variant_f4

    I have used all the FM modules mentioned but I am not able to get the total of the sales doc on the top of the page to chnage when filtering of data is done . I just want to see this count of sales document (distict ) and to see it change as filtering is done , be it at any place in teh ALV , its not necessary that it has to be on the top of the ALV output. Could I get some inputs please. As you can see I used the below mentioned FM but on debugging I find the gt_stack is empty still.
    *&      Form  build_top_of_page
    * Build heading for report.                                            *
    *      -->P_GT_LIST_TOP_OF_PAGE[]  Header stuff for report
    FORM build_top_of_page USING   e04_lt_top_of_page TYPE slis_t_listheader.
      DATA: ls_line TYPE slis_listheader.  "Header table for top of page
    * construct 'top of page' info. to display. In this case, one line.
      DATA: w_selections(40) TYPE c,
            w_date_from(10) TYPE c,
            w_date_to(10) TYPE c.
      WRITE: s_vdatu-low TO w_date_from DD/MM/YYYY.
      IF s_vdatu-high IS NOT INITIAL.
        WRITE: s_vdatu-high TO w_date_to DD/MM/YYYY.
        CLEAR w_selections.
        CONCATENATE 'Del.Req.Date: ' w_date_from 'To' w_date_to
          INTO w_selections SEPARATED BY space.
        CLEAR ls_line.
        ls_line-typ  = 'H'.
        ls_line-info = w_selections.
        APPEND ls_line TO e04_lt_top_of_page.
        gs_list_top_of_page-typ = 'S'.
        gs_list_top_of_page-info = ' Total Number of Sales Documents'.
        append gs_list_top_of_page to gt_list_top_of_page.
        gs_list_top_of_page-typ  = 'S'.
        gs_list_top_of_page-info = count1.
        append gs_list_top_of_page to gt_list_top_of_page.
      ELSE.
        CLEAR w_date_to.
        CONCATENATE 'Del.Req.Date: ' w_date_from
             INTO w_selections SEPARATED BY space.
        CLEAR ls_line.
        ls_line-typ  = 'H'.
        ls_line-info = w_selections.
        APPEND ls_line TO e04_lt_top_of_page.
      ENDIF.
    ENDFORM.                    " build_top_of_page
    *&      Form  alv_eventtab_build
    *     Pass list of events to be triggered by the ALV function module
    FORM alv_eventtab_build USING  u_name  TYPE slis_alv_event-name
                                   u_form  TYPE slis_alv_event-form
                                   alv_lt_events  TYPE slis_t_event.
      DATA: ls_event TYPE slis_alv_event.   " structure for event handling
      ls_event-name = u_name.
      ls_event-form = u_form.
      APPEND ls_event TO alv_lt_events.
    ENDFORM.                    " alv_eventtab_build
    *       FORM TOP_OF_PAGE                                              *
    FORM top_of_page.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          i_logo             = 'NEWALTA_LOGO'
          it_list_commentary = gt_list_top_of_page.
      Data:lt_FILTERED_ENTRIES type SLIS_T_FILTERED_ENTRIES,
      wa_filter like line of lt_FILTERED_ENTRIES.
      data: count2 type i.
    data: it_fieldcat  type slis_t_fieldcat_alv with header line.
      CALL FUNCTION 'REUSE_ALV_LIST_LAYOUT_INFO_GET'
        IMPORTING
          ET_FILTERED_ENTRIES = lt_FILTERED_ENTRIES
        EXCEPTIONS
          NO_INFOS            = 1
          PROGRAM_ERROR       = 2
          OTHERS              = 3.
      IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID  TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        MESSAGE i000 WITH  count1  .
      ENDIF.
      loop at lt_FILTERED_ENTRIES into wa_filter.
    *    if sy-tabix <> 0.
        if sy-subrc = 0 .
          count2 = count2 + 1.
    *count3 =  count1 - count2 .
    *  write:/ 'Total number of Sales Documents =', count3 .
        endif.
      endloop.
    ENDFORM.                    " TOP_OF_PAGE
    I tried using it at user-command level too but it dosent help.
    Thanks

  • Create Dynamic Structure at Runtime via ALV-Methods!

    Hi Experts,
    i try to create at the ABAP Runtime a new Structure.
    FOR EXAMPLE: I have a internal Table "database" and i dont know their Structure or Typ.
    MY Question: How can i get the structuretype for this internal Table "database" ??
                                    I thought that it is possible with ALV-Methods, but i dont find the right way.
    First Step:       I must get the structure of this internal Table.
    Second Step: I must create a workarea/ line of this internal Table, that i can work row for row with the table.
    Have someone an code example for me, because iám very confused about this Problem.
    With kind regards.
    Ersin Tosun

    Hello,
    For this specific requirement, SAP has provided RTTI class.
    Below is a code snippet for your ready reference. In this example we're trying to get the structure of the dynamic table <ITAB> whose structure is not defined till run-time.
    TYPE-POOLS: abap.
    PARAMETERS: p_table TYPE tabname.
    DATA: dref TYPE REF TO data.
    FIELD-SYMBOLS <itab> TYPE STANDARD TABLE.
    CREATE DATA dref TYPE STANDARD TABLE OF (p_table).
    ASSIGN dref->* TO <itab>.
    DATA: go_tab_descr TYPE REF TO cl_abap_tabledescr,
          go_struc_descr TYPE REF TO cl_abap_structdescr,
          wa_comp TYPE abap_compdescr.
    go_tab_descr ?= cl_abap_tabledescr=>describe_by_data( <itab> ).
    CHECK sy-subrc = 0.
    go_struc_descr ?= go_tab_descr->get_table_line_type( ).
    LOOP AT go_struc_descr->components INTO wa_comp.
      WRITE: / wa_comp-name.
    ENDLOOP.
    I must create a workarea/ line of this internal Table, that i can work row for row with the table.
    Sorry i missed the Step 2:
    FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE,
                   <wa> TYPE ANY,
                   <val> TYPE ANY.
    LOOP AT <itab> ASSIGNING <wa>.
      LOOP AT go_struc_descr->components INTO wa_comp.
    *   To access the components of the structure dynamically
        ASSIGN COMPONENT wa_comp-name OF STRUCTURE <wa> TO <val>.
      ENDLOOP.
    ENDLOOP.
    BR,
    Suhas
    Edited by: Suhas Saha on Nov 18, 2010 7:26 PM

  • Download the ALV Report output into excel sheet or notepad

    Hi,
    how to downlaod the alv report out into excel sheet or notepad in a proper manner. program contain large number records....
    Thanks in advance!!!!
    Regards,
    kranthi.

    Hi
    Download a report to excel with format (border, color cell, etc) 
    Try this program...it may help you to change the font ..etc.
    Code:
    REPORT ZSIRI NO STANDARD PAGE HEADING.
    this report demonstrates how to send some ABAP data to an
    EXCEL sheet using OLE automation.
    INCLUDE OLE2INCL.
    handles for OLE objects
    DATA: H_EXCEL TYPE OLE2_OBJECT,        " Excel object
          H_MAPL TYPE OLE2_OBJECT,         " list of workbooks
          H_MAP TYPE OLE2_OBJECT,          " workbook
          H_ZL TYPE OLE2_OBJECT,           " cell
          H_F TYPE OLE2_OBJECT.            " font
    TABLES: SPFLI.
    DATA  H TYPE I.
    table of flights
    DATA: IT_SPFLI LIKE SPFLI OCCURS 10 WITH HEADER LINE.
    *&   Event START-OF-SELECTION
    START-OF-SELECTION.
    read flights
      SELECT * FROM SPFLI INTO TABLE IT_SPFLI UP TO 10 ROWS.
    display header
      ULINE (61).
      WRITE: /     SY-VLINE NO-GAP,
              (3)  'Flg'(001) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (4)  'Nr'(002) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (20) 'Von'(003) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (20) 'Nach'(004) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (8)  'Zeit'(005) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP.
      ULINE /(61).
    display flights
      LOOP AT IT_SPFLI.
      WRITE: / SY-VLINE NO-GAP,
               IT_SPFLI-CARRID COLOR COL_KEY NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-CONNID COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-CITYFROM COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-CITYTO COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-DEPTIME COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP.
      ENDLOOP.
      ULINE /(61).
    tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               TEXT       = TEXT-007
           EXCEPTIONS
                OTHERS     = 1.
    start Excel
      CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.
    PERFORM ERR_HDL.
      SET PROPERTY OF H_EXCEL  'Visible' = 1.
    CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'c:\kis_excel.xls'
    PERFORM ERR_HDL.
    tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               TEXT       = TEXT-008
           EXCEPTIONS
                OTHERS     = 1.
    get list of workbooks, initially empty
      CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
      PERFORM ERR_HDL.
    add a new workbook
      CALL METHOD OF H_MAPL 'Add' = H_MAP.
      PERFORM ERR_HDL.
    tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               TEXT       = TEXT-009
           EXCEPTIONS
                OTHERS     = 1.
    output column headings to active Excel sheet
      PERFORM FILL_CELL USING 1 1 1 'Flug'(001).
      PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
      PERFORM FILL_CELL USING 1 3 1 'Von'(003).
      PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
      PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
      LOOP AT IT_SPFLI.
    copy flights to active EXCEL sheet
        H = SY-TABIX + 1.
        PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
        PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
        PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
        PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
        PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
      ENDLOOP.
    changes by Kishore  - start
    CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
      CALL METHOD OF H_EXCEL 'Worksheets' = H_MAPL." EXPORTING #1 = 2.
      PERFORM ERR_HDL.
    add a new workbook
      CALL METHOD OF H_MAPL 'Add' = H_MAP  EXPORTING #1 = 2.
      PERFORM ERR_HDL.
    tell user what is going on
      SET PROPERTY OF H_MAP 'NAME' = 'COPY'.
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               TEXT       = TEXT-009
           EXCEPTIONS
                OTHERS     = 1.
    output column headings to active Excel sheet
      PERFORM FILL_CELL USING 1 1 1 'Flug'(001).
      PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
      PERFORM FILL_CELL USING 1 3 1 'Von'(003).
      PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
      PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
      LOOP AT IT_SPFLI.
    copy flights to active EXCEL sheet
        H = SY-TABIX + 1.
        PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
        PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
        PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
        PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
        PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
      ENDLOOP.
    changes by Kishore  - end
    disconnect from Excel
         CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING  #1 = 'C:\SKV.XLS'.
      FREE OBJECT H_EXCEL.
      PERFORM ERR_HDL.
          FORM FILL_CELL                                                *
          sets cell at coordinates i,j to value val boldtype bold       *
    FORM FILL_CELL USING I J BOLD VAL.
      CALL METHOD OF H_EXCEL 'Cells' = H_ZL EXPORTING #1 = I #2 = J.
      PERFORM ERR_HDL.
      SET PROPERTY OF H_ZL 'Value' = VAL .
      PERFORM ERR_HDL.
      GET PROPERTY OF H_ZL 'Font' = H_F.
      PERFORM ERR_HDL.
      SET PROPERTY OF H_F 'Bold' = BOLD .
      PERFORM ERR_HDL.
    ENDFORM.
    *&      Form  ERR_HDL
          outputs OLE error if any                                       *
    -->  p1        text
    <--  p2        text
    FORM ERR_HDL.
    IF SY-SUBRC <> 0.
      WRITE: / 'Fehler bei OLE-Automation:'(010), SY-SUBRC.
      STOP.
    ENDIF.
    ENDFORM.                    " ERR_HDL
    Please note that this example maybe slow at filling the excel table
    (perhaps four fields per second on a 900 MHz machine - almost 30 seconds
    for a short example).
    To get the data on properties and methods - there is a bit of smoke and mirrors
    going on here; they are EXCEL properties and methods, not sap ones - so you need
    to look at excel help to determine how a particular function is structured. then
    build the block in sap, as shown in the example.
    If you only want to transfer the data to Excel like when you transfer the data from
    ALV to Excel simply use the Function Modules:
    XXL_SIMPLE_API
    If you want more modifications when you transfer it to Excel use:
    XXL_FULL_API

  • Running the alv report  in  background and sending it thro email

    hi,
          i have to run the  alv report in background and send the output through email

    Hi
    Many a times there is a requirement to display ALV Grid (not ALV List) in the background Job. I have checked the SDN Forum for the same and it has been mentioned that ALV Grid cannot be displayed in Background, but the list output of ALV is possible. So user won’t have the actual Grid interface but the List interface.
    There is a workaround to display ALV Grid in Background Job. The only restriction is you can’t schedule the job through SM36. You need to execute the transaction of the report program, fill in the selection screen data and hit Execute.
    The job would be executed in background. User will be able to see the Job Log and Job Status after executing the program. User doesn’t have to go to SM37 to view the job status/log. Once the Job Status is changed to “COMPLETED”, user can click on “DISPLAY SPOOL” to view the ALV Grid.
    Limitations:
    Can’t schedulea background job
    The session should be active until the background job is completed. If the session is closed, then user won’t be able to check the output in ALV Grid. User would be able to check the output through spool or SM37
    Advantages:
    If the spool width is greater than 255 characters, then the entire width could be seen in the output because the output is directed to an ALV Grid and not to spool
    Interface of ALV Grid is available instead of ALV List even though it’s a background job.
    Program won’t give the TIME OUT error
    Steps Required:
    1. Once you execute the program, the following screen would be displayed
    2. Click “Display Job Status” to check the Status of the Background Job
    3. Click on “Display the Job Log” to check the Log
    4. Click on “Display Job Status” to check the Job Status
    5. Click on “DISPLAY SPOOL” to check the spool content once the Job Status is changed to “COMPLETED”. Output is displayed in ALV Grid
    Programs:
    1.  Two different programs needs to be created
    ZPROGRAM_ONE: This is the 1st program, where the selection screen and all the data validations would be done. Error handling for invalid data should be done in this program.
    Once the data validation is done, this program would call the 2nd program ZPROGEAM_TWO. Build the logic to display ALV Grid in this program. The logic will only display ALV in foreground and it won’t be reflected in the spool.
    ZPROGRAM_TWO: This program would fetch all the data and do all the processing. If you want the spool output along with ALV Grid output, then build the logic in this program to display ALV Grid.
    *& Report  ZPROGRAM_ONE                                                *
    REPORT  zprogram_one                            .
    PRASHANT PATIL
    TABLES : mara,
             tsp01.
    type-pools:slis.
    TYPES : BEGIN OF t_mara,
              matnr   TYPE mara-matnr,
              ersda   TYPE mara-ersda,
              ernam   TYPE mara-ernam,
              laeda   TYPE mara-laeda,
            END OF t_mara.
    DATA : i_mara       TYPE STANDARD TABLE OF t_mara,
           wa_mara      TYPE t_mara,
           wa_index     TYPE indx,        " For Index details
           wa_index_key TYPE indx-srtfd VALUE 'PRG_ONE',
           i_jobsteplist     TYPE STANDARD TABLE OF tbtcstep, " For spool number
           wa_params         TYPE pri_params,  " To Get Print Parameters
           wa_jobhead        TYPE tbtcjob,     " To know the status of job
           wa_jobsteplist    TYPE tbtcstep,    " To know the spool
           w_jobname         TYPE tbtco-jobname,  " Job name for bckgrnd job
           w_jobcount        TYPE tbtco-jobcount, " Unique id for bckgrd job
           w_path            TYPE string,         " Upload path
           w_lsind           TYPE sy-lsind,       " Index
           wa_seltab         TYPE rsparams,
           i_seltab          TYPE STANDARD TABLE OF rsparams,
           wa_index1         TYPE indx,        " For Index details
           wa_index_key1     TYPE indx-srtfd VALUE 'PRG_TWO',
           i_fieldcat        TYPE slis_t_fieldcat_alv,
           wa_fieldcat       LIKE LINE OF i_fieldcat.
            CONSTANTS DECLARATION                                        *
    CONSTANTS :
             c_a(1) TYPE c VALUE 'A',
             c_m(1) TYPE c VALUE 'M',
             c_l(1) TYPE c VALUE 'L',
             c_c(1) TYPE c VALUE 'C',
             c_zfdr(4) TYPE c VALUE 'ZFDR',
             c_x(1)    TYPE c VALUE 'X',
             c_locl(4) TYPE c VALUE 'LOCL', " Destination is LOCAL
             c_f(1)    TYPE c VALUE 'F',   " Job Status - Failed
             c_s(1)    TYPE c VALUE 'S',
             c_p(1)    TYPE c VALUE 'P'.
    SELECTION SCREEN PARAMETERS
    SELECT-OPTIONS : s_matnr FOR mara-matnr.
    START-OF-SELECTION.
    Before the export, fill the data fields before CLUSTR
      wa_index-aedat = sy-datum.
      wa_index-usera = sy-uname.
      EXPORT s_matnr
           TO DATABASE indx(st) FROM wa_index ID wa_index_key.
    To Open the Job for background processing
      PERFORM open_job.
    To get the print parameters
      PERFORM get_print_parameters.
    Submit the job in background
      PERFORM job_submit.
    Close the background job
      PERFORM job_close.
    This is the output screen with the buttons ********
    Create 3 buttons DISPLAY SPOOL, STATUS, JOBLOG
      SET PF-STATUS 'ZS001'.
      WRITE: / 'The program is submitted in Background'.
      WRITE: / 'Press DISPLAY SPOOL to see the spool'.
      WRITE: / 'Press STATUS to see the status of the background'.
    AT USER-COMMAND.
    If user presses the 'BACK' button
      IF sy-ucomm = 'BAK'.
        IF  wa_jobhead-status = c_f OR
            wa_jobhead-status = c_a.
          LEAVE TO SCREEN 0.
        ENDIF.
      ENDIF.
    If the user presses the 'DISPLAY SPOOL' Button
      IF sy-ucomm = 'DISPLAY'.
        PERFORM display_spool.
      ENDIF.
    If the user presses the 'JOB STATUS' Button
      IF sy-ucomm = 'STATUS'.
        PERFORM display_status.
      ENDIF.
    If the user presses the 'JOB LOG' Button
      IF sy-ucomm = 'JOBLOG'.
        PERFORM display_job_log.
      ENDIF.
    *&      Form  open_job
          text
    -->  p1        text
    <--  p2        text
    FORM open_job .
    This is to Create a new job which is to be submitted in background to
    process sales order/delivery/invoice
    Here we would get a unique id ( Jobcount ) which identifies our job
    along with the job name which we have assigned to our job
      CONCATENATE sy-uname
                  sy-datum
                  sy-uzeit
                          INTO w_jobname .  " Assign unique jobname
      CALL FUNCTION 'JOB_OPEN'
       EXPORTING
      DELANFREP              = ' '
      JOBGROUP               = ' '
        jobname                = w_jobname
      SDLSTRTDT              = NO_DATE
      SDLSTRTTM              = NO_TIME
      JOBCLASS               =
      IMPORTING
       jobcount                = w_jobcount
    CHANGING
      RET                    =
    EXCEPTIONS
       cant_create_job        = 1
       invalid_job_data       = 2
       jobname_missing        = 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.
    ENDFORM.                    " open_job
    *&      Form  get_print_parameters
          text
    -->  p1        text
    <--  p2        text
    FORM get_print_parameters .
      DATA : l_valid TYPE c.
    This is to get the Print Parameters for the job which is to be
    submitted in background to process sales order/delivery/invoice
      CALL FUNCTION 'GET_PRINT_PARAMETERS'
       EXPORTING
      ARCHIVE_ID                   = C_CHAR_UNKNOWN
      ARCHIVE_INFO                 = C_CHAR_UNKNOWN
      ARCHIVE_MODE                 = C_CHAR_UNKNOWN
      ARCHIVE_TEXT                 = C_CHAR_UNKNOWN
      AR_OBJECT                    = C_CHAR_UNKNOWN
      ARCHIVE_REPORT               = C_CHAR_UNKNOWN
      AUTHORITY                    = C_CHAR_UNKNOWN
      COPIES                       = C_NUM3_UNKNOWN
      COVER_PAGE                   = C_CHAR_UNKNOWN
      DATA_SET                     = C_CHAR_UNKNOWN
      DEPARTMENT                   = C_CHAR_UNKNOWN
          destination                  = c_locl " LOCL
      EXPIRATION                   = C_NUM1_UNKNOWN
          immediately                  = space
      IN_ARCHIVE_PARAMETERS        = ' '
      IN_PARAMETERS                = ' '
      LAYOUT                       = C_CHAR_UNKNOWN
      LINE_COUNT                   = C_INT_UNKNOWN
      LINE_SIZE                    = C_INT_UNKNOWN
      LIST_NAME                    = C_CHAR_UNKNOWN
      LIST_TEXT                    = C_CHAR_UNKNOWN
      MODE                         = ' '
          new_list_id                  = c_x
      PROTECT_LIST                 = C_CHAR_UNKNOWN
          no_dialog                    = c_x
      RECEIVER                     = C_CHAR_UNKNOWN
      RELEASE                      = C_CHAR_UNKNOWN
      REPORT                       = C_CHAR_UNKNOWN
      SAP_COVER_PAGE               = C_CHAR_UNKNOWN
      HOST_COVER_PAGE              = C_CHAR_UNKNOWN
      PRIORITY                     = C_NUM1_UNKNOWN
      SAP_OBJECT                   = C_CHAR_UNKNOWN
      TYPE                         = C_CHAR_UNKNOWN
          user                         = sy-uname
      USE_OLD_LAYOUT               = ' '
      UC_DISPLAY_MODE              = C_CHAR_UNKNOWN
      DRAFT                        = C_CHAR_UNKNOWN
      ABAP_LIST                    = ' '
      USE_ARCHIVENAME_DEF          = ' '
      DEFAULT_SPOOL_SIZE           = C_CHAR_UNKNOWN
      PO_FAX_STORE                 = ' '
      NO_FRAMES                    = C_CHAR_UNKNOWN
       IMPORTING
      OUT_ARCHIVE_PARAMETERS       =
          out_parameters               = wa_params
       valid                        = l_valid
       EXCEPTIONS
         archive_info_not_found       = 1
         invalid_print_params         = 2
         invalid_archive_params       = 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.
    ENDFORM.                    " get_print_parameters
    *&      Form  job_submit
          text
    -->  p1        text
    <--  p2        text
    FORM job_submit .
    The job which we have created & the unique id ( jobcount ) which we
    have got identifies our job. Hence those parameters are passed along
    with the name of the background program "ZPROGRAM_TWO"
    The job is submitted in background.
      CALL FUNCTION 'JOB_SUBMIT'
        EXPORTING
      ARCPARAMS                         =
        authcknam                         = sy-uname
      COMMANDNAME                       = ' '
      OPERATINGSYSTEM                   = ' '
      EXTPGM_NAME                       = ' '
      EXTPGM_PARAM                      = ' '
      EXTPGM_SET_TRACE_ON               = ' '
      EXTPGM_STDERR_IN_JOBLOG           = 'X'
      EXTPGM_STDOUT_IN_JOBLOG           = 'X'
      EXTPGM_SYSTEM                     = ' '
      EXTPGM_RFCDEST                    = ' '
      EXTPGM_WAIT_FOR_TERMINATION       = 'X'
        jobcount                          = w_jobcount
        jobname                           = w_jobname
      LANGUAGE                          = SY-LANGU
        priparams                         = wa_params
        report                            = 'ZPROGRAM_TWO'
      VARIANT                           = ' '
    IMPORTING
      STEP_NUMBER                       =
       EXCEPTIONS
         bad_priparams                     = 1
         bad_xpgflags                      = 2
         invalid_jobdata                   = 3
         jobname_missing                   = 4
         job_notex                         = 5
         job_submit_failed                 = 6
         lock_failed                       = 7
         program_missing                   = 8
         prog_abap_and_extpg_set           = 9
         OTHERS                            = 10
      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.                    " job_submit
    *&      Form  job_close
          text
    -->  p1        text
    <--  p2        text
    FORM job_close .
    Once the job is submitted in background then the job is closed
      CALL FUNCTION 'JOB_CLOSE'
        EXPORTING
      AT_OPMODE                         = ' '
      AT_OPMODE_PERIODIC                = ' '
      CALENDAR_ID                       = ' '
      EVENT_ID                          = ' '
      EVENT_PARAM                       = ' '
      EVENT_PERIODIC                    = ' '
        jobcount                          = w_jobcount
        jobname                           = w_jobname
      LASTSTRTDT                        = NO_DATE
      LASTSTRTTM                        = NO_TIME
      PRDDAYS                           = 0
      PRDHOURS                          = 0
      PRDMINS                           = 0
      PRDMONTHS                         = 0
      PRDWEEKS                          = 0
      PREDJOB_CHECKSTAT                 = ' '
      PRED_JOBCOUNT                     = ' '
      PRED_JOBNAME                      = ' '
      SDLSTRTDT                         = NO_DATE
      SDLSTRTTM                         = NO_TIME
      STARTDATE_RESTRICTION             = BTC_PROCESS_ALWAYS
        strtimmed                         = c_x
      TARGETSYSTEM                      = ' '
      START_ON_WORKDAY_NOT_BEFORE       = SY-DATUM
      START_ON_WORKDAY_NR               = 0
      WORKDAY_COUNT_DIRECTION           = 0
      RECIPIENT_OBJ                     =
      TARGETSERVER                      = ' '
      DONT_RELEASE                      = ' '
      TARGETGROUP                       = ' '
      DIRECT_START                      =
    IMPORTING
      JOB_WAS_RELEASED                  =
    CHANGING
      RET                               =
       EXCEPTIONS
         cant_start_immediate              = 1
         invalid_startdate                 = 2
         jobname_missing                   = 3
         job_close_failed                  = 4
         job_nosteps                       = 5
         job_notex                         = 6
         lock_failed                       = 7
         invalid_target                    = 8
         OTHERS                            = 9
      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.                    " job_close
    *&      Form  display_spool
          text
    -->  p1        text
    <--  p2        text
    FORM display_spool .
    To Read the Job to get the spool details
      DATA : l_rqident TYPE tsp01-rqident, " Spool Number
             l_spoolno TYPE tsp01_sp0r-rqid_char.
      CLEAR : l_rqident,
              w_lsind,
              wa_jobsteplist.
      REFRESH : i_jobsteplist.
      SET PF-STATUS 'ZAR02'.
    Get the Spool Number
      CALL FUNCTION 'BP_JOB_READ'
        EXPORTING
          job_read_jobcount           = w_jobcount
          job_read_jobname            = w_jobname
          job_read_opcode             = '20'
        JOB_STEP_NUMBER             =
       IMPORTING
         job_read_jobhead            = wa_jobhead
       TABLES
         job_read_steplist           = i_jobsteplist
    CHANGING
       RET                         =
       EXCEPTIONS
         invalid_opcode              = 1
         job_doesnt_exist            = 2
         job_doesnt_have_steps       = 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.
    Read the Job Step list to get the spool number
      READ TABLE i_jobsteplist INTO wa_jobsteplist INDEX 1.
      CHECK wa_jobsteplist-listident <> space.
    Spool Number
      l_rqident = wa_jobsteplist-listident.
      MOVE l_rqident TO l_spoolno.
    Check the spool in TSP01
      SELECT SINGLE * FROM tsp01 WHERE rqident = l_rqident.
      IF  sy-subrc = 0.
        LEAVE TO LIST-PROCESSING.
        CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
          EXPORTING
            spoolid       = l_spoolno
        IMPORTING
          RC            =
          STATUS        =
        PERFORM show_alv.
      ENDIF.
      w_lsind = sy-lsind.
      IF sy-lsind GE 19.
        sy-lsind = 1.
      ENDIF.
    ENDFORM.                    " display_spool
    *&      Form  show_alv
          text
    -->  p1        text
    <--  p2        text
    FORM show_alv .
    Before the import, fill the data fields before CLUSTR.
      wa_index1-aedat = sy-datum.
      wa_index1-usera = sy-uname.
    To Import the selection screen data from Calling Program
      IMPORT i_mara
      FROM DATABASE indx(st) ID wa_index_key1 TO wa_index1.
      FREE MEMORY ID wa_index_key1.
    This prepares the field-catalog for ALV.
      PERFORM prepare_fieldcatalog.
    This displays the output in  ALV format .
      PERFORM display_alv.
    ENDFORM.                    " show_alv
    *&      Form  display_status
          text
    -->  p1        text
    <--  p2        text
    FORM display_status .
    To Display the STATUS of the JOB which is exectued in background
      CLEAR : wa_jobsteplist.
      REFRESH : i_jobsteplist.
      WRITE:/ 'DISPLAYING JOB STATUS'.
      CALL FUNCTION 'BP_JOB_READ'
        EXPORTING
          job_read_jobcount           = w_jobcount
          job_read_jobname            = w_jobname
          job_read_opcode             = '20'
        JOB_STEP_NUMBER             =
       IMPORTING
         job_read_jobhead            = wa_jobhead
       TABLES
         job_read_steplist           = i_jobsteplist
    CHANGING
       RET                         =
       EXCEPTIONS
         invalid_opcode              = 1
         job_doesnt_exist            = 2
         job_doesnt_have_steps       = 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.
    To Display the status text as per the status type
      CASE wa_jobhead-status.
        WHEN 'S'. WRITE: / 'Scheduled'.
        WHEN 'R'. WRITE: / 'Released'.
        WHEN 'F'. WRITE: / 'Completed'.
        WHEN 'A'. WRITE: / 'Cancelled'.
        WHEN OTHERS.
      ENDCASE.
      IF sy-lsind GE 19.
        sy-lsind = 1.
      ENDIF.
    ENDFORM.                    " display_status
    *&      Form  display_job_log
          text
    -->  p1        text
    <--  p2        text
    FORM display_job_log .
    To display the log of the background program
      LEAVE TO LIST-PROCESSING.
      CALL FUNCTION 'BP_JOBLOG_SHOW_SM37B'
        EXPORTING
          client                    = sy-mandt
          jobcount                  = w_jobcount
          joblogid                  = ' '
          jobname                   = w_jobname
        EXCEPTIONS
          error_reading_jobdata     = 1
          error_reading_joblog_data = 2
          jobcount_missing          = 3
          joblog_does_not_exist     = 4
          joblog_is_empty           = 5
          joblog_show_canceled      = 6
          jobname_missing           = 7
          job_does_not_exist        = 8
          no_joblog_there_yet       = 9
          no_show_privilege_given   = 10
          OTHERS                    = 11.
      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_job_log
    *&      Form  prepare_fieldcatalog
          text
    -->  p1        text
    <--  p2        text
    FORM prepare_fieldcatalog .
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname    = 'MATNR'.
      wa_fieldcat-tabname      = 'I_MARA'.
      wa_fieldcat-reptext_ddic = 'Material no.'.
      wa_fieldcat-outputlen    = '18'.
      APPEND wa_fieldcat TO i_fieldcat.
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname    = 'ERSDA'.
      wa_fieldcat-tabname      = 'I_MARA'.
      wa_fieldcat-reptext_ddic = 'Creation date'.
      wa_fieldcat-outputlen    = '10'.
      APPEND  wa_fieldcat TO i_fieldcat.
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname    = 'ERNAM'.
      wa_fieldcat-tabname      = 'I_MARA'.
      wa_fieldcat-reptext_ddic = 'Name of Person'.
      wa_fieldcat-outputlen    = '10'.
      APPEND wa_fieldcat TO i_fieldcat.
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname    = 'LAEDA'.
      wa_fieldcat-tabname      = 'I_MARA'.
      wa_fieldcat-reptext_ddic = ' Last Change'.
      wa_fieldcat-outputlen    = '10'.
      APPEND  wa_fieldcat TO i_fieldcat.
    ENDFORM.                    " prepare_fieldcatalog
    *&      Form  display_alv
          text
    -->  p1        text
    <--  p2        text
    FORM display_alv .
    Call ABAP List Viewer (ALV)
      call function 'REUSE_ALV_GRID_DISPLAY'
        exporting
          it_fieldcat  = i_fieldcat
        tables
          t_outtab     = i_mara.
    ENDFORM.                    " display_alv
    •     ZPROGRAM_TWO: This is the 2nd program which would be called from program ZPROGRAM_ONE.
    *& Report  ZPROGRAM_TWO                                                *
    REPORT  zprogram_two                            .
    PRASHANT PATIL
    TABLES : mara.
    TYPE-POOLS:slis.
    TYPES : BEGIN OF t_mara,
              matnr   TYPE mara-matnr,
              ersda   TYPE mara-ersda,
              ernam   TYPE mara-ernam,
              laeda   TYPE mara-laeda,
            END OF t_mara.
    DATA : i_mara        TYPE STANDARD TABLE OF t_mara,
           wa_mara       TYPE t_mara,
           wa_index      TYPE indx,        " For Index details
           wa_index_key  TYPE indx-srtfd VALUE 'PRG_ONE',
           wa_index1     TYPE indx,        " For Index details
           wa_index_key1 TYPE indx-srtfd VALUE 'PRG_TWO',
           i_fieldcat        TYPE slis_t_fieldcat_alv,
           wa_fieldcat       LIKE LINE OF i_fieldcat.
    SELECT-OPTIONS : s_matnr FOR mara-matnr.
    Before the import, fill the data fields before CLUSTR.
    wa_index-aedat = sy-datum.
    wa_index-usera = sy-uname.
    To Import the selection screen data from Calling Program
    IMPORT s_matnr
    FROM DATABASE indx(st) ID wa_index_key TO wa_index.
    FREE MEMORY ID wa_index_key.
    SELECT matnr
           ersda
           ernam
           laeda
           FROM mara
           INTO TABLE i_mara
           WHERE matnr IN s_matnr.
    PERFORM prepare_fieldcatalog.
    PERFORM display_alv.
    Before the export, fill the data fields before CLUSTR
    wa_index1-aedat = sy-datum.
    wa_index1-usera = sy-uname.
    EXPORT i_mara
    TO DATABASE indx(st) FROM wa_index1 ID wa_index_key1.
    *&      Form  prepare_fieldcatalog
          text
    -->  p1        text
    <--  p2        text
    FORM prepare_fieldcatalog .
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname    = 'MATNR'.
      wa_fieldcat-tabname      = 'I_MARA'.
      wa_fieldcat-outputlen    = '18'.
      APPEND wa_fieldcat TO i_fieldcat.
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname    = 'ERSDA'.
      wa_fieldcat-tabname      = 'I_MARA'.
      wa_fieldcat-outputlen    = '10'.
      APPEND  wa_fieldcat TO i_fieldcat.
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname    = 'ERNAM'.
      wa_fieldcat-tabname      = 'I_MARA'.
      wa_fieldcat-outputlen    = '10'.
      APPEND wa_fieldcat TO i_fieldcat.
      CLEAR wa_fieldcat.
      wa_fieldcat-fieldname    = 'LAEDA'.
      wa_fieldcat-tabname      = 'I_MARA'.
      wa_fieldcat-outputlen    = '10'.
      APPEND  wa_fieldcat TO i_fieldcat.
    ENDFORM.                    " prepare_fieldcatalog
    *&      Form  display_alv
          text
    -->  p1        text
    <--  p2        text
    FORM display_alv .
    Call ABAP List Viewer (ALV)
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          it_fieldcat = i_fieldcat
        TABLES
          t_outtab    = i_mara.
    ENDFORM.                    " display_alv
    its possible to display ALV Grid using OO ALV. Following code can be used instead of FM.
    In the PBO, add following code
    SET PF-STATUS 'ZSTAT'.
    If program is executed in background
    CALL METHOD cl_gui_alv_grid=>offline
    RECEIVING
    e_offline = off.
    IF off IS INITIAL.
    IF container1 IS INITIAL.
    CREATE OBJECT container1
    EXPORTING
    container_name = 'CC_ALV1' .
    ENDIF.
    ENDIF.
    CREATE OBJECT g_grid1
    EXPORTING
    i_parent = container1.
    CALL METHOD g_grid1->set_table_for_first_display
    EXPORTING
    I_BUFFER_ACTIVE =
    I_BYPASSING_BUFFER =
    I_CONSISTENCY_CHECK =
    I_STRUCTURE_NAME =
    IS_VARIANT =
    i_save = 'A'
    i_default = ' '
    is_layout =
    is_print =
    IT_SPECIAL_GROUPS =
    it_toolbar_excluding =
    IT_HYPERLINK =
    IT_ALV_GRAPHICS =
    IT_EXCEPT_QINFO =
    CHANGING
    it_outtab = i_output
    it_fieldcatalog = i_fieldcatalog
    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.
    Reward points if useful
    Regards
    Anji

Maybe you are looking for

  • I have an iPad 2 and would like to know how to download photos on iPad to an external memory card for printing purposes

    I have an iPad 2 and have quite a lot of photos stored on the device. I would like to be able to download them onto an SD Card or a memory stick which would then allow me to go to a print shop and print out some hard copy prints of the photos I requi

  • Suggestions please

    Hi Everyone, May be if I explain it in detail someone can suggest something. This involves Oracle Label Security tables. I’m taking the results from a PL/SQL table which is a single column one dimensional array and using those results as variables to

  • Local Webauth WLC using radius database

    Hi all, I was implement local Webauth WLC not using local auth . I use radius database. at least I try to add on my  WLAN: layer 3 web auth  authentication layer 2 security is WPA/WPA2 PSK adding aaa radius server aaa radius "network user" check list

  • OBIEE, default users?

    Dear Experts, My server is: Redhat Linux 5.5 64 bit I've managed to install OBIEE on this server and it seems to be running ok. This was done in stages: create schemas in the database with RCU install weblogic install OBIEE, software only I can go to

  • MacMini server used as regular computer ?

    I love the specs on the new MacMini server, and want to buy one. I see it comes with server software, and I know absolutely nothing about the Lion server software. I want to use this MacMini as a regular computer - I want to use it's first hard drive