Monday, November 1, 2010

Fast and Furious

Thanks to all my friends and my family, who are pushing me towards launching a wesite. I am in the process of writing good quality articles. You may see it all very soon

Tuesday, February 24, 2009

Check box in ALV Grid (Select multiple lines for processing in ALV)

LVLVDuring interactive reporting, it is required to selected more than one line in the output ALV. After selecting multiple lines we might have to process the selection.

For example; The first ALV has the sales order header data. We might have to select more than one line from the Sales order header list. After selecting the lines, when we click a button, it should show the item details of the selected sales orders.




The following code shows how to achieve this.

REPORT znstest.
************************************************************************
* Written by : Saravanan Natarajan *
* Purpose : Enable multiple line selection in ALV grid didsplay. *
* To show checkbox button in front of every line in *
* ALV Grid display. After selectiing multiple lines *
* press a button and display the item level *
************************************************************************

TYPE-POOLS : slis.

TYPES : BEGIN OF t_header,
vbeln LIKE vbak-vbeln,
erdat LIKE vbak-erdat,
ernam LIKE vbak-ernam,
chkbox(1) TYPE c, "Checkbox field in ALV
END OF t_header.

TYPES : BEGIN OF t_item,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
kwmeng LIKE vbap-kwmeng,
END OF t_item.

DATA : it_header TYPE STANDARD TABLE OF t_header,
it_item TYPE STANDARD TABLE OF t_item.


START-OF-SELECTION.

PERFORM get_data.

END-OF-SELECTION.

IF it_header IS NOT INITIAL.

PERFORM display_alv.

ENDIF.



*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* Select data from the VBAK table ( first 10 rows only )
*----------------------------------------------------------------------*
FORM get_data.

SELECT vbeln
erdat
ernam
FROM vbak
INTO TABLE it_header UP TO 10 ROWS.

IF sy-subrc IS INITIAL.
SORT it_header BY vbeln.
ENDIF.

ENDFORM. "get_data

*&---------------------------------------------------------------------*
*& Form display_alv
*&---------------------------------------------------------------------*
* To display the final output in the form of the ALV GRID report
*----------------------------------------------------------------------*
FORM display_alv.
*----------------------------------------------------------------------*
*-Local Internal table declaration
DATA : l_it_fcat TYPE slis_t_fieldcat_alv .

*-Local data declaration
DATA : l_layo TYPE slis_layout_alv .

*----------------------------------------------------------------------*

*-Build the field catalog used for displaying the ALV
PERFORM build_fieldcat CHANGING l_it_fcat.

*-set layout for ALV
*-inorder to show the checkbox button in every line, pass the checkbox
*-field name to the followingn field
l_layo-box_fieldname = 'CHKBOX'.

*-Display the data in ALV Grid

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'ALV_EVENT_PF_STATUS_SET'
i_callback_user_command = 'ALV_EVENT_USER_COMMAND'
is_layout = l_layo
it_fieldcat = l_it_fcat
i_default = 'X'
i_save = 'A'
TABLES
t_outtab = it_header
EXCEPTIONS
program_error = 1
OTHERS = 2.

IF NOT sy-subrc IS INITIAL.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

ENDFORM. "display_alv


*&---------------------------------------------------------------------*
*& Form build_fieldcat
*&---------------------------------------------------------------------*
* This subroutine is used to build field catalog
*----------------------------------------------------------------------*
* <--P_L_IT_FCAT - Contains the field catalog

*----------------------------------------------------------------------*

