Handling Check Box in ALV Report in sap abap

&---------------------------------------------------------------------
*& Report ZS_CTM_TEST
*&
&---------------------------------------------------------------------
*&
*&
&---------------------------------------------------------------------

report zs_ctm_test.

*Define tables....
tables: mara,
makt,
marc.

*Define types....
types: begin of t_tab_globe,
check type c,
matnr type matnr,
maktx type maktx,
werks type werks_d,
sernp type serail.
types: end of t_tab_globe.

*Define data....
data: g_tab_globe type standard table of t_tab_globe,
g_wa_globe like line of g_tab_globe,
g_tab_globe_x type standard table of t_tab_globe,
g_wa_globe_x like line of g_tab_globe_x,
g_tab_globe_y type standard table of t_tab_globe,
g_wa_globe_y like line of g_tab_globe_y,
g_tab_globe_z type standard table of zbdc_mat_str_t,
g_wa_globe_z like line of g_tab_globe_z.
*DATA: BEGIN OF log_tab OCCURS 0.
  • INCLUDE STRUCTURE bdcmsgcoll.
*DATA: END OF log_tab.
*DATA: log_wa TYPE LINE OF bdcmsgcoll.
data: begin of map_tab occurs 0.
include structure bdcdata.
data: end of map_tab.
data: log_tab type standard table of bdcmsgcoll,
log_wa like line of log_tab.
data: l_session type apq_grpn.

type-pools: slis.
data: repid like sy-repid,
l_tab_fieldcat type slis_t_fieldcat_alv,
l_tab_fieldcat1 type slis_t_fieldcat_alv,
l_tab_fieldcat2 type slis_t_fieldcat_alv,
l_pos type i,
wa_selfield type slis_selfield,
gs_private type slis_data_caller_exit,
gs_selfield type slis_selfield,
g_exit(1) type c,
checkbox type c,
events type slis_t_event,
events1 type slis_t_event,
wa_events like line of events,
layout type slis_layout_alv,
fieldcat type slis_t_fieldcat_alv,
print type slis_print_alv.
data: bdcdata like bdcdata occurs 0 with header line.

*Define selection screen.....
selection-screen begin of block b1 with frame title text-001.
select-options: s_mater for mara-matnr.
parameters: p_plant like marc-werks,
p_sino like marc-sernp value check obligatory.
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-002.
parameters ctumode like ctu_params-dismode default 'N'.
"A: show all dynpros
"E: show dynpro on error only
"N: do not display dynpro
selection-screen end of block b2.

*get the data
select mara~matnr
makt~maktx
marc~werks
marc~sernp
from
mara inner join makt
on mara~matnr = makt~matnr
inner join marc
on mara~matnr = marc~matnr
into corresponding fields of table g_tab_globe
where
mara~matnr in s_mater
and
werks = p_plant
and
spras = 'EN'
and
marc~sernp ne ''.

perform get_popup.
if not g_exit eq 'X'.
perform display_data.
perform bdc_data.
endif.

&---------------------------------------------------------------------
*& Form get_popup
&---------------------------------------------------------------------

  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- p2 text
----------------------------------------------------------------------
form get_popup .
perform fill_fieldcat.
perform fill_popup.

endform. " get_popup
&---------------------------------------------------------------------
*& Form fill_fieldcat
&---------------------------------------------------------------------

  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- p2 text
----------------------------------------------------------------------
form fill_fieldcat .
perform field_catalog using l_pos 'CHECK' 'G_TAB_GLOBE' '01' text-010.
perform field_catalog using l_pos 'MATNR' 'G_TAB_GLOBE' '18' text-011.
perform field_catalog using l_pos 'MAKTX' 'G_TAB_GLOBE' '40' text-012.
perform field_catalog using l_pos 'WERKS' 'G_TAB_GLOBE' '04' text-013.
perform field_catalog using l_pos 'SERNP' 'G_TAB_GLOBE' '04' text-014.

endform. " fill_fieldcat
&---------------------------------------------------------------------
*& Form field_catalog
&---------------------------------------------------------------------

  • text
----------------------------------------------------------------------
  • -->P_L_POS text
  • -->P_0224 text
  • -->P_0225 text
  • -->P_0226 text
  • -->P_TEXT_010 text
