Skip to Content
author's profile photo Former Member
Former Member

Report

Hi,

I have a requirement where in the o/p i have some records.The checkboxes were placed besides each record.On the top 4 pushbuttons were placed (checkall,uncheckall,change,export).If the user wants to change the data of some fields of a particular record in the o/p,then he checks the checkbox of that particular record and click on the change button.Then the control should go to update screen,where the user can change the data of the fields which he want to change.In the update screen there are 2 pushbuttons(accept,cancle).After changing the data in the update screen,if the user clicks on the accept button the data

should be updated in material master.

How can I do the coding for this

Regards,

Hema

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 30, 2008 at 06:36 AM

    Hi Hema,

    Please mention you are developing a classical report or modulepool.

    On click of Change button write a code to call the update screen.

    User will change the required data and then when he presses the Accept button call the BAPI / function module related to updation to MM.

    Regards,

    Vaibhav.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      Thanks for your reply.I am developing a module pool program.

      How can I write the code to call the update screen.How can I know only for the selected record in the o/p the data can be changed in the update screen.How can i do the coding for this?

      I have written some code for the update screen.It is giving runtime error as 'Program XXXXXXX tried to use the screen 2000.But the screen does not exist'.Here screen 2000 is the update screen.

      How can I solve this problem?

  • author's profile photo Former Member
    Former Member
    Posted on Jan 30, 2008 at 06:47 AM

    here is a similar code for ur requirement.

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

    • Tables

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

    TABLES: z000k_dfm. " DFM Master table

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

    • CONSTANTS *

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

    CONSTANTS:

    c_x TYPE c VALUE 'X'. " Value X

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

    • CONTROLS *

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

    *Table control

    CONTROLS:

    tc_dfmacc TYPE TABLEVIEW USING SCREEN 9000.

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

    • VARIABLE DECLARATION *

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

    DATA:

    v_position TYPE i, " Position

    v_okcode LIKE sy-ucomm, " OK Code

    v_lines TYPE i, " No of Table control lines

    v_err_flag TYPE c, " Error Flag variable

    v_confirm_ind TYPE c, " Indicator for confirm window

    v_insert_flag TYPE c, " Flag variable

    v_modify_flag TYPE c, " Flag variable

    v_tabix LIKE sy-tabix, " Index variable

    v_chgind_flag TYPE c. " Change indicator variable

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

    • INTERNAL TABLES *

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

    • Internal table to fetch data from table.

    DATA:

    BEGIN OF fs_z000k_dfm .

    INCLUDE STRUCTURE z000k_dfm.

    DATA:

    sel TYPE c, " To identify selected row

    ins TYPE c, " To identify inserted row

    END OF fs_z000k_dfm.

    DATA:i_z000k_dfm LIKE STANDARD TABLE OF fs_z000k_dfm.

    • Internal table used for validation.

    DATA:

    BEGIN OF i_z000k_dfm_out OCCURS 0.

    INCLUDE STRUCTURE z000k_dfm.

    DATA:

    sel TYPE c, " To identify selected row

    ins TYPE c, " To identify inserted row

    END OF i_z000k_dfm_out.

    • Working Internal table used to store newly enterd date for validation.

    DATA:

    BEGIN OF i_z000k_dfm_tmp OCCURS 0.

    INCLUDE STRUCTURE z000k_dfm.

    DATA:

    sel TYPE c, " To identify selected row

    ins TYPE c, " To identify inserted row

    END OF i_z000k_dfm_tmp.

    • Internal table to store ok_codes

    DATA:

    BEGIN OF i_okcodes OCCURS 0,

    func_code LIKE sy-ucomm,

    END OF i_okcodes.

    • Work area to hold table control data

    DATA:

    v_dfm LIKE LINE OF " Work area for table control

    tc_dfmacc-cols. " COLS struct TC_ZVC0_SALESINFO

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

    • Start Of Selection *

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

    START-OF-SELECTION.

    *Populate internal table with table entries

    PERFORM f_get_table_data.

    *Call Screen to maintain table Z000K_DFM via table control.

    CALL SCREEN 9000.

    &----


    *& Form F_GET_TABLE_DATA *

    &----


    *This subroutine populates internal table from table Z000K_DFM *

    ----


    *No interface parameters are passed to this subroutine *

    ----


    FORM f_get_table_data.

    CLEAR :

    v_insert_flag,

    v_err_flag,

    v_modify_flag.

    REFRESH

    i_z000k_dfm[].

    • Get all the data from table

    SELECT *

    FROM z000k_dfm

    INTO TABLE i_z000k_dfm.

    IF sy-subrc EQ 0.

    • Do Nothing

    ENDIF. " IF sy-subrc EQ 0

    ENDFORM. " F_GET_TABLE_DATA

    &----


    *& Module STATUS_9000 OUTPUT *

    &----


    • PBO of the screen 9000 *

    ----


    MODULE status_9000 OUTPUT.

    SET PF-STATUS 'SCREEN_9000'.

    SET TITLEBAR 'TITLE'.

    DESCRIBE TABLE i_z000k_dfm LINES v_lines.

    tc_dfmacc-lines = v_lines.

    • Put delete and modify buttons only when there are more entries

    IF v_lines EQ 0.

    REFRESH i_okcodes.

    i_okcodes-func_code = 'MODIFY'.

    APPEND i_okcodes.

    i_okcodes-func_code = 'DELETE'.

    APPEND i_okcodes.

    i_okcodes-func_code = 'SELECTALL'.

    APPEND i_okcodes.

    i_okcodes-func_code = 'DESELECT'.

    APPEND i_okcodes.

    i_okcodes-func_code = 'EXPORT'.

    APPEND i_okcodes.

    SET PF-STATUS 'SCREEN_9000' EXCLUDING i_okcodes IMMEDIATELY.

    ELSE.

    REFRESH i_okcodes.

    SET PF-STATUS 'SCREEN_9000' EXCLUDING i_okcodes IMMEDIATELY.

    ENDIF. " IF v_lines EQ 0

    • To display the data in display mode.

    LOOP AT tc_dfmacc-cols INTO v_dfm.

    v_dfm-screen-input = '0'.

    MODIFY tc_dfmacc-cols FROM

    v_dfm INDEX sy-tabix.

    ENDLOOP. " LOOP AT TC_TMPL_LWEIGHT-COLS

    ENDMODULE. " STATUS_9000 OUTPUT

    &----


    *& Module USER_COMMAND_9000 INPUT *

    &----


    • PAI of the screen 9000 *

    ----


    MODULE user_command_9000 INPUT.

    CASE v_okcode.

    WHEN 'ENTR'.

    IF sy-datar EQ c_x.

    v_chgind_flag = c_x.

    ENDIF. " IF sy-datar = 'X'.

    • This perform inserts records.

    WHEN 'INSERT'.

    CLEAR v_modify_flag.

    PERFORM f_insertrows.

    • This perform is to update/insert the data.

    WHEN 'SAVE'.

    IF v_modify_flag = c_x.

    IF sy-datar = c_x OR v_chgind_flag EQ c_x.

    PERFORM f_dbchange.

    ENDIF. " IF SY-DATAR = 'X'.

    ELSEIF v_insert_flag = c_x.

    PERFORM f_dbsave.

    ENDIF. " IF v_modify_flag = c_x.

    • This perform modifys the existing data .

    WHEN 'MODIFY'.

    PERFORM f_modification.

    • Selects all the entries in control

    WHEN 'SELECTALL'.

    CLEAR fs_z000k_dfm.

    LOOP AT i_z000k_dfm INTO fs_z000k_dfm.

    fs_z000k_dfm-sel = c_x.

    MODIFY i_z000k_dfm FROM fs_z000k_dfm

    TRANSPORTING sel.

    ENDLOOP. " LOOP AT i_Z000K_DFM

    • Deselects all the selected records in control

    WHEN 'DESELECT'.

    CLEAR fs_z000k_dfm.

    LOOP AT i_z000k_dfm INTO fs_z000k_dfm.

    fs_z000k_dfm-sel = space.

    MODIFY i_z000k_dfm FROM fs_z000k_dfm

    TRANSPORTING sel.

    ENDLOOP. " LOOP AT i_Z000K_DFM

    • Delete selected entries

    WHEN 'DELETE'.

    CLEAR:

    v_modify_flag,

    v_insert_flag.

    PERFORM f_dbdelete.

    • Exit from program

    WHEN 'EXIT'.

    LEAVE PROGRAM.

    • Leaving to selection screen

    WHEN 'CANCEL' OR 'BACK'.

    v_confirm_ind = 'N'.

    IF sy-datar EQ c_x.

    v_chgind_flag = c_x.

    ENDIF. " IF sy-datar EQ c_x

    IF ( v_insert_flag EQ c_x AND ( sy-datar = c_x OR

    v_chgind_flag EQ c_x ) )

    OR

    ( v_modify_flag EQ c_x AND ( sy-datar = c_x OR

    v_chgind_flag EQ c_x ) ).

    CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'

    EXPORTING

    defaultoption = 'Y'

    textline1 = text-001

    titel = text-002

    IMPORTING

    answer = v_confirm_ind.

    ENDIF. " IF ( v_insert_flag EQ c_x

    IF v_confirm_ind EQ 'A'.

    CLEAR v_modify_flag.

    ELSEIF v_confirm_ind EQ 'N'.

    LEAVE TO SCREEN 0.

    ENDIF. " IF v_confirm_ind EQ 'A'.

    • Insert/modify the data.

    IF v_confirm_ind = 'J'.

    IF v_modify_flag = c_x.

    PERFORM f_dbchange.

    ELSE.

    PERFORM f_dbsave.

    ENDIF. " IF v_modify_flag = c_x.

    ENDIF. " IF v_confirm_ind = 'J'.

    • Export to Excel

    WHEN 'EXPORT'.

    PERFORM f_export.

    ENDCASE. " CASE v_okcode.

    CLEAR v_okcode.

    ENDMODULE. " USER_COMMAND_9000 INPUT

    &----


    *& Form F_VALIDATION *

    &----


    • Validate the data of new or modified entries *

    ----


    • There are no interface parameters to be passed to this subroutine *

    ----


    FORM f_validation.

    DATA:

    l_dfmacc LIKE z000k_dfm-dfmaccount." DFM Account

    REFRESH:

    i_z000k_dfm_out,

    i_z000k_dfm_tmp.

    CLEAR:

    i_z000k_dfm_out,

    i_z000k_dfm_tmp.

    • Populate enterd data in internal table i_Z000K_DFM_TMP

    LOOP AT i_z000k_dfm INTO fs_z000k_dfm WHERE ins EQ c_x.

    i_z000k_dfm_tmp = fs_z000k_dfm.

    APPEND i_z000k_dfm_tmp.

    ENDLOOP. " LOOP AT i_Z000K_DFM

    IF v_modify_flag EQ c_x.

    • Populate enterd data in internal table i_Z000K_DFM_TMP

    LOOP AT i_z000k_dfm INTO fs_z000k_dfm WHERE sel EQ c_x.

    i_z000k_dfm_tmp = fs_z000k_dfm.

    APPEND i_z000k_dfm_tmp.

    ENDLOOP. " LOOP AT i_Z000K_DFM

    ENDIF. " IF v_modify_flag EQ c_x

    i_z000k_dfm_out[] = i_z000k_dfm[].

    DELETE i_z000k_dfm_out WHERE ins EQ c_x.

    IF v_modify_flag EQ c_x.

    DELETE i_z000k_dfm_out WHERE sel EQ c_x.

    ENDIF. " IF v_modify_flag EQ c_x

    SORT:

    i_z000k_dfm_tmp BY dfmaccount,

    i_z000k_dfm_out BY dfmaccount.

    IF v_modify_flag EQ c_x OR v_insert_flag EQ c_x.

    LOOP AT i_z000k_dfm_tmp.

    IF l_dfmacc EQ i_z000k_dfm_tmp-dfmaccount.

    v_err_flag = c_x.

    MESSAGE i002(8a) WITH i_z000k_dfm_tmp-dfmaccount.

    EXIT.

    ENDIF. " IF lv_dfmacc EQ..

    l_dfmacc = i_z000k_dfm_tmp-dfmaccount.

    READ TABLE i_z000k_dfm_out WITH KEY dfmaccount =

    i_z000k_dfm_tmp-dfmaccount.

    IF sy-subrc EQ 0.

    v_err_flag = c_x.

    MESSAGE i002(8a) WITH i_z000k_dfm_tmp-dfmaccount.

    EXIT.

    ENDIF. " IF SY-SUBRC EQ 0

    ENDLOOP. " LOOP AT i_Z000K_DFM_TMP

    ENDIF. " IF v_modify_flag EQ c_x

    IF v_err_flag NE c_x.

    • Check all mandatory fields are entered

    PERFORM f_mand_fields.

    ENDIF. " IF v_err_flag NE c_x

    IF v_err_flag NE c_x.

    LOOP AT i_z000k_dfm_tmp.

    IF v_err_flag NE c_x.

    APPEND i_z000k_dfm_tmp TO i_z000k_dfm_out.

    ELSE.

    EXIT.

    ENDIF. " IF v_err_flag NE c_x

    ENDLOOP. " LOOP AT i_Z000K_DFM_tmp

    ENDIF. " IF v_err_flag NE

    ENDFORM. " F_VALIDATION

    &----


    *& Form F_MAND_FIELDS *

    &----


    • Check all the required fields are populated or not *

    ----


    • There are no interface parameters to be passed to this subroutine *

    ----


    FORM f_mand_fields.

    LOOP AT i_z000k_dfm_tmp.

    IF i_z000k_dfm_tmp-dfmaccount IS INITIAL

    OR i_z000k_dfm_tmp-dfmaccdesc IS INITIAL.

    v_err_flag = c_x.

    MESSAGE i055(00).

    EXIT.

    ENDIF. " IF i_Z000K_DFM_TMP-DFMACCOUNT

    ENDLOOP. " Loop at i_Z000K_DFM_TMP

    ENDFORM. " F_MAND_FIELDS

    ----


    • Form F_INSERTROWS *

    ----


    • To insert row in the internal Table i_Z000K_DFM *

    ----


    • There are no interface parameters to be passed to this subroutine *

    ----


    FORM f_insertrows .

    DESCRIBE TABLE i_z000k_dfm LINES v_tabix.

    v_tabix = v_tabix + 1.

    v_insert_flag = c_x.

    tc_dfmacc-lines = tc_dfmacc-lines + 1.

    CLEAR fs_z000k_dfm.

    fs_z000k_dfm-ins = c_x.

    INSERT fs_z000k_dfm INTO i_z000k_dfm INDEX v_tabix.

    ENDFORM. " F_INSERTROWS

    &----


    *& Form F_DBCHANGE *

    &----


    • Updates the data into zvc0_salesinfo from table control *

    ----


    • There are no interface parameters to be passed to this subroutine *

    ----


    FORM f_dbchange .

    • To validate the enterd data with the other entered

    • data & with existing data

    PERFORM f_validation.

    IF v_err_flag NE c_x.

    MODIFY z000k_dfm FROM TABLE i_z000k_dfm_tmp.

    IF sy-subrc EQ 0.

    MESSAGE s000(15).

    CLEAR:

    v_modify_flag,

    v_insert_flag,

    v_err_flag,

    v_chgind_flag.

    LOOP AT i_z000k_dfm INTO fs_z000k_dfm.

    fs_z000k_dfm-sel = space.

    fs_z000k_dfm-ins = space.

    MODIFY i_z000k_dfm FROM fs_z000k_dfm

    TRANSPORTING sel ins.

    ENDLOOP. " LOOP AT i_Z000K_DFM

    ELSE.

    MESSAGE e531(0u) WITH text-011.

    ENDIF. " IF sy-subrc EQ 0.

    ENDIF. " IF v_error_flag NE c_x.

    ENDFORM. " F_DBCHANGE

    &----


    *& Form F_DBSAVE *

    &----


    • Performs validations before saving the records *

    ----


    • There are no interface parameters to be passed to this subroutine *

    ----


    FORM f_dbsave .

    • To validate the enterd data with the other entered

    • data & with existing data

    PERFORM f_validation.

    IF v_err_flag NE c_x.

    • To insert data in database if the entered data is valid.

    PERFORM f_dbupdate.

    ENDIF. " IF v_err_flag NE c_x.

    ENDFORM. " F_DBSAVE

    ----


    • Form F_DBUPDATE *

    ----


    • To insert or update data in database. *

    ----


    • There are no interface parameters to be passed to this subroutine *

    ----


    FORM f_dbupdate .

    INSERT z000k_dfm FROM TABLE i_z000k_dfm_tmp.

    IF sy-subrc EQ 0.

    MESSAGE s531(0u) WITH text-003.

    CLEAR:

    v_insert_flag,

    v_err_flag.

    LOOP AT i_z000k_dfm INTO fs_z000k_dfm.

    fs_z000k_dfm-sel = space.

    fs_z000k_dfm-ins = space.

    MODIFY i_z000k_dfm FROM fs_z000k_dfm

    TRANSPORTING sel ins.

    ENDLOOP. " LOOP AT i_Z000K_DFM

    ELSE.

    MESSAGE e811(clmm) WITH text-013.

    ENDIF. " IF sy-subrc EQ 0.

    ENDFORM. " F_DBUPDATE

    &----


    *& Form F_MODIFICATION *

    &----


    • To check the authority and check for the selection of record before *

    • modification *

    ----


    • There are no interface parameters to be passed to this subroutine *

    ----


    FORM f_modification.

    READ TABLE i_z000k_dfm INTO fs_z000k_dfm

    WITH KEY sel = c_x.

    IF sy-subrc NE 0.

    MESSAGE s609(00).

    ELSE.

    CLEAR v_err_flag.

    REFRESH i_z000k_dfm_out.

    LOOP AT i_z000k_dfm INTO fs_z000k_dfm

    WHERE sel = c_x.

    i_z000k_dfm_out = fs_z000k_dfm.

    APPEND i_z000k_dfm_out.

    ENDLOOP. " LOOP AT i_z000k_dfm

    IF v_err_flag NE c_x.

    v_modify_flag = c_x.

    ENDIF. " IF v_ERR_FLAG NE c_x.

    ENDIF. " IF sy-subrc NE 0.

    ENDFORM. " F_MODIFICATION

    ----


    • Form F_DBDELETE *

    ----


    • To delete the selected row *

    ----


    • There are no interface parameters to be passed to this subroutine *

    ----


    FORM f_dbdelete .

    • DATA:

    • i_z000k_pc_dfm LIKE z000k_pc_dfm OCCURS 0

    • WITH HEADER LINE.

    READ TABLE i_z000k_dfm INTO fs_z000k_dfm

    WITH KEY sel = c_x.

    IF sy-subrc NE 0.

    MESSAGE s609(00).

    ELSE.

    CLEAR v_err_flag.

    REFRESH i_z000k_dfm_out.

    LOOP AT i_z000k_dfm INTO fs_z000k_dfm

    WHERE sel = c_x.

    i_z000k_dfm_out = fs_z000k_dfm.

    APPEND i_z000k_dfm_out.

    ENDLOOP. " LOOP AT i_z000k_dfm

    • IF NOT i_z000k_dfm_out[] IS INITIAL.

    • SORT i_z000k_dfm_out BY dfmaccount.

    • SELECT *

    • FROM z000k_pc_dfm

    • INTO TABLE i_z000k_pc_dfm

    • FOR ALL ENTRIES IN i_z000k_dfm_out

    • WHERE dfmaccount EQ i_z000k_dfm_out-dfmaccount.

    *

    • IF sy-subrc EQ 0.

    • SORT i_z000k_pc_dfm BY dfmaccount.

    • LOOP AT i_z000k_dfm_out INTO fs_z000k_dfm.

    • READ TABLE i_z000k_pc_dfm WITH KEY dfmaccount =

    • fs_z000k_dfm-dfmaccount BINARY SEARCH.

    • IF sy-subrc EQ 0.

    • DELETE i_z000k_dfm_out WHERE dfmaccount =

    • fs_z000k_dfm-dfmaccount.

    • fs_z000k_dfm-sel = ''.

    • APPEND fs_z000k_dfm TO i_z000k_dfm .

    • ENDIF. " IF SY-SUBRC EQ 0

    • ENDLOOP. " LOOP AT ..

    • ENDIF. " IF SY-SUBRC EQ 0

    • ENDIF. " IF SY-SUBRC EQ 0

    IF i_z000k_dfm_out[] IS INITIAL.

    SORT i_z000k_dfm BY dfmaccount.

    DELETE ADJACENT DUPLICATES FROM i_z000k_dfm

    comparing dfmaccount.

    MESSAGE e001(seudependency).

    CLEAR i_z000k_dfm_out.

    ELSE.

    CLEAR v_confirm_ind.

    CALL FUNCTION 'POPUP_TO_CONFIRM'

    EXPORTING

    titlebar = 'Warning'(010)

    text_question = text-009

    text_button_1 = 'Yes'

    icon_button_1 = 'ICON_OKAY'

    text_button_2 = 'No'

    icon_button_2 = 'ICON_CANCEL'

    default_button = '2'

    display_cancel_button = ' '

    start_column = 25

    start_row = 6

    popup_type = 'ICON_MESSAGE_WARNING'

    IMPORTING

    answer = v_confirm_ind.

    IF v_confirm_ind = '1'.

    DELETE z000k_dfm FROM TABLE i_z000k_dfm_out[].

    IF sy-subrc EQ 0.

    DELETE i_z000k_dfm WHERE sel = c_x.

    sort i_z000k_dfm by dfmaccount.

    MESSAGE s531(0u) WITH text-012.

    ENDIF. " IF sy-subrc EQ 0.

    ENDIF. " IF v_confirm_ind = '1'.

    ENDIF. " IF SY-SUBRC EQ 0

    ENDIF. " IF sy-subrc NE 0.

    ENDFORM. " F_DBDELETE

    ----


    • Module F_POPULATE_DATA OUTPUT *

    ----


    • To populate data *

    ----


    • There are no interface parameters to be passed to this subroutine *

    ----


    MODULE f_populate_data OUTPUT.

    CLEAR fs_z000k_dfm.

    READ TABLE i_z000k_dfm INTO fs_z000k_dfm

    INDEX tc_dfmacc-current_line.

    ENDMODULE. " F_POPULATE_DATA OUTPUT

    ----


    • Module F_ENABLE_TC OUTPUT *

    ----


    • Make cols in edit mode while insertion & change. *

    ----


    • There are no interface parameters to be passed to this subroutine *

    ----


    MODULE f_enable_tc OUTPUT.

    LOOP AT SCREEN.

    IF fs_z000k_dfm-ins EQ c_x .

    screen-input = 1.

    ELSEIF v_modify_flag EQ c_x AND

    fs_z000k_dfm-sel EQ c_x.

    IF screen-name EQ 'FS_Z000K_DFM-DFMACCDESC'.

    screen-input = 1.

    ELSE.

    screen-input = 0.

    ENDIF. " IF screen-name EQ 'I_ZVC0_S..

    ENDIF. " IF I_ZVC0_SALESINFO-INS EQ ..

    MODIFY SCREEN.

    ENDLOOP. " LOOP AT SCREEN.

    ENDMODULE. " F_ENABLE_TC OUTPUT

    ----


    • Module F_PROCESS_DATA INPUT *

    ----


    • Populating the I.T i_Z000K_DFM from Table control *

    ----


    • There are no interface parameters to be passed to this subroutine *

    ----


    MODULE f_process_data INPUT.

    CLEAR v_err_flag.

    IF v_lines EQ 0.

    v_insert_flag = c_x.

    fs_z000k_dfm-ins = c_x.

    INSERT fs_z000k_dfm INTO i_z000k_dfm

    INDEX tc_dfmacc-current_line.

    ENDIF. " IF v_lines EQ 0.

    MODIFY i_z000k_dfm FROM fs_z000k_dfm

    INDEX tc_dfmacc-current_line.

    ENDMODULE. " F_PROCESS_DATA INPUT

    &----


    *& Module F_SET_CURSOR OUTPUT *

    &----


    • This subroutine is used to place the cursor on invalid record *

    ----


    • There are no interface parameters to be passed to this subroutine *

    ----


    MODULE f_set_cursor OUTPUT.

    IF v_position NE 0 .

    SET CURSOR LINE v_position.

    CLEAR v_position.

    ENDIF. " IF v_position NE 0

    ENDMODULE. " F_PROCESS_DATA INPUT

    &----


    *& Form F_EXPORT *

    &----


    • This subroutine is used to export the data to excel *

    ----


    • There are no interface parameters to be passed to this subroutine *

    ----


    FORM f_export.

    • Internal table for DFM Accounts

    DATA:

    BEGIN OF li_export OCCURS 0,

    dfmaccount LIKE " DFM Account

    z000k_dfm-dfmaccount,

    dfmaccdesc LIKE " DFM Account Desc

    z000k_dfm-dfmaccdesc,

    END OF li_export.

    • File Path

    DATA:

    l_file LIKE rlgrap-filename, " File Path

    l_file1 TYPE string. " File Path

    • Select all the entries into internal table

    SELECT dfmaccount " DFM Account

    dfmaccdesc " DFM Acc Desc

    FROM z000k_dfm

    INTO TABLE li_export.

    IF NOT li_export[] IS INITIAL.

    li_export-dfmaccount = 'DFMAccount'(004).

    li_export-dfmaccdesc = 'DFM Account Desc'(005).

    INSERT li_export INDEX 1.

    • Pop Window to choose file name

    CALL FUNCTION 'F4_FILENAME'

    EXPORTING

    program_name = syst-cprog

    dynpro_number = syst-dynnr

    IMPORTING

    file_name = l_file.

    IF NOT l_file IS INITIAL.

    l_file1 = l_file.

    • Validate File path

    PERFORM f_validate_file USING l_file1.

    • Export to Excel

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    filename = l_file1

    filetype = 'ASC'

    write_field_separator = 'X'

    TABLES

    data_tab = li_export[]

    EXCEPTIONS

    file_write_error = 1

    no_batch = 2

    gui_refuse_filetransfer = 3

    invalid_type = 4

    no_authority = 5

    unknown_error = 6

    header_not_allowed = 7

    separator_not_allowed = 8

    filesize_not_allowed = 9

    header_too_long = 10

    dp_error_create = 11

    dp_error_send = 12

    dp_error_write = 13

    unknown_dp_error = 14

    access_denied = 15

    dp_out_of_memory = 16

    disk_full = 17

    dp_timeout = 18

    file_not_found = 19

    dataprovider_exception = 20

    control_flush_error = 21

    OTHERS = 22.

    IF sy-subrc NE 0.

    MESSAGE e815(td) WITH space.

    ENDIF. " IF SY-SUBRC EQ 0

    ELSE.

    MESSAGE e143(xw).

    EXIT.

    ENDIF. " IF SY-SUBRC EQ 0

    ELSE.

    MESSAGE i531(0u) WITH text-014.

    ENDIF. " IF SY-SUBRC EQ 0.

    ENDFORM. " F_EXPORT

    &----


    *& Form F_VALIDATE_FILE *

    &----


    • This subroutine is used to validate the existence of local file *

    ----


    • -->P_LV_FILE1 File path *

    ----


    FORM f_validate_file USING p_lv_file1 TYPE string.

    DATA:

    l_file TYPE string, " File path

    l_res TYPE c, " Result

    l_ans TYPE c. " Answer

    l_file = p_lv_file1.

    *To Validate given file path

    CALL METHOD cl_gui_frontend_services=>file_exist

    EXPORTING

    file = l_file

    RECEIVING

    result = l_res

    EXCEPTIONS

    cntl_error = 1

    error_no_gui = 2

    wrong_parameter = 3

    OTHERS = 5.

    IF sy-subrc NE 0.

    MESSAGE e005(tl).

    ELSE.

    IF NOT l_res IS INITIAL.

    CALL FUNCTION 'POPUP_CONTINUE_YES_NO'

    EXPORTING

    defaultoption = 'Y'

    textline1 = text-015

    textline2 = text-016

    titel = text-017

    start_column = 25

    start_row = 6

    IMPORTING

    answer = l_ans.

    IF l_ans EQ 'N'.

    MESSAGE e502(ctwf).

    ENDIF. " IF l_ans EQ 'N'

    ENDIF. " IF NOT l_res IS

    ENDIF. " IF sy-subrc NE 0

    ENDFORM. " F_VALIDATE_FILE

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.