FORM build_fieldcat CHANGING p_l_it_fcat TYPE slis_t_fieldcat_alv. *----------------------------------------------------------------------* *-Local Data Declarations-* DATA: l_fcat TYPE slis_fieldcat_alv. *----------------------------------------------------------------------* CLEAR l_fcat. l_fcat-fieldname = 'VBELN'. l_fcat-col_pos = 0. l_fcat-seltext_l = 'Sales Order Number'. l_fcat-seltext_m = 'Order Number'. l_fcat-seltext_s = 'Order #'. l_fcat-outputlen = 12. APPEND l_fcat TO p_l_it_fcat. CLEAR l_fcat. l_fcat-fieldname = 'ERDAT'. l_fcat-col_pos = 1. l_fcat-seltext_l = 'Created on'. l_fcat-seltext_m = 'Created on'. l_fcat-seltext_s = 'Created on'. l_fcat-outputlen = 12. APPEND l_fcat TO p_l_it_fcat. CLEAR l_fcat. l_fcat-fieldname = 'ERNAM'. l_fcat-col_pos = 2. l_fcat-seltext_l = 'Created by'. l_fcat-seltext_m = 'Created by'. l_fcat-seltext_s = 'Created by'. l_fcat-outputlen = 30. APPEND l_fcat TO p_l_it_fcat. ENDFORM. "build_fieldcat *---------------------------------------------------------------------* * FORM alv_event_pf_status_set * *---------------------------------------------------------------------* *Passing an EXIT routine indicates to the ALV that the caller wants * *to set a self-defined user status. * *Set the PF status in this form which is called dynamically. * *---------------------------------------------------------------------* FORM alv_event_pf_status_set USING rt_extab TYPE slis_t_extab. "#EC * SET PF-STATUS 'STATUS_HEADER'. ENDFORM. "alv_event_pf_status_set *---------------------------------------------------------------------* * FORM ALV_EVENT_USER_COMMAND * *---------------------------------------------------------------------* * This subroutine is triggered during the user interaction in ALV * *---------------------------------------------------------------------* FORM alv_event_user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield."#EC CALLED *---------------------------------------------------------------------* DATA : lt_header TYPE STANDARD TABLE OF t_header. *---------------------------------------------------------------------* CASE r_ucomm. *-Click the button after selecting the header lines WHEN '&ITM'. *-when the checkbox in front of the every ALV line is clicked. The *-CHKBOX field of the respective line is marked 'X'. REFRESH lt_header. lt_header = it_header. REFRESH it_item. DELETE lt_header WHERE chkbox NE 'X'. SELECT vbeln posnr matnr kwmeng FROM vbap INTO TABLE it_item FOR ALL ENTRIES IN lt_header WHERE vbeln EQ lt_header-vbeln. IF sy-subrc IS INITIAL. SORT it_item. PERFORM display_item. ENDIF. ENDCASE. ENDFORM. "alv_event_user_command *&---------------------------------------------------------------------* *& Form display_item *&---------------------------------------------------------------------* * To display the item level interactive ALV *----------------------------------------------------------------------* FORM display_item. *----------------------------------------------------------------------* *-Local Internal table declaration DATA : l_it_fcat TYPE slis_t_fieldcat_alv . *----------------------------------------------------------------------* *-Build the field catalog used for displaying the ALV PERFORM build_fieldcat_item CHANGING l_it_fcat. *-Display the data in ALV Grid CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = sy-repid it_fieldcat = l_it_fcat i_default = 'X' i_save = 'A' TABLES t_outtab = it_item EXCEPTIONS program_error = 1 OTHERS = 2. IF NOT sy-subrc IS INITIAL. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. ENDFORM. "display_item *&---------------------------------------------------------------------* *& Form build_fieldcat *&---------------------------------------------------------------------* * This subroutine is used to build field catalog *----------------------------------------------------------------------* * <--P_L_IT_FCAT - Contains the field catalog *----------------------------------------------------------------------* FORM build_fieldcat_item CHANGING p_l_it_fcat TYPE slis_t_fieldcat_alv. *----------------------------------------------------------------------* *-Local Data Declarations-* DATA: l_fcat TYPE slis_fieldcat_alv. *----------------------------------------------------------------------* CLEAR l_fcat. l_fcat-fieldname = 'VBELN'. l_fcat-col_pos = 0. l_fcat-seltext_l = 'Sales Order Number'. l_fcat-seltext_m = 'Order Number'. l_fcat-seltext_s = 'Order #'. l_fcat-outputlen = 12. APPEND l_fcat TO p_l_it_fcat. CLEAR l_fcat. l_fcat-fieldname = 'POSNR'. l_fcat-col_pos = 1. l_fcat-seltext_l = 'Item #'. l_fcat-seltext_m = 'Item #'. l_fcat-seltext_s = 'Item #'. l_fcat-outputlen = 8. APPEND l_fcat TO p_l_it_fcat. CLEAR l_fcat. l_fcat-fieldname = 'MATNR'. l_fcat-col_pos = 2. l_fcat-seltext_l = 'Material'. l_fcat-seltext_m = 'Material'. l_fcat-seltext_s = 'Material'. l_fcat-outputlen = 20. APPEND l_fcat TO p_l_it_fcat. CLEAR l_fcat. l_fcat-fieldname = 'KWMENG'. l_fcat-col_pos = 2. l_fcat-seltext_l = 'Quantity'. l_fcat-seltext_m = 'Quantity'. l_fcat-seltext_s = 'Quantity'. l_fcat-outputlen = 10. APPEND l_fcat TO p_l_it_fcat. ENDFORM. "build_fieldcat_item