----------------------------------------------------------------------
form field_catalog using u_pos type any
value(u_0212) type any
value(u_0213) type any
value(u_0214) type any
u_text type any.
data: l_wa_fieldcat type slis_fieldcat_alv.
add 1 to u_pos.
l_wa_fieldcat-col_pos = u_pos.
l_wa_fieldcat-fieldname = u_0212.
l_wa_fieldcat-tabname = u_0213.
l_wa_fieldcat-outputlen = u_0214.
l_wa_fieldcat-reptext_ddic = u_text.

append l_wa_fieldcat to l_tab_fieldcat.

endform. " field_catalog
&---------------------------------------------------------------------
*& Form fill_popup
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- p2 text
----------------------------------------------------------------------
form fill_popup .
call function 'REUSE_ALV_POPUP_TO_SELECT'
exporting
i_title = 'SELECT THE AMONG'
i_zebra = 'X'
i_checkbox_fieldname = 'CHECK'
i_tabname = 'G_TAB_GLOBE'
it_fieldcat = l_tab_fieldcat
is_private = gs_private
importing
es_selfield = gs_selfield
e_exit = g_exit
tables
t_outtab = g_tab_globe.
  • EXCEPTIONS
  • PROGRAM_ERROR = 1
  • OTHERS = 2

if sy-subrc 0.
exit.
  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.

endform. " fill_popup
&---------------------------------------------------------------------
*& Form display_data
&---------------------------------------------------------------------

  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- p2 text
----------------------------------------------------------------------
form display_data .
loop at g_tab_globe into g_wa_globe where check = 'X'.
clear g_wa_globe_x.
move g_wa_globe to g_wa_globe_x.
move p_sino to g_wa_globe_x-sernp.
append g_wa_globe_x to g_tab_globe_x.
endloop.

endform. " display_data
&---------------------------------------------------------------------
*& Form bdc_data
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- p2 text
----------------------------------------------------------------------
form bdc_data .

  • IF NOT g_tab_globe_z[] IS INITIAL.
  • CONCATENATE sy-uname sy-datum+4(4) INTO l_session SEPARATED BY '_'.
l_session = sy-repid.
call function 'BDC_OPEN_GROUP'
exporting
  • CLIENT = SY-MANDT
  • DEST = FILLER8
group = l_session
  • HOLDDATE = FILLER8
keep = 'X'
user = sy-uname
  • RECORD = FILLER1
  • PROG = SY-CPROG
  • IMPORTING
  • QID =
  • EXCEPTIONS
  • CLIENT_INVALID = 1
  • DESTINATION_INVALID = 2
  • GROUP_INVALID = 3
  • GROUP_IS_LOCKED = 4
  • HOLDDATE_INVALID = 5
  • INTERNAL_ERROR = 6
  • QUEUE_ERROR = 7
  • RUNNING = 8
  • SYSTEM_LOCK_ERROR = 9
  • USER_INVALID = 10
  • OTHERS = 11
.
if sy-subrc <> 0.
  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
  • ENDIF.

loop at g_tab_globe_x into g_wa_globe_x.
refresh map_tab.
perform sub using 'SAPLMGMM' '0060'.
perform sub1 using 'BDC_CURSOR'
'RMMG1-MATNR'.
perform sub1 using 'BDC_OKCODE'
'/00'.
perform sub1 using 'RMMG1-MATNR'
g_wa_globe_x-matnr.
perform sub using 'SAPLMGMM' '0070'.
perform sub1 using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(06)'.
perform sub1 using 'BDC_OKCODE'
'=ENTR'.
perform sub1 using 'MSICHTAUSW-KZSEL(06)'
'X'.
perform sub using 'SAPLMGMM' '0080'.
perform sub1 using 'BDC_CURSOR'
'RMMG1-WERKS'.
perform sub1 using 'BDC_OKCODE'
'=ENTR'.
perform sub1 using 'RMMG1-WERKS'
g_wa_globe_x-werks.
perform sub using 'SAPLMGMM' '4000'.
perform sub1 using 'BDC_OKCODE'
'/00'.
perform sub1 using 'MAKT-MAKTX'
g_wa_globe_x-maktx..
perform sub1 using 'MARA-MEINS'
'PC'.
perform sub1 using 'MARA-BRGEW'
'3'.
perform sub1 using 'MARA-GEWEI'
'KG'.
perform sub1 using 'MARA-NTGEW'
'2'.
perform sub1 using 'MARC-MTVFP'
'02'.
perform sub1 using 'MARA-TRAGR'
'0001'.
perform sub1 using 'MARC-LADGR'
'0001'.
perform sub1 using 'MARC-VRVEZ'
'1.00'.
perform sub1 using 'MARC-VBEAZ'
'1.00'.
perform sub1 using 'MARC-VBAMG'
'1'.
perform sub1 using 'BDC_CURSOR'
'MARC-SERNP'.
perform sub1 using 'MARC-PRCTR'
'1010'.
perform sub1 using 'MARC-SERNP'
g_wa_globe_x-sernp.

