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: 

To Insert the Row in the alv display

karthisaki
Explorer
0 Kudos

how to create a row in alv grid output display without using oop concept ,Please share the queries to insert the row

7 REPLIES 7

DoanManhQuynh
Active Contributor
0 Kudos

add a new row is standard function of ALV

tan_michael
Active Participant
0 Kudos

Hi Karthik Sekar,

Are you referring to user command and refreshing of ALV? if thats the case you just have to append the workarea(row) to your internal table(report displayed) then refresh the screen and ofcourse you have to do the code under user command.

0 Kudos

FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.

*------------------------------------------------------------------*
* Check function code
*------------------------------------------------------------------*
data : ka_num type sy-tabix,
ka_usrnmr(20) type c.

CASE R_UCOMM.

WHEN '&LFO'.

DESCRIBE TABLE ITAB_NAVY LINES ka_num.
ka_usrnmr = ka_num + 1.
WA_NAVY-USERNAME = ka_usrnmr.

READ TABLE ITAB_NAVY INTO WA_NAVY INDEX ka_usrnmr.
"RS_SELFIELD-TABINDEX.

INSERT INITIAL LINE INTO TABLE ITAB_NAVY.


IF SY-SUBRC = 0.
CLEAR : KA_USRNMR.
INSERT ZQED_KA_NAVY FROM WA_NAVY.

"TABLE ITAB_NAVY ACCEPTING
*DUPLICATE KEYS.

ELSE.

MESSAGE I019(ZQED) WITH 'FAILED'.

ENDIF.

rs_selfield-refresh = 'X'.
rs_selfield-col_stable = 'X'.
rs_selfield-row_stable = 'X'.

add above code after adding line into your internal tables, this is to update your alv screen after a user command

karthisaki
Explorer
0 Kudos

Thank You, But its working in output itab table only. I want to store it in Database Table and to add the values in the database table.When i come back from the output screen, the created row is cleared and not storing in the database table.

Kindly review my code .

0 Kudos

what is the sy-subrc after the insert? you have to check the data fields of your database table(ZQED_KA_NAVY) and wa_navy.

maybe they have different fields, wa_navy and database table must be the same database column fields

karthisaki
Explorer
0 Kudos

FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.

DATA : KA_NUM TYPE SY-TABIX,
KA_USRNMR(20) TYPE C.

CASE R_UCOMM.
*----------------------------------------------------------------*
* To Delete the Selected Row
*-----------------------------------------------------------------*

WHEN '&DEL'.

READ TABLE ITAB_NAVY INTO WA_NAVY INDEX RS_SELFIELD-TABINDEX.

PERFORM DO_DELETE.

*------------------------------------------------------------------*
* To Create or Insert the new row in the ALV
*------------------------------------------------------------------*
WHEN '&LFO'.

rs_selfield-refresh = 'X'.
rs_selfield-col_stable = 'X'.
rs_selfield-row_stable = 'X'.


DESCRIBE TABLE ITAB_NAVY LINES KA_NUM.
KA_USRNMR = KA_NUM + 1.
WA_NAVY-USERNAME = KA_USRNMR.

READ TABLE ITAB_NAVY INTO WA_NAVY INDEX KA_USRNMR.


INSERT INITIAL LINE INTO TABLE ITAB_NAVY.


IF SY-SUBRC = 0.
INSERT ZQED_KA_NAVY FROM WA_NAVY.

ELSE.

MESSAGE I019(ZQED) WITH 'FAILED'.

ENDIF.

Here i get the temporary row and it can't update to database table. Can you tell me the code to execute it. And fields are ok within database table and internal table including client field also.