ABAP Frequently Asked Questions

Embed Size (px)

Citation preview

  • 7/31/2019 ABAP Frequently Asked Questions

    1/7

    ABAP Solutions for Frequently Asked Questions: Part 1

    Calling a SM30 Maintenance from your program:

    Use TABLE_CUSTOMIZING_MAINT_RANGE to call:

    DATA: wa_f1 TYPE vimsellist,

    t_f1 TYPE TABLE OF vimsellist.

    wa_f1-viewfield = 'WERKS'.

    wa_f1-operator = 'EQ'.

    wa_f1-value = v_werks.

    append wa_f1 to t_f1.

    wa_f1-and_or = 'OR'.

    wa_f1-viewfield = 'WERKS'.

    wa_f1-operator = 'EQ'.

    wa_f1-value = v_werks2.

    append wa_f1 to t_f1.

    CALL FUNCTION 'TABLE_CUSTOMIZING_MAINT_RANGE '

    EXPORTING

    tabname = 'Z_SD001' " Table with SM30 created

    action = 'U'

  • 7/31/2019 ABAP Frequently Asked Questions

    2/7

    TABLES

    dba_sellist = t_filter

    EXCEPTIONS

    no_views = 001.

    Inserting a Button in Selection Screen Status:

    If you need a special button in the selection screen to execute an event before the program execution

    starts, and you cannot change the default status GUI, then you need to insert the button using a

    standard functionality.

    include .

    tables: SSCRFIELDS.

    selection-screen: FUNCTION KEY 1.

    initialization.

    data: wa_button LIKE SMP_DYNTXT.

    wa_button-icon_id = ICON_TEST.

    wa_button-icon_text = 'IconText'.

    wa_button-quickinfo = 'ButtonHint'.

    wa_button-text = space.

    wa_button-path = space.

  • 7/31/2019 ABAP Frequently Asked Questions

    3/7

    SSCRFIELDS-FUNCTXT_01 = wa_button.

    at selection-screen.

    case SSCRFIELDS-UCOMM.

    when 'FC01'.

    endcase.

    How to split a string by TAB:

    You have to use a special property of a standard class while you do split a string that is separated by a

    TAB character.

    data: v_text type string.

    split v_text at CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB into v_first v_second v_last.

    Get Last Date of Month:

    parameter: p_date type sy-datum.

    data: v_ldate type sy-datum.

    v_ldate = p_date - p_date+6(2) + 45.

    v_ldate+6(2) = '01'.

    v_ldate = v_ldate - 1.

    How to call a query by creating a transaction:

  • 7/31/2019 ABAP Frequently Asked Questions

    4/7

    To create a transaction which calls a query, go to SE93 and create a parameter transaction with the

    values described below.

    TRANSACTION: START_REPORT

    Skip Initial Screen: [X]

    Default Values

    D_SREPOVARI-REPORTTYPE: AQ

    D_SREPOVARI-REPORT: {User Group}

    D_SREPOVARI-EXTDREPORT: {Query Name}

    D_SREPOVARI-VARIANT: {Blank or Name of Initial Variant}

    Separating a filename from path:

    Usually you receive a string with path and filename together and you need to split it and use them to

    update the values in some table or message.

    CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH '

    EXPORTING

    full_name =

    How to add a listbox in the Selection Screen:

    To insert a listbox in the selection screen you need to create an internal table that refers to

    VRM_VALUESs type. In the key field, put the value which will be re turned and in the text field, put the

    value which will be displayed.

    TYPE-POOLS: vrm.

    PARAMETERS: p_tipo type char2 as listbox visible length 30.

  • 7/31/2019 ABAP Frequently Asked Questions

    5/7

    initialization.

    DATA: wa_item TYPE vrm_value,

    t_list TYPE vrm_values.

    wa_item-key = '01'.

    wa_item-text = 'Item1'.

    append wa_item to t_list.

    wa_item-key = 'A2'.

    wa_item-text = 'Item2'.

    append wa_item to t_list.

    CALL FUNCTION 'VRM_SET_VALUES'

    EXPORTING id = 'p_tipo'

    values = t_list.

    p_tipo = '01'.

    start-of-selection.

    write p_tipo.

    How to create an Open File window in the Selection Screen :

    PARAMETER p_file TYPE rlgrap-filename.

    AT SELECTION-SCREEN on VALUE-REQUEST FOR p_file.

  • 7/31/2019 ABAP Frequently Asked Questions

    6/7

    CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

    CHANGING

    file_name = p_file

    EXCEPTIONS

    MASK_TOO_LONG = 1

    OTHERS = 2.

    Getting the Hexadecimal (ASCII) value of a char :

    parameter: field1 type c.

    field-symbols: type x.

    assign field1 to CASTING.

    write: .

    How to Open a Directory window in Selection Screen:

    call method CL_GUI_FRONTEND_SERVICES=>DIRECTORY_BROWSE

    exporting

    WINDOW_TITLE = 'Select a Directory'

    INITIAL_FOLDER = 'C:\yourfoldername'

    changing

    SELECTED_FOLDER = l_path.

    Download and Upload SapScripts:

    To Download and Upload a SapScript in order to test it in another client, you can use the RSTXR3TR

    program. You need to inform the request where the SapScript is saved, choose FileSystem = GUI and

    inform a filename in your computer.

  • 7/31/2019 ABAP Frequently Asked Questions

    7/7

    Save the actual scroll position in an ALV using function:

    When using an ALV function, every user command executed returns the scroll position in row and

    column 1. To solve this problem by getting the actual scroll position, use the function below.

    During the Call of ALV Function

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    i_callback_program = sy-repid

    i_callback_pf_status_set = 'SET_STATUS'

    i_callback_user_command = 'USER_COMMAND'

    In the User_Command FORM, call the function to get actual position.

    CALL FUNCTION 'REUSE_ALV_GRID_LAYOUT_INFO_GET'

    IMPORTING

    ES_GRID_SCROLL = i_scroll

    In the Set_Status FORM, call the function to set the position.

    CALL FUNCTION 'REUSE_ALV_GRID_LAYOUT_INFO_SET'

    EXPORTING

    IS_GRID_SCROLL = i_scroll