perform sub using 'SAPLSPO1' '0300'.
perform sub1 using 'BDC_OKCODE'
'=YES'.
call transaction 'MM02' using map_tab mode ctumode
messages into log_tab.
if sy-subrc eq 0.
move-corresponding g_wa_globe_x to g_wa_globe_y.
append g_wa_globe_y to g_tab_globe_y.
else.
data: l_tabis type c.
l_tabis = sy-tabix.
clear l_tabis.
add 1 to l_tabis.
read table log_tab into log_wa index l_tabis.
if sy-subrc eq 0.
data: text(70) type c.
call function 'FORMAT_MESSAGE'
exporting
id = log_wa-msgid
lang = sy-langu
no = log_wa-msgnr
v1 = log_wa-msgv1
v2 = log_wa-msgv1
v3 = log_wa-msgv1
v4 = log_wa-msgv1
importing
msg = text.
  • EXCEPTIONS
  • NOT_FOUND = 1
  • OTHERS = 2
.
if sy-subrc <> 0.
  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endif.
move text to g_wa_globe_z-text.
move-corresponding g_wa_globe_x to g_wa_globe_z.
append g_wa_globe_z to g_tab_globe_z.

call function 'BDC_INSERT'
exporting
tcode = 'MM02'
  • POST_LOCAL = NOVBLOCAL
  • PRINTING = NOPRINT
  • SIMUBATCH = ' '
  • CTUPARAMS = ' '
tables
dynprotab = map_tab
exceptions
internal_error = 1
not_open = 2
queue_error = 3
tcode_invalid = 4
printing_invalid = 5
posting_invalid = 6
others = 7
.
if sy-subrc <> 0.
  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.

endif.

  • LOOP AT log_tab.
  • IF log_tab-msgtyp = 'I' OR
  • log_tab-msgnr = 000.
  • WRITE:/ g_wa_globe_x-matnr,
  • g_wa_globe_x-maktx,
  • g_wa_globe_x-werks,
  • g_wa_globe_x-sernp.
*
  • ELSEIF log_tab-msgtyp = 'E' OR
  • log_tab-msgnr = 001.
  • WRITE:/ g_wa_globe_x-matnr,
  • g_wa_globe_x-maktx,
  • g_wa_globe_x-werks,
  • g_wa_globe_x-sernp.
*
  • ENDIF.
    • REFRESH log_tab.
  • ENDLOOP.
  • REFRESH log_tab.
endloop.
call function 'BDC_CLOSE_GROUP'
.
if sy-subrc <> 0.
  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
*endif.

perform grid_display.

endform. " bdc_data
&---------------------------------------------------------------------
*& Form sub
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • -->P_0391 text
  • -->P_0392 text
----------------------------------------------------------------------
form sub using a b.
clear map_tab.
map_tab-program = a.
map_tab-dynpro = b.
map_tab-dynbegin = 'X'.
append map_tab.

endform. " sub
&---------------------------------------------------------------------
*& Form sub1
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • -->P_0396 text
  • -->P_G_WA_GLOBE_X_MATNR text
----------------------------------------------------------------------
form sub1 using c d.
clear map_tab.
map_tab-fnam = c.
map_tab-fval = d.
append map_tab.

endform. " sub1
&---------------------------------------------------------------------
*& Form grid_display
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- p2 text
----------------------------------------------------------------------
form grid_display .
perform fill_fieldcatlog.
perform fill_fieldcatlog1.
perform call_grid.

