Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ALV class method?

Former Member
0 Kudos
119

Hi, can anybody gve material or sample code for ALV class method?

Also can anybody gve material to edit ALV output?

4 REPLIES 4

Former Member
0 Kudos
67

Hi Abhay,

Check the following link

http://sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/abap/an%20easy%20refere...

Check the following example.


*&---------------------------------------------------------------------*
*& Report  ZALVSAVEUPDATE                                              *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZALVCUSTOMERDISP                                              .
INCLUDE <icon>.

CLASS Lcl_application  DEFINITION DEFERRED.

data : g_alv           type ref to cl_gui_alv_grid,
        gref_docking_container TYPE REF TO cl_gui_custom_container,
        gs_layout TYPE lvc_s_layo.

data :event_receiver TYPE REF TO lcl_application,
      gt_fieldcat type lvc_t_fcat,
      gs_fieldcat type lvc_s_fcat.


DATA:gt_outtab type table of SFLIGHT.

data : gs_outtab like line of gt_outtab.

call screen 100.


************************************************************************
CLASS lcl_application DEFINITION.

  PUBLIC SECTION.

    METHODS:
    handle_toolbar
        FOR EVENT toolbar OF cl_gui_alv_grid
            IMPORTING e_object e_interactive,

    handle_user_command
        FOR EVENT user_command OF cl_gui_alv_grid
            IMPORTING e_ucomm.


ENDCLASS.                              "lcl_application DEFINITION


CLASS lcl_application IMPLEMENTATION.

  METHOD handle_toolbar.

    DATA: ls_toolbar  TYPE stb_button.

* append a separator to normal toolbar
    CLEAR ls_toolbar.
    MOVE 3 TO ls_toolbar-butn_type.
    APPEND ls_toolbar TO e_object->mt_toolbar.

* append an icon to show booking table
    CLEAR ls_toolbar.
    MOVE 'ADD' TO ls_toolbar-function.
    MOVE icon_insert_row TO ls_toolbar-icon.
    MOVE 'Add RFC info'(111) TO ls_toolbar-quickinfo.
    MOVE  space TO ls_toolbar-text.
    MOVE ' ' TO ls_toolbar-disabled.
    APPEND ls_toolbar TO e_object->mt_toolbar.

  ENDMETHOD.

   METHOD handle_user_command.

    DATA: lt_rows TYPE lvc_t_row.

    CASE e_ucomm.
      WHEN 'ADD'.
       gs_outtab-CARRID = SPACE.
       gs_outtab-CONNID = space.
       gs_outtab-FLDATE = space.
        append  gs_outtab to gt_outtab.

            CALL METHOD g_alv->refresh_table_display
                    .


    ENDCASE.
  ENDMETHOD.                           "handle_user_command

endclass.
************************************************************************



*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.

*data : lt_sflight type table of sflight,
*       ls_sflight like line of lt_sflight.
*
  SET PF-STATUS 'STAT'.
*  SET TITLEBAR 'xxx'.
  create object gref_docking_container
       exporting
         container_name = 'CCAREA_ALV'.

  create object g_alv
     exporting i_parent = GREF_DOCKING_CONTAINER.



  select * from SFLIGHT into table GT_OUTTAB.

  gs_fieldcat-fieldname = 'CARRID'.
  gs_fieldcat-ref_table = 'SFLIGHT'.
  gs_fieldcat-edit       = 'X'.
  gs_fieldcat-key = 'X'.
  append gs_fieldcat to gt_fieldcat.

  gs_fieldcat-fieldname = 'CONNID'.
  gs_fieldcat-ref_table = 'SFLIGHT'.
  gs_fieldcat-edit       = 'X'.
  gs_fieldcat-key = 'X'.
  append gs_fieldcat to gt_fieldcat.

  gs_fieldcat-fieldname = 'FLDATE'.
  gs_fieldcat-ref_table = 'SFLIGHT'.
  gs_fieldcat-edit       = 'X'.
  gs_fieldcat-key = 'X'.
  append gs_fieldcat to gt_fieldcat.

  gs_layout-grid_title = 'TEST'.



    call method g_ALV->set_table_for_first_display
         exporting                     " i_buffer_active = 'X'