Friday, February 20, 2009

Finding the Outbound IDOC number for an delivery

How to find an IDOC number for an delivery document

This blogs show you how to find the outbound IDOC number which is created from a delivery document.

In order to achieve this we have to use two tables SRRELROLES and IDOCREL.
  • Enter the delivery number in the objectkey OBJKEY field and 'LIKP' in the objecttype OBJTYP field of the table SRRELROLES. Get its related SRRELROLES-ROLEID value.
  • Now pass the value of SRRELROLES-ROLEID to the field ROLE_A of the table IDOCREL and get the IDOCREL-ROLE_B value.
  • Go back to SRRELROLES table and enter the IDOCREL-ROLE_B value in the SRRELROLES-ROLEID. The object key OBJKEY value of this line is nothing but the IDOC number of the delivery document.

Monday, February 2, 2009

Restict Select-Option entries

When we press the "Multiple selection" button at the end of the SELECT-OPTIONS, we will get the following screen.







In the above screen, we might have to restict the user from entering the values in anyone or more tabs. For that we have to hid that tabs from display.

This can be achived using the follwoing code.

*&---------------------------------------------------------------------
*& Report ZNSTEST
*&---------------------------------------------------------------------
*&Written by Saravanan Natarajan.
*&Purpose : Restrict the select-options entries
*&---------------------------------------------------------------------
REPORT znstest.

TABLES : mara .
TYPE-POOLS : sscr .

SELECT-OPTIONS : s_matnr FOR mara-matnr.


INITIALIZATION.

PERFORM restrict_select_options.


START-OF-SELECTION.

Write : 'Code in START OF SELECTION'.

*&---------------------------------------------------------------------
*& Form restrict_select_option
*&---------------------------------------------------------------------
FORM restrict_select_options.
*-Local Data Declarations-*
DATA: str_restrict TYPE sscr_restrict,
str_opt_list TYPE sscr_opt_list,
str_ass TYPE sscr_ass.
*----------------------------------------------------------------------
*-Restrict Material Number-*

*-Create the str_ass entry to show that we are restricting S_MATNR
CLEAR str_ass.
str_ass-op_main = 'S_MATNR'.
str_ass-name = 'S_MATNR'.
str_ass-kind = 'S'.
str_ass-sg_main = '*'.

APPEND str_ass TO str_restrict-ass_tab.

*-Create str_opt_list, which specifies the options of S_MATNR
CLEAR: str_opt_list.
str_opt_list-name = 'S_MATNR'.
str_opt_list-options-eq = 'X'. "activate-include Single values
str_opt_list-options-ne = space. "Dont activate-exclude single values
str_opt_list-options-bt = space. "Dont activate-include ranges
str_opt_list-options-nb = space. "Dont activate-exclude ranges
str_opt_list-options-cp = space. "Dont activate- Include Pattern
str_opt_list-options-ge = space. "Dont activate- >=
str_opt_list-options-gt = space. "Dont activate- >
str_opt_list-options-le = space. "Dont activate- <= str_opt_list-options-lt = space. "Dont activate- < np =" space." restriction =" str_restrict" too_late =" 1" repeated =" 2" selopt_without_options =" 3" selopt_without_signs =" 4" invalid_sign =" 5" empty_option_list =" 6" invalid_kind =" 7" repeated_kind_a =" 8" others =" 9."> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ENDFORM. "restrict_select_options



Ouput of the above code:

When the "Multiple Selection" button is clicked