endform. " grid_display
&---------------------------------------------------------------------
*& Form fill_fieldcatlog
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- p2 text
----------------------------------------------------------------------
form fill_fieldcatlog .
perform field_catlog using l_pos 'MATNR' 'G_TAB_GLOBE_Y' '18' text-222.
perform field_catlog using l_pos 'MAKTX' 'G_TAB_GLOBE_Y' '40' text-223.
perform field_catlog using l_pos 'WERKS' 'G_TAB_GLOBE_Y' '04' text-224.
perform field_catlog using l_pos 'SERNP' 'G_TAB_GLOBE_Y' '04' text-225.

endform. " fill_fieldcatlog
&---------------------------------------------------------------------
*& Form field_catlog
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • -->P_L_POS text
  • -->P_0538 text
  • -->P_0539 text
  • -->P_0540 text
----------------------------------------------------------------------
form field_catlog using u_pos type any
value(u_0538) type any
value(u_0539) type any
value(u_0540) type any
u_text type any.
data: l_wa_fieldcat1 type slis_fieldcat_alv.
add 1 to u_pos.
l_wa_fieldcat1-col_pos = u_pos.
l_wa_fieldcat1-fieldname = u_0538.
l_wa_fieldcat1-tabname = u_0539.
l_wa_fieldcat1-outputlen = u_0540.
l_wa_fieldcat1-reptext_ddic = u_text.

append l_wa_fieldcat1 to l_tab_fieldcat1.

endform. " field_catlog
&---------------------------------------------------------------------
*& Form call_grid
&---------------------------------------------------------------------

  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- p2 text
----------------------------------------------------------------------
form call_grid.
clear events.
wa_events-name = slis_ev_top_of_page.
wa_events-form = 'TOP_OF_PAGE'.
append wa_events to events.
clear wa_events.
wa_events-name = slis_ev_top_of_page.
wa_events-form = 'ETOP_OF_PAGE'.
append wa_events to events1.

  • CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  • EXPORTING
    • I_INTERFACE_CHECK = ' '
    • I_BYPASSING_BUFFER = ' '
    • I_BUFFER_ACTIVE = ' '
    • I_CALLBACK_PROGRAM = ' '
    • I_CALLBACK_PF_STATUS_SET = ' '
    • I_CALLBACK_USER_COMMAND = ' '
    • i_callback_top_of_page = 'top_of_page'
    • i_callback_html_top_of_page = ' '
    • I_CALLBACK_HTML_END_OF_LIST = ' '
  • i_structure_name = 'ZBDC_MAT_STR'
    • I_BACKGROUND_ID = ' '
  • i_grid_title = text-111
    • I_GRID_SETTINGS =
    • IS_LAYOUT =
  • it_fieldcat = l_tab_fieldcat1
    • IT_EXCLUDING =
    • IT_SPECIAL_GROUPS =
    • IT_SORT =
    • IT_FILTER =
    • IS_SEL_HIDE =
    • I_DEFAULT = 'X'
    • I_SAVE = ' '
    • IS_VARIANT =
    • IT_EVENTS =
    • IT_EVENT_EXIT =
    • IS_PRINT =
    • IS_REPREP_ID =
    • I_SCREEN_START_COLUMN = 0
    • I_SCREEN_START_LINE = 0
    • I_SCREEN_END_COLUMN = 0
    • I_SCREEN_END_LINE = 0
    • I_HTML_HEIGHT_TOP = 0
    • I_HTML_HEIGHT_END = 0
    • IT_ALV_GRAPHICS =
    • IT_HYPERLINK =
    • IT_ADD_FIELDCAT =
    • IT_EXCEPT_QINFO =
    • IR_SALV_FULLSCREEN_ADAPTER =
    • IMPORTING
    • E_EXIT_CAUSED_BY_CALLER =
    • ES_EXIT_CAUSED_BY_USER =
  • TABLES
  • t_outtab = g_tab_globe_y
    • EXCEPTIONS
    • PROGRAM_ERROR = 1
    • OTHERS = 2
  • .
  • IF sy-subrc 0.
    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  • ENDIF.
call function 'REUSE_ALV_BLOCK_LIST_INIT'
exporting
i_callback_program = sy-repid
  • I_CALLBACK_PF_STATUS_SET = ' '
  • I_CALLBACK_USER_COMMAND = ' '
  • IT_EXCLUDING =