*                   i_save = 'A'
*                   is_variant = gs_variant
                   is_layout  = gs_layout
         changing  it_fieldcatalog = gt_fieldcat
*                   it_sort = gt_sort
                   it_outtab        = gt_outtab[].


*** addition button on alv
    CREATE OBJECT event_receiver.
    SET HANDLER event_receiver->handle_user_command FOR g_alv.
    SET HANDLER event_receiver->handle_toolbar FOR g_alv.

call method g_alv->register_edit_event exporting
                             i_event_id =
                 cl_gui_alv_grid=>mc_evt_modified.

*  Call method 'set_toolbar_interactive' to raise event TOOLBAR.
    CALL METHOD g_alv->set_toolbar_interactive.


ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
data : ok_code type sy-ucomm.

case ok_code.
  when 'BACK'.
     LEAVE TO SCREEN 0.
endcase.
ENDMODULE.                 " USER_COMMAND_0100  INPUT

hope this helps.

Regards,

Kinshuk

raguraman_c
Active Contributor
0 Kudos
67

Hi,

Check this link, a very good guide for OO ALV, Please check page 47, to make ALV editable.

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a41...

Hope this will help in solving your problem.

Feel free to revert back.

--Ragu

sourabhshah
Advisor
Advisor
0 Kudos
67

hi,

you will find a lot of sample programs on ALV both with reuse library and also for class based ALV in Development Class "SLIS".You can also search for programs using BCALV* as search criteria.

You can find a lot of resource on help.sap.com.The link below will also help you.

http://help.sap.com/saphelp_nw04/helpdata/en/66/88d440e14f8431e10000000a1550b0/frameset.htm

Former Member
0 Kudos
67

Hi,

TYPE-POOLS : SLIS.

 

*----


*

  • Tables *

*----


*

TABLES:

VBRK,

VBRP.

*----


*

  • Parameters and select options OR SELECTION SCREEN

*----


*

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

SELECT-OPTIONS:

S_VBELN FOR VBRK-VBELN.

SELECTION-SCREEN END OF BLOCK B1.

 

*----


*

  • Internal Tables *

*----


*

  • work areas

DATA: BEGIN OF IT_VBRP OCCURS 0,

VBELN LIKE VBRK-VBELN,

POSNR LIKE VBRP-POSNR,

UEPOS LIKE VBRP-UEPOS,

FKIMG LIKE VBRP-FKIMG,

NETWR LIKE VBRP-NETWR,

MEINS LIKE VBRP-MEINS.

DATA : END OF IT_VBRP.

 

*----


*

  • Variables *

*----


*

DATA : GR_ALVGRID TYPE REF TO CL_GUI_ALV_GRID,

GC_CUSTOM_CONTROL_NAME TYPE SCRFNAME VALUE 'CC_ALV',

GR_CCONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,

GT_FIELDCAT TYPE LVC_T_FCAT,

GS_LAYOUT TYPE LVC_S_LAYO,

V_FLAG VALUE 'X'.

 

***********************************************************************

  • Start of Program *

***********************************************************************

 

*----


*

  • INITIALIZATION. *

*----


*

INITIALIZATION.

*----


*

S_VBELN-LOW = 1.

S_VBELN-HIGH = 1000000000.

S_VBELN-OPTION = 'EQ'.

S_VBELN-SIGN = 'I'.

APPEND S_VBELN.

*----


*

  • SELECTION-SCREEN *

*----


*

AT SELECTION-SCREEN.

*----


*

PERFORM VALIDATION.

*----


*

  • START-OF-SELECTION *

*----


*

START-OF-SELECTION.

*----


*

 

PERFORM GET_DATA.

CALL SCREEN 0100.

 

 

 

 

 

*----


*

  • END-OF-SELECTION *

*----


*

END-OF-SELECTION.

*----


*

 

 

 

*----


*

  • TOP-OF-PAGE *

*----


*

TOP-OF-PAGE.

*----


*

 

 

 

*----


*

  • END-OF-PAGE *

*----


*

