Skip to Content
0
Former Member
Jul 06, 2006 at 11:47 AM

table control

41 Views

Hi all,

I am new at using Table control , I am unable to get the selected rows of table control.

On screen '100' when customer no and data are entered ,sales data for the corresponding customer are displayed in table control on the same screen when a button is triggered . now i want to select a record.

I have added sel field it but unable to get . my code is as follow ,Please any of you suggest where I went wrong.

&----


*& Module pool YCUSTOMER_DETAILS *

*& *

PROGRAM ycustomer_details .

TABLES:

kna1,

vbap,

vbak.

*&spwizard: lines of tablecontrol 'TABCONPR'

DATA: g_tabconpr_lines LIKE sy-loopc.

DATA:

fs_fieldcat TYPE lvc_s_fcat, " Field-cat work area

w_grid TYPE REF TO cl_gui_alv_grid,

" ALV Grid

cus_container TYPE REF TO cl_gui_custom_container,

" Custom container

w_grid_layout TYPE lvc_s_layo. " Grid layout

DATA:

t_fieldcat TYPE STANDARD TABLE OF lvc_s_fcat,

t_fieldcat2 TYPE STANDARD TABLE OF lvc_s_fcat.

DATA:

BEGIN OF sales_data OCCURS 0,

sel type c ,

vbeln LIKE vbak-vbeln, " sales doc

erdat LIKE vbak-erdat, " date

bstnk LIKE vbak-bstnk, " po

kostl LIKE vbak-kostl, " cost center

END OF sales_data.

DATA:

BEGIN OF i_salesitem OCCURS 0,

vbeln LIKE vbap-vbeln,

posnr LIKE vbap-posnr,

matnr LIKE vbap-matnr,

pmatn LIKE vbap-pmatn,

END OF i_salesitem.

data:

t_salesitem like standard table of i_salesitem .

DATA:

sel,

w_flag,

pop_confirm TYPE c,

  • cust_no LIKE kna1-kunnr,

from LIKE vbak-erdat,

to LIKE vbak-erdat,

ok_code LIKE sy-ucomm.

CONTROLS: tabctrl TYPE TABLEVIEW USING SCREEN '0100'.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE status_0100 OUTPUT.

SET PF-STATUS 'STATUS'.

  • SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE user_command_0100 INPUT.

CASE ok_code.

WHEN 'CLICK'.

PERFORM sales_data.

WHEN 'EXIT'.

CLEAR ok_code.

LEAVE TO SCREEN '0'.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

WHEN 'ITEM_DETAI'.

loop at sales_data where sel = 'X'.

  • IF sales_data-sel = 'X'.

SELECT vbeln

posnr

matnr

pmatn

FROM vbap

INTO TABLE t_salesitem

WHERE vbeln EQ sales_data-vbeln .

  • AND sel eq 'X'.

  • endif.

endloop.

PERFORM sales_item.

  • IF SEL = 'X'.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

&----


*& Module details_0100 OUTPUT

&----


  • text

----


MODULE details_0100 OUTPUT.

sel = sales_data-sel.

vbak-vbeln = sales_data-vbeln.

vbak-erdat = sales_data-erdat.

vbak-bstnk = sales_data-bstnk.

vbak-kostl = sales_data-kostl.

ENDMODULE. " details_0100 OUTPUT

&----


*& Module hide_0100 OUTPUT

&----


  • text

----


MODULE hide_0100 OUTPUT.

IF w_flag EQ space.

LOOP AT SCREEN.

tabctrl-invisible = 'X'.

MODIFY SCREEN.

ENDLOOP.

ELSE.

LOOP AT SCREEN.

tabctrl-invisible = ''.

MODIFY SCREEN.

ENDLOOP.

ENDIF.

ENDMODULE. " hide_0100 OUTPUT

&----


*& Form BUILD_FIELDCATALOG

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM build_fieldcatalog .

CLEAR: t_fieldcat, t_fieldcat[].

CLEAR fs_fieldcat.

fs_fieldcat-fieldname = 'VBELN'.

  • fs_fieldcat-ref_tabname = 'VBAP' .

fs_fieldcat-tabname = 'T_SALESITEM'.

fs_fieldcat-coltext = 'SALES ORDER'.

APPEND fs_fieldcat TO t_fieldcat.

CLEAR fs_fieldcat.

fs_fieldcat-fieldname = 'POSNR'.

  • fs_fieldcat-ref_tabname = 'VBAP' .

fs_fieldcat-tabname = 'T_SALESITEM'.

fs_fieldcat-coltext = 'SALES DOC ITEM'.

APPEND fs_fieldcat TO t_fieldcat.

CLEAR fs_fieldcat.

fs_fieldcat-fieldname = 'MATNR'.

  • fs_fieldcat-ref_tabname = 'VBAP' .

fs_fieldcat-tabname = 'T_SALESITEM'.

fs_fieldcat-coltext = 'MATERNIAL NO'.

APPEND fs_fieldcat TO t_fieldcat.

CLEAR fs_fieldcat.

fs_fieldcat-fieldname = 'PMATN'.

  • fs_fieldcat-ref_tabname = 'VBAP' .

fs_fieldcat-tabname = 'T_SALESITEM'.

fs_fieldcat-coltext = 'PRICING REFERENCE MATERIAL'.

APPEND fs_fieldcat TO t_fieldcat.

ENDFORM. " BUILD_FIELDCATALOG

&----


*& Module STATUS_0101 OUTPUT

&----


  • text

----


MODULE status_0101 OUTPUT.

SET PF-STATUS 'STATUS' EXCLUDING 'CLICK'.

SET TITLEBAR 'SALES ITEM DATA'.

ENDMODULE. " STATUS_0101 OUTPUT

&----


*& Form display_grid

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_grid .

w_grid_layout-grid_title = 'SALES ITEM DETAILS'.

w_grid_layout-sel_mode = 'A'.

w_grid_layout-cwidth_opt = 'X'.

t_salesitem[] = i_salesitem[].

CALL METHOD w_grid->set_table_for_first_display

EXPORTING

i_save = 'A'

is_layout = w_grid_layout

CHANGING

it_outtab = t_salesitem

it_fieldcatalog = t_fieldcat

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

IF sy-subrc NE 0.

  • MESSAGE e002.

ENDIF.

ENDFORM. " display_grid

&----


*& Form SALES_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sales_data .

w_flag = 'X'.

SELECT vbeln

erdat

bstnk

kostl

FROM vbak

INTO corresponding fields of TABLE sales_data

WHERE kunnr EQ kna1-kunnr

AND erdat GE from

AND erdat LE to .

tabctrl-top_line = 1.

ENDFORM. " SALES_DATA

&----


*& Form SALES_ITEM

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sales_item .

  • Instantiate the container control and Grid control.

IF cl_gui_alv_grid=>offline( ) IS INITIAL.

  • For Foreground Execution

IF cus_container IS INITIAL.

CREATE OBJECT cus_container

EXPORTING

container_name = 'CUST_CONTROL'.

IF w_grid IS INITIAL.

CREATE OBJECT w_grid

EXPORTING

i_parent = cus_container.

ENDIF. " IF W_GRID IS INITIAL

ENDIF. " IF W_CUSTOM_CONTAINER....

ELSE.

  • BackGround Execution

  • CREATE OBJECT w_grid

  • EXPORTING

  • i_parent = w_custom_container.

  • *

    ENDIF. " IF CL_GUI_ALV_GRID=>...

    • TO BULID FIELD CATALOG.

    PERFORM build_fieldcatalog.

    PERFORM display_grid.

    CALL SCREEN '0101'.

    • ENDIF.

    • ENDLOOP.

    ENDFORM. " SALES_ITEM

    &----


    *& Module getsalesitem_0100 INPUT

    &----


    • text

    ----


    module getsalesitem_0100 input.

    LOOP AT sales_data.

    IF sales_data-sel = 'X'.

    SELECT vbeln

    posnr

    matnr

    pmatn

    FROM vbap

    INTO TABLE t_salesitem

    WHERE vbeln EQ sales_data-vbeln .

    endif.

    endloop.

    endmodule. " getsalesitem_0100 INPUT

    &----


    *& Module USER_COMMAND_0101 INPUT

    &----


    • text

    ----


    module USER_COMMAND_0101 input.

    case sy-ucomm.

    WHEN 'EXIT'.

    CLEAR ok_code.

    LEAVE TO SCREEN '0'.

    WHEN 'BACK'.

    LEAVE TO SCREEN '0100'.

    endcase.

    endmodule. " USER_COMMAND_0101 INPUT

    Thanks ,

    Vani.