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

regarding editable alv

Former Member
0 Likes
849

Hi all,

Frnds i am working in editable alv using function modules not object oriented abap.

i m trying to edit a Field(MATNR ) in my output list and finally update it with changed values in the DB table.

But i m getting syntax error like

"the work area i_final is not alligned properly

below i m providing my code.

<code>

&----


*& Report ZEDITABLE_ALV1

*&

&----


*&

*&

&----


REPORT ZEDITABLE_ALV1.

TABLES: vbak,vbap.

TYPE-POOLS: slis. "ALV Declarations

data: BEGIN OF i_final occurs 0,

vbeln like vbap-vbeln,

posnr like vbap-posnr,

matnr like vbap-matnr,

erdat like vbap-erdat,

END OF i_final.

DATA : C_X(1) TYPE C VALUE 'X',

C_FC_MODIFY(6) TYPE C VALUE 'MODIFY'.

*DATA: i_final TYPE STANDARD TABLE OF T_FINAL with header line.

  • i_temp type standard table of T_FINAL with header line.

*wa_final like line of i_final.

*DATA:i_final LIKE vbap OCCURS 0.

*DATA:wa_final LIKE vbap.

*ALV data declarations

DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,

gd_tab_group TYPE slis_t_sp_group_alv,

gd_layout TYPE slis_layout_alv,

gd_repid LIKE sy-repid.

*Start-of-selection.

START-OF-SELECTION.

PERFORM data_retrieval.

PERFORM build_fieldcatalog.

PERFORM build_layout.

PERFORM display_alv_report.

*&----


*& Form BUILD_FIELDCATALOG

*&----


*• Build Fieldcatalog for ALV Report

*----


FORM build_fieldcatalog.

fieldcatalog-fieldname = 'VBELN'.

fieldcatalog-seltext_m = 'sales order'.

fieldcatalog-col_pos = 0.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

fieldcatalog-fieldname = 'ERDAT'.

fieldcatalog-seltext_m = 'date'.

fieldcatalog-col_pos = 1.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

fieldcatalog-fieldname = 'MATNR'.

fieldcatalog-seltext_m = 'material no.'.

fieldcatalog-col_pos = 2.

fieldcatalog-edit = 'X'.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

fieldcatalog-fieldname = 'POSNR'.

fieldcatalog-seltext_m = 'line item no.'.

fieldcatalog-col_pos = 3.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

fieldcatalog-FIELDNAME = 'REC_SEL'.

fieldcatalog-NO_OUT = C_X.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

ENDFORM. " BUILD_FIELDCATALOG

*&----


*& Form BUILD_LAYOUT

*&----


*• Build layout for ALV grid report

*----


FORM build_layout.

gd_layout-no_input = 'X'.

gd_layout-colwidth_optimize = 'X'.

gd_layout-totals_text = 'Totals'(201).

gd_layout-totals_only = 'X'.

gd_layout-f2code = 'DISP'. "Sets fcode for when double

"click(press f2)

gd_layout-zebra = 'X'.

gd_layout-group_change_edit = 'X'.

gd_layout-header_text = 'helllllo'.

ENDFORM. " BUILD_LAYOUT

*&----


*& Form DISPLAY_ALV_REPORT

*&----


*• Display report using ALV grid

*----


FORM display_alv_report.

gd_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = gd_repid

i_callback_user_command = 'USER_COMMAND'

i_callback_pf_status_set = 'GUI_STAT'

*i_grid_title = outtext

is_layout = gd_layout

it_fieldcat = fieldcatalog[]

*it_special_groups = gd_tabgroup

*it_events = it_events

i_save = 'X'

*is_variant = z_template

TABLES

t_outtab = i_final

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. " DISPLAY_ALV_REPORT

*&----


**& Form DATA_RETRIEVAL

*&----


*• Retrieve data form EKPO table and populate itab it_ekko

*----


FORM data_retrieval.

*SELECT avbeln aerdat bmatnr bposnr FROM vbak AS a

*INNER JOIN vbap AS b ON avbeln = bvbeln

*INTO TABLE i_final WHERE a~vbeln = b~vbeln.

select VBELN ERDAT MATNR POSNR up to 10 rows from vbap into corresponding fields of table i_final.

ENDFORM. " DATA_RETRIEVAL

*

*----


*• FORM GUI_STAT *

*----


*• ........ *

*----


*• --> RT_EXTAB *

*----


FORM gui_stat USING rt_extab TYPE slis_t_extab.

SET PF-STATUS 'MODIFY' EXCLUDING rt_extab.

ENDFORM.

*----


*• FORM USER_COMMAND *

*----


*• ........ *

*----


*• --> U_COMM *

*• --> RS_SELFIELD *

*----


FORM user_command USING u_comm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

DATA:selfield TYPE slis_selfield.

*RS_SELFIELD-REFRESH = C_X.

CASE u_comm.

*IF U_COMM = C_FC_MODIFY.

WHEN 'UPDATE'.

LOOP AT i_final. " into wa_final."into wa_final.

*READ TABLE I_TEMP WITH KEY VBELN = I_FINAL-VBELN.

*IF SY-SUBRC = 0.

i_final-matnr = vbap-matnr.

*MODIFY I_final INDEX SY-TABIX.

*ENDIF.

ENDLOOP.

*ENDIF.

MODIFY VBAP FROM TABLE i_final.

IF SY-SUBRC = 0.

COMMIT WORK AND WAIT.

*MESSAGE I000 WITH SY-DBCNT

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

ENDIF.

*append i_final.

*it_temp = i_final.

*append it_temp.

*

**UPDATE sflight FROM TABLE sflight_tab.

*ENDLOOP.

*update vbap from table i_final.

*IF sy-subrc = 0.

*MESSAGE s000(0) WITH 'records updated successfully'.

*ENDIF.

ENDCASE.

ENDFORM.

</code>

Frnds plz help me in this regard.

Thanks,

satya

Hi all,

Frnds i am working in editable alv using function modules not object oriented abap.

i m trying to edit a Field(MATNR ) in my output list and finally update it with changed values in the DB table.

But i m getting syntax error like

"the work area i_final is not alligned properly

below i m providing my code.

<code>

&----


*& Report ZEDITABLE_ALV1

*&

&----


*&

*&

&----


REPORT ZEDITABLE_ALV1.

TABLES: vbak,vbap.

TYPE-POOLS: slis. "ALV Declarations

data: BEGIN OF i_final occurs 0,

vbeln like vbap-vbeln,

posnr like vbap-posnr,

matnr like vbap-matnr,

erdat like vbap-erdat,

END OF i_final.

DATA : C_X(1) TYPE C VALUE 'X',

C_FC_MODIFY(6) TYPE C VALUE 'MODIFY'.

*DATA: i_final TYPE STANDARD TABLE OF T_FINAL with header line.

  • i_temp type standard table of T_FINAL with header line.

*wa_final like line of i_final.

*DATA:i_final LIKE vbap OCCURS 0.

*DATA:wa_final LIKE vbap.

*ALV data declarations

DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,

gd_tab_group TYPE slis_t_sp_group_alv,

gd_layout TYPE slis_layout_alv,

gd_repid LIKE sy-repid.

*Start-of-selection.

START-OF-SELECTION.

PERFORM data_retrieval.

PERFORM build_fieldcatalog.

PERFORM build_layout.

PERFORM display_alv_report.

*&----


*& Form BUILD_FIELDCATALOG

*&----


*• Build Fieldcatalog for ALV Report

*----


FORM build_fieldcatalog.

fieldcatalog-fieldname = 'VBELN'.

fieldcatalog-seltext_m = 'sales order'.

fieldcatalog-col_pos = 0.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

fieldcatalog-fieldname = 'ERDAT'.

fieldcatalog-seltext_m = 'date'.

fieldcatalog-col_pos = 1.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

fieldcatalog-fieldname = 'MATNR'.

fieldcatalog-seltext_m = 'material no.'.

fieldcatalog-col_pos = 2.

fieldcatalog-edit = 'X'.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

fieldcatalog-fieldname = 'POSNR'.

fieldcatalog-seltext_m = 'line item no.'.

fieldcatalog-col_pos = 3.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

fieldcatalog-FIELDNAME = 'REC_SEL'.

fieldcatalog-NO_OUT = C_X.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

ENDFORM. " BUILD_FIELDCATALOG

*&----


*& Form BUILD_LAYOUT

*&----


*• Build layout for ALV grid report

*----


FORM build_layout.

gd_layout-no_input = 'X'.

gd_layout-colwidth_optimize = 'X'.

gd_layout-totals_text = 'Totals'(201).

gd_layout-totals_only = 'X'.

gd_layout-f2code = 'DISP'. "Sets fcode for when double

"click(press f2)

gd_layout-zebra = 'X'.

gd_layout-group_change_edit = 'X'.

gd_layout-header_text = 'helllllo'.

ENDFORM. " BUILD_LAYOUT

*&----


*& Form DISPLAY_ALV_REPORT

*&----


*• Display report using ALV grid

*----


FORM display_alv_report.

gd_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = gd_repid

i_callback_user_command = 'USER_COMMAND'

i_callback_pf_status_set = 'GUI_STAT'

*i_grid_title = outtext

is_layout = gd_layout

it_fieldcat = fieldcatalog[]

*it_special_groups = gd_tabgroup

*it_events = it_events

i_save = 'X'

*is_variant = z_template

TABLES

t_outtab = i_final

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. " DISPLAY_ALV_REPORT

*&----


**& Form DATA_RETRIEVAL

*&----


*• Retrieve data form EKPO table and populate itab it_ekko

*----


FORM data_retrieval.

*SELECT avbeln aerdat bmatnr bposnr FROM vbak AS a

*INNER JOIN vbap AS b ON avbeln = bvbeln

*INTO TABLE i_final WHERE a~vbeln = b~vbeln.

select VBELN ERDAT MATNR POSNR up to 10 rows from vbap into corresponding fields of table i_final.

ENDFORM. " DATA_RETRIEVAL

*

*----


*• FORM GUI_STAT *

*----


*• ........ *

*----


*• --> RT_EXTAB *

*----


FORM gui_stat USING rt_extab TYPE slis_t_extab.

SET PF-STATUS 'MODIFY' EXCLUDING rt_extab.

ENDFORM.

*----


*• FORM USER_COMMAND *

*----


*• ........ *

*----


*• --> U_COMM *

*• --> RS_SELFIELD *

*----


FORM user_command USING u_comm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

DATA:selfield TYPE slis_selfield.

*RS_SELFIELD-REFRESH = C_X.

CASE u_comm.

*IF U_COMM = C_FC_MODIFY.

WHEN 'UPDATE'.

LOOP AT i_final. " into wa_final."into wa_final.

*READ TABLE I_TEMP WITH KEY VBELN = I_FINAL-VBELN.

*IF SY-SUBRC = 0.

i_final-matnr = vbap-matnr.

*MODIFY I_final INDEX SY-TABIX.

*ENDIF.

ENDLOOP.

*ENDIF.

MODIFY VBAP FROM TABLE i_final.

IF SY-SUBRC = 0.

COMMIT WORK AND WAIT.

*MESSAGE I000 WITH SY-DBCNT

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

ENDIF.

*append i_final.

*it_temp = i_final.

*append it_temp.

*

**UPDATE sflight FROM TABLE sflight_tab.

*ENDLOOP.

*update vbap from table i_final.

*IF sy-subrc = 0.

*MESSAGE s000(0) WITH 'records updated successfully'.

*ENDIF.

ENDCASE.

ENDFORM.

</code>

Frnds plz help me in this regard.

Thanks,

satya

5 REPLIES 5
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
826

Do Mark the Line....

Read only

0 Likes
826

Hi Keshu,

That syntax error got solved but my problem is

I am able to edit the output field (matnr) but my problem is its not modifying and updating the table vbap .

can you help me regarding this.

regards,

satya

Read only

Former Member
0 Likes
826

Hi,

First of all It is not a good programming practice to update database table directly from the program. It will avoid all the validations & there may be unknown other tables that need to be updated when you update your table.

The following statement i feel is wrong, because table VBAP and I_FINAL are not the same structure.

MODIFY VBAP FROM TABLE i_final.

Instead try like this.

UPDATE VBAP set <vbap field> = i_final-field

<vbap field> = i_final-field

...

where VBELN = i_final-field.

Hope this helps..

Harikrishna.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
826

Try something like this...ur code was not clear..i have done something u can understand.

First check that u r not trying to update the primary key field.

first before updating.

Before updating select the record u r going to update from the main table.

select single * from VBAP where <pass the key values>.

if sy-subrc = 0.

move the rest of the values to the table header except the key values.

vbap-<field1> = value1.

vbap-<field2> = value2.

after moving the values.

update <table>.

if sy-subrc = 0.

commit work.

endif.

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

data:st_vbap type vbap.

WHEN 'UPDATE'.

LOOP AT i_final. " into wa_final."into wa_final.

select single * from vbap where vbeln = I_FINAL-VBELN.

move-corresponding i_final to vbap.

update vbap.

if sy-subrc = 0.

commit work.

wk_cnt = wk_cnt + 1.

endif.

at last.

*MESSAGE I000 WITH SY-DBCNT

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

endat.

endloop

Read only

0 Likes
826

Hi keshu ,

I like to say, it never recommand to change the table from any Z program. Although if your recommand are like that onyl then go ahead but try some bapi or BDC.

About the Table updation not happening,better you check your command.

But before doing the such things please

Lock the table,So that no one can else change the same table entry at the same time.

I hope it may be use full.

Regards

Swati