Sample ALV with Button and Checkbox
REPORT ZZZZYYYYYZZZZYYYY
NO STANDARD PAGE HEADING MESSAGE-ID zusf
LINE-COUNT 65 LINE-SIZE 120.
*&------------------------------------------------------------------*&
*& TYPE POOLS: &*
*&------------------------------------------------------------------&*
TYPE-POOLS: slis.
*&------------------------------------------------------------------&*
*& PROGRAM VARIABLES: &*
*&------------------------------------------------------------------&*
RANGES: r_blart FOR vbkpf-blart.
*&------------------------------------------------------------------&*
*&------------------------------------------------------------------&*
*& STRUCTURES: &*
*&------------------------------------------------------------------&*
DATA: gs_layout TYPE slis_layout_alv.
*&------------------------------------------------------------------&*
*& INTERNAL TABLES &*
*&------------------------------------------------------------------&*
DATA: BEGIN OF t_vbkpf OCCURS 0,
waers LIKE vbkpf-waers,
bukrs LIKE vbkpf-bukrs,
belnr LIKE vbkpf-belnr,
gjahr LIKE vbkpf-gjahr,
bzkey LIKE zfapapprvtabl-bzkey,
bldat LIKE vbkpf-bldat,
blart LIKE vbkpf-blart,
xblnr LIKE vbkpf-xblnr,
lists LIKE zfapapprvtabl-lists,
aprsn LIKE zfapapprvtabl-aprsn ,
versn LIKE zfapapprvtabl-versn ,
dmbtr LIKE vbsegk-dmbtr,
wrbtr LIKE vbsegk-wrbtr,
lifnr LIKE vbsegk-lifnr,
qsshb LIKE vbsegk-qsshb,
qbshb LIKE vbsegk-qbshb,
zlsch LIKE vbsegk-zlsch,
check TYPE c,
END OF t_vbkpf.
DATA: BEGIN OF t_vbsegk OCCURS 0,
bukrs LIKE vbkpf-bukrs,
belnr LIKE vbkpf-belnr,
gjahr LIKE vbkpf-gjahr,
dmbtr LIKE vbsegk-dmbtr,
wrbtr LIKE vbsegk-wrbtr,
lifnr LIKE vbsegk-lifnr,
qsshb LIKE vbsegk-qsshb,
qbshb LIKE vbsegk-qbshb,
zlsch LIKE vbsegk-zlsch,
END OF t_vbsegk.
DATA: t_field_cat TYPE slis_t_fieldcat_alv,
t_event TYPE slis_t_event.
*&--------------------------------------------------------------------&*
*& INITIALIZATION &*
*&--------------------------------------------------------------------&*
*& Event which occurs before the selection screen is shown to the &*
*& user. It happens only once and ignored in backgroung processing. &*
INITIALIZATION.
PERFORM sub_initialize_range.
*&--------------------------------------------------------------------&*
*& AT SELECTION-SCREEN &*
*&--------------------------------------------------------------------&*
*& Event which occurs each time the user hits ENTER on the &*
*& selection-screen. This is ignored in the background processing &*
AT SELECTION-SCREEN.
*&--------------------------------------------------------------------&*
*& TOP OF PAGE &*
*&--------------------------------------------------------------------&*
TOP-OF-PAGE.
*&--------------------------------------------------------------------&*
*& END OF PAGE &*
*&--------------------------------------------------------------------&*
END-OF-PAGE.
*&--------------------------------------------------------------------&*
*& START OF SELECTION &*
*&--------------------------------------------------------------------&*
START-OF-SELECTION.
***-----Get Data from Database-----------------***
PERFORM sub_get_data.
***-------Build ALV Components-----------------***
PERFORM sub_create_field_catalog.
PERFORM sub_create_events.
***-------Display Report-----------------------***
PERFORM sub_display_report.
*&--------------------------------------------------------------------&*
*& END OF SELECTION &*
*&--------------------------------------------------------------------&*
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form sub_initialize_range
*&---------------------------------------------------------------------*
* Initialize Range Table
*----------------------------------------------------------------------*
FORM sub_initialize_range.
r_blart-sign = 'I'.
r_blart-option = 'EQ'.
r_blart-low = 'ZI'.
APPEND r_blart.
r_blart-low = 'ZJ'.
APPEND r_blart.
ENDFORM. " sub_initialize_range
*&---------------------------------------------------------------------*
*& Form sub_get_data
*&---------------------------------------------------------------------*
* Get Data
*----------------------------------------------------------------------*
FORM sub_get_data.
DATA: l_aprst LIKE zfapapprvtabl-aprst.
DATA: lt_vbkpf_temp LIKE t_vbkpf OCCURS 0 WITH HEADER LINE.
SELECT a~bukrs
a~belnr
a~gjahr
b~bzkey
a~bldat
a~blart
a~xblnr
a~waers
b~lists
b~aprsn
b~versn
INTO CORRESPONDING FIELDS OF TABLE t_vbkpf
FROM vbkpf AS a
JOIN zfapapprvtabl AS b
ON a~bukrs EQ b~ausbk
AND a~belnr EQ b~belnr
AND a~gjahr EQ b~gjahr
WHERE a~blart IN r_blart.
IF sy-subrc EQ 0.
SORT t_vbkpf BY bukrs belnr gjahr bzkey aprsn versn DESCENDING.
DELETE ADJACENT DUPLICATES FROM t_vbkpf COMPARING
bukrs belnr gjahr bzkey aprsn .
lt_vbkpf_temp[] = t_vbkpf[].
DELETE lt_vbkpf_temp WHERE NOT lists EQ 'D'.
LOOP AT t_vbkpf.
READ TABLE lt_vbkpf_temp WITH KEY bukrs = t_vbkpf-bukrs
belnr = t_vbkpf-belnr
gjahr = t_vbkpf-gjahr
bzkey = t_vbkpf-bzkey.
IF sy-subrc NE 0.
t_vbkpf-check = 'X'.
MODIFY t_vbkpf FROM t_vbkpf TRANSPORTING check
WHERE bukrs = t_vbkpf-bukrs
AND belnr = t_vbkpf-belnr
AND gjahr = t_vbkpf-gjahr.
ENDIF.
ENDLOOP.
*---Delete all the un-approved lines-------*
*=========NEED CHANGE --> NE should be EQ before delevery==========*
DELETE t_vbkpf WHERE check EQ 'X'.
*----Display Message In Case No Records Found----------------------*
IF t_vbkpf[] IS INITIAL.
MESSAGE s003 WITH 'No record found !'.
LEAVE LIST-PROCESSING.
ENDIF.
SORT t_vbkpf BY bukrs belnr gjahr.
DELETE ADJACENT DUPLICATES FROM t_vbkpf COMPARING bukrs belnr gjahr.
SELECT bukrs
belnr
gjahr
dmbtr
wrbtr
lifnr
qsshb
qbshb
zlsch
FROM vbsegk
INTO TABLE t_vbsegk
FOR ALL ENTRIES IN t_vbkpf
WHERE bukrs EQ t_vbkpf-bukrs
AND belnr EQ t_vbkpf-belnr
AND gjahr EQ t_vbkpf-gjahr.
IF sy-subrc EQ 0.
LOOP AT t_vbkpf.
READ TABLE t_vbsegk WITH KEY bukrs = t_vbkpf-bukrs
belnr = t_vbkpf-belnr
gjahr = t_vbkpf-gjahr.
IF sy-subrc EQ 0.
MOVE-CORRESPONDING t_vbsegk TO t_vbkpf.
MODIFY t_vbkpf.
ENDIF.
ENDLOOP.
ENDIF.
ELSE.
*----Display Message In Case No Records Found----------------------*
MESSAGE s003 WITH 'No record found !'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " sub_get_data
*&---------------------------------------------------------------------*
*& Form sub_Create_field_catalog
*&---------------------------------------------------------------------*
* Create Field Catalog
*----------------------------------------------------------------------*
FORM sub_create_field_catalog.
PERFORM sub_build_field_catalog USING :
'1' 'LIFNR' 'T_VBKPF' 'LIFNR' 'VBSEGK',
'2' 'BUKRS' 'T_VBKPF' 'BUKRS' 'VBKPF' ,
'3' 'BELNR' 'T_VBKPF' 'BELNR' 'VBKPF' ,
'4' 'GJAHR' 'T_VBKPF' 'GJAHR' 'VBKPF' ,
'5' 'BLDAT' 'T_VBKPF' 'BLDAT' 'VBKPF' ,
'6' 'BLART' 'T_VBKPF' 'BLART' 'VBKPF' ,
'7' 'XBLNR' 'T_VBKPF' 'XBLNR' 'VBKPF' ,
'8' 'DMBTR' 'T_VBKPF' 'DMBTR' 'VBSEGK',
'9' 'WAERS' 'T_VBKPF' 'WAERS' 'VBKPF' ,
'10' 'WRBTR' 'T_VBKPF' 'WRBTR' 'VBSEGK' ,
'11' 'ZLSCH' 'T_VBKPF' 'ZLSCH' 'VBSEGK' ,
'12' 'QSSHB' 'T_VBKPF' 'QSSHB' 'VBSEGK' ,
'13' 'QBSHB' 'T_VBKPF' 'QBSHB' 'VBSEGK' .
ENDFORM. " sub_Create_field_catalog
*&---------------------------------------------------------------------*
*& Form sub_build_field_catalog
*&---------------------------------------------------------------------*
* Build Field Catalog
*----------------------------------------------------------------------*
FORM sub_build_field_catalog USING p_col_pos
p_fieldname
p_tabname
p_ref_fieldname
p_ref_tabname.
DATA: ls_field_cat TYPE slis_fieldcat_alv.
CLEAR ls_field_cat.
ls_field_cat-col_pos = p_col_pos.
ls_field_cat-fieldname = p_fieldname.
ls_field_cat-tabname = p_tabname.
ls_field_cat-ref_fieldname = p_ref_fieldname.
ls_field_cat-ref_tabname = p_ref_tabname.
APPEND ls_field_cat TO t_field_cat.
ENDFORM. " sub_build_field_catalog
*&---------------------------------------------------------------------*
*& Form sub_create_events
*&---------------------------------------------------------------------*
* Create Events
*----------------------------------------------------------------------*
FORM sub_create_events.
DATA: l_event TYPE slis_alv_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
* EXPORTING
* I_LIST_TYPE = 0
IMPORTING
et_events = t_event
EXCEPTIONS
list_type_wrong = 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.
*-------Populate Events------------------*
READ TABLE t_event INTO l_event WITH KEY name = 'TOP_OF_PAGE'.
IF sy-subrc EQ 0.
l_event-form = 'SUB_TOP_OF_PAGE'.
MODIFY t_event FROM l_event INDEX sy-tabix.
ENDIF.
ENDFORM. " sub_create_events
*&---------------------------------------------------------------------*
*& Form sub_display_report
*&---------------------------------------------------------------------*
* Display Report
*----------------------------------------------------------------------*
FORM sub_display_report.
DATA: l_repid LIKE sy-repid .
l_repid = sy-repid.
gs_layout-box_fieldname = 'CHECK'.
SORT t_vbkpf BY bukrs belnr gjahr.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
i_callback_program = l_repid
i_callback_pf_status_set = 'SUB_PF_STATUS_SET'
i_callback_user_command = 'SUB_USER_COMMAND'
* I_STRUCTURE_NAME =
is_layout = gs_layout
it_fieldcat = t_field_cat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
it_events = t_event
* 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
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = t_vbkpf
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. " sub_display_report
*---------------------------------------------------------------------*
* FORM pf_status_set *
*---------------------------------------------------------------------*
* Set PF Status *
*---------------------------------------------------------------------*
FORM sub_pf_status_set USING pt_extab TYPE slis_t_extab.
SET PF-STATUS 'STANDARD'.
ENDFORM.
*---------------------------------------------------------------------*
* FORM pf_status_set *
*---------------------------------------------------------------------*
* User Command *
*---------------------------------------------------------------------*
FORM sub_user_command USING p_ucomm LIKE sy-ucomm
ps_selfield TYPE slis_selfield.
IF p_ucomm EQ '&POST'.
***-----Post Selected Docuemnts----------------*
PERFORM sub_post_document.
***-----Update Summary/Detail Table------------*
WAIT UP TO 10 SECONDS.
PERFORM sub_get_data.
ps_selfield-refresh = 'X'.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM SUB_TOP_OF_PAGE *
*---------------------------------------------------------------------*
* TOP OF PAGE *
*---------------------------------------------------------------------*
FORM sub_top_of_page.
DATA: lt_vbkpf LIKE t_vbkpf OCCURS 0 WITH HEADER LINE.
lt_vbkpf[] = t_vbkpf[].
***----Print Summary Report-----------------**
SORT lt_vbkpf BY waers.
ULINE:/1(88).
FORMAT COLOR COL_HEADING.
WRITE:/ '',
(8) 'Doc Curr', '' ,
(16) 'Amount in LC', '' ,
(16) 'Amount in DC', '' ,
(16) 'WTax Base Amount', '',
(16) 'WTax Amount', ''.
FORMAT COLOR OFF.
ULINE:/1(88).
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
LOOP AT lt_vbkpf.
AT END OF waers.
SUM.
WRITE:/ '',
(8) lt_vbkpf-waers, '' ,
(16) lt_vbkpf-dmbtr, '' ,
(16) lt_vbkpf-wrbtr, '' ,
(16) lt_vbkpf-qsshb, '',
(16) lt_vbkpf-qbshb, ''.
ENDAT.
ENDLOOP.
FORMAT COLOR OFF.
ULINE:/1(88).
ENDFORM.
*&---------------------------------------------------------------------*
*& Form sub_post_document
*&---------------------------------------------------------------------*
* Post Selected Foreign AP Documents
*----------------------------------------------------------------------*
FORM sub_post_document.
DATA: l_object_key LIKE sweinstcou-objkey.
LOOP AT t_vbkpf WHERE check = 'X'.
CONCATENATE t_vbkpf-bukrs
t_vbkpf-belnr
t_vbkpf-gjahr
INTO l_object_key.
CALL FUNCTION 'SAP_WAPI_CREATE_EVENT'
EXPORTING
object_type = 'ZFAPWRKF'
object_key = l_object_key
event = 'POSTFOREIGNAPDOCUMENT'
* COMMIT_WORK = 'X'
* EVENT_LANGUAGE = SY-LANGU
* IMPORTING
* RETURN_CODE =
* EVENT_ID =
* TABLES
* INPUT_CONTAINER =
* MESSAGE_LINES =
* MESSAGE_STRUCT =
.
ENDLOOP.
ENDFORM. " sub_post_document
NO STANDARD PAGE HEADING MESSAGE-ID zusf
LINE-COUNT 65 LINE-SIZE 120.
*&------------------------------------------------------------------*&
*& TYPE POOLS: &*
*&------------------------------------------------------------------&*
TYPE-POOLS: slis.
*&------------------------------------------------------------------&*
*& PROGRAM VARIABLES: &*
*&------------------------------------------------------------------&*
RANGES: r_blart FOR vbkpf-blart.
*&------------------------------------------------------------------&*
*&------------------------------------------------------------------&*
*& STRUCTURES: &*
*&------------------------------------------------------------------&*
DATA: gs_layout TYPE slis_layout_alv.
*&------------------------------------------------------------------&*
*& INTERNAL TABLES &*
*&------------------------------------------------------------------&*
DATA: BEGIN OF t_vbkpf OCCURS 0,
waers LIKE vbkpf-waers,
bukrs LIKE vbkpf-bukrs,
belnr LIKE vbkpf-belnr,
gjahr LIKE vbkpf-gjahr,
bzkey LIKE zfapapprvtabl-bzkey,
bldat LIKE vbkpf-bldat,
blart LIKE vbkpf-blart,
xblnr LIKE vbkpf-xblnr,
lists LIKE zfapapprvtabl-lists,
aprsn LIKE zfapapprvtabl-aprsn ,
versn LIKE zfapapprvtabl-versn ,
dmbtr LIKE vbsegk-dmbtr,
wrbtr LIKE vbsegk-wrbtr,
lifnr LIKE vbsegk-lifnr,
qsshb LIKE vbsegk-qsshb,
qbshb LIKE vbsegk-qbshb,
zlsch LIKE vbsegk-zlsch,
check TYPE c,
END OF t_vbkpf.
DATA: BEGIN OF t_vbsegk OCCURS 0,
bukrs LIKE vbkpf-bukrs,
belnr LIKE vbkpf-belnr,
gjahr LIKE vbkpf-gjahr,
dmbtr LIKE vbsegk-dmbtr,
wrbtr LIKE vbsegk-wrbtr,
lifnr LIKE vbsegk-lifnr,
qsshb LIKE vbsegk-qsshb,
qbshb LIKE vbsegk-qbshb,
zlsch LIKE vbsegk-zlsch,
END OF t_vbsegk.
DATA: t_field_cat TYPE slis_t_fieldcat_alv,
t_event TYPE slis_t_event.
*&--------------------------------------------------------------------&*
*& INITIALIZATION &*
*&--------------------------------------------------------------------&*
*& Event which occurs before the selection screen is shown to the &*
*& user. It happens only once and ignored in backgroung processing. &*
INITIALIZATION.
PERFORM sub_initialize_range.
*&--------------------------------------------------------------------&*
*& AT SELECTION-SCREEN &*
*&--------------------------------------------------------------------&*
*& Event which occurs each time the user hits ENTER on the &*
*& selection-screen. This is ignored in the background processing &*
AT SELECTION-SCREEN.
*&--------------------------------------------------------------------&*
*& TOP OF PAGE &*
*&--------------------------------------------------------------------&*
TOP-OF-PAGE.
*&--------------------------------------------------------------------&*
*& END OF PAGE &*
*&--------------------------------------------------------------------&*
END-OF-PAGE.
*&--------------------------------------------------------------------&*
*& START OF SELECTION &*
*&--------------------------------------------------------------------&*
START-OF-SELECTION.
***-----Get Data from Database-----------------***
PERFORM sub_get_data.
***-------Build ALV Components-----------------***
PERFORM sub_create_field_catalog.
PERFORM sub_create_events.
***-------Display Report-----------------------***
PERFORM sub_display_report.
*&--------------------------------------------------------------------&*
*& END OF SELECTION &*
*&--------------------------------------------------------------------&*
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form sub_initialize_range
*&---------------------------------------------------------------------*
* Initialize Range Table
*----------------------------------------------------------------------*
FORM sub_initialize_range.
r_blart-sign = 'I'.
r_blart-option = 'EQ'.
r_blart-low = 'ZI'.
APPEND r_blart.
r_blart-low = 'ZJ'.
APPEND r_blart.
ENDFORM. " sub_initialize_range
*&---------------------------------------------------------------------*
*& Form sub_get_data
*&---------------------------------------------------------------------*
* Get Data
*----------------------------------------------------------------------*
FORM sub_get_data.
DATA: l_aprst LIKE zfapapprvtabl-aprst.
DATA: lt_vbkpf_temp LIKE t_vbkpf OCCURS 0 WITH HEADER LINE.
SELECT a~bukrs
a~belnr
a~gjahr
b~bzkey
a~bldat
a~blart
a~xblnr
a~waers
b~lists
b~aprsn
b~versn
INTO CORRESPONDING FIELDS OF TABLE t_vbkpf
FROM vbkpf AS a
JOIN zfapapprvtabl AS b
ON a~bukrs EQ b~ausbk
AND a~belnr EQ b~belnr
AND a~gjahr EQ b~gjahr
WHERE a~blart IN r_blart.
IF sy-subrc EQ 0.
SORT t_vbkpf BY bukrs belnr gjahr bzkey aprsn versn DESCENDING.
DELETE ADJACENT DUPLICATES FROM t_vbkpf COMPARING
bukrs belnr gjahr bzkey aprsn .
lt_vbkpf_temp[] = t_vbkpf[].
DELETE lt_vbkpf_temp WHERE NOT lists EQ 'D'.
LOOP AT t_vbkpf.
READ TABLE lt_vbkpf_temp WITH KEY bukrs = t_vbkpf-bukrs
belnr = t_vbkpf-belnr
gjahr = t_vbkpf-gjahr
bzkey = t_vbkpf-bzkey.
IF sy-subrc NE 0.
t_vbkpf-check = 'X'.
MODIFY t_vbkpf FROM t_vbkpf TRANSPORTING check
WHERE bukrs = t_vbkpf-bukrs
AND belnr = t_vbkpf-belnr
AND gjahr = t_vbkpf-gjahr.
ENDIF.
ENDLOOP.
*---Delete all the un-approved lines-------*
*=========NEED CHANGE --> NE should be EQ before delevery==========*
DELETE t_vbkpf WHERE check EQ 'X'.
*----Display Message In Case No Records Found----------------------*
IF t_vbkpf[] IS INITIAL.
MESSAGE s003 WITH 'No record found !'.
LEAVE LIST-PROCESSING.
ENDIF.
SORT t_vbkpf BY bukrs belnr gjahr.
DELETE ADJACENT DUPLICATES FROM t_vbkpf COMPARING bukrs belnr gjahr.
SELECT bukrs
belnr
gjahr
dmbtr
wrbtr
lifnr
qsshb
qbshb
zlsch
FROM vbsegk
INTO TABLE t_vbsegk
FOR ALL ENTRIES IN t_vbkpf
WHERE bukrs EQ t_vbkpf-bukrs
AND belnr EQ t_vbkpf-belnr
AND gjahr EQ t_vbkpf-gjahr.
IF sy-subrc EQ 0.
LOOP AT t_vbkpf.
READ TABLE t_vbsegk WITH KEY bukrs = t_vbkpf-bukrs
belnr = t_vbkpf-belnr
gjahr = t_vbkpf-gjahr.
IF sy-subrc EQ 0.
MOVE-CORRESPONDING t_vbsegk TO t_vbkpf.
MODIFY t_vbkpf.
ENDIF.
ENDLOOP.
ENDIF.
ELSE.
*----Display Message In Case No Records Found----------------------*
MESSAGE s003 WITH 'No record found !'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " sub_get_data
*&---------------------------------------------------------------------*
*& Form sub_Create_field_catalog
*&---------------------------------------------------------------------*
* Create Field Catalog
*----------------------------------------------------------------------*
FORM sub_create_field_catalog.
PERFORM sub_build_field_catalog USING :
'1' 'LIFNR' 'T_VBKPF' 'LIFNR' 'VBSEGK',
'2' 'BUKRS' 'T_VBKPF' 'BUKRS' 'VBKPF' ,
'3' 'BELNR' 'T_VBKPF' 'BELNR' 'VBKPF' ,
'4' 'GJAHR' 'T_VBKPF' 'GJAHR' 'VBKPF' ,
'5' 'BLDAT' 'T_VBKPF' 'BLDAT' 'VBKPF' ,
'6' 'BLART' 'T_VBKPF' 'BLART' 'VBKPF' ,
'7' 'XBLNR' 'T_VBKPF' 'XBLNR' 'VBKPF' ,
'8' 'DMBTR' 'T_VBKPF' 'DMBTR' 'VBSEGK',
'9' 'WAERS' 'T_VBKPF' 'WAERS' 'VBKPF' ,
'10' 'WRBTR' 'T_VBKPF' 'WRBTR' 'VBSEGK' ,
'11' 'ZLSCH' 'T_VBKPF' 'ZLSCH' 'VBSEGK' ,
'12' 'QSSHB' 'T_VBKPF' 'QSSHB' 'VBSEGK' ,
'13' 'QBSHB' 'T_VBKPF' 'QBSHB' 'VBSEGK' .
ENDFORM. " sub_Create_field_catalog
*&---------------------------------------------------------------------*
*& Form sub_build_field_catalog
*&---------------------------------------------------------------------*
* Build Field Catalog
*----------------------------------------------------------------------*
FORM sub_build_field_catalog USING p_col_pos
p_fieldname
p_tabname
p_ref_fieldname
p_ref_tabname.
DATA: ls_field_cat TYPE slis_fieldcat_alv.
CLEAR ls_field_cat.
ls_field_cat-col_pos = p_col_pos.
ls_field_cat-fieldname = p_fieldname.
ls_field_cat-tabname = p_tabname.
ls_field_cat-ref_fieldname = p_ref_fieldname.
ls_field_cat-ref_tabname = p_ref_tabname.
APPEND ls_field_cat TO t_field_cat.
ENDFORM. " sub_build_field_catalog
*&---------------------------------------------------------------------*
*& Form sub_create_events
*&---------------------------------------------------------------------*
* Create Events
*----------------------------------------------------------------------*
FORM sub_create_events.
DATA: l_event TYPE slis_alv_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
* EXPORTING
* I_LIST_TYPE = 0
IMPORTING
et_events = t_event
EXCEPTIONS
list_type_wrong = 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.
*-------Populate Events------------------*
READ TABLE t_event INTO l_event WITH KEY name = 'TOP_OF_PAGE'.
IF sy-subrc EQ 0.
l_event-form = 'SUB_TOP_OF_PAGE'.
MODIFY t_event FROM l_event INDEX sy-tabix.
ENDIF.
ENDFORM. " sub_create_events
*&---------------------------------------------------------------------*
*& Form sub_display_report
*&---------------------------------------------------------------------*
* Display Report
*----------------------------------------------------------------------*
FORM sub_display_report.
DATA: l_repid LIKE sy-repid .
l_repid = sy-repid.
gs_layout-box_fieldname = 'CHECK'.
SORT t_vbkpf BY bukrs belnr gjahr.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
i_callback_program = l_repid
i_callback_pf_status_set = 'SUB_PF_STATUS_SET'
i_callback_user_command = 'SUB_USER_COMMAND'
* I_STRUCTURE_NAME =
is_layout = gs_layout
it_fieldcat = t_field_cat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
it_events = t_event
* 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
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = t_vbkpf
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. " sub_display_report
*---------------------------------------------------------------------*
* FORM pf_status_set *
*---------------------------------------------------------------------*
* Set PF Status *
*---------------------------------------------------------------------*
FORM sub_pf_status_set USING pt_extab TYPE slis_t_extab.
SET PF-STATUS 'STANDARD'.
ENDFORM.
*---------------------------------------------------------------------*
* FORM pf_status_set *
*---------------------------------------------------------------------*
* User Command *
*---------------------------------------------------------------------*
FORM sub_user_command USING p_ucomm LIKE sy-ucomm
ps_selfield TYPE slis_selfield.
IF p_ucomm EQ '&POST'.
***-----Post Selected Docuemnts----------------*
PERFORM sub_post_document.
***-----Update Summary/Detail Table------------*
WAIT UP TO 10 SECONDS.
PERFORM sub_get_data.
ps_selfield-refresh = 'X'.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM SUB_TOP_OF_PAGE *
*---------------------------------------------------------------------*
* TOP OF PAGE *
*---------------------------------------------------------------------*
FORM sub_top_of_page.
DATA: lt_vbkpf LIKE t_vbkpf OCCURS 0 WITH HEADER LINE.
lt_vbkpf[] = t_vbkpf[].
***----Print Summary Report-----------------**
SORT lt_vbkpf BY waers.
ULINE:/1(88).
FORMAT COLOR COL_HEADING.
WRITE:/ '',
(8) 'Doc Curr', '' ,
(16) 'Amount in LC', '' ,
(16) 'Amount in DC', '' ,
(16) 'WTax Base Amount', '',
(16) 'WTax Amount', ''.
FORMAT COLOR OFF.
ULINE:/1(88).
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
LOOP AT lt_vbkpf.
AT END OF waers.
SUM.
WRITE:/ '',
(8) lt_vbkpf-waers, '' ,
(16) lt_vbkpf-dmbtr, '' ,
(16) lt_vbkpf-wrbtr, '' ,
(16) lt_vbkpf-qsshb, '',
(16) lt_vbkpf-qbshb, ''.
ENDAT.
ENDLOOP.
FORMAT COLOR OFF.
ULINE:/1(88).
ENDFORM.
*&---------------------------------------------------------------------*
*& Form sub_post_document
*&---------------------------------------------------------------------*
* Post Selected Foreign AP Documents
*----------------------------------------------------------------------*
FORM sub_post_document.
DATA: l_object_key LIKE sweinstcou-objkey.
LOOP AT t_vbkpf WHERE check = 'X'.
CONCATENATE t_vbkpf-bukrs
t_vbkpf-belnr
t_vbkpf-gjahr
INTO l_object_key.
CALL FUNCTION 'SAP_WAPI_CREATE_EVENT'
EXPORTING
object_type = 'ZFAPWRKF'
object_key = l_object_key
event = 'POSTFOREIGNAPDOCUMENT'
* COMMIT_WORK = 'X'
* EVENT_LANGUAGE = SY-LANGU
* IMPORTING
* RETURN_CODE =
* EVENT_ID =
* TABLES
* INPUT_CONTAINER =
* MESSAGE_LINES =
* MESSAGE_STRUCT =
.
ENDLOOP.
ENDFORM. " sub_post_document
Comments
Post a Comment