2013 Jul 30 7:18 AM
Hello Gurus,
I am having a table control in my module pool program.Out of 25 columns , I am having 12 columns on months wise like (jan, feb, march....).Now my concern is based on current month I want to enable the column of month rest all months will be in disable mode.So that the user can enter his/her time of work.Could you please tell me any way.I tired to read tc-cols and stored in col with index but its not working I wrote this code for first month without any condition
READ TABLE tC-COLS INTO col INDEX 22.
col-SCREEN-INPUT = 0.
MODIFY tC-COLS FROM col INDEX 22.
but its not working.I wrote this code in PBO as well as i tried in PAI as wellstill my columns is in enable mode.Also when user clicks on button then only the table control required fields should start working like months enable/disable process.for eg. I am having 2 button one is Create and other is Search on both these buttons after click the condition for enable/disable months should work.
Thanks
Gaurav
2013 Jul 30 7:52 AM
module user_command_0100 input.
when 'CHANGE'
loop at tc_action-cols into cols.
if cols-screen-name = 'JULY'. " if cols-screen-name = fieldname
cols-screen-input = '1'.
modify tc_action-cols from cols index sy-tabix.
endif.
endloop.
when 'SAVE'
* fieldname = current month
loop at tc_action-cols into cols.
if cols-screen-name = 'JULY'. " if cols-screen-name = fieldname
cols-screen-input = '0'.
modify tc_action-cols from cols index sy-tabix.
endif.
endloop.
2013 Jul 30 7:26 AM
Hi,
Try this:
Use structure 'cols'
eg. my_control is your table control
code:-
loop at my_control-cols into wa.
if wa-index = 2. "your hidden column
wa-invisible = 1.
endif.
modify my_control-cols from wa.
endloop.
BR
Chandra
2013 Jul 30 7:37 AM
Hi Chandra,
All the columns are in disable mode at first
Now when I click on Create then
Here when I clicked on Create/Search I want only the required Month column based on current month to be enabled rest all month column should be disabled.like for e.g Current month is JULY so only JUL column should be enabled for entry rest no months columns should be ready to take input.
Thanks
Gaurav
2013 Jul 30 8:03 AM
Hello
Firstly calculate current month using sy-datum(date) .
lv_month = date+4(6).
loop at my_control-cols into wa.
if wa-index <> lv_MONTH. "your hidden column (Column which is not equal to current month)
wa-invisible = 1. OR wa-input = 0.
endif.
modify my_control-cols from wa.
endloop.
2013 Jul 30 8:13 AM
Hi Gaurav,
try this below code. it might help you to fix your bug.
this code to disable a column in tablecontrol.
LOOP AT TC-COLS INTO COL.
IF COL-SCREEN-NAME = 'JAN'.
COL-SCREEN-INPUT = 0.
COL-SCREEN-OUTPUT = 1.
MODIFY TC-COLS FROM COL.
ENDIF.
ENDLOOP.
Regards,
Gokulan
2013 Jul 30 7:52 AM
module user_command_0100 input.
when 'CHANGE'
loop at tc_action-cols into cols.
if cols-screen-name = 'JULY'. " if cols-screen-name = fieldname
cols-screen-input = '1'.
modify tc_action-cols from cols index sy-tabix.
endif.
endloop.
when 'SAVE'
* fieldname = current month
loop at tc_action-cols into cols.
if cols-screen-name = 'JULY'. " if cols-screen-name = fieldname
cols-screen-input = '0'.
modify tc_action-cols from cols index sy-tabix.
endif.
endloop.
2013 Jul 30 12:56 PM
Hi Susmitha,
I tried your way but its not working.Month July with all other are in enable mode.Could you please look into it.I tried to disable the field from screen attribute and then tried to make it enable then also its not working its modifying the screen.
Thanks
Gaurav
2013 Jul 30 1:40 PM
Hi Susmitha,
With your code instead of screen-input I used cols-screen-active = 0 its working fine but when I am using for else also my whole screen is getting into disable mode except the current month.
for eg
w_month = sy-datum+4(2).
LOOP AT tc-cols INTO cols.
IF w_month = 01 and
cols-SCREEN-name = 'ZEXT_RPT_WA-JANY'.
cols-screen-active = 1.
ELSE.
cols-screen-active = 0.
ENDIF.
MODIFY tc-cols FROM cols .
ENDLOOP.
like this for every month then only july is enabled in the whole screen.
Thanks
Gaurav
2013 Jul 30 2:08 PM
HI Gaurav,
When active = 1, the fields are enabled/displayed and when active = 0, the field is disabled/not displayed irrespective of the values of other fields.
Check the different combinations in this link.
http://help.sap.com/saphelp_nw04/helpdata/en/9f/dbab6f35c111d1829f0000e829fbfe/content.htm
So these fields should always be active.
Try this combination.
w_month = sy-datum+4(2).
LOOP AT tc-cols INTO cols.
IF w_month = 01 and
cols-SCREEN-name = 'ZEXT_RPT_WA-JANY'.
cols-screen-active = 1.
cols-screen-input = 1.
cols-screen-output = 1.
ELSE.
cols-screen-active = 1.
cols-screen-input = 0.
cols-screen-output = 1.
ENDIF.
MODIFY tc-cols FROM cols .
ENDLOOP.
2013 Jul 30 2:26 PM
Hi Susmitha,
I wrote same for every month. from (jan to dec).
Now where the condition is matching there its working rest its not working for all.Like is tried to disable the month when condition meets its working fine but why not for other months.Still they are enabled.
Thanks
Gaurav
2013 Jul 30 2:58 PM
Just put a break point here and check all the screen attributes, does the attributes differ from what is expected for the fields?
Can check this combination also. I am sorry, I dont have SAP GUI to test the combination.
LOOP AT tc-cols INTO cols.
IF w_month = 01 and
cols-SCREEN-name = 'ZEXT_RPT_WA-JANY'.
cols-screen-active = 1.
cols-screen-input = 1.
ElsE.
cols-screen-input = 0.
ENDIF.
MODIFY tc-cols FROM cols .
ENDLOOP.
2013 Jul 30 3:29 PM
Hi Susmitha,
I made with this
w_month = sy-datum+4(2).
*IF cols-SCREEN-name = .
LOOP AT tc-cols INTO cols.
IF w_month = 01 AND
cols-screen-name = 'ZEXT_RPT_WA-JANY'.
cols-screen-active = 1.
cols-screen-input = 1.
cols-screen-output = 1.
ELSEif cols-screen-name = 'ZEXT_RPT_WA-JANY' .
cols-screen-active = 0.
* cols-screen-input = 1.
* cols-screen-output = 1.
ENDIF.
MODIFY tc-cols FROM cols.
Its working fine but for new entry it would work but what about change if the user clicked on change will the values entered before for others months be visible or not.
Thanks
Gaurav
2013 Jul 30 3:50 PM
I assume your function code would be different for Create and Modify.
Put the above code under a subroutine eg screen_setting
If its create, call the code that you have done. (If screen-output = 1 is not necessary, I think its better to omit that statement also, coz I read that it may make input = 1 ineffective. So if it works without that statement, then comment that also ).
For Modify, instead of checking it againt current month, you wil have to validate against the month inputted by user when he clicks on modify.
(wa_month = p_month. )
when 'create'.
w_month = sy-datum+4(2).
perform screen_setting.
when 'MODIFY'
w_month = p_month
perform screen_setting.
2013 Jul 31 6:49 AM
I used the subroutine.
Now when I click on CREATE
this is my output
When I clicked on Search then with Respective options I got this
when I clicked on MODIFY.Then the input data is getting lost. AS i used Active = 0 And
when I am keeping the screen-active option as 1 and input = 0 then the all screen field enabled for input.
2013 Jul 31 7:57 AM
Hi Gaurav,
I dont know why its not coming in your program. Check this code, its working fine.
I have done it with just three months - Jun, July and August.
In Se51, these are the screen attribute for each month field
PROCESS BEFORE OUTPUT.
LOOP AT GT_table
INTO GW_table
WITH CONTROL TC_table
CURSOR TC_table-CURRENT_LINE.
ENDLOOP.
MODULE STATUS_0100.
*
PROCESS AFTER INPUT.
* PAI FLOW LOGIC FOR TABLECONTROL
LOOP AT GT_table.
CHAIN.
FIELD GW_table-JUN.
FIELD GW_table-JUL.
FIELD GW_table-AUG.
MODULE TC_table_MODIFY ON CHAIN-REQUEST.
endchain.
ENDLOOP.
MODULE USER_COMMAND_0100.
In SE41, I have created three buttons - Create, Edit, Save.
2013 Jul 31 8:05 AM
TYPES: BEGIN OF zhr_month,
jun TYPE i,
jul TYPE i,
aug TYPE i,
END OF zhr_month.
DATA: gt_table TYPE TABLE OF zhr_month,
gw_table LIKE LINE OF gt_table.
CONTROLS: tc_table TYPE TABLEVIEW USING SCREEN 0100.
DATA: cols LIKE LINE OF tc_table-cols.
DATA: ok_code TYPE sy-ucomm,
save_ok TYPE sy-ucomm.
CALL SCREEN 100.
*----------------------------------------------------------------------*
* MODULE status_0100 OUTPUT
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STAT1'.
SET TITLEBAR 'TITL1'.
ENDMODULE. "status_0100 OUTPUT
*----------------------------------------------------------------------*
* MODULE user_command_0100 INPUT
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
DATA w_month(2) TYPE c.
DATA p_date TYPE datum.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'CREATE'.
w_month = sy-datum+4(2).
PERFORM screen_setting.
WHEN 'MODIFY'.
* You can use any function module you want to get the month input from user.
CALL FUNCTION 'F4_DATE'
EXPORTING
date_for_first_month = sy-datum
IMPORTING
select_date = p_date
EXCEPTIONS
calendar_buffer_not_loadable = 1
date_after_range = 2
date_before_range = 3
date_invalid = 4
factory_calendar_not_found = 5
holiday_calendar_not_found = 6
parameter_conflict = 7
OTHERS = 8.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
w_month = p_date+4(2).
PERFORM screen_setting.
WHEN 'SAVE'.
LOOP AT gt_table INTO gw_table.
* Save to database.
ENDLOOP.
LOOP AT tc_table-cols INTO cols.
cols-screen-input = '0'.
MODIFY tc_table-cols FROM cols INDEX sy-tabix.
ENDLOOP.
ENDCASE."CASE save_ok
CLEAR save_ok.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form screen_setting
*&---------------------------------------------------------------------*
FORM screen_setting.
CASE w_month.
WHEN '06'.
LOOP AT tc_table-cols INTO cols.
IF cols-screen-name = 'GW_TABLE-JUN' .
cols-screen-input = '1'.
ELSE.
cols-screen-input = '0'.
ENDIF.
MODIFY tc_table-cols FROM cols INDEX sy-tabix.
ENDLOOP.
WHEN '07'.
LOOP AT tc_table-cols INTO cols.
IF cols-screen-name = 'GW_TABLE-JUL' .
cols-screen-input = '1'.
ELSE.
cols-screen-input = '0'.
ENDIF.
MODIFY tc_table-cols FROM cols INDEX sy-tabix.
ENDLOOP.
WHEN '08'.
LOOP AT tc_table-cols INTO cols.
IF cols-screen-name = 'GW_TABLE-AUG' .
cols-screen-input = '1'.
ELSE.
cols-screen-input = '0'.
ENDIF.
MODIFY tc_table-cols FROM cols INDEX sy-tabix.
ENDLOOP.
ENDCASE.
ENDFORM. "screen_setting
module tc_TABLE_modify input.
* Saving the contents of table control
modify gt_TABLE
from gw_TABLE
index tc_TABLE-current_line .
endmodule.
2013 Jul 31 10:02 AM
Screenshots.
On clicking Create
On Clicking Modify and selecting month of June
On Clicking Save Button
2013 Aug 01 6:39 AM
I was making a mistake as I was looping at two different places.Firstly for the complete screen and second time for the months.That's why my months were not able to work.Later on I created a fresh new code and then it worked ,fine.Well thanks for your efforts and time.Its was nice working with you.Once again thanks.
Gaurav
2013 Jul 30 8:42 AM
Hi Gaurav,
write this code in PBO of screen.
Module make_editable output.
LOOP AT SCREEN.
IF tc_9001-cols = <column number of your required month> .
screen-input = 1.
screen-active = 1.
MODIFY SCREEN .
ENDIF.
ENDLOOP.
Endmodule.
2013 Jul 30 9:17 AM
Hi Gaurav.
A separate PAI event is not necessary for your requirement.
In PBO, create a new module / write the following logic in MODULE TC_GET_LINES.
For instance (assuming that you computed current_month;current_month = 'JULY'),
concatenate 'ITAB-' current_month+0(3) into month.
loop at screen.
if screen-name = month. "ITAB-JUL (all letters in CAPS)
screen-input = 1. "JULY column will be enabled
modify screen.
endif.
endloop.
Regards.
2013 Jul 30 12:58 PM
Hi Arun,
But I want to disable the respective field on button click as I showed in my pic.By default whole tc is disabled but when I click on Create then I want all 28 fields in enable mode.Apart from that looking into the months column only the current month should be enabled rest months disabled.
Thanks
Gaurav
2013 Jul 30 12:14 PM
Hi,
In my scenario, I have used months as radio buttons. A month is selected and "enable" button must be clicked so that only the corresponding column of the month turns into an editable mode.
I have attached the output.
The field can be disabled or enabled by using the line type of <table_control_name>-cols.
It contains the screen elements. For disabling / enabling, use active element in screen.
This must be written in PBO event of the corresponding screen containing the table control.
Coding:
*--------------------------------------------------------------------*
* Type-Pools
*--------------------------------------------------------------------*
TYPE-POOLS: abap.
*--------------------------------------------------------------------*
* Types
*--------------------------------------------------------------------*
TYPES: BEGIN OF ty_month_emp,
jan TYPE char30,
feb TYPE char30,
mar TYPE char30,
apr TYPE char30,
may TYPE char30,
jun TYPE char30,
jul TYPE char30,
aug TYPE char30,
sep TYPE char30,
oct TYPE char30,
nov TYPE char30,
dec TYPE char30,
id TYPE char10,
name TYPE char10,
age TYPE char10,
END OF ty_month_emp,
ty_t_month_emp TYPE STANDARD TABLE OF ty_month_emp.
*--------------------------------------------------------------------*
* Data
*--------------------------------------------------------------------*
DATA: gs_month_emp TYPE ty_month_emp,
gt_month_emp TYPE ty_t_month_emp,
ok_code TYPE sy-ucomm,
r1 TYPE char1 VALUE abap_true,
r2 TYPE char1,
r3 TYPE char1,
r4 TYPE char1,
r5 TYPE char1,
r6 TYPE char1,
r7 TYPE char1,
r8 TYPE char1,
r9 TYPE char1,
r10 TYPE char1,
r11 TYPE char1,
r12 TYPE char1.
*--------------------------------------------------------------------*
* Table Controls
*--------------------------------------------------------------------*
CONTROLS: tc TYPE TABLEVIEW USING SCREEN 9000.
*--------------------------------------------------------------------*
* Field-Symbols
*--------------------------------------------------------------------*
FIELD-SYMBOLS: <fs_cols> LIKE LINE OF tc-cols.
*--------------------------------------------------------------------*
* Initialization
*--------------------------------------------------------------------*
INITIALIZATION.
CALL SCREEN 9000.
*&---------------------------------------------------------------------*
*& Module ENABLE_COLUMN OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE enable_column OUTPUT.
LOOP AT tc-cols ASSIGNING <fs_cols>.
PERFORM enable_col USING: r1 'GS_MONTH_EMP-JAN' CHANGING <fs_cols>,
r2 'GS_MONTH_EMP-FEB' CHANGING <fs_cols>,
r3 'GS_MONTH_EMP-MAR' CHANGING <fs_cols>,
r4 'GS_MONTH_EMP-APR' CHANGING <fs_cols>,
r5 'GS_MONTH_EMP-MAY' CHANGING <fs_cols>,
r6 'GS_MONTH_EMP-JUN' CHANGING <fs_cols>,
r7 'GS_MONTH_EMP-JUL' CHANGING <fs_cols>,
r8 'GS_MONTH_EMP-AUG' CHANGING <fs_cols>,
r9 'GS_MONTH_EMP-SEP' CHANGING <fs_cols>,
r10 'GS_MONTH_EMP-OCT' CHANGING <fs_cols>,
r11 'GS_MONTH_EMP-NOV' CHANGING <fs_cols>,
r12 'GS_MONTH_EMP-DEC' CHANGING <fs_cols>.
ENDLOOP.
* LOOP AT tc-cols INTO ls_cols.
* IF r1 = 'X'.
* ls_cols-screen-active = 1.
* else.
* ls_cols-screen-active = 0.
* ENDIF.
* modify tc-cols FROM ls_cols INDEX sy-tabix.
* ENDLOOP.
ENDMODULE. " ENABLE_COLUMN OUTPUT
*&---------------------------------------------------------------------*
*& Form ENABLE_COL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0170 text
* -->P_0171 text
* <--P_<FS_COLS> text
*----------------------------------------------------------------------*
FORM enable_col USING p_radio TYPE c
value(p_screen_name) LIKE screen-name
CHANGING pa_cols LIKE LINE OF tc-cols.
IF p_radio = abap_true.
IF pa_cols-screen-name = p_screen_name.
pa_cols-screen-active = 1.
ELSE.
pa_cols-screen-active = 0.
ENDIF.
ENDIF.
ENDFORM. " ENABLE_COL
Thanks & Regards,
T. Prasanna Kumar
2013 Jul 30 2:19 PM
Hi Gaurav,
First find the month using date. as
lw_month = lv_date+4(2).
where lv_Date is the date for your requirement.
Then try the code,
if TC_CTRL is your table control structure,
TC_CTRL-cols is a structure which is having columns as index. Like your first column will have an index 1, second as index 2 and so on. First find out the month and corresponding index and then try the following code,
data : wa_cols like line of TC_CTRL-cols,
lv_index type sy-index.
lv_index will be having the value acording to your month calculation.
Loop at TC_CTRL-cols into wa_cols where index NE lv_index.
wa_cols-input = 0.
wa_cols-output = 1.
modify TC_XXX from wa_XXX.
clear wa_cols.
endloop.