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: 

Functionality of Checkbox in ALV Grid Report

Former Member
0 Kudos
1,330

Hi Experts,

I created a ALV grid report with the checkbox as my first coloum and other fields as shown below. Initially, my ALV report displays as below. It is working fine till here.

checkbox customer material quantity UOM Sales Order Delivery

C1 M1 1 KG

C1 M2 2 KG

C2 M1 1 KG

C2 M2 2 KG

C3 M1 1 KG

C3 M2 2 KG

C3 M3 3 KG

C4 M1 1 KG

C5 M5 1 KG

I have created a push button on application toolbar for creating sales order and delivery using bapi's. When I click on my pushbutton, as of now it creates the SO and delivery for the first customer C1 and updates my Internal table with the sales order number and delivery number. If I need to create sales order for the second customer I need to run my ALV report again and so on for 3rd, 4th and 5th customers. It is also working fine till here.

checkbox customer material quantity UOM Sales Order Delivery

C1 M1 1 KG SO1 DEL1

C1 M2 2 KG SO1 DEL1

C2 M1 1 KG

C2 M2 2 KG

C3 M1 1 KG

C3 M2 2 KG

C3 M3 3 KG

C4 M1 1 KG

C5 M5 1 KG

Need help on this:

When I select the check boxes as shown below and when I click the push button to create SO and Delivery then my program should create sales order and delivery for all the checked ones as shown below. What is the condition do I need to put here for selecting the checkbox.

checkbox customer material quantity UOM Sales Order Delivery

X C1 M1 1 KG SO1 DEL1

X C1 M2 2 KG SO1 DEL1

C2 M1 1 KG

C2 M2 2 KG

X C3 M1 1 KG SO3 DEL3

X C3 M2 2 KG SO3 DEL3

X C3 M3 3 KG SO3 DEL3

C4 M1 1 KG

X C5 M5 1 KG SO5 DEL5

I would really appreciate if somebody could help me / guide me on this. I will also post my code if someone needs to understand what I am doing exactly.

Thanks.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
267

Hi,

You can call a method check_changed_data

DATA: l_valid type c,

CALL METHOD ref_grid->check_changed_data

IMPORTING

e_valid = l_valid.

Where user click on the check box in report the above method will set it in internal table.

LOOP AT output_table ............ where checkbox_column eq 'x'.

" write your logic here"

ENDLOOP.

Hope this will work.

Thanks.

17 REPLIES 17

Former Member
0 Kudos
267

Moderator message - Please respect the 5,000 character maximum when posting. Post only the relevant portions of code

Edited by: Rob Burbank on Jun 9, 2011 2:59 PM

0 Kudos
267

Can Someone please help me on this.

Thanks in Advance

0 Kudos
267

I would really really appreciate if someone could help me on this.

Below is my code.

FORM USER_COMMAND USING L_UCOMM LIKE SY-UCOMM LS_SELFIELD TYPE SLIS_SELFIELD.
L_UCOMM = SY-UCOMM.
CASE L_UCOMM. 
WHEN '&SO_DELIV&'. 
READ TABLE ITAB INTO WA INDEX 1. 
CLEAR: GV_SOLD, GV_SHIP. 
GV_SOLD = WA-CUSTOMER.
GV_SHIP = WA-CUSTOMER. 

GS_ORDERHEADERIN-DOC_TYPE = GC_AUART. 
GS_ORDERHEADERIN-SALES_ORG = GC_SORG. 
GS_ORDERHEADERIN-DISTR_CHAN = GC_DISTC. 
GS_ORDERHEADERIN-DIVISION = GC_DIVI. 
GS_ORDERHEADERIN-ORD_REASON = GC_AUGRU.
GS_ORDERHEADERIN-REQ_DATE_H = WA-REQ_DEL_DATE. 
GS_ORDERHEADERIN-PURCH_DATE = WA-PURCH_DATE. 
GS_ORDERHEADERIN-PURCH_NO_C = WA-PURCH_NO_C.
 
GS_ORDERHEADERINX-DOC_TYPE = GC_FLAG. 
GS_ORDERHEADERINX-SALES_ORG = GC_FLAG. 
GS_ORDERHEADERINX-DISTR_CHAN = GC_FLAG. 
GS_ORDERHEADERINX-DIVISION = GC_FLAG. 
GS_ORDERHEADERINX-ORD_REASON = GC_FLAG.
GS_ORDERHEADERINX-REQ_DATE_H = GC_FLAG. 
GS_ORDERHEADERINX-PURCH_DATE = GC_FLAG.
GS_ORDERHEADERINX-PURCH_NO_C = GC_FLAG. 

LOOP AT IT_ZSD_USAGE INTO WA_ZSD_USAGE WHERE CUSTOMER = WA_ZSD_USAGE-CUSTOMER. 
GS_ORDERITEMSIN-ITM_NUMBER = WA-POSNR. 
GS_ORDERITEMSIN-MATERIAL = WA-MATERIAL. 
GS_ORDERITEMSIN-TARGET_QU = WA-ZIEME. 
GS_ORDERITEMSIN-TARGET_QTY = WA-ZMENG. 
APPEND GS_ORDERITEMSIN TO GT_ORDERITEMSIN. 
CLEAR GS_ORDERITEMSIN. 

GS_ORDERITEMSINX-ITM_NUMBER = WA-POSNR. 
GS_ORDERITEMSINX-MATERIAL = GC_FLAG. 
GS_ORDERITEMSINX-TARGET_QU = GC_FLAG. 
GS_ORDERITEMSINX-TARGET_QTY = GC_FLAG. 
APPEND GS_ORDERITEMSINX TO GT_ORDERITEMSINX. 
CLEAR GS_ORDERITEMSINX.

GS_ORDER_SCHEDULES_IN-ITM_NUMBER = WA-POSNR. 
GS_ORDER_SCHEDULES_IN-REQ_QTY = WA-ZMENG. 
GS_ORDER_SCHEDULES_IN-REQ_DATE = WA-REQ_DEL_DATE. 
APPEND GS_ORDER_SCHEDULES_IN TO GT_ORDER_SCHEDULES_IN. 
CLEAR GS_ORDER_SCHEDULES_IN. 

GS_ORDER_SCHEDULES_INX-ITM_NUMBER = WA-POSNR. 
GS_ORDER_SCHEDULES_INX-REQ_QTY = GC_FLAG. 
GS_ORDER_SCHEDULES_INX-REQ_DATE = GC_FLAG. 
APPEND GS_ORDER_SCHEDULES_INX TO GT_ORDER_SCHEDULES_INX.
CLEAR GS_ORDER_SCHEDULES_INX. 
ENDLOOP. 

GS_ORDERPARTNERS-PARTN_ROLE = GC_SP.
GS_ORDERPARTNERS-PARTN_NUMB = GV_SOLD. 
APPEND GS_ORDERPARTNERS TO GT_ORDERPARTNERS. 
CLEAR GS_ORDERPARTNERS.

GS_ORDERPARTNERS-PARTN_ROLE = GC_SH. 
GS_ORDERPARTNERS-PARTN_NUMB = GV_SHIP. 
APPEND GS_ORDERPARTNERS TO GT_ORDERPARTNERS. 
CLEAR GS_ORDERPARTNERS. 

CLEAR:GV_SALESDOCUMENT. 

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2' 
EXPORTING 
ORDER_HEADER_IN = GS_ORDERHEADERIN 
ORDER_HEADER_INX = GS_ORDERHEADERINX
IMPORTING 
SALESDOCUMENT = GV_SALESDOCUMENT 
TABLES 
ORDER_ITEMS_IN = GT_ORDERITEMSIN 
ORDER_ITEMS_INX = GT_ORDERITEMSINX 
ORDER_SCHEDULES_IN = GT_ORDER_SCHEDULES_IN 
ORDER_SCHEDULES_INX = GT_ORDER_SCHEDULES_INX 
ORDER_PARTNERS = GT_ORDERPARTNERS 
RETURN = GT_BAPIRETURN.

IF GV_SALESDOCUMENT NE ''. 
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' 
EXPORTING WAIT = GC_FLAG.

LOOP AT IT_ZSD_USAGE INTO WA_ZSD_USAGE WHERE CUSTOMER = WA_ZSD_USAGE-CUSTOMER. 
GS_DELV-REF_DOC = GV_SALESDOCUMENT. 
GS_DELV-REF_ITEM = WA-POSNR. 
GS_DELV-DLV_QTY = WA-DLV_QTY. 
GS_DELV-SALES_UNIT = WA-ZIEME. 
APPEND GS_DELV TO GT_DELV. 
CLEAR GS_DELV. 

GS_CREATED-REF_DOC = GV_SALESDOCUMENT. 
GS_CREATED-REF_ITEM = WA-POSNR. 
GS_CREATED-MATERIAL = WA-MATERIAL. 
GS_CREATED-DLV_QTY = WA-DLV_QTY. 
GS_CREATED-SALES_UNIT = WA-ZIEME. 
APPEND GS_CREATED TO GT_CREATED. 
CLEAR GS_CREATED. 
ENDLOOP.

CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_SLS'
EXPORTING 
DUE_DATE = WA-REQ_DEL_DATE 
IMPORTING
DELIVERY = GV_DELIVERY 
TABLES 
SALES_ORDER_ITEMS = GT_DELV 
CREATED_ITEMS = GT_CREATED 
RETURN = GT_DELRETURN. 

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' 
EXPORTING WAIT = GC_FLAG.

IF SY-SUBRC EQ 0 AND GV_DELIVERY NE ' '. 
MESSAGE S000(001) WITH 'Sales Order No.:' GV_SALESDOCUMENT 'and Delivery No.:' GV_DELIVERY. 

DATA: REF_GRID TYPE REF TO CL_GUI_ALV_GRID.
IF REF_GRID IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = REF_GRID. 
ENDIF.

IF NOT REF_GRID IS INITIAL. 
CALL METHOD REF_GRID->CHECK_CHANGED_DATA. 
ENDIF. 

LOOP AT ITAB INTO WA WHERE CUSTOMER = WA-CUSTOMER. 
WA-SALESORDER = GV_SALESDOCUMENT. 
WA-DELIVERY = GV_DELIVERY. 
MODIFY ITAB FROM WA. 

UPDATE ZTABLE SET ERDAT = SY-DATUM 
                                    ERZET = SY-UZEIT 
                                    FLAG = GC_FLAG 
                                   SALESORDER = GV_SALESDOCUMENT
                                   DELIVERY = GV_DELIVERY 
                                   WHERE CUSTOMER = WA-CUSTOMER.
ENDLOOP. 

LS_SELFIELD-REFRESH = GC_FLAG. 

ELSE. 

MESSAGE S203(ER) WITH 'Sales Order:' GV_SALESDOCUMENT 'created. Delivery is not created'.
ENDIF. 

ELSE. 

MESSAGE S204(ER) WITH 'Sales Order Not Created'. 
ENDIF. 
ENDCASE.
ENDFORM.                    "USER_COMMAND

Thanks in Advance

0 Kudos
267

You need to use OO ABAP

Use Class the class 1) CL_GUI_ALV_GRID, 2) CL_GUI_CUSTOM_CONTAINER

Create Sceen and container on same screen.

Check following COde it used for printing purpose.

Using AFTER_USER_COMMAND Event you will find Check box selected entries.

Capture those in another internal Table and use it for SO Creation

DATA: O_GRID TYPE REF TO CL_GUI_ALV_GRID,

O_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,

T_FCAT TYPE LVC_T_FCAT,

CONTAINER(15) TYPE C VALUE 'ET_CONTAINER'.

----


  • CLASS EVENT_CLASS DEFINITION

----


*

----


CLASS EVENT_CLASS DEFINITION.

PUBLIC SECTION.

METHODS: BEFORE_COMMAND FOR EVENT AFTER_USER_COMMAND OF CL_GUI_ALV_GRID IMPORTING E_UCOMM,

DOUBLE_CLICK_N FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID IMPORTING E_ROW E_COLUMN,

TOOLBAR FOR EVENT TOOLBAR OF CL_GUI_ALV_GRID IMPORTING E_OBJECT.

ENDCLASS. "EVENT_CLASS DEFINITION

----


  • CLASS EVENT_CLASS IMPLEMENTATION

----


*

----


CLASS EVENT_CLASS IMPLEMENTATION.

METHOD BEFORE_COMMAND.

IF E_UCOMM = 'PRINT'.

CLEAR : W_FLAG.

T_FINAL2 = T_FINAL.

SORT T_FINAL2 BY COL_CHK .

DELETE T_FINAL2 WHERE COL_CHK = ' '.

IF NOT T_FINAL2 IS INITIAL.

LOOP AT T_FINAL2 INTO WA_FINAL.

IF W_FLAG IS INITIAL.

  • Does some of modification/s in control parameters

W_CONTROL_PARAM-NO_OPEN = 'X'.

W_CONTROL_PARAM-NO_CLOSE = 'X'.

W_CONTROL_PARAM-PREVIEW = 'X'.

W_CONTROL_PARAM-NO_DIALOG = SPACE.

W_OUTPUT_OPTIONS-TDNEWID = 'X'.

W_OUTPUT_OPTIONS-TDIMMED = SPACE.

  • Opens the smartform print-job

CALL FUNCTION 'SSF_OPEN'

EXPORTING

OUTPUT_OPTIONS = W_OUTPUT_OPTIONS

CONTROL_PARAMETERS = W_CONTROL_PARAM

EXCEPTIONS

FORMATTING_ERROR = 1

INTERNAL_ERROR = 2

SEND_ERROR = 3

USER_CANCELED = 4

OTHERS = 5.

IF SY-SUBRC EQ 0.

W_FLAG = 'X'.

ELSE.

  • LEAVE LIST-PROCESSING.

ENDIF.

ENDIF.

IF W_FLAG = 'X'.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

FORMNAME = 'ZFORM_BIW_PRINT'

IMPORTING

FM_NAME = LF_FM_NAME

EXCEPTIONS

NO_FORM = 1

NO_FUNCTION_MODULE = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

ENDIF.

IF SY-SUBRC = 0.

CALL FUNCTION LF_FM_NAME

EXPORTING

CONTROL_PARAMETERS = W_CONTROL_PARAM

  • V_VBELN = WA_FINAL-VBELN

WA_FINAL = WA_FINAL.

  • TABLES

  • T_FINAL = T_FINAL.

ELSE.

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

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

ENDIF.

ENDIF.

ENDLOOP.

  • * Close the smartform print job

IF W_FLAG EQ 'X'.

CALL FUNCTION 'SSF_CLOSE'

EXCEPTIONS

FORMATTING_ERROR = 1

INTERNAL_ERROR = 2

SEND_ERROR = 3

OTHERS = 4.

ENDIF.

ENDIF.

ENDIF.

ENDMETHOD. "BEFORE_COMMAND

Former Member
0 Kudos
268

Hi,

You can call a method check_changed_data

DATA: l_valid type c,

CALL METHOD ref_grid->check_changed_data

IMPORTING

e_valid = l_valid.

Where user click on the check box in report the above method will set it in internal table.

LOOP AT output_table ............ where checkbox_column eq 'x'.

" write your logic here"

ENDLOOP.

Hope this will work.

Thanks.

0 Kudos
267

Hi Sarkar,

Thanks so much for your response. I am new to OOPS concept. I have posted my code. Could you please suggest me where to add therequired code based on my sample code.

Thanks in Advance.

0 Kudos
267

Hi,

Please do the following coding


when ' sy-ucomm '.

 DATA: L_VALID TYPE C,
        LT_ROW_NO TYPE LVC_T_ROID WITH HEADER LINE.


    CALL METHOD G_GRID->CHECK_CHANGED_DATA
              IMPORTING
                 E_VALID = L_VALID.
  IF L_VALID EQ 'X'.

LOOP AT output_table ............ where checkbox_column eq 'x'.
       "call the bapi for SO and Delivery.
	"pass the sales order number and delivery number 
       MODIFY PT_OUTTAB FROM LS_OUTTAB ."modify the itab
    endloop.

    CALL METHOD G_GRID->REFRESH_TABLE_DISPLAY."call this method after the endloop.

endif.

Regards,

Dhina..

Edited by: Dhina DMD on Jun 9, 2011 7:06 AM

0 Kudos
267

Hi Dhina and Sarkar

Thanks for the replies. It worked for me. But I have one more thing to do with my check box. I need to disable my checkboxes for which the SO and delivery got created sucessfully. Is there any function module or method to do this?

I tried using

LOOP AT ITAB INTO WA WHERE CUSTOMER = WA-CUSTOMER.
                IF L_VALID = GC_FLAG.
                  WA-CHECKBOX = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
                ENDIF.
                WA-SALESORDER  = GV_SALESDOCUMENT.
                WA-DELIVERY        = GV_DELIVERY.
                MODIFY ITAB FROM WA.
               ENDLOOP.

But didn't worked. Please suggest.

Thanks.

0 Kudos
267

Nani,

You can use this forum not only to post questions but also to search for existing answers.

0 Kudos
267

Hi Suman,

Thanks for the reply. I went thru the link which you sent me. But I am not able to understand. Please help me.

Thanks.

0 Kudos
267

I really don't understand what you didnt understand after going through the link for enabling & disabling fields in ALV Grid. Please be precise as to what you have tried and what is not working ( if possible with code ) so that we can help you better.

0 Kudos
267

I have already pasted my code before u sent me the link details. I went thru many forums and couldn't find the solution for this.

Please suggest me.

Thanks.

0 Kudos
267

If you really want help, you must be precise in stating the problem. Just saying that you "don't understand" something in a link doesn't help.

Rob

0 Kudos
267

Define your output table like the one shown in the link which is adding "DATA: cellstyles TYPE lvc_t_styl." in the output table.

Then do the other code. Write a perform.

DATA: ls_listrow LIKE LINE OF pt_list. " this is like line of internal table.

  • Following two are your internal table for style and work area for style.

DATA: ls_stylerow TYPE lvc_s_styl.

DATA: ls_styletab TYPE lvc_t_styl.

Loop through your internal table and then...

if wa-vbeln = 'processed' . "do whatever code you want to check for then

ls_stylerow-fieldname = 'CUSTOMER'.

ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.

APPEND ls_stylerow TO ls_styletab.

endif.

  • finally insert the styles into your internal table - table (this is deep structure at this point)

INSERT LINES OF ls_styletab INTO TABLE ls_listrow-cellstyles.

MODIFY pt_list FROM ls_listrow. "Modifying your existing internal table from work are.

ENDLOOP.

Try it.. if you can't get it ... Tell us how you defined the check box and how and where you made it editable.

0 Kudos
267

Hi Nani,

I saw the code you pasted here.

Hope you have used container and CL_GUI_ALV_GRID class to display your ALV GRID.

After call CHECK_CHANGED_DATA method ,in loop have you added the where condition for checkbox field?

thanks...

0 Kudos
267

Hi,

there 3 steps:

1): you have an internal table which you will show via ALV. In this table you have to declare an new field,


STYLE TYPE LVC_T_STYL, "insert this field in your itab

2) you fill the itab with data. in sthis part fill the value of STYLE

  • Do this in filling your internal table.


CLEAR : GS_STYLE, WA_ITAB-STYLE[].
GS_STYLE-FIELDNAME = 'CHKBX'.
IF ... ."Put the condition proceed or not
GS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
ELSE.
GS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.
ENDIF.
APPEND GS_STYLE TO WA_ITAB-STYLE.

3) in the layoutdefinition you have to set this inserted Field.

  • set this in LAYOUT


GS_LAYOUT-STYLEFNAME = 'STYLE'.

Hope this is More Helpfull

Regards,

Dhina..

0 Kudos
267

Thank you all for your valuable responses.