Skip to Content
author's profile photo
Former Member

SIMPLE program for retriving data from DATABASE

Hi friends,

i have one calss.. in that some structure is there now my requirement is i want to write a simple program that should be fetch the data from ZTABLE and load that data into structure of my calss...

for that what i have to write the coding...

for example : my class name is ZAK27CO_A27_PROXY_TO_FILE_MI_O

and my output structure in the class is ZAK27A27_PROXY_TO_FILE_MT_OB

(This structure contain 4 fields those are EMPNO, ENAME , SAL ,DEPT)

and i want to retrive the data from ZEMPTABLE: so, i want to retrive these 4 fields (EMPNO,ENAME, SAL, DEPT) from ztable and i want to move these data into structure of a class..

plz provide me the exact coding..

Thanks

Babu

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • author's profile photo
    Former Member
    Posted on Sep 28, 2007 at 04:53 AM

    hi

    i will give u a sample program,

    CLASS timer_event DEFINITION.

    PUBLIC SECTION.

    METHODS: time_over FOR EVENT finished OF cl_gui_timer.

    ENDCLASS. "timer_event DEFINITION

    ----


    • CLASS timer_event IMPLEMENTATION

    ----


    *

    ----


    CLASS timer_event IMPLEMENTATION.

    METHOD time_over.

    cl_gui_cfw=>set_new_ok_code( new_code = 'ONLI' ).

    ENDMETHOD. "time_over

    ENDCLASS. "timer_event IMPLEMENTATION

    CLASS lcl_events DEFINITION DEFERRED.

    DATA: container TYPE scrfname VALUE 'SCRCONTAINER',

    custom_container TYPE REF TO cl_gui_custom_container,

    obj_con_pop TYPE REF TO cl_gui_dialogbox_container,

    grid1 TYPE REF TO lcl_events,

    grid2 TYPE REF TO cl_gui_alv_grid,

    grid3 TYPE REF TO lcl_events,

    event TYPE REF TO lcl_events,

    layout TYPE lvc_s_layo.

    DATA: ls_col_id TYPE lvc_s_col.

    DATA: row TYPE i,

    wa_row TYPE lvc_s_row,

    it_row1 TYPE lvc_t_row,

    wa_row1 LIKE LINE OF it_row1,

    it_rowid TYPE lvc_t_roid,

    wa_rowid LIKE LINE OF it_rowid.

    DATA: it_fieldcat TYPE lvc_t_fcat,

    wa_fieldcat LIKE LINE OF it_fieldcat.

    DATA: it_fieldcat2 TYPE lvc_t_fcat,

    wa_fieldcat2 LIKE LINE OF it_fieldcat2.

    DATA: auto_timer TYPE REF TO cl_gui_timer,

    auto_ref TYPE REF TO timer_event.

    DATA: display TYPE i,

    fn_code TYPE sy-ucomm.

    DATA : BEGIN OF wa_popupfields,

    matnr LIKE mast-matnr,

    werks LIKE mast-werks,

    stlan LIKE mast-stlan,

    stlnr LIKE mast-stlnr,

    stlal LIKE mast-stlal,

    andat LIKE mast-andat,

    annam LIKE mast-annam,

    END OF wa_popupfields.

    DATA : l TYPE i,

    tab TYPE i.

    DATA: it_popupfields LIKE TABLE OF wa_popupfields.

    INCLUDE z282_obj1_datadeclaration.

    INCLUDE z282_obj1_screendesign.

    *CALL SELECTION-SCREEN 2000.

    AT SELECTION-SCREEN OUTPUT.

    CREATE OBJECT: auto_timer, auto_ref.

    SET HANDLER auto_ref->time_over FOR auto_timer.

    auto_timer->interval = 20.

    auto_timer->run( ).

    AT SELECTION-SCREEN.

    IF matnr AND werks AND lgort IS INITIAL.

    MESSAGE e001.

    ELSE.

    INCLUDE z282_obj1_selection.

    DESCRIBE TABLE it_matdetails LINES display.

    ENDIF.

    CALL SCREEN 3000.

    *----


    • CLASS LCL_EVENTS DEFINITION

    ----


    *

    ----


    CLASS lcl_events DEFINITION INHERITING FROM cl_gui_alv_grid.

    PUBLIC SECTION.

    METHODS: click FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row e_column es_row_no,

    pop_close FOR EVENT close OF cl_gui_dialogbox_container

    IMPORTING sender,

    select.

    ENDCLASS. "LCL_EVENTS DEFINITION

    &----


    *& Module STATUS_3000 OUTPUT

    &----


    • text

    ----


    MODULE status_3000 OUTPUT.

    SET PF-STATUS 'GRIDSCREEN'.

    IF custom_container IS INITIAL.

    PERFORM container_load.

    ENDIF.

    ENDMODULE. " STATUS_3000 OUTPUT

    &----


    *& Module USER_COMMAND_3000 INPUT

    &----


    • text

    ----


    MODULE user_command_3000 INPUT.

    fn_code = sy-ucomm.

    CASE fn_code.

    WHEN 'BACK'.

    CALL SELECTION-SCREEN 2000.

    WHEN 'EXIT'.

    LEAVE PROGRAM.

    WHEN 'CANCEL'.

    LEAVE PROGRAM.

    WHEN 'CHANGE'.

    CALL METHOD grid1->set_ready_for_input

    EXPORTING

    i_ready_for_input = 1.

    WHEN 'BOM'.

    CLEAR row.

    CALL METHOD grid1->get_current_cell

    IMPORTING

    e_row = row

    es_row_id = wa_row.

    PERFORM popup.

    WHEN 'UPDATE'.

    CALL METHOD grid1->set_ready_for_input

    EXPORTING

    i_ready_for_input = 0.

    WHEN 'RESTORE'.

    it_matdetails = it_mat.

    CALL METHOD grid1->set_table_for_first_display

    EXPORTING

    i_structure_name = 'WA_MATDETAILS'

    is_layout = layout

    CHANGING

    it_outtab = it_matdetails

    it_fieldcatalog = it_fieldcat.

    WHEN 'ALL'.

    CALL METHOD grid1->select.

    WHEN 'BLOCK'.

    CALL METHOD grid1->refresh_table_display.

    WHEN 'INSERT'.

    • CALL METHOD grid1->append_rows

    • EXPORTING

    • i_row_count = 1.

    *

    APPEND INITIAL LINE TO it_matdetails.

    CALL METHOD grid1->refresh_table_display.

    CALL METHOD grid1->set_ready_for_input

    EXPORTING

    i_ready_for_input = 1.

    WHEN 'DELETE'.

    REFRESH: it_row1, it_rowid.

    CALL METHOD grid1->get_selected_rows

    IMPORTING

    et_index_rows = it_row1

    et_row_no = it_rowid.

    DESCRIBE TABLE it_row1 LINES l.

    tab = l.

    DO l TIMES.

    READ TABLE it_row1 INTO wa_row1 INDEX tab.

    DELETE it_matdetails INDEX wa_row1-index.

    tab = tab - 1.

    ENDDO.

    CALL METHOD grid1->refresh_table_display.

    display = display - l.

    WHEN 'UP'.

    CALL METHOD grid1->get_current_cell

    IMPORTING

    es_col_id = ls_col_id.

    PERFORM sort_up.

    WHEN 'DOWN'.

    CALL METHOD grid1->get_current_cell

    IMPORTING

    es_col_id = ls_col_id.

    PERFORM sort_down.

    ENDCASE.

    ENDMODULE. " USER_COMMAND_3000 INPUT

    ----


    • CLASS LCL_EVENTS IMPLEMENTATION

    ----


    *

    ----


    CLASS lcl_events IMPLEMENTATION.

    METHOD click.

    READ TABLE it_matdetails INTO wa_matdetails INDEX e_row.

    SET PARAMETER ID 'MAT' FIELD wa_matdetails-matnr.

    CALL TRANSACTION 'MM02' AND SKIP FIRST SCREEN.

    ENDMETHOD. "CLICK

    METHOD select.

    CALL METHOD grid1->select_all_rows.

    ENDMETHOD. "select

    METHOD pop_close.

    CALL METHOD sender->set_visible

    EXPORTING

    visible = space.

    ENDMETHOD. "POP_CLOSE

    ENDCLASS. "LCL_EVENTS IMPLEMENTATION

    &----


    *& Form CONTAINER_LOAD

    &----


    • text

    ----


    FORM container_load.

    CREATE OBJECT custom_container

    EXPORTING

    container_name = container.

    CREATE OBJECT grid1

    EXPORTING

    i_parent = custom_container.

    PERFORM loadingvalues.

    layout-zebra = 'X'.

    layout-no_toolbar = 'X'.

    layout-sel_mode = 'A'.

    layout-edit = 'A'.

    layout-grid_title = 'Grid Container for Material Display'.

    CALL METHOD grid1->set_table_for_first_display

    EXPORTING

    i_structure_name = 'WA_MATDETAILS'

    is_layout = layout

    CHANGING

    it_outtab = it_matdetails

    it_fieldcatalog = it_fieldcat.

    CREATE OBJECT event

    EXPORTING

    i_parent = custom_container.

    SET HANDLER event->click FOR grid1.

    call method cl_gui_control=>set_focus exporting control = grid1.

    ENDFORM. "CONTAINER_LOAD

    INCLUDE zfieldcatalog.

    &----


    *& Form POPUP

    &----


    • text

    ----


    FORM popup.

    CREATE OBJECT obj_con_pop

    EXPORTING

    width = 300

    height = 300

    top = 30

    left = 30.

    CREATE OBJECT grid2

    EXPORTING

    i_parent = obj_con_pop.

    PERFORM popupload.

    CALL METHOD grid2->set_table_for_first_display

    • EXPORTING

    • I_STRUCTURE_NAME = 'WA_POPUPFIELDS'

    • IS_LAYOUT =

    CHANGING

    it_outtab = it_popupfields

    it_fieldcatalog = it_fieldcat2.

    DATA: obj_cl_event TYPE REF TO lcl_events.

    CREATE OBJECT obj_cl_event

    EXPORTING

    i_parent = obj_con_pop.

    SET HANDLER obj_cl_event->pop_close FOR obj_con_pop.

    ENDFORM. "POPUP

    &----


    *& Form POPUPLOAD

    &----


    • text

    ----


    FORM popupload.

    READ TABLE it_matdetails INTO wa_matdetails INDEX row.

    SELECT matnr werks stlan stlnr stlal andat annam FROM mast INTO TABLE it_popupfields WHERE matnr = wa_matdetails-matnr.

    PERFORM fieldcat2 USING 'MATNR' 'IT_POPUPFIELDS' 'Material Number' 10.

    PERFORM fieldcat2 USING 'WERKS' 'IT_POPUPFIELDS' 'Plant' 10.

    PERFORM fieldcat2 USING 'STLAN' 'IT_POPUPFIELDS' 'BOM usage' 10.

    PERFORM fieldcat2 USING 'STLNR' 'IT_POPUPFIELDS' 'BOM' 10.

    PERFORM fieldcat2 USING 'STLAL' 'IT_POPUPFIELDS' 'Alternative BOM' 10.

    PERFORM fieldcat2 USING 'ANDAT' 'IT_POPUPFIELDS' 'Data record created on' 10.

    PERFORM fieldcat2 USING 'ANNAM' 'IT_POPUPFIELDS' 'User' 10.

    ENDFORM. "POPUPLOAD

    &----


    *& Form FIELDCAT2

    &----


    • text

    ----


    • -->FNAME text

    • -->TNAME text

    • -->REPTEXT text

    • -->OUTPUTLEN text

    ----


    FORM fieldcat2 USING fname tname reptext outputlen.

    wa_fieldcat2-fieldname = fname.

    wa_fieldcat2-tabname = tname.

    wa_fieldcat2-reptext = reptext.

    wa_fieldcat2-outputlen = outputlen.

    APPEND wa_fieldcat2 TO it_fieldcat2.

    CLEAR wa_fieldcat2.

    ENDFORM. "FIELDCAT2

    &----


    *& Form SORT_UP

    &----


    • text

    ----


    FORM sort_up.

    CASE ls_col_id.

    WHEN 'MATNR' .

    SORT it_matdetails DESCENDING STABLE BY matnr .

    WHEN 'ERSDA'.

    SORT it_matdetails DESCENDING STABLE BY ersda.

    WHEN 'MTART' .

    SORT it_matdetails DESCENDING STABLE BY mtart .

    WHEN 'MEINS' .

    SORT it_matdetails DESCENDING STABLE BY meins .

    WHEN 'BSTME' .

    SORT it_matdetails DESCENDING STABLE BY bstme .

    WHEN 'MAKTX' .

    SORT it_matdetails DESCENDING STABLE BY maktx .

    WHEN 'BWKEY' .

    SORT it_matdetails DESCENDING STABLE BY bwkey .

    WHEN 'LBKUM' .

    SORT it_matdetails DESCENDING STABLE BY lbkum .

    WHEN 'SALK3' .

    SORT it_matdetails DESCENDING STABLE BY salk3 .

    WHEN 'STPRS' .

    SORT it_matdetails DESCENDING STABLE BY stprs .

    WHEN 'PEINH' .

    SORT it_matdetails DESCENDING STABLE BY peinh .

    WHEN 'BKLAS' .

    SORT it_matdetails DESCENDING STABLE BY bklas .

    ENDCASE .

    CALL METHOD grid1->refresh_table_display .

    ENDFORM. "SORT_UP

    &----


    *& Form SORT_DOWN

    &----


    • text

    ----


    FORM sort_down.

    CASE ls_col_id.

    WHEN 'MATNR' .

    SORT it_matdetails ASCENDING STABLE BY matnr .

    WHEN 'ERSDA'.

    SORT it_matdetails ASCENDING STABLE BY ersda.

    WHEN 'MTART' .

    SORT it_matdetails ASCENDING STABLE BY mtart .

    WHEN 'MEINS' .

    SORT it_matdetails ASCENDING STABLE BY meins .

    WHEN 'BSTME' .

    SORT it_matdetails ASCENDING STABLE BY bstme .

    WHEN 'MAKTX' .

    SORT it_matdetails ASCENDING STABLE BY maktx .

    WHEN 'BWKEY' .

    SORT it_matdetails ASCENDING STABLE BY bwkey .

    WHEN 'LBKUM' .

    SORT it_matdetails ASCENDING STABLE BY lbkum .

    WHEN 'SALK3' .

    SORT it_matdetails ASCENDING STABLE BY salk3 .

    WHEN 'STPRS' .

    SORT it_matdetails ASCENDING STABLE BY stprs .

    WHEN 'PEINH' .

    SORT it_matdetails ASCENDING STABLE BY peinh .

    WHEN 'BKLAS' .

    SORT it_matdetails ASCENDING STABLE BY bklas .

    ENDCASE .

    CALL METHOD grid1->refresh_table_display .

    ENDFORM. "SORT_DOWN

    <b>Pls reward if helpful.</b>

    Add comment
    10|10000 characters needed characters exceeded