.
call function 'REUSE_ALV_BLOCK_LIST_APPEND'
exporting
is_layout = layout
it_fieldcat = l_tab_fieldcat1
i_tabname = 'G_TAB_GLOBE_Y'
it_events = events
  • IT_SORT =
i_text = 'UPDATED RECORDS'
tables
t_outtab = g_tab_globe_y.
  • EXCEPTIONS
  • PROGRAM_ERROR = 1
  • MAXIMUM_OF_APPENDS_REACHED = 2
  • OTHERS = 3
.
if sy-subrc 0.
  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
call function 'REUSE_ALV_BLOCK_LIST_APPEND'
exporting
is_layout = layout
it_fieldcat = l_tab_fieldcat2
i_tabname = 'G_TAB_GLOBE_Z'
it_events = events1
  • IT_SORT =
i_text = 'ERROR RECORS'
tables
t_outtab = g_tab_globe_z
  • EXCEPTIONS
  • PROGRAM_ERROR = 1
  • MAXIMUM_OF_APPENDS_REACHED = 2
  • OTHERS = 3
.
if sy-subrc 0.
  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
call function 'REUSE_ALV_BLOCK_LIST_DISPLAY'
  • EXPORTING
    • I_INTERFACE_CHECK = ' '
  • IS_PRINT = print
    • I_SCREEN_START_COLUMN = 0
  • I_SCREEN_START_LINE = 0
  • I_SCREEN_END_COLUMN = 0
  • I_SCREEN_END_LINE = 0
  • IMPORTING
  • E_EXIT_CAUSED_BY_CALLER =
  • ES_EXIT_CAUSED_BY_USER =
  • EXCEPTIONS
  • PROGRAM_ERROR = 1
  • OTHERS = 2
.
if sy-subrc 0.
  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. "call_grid
&---------------------------------------------------------------------
*& Form top_of_page
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- p2 text
----------------------------------------------------------------------
form top_of_page .
write: 'Updated Records'.

endform. " top_of_page
&---------------------------------------------------------------------
*& Form ETOP_OF_PAGE
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- p2 text
----------------------------------------------------------------------
form etop_of_page .
write: 'Error Records'.

endform. " ETOP_OF_PAGE
&---------------------------------------------------------------------
*& Form FILL_FIELDCATLOG1
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- p2 text
----------------------------------------------------------------------
form fill_fieldcatlog1 .
perform field_catlog1 using l_pos 'MATNR' 'G_TAB_GLOBE_Z' '18' text-333.
perform field_catlog1 using l_pos 'MAKTX' 'G_TAB_GLOBE_Z' '40' text-334.
perform field_catlog1 using l_pos 'WERKS' 'G_TAB_GLOBE_Z' '04' text-335.
perform field_catlog1 using l_pos 'SERNP' 'G_TAB_GLOBE_Z' '04' text-336.
perform field_catlog1 using l_pos 'TEXT' 'G_TAB_GLOBE_Z' '70' text-337.

endform. " FILL_FIELDCATLOG1
&---------------------------------------------------------------------
*& Form field_catlog1
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • -->P_L_POS text
  • -->P_1022 text
  • -->P_1023 text
  • -->P_1024 text
  • -->P_TEXT_333 text
----------------------------------------------------------------------
form field_catlog1 using u_pos type any
value(u_1022) type any
value(u_1023) type any
value(u_1024) type any
u_text type any.

data: l_wa_fieldcat2 type slis_fieldcat_alv.
add 1 to u_pos.
l_wa_fieldcat2-col_pos = u_pos.
l_wa_fieldcat2-fieldname = u_1022.
l_wa_fieldcat2-tabname = u_1023.
l_wa_fieldcat2-outputlen = u_1024.
l_wa_fieldcat2-reptext_ddic = u_text.
append l_wa_fieldcat2 to l_tab_fieldcat2.
endform. " field_catlog1

where checkbox fucntionalty in FM called 'REUSE_ALV_POPUP_TO_SELECT'

RELATED POST

ALV REPORT AND DOUBLE CLICK EVENT
FILTER DEPENDENT BADI IMPLEMENTATION PART TWO

SAP ABAP FILTER DEPENDENT BADI IMPLEMENTATION

BADI AND OTHER ENHANCEMENTS COMPARISON

SAP ABAP BADI PART ONE

ABAP BADI PART TWO

No comments:

Post a Comment