Application Development 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: 

Editing Alv Output

Former Member
0 Kudos

Hi all ,

Iam Generating ALV Grid using OOPs method, In the output list Iam editing some of the entries , now i need to store the edited output in a custom table.

Can anyubody tell me how to capture these changes into an internal table.

Early replies would be rewarded points.

Thanks In advance,

Neha

3 REPLIES 3

anversha_s
Active Contributor
0 Kudos

hi,

chk this standard pgm

BCALV_EDIT_03

In this example the user may change values of fields SEATSOCC (occupied seats) and/or PLANETYPE.

The report checks the input value(s) semantically and provides protocol messages in case of error

rgds

anver

if hlped mark points

Former Member
0 Kudos

Hi Neha,

check this code

&----


*& Report ZLAXMI_REPORT6 *

*& *

&----


*& *

*& *

&----


REPORT ZLAXMI_REPORT6 NO STANDARD PAGE HEADING

MESSAGE-ID ZZ

LINE-SIZE 132

LINE-COUNT 65 .

TABLES: MARA.

TYPE-POOLS: SLIS.

TYPES: BEGIN OF T_MARA,

MATNR TYPE MARA-MATNR, "Material Number

ERSDA TYPE MARA-ERSDA, "Creation date

BRGEW TYPE MARA-BRGEW, "Gross weight

NTGEW TYPE MARA-NTGEW, "Net weight

MTART TYPE MARA-MTART, "Material type

MBRSH TYPE MARA-MBRSH, "Industry Sector

REC_SEL TYPE C , "checkbox

END OF T_MARA.

----


  • V A R I A B L E S

----


DATA: V_REPID LIKE SY-REPID,

V_FLAG(1) TYPE C.

CONSTANTS :

C_X(1) TYPE C VALUE 'X',

C_PF_STATUS TYPE SLIS_FORMNAME VALUE 'F_SET_PF_STATUS',

C_FC_DELETE(6) TYPE C VALUE 'DELETE',

C_FC_MODIFY(6) TYPE C VALUE 'MODIFY',

C_USER_COMMAND TYPE SLIS_FORMNAME VALUE 'F_USER_COMMAND',

C_USER_COMMAND_MODIFY TYPE SLIS_FORMNAME

VALUE 'F_USER_COMMAND_MODIFY',

C_ICON_DELETE TYPE ICON-NAME VALUE 'ICON_DELETE', " Icon,Delete'

C_ICON_CANCEL TYPE ICON-NAME VALUE 'ICON_CANCEL', " Icon,Cancel'

C_FC_SAVE(4) TYPE C VALUE 'SAVE'.

*internal table declarations.

DATA: IT_MARA TYPE STANDARD TABLE OF T_MARA WITH HEADER LINE,

IT_MODIFY TYPE STANDARD TABLE OF T_MARA WITH HEADER LINE,

IT_TEMP TYPE STANDARD TABLE OF MARA WITH HEADER LINE,

*-ALV Internal Tables.

*--Field Catalog

IT_FIELDCAT TYPE STANDARD TABLE OF

SLIS_FIELDCAT_ALV WITH HEADER LINE,

*--Layout

WA_LAYOUT TYPE SLIS_LAYOUT_ALV,

*--Sort

IT_SORT TYPE SLIS_T_SORTINFO_ALV,

WA_SORT TYPE SLIS_SORTINFO_ALV ,

**-Structure for excluding function codes

WA_EXTAB TYPE SLIS_EXTAB,

**-To hold function codes to be excluded in ALV toolbar

IT_EXTAB TYPE SLIS_T_EXTAB.

*selection screen.

SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS: S_MATNR FOR MARA-MATNR,

S_ERSDA FOR MARA-ERSDA.

SELECTION-SCREEN: END OF BLOCK B1.

*--Radio buttons to select either Display/Delete/Modify

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME

TITLE TEXT-002.

SELECTION-SCREEN : BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(20) TEXT-003.

PARAMETERS: P_DISP RADIOBUTTON GROUP RAD1 DEFAULT 'X'.

SELECTION-SCREEN : END OF LINE.

SELECTION-SCREEN : BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(20) TEXT-005.

PARAMETERS: P_UPD RADIOBUTTON GROUP RAD1.

SELECTION-SCREEN : END OF LINE.

SELECTION-SCREEN : BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(20) TEXT-004.

PARAMETERS: P_DEL RADIOBUTTON GROUP RAD1.

SELECTION-SCREEN : END OF LINE.

SELECTION-SCREEN END OF BLOCK B2 .

