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: 

How to edit a particular row in the table ctrl when a push button is clickd

Former Member
0 Kudos

Hi Experts,

How to edit a particular row (except the Primary keys) after selecting it in the TABLE CONTROL when a

push button is clicked in the table control.

For Eg. If you have a push button say "Modify", the particular row what we select in the table control should be in a

editable mode after clicking "Modify" Push button.

Please help me out.

Thanks in advance.

1 ACCEPTED SOLUTION

former_member1245113
Active Contributor
0 Kudos

hI,

in PBO

loop at itab with control tc.
module modify_screen. " If you place your loop at screen in this module the row will be editable/changed to disabled mode
endlooop.

in program.
module modify_screen.
 CASE ok.
    WHEN 'MOD'.  " Your Modify OK code

        LOOP AT SCREEN.
      IF jtab-mark = 'X'.
          IF screen-name = 'JTAB-MATNR'. " You can use screen group for the fields you want editable
" Assign a GRP1 for all key fields and GRP2 for other fields
" if screen-group2 = 'GRP2'. " All the screens belong to GRP2 will be modified here
            screen-input = 0.
            MODIFY SCREEN.
          ENDIF.
ELSE.
IF SCREEN-NAME = 'JTAB-MATNR'.
SCREEN-INPUT = 1.
MODIFY SCREEN.
ENDIF.
        ENDLOOP.
clear jtab-mark.
modify jtab index sy-tabix. " This clears the Table control Row selector 
" If you dont want just remove this.
  ENDCASE.
endmodule.

in PAI

loop at  itab.
module modify_tab.
" In Top include
data : begin of jtab occurs 0,
mark type c,
 matnr type matnr,
maktx type maktx,
end of jtab.

" dont forget to enter JTAB-MARK in screenpainter at Table control W/SelColumn
in program

MODULE modify_tab.
  DESCRIBE TABLE jtab LINES tc-lines.
  MODIFY jtab INDEX tc-current_line. " This will transfer the Selected line back to internal table of program
ENDMODULE. 
endloop.
" Happy new year to you ALL
" This is a tested program and working fine in my system

Cheerz

Ram

12 REPLIES 12

Former Member
0 Kudos

Hi Anath,

Try following procedure.. (when OKCODE = modify ok code)

1. Get the Selected Row in PAI

2. In LOOP AT TC... (IN PBO)

-- Set SCREEN Input 0 for the selected fields .. when the Row matches the selection.

Hope this helps,

Nag

Edited by: Naga Mohan Kummara on Dec 31, 2009 6:55 AM

0 Kudos

Hi Nag,

Thanks for the reply,

But i have a query on this, Are you looping table control or the internal table in PBO ?

I have selected the particular row and also i am able to capture the data into variable (which is declared in the internal table) , but i am unable to edit the row.

Can you please guide me ?

Thanks in Advance.

0 Kudos

Hi Ananth,

2 Ways to work on this..

1. In PAI .. Get the data of selected row --- All key fields(as u alrady got)..

In PBO .. When Loop at table control.. read the record and compare with Key fields.. if the record matching u can proceed with modify logic

2. In PAI Get record number (By using Logic - Get Cursor + TC-topline - 1) == say variable x

In PBO .. use

LOOP AT ITAB WITH CONTROL SELFIELDS_TC CURSOR

SELFIELDS_TC-CURRENT_LINE.

compare the line number with variable x and proceed with edit logic.

Let me know if you need more info..

Nag

0 Kudos

Hi Nag,

Thanks for the reply,

Here, my requirement is : Once i click the modify button, the particular record which i selected should be in a editable mode and after i modify in that editable row or edited in the editable row, i click the other pushbutton button called "Save". Here in this i have written the code of Modify button.

(It is working when i dont keep the values in the output in the table control in a displayed mode but i want it in a displayed mode)

but here, whenever the transaction code is triggered, the values in the output table control is in displayed mode, now what i want is after i click on the modify button the particular value which i selected should be in a editable mode. After modifying it, i have another button called "Save" which i trigger or click it which helps the data to save in Database table.

0 Kudos

Hi Nag,

I had followed the first procedure, so here as you said loop at table control.....how can we compare with key fields?

Please can you guide me.....

Thanks in advance.

0 Kudos

Hi Ananth,

Steps:

1. Remove the logic for Diplay/Edit of Table control

2. In PBO (LOOP)


IF OKCODE = 'MODIFY'.
LOOP AT SCREEN.
" Logic for Edit along with conditions
ENDLOOP.
ELSE.  
LOOP AT SCREEN.
" screen-active = 0. (except for Check box)
ENDLOOP.
ENDIF.

" by default (when transaction executed OKCODE would be balnk so transaction will be displayed in displaymode)

Nag

0 Kudos

Hi Ananth,

In first method..

If you write

in PBO..

LOOP at ITAB with control....

endlooop.

ITAB work are will contain correposing records.. Hence you can use the same for your key field comparision.

Nag

-


Another approach..

In PAI .. update the selected row to X in internaltable (eg: ITAB-CHECK = 'x')

In PBO..

If ITAB_CHECK = 'x' .. in LOOP ITAB with control TC...

Proceed with Modify logic

Edited by: Naga Mohan Kummara on Dec 31, 2009 9:22 AM

Edited by: Naga Mohan Kummara on Dec 31, 2009 9:26 AM

Former Member
0 Kudos

Hi,

in the user-command module of PAI event, code as follows..


CONTROLS tabctrl TYPE TABLEVIEW USING SCREEN 100.

MODULE user_command_0100 INPUT.
 CASE SY-UCOMM.
    WHEN 'MODIFY'.
      LOOP AT tabctrl-cols INTO cols WHERE index GT 2.
          cols-screen-input = '1'.
  MODIFY tabctrl-cols FROM cols INDEX sy-tabix.
ENDLOOP.
endmodule.

Check the useful link..

http://help.sap.com/saphelp_nw04/helpdata/EN/9f/dbac5e35c111d1829f0000e829fbfe/content.htm

Regards,

Deeba

Former Member
0 Kudos

hai,

Have a look once on a following given below link, I am damn sure it will be very helpful for u...

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/1499ec90-0201-0010-769f-860989655...

Regards

Shelly Malik

former_member1245113
Active Contributor
0 Kudos

hI,

in PBO

loop at itab with control tc.
module modify_screen. " If you place your loop at screen in this module the row will be editable/changed to disabled mode
endlooop.

in program.
module modify_screen.
 CASE ok.
    WHEN 'MOD'.  " Your Modify OK code

        LOOP AT SCREEN.
      IF jtab-mark = 'X'.
          IF screen-name = 'JTAB-MATNR'. " You can use screen group for the fields you want editable
" Assign a GRP1 for all key fields and GRP2 for other fields
" if screen-group2 = 'GRP2'. " All the screens belong to GRP2 will be modified here
            screen-input = 0.
            MODIFY SCREEN.
          ENDIF.
ELSE.
IF SCREEN-NAME = 'JTAB-MATNR'.
SCREEN-INPUT = 1.
MODIFY SCREEN.
ENDIF.
        ENDLOOP.
clear jtab-mark.
modify jtab index sy-tabix. " This clears the Table control Row selector 
" If you dont want just remove this.
  ENDCASE.
endmodule.

in PAI

loop at  itab.
module modify_tab.
" In Top include
data : begin of jtab occurs 0,
mark type c,
 matnr type matnr,
maktx type maktx,
end of jtab.

" dont forget to enter JTAB-MARK in screenpainter at Table control W/SelColumn
in program

MODULE modify_tab.
  DESCRIBE TABLE jtab LINES tc-lines.
  MODIFY jtab INDEX tc-current_line. " This will transfer the Selected line back to internal table of program
ENDMODULE. 
endloop.
" Happy new year to you ALL
" This is a tested program and working fine in my system

Cheerz

Ram

Former Member
0 Kudos

Hey Ram,

Thanks a ton.

Its working fine...sorry for the late reply.

The reason behind the delay is because i had modified my code as per your logic it worked fine but the thing is that the whole column was in editable mode but not a single row.

For E.g If i want to edit a particular row, first i select the row and then click on "Modify" button. After i click on the button, the whole column gets in a editable mode including the one which i intentionally selected.

Here, the solution is that you have to set a flag in PBO so that once it is done with PBO then it need not come back again after we click on "Modify" button.

And one more query is that after you modify a particular row in the table control ( When it is in editable mode) and click on the "Save" button, it is not getting updated to database.

To update the database, we need to select the row once again after modifying it and click on the "Save" button.

Here, database is updating only when it is selected again. If it is not selected, it is not getting updated.

If you have any alternative solution, then please help me out.( I hope i am clear with the question.)

Thanks,

Ananth.

0 Kudos

Hi,

Could you please share the code for the flag check. I am also facing the same issue.

Thanks,

KB