Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ALV table

Former Member
0 Likes
571

Hi all.

I want to create a alv table for user to enter records and save all the enter record at one save in a table. How can i do this? Any alv code available?

Example

student alv Table

Name | Address | Contact

record enter: Gary abc 123

Peter def 456

save button

Thanks

4 REPLIES 4
Read only

hymavathi_oruganti
Active Contributor
0 Likes
531

yah u can do this this normal alv by putting edit = 'x' for the fields while building fieldcat.but for saving u have to select the row and then save data. but the problem comes when we have to catch the data_changed.

if u switch it to oo alv, u can easily do this.

there are methods, data_changed, get_selected_rows. using these methods we can achive this easily.

for guidance to ooalv, there are many posts in this forum. if still u need help. i will guide u no problem. try doing with oo slv. it will be simple

Read only

0 Likes
531

Thk for yr fast response.

Do you have available source code for my situation.

Because i new to alv. Therefore it will be difficult for me to start on a new stretch.

Thank for helping!

Read only

0 Likes
531

weel, i will guide u the procedure, try to do like this:

step 1: create a screen in the report and in the screen layout, place a blank custom control and name it. ex: "cust_control".

step 2: in the flowlogic, define the modules:

ex: like below:

PROCESS BEFORE OUTPUT.

MODULE STATUS_0100.

MODULE CREATE_OBJECTS.

MODULE DISP_DATA.

*

PROCESS AFTER INPUT.

MODULE USER_COMMAND_0100.

step 3:

now see the exmaple report,

REPORT Zexmaple.

NO STANDARD PAGE HEADING

LINE-SIZE 80

LINE-COUNT 65(0).

TYPE-POOLS:slis.

TABLES: ekko.

SELECT-OPTIONS: s_lifnr FOR ekko-lifnr.

*****DECLARING DATA FOR SLIS TYPET******

DATA: ls_fieldcat TYPE slis_fieldcat_alv,

lt_fieldcat LIKE TABLE OF ls_fieldcat,

ls_fieldcat1 TYPE slis_fieldcat_alv,

lt_fieldcat1 LIKE TABLE OF ls_fieldcat,

ls_events TYPE slis_alv_event,

lt_events TYPE slis_t_event,

ls_layout TYPE SLIS_LAYOUT_ALV,

isort TYPE slis_t_sortinfo_alv,

v_repid LIKE sy-repid.

****DECLARING DATA FOR LVC TYPE****

DATA: lt_lvcfieldcat type lvc_t_fcat,

ls_lvclayout type lvc_s_layo,

lt_lvcfieldcat1 type lvc_t_fcat,

ls_lvclayout1 type lvc_s_layo,

sel_row type lvc_s_row,

sel_t_row type lvc_t_row,

T_LINES TYPE I.

CLASS CL_EVENT_RECEIVER DEFINITION DEFERRED.

DATA: text_row TYPE i,

text_value(200) TYPE c,

text_col TYPE i.

data: begin of pftab occurs 0,

fcode(100),

end of pftab.

***************Decalring Internal tables***************

DATA: BEGIN OF ITAB_WA,

elikz LIKE ekpo-elikz,

ebeln LIKE ekpo-ebeln,

ebelp LIKE ekpo-ebelp,

menge LIKE ekpo-menge,

END OF ITAB_WA.

DATA: ITAB LIKE TABLE OF ITAB_WA WITH HEADER LINE.

DATA: BEGIN OF INTAB OCCURS 0,

EBELN LIKE EKPO-EBELN,

END OF INTAB.

DATA: BEGIN OF itab1 occurs 0,

bukrs LIKE ekko-bukrs,

lifnr LIKE ekko-lifnr,

END OF itab1.

******DEFINING INSTANCE FOR THE CLASS******

data:event_receiver type ref to cl_event_receiver,

PT_EXTAB TYPE UI_FUNCTIONS.

********DEFINITION OF CLASS***********

class cl_event_receiver definition.

public section.

methods handle_double_click

for event double_click of cl_gui_alv_grid.

endclass. "cl_event_receiver DEFINITION

*******IMPLEMENTATION OF CLASS*****

class cl_event_receiver implementation.

METHOD handle_double_click .

PERFORM handle_double_click.

ENDMETHOD . "handle_double_click

ENDCLASS . "cl_event_receiver IMPLEMENTATION

*************data for objects**********

DATA:

go_grid type ref to cl_gui_alv_grid,

go_custom_container type ref to cl_gui_custom_container.

INITIALIZATION.

v_repid = sy-repid.

START-OF-SELECTION.

***********select data into table***

*

PERFORM select_data.

call screen 100.

&----


*& Form SELECT_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM select_data.

SELECT aebeln aebelp a~menge FROM ekpo AS a INNER JOIN

ekko AS b ON aebeln = bebeln

INTO CORRESPONDING FIELDS OF TABLE itab

WHERE aelikz <> 'X' AND blifnr IN s_lifnr.

ENDFORM. " SELECT_DATA

&----


*& Form FIELD_CAT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM field_cat.

PERFORM mapping USING:

'EBELN' 'PURCHASE ORDER',

'EBELP' 'ITEM',

'ELIKZ' 'INDICATOR',

'MENGE' 'QTY'.

ENDFORM. " FIELD_CAT

&----


*& Form MAPPING

&----


  • textre

----


  • -->P_0090 text

  • -->P_0091 text

----


FORM mapping USING vname vdesc.

ls_fieldcat-fieldname = vname.

ls_fieldcat-seltext_s = vdesc.

IF ls_fieldcat-fieldname = 'MENGE'.

ls_fieldcat-do_sum = 'X'.

<b>ls_fieldcat-edit = 'X'.</b>

ENDIF.

APPEND ls_fieldcat TO lt_fieldcat.

ENDFORM. " MAPPING

----


  • FORM field_cat1 *

----


  • ........ *

----


FORM field_cat1.

PERFORM mapping1 USING: 'BUKRS' 'COMAPANY CODE' '15',

'LIFNR' 'Vendor' '10'.

ENDFORM. " FIELD_CAT

&----


*& Form MAPPING

&----


  • text

----


  • -->P_0090 text

  • -->P_0091 text

----


FORM mapping1 USING vname vdesc vlen.

ls_fieldcat1-fieldname = vname.

ls_fieldcat1-seltext_s = vdesc.

ls_fieldcat1-outputlen = vlen.

APPEND ls_fieldcat1 TO lt_fieldcat1.

ENDFORM. " MAPPING

&----


*& Form sort_build

&----


  • text

----


  • -->P_ISORT text

----


FORM sort_build.

DATA: ls_sort TYPE slis_sortinfo_alv.

CLEAR ls_sort.

ls_sort-fieldname = 'EBELN'.

ls_sort-spos = 2.

ls_sort-up = 'X'.

ls_sort-subtot = 'X'.

APPEND ls_sort TO isort.

ENDFORM. " sort_build

----


  • FORM PF_STATUS_SET *

----


  • ........ *

----


FORM pf_status_set USING extab TYPE slis_t_extab.

DATA ltab TYPE slis_extab.

ltab-fcode = 'SAVE'.

APPEND ltab TO extab.

SET PF-STATUS 'ZMENU' EXCLUDING extab.

ENDFORM. "pf_status_set

&----


*& Form transfer_from_slis

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM transfer_from_slis .

CALL FUNCTION 'LVC_TRANSFER_FROM_SLIS'

EXPORTING

IT_FIELDCAT_ALV = lt_fieldcat

IS_LAYOUT_ALV = ls_layout

IMPORTING

ET_FIELDCAT_LVC = lt_lvcfieldcat

ES_LAYOUT_LVC = ls_lvclayout

TABLES

IT_DATA = itab.

ENDFORM. " transfer_from_slis

&----


*& Form layout1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM layout1 .

  • ls_lvclayout-box_fname = 'itab-box'.

ls_lvclayout-sel_mode = 'C'.

ls_lvclayout-grid_title = 'Open Purchase Order Details'.

ENDFORM. " layout1

&----


*& Form CREATE_OBJECTS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM CREATE_OBJECTS .

CREATE OBJECT GO_CUSTOM_CONTAINER

EXPORTING

CONTAINER_NAME = 'CUST_CONTROL'.

CREATE OBJECT GO_GRID

EXPORTING

I_PARENT = GO_CUSTOM_CONTAINER.

CREATE OBJECT event_receiver .

SET HANDLER event_receiver->handle_double_click FOR go_grid.

ENDFORM. " CREATE_OBJECTS

&----


*& Form OO_DISPLAY

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM OO_DISPLAY .

REFRESH SEL_T_ROW.

clear t_lines.

clear sel_row.

IF T_LINES > 0.

CALL METHOD GO_GRID->SET_SELECTED_ROWS

EXPORTING

IT_INDEX_ROWS = SEL_T_ROW.

ENDIF.

  • CALL METHOD CL_GUI_CFW=>FLUSH.

CALL METHOD GO_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

IS_LAYOUT = LS_LVCLAYOUT

CHANGING

IT_OUTTAB = itab[]

IT_FIELDCATALOG = lt_lvcfieldcat[].

  • CALL METHOD GO_GRID->REFRESH_TABLE_DISPLAY.

ENDFORM. " OO_DISPLAY

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE STATUS_0100 OUTPUT.

REFRESH PFTAB.

refresh itab1.

pftab-fcode = 'SAVE'.

append pftab.

pftab-fcode = 'GOBACK'.

append pftab.

SET PF-STATUS 'ZMENU' EXCLUDING pftab.

free go_grid.

free go_custom_container.

CALL METHOD CL_GUI_CFW=>FLUSH.

  • SET TITLEBAR 'xxx'.

IF go_custom_container is INITIAL.

PERFORM CREATE_OBJECTS.

PERFORM field_cat.

perform transfer_from_slis.

endif.

perform layout1.

  • perform disp_data.

PERFORM OO_DISPLAY.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE USER_COMMAND_0100 INPUT.

call method cl_gui_cfw=>dispatch.

CASE SY-UCOMM.

WHEN 'DISPLAY'.

perform disp_for_sel_lines.

WHEN 'EXIT'.

free go_custom_container.

free go_grid.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

&----


*& Module STATUS_0200 OUTPUT

&----


  • text

----


MODULE STATUS_0200 OUTPUT.

REFRESH PFTAB.

pftab-fcode = 'SAVE'.

append pftab.

pftab-fcode = 'DISPLAY'.

append pftab.

pftab-fcode = 'EXIT'.

append pftab.

SET PF-STATUS 'ZMENU' EXCLUDING pftab.

  • SET TITLEBAR 'xxx'.

PERFORM CREATE_OBJECT1.

if itab1[] is initial.

PERFORM SELECT_DATA1.

endif.

PERFORM FIELD_CAT1.

PERFORM TRANSFER_TO_LVC.

PERFORM OO_DISPLAY1.

ENDMODULE. " STATUS_0200 OUTPUT.

&----


*& Form SELECT_DATA1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM SELECT_DATA1 .

data v_val(10).

loop at intab.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = intab-ebeln

IMPORTING

OUTPUT = v_val.

SELECT bukrs lifnr FROM ekko APPENDING TABLE itab1

WHERE ebeln = v_val.

ENDLOOP .

ENDFORM. " SELECT_DATA1

&----


*& Form TRANSFER_TO_LVC

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM TRANSFER_TO_LVC .

CALL FUNCTION 'LVC_TRANSFER_FROM_SLIS'

EXPORTING

IT_FIELDCAT_ALV = LT_FIELDCAT1

IMPORTING

ET_FIELDCAT_LVC = LT_LVCFIELDCAT1

  • ET_SORT_LVC =

  • ES_LAYOUT_LVC =

TABLES

IT_DATA = ITAB1.

ENDFORM. " TRANSFER_TO_LVC

&----


*& Form OO_DISPLAY1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM OO_DISPLAY1 .

PERFORM TOOLBAR_EXCLUDE CHANGING PT_EXTAB.