AT SELECTION-SCREEN.

PERFORM VALIDATE_SCREEN.

*start of selection

START-OF-SELECTION.

*clear the internal tables to be used.

CLEAR: IT_MARA,IT_MARA[],

V_FLAG.

*get the data

PERFORM GET_DATA.

*end of selection

END-OF-SELECTION.

IF IT_MARA[] IS INITIAL.

MESSAGE I000 WITH

'No Records found for the given Selection Criteria'(012).

ELSE.

*do alv process

V_REPID = SY-REPID.

*--Sort the Output Fields

PERFORM SORT_FIELDS.

*--Build Field catalog for the Output fields

PERFORM BUILD_FIELDCAT.

*--Set the Layout for ALV

PERFORM SET_LAYOUT.

IF P_DISP = C_X.

*--Exclude any Buttons on the Appn tool bar

  • perform change_default_pf_status.

MOVE C_FC_DELETE TO WA_EXTAB-FCODE. " DELETE button on ALV

APPEND WA_EXTAB TO IT_EXTAB.

MOVE C_FC_MODIFY TO WA_EXTAB-FCODE. " MODIFY button on ALV

APPEND WA_EXTAB TO IT_EXTAB.

ELSEIF P_UPD = C_X.

*--Exclude DELETE Button on the appn tool bar

MOVE C_FC_DELETE TO WA_EXTAB-FCODE. " DELETE button on ALV

APPEND WA_EXTAB TO IT_EXTAB.

ELSEIF P_DEL = C_X.

*--Exclude MODIFY button on appn tool bar

MOVE C_FC_MODIFY TO WA_EXTAB-FCODE. " MODIFY button on ALV

APPEND WA_EXTAB TO IT_EXTAB.

ENDIF.

*--Exclude SAVE button for all options

MOVE 'SAVE' TO WA_EXTAB-FCODE. " SAVE button on ALV

APPEND WA_EXTAB TO IT_EXTAB.

*--Display ALV output

PERFORM LIST_DISPLAY TABLES IT_MARA

USING C_USER_COMMAND.

ENDIF.

&----


*& Form get_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM GET_DATA .

SELECT MATNR

ERSDA

BRGEW

NTGEW

MTART

MBRSH

FROM MARA

INTO TABLE IT_MARA

WHERE MATNR IN S_MATNR

AND ERSDA IN S_ERSDA.

IF SY-SUBRC <> 0.

*no records selected leave processing

STOP.

ENDIF.

SORT IT_MARA.

ENDFORM. " get_data

&----


*& Form sort_fields

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM SORT_FIELDS .

CLEAR WA_SORT.

WA_SORT-FIELDNAME = 'MATNR'.

WA_SORT-SPOS = '1'.

WA_SORT-UP = 'X'.

APPEND WA_SORT TO IT_SORT.

CLEAR WA_SORT.

WA_SORT-FIELDNAME = 'ERSDA'.

WA_SORT-SPOS = '2'.

WA_SORT-UP = 'X'.

APPEND WA_SORT TO IT_SORT.

ENDFORM. " sort_fields

&----


*& Form build_fieldcat

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BUILD_FIELDCAT .

IT_FIELDCAT-COL_POS = '1'.

IT_FIELDCAT-FIELDNAME = 'MATNR'.

IT_FIELDCAT-KEY = 'X'.

IT_FIELDCAT-OUTPUTLEN = '15'.

IT_FIELDCAT-SELTEXT_L = 'Material number'(022).

APPEND IT_FIELDCAT.

CLEAR IT_FIELDCAT.

IT_FIELDCAT-COL_POS = '2'.

IT_FIELDCAT-FIELDNAME = 'ERSDA'.

IT_FIELDCAT-KEY = 'X'.

IT_FIELDCAT-OUTPUTLEN = '10'.

IT_FIELDCAT-SELTEXT_L = 'Created on'(023).

APPEND IT_FIELDCAT.

CLEAR IT_FIELDCAT.

IT_FIELDCAT-COL_POS = '3'.

IT_FIELDCAT-FIELDNAME = 'BRGEW'.

IT_FIELDCAT-OUTPUTLEN = '10'.

IT_FIELDCAT-SELTEXT_L = 'GROSS WEIGHT'(024).

APPEND IT_FIELDCAT.

CLEAR IT_FIELDCAT.

IT_FIELDCAT-COL_POS = '4'.

IT_FIELDCAT-FIELDNAME = 'NTGEW'.

IT_FIELDCAT-OUTPUTLEN = '15'.

