Sap Abap Alv Tips

download Sap Abap Alv Tips

of 21

Transcript of Sap Abap Alv Tips

  • 8/10/2019 Sap Abap Alv Tips

    1/21

    Change layout format in ALV

    Layout format in ALV defined in structure IS_LAYOUT as importing structure of ALV

    REUSE_ALV_LIST_DISPLAY.

    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

    EXPORTING....

    s_layout = wa_layout

    ....EXCEPTIONS

    program_error = 1

    OTHERS = 2.

    Commonly used field:

    IS_LAYOUT-ZEBRA: X=striped (zebra) pattern

    IS_LAYOUT-BOX_FIELDNAME: insert column checkbox for each row to select row.How to inset checkbox:

    . insert new field with type C in internal table ALV data to record selection indicator (X:selected).Example:

    DATA: BEGIN OF t_alv OCCURS 1,

    ield1,ield2,

    .

    BOX,END Of T_alv.

    2. set IS_LAYOUT-BOX_FIELDNAME = fieldname in internal table ALV data.

    Example:

    S_LAYOUT-BOX_FIELDNAME = 'BOX'.

    . At run time, t_alv-box will filled with 'X' for selected data.

    CheckBox can be initiated in these ways:: selected, can not be changed

    0: not selected, can not be changed

    X: selected, can be changedSPACE (blank):not selected, can be changed: disable check box

    IS_LAYOUT-COL_FIELDNAME

    Cells can be colored individually using a color code which is contained in a column of the internal output table for tecord containing the cell.

    Assign the name of the field to this parameter.

    The internal output table field must be of type SLIS_T_SPECIALCOL_ALV.Principle: the color code field is entered for the record containing the cells to be colored. The field contains an intern

    able with the above structure, containing the field names of the cells to be colored and the color code. The cell

    oordinates are determined by the record position containing the color code and the column information in the color

    http://abap-gallery.blogspot.com/2007/07/change-layout-format-in-alv.htmlhttp://abap-gallery.blogspot.com/2007/07/change-layout-format-in-alv.htmlhttp://abap-gallery.blogspot.com/2007/07/change-layout-format-in-alv.html
  • 8/10/2019 Sap Abap Alv Tips

    2/21

    able.The record structure of the internal color table of type SLIS_T_SPECIALCOL_ALV is as follows:

    Color table-FIELDNAME = field name of the cell to be colored

    Color table-COLOR-COL = color number (1 - 9)

    Color table-COLOR-INT = bold (0 = off, 1 = on)Color table-COLOR-INV = inverse (0 = off, 1 = on)

    Color table-NOKEYCOL = ignore key coloring ('X' = yes, ' ' = no)

    f the parameter color table-FIELDNAME is not filled, the coloring applies to all fields, so the entire record is color---------------------------------------------------------------------------------------------------------------

    Tabstrip in selection screen

    To define a tabstrip area with tab pages in selection screen, use the following statements in your selection screendefinition:

    SELECTION-SCREEN: BEGIN OF TABBED BLOCK FOR LINES,

    TAB () USER-COMMAND

    DEFAULT [PROGRAM ] SCREEN ],TAB () USER-COMMAND

    DEFAULT [PROGRAM ] SCREEN ],

    .END OF BLOCK .

    This defines a tabstrip control with size . The tab pages , ... are assigned to the tab area. defines the width of the tab

    itle. You must assign a function code area to each tab title.

    For each tab title, the system automatically creates a character field in the ABAP program with the same name. In

    titialization, you can assign a text to the field. This then appears as the title of the corresponding tab page on theelection screen.

    You must assign a subscreen to each tab title. This will be displayed in the tab area when the user chooses that title.

    You can assign one of the following as a subscreen:

    . A subscreen screen defined using the Screen Painter.

    The dialog modules containing its flow logic must be defined in the current ABAP program.

    2. A selection screen subscreen, defined in an ABAP program.User actions will trigger the AT SELECTION-SCREEN event at least twice firstly for the "included" selection scr

    we can use it for validation), then for the selection screen on which it appears.

    This is simple program with three tab title.

    Tab1 demonstrating input validation.Don't forget to create subscreen 0300 for Tab3.

    REPORT ZAALGAL0007.http://abap-gallery.blogspot.com

    TABLES: sscrfields.

    http://abap-gallery.blogspot.com/2007/07/tabstrip-in-selection-screen.htmlhttp://abap-gallery.blogspot.com/2007/07/tabstrip-in-selection-screen.htmlhttp://abap-gallery.blogspot.com/2007/07/tabstrip-in-selection-screen.html
  • 8/10/2019 Sap Abap Alv Tips

    3/21

    SUBSCREEN 1 For Tabstrip BUTTON1

    SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.

    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.PARAMETERS: p1(10) TYPE c,

    p2(10) TYPE c,

    p3(10) TYPE c.SELECTION-SCREEN END OF BLOCK b1.

    SELECTION-SCREEN END OF SCREEN 100.

    SUBSCREEN 2 For Tabstrip BUTTON2

    SELECTION-SCREEN BEGIN OF SCREEN 200 AS SUBSCREEN.

    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME.PARAMETERS: q1(10) TYPE c OBLIGATORY,

    q2(10) TYPE c.

    SELECTION-SCREEN END OF BLOCK b2.

    SELECTION-SCREEN END OF SCREEN 200.

    Go to tcode SE51 Create screen no 0300 with screen type = subscreen

    STANDARD SELECTION SCREEN

    PARAMETERS: h1(10) TYPE c.

    SELECTION-SCREEN: BEGIN OF TABBED BLOCK mytab FOR 10 LINES,

    TAB (20) button1 USER-COMMAND push1DEFAULT SCREEN 100,

    TAB (20) button2 USER-COMMAND push2

    DEFAULT SCREEN 200,TAB (20) button3 USER-COMMAND push3

    DEFAULT SCREEN 300,

    END OF BLOCK mytab.

    NITIALIZATION.

    button1 = 'This is sel-screen 100'.

    button2 = 'This is sel-screen 200'.button3 = 'This is screen 300'.

    mytab-prog = sy-repid.

    mytab-dynnr = 100.

    mytab-activetab = 'BUTTON1'.

    AT SELECTION-SCREEN.

    CASE sy-dynnr.WHEN 1000.

    WHEN 100.

    F p1 IS INITIAL.scrfields-ucomm = 'PUSH1'.

    MESSAGE I888(sabapdocu) WITH 'Make an entry in P1'.

    ENDIF.WHEN 200.

    MESSAGE s888(sabapdocu) WITH 'Validation on' sy-dynnr.

  • 8/10/2019 Sap Abap Alv Tips

    4/21

    ENDCASE.

    START-OF-SELECTION.

    WRITE: / 'P1:', p1,'Q1:', q1,'P2:', p2,'Q2:', q2,

    'P3:', p3.

    Field catalog in ALV

    Field catalog containing descriptions of the list output fields. You can use fields of the catalog to determine the num

    ormat and column properties of the list to be displayed.

    The field catalog contains more than 60 fields, some of which are only used internally. The field catalog is defined ihe Data Dictionary through table type LVC_T_FCAT.

    We can get field description by calling function module REUSE_ALV_FIELDCATALOG_MERGE. You can see t

    ample in my post aboutSimple ALV Report.

    n general case, we only use few field to describe output field.

    To make it easier I use this form:

    FORM f_alv_fieldcatg USING

    u_types "internal table name

    u_fname "Field name of internal table fieldu_reftb "reference table name

    u_refld "reference table field

    u_noout "X= No outu_outln "out

    u_fltxt "output length

    u_dosum "X=Do sum (total)

    u_hotsp "X=hotspot onu_just. "Justification:L,R,C

    CLEAR: t_fieldcat._fieldcat-tabname = fu_types.

    _fieldcat-fieldname = fu_fname.

    _fieldcat-ref_tabname = fu_reftb.

    _fieldcat-ref_fieldname = fu_refld._fieldcat-no_out = fu_noout.

    _fieldcat-outputlen = fu_outln.

    _fieldcat-seltext_l = fu_fltxt._fieldcat-seltext_m = fu_fltxt.

    _fieldcat-seltext_s = fu_fltxt.

    _fieldcat-reptext_ddic = fu_fltxt._fieldcat-no_out = fu_noout.

    _fieldcat-do_sum = fu_dosum.

    _fieldcat-hotspot = fu_hotsp.

    _fieldcat-just = fu_just.

    http://abap-gallery.blogspot.com/2007/07/field-catalog-in-alv.htmlhttp://abap-gallery.blogspot.com/2007/07/field-catalog-in-alv.htmlhttp://abap-gallery.blogspot.com/2007/07/simple-alv.htmlhttp://abap-gallery.blogspot.com/2007/07/simple-alv.htmlhttp://abap-gallery.blogspot.com/2007/07/simple-alv.htmlhttp://abap-gallery.blogspot.com/2007/07/simple-alv.htmlhttp://abap-gallery.blogspot.com/2007/07/field-catalog-in-alv.html
  • 8/10/2019 Sap Abap Alv Tips

    5/21

    APPEND t_fieldcat.CLEAR t_fieldcat.

    ENDFORM. " f_alv_fieldcatg

    We can use it in two way:. refer to data dictionary:

    PERFORM f_alv_fieldcatg USING 'T_REPORT' :

    EQUNR' 'EQUI' 'EQUNR' '' '' '' '' 'X' '',SPART' 'VBAK' 'SPART' '' '' '' '' '' ''.

    2. or define yourself

    PERFORM f_alv_fieldcatg USING 'T_REPORT' :

    FIELD1' '' '' '' '20' 'Text Field1' '' '' ''.

    nd for field with type number, I use this:

    &---------------------------------------------------------------------*& Form f_alv_fieldcatg_number

    &---------------------------------------------------------------------*

    text----------------------------------------------------------------------*

    FORM f_alv_fieldcatg_number USING fu_types

    u_fnameu_noout

    u_outln

    u_no_sign

    u_no_zero

    u_fltxtu_dosum

    u_exponentu_decimals_out.

    CLEAR: t_fieldcat._fieldcat-tabname = fu_types.

    _fieldcat-fieldname = fu_fname.

    _fieldcat-no_out = fu_noout.

    _fieldcat-outputlen = fu_outln._fieldcat-seltext_l = fu_fltxt.

    _fieldcat-seltext_m = fu_fltxt.

    _fieldcat-seltext_s = fu_fltxt.

    _fieldcat-reptext_ddic = fu_fltxt._fieldcat-no_zero = fu_no_zero.

    _fieldcat-no_sign = fu_no_sign.

    _fieldcat-exponent = fu_exponent._fieldcat-decimals_out = fu_decimals_out.

    _fieldcat-do_sum = fu_dosum.

    _fieldcat-datatype = 'FLTP'.APPEND t_fieldcat.

    CLEAR t_fieldcat.

  • 8/10/2019 Sap Abap Alv Tips

    6/21

    ENDFORM. " f_alv_fieldcatg_number

    For field currency, there are two options, fixed currency or variable currency.

    &---------------------------------------------------------------------*

    & Form f_alv_fieldcatg_curr&---------------------------------------------------------------------*

    text

    ----------------------------------------------------------------------*FORM f_alv_fieldcatg_curr USING fu_types

    u_fname

    u_reftb

    u_refldu_noout

    u_outln

    u_fltxt

    u_dosumu_hotsp

    u_cfield.

    CLEAR: t_fieldcat.

    _fieldcat-tabname = fu_types.

    _fieldcat-fieldname = fu_fname._fieldcat-ref_tabname = fu_reftb.

    _fieldcat-ref_fieldname = fu_refld.

    _fieldcat-no_out = fu_noout.

    _fieldcat-outputlen = fu_outln._fieldcat-seltext_l = fu_fltxt.

    _fieldcat-seltext_m = fu_fltxt.

    _fieldcat-seltext_s = fu_fltxt._fieldcat-reptext_ddic = fu_fltxt.

    _fieldcat-do_sum = fu_dosum.

    _fieldcat-hotspot = fu_hotsp._fieldcat-cfieldname = fu_cfield.

    _fieldcat-ctabname = fu_types.

    _fieldcat-no_zero = 'X'.

    APPEND t_fieldcat.CLEAR t_fieldcat.

    ENDFORM. " F_FIELDCATG_CURR

    &---------------------------------------------------------------------*

    & Form f_alv_fieldcatg_curr

    &---------------------------------------------------------------------* text

    ----------------------------------------------------------------------*

    FORM f_alv_fieldcatg_curr_fixed USING fu_typesu_fname

    u_reftb

    u_refldu_noout

    u_outln

  • 8/10/2019 Sap Abap Alv Tips

    7/21

    u_fltxtu_dosum

    u_hotsp

    u_curr.

    CLEAR: t_fieldcat.

    _fieldcat-tabname = fu_types.

    _fieldcat-fieldname = fu_fname._fieldcat-ref_tabname = fu_reftb.

    _fieldcat-ref_fieldname = fu_refld.

    _fieldcat-no_out = fu_noout._fieldcat-outputlen = fu_outln.

    _fieldcat-seltext_l = fu_fltxt.

    _fieldcat-seltext_m = fu_fltxt.

    _fieldcat-seltext_s = fu_fltxt._fieldcat-reptext_ddic = fu_fltxt.

    _fieldcat-do_sum = fu_dosum.

    _fieldcat-hotspot = fu_hotsp.

    t_fieldcat-cfieldname = fu_cfield. t_fieldcat-ctabname = fu_types.

    _fieldcat-datatype = 'CURR'._fieldcat-currency = fu_curr._fieldcat-no_zero = 'X'.

    APPEND t_fieldcat.

    CLEAR t_fieldcat.

    ENDFORM. " F_FIELDCATG_CURR

    Dynamic Table Maintenance

    t is a good sample of how to create dynamic table maintenance by utilized SAP function moduleSTC1_FULLSCREEN_TABLE_CONTROL".

    copy this code fromITToolbox

    You can use it to replace funtion of SM31 with additional benefit.

    . Because it is written in as customer program we can add additional feature, for example change history.

    2. There is no need to create screen maintenance for all table because screen will automatically generated.

    But, remember, this is only a demonstration of how to use STC1_FULLSCREEN_TABLE_CONTROL. Use it

    arefully and only for customer table (Z*).

    Because there is difficulty in write "" in blogger, I replace "" with "}" in this sample cod

    Copy this sample code, then replace all "{" with "".

    REPORT ZAALGAL002 NO STANDARD PAGE HEADING.

    TYPE-POOLS: rsds.

    DATA: is_x030l TYPE x030l,

    http://abap-gallery.blogspot.com/2007/07/dynamic-table-maintenance.htmlhttp://abap-gallery.blogspot.com/2007/07/dynamic-table-maintenance.htmlhttp://sap.ittoolbox.com/code/archives.asp?i=10&d=3038&a=shttp://sap.ittoolbox.com/code/archives.asp?i=10&d=3038&a=shttp://sap.ittoolbox.com/code/archives.asp?i=10&d=3038&a=shttp://sap.ittoolbox.com/code/archives.asp?i=10&d=3038&a=shttp://abap-gallery.blogspot.com/2007/07/dynamic-table-maintenance.html
  • 8/10/2019 Sap Abap Alv Tips

    8/21

    t_dfies TYPE TABLE OF dfies,s_dfies TYPE dfies,

    t_fdiff TYPE TABLE OF field_dif,

    s_fdiff TYPE field_dif.

    DATA: w_selid TYPE rsdynsel-selid,

    t_tables TYPE TABLE OF rsdstabs,

    s_tables TYPE rsdstabs,t_fields TYPE TABLE OF rsdsfields,

    t_expr TYPE rsds_texpr,

    t_ranges TYPE rsds_trange,t_where TYPE rsds_twhere,

    s_where TYPE rsds_where,

    w_active TYPE i.

    DATA: it_content TYPE REF TO data,

    t_modif TYPE REF TO data,

    t_fcat TYPE lvc_t_fcat.

    DATA: w_okcode TYPE sy-ucomm.

    FIELD-SYMBOLS: {itab} TYPE STANDARD TABLE,

    ntab} TYPE STANDARD TABLE.

    Macros

    DEFINE table_error.

    message e398(00) with 'Table' p_table &1.END-OF-DEFINITION.

    DEFINE fixed_val.s_fdiff-fieldname = is_dfies-fieldname.

    s_fdiff-fixed_val = &1.

    s_fdiff-no_input = 'X'.ppend is_fdiff to it_fdiff.

    END-OF-DEFINITION.

    Selection screen

    SELECTION-SCREEN: BEGIN OF BLOCK b01 WITH FRAME.

    PARAMETERS: p_table TYPE tabname OBLIGATORY "table

    MEMORY ID dtbMATCHCODE OBJECT dd_dbtb_16.

    SELECTION-SCREEN: BEGIN OF LINE,

    PUSHBUTTON 33(20) selopt USER-COMMAND sel,COMMENT 55(15) selcnt,

    END OF LINE.

    SELECTION-SCREEN: SKIP.PARAMETERS: p_rows TYPE i. "rows

    SELECTION-SCREEN: END OF BLOCK b01,

    SKIP,BEGIN OF BLOCK b02 WITH FRAME.

    PARAMETERS: p_displ TYPE c AS CHECKBOX. "display

  • 8/10/2019 Sap Abap Alv Tips

    9/21

    SELECTION-SCREEN: END OF BLOCK b02.

    Initialization

    NITIALIZATION.

    MOVE '@4G@ Filter records' TO selopt.

    PBO

    AT SELECTION-SCREEN OUTPUT.F w_active IS INITIAL.

    CLEAR: selcnt.

    ELSE.WRITE w_active TO selcnt LEFT-JUSTIFIED.

    ENDIF.

    PAIAT SELECTION-SCREEN.

    F p_table NE is_x030l-tabname.

    CALL FUNCTION 'DDIF_NAMETAB_GET'

    EXPORTINGabname = p_table

    MPORTINGx030l_wa = is_x030lTABLES

    dfies_tab = it_dfies

    EXCEPTIONSOTHERS = 1.

    F is_x030l IS INITIAL.

    able_error 'does not exist or is not active'.

    ELSEIF is_x030l-tabtype NE 'T'.able_error 'is not selectable'.

    ELSEIF is_x030l-align NE 0.

    able_error 'has alignment - cannot continue'.ENDIF.

    Default values for system fieldsREFRESH: it_fdiff.

    s_fdiff-tabname = p_table.

    LOOP AT it_dfies INTO is_dfies.

    F is_dfies-datatype = 'CLNT'.ixed_val sy-mandt.

    ELSEIF is_dfies-rollname = 'ERDAT'

    OR is_dfies-rollname = 'ERSDA'

    OR is_dfies-rollname = 'AEDAT'OR is_dfies-rollname = 'LAEDA'.

    ixed_val sy-datum.

    ELSEIF is_dfies-rollname = 'ERTIM'OR is_dfies-rollname = 'AETIM'.

    ixed_val sy-uzeit.

    ELSEIF is_dfies-rollname = 'ERNAM'OR is_dfies-rollname = 'AENAM'.

    ixed_val sy-uname.

    ENDIF.ENDLOOP.

  • 8/10/2019 Sap Abap Alv Tips

    10/21

    Prepare free selection on tableREFRESH it_tables.

    s_tables-prim_tab = p_table.

    APPEND is_tables TO it_tables.

    CLEAR: w_selid.

    ENDIF.

    F sy-ucomm = 'SEL'.

    F w_selid IS INITIAL.

    Init free selection dialogCALL FUNCTION 'FREE_SELECTIONS_INIT'

    EXPORTING

    xpressions = it_expr

    MPORTINGelection_id = w_selid

    xpressions = it_expr

    TABLES

    ables_tab = it_tablesEXCEPTIONS

    OTHERS = 1.ENDIF.

    Display free selection dialog

    CALL FUNCTION 'FREE_SELECTIONS_DIALOG'EXPORTING

    election_id = w_selid

    itle = 'Selection'

    tatus = 1s_window = 'X'

    MPORTING

    xpressions = it_exprield_ranges = it_ranges

    number_of_active_fields = w_active

    TABLESields_tab = it_fields

    EXCEPTIONS

    OTHERS = 1.

    ENDIF.

    Start of processing

    START-OF-SELECTION.

    PERFORM f_create_table USING p_table.

    PERFORM f_select_table.

    PERFORM f_display_table.

    ---------------------------------------------------------------------* FORM f_create_table *

    ---------------------------------------------------------------------*

  • 8/10/2019 Sap Abap Alv Tips

    11/21

    FORM f_create_table USING in_tabname.

    FIELD-SYMBOLS: {fcat> TYPE lvc_s_fcat.

    CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'EXPORTING

    _structure_name = in_tabname

    CHANGINGt_fieldcat = it_fcat

    EXCEPTIONS

    OTHERS = 1.F sy-subrc = 0.

    Complete field catalog

    LOOP AT it_fcat ASSIGNING {fcat>.

    fcat>-tabname = in_tabname.ENDLOOP.

    CALL FUNCTION 'LVC_FIELDCAT_COMPLETE'

    CHANGING

    t_fieldcat = it_fcatEXCEPTIONS

    OTHERS = 1.ELSE.WRITE: 'Error building field catalog'.

    STOP.

    ENDIF.

    Create dynamic table for data

    CALL METHOD cl_alv_table_create=>create_dynamic_table

    EXPORTINGt_fieldcatalog = it_fcat

    MPORTING

    p_table = it_content.F sy-subrc = 0.

    ASSIGN it_content->* TO {itab}.

    ELSE.WRITE: 'Error creating internal table'.

    STOP.

    ENDIF.

    Create dynamic table for modif

    CALL METHOD cl_alv_table_create=>create_dynamic_table

    EXPORTING

    t_fieldcatalog = it_fcatMPORTING

    p_table = it_modif.

    F sy-subrc = 0.ASSIGN it_modif->* TO {ntab}.

    ELSE.

    WRITE: 'Error creating internal table'.STOP.

    ENDIF.

    ENDFORM.

  • 8/10/2019 Sap Abap Alv Tips

    12/21

    ---------------------------------------------------------------------*

    FORM f_select_table *

    ---------------------------------------------------------------------*

    FORM f_select_table.

    F w_active = 0.

    SELECT * FROM (p_table)NTO CORRESPONDING FIELDS OF TABLE {itab}

    UP TO p_rows ROWS.

    ELSE. Selection with parameters

    CALL FUNCTION 'FREE_SELECTIONS_RANGE_2_WHERE'

    EXPORTING

    ield_ranges = it_rangesMPORTING

    where_clauses = it_where.

    READ TABLE it_where INTO is_where WITH KEY tablename = p_table.

    SELECT * FROM (p_table)

    NTO CORRESPONDING FIELDS OF TABLE {itab}UP TO p_rows ROWSWHERE (is_where-where_tab).

    ENDIF.

    F sy-dbcnt = 0.

    WRITE: 'No record selected'.

    STOP.

    ENDIF.ENDFORM.

    ---------------------------------------------------------------------*

    FORM f_display_table *

    ---------------------------------------------------------------------*FORM f_display_table.

    DATA: l_answer TYPE c,

    _eflag TYPE c.

    CLEAR: w_okcode.

    REFRESH: {ntab}.

    Display table contents

    CALL FUNCTION 'STC1_FULLSCREEN_TABLE_CONTROL'EXPORTING

    header = p_table

    abname = p_tabledisplay_only = p_displ

    ndless = 'X'

    no_button = spaceMPORTING

    okcode = w_okcode

    TABLESnametab = it_dfies

    able = {itab}

  • 8/10/2019 Sap Abap Alv Tips

    13/21

    ielddif = it_fdiffmodif_table = {ntab}

    EXCEPTIONS

    OTHERS = 1.

    F sy-subrc = 0.F p_displ IS INITIAL AND w_okcode = 'SAVE'.

    Confirm update

    CALL FUNCTION 'POPUP_TO_CONFIRM'EXPORTING

    itlebar = p_table

    ext_question = 'Do you want to update table ?'default_button = '2'

    display_cancel_button = ' '

    MPORTING

    nswer = l_answerEXCEPTIONS

    OTHERS = 1.

    F l_answer = '1'.

    Apply modificationsF NOT {ntab}[] IS INITIAL.

    PERFORM f_add_system USING space.MODIFY (p_table) FROM TABLE {ntab}.F sy-subrc NE 0.

    _eflag = 'X'.

    ENDIF.ENDIF.

    Apply deletions

    F l_eflag IS INITIAL.

    REFRESH: {ntab}.CALL FUNCTION 'STC1_GET_DATA'

    TABLES

    deleted_data = {ntab}EXCEPTIONS

    OTHERS = 1.

    F NOT {ntab}[] IS INITIAL.DELETE (p_table) FROM TABLE {ntab}.

    F sy-subrc NE 0.

    ROLLBACK WORK.

    _eflag = 'X'.ENDIF.

    ENDIF.

    ENDIF.

    Apply creationsF l_eflag IS INITIAL.

    REFRESH: {ntab}.

    CALL FUNCTION 'STC1_GET_DATA'TABLES

    new_data = {ntab}

    EXCEPTIONSOTHERS = 1.

    F NOT {ntab}[] IS INITIAL.

    PERFORM f_add_system USING 'X'.NSERT (p_table) FROM TABLE {ntab}.

    F sy-subrc NE 0.

  • 8/10/2019 Sap Abap Alv Tips

    14/21

    ROLLBACK WORK._eflag = 'X'.

    ENDIF.

    ENDIF.

    ENDIF.F l_eflag IS INITIAL.

    COMMIT WORK.

    MESSAGE s261(53).ELSE.

    MESSAGE s075(3i).

    PERFORM f_select_table.ENDIF.

    ENDIF.

    Display table again

    PERFORM f_display_table.ENDIF.

    ENDIF.

    ENDFORM.

    ---------------------------------------------------------------------* FORM f_add_system *

    ---------------------------------------------------------------------*

    FORM f_add_system USING new TYPE c.

    FIELD-SYMBOLS: {irec} TYPE ANY,

    upd} TYPE ANY.

    LOOP AT it_fdiff INTO is_fdiff.

    READ TABLE it_dfies INTO is_dfies

    WITH KEY fieldname = is_fdiff-fieldname.LOOP AT {ntab} ASSIGNING {irec}.

    ASSIGN COMPONENT is_fdiff-fieldname OF STRUCTURE {irec} TO {upd}.

    F is_dfies-datatype = 'CLNT'.upd} = sy-mandt.

    ELSE.

    CASE is_dfies-rollname.

    WHEN 'AENAM'.upd} = sy-uname.

    WHEN 'AEDAT' OR 'LAEDA'.

    upd} = sy-datum.

    WHEN 'AETIM'.upd} = sy-uzeit.

    WHEN OTHERS.

    ENDCASE.ENDIF.

    ENDLOOP.

    ENDLOOP.

    ENDFORM.

  • 8/10/2019 Sap Abap Alv Tips

    15/21

    Performance Tuning - Operation on Internal Table

    n development server you may not aware of performance tuning on operation on internal table, but it could become

    problem when you are working on internal table containing more 10 thousand rows.

    These are tips to improve your program performance.

    READ Table WITH CriteriaBy default, read command on internal table will read it sequentially. The binary search algorithm helps faster search

    value in an internal table. But you must sort it before use binary search. Binary search repeatedly divides the searc

    nterval in half. If the value to be searched is less than the item in the middle of the interval, the search is narrowed t

    he lower half, otherwise the search is narrowed to the upper half.

    SORT TABLE BYfield1.

    READ TABLE table1WITH KEYfield1 = criteria1BINARY SEARCH.

    Do try it for internal table containing more than 10 thousand rows, you will find it significantly improve performanc

    uning.

    You can apply binary search method to improve performance on nested loop.

    Nested loop:

    LOOP AT inttab1.

    LOOP AT inttab2 WHERE intab2-field1 = intab1-field1.

    ENDLOOP.

    NDLOOP.

    Replace above code with additional binary search.

    ORT inttab2 BY field1.

    LOOP AT inttab1.

    READ TABLE inttab2WITH KEY field1 = inttab1-field1 BINARY SEARCH.

    CHECK sy-subrc = 0.

    LOOP AT inttab2 FROM sy-tabix.

    IF inttab2-field1 NE inttab1-field1.

    EXIT.

    ENDIF.

    ENDLOOP.

    NDLOOP.

    Add toolbar button on selection screen

    http://abap-gallery.blogspot.com/2007/07/performance-tuning-operation-on.htmlhttp://abap-gallery.blogspot.com/2007/07/performance-tuning-operation-on.htmlhttp://abap-gallery.blogspot.com/2007/07/add-toolbar-on-selection-screen.htmlhttp://abap-gallery.blogspot.com/2007/07/add-toolbar-on-selection-screen.htmlhttp://1.bp.blogspot.com/_KRC44WsW6Ps/RqW7rEuJCoI/AAAAAAAAADE/OSLvTEoUuD8/s1600-h/add_toolbar.jpghttp://abap-gallery.blogspot.com/2007/07/add-toolbar-on-selection-screen.htmlhttp://abap-gallery.blogspot.com/2007/07/performance-tuning-operation-on.html
  • 8/10/2019 Sap Abap Alv Tips

    16/21

    We can add new toolbar (maximal 5) in ABAP report to make program more interactive to user on selection screen.

    Do following step.

    . Declare work area sscrfields.

    TABLES: sscrfields.

    2. Define text displayed in button in initialization event.

    NITIALIZATION.MOVE 'This is button 1' TO sscrfields-functxt_0n." n = 1 up to 5

    . Activate toolbar in selection screen.

    SELECTION-SCREEN FUNCTION KEY n.

    4. Check user command in AT selection screen

    AT SELECTION-SCREEN.F sy-ucomm = 'FC0n'." n = 1 up to 5

    ..

    ENDIF.

    This is complete sample:

    REPORT ZAALGAL0005 .

    TABLES: sscrfields.

    DATA: d_butt1(4).

    PARAMETERS: p_grpa1(10) MODIF ID A,

    p_grpa2(10) MODIF ID A,p_grpb1(10) MODIF ID B.

    SELECTION-SCREEN FUNCTION KEY 1.SELECTION-SCREEN FUNCTION KEY 2.

    NITIALIZATION.

    MOVE 'This is button 1' TO sscrfields-functxt_01.

    MOVE 'Toggle 1' TO sscrfields-functxt_02.d_butt1 = 'NO'.

    AT SELECTION-SCREEN.F sy-ucomm = 'FC01'.

    d_butt1 = 'YES'.

    scrfields-ucomm = 'ONLI'.ELSEIF sy-ucomm = 'FC02'.

    F sscrfields-functxt_02 = 'Toggle 1'.

    scrfields-functxt_02 = 'Toggle 2'.

    ELSE.

    scrfields-functxt_02 = 'Toggle 1'.

  • 8/10/2019 Sap Abap Alv Tips

    17/21

    ENDIF.ENDIF.

    START-OF-SELECTION.

    WRITE d_butt1.

    Help Value Request (F4)

    This sample program demonstrate how to create "Help Value Request". It will appear when user pressing F4 (help)

    n input field to request list of available value.

    To do this we are using function module F4IF_INT_TABLE_VALUE_REQUEST. It provide help value request wi

    ollowing feature:

    . single / multiple choice.

    2. update screen without PBO, so it can be used to update more than one field on one request.

    Here is the code:

    REPORT ZAALGAL0003 .

    TABLES: usr02.

    parameters: p_bname LIKE usr02-bname,p_class LIKE usr02-class.

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_bname.PERFORM f_valuerequest_vbeln.

    &---------------------------------------------------------------------*& Form f_valuerequest_vbeln

    &---------------------------------------------------------------------* text

    ----------------------------------------------------------------------*

    --> p1 text

  • 8/10/2019 Sap Abap Alv Tips

    18/21

    ENDSELECT.

    PERFORM f_fieldinfo_get USING 'USR02'

    BNAME'

    CHANGING h_field_wa.APPEND h_field_wa TO h_field_tab.

    PERFORM f_fieldinfo_get USING 'USR02'

    CLASS'CHANGING h_field_wa.

    APPEND h_field_wa TO h_field_tab.

    h_dselc-fldname = 'BNAME'.

    h_dselc-dyfldname = 'P_BNAME'.

    APPEND h_dselc.

    h_dselc-fldname = 'CLASS'.h_dselc-dyfldname = 'P_CLASS'.

    APPEND h_dselc.

    DATA: ld_repid LIKE sy-repid.d_repid = sy-repid.

    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'EXPORTING

    etfield = 'P_BNAME'

    dynpprog = ld_repiddynpnr = '1000'

    dynprofield = 'P_BNAME'

    multiple_choice = ''

    value_org = 'S'TABLES

    value_tab = t_data

    ield_tab = h_field_tab return_tab = return_tab

    DYNPFLD_MAPPING = h_dselc

    EXCEPTIONSOTHERS = 0.

    ENDFORM. " f_valuerequest_vbeln

    &---------------------------------------------------------------------*& Form f_fieldinfo_get

    &---------------------------------------------------------------------*

    text

    ----------------------------------------------------------------------* -->P_0079 text

    -->P_0080 text

  • 8/10/2019 Sap Abap Alv Tips

    19/21

    TABNAME = fu_tabnameFIELDNAME = fu_fieldname

    LFIELDNAME = fu_fieldname

    MPORTING

    DFIES_WA = fwa_field_tabEXCEPTIONS

    NOT_FOUND = 1

    NTERNAL_ERROR = 2OTHERS = 3

    F SY-SUBRC 0.MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

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

    ENDIF.

    ENDFORM. " f_fieldinfo_get

    ABAP sample code provided by SAP

    SAP provide a alot of sample code.

    For demo about selection screen validation, dynamic selection screen, find them in DEMO_SEL_SCREEN*

    For demo about select data, dynamic condition, find them in in DEMO_SELECT*

    Demo about write output to list can be found in program DEMO_LIST*

    You can find also demo about object oriented programming, tree control, drap & drop menu (contect menu)

    To find all the demos, find program including word *DEMO* in program name.

    Enjoy exploring SAP demo :)

    Event in ABAP Report

    Event in ABAP report determine process flow of a program. The events are triggered depended on the way the outp

    s generated. They begin after event keyword and end when the next event reached.

    Event keyword:

    NITIALIZATION.

    Occurs when report initialized.

    We can use it to check user authorization or prepare output for selection screen.

    AT SELECTION-SCREEN OUTPUT :

    Occurs each time selection screen about to generated.

    We can use it to modify selection screen, for example hide / unhide parameter.

    http://abap-gallery.blogspot.com/2008/07/abap-sample-code-provided-by-sap.htmlhttp://abap-gallery.blogspot.com/2008/07/abap-sample-code-provided-by-sap.htmlhttp://abap-gallery.blogspot.com/2007/08/event-in-abap-report.htmlhttp://abap-gallery.blogspot.com/2007/08/event-in-abap-report.htmlhttp://abap-gallery.blogspot.com/2007/08/event-in-abap-report.htmlhttp://abap-gallery.blogspot.com/2008/07/abap-sample-code-provided-by-sap.html
  • 8/10/2019 Sap Abap Alv Tips

    20/21

    AT SELECTION-SCREEN.

    Occurs each user command in selection screen. we can use it to perform checking on user input.

    START-OF-SELECTIONOccurs after the standard selection screen has been processed.,

    data is read in this event.

    END-OF-SELECTION

    Occurs after start-of-selection.

    TOP-OF-PAGE

    Occurs when a new page starts.

    Use it for write report header.

    END-OF-PAGE

    Occurs when a page ends.

    Use it for write report footer.

    AT LINE-SELECTION

    Occurs when the user double-click on report.

    AT USER-COMMAND

    Occurs when the user push toolbar button.

    This is program to demonstrate how to use event properly.

    REPORT ZAALGAL0008LINE-COUNT 10(1).

    http://abap-gallery.blogspot.com

    TABLES: sflight.

    DATA: BEGIN OF t_report OCCURS 3,

    arrid LIKE sflight-carrid,

    onnid LIKE sflight-connid,END OF t_report.

    begin selection screen

    PARAMETERS p_datum LIKE sy-datum.

    PARAMETERS p_check AS CHECKBOX.end selection screen

    NITIALIZATION.begin initialization

    MOVE sy-datum TO p_datum.

    end initialization

    AT SELECTION-SCREEN.

    begin at selection-screen

    MESSAGE I888(sabapdocu) WITH 'At selection-screen'.

    F p_check = 'X'.

  • 8/10/2019 Sap Abap Alv Tips

    21/21

    MESSAGE E888(sabapdocu) WITH 'Clear checkbox'.ENDIF.

    end at selection-screen

    AT SELECTION-SCREEN OUTPUT.begin at selection-screen output

    MESSAGE I888(sabapdocu) WITH 'At selection-screen output'.

    end at selection-screen output

    START-OF-SELECTION.

    begin start-of-selection.MESSAGE I888(sabapdocu) WITH 'start-of-selection'.

    SELECT * FROM sflight.

    MOVE sflight-carrid TO t_report-carrid.

    MOVE sflight-connid TO t_report-connid.APPEND t_report.

    ENDSELECT.

    end start-of-selection.

    END-OF-SELECTION.

    begin end-of-selection.MESSAGE I888(sabapdocu) WITH 'end-of-selection'.FORMAT COLOR col_normal.

    DO 30 TIMES.

    LOOP AT t_report.WRITE / t_report-carrid.

    WRITE t_report-connid.

    ENDLOOP.

    ENDDO.end end-of-selection.

    TOP-OF-PAGE.FORMAT COLOR col_heading.

    WRITE 'This is header'.

    END-OF-PAGE.

    FORMAT COLOR col_total.

    WRITE 'This is footer'.

    AT LINE-SELECTION.

    WRITE: / 'Cursor Row:', sy-curow.

    WRITE: / 'Cursor Col:', sy-cucol.