END-OF-PAGE.

*----


*

 

 

 

 

*----


*

  • AT USER-COMMAND *

 

*&----


*

*& Form VALIDATION

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM VALIDATION .

SELECT SINGLE VBELN

FROM VBRK

INTO VBRK-VBELN

WHERE VBELN IN S_VBELN.

 

IF SY-SUBRC <> 0.

MESSAGE E000 WITH 'no billing documents found'.

ENDIF.

ENDFORM. " VALIDATION

*&----


*

*& Form GET_DATA

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM GET_DATA .

SELECT VBELN

POSNR

UEPOS

FKIMG

NETWR

MEINS

FROM VBRP

INTO TABLE IT_VBRP

WHERE VBELN IN S_VBELN.

ENDFORM. " GET_DATA

*&----


*

*& Module DISPLAY_ALV OUTPUT

*&----


*

  • text

*----


*

MODULE DISPLAY_ALV OUTPUT.

 

IF V_FLAG = 'X'.

 

PERFORM DISPLAY_ALV.

PERFORM PREPARE_FIELD_CATALOG CHANGING GT_FIELDCAT.

PERFORM PREPARE_LAYOUT CHANGING GS_LAYOUT.

CALL METHOD GR_ALVGRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

  • I_BUFFER_ACTIVE =

  • I_BYPASSING_BUFFER =

  • I_CONSISTENCY_CHECK =

  • I_STRUCTURE_NAME = 'VBRP'

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

IS_LAYOUT = GS_LAYOUT

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

CHANGING

IT_OUTTAB = IT_VBRP[]

IT_FIELDCATALOG = GT_FIELDCAT

  • IT_SORT =

  • IT_FILTER =

EXCEPTIONS

INVALID_PARAMETER_COMBINATION = 1

PROGRAM_ERROR = 2

TOO_MANY_LINES = 3

OTHERS = 4

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

 

CALL METHOD GR_ALVGRID->SET_READY_FOR_INPUT

EXPORTING

I_READY_FOR_INPUT = 1.

 

ELSE.

CALL METHOD GR_ALVGRID->REFRESH_TABLE_DISPLAY

  • EXPORTING

  • IS_STABLE =

  • I_SOFT_REFRESH =

EXCEPTIONS

FINISHED = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDIF.

CLEAR V_FLAG.

ENDIF.

ENDMODULE. " DISPLAY_ALV OUTPUT

*&----


*

*& Form DISPLAY_ALV

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM DISPLAY_ALV .

IF GR_ALVGRID IS INITIAL.

CREATE OBJECT GR_ALVGRID

EXPORTING

  • I_SHELLSTYLE = 0

  • I_LIFETIME =

I_PARENT = GR_CCONTAINER

  • I_APPL_EVENTS = space

  • I_PARENTDBG =

  • I_APPLOGPARENT =

  • I_GRAPHICSPARENT =

  • I_NAME =

EXCEPTIONS

ERROR_CNTL_CREATE = 1

ERROR_CNTL_INIT = 2

ERROR_CNTL_LINK = 3

ERROR_DP_CREATE = 4

OTHERS = 5

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

 

ENDIF.

ENDFORM. " DISPLAY_ALV

*&----


*

*& Form PREPARE_FIELD_CATALOG

*&----


*

  • text

*----


*

  • <--P_GT_FIELDCAT text

*----


*

FORM PREPARE_FIELD_CATALOG CHANGING P_GT_FIELDCAT TYPE LVC_T_FCAT.

 

DATA : LS_FCAT TYPE LVC_S_FCAT,

L_POS TYPE I.

 

L_POS = L_POS + 1.

 

LS_FCAT-FIELDNAME = 'VBELN'.

LS_FCAT-TABNAME = 'IT_VBRP'.

LS_FCAT-COL_POS = L_POS.

LS_FCAT-SCRTEXT_M = 'Billing Document'.

LS_FCAT-OUTPUTLEN = '10'.

APPEND LS_FCAT TO P_GT_FIELDCAT.

CLEAR LS_FCAT.

 

L_POS = L_POS + 1.

 

LS_FCAT-FIELDNAME = 'POSNR'.

LS_FCAT-TABNAME = 'IT_VBRP'.

LS_FCAT-COL_POS = L_POS.

LS_FCAT-SCRTEXT_M = 'Billing Item'.

LS_FCAT-OUTPUTLEN = '6'.

APPEND LS_FCAT TO P_GT_FIELDCAT.

CLEAR LS_FCAT.

 

L_POS = L_POS + 1.

 

LS_FCAT-FIELDNAME = 'UEPOS'.

LS_FCAT-TABNAME = 'IT_VBRP'.

LS_FCAT-COL_POS = L_POS.

LS_FCAT-SCRTEXT_M = 'Higher Level Item'.

LS_FCAT-OUTPUTLEN = '6'.

APPEND LS_FCAT TO P_GT_FIELDCAT.

CLEAR LS_FCAT.

 

L_POS = L_POS + 1.

 

LS_FCAT-FIELDNAME = 'FKIMG'.

LS_FCAT-TABNAME = 'IT_VBRP'.

LS_FCAT-COL_POS = L_POS.

LS_FCAT-SCRTEXT_M = 'Invoice Quantity'.

LS_FCAT-OUTPUTLEN = '13'.

APPEND LS_FCAT TO P_GT_FIELDCAT.

CLEAR LS_FCAT.

 

L_POS = L_POS + 1.

 

LS_FCAT-FIELDNAME = 'NETWR'.

LS_FCAT-TABNAME = 'IT_VBRP'.

LS_FCAT-COL_POS = L_POS.

LS_FCAT-SCRTEXT_M = 'Net Value'.

LS_FCAT-OUTPUTLEN = '15'.

APPEND LS_FCAT TO P_GT_FIELDCAT.

CLEAR LS_FCAT.

 

L_POS = L_POS + 1.

 

LS_FCAT-FIELDNAME = 'MEINS'.

LS_FCAT-TABNAME = 'IT_VBRP'.

LS_FCAT-COL_POS = L_POS.

LS_FCAT-SCRTEXT_M = 'Unit of Measure'.

LS_FCAT-OUTPUTLEN = '3'.

APPEND LS_FCAT TO P_GT_FIELDCAT.

CLEAR LS_FCAT.

 

L_POS = L_POS + 1.

 

 

 

 

ENDFORM. " PREPARE_FIELD_CATALOG

*&----


*

*& Form PREPARE_LAYOUT

*&----


*

  • text

*----


*

  • <--P_GS_LAYOUT text

*----


*

FORM PREPARE_LAYOUT CHANGING P_GS_LAYOUT TYPE LVC_S_LAYO.

P_GS_LAYOUT-ZEBRA = 'X'.

P_GS_LAYOUT-GRID_TITLE = 'INVOICE DETAILS'.

P_GS_LAYOUT-SMALLTITLE = 'X'.

P_GS_LAYOUT-EDIT = 'X'.

ENDFORM. " PREPARE_LAYOUT

*&----


*

*& Module STATUS_0100 OUTPUT

*&----


*

  • text

*----


*

MODULE STATUS_0100 OUTPUT.

SET PF-STATUS 'CANCEL'.

  • SET TITLEBAR 'xxx'.

 

ENDMODULE. " STATUS_0100 OUTPUT

*&----


*

*& Module USER_COMMAND_0100 INPUT

*&----


*

  • text

*----


*

MODULE USER_COMMAND_0100 INPUT.

CASE SY-UCOMM.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

WHEN 'CANCEL'.

LEAVE TO SCREEN 0.

WHEN 'EXIT'.

CALL TRANSACTION 'SE38'.

WHEN 'CHANGE'.

IF GR_ALVGRID->IS_READY_FOR_INPUT( ) = 0.

CALL METHOD GR_ALVGRID->SET_READY_FOR_INPUT

EXPORTING

I_READY_FOR_INPUT = 1.

 

ELSE.

CALL METHOD GR_ALVGRID->SET_READY_FOR_INPUT

EXPORTING

I_READY_FOR_INPUT = 0.

 

ENDIF.

ENDCASE.

With Regards

K Srinivas