simple alv

Upload: arunprasadeee

Post on 09-Apr-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 simple alv

    1/4

    Simple ALV Report PDF Print E-mailUser Rating: / 36PoorBestWritten by Martin SchlegelSaturday, 20 January 2007

    Simple example to use ALV and to define the ALV data in an internal table.

    Also see ALV Grid ControlREPORT Z_ALV_SIMPLE_EXAMPLE_WITH_ITAB .*************************************************************************Simple example to use ALV and to define the ALV data in an internal*table************************************************************************* Martin Schlegel, BearingPoint, December 2004** Thanks to Madhusudhan Sonee and Rama Krishna Kommineni for testing* and feedback*

    *************************************************************************************************************************************************For a very long time, people gave me the feeling that ALV is a*complicated tool that is difficult to understand and to use.*Lately I had to use it and I discovered that ALV is easy to use and*saves a lot of work:*ALV will generate the column headings on its own, so one does not need*to work on headlines and transalation.*ALV allows the user to select the columns he wants to see, so the user*does not need to contact a developer for every change he likes to have.*ALV allows the user to create his own sums, so *ALV has a simple way to work with internal tables.*If you really want to save time, use ALV instead of write!

    **************************************************************************Please take 30 minutes to explore the following example and see how*easy it is to use ALV!**************************************************************************data definitiontables:marav. "Table MARA and table MAKT

    *---------------------------------------------------------------------** Data to be displayed in ALV* Using the following syntax, REUSE_ALV_FIELDCATALOG_MERGE can auto-* matically determine the fieldstructure from this source programData:begin of imat occurs 100,matnr like marav-matnr, "Material numbermaktx like marav-maktx, "Material short textmatkl like marav-matkl, "Material group (so you can test to make

    " intermediate sums)ntgew like marav-ntgew, "Net weight, numeric field (so you can test to

    "make sums)gewei like marav-gewei, "weight unit (just to be complete)

    end of imat.*---------------------------------------------------------------------*

  • 8/7/2019 simple alv

    2/4

    * Other data needed* field to store report namedata i_repid like sy-repid.* field to check table lengthdata i_lines like sy-tabix.*---------------------------------------------------------------------*

    * Data for ALV displayTYPE-POOLS: SLIS.data int_fcat type SLIS_T_FIELDCAT_ALV.*---------------------------------------------------------------------*select-options:s_matnr for marav-matnr matchcode object MAT1.*---------------------------------------------------------------------*start-of-selection.* read data into table imat

    select * from maravinto corresponding fields of table imatwherematnr in s_matnr.

    * Check if material was foundclear i_lines.describe table imat lines i_lines.if i_lines lt 1.

    * Using hardcoded write here for easy uploadwrite: /'No materials found.'.exit.

    endif.end-of-selection.*---------------------------------------------------------------------*** Now, we start with ALV**---------------------------------------------------------------------**** To use ALV, we need a DDIC-structure or a thing called Fieldcatalogue.* The fieldcatalouge can be generated by FUNCTION* 'REUSE_ALV_FIELDCATALOG_MERGE' from an internal table from any* report source, including this report.* The only problem one might have is that the report and table names* need to be in capital letters. (I had it :-( )***---------------------------------------------------------------------** Store report namei_repid = sy-repid.

    * Create Fieldcatalogue from internal tableCALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTINGI_PROGRAM_NAME = i_repidI_INTERNAL_TABNAME = 'IMAT' "capital letters!

  • 8/7/2019 simple alv

    3/4

    I_INCLNAME = i_repidCHANGING

    CT_FIELDCAT = int_fcatEXCEPTIONS

    INCONSISTENT_INTERFACE = 1PROGRAM_ERROR = 2OTHERS = 3.

    *explanations:* I_PROGRAM_NAME is the program which calls this function** I_INTERNAL_TABNAME is the name of the internal table which you want* to display in ALV** I_INCLNAME is the ABAP-source where the internal table is defined* (DATA....)* CT_FIELDCAT contains the Fieldcatalouge that we need later for* ALV display

    IF SY-SUBRC 0.write: /'Returncode',sy-subrc,'from FUNCTION REUSE_ALV_FIELDCATALOG_MERGE'.

    ENDIF.*This was the fieldcatlogue*---------------------------------------------------------------------*** And now, we are ready to display our list* Call for ALV list display

    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'EXPORTING

    * I_CALLBACK_PROGRAM = 'Z_ALV_SIMPLE_EXAMPLE_WITH_ITAB'I_CALLBACK_PROGRAM = i_repidIT_FIELDCAT = int_fcatI_SAVE = 'A'

    TABLEST_OUTTAB = imat

    EXCEPTIONSPROGRAM_ERROR = 1OTHERS = 2.

    **explanations:* I_CALLBACK_PROGRAM is the program which calls this function** IT_FIELDCAT (just made by REUSE_ALV_FIELDCATALOG_MERGE) contains* now the data definition needed for display** I_SAVE allows the user to save his own layouts** T_OUTTAB contains the data to be displayed in ALV

    IF SY-SUBRC 0.write: /

    'Returncode',sy-subrc,'from FUNCTION REUSE_ALV_LIST_DISPLAY'.

  • 8/7/2019 simple alv

    4/4

    ENDIF.**---------------------------------------------------------------------*** yes, it is that simple. Go ahead and try yourself!**---------------------------------------------------------------------*