CALL METHOD GO_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

  • IS_LAYOUT =

IT_TOOLBAR_EXCLUDING = PT_EXTAB

CHANGING

IT_OUTTAB = ITAB1[]

IT_FIELDCATALOG = LT_LVCFIELDCAT1.

ENDFORM. " OO_DISPLAY1

&----


*& Form CREATE_OBJECT1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM CREATE_OBJECT1 .

free go_custom_container.

free go_grid.

if go_custom_container is initial.

CREATE OBJECT GO_CUSTOM_CONTAINER

EXPORTING

CONTAINER_NAME = 'CUST_CONTROL1'.

CREATE OBJECT GO_GRID

EXPORTING

I_PARENT = GO_CUSTOM_CONTAINER.

endif.

ENDFORM. " CREATE_OBJECT1

&----


*& Module USER_COMMAND_0200 INPUT

&----


  • text

----


MODULE USER_COMMAND_0200 INPUT.

CASE SY-UCOMM.

WHEN 'GOBACK'.

CALL SCREEN 100.

  • LEAVE SCREEN .

ENDCASE.

ENDMODULE. " USER_COMMAND_0200 INPUT

&----


*& Form disp_for_sel_lines

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM disp_for_sel_lines .

CALL METHOD go_grid->GET_SELECTED_ROWS

IMPORTING

ET_INDEX_ROWS = sel_t_row.

  • ET_ROW_NO =

.

DESCRIBE TABLE SEL_T_ROW LINES T_LINES.

IF T_LINES IS INITIAL.

CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'

EXPORTING

TEXTLINE1 = 'SELECT AT LEAST ONE ROW'.

ENDIF.

IF T_LINES > 0.

LOOP AT SEL_T_ROW INTO SEL_ROW.

READ TABLE ITAB INDEX SEL_ROW-INDEX

INTO ITAB_WA.

INTAB-EBELN = ITAB_WA-EBELN.

APPEND INTAB.

ENDLOOP.

CALL SCREEN 200.

ENDIF.

clear t_lines.

ENDFORM. " disp_for_sel_lines

&----


*& Form handle_double_click

&----


  • text

----


  • -->I_ROW text

  • -->I_COLUMN text

  • -->IS_ROW_NO text

----


FORM handle_double_click.

"i_column TYPE lvc_s_col

"is_row_no TYPE lvc_s_roid.

" IF sy-subrc = 0.

CALL METHOD go_grid->get_current_cell

IMPORTING

e_row = text_row

e_value = text_value

e_col = text_col.

PERFORM get_daten.

  • ENDIF .

ENDFORM . "handle_double_click

&----


*& Form get_daten

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_daten .

refresh itab1.

SELECT bukrs lifnr FROM ekko into

table itab1 WHERE ebeln = text_value.

call screen 200.

ENDFORM. " get_daten

end-of-selection.

refresh pftab.

refresh itab1.

&----


*& Form TOOLBAR_EXCLUDE

&----


  • text

----


  • -->PT_FUNCTIONtext

----


FORM TOOLBAR_EXCLUDE CHANGING PT_FUNCTIONS TYPE UI_FUNCTIONS.

DATA LS_EXCLUDE TYPE UI_FUNC.

LS_EXCLUDE = cl_gui_alv_grid=>mc_fc_DETAIL.

APPEND LS_EXCLUDE TO PT_FUNCTIONS.

ENDFORM. "TOOLBAR_EXCLUDE

tHE ABOVE IS AN EXMAPLE REPORT FOR ALVOO.

IN THE ABOVE REPORT , what i bolded is only for ur requirement edit = 'x'.

and also there a class <b>CL_ALV_CHANGED_DATA_PROTOCOL</b> in that there is a method fet_cell_value which gets the changed value of the cell.

i hope this information fulfills ur requirement.

using the above info try programming urself and if u find any doubts post here.

also see pdfs on ooalv in this forum. so that u can do it.

Read only

0 Likes
531

Thank alots of yr help and the time spend for creating this sample code. i will try it tml due to time constraint now.

Tml if i had any problem i will send u a reply for help!

Thk thk.