IT_FIELDCAT-SELTEXT_L = 'NET WEIGHT'(025).

APPEND IT_FIELDCAT.

CLEAR IT_FIELDCAT.

IT_FIELDCAT-COL_POS = '5'.

IT_FIELDCAT-FIELDNAME = 'MTART'.

IT_FIELDCAT-OUTPUTLEN = '3'.

IT_FIELDCAT-SELTEXT_L = 'Material type'(026).

APPEND IT_FIELDCAT.

CLEAR IT_FIELDCAT.

IT_FIELDCAT-COL_POS = '6'.

IT_FIELDCAT-FIELDNAME = 'MBRSH'.

IT_FIELDCAT-OUTPUTLEN = '25'.

IT_FIELDCAT-SELTEXT_L = 'Industry sector'(027).

APPEND IT_FIELDCAT.

CLEAR IT_FIELDCAT.

IT_FIELDCAT-FIELDNAME = 'REC_SEL'.

IT_FIELDCAT-NO_OUT = C_X.

APPEND IT_FIELDCAT.

CLEAR IT_FIELDCAT.

ENDFORM. " build_fieldcat

&----


*& Form list_display

&----


  • text

----


  • -->P_IT_MARA text

  • -->P_C_USER_COMMAND text

----


FORM LIST_DISPLAY TABLES P_IT_MARA

USING P_USER_COMMAND TYPE SLIS_FORMNAME.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = V_REPID

I_CALLBACK_PF_STATUS_SET = C_PF_STATUS

I_CALLBACK_USER_COMMAND = P_USER_COMMAND

IS_LAYOUT = WA_LAYOUT

IT_FIELDCAT = IT_FIELDCAT[]

IT_EXCLUDING = IT_EXTAB[]

IT_SORT = IT_SORT[]

TABLES

T_OUTTAB = P_IT_MARA

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " list_display

&----


*& Form F_SET_PF_STATUS

&----


  • Set PF_STATUS STANDARD modifying the standard toolbar

  • by excluding some buttons

----


  • -->P_IT_EXTAB -- TABLE OF EXCLUDING FUNCTIONS

----


FORM F_SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.

CLEAR : WA_EXTAB,

IT_EXTAB.

*--Set the Modified PF status for the ALV.

SET PF-STATUS 'ALV_STATUS_01' EXCLUDING RT_EXTAB.

ENDFORM. " SET_PF_STATUS

&----


*& Form f_user_command

&----


  • Handle user action on ALV toolbar

----


FORM F_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM

RS_SELFIELD TYPE SLIS_SELFIELD.

RS_SELFIELD-REFRESH = C_X.

IF R_UCOMM = C_FC_DELETE.

*--User Selected DELETE button.

PERFORM DELETE_SELECTED_RECORDS.

ELSEIF R_UCOMM = C_FC_MODIFY.

*--If user selects MODIFY button.

PERFORM CHANGE_RECORDS.

ENDIF.

ENDFORM. "F_USER_COMMAND

&----


*& Form POP_UP_CONFIRMATION

&----


  • text

----


  • <--P_ANSWER text

----


FORM POP_UP_CONFIRMATION

CHANGING P_ANSWER TYPE C.

DATA:

L_TITLE(14) TYPE C, " Title of pop-up

L_TXT_QUESTION(52) TYPE C, " Text displayed in pop-up

  • L_DISP_CANCEL TYPE C, " Display 'Cancel' button?

L_BTN1 TYPE ICON-NAME, " Icon on button 1

L_BTN2 TYPE ICON-NAME. " Icon on button 2

L_TITLE = 'Delete'(017). " delete

L_TXT_QUESTION = 'Are you sure to delete?'(018).

L_BTN1 = C_ICON_DELETE.

L_BTN2 = C_ICON_CANCEL.

**-Display pop-up asking user for confirmation

CALL FUNCTION 'POPUP_TO_CONFIRM'

EXPORTING

TITLEBAR = L_TITLE

TEXT_QUESTION = L_TXT_QUESTION

TEXT_BUTTON_1 = 'Yes'

ICON_BUTTON_1 = L_BTN1

TEXT_BUTTON_2 = 'No'

ICON_BUTTON_2 = L_BTN2

DEFAULT_BUTTON = '2'

DISPLAY_CANCEL_BUTTON = 'X'

IMPORTING

ANSWER = P_ANSWER

EXCEPTIONS

TEXT_NOT_FOUND = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

MESSAGE E000 WITH 'Error executing function module:'(019)

'POPUP_TO_CONFIRM'.

ENDIF.

ENDFORM. "pop_up_confirmation

&----


*& Form set_layout

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM SET_LAYOUT .

IF P_DEL = C_X OR P_UPD = C_X.

*--Allow Input only if user choose 'UPDATE'/ 'DELETE' radio buttons

WA_LAYOUT-BOX_FIELDNAME = 'REC_SEL'.

WA_LAYOUT-BOX_TABNAME = 'IT_MARA'.

ENDIF.

*--Display Header based on the user selection

IF P_DISP = C_X.

WA_LAYOUT-WINDOW_TITLEBAR =

'Display '(036).

ELSEIF P_DEL = C_X.

WA_LAYOUT-WINDOW_TITLEBAR =

'Delete '(037).

ELSEIF P_UPD = C_X.

WA_LAYOUT-WINDOW_TITLEBAR =

'Change '(038).

ENDIF.

ENDFORM. " set_layout

&----


*& Form change_default_pf_status

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM CHANGE_DEFAULT_PF_STATUS .

MOVE C_FC_DELETE TO WA_EXTAB-FCODE. " DELETE button on ALV

APPEND WA_EXTAB TO IT_EXTAB.

MOVE C_FC_MODIFY TO WA_EXTAB-FCODE. " MODIFY button on ALV

APPEND WA_EXTAB TO IT_EXTAB.

ENDFORM. " change_default_pf_status

&----


*& Form f_user_command

&----


  • Handle user action on ALV toolbar

----


FORM F_USER_COMMAND_MODIFY USING R_UCOMM LIKE SY-UCOMM "#EC *

RS_SELFIELD TYPE SLIS_SELFIELD.

DATA : L_ANSWER TYPE C. "#EC *

IF R_UCOMM = C_FC_SAVE.

*user selected save button

READ TABLE IT_MODIFY WITH KEY REC_SEL = 'X'.

*check if user selected atleast one line.

IF SY-SUBRC <> 0.

MESSAGE I000 WITH 'No record(s) Selected to Modify'(016).

EXIT.

ENDIF.

LOOP AT IT_MODIFY WHERE REC_SEL = 'X'.

*--Check the entered values are valid or not.

  • IF NOT ( it_modify-status = 'A' OR

  • it_modify-status = 'C' OR

  • it_modify-status = 'E' ).

*--User Entered invalid value for STATUS field,so Display Error Msg

CLEAR R_UCOMM.

  • MESSAGE e000 WITH 'Invalid value '''(031)

  • '' for Status in the Record # '(032)

  • sy-tabix.

  • ENDIF.

ENDLOOP.

CLEAR: IT_TEMP,

IT_TEMP[].

LOOP AT IT_MODIFY WHERE REC_SEL = 'X'.

MOVE-CORRESPONDING IT_MODIFY TO IT_TEMP.

APPEND IT_TEMP.

CLEAR IT_TEMP.

ENDLOOP.

*--start new code

DATA : IT_TEMP2 LIKE STANDARD TABLE OF MARA WITH HEADER LINE.

SELECT * FROM MARA

INTO TABLE IT_TEMP2

FOR ALL ENTRIES IN IT_TEMP

WHERE MATNR = IT_TEMP-MATNR.

IF SY-SUBRC = 0.

LOOP AT IT_MODIFY WHERE REC_SEL = 'X'.

READ TABLE IT_TEMP2 WITH KEY MATNR = IT_MODIFY-MATNR.

IF SY-SUBRC = 0.

IT_TEMP2-NTGEW = IT_MODIFY-NTGEW.

IT_TEMP2-BRGEW = IT_MODIFY-BRGEW.

MODIFY IT_TEMP2 INDEX SY-TABIX.

ENDIF.

ENDLOOP.

ENDIF.

*modify mara table with the changed values

MODIFY MARA FROM TABLE IT_TEMP2 .

*--end new code

IF SY-SUBRC = 0.

COMMIT WORK AND WAIT.

*--Display message with Success in Updating database

MESSAGE I000 WITH SY-DBCNT

' Record(s) has been Updated'(020).

CLEAR :

IT_MARA,

IT_MARA[].

*get-data again from database.

PERFORM GET_DATA.

  • RS_SELFIELD-REFRESH = C_X.

ELSE.

*--Error occurred

MESSAGE I000 WITH 'Error occured in Modifying the database'(021).

ENDIF.

ENDIF.

ENDFORM. "f_user_command_modify

&----


*& Form validate_screen

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM VALIDATE_SCREEN .

DATA : LV_MATNR LIKE MARA-MATNR.

*--validate product

IF NOT S_MATNR[] IS INITIAL.

SELECT MATNR

INTO MARA-MATNR

FROM MARA

WHERE MATNR IN S_MATNR.

ENDSELECT.

IF SY-SUBRC <> 0.

*--Error

MESSAGE E000 WITH 'Invalid Material'(034).

ENDIF.

ENDIF.

ENDFORM. " validate_screen

&----


*& Form delete_records

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM DELETE_RECORDS .

LOOP AT IT_MARA.

MOVE-CORRESPONDING IT_MARA TO IT_TEMP.

APPEND IT_TEMP.

CLEAR IT_TEMP.

ENDLOOP.

DELETE MARA FROM TABLE IT_TEMP.

IF SY-SUBRC = 0.

*--Successfully selected records Deleted.

COMMIT WORK AND WAIT.

*--Display Success Message to the user

MESSAGE I000 WITH SY-DBCNT

' Record(s) deleted Successfully'(010).

ELSE.

*--Error occured in deletion

MESSAGE I000 WITH 'Error occured in Deleting the Record(s)'(011).

ENDIF.

CLEAR: IT_MARA,

IT_MARA[],

IT_TEMP,

IT_TEMP[].

V_FLAG = C_X.

STOP.

ENDFORM. " delete_records

&----


*& Form delete_selected_records

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM DELETE_SELECTED_RECORDS .

DATA : L_ANSWER(1) TYPE C.

READ TABLE IT_MARA WITH KEY REC_SEL = C_X.

IF SY-SUBRC <> 0.

MESSAGE I000 WITH 'No record(s) Selected to Delete'(013).

EXIT.

ELSE.

*--Ask for delete confirmation

PERFORM POP_UP_CONFIRMATION

CHANGING L_ANSWER.

IF L_ANSWER = '1'. " 'Yes'

CLEAR: IT_TEMP,

IT_TEMP[].

LOOP AT IT_MARA WHERE REC_SEL = 'X'.

MOVE-CORRESPONDING IT_MARA TO IT_TEMP.

APPEND IT_TEMP.

CLEAR IT_TEMP.

ENDLOOP.

DELETE MARA FROM TABLE IT_TEMP.

IF SY-SUBRC = 0.

*--Successfully selected records Deleted.

COMMIT WORK AND WAIT.

*--Display completed work information to the user

MESSAGE I000 WITH SY-DBCNT

' Record(s) deleted Successfully'(014).

*--Clear the Internal tables

CLEAR: IT_MARA,

IT_MARA[].

*--Reselects entries from Database again & display in ALV

PERFORM GET_DATA.

ELSE.

*--Error occured

MESSAGE I000 WITH

'Error occured in Deleting the Record(s)'(015).

ENDIF.

ENDIF.

ENDIF.

ENDFORM. " delete_selected_records

&----


*& Form change_records

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM CHANGE_RECORDS .

READ TABLE IT_MARA WITH KEY REC_SEL = 'X'.

*--check user selected at least 1 record to MODIFY or not

IF SY-SUBRC <> 0.

MESSAGE I000 WITH 'No record(s) Selected to Modify'(016).

EXIT.

ELSE.

CLEAR : IT_MODIFY,

IT_MODIFY[].

LOOP AT IT_MARA WHERE REC_SEL = 'X'.

IT_MODIFY = IT_MARA.

APPEND IT_MODIFY.

CLEAR IT_MODIFY.

ENDLOOP.

*--Change PF status for this new ALV list.

PERFORM CHANGE_PF_STATUS_AGAIN.

*--Change Field Catalog to make INPUT enabled.

READ TABLE IT_FIELDCAT WITH KEY FIELDNAME = 'NTGEW'.

IT_FIELDCAT-INPUT = C_X.

MODIFY IT_FIELDCAT INDEX SY-TABIX.

*--Call ALV LIST DISPLAY with this new values.

PERFORM LIST_DISPLAY TABLES IT_MODIFY

USING C_USER_COMMAND_MODIFY.

ENDIF.

ENDFORM. " change_records

&----


*& Form change_pf_status_again

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM CHANGE_PF_STATUS_AGAIN .

MOVE C_FC_DELETE TO WA_EXTAB-FCODE. " DELETE button on ALV

APPEND WA_EXTAB TO IT_EXTAB.

MOVE C_FC_MODIFY TO WA_EXTAB-FCODE. " MODIFY button on ALV

APPEND WA_EXTAB TO IT_EXTAB.

ENDFORM. " change_pf_status_again

Regards,

Laxmi.

Former Member