Sample Program for F-05 BDC
This program can be used as a sample program for a special type of ALV output. The report shows an output with check boxes in each line. If one select check boxes and process those documents the report process those selected document but after processing it keeps those documents with reference (follow on document numbers) numbers in the list. But the checkboxes will be disabled at this time.
*&---------------------------------------------------------------------*
*& Report name : Invoicing Alternate Payee from(clearing)
*& Individual Vendor Invoices
*& Program name : ZFIAPUO004_AMEX_PCARD_INV
*& Purpose : This program is going to be used for Payment
*& of Alternate Payee Vendor. This program will be
*& run to clear all the open invoices for the
*& vendors for which Alt Payee has been
*& used (as Payee). This program will create
*& invoices for Alt Payee. These invoices
*& can directly processed for Payment.
************************************************************************
REPORT zfiapuo004_amex_pcard_inv
NO STANDARD PAGE HEADING
LINE-SIZE 132
LINE-COUNT 65
MESSAGE-ID zfi.
************************************************************************
* C O N S T A N T S
************************************************************************
*CONSTANTS:
INCLUDE <icon>.
************************************************************************
* D A T A D E F I N I T I O N
************************************************************************
TABLES:
bsik. " General Data in Vendor Master
* wkbp. " Pricing document : item
TYPE-POOLS: slis.
TYPES:
BEGIN OF zbsik,
bukrs LIKE bsik-bukrs,
lifnr LIKE bsik-lifnr,
gjahr LIKE bsik-gjahr,
belnr LIKE bsik-belnr,
budat LIKE bsik-budat,
bldat LIKE bsik-bldat,
waers LIKE bsik-waers,
xblnr LIKE bsik-xblnr,
blart LIKE bsik-blart,
shkzg LIKE bsik-shkzg,
dmbtr LIKE bsik-dmbtr,
wrbtr LIKE bsik-wrbtr,
belnr_2 LIKE bsik-belnr,
message(40) TYPE c,
check_icon(4) TYPE c,
check TYPE c,
END OF zbsik.
************************************************************************
* I N T E R N A L S T R U C T U R E S & T A B L E S
************************************************************************
DATA:
gt_bsik TYPE STANDARD TABLE OF zbsik WITH HEADER LINE,
gt_bdcdata TYPE STANDARD TABLE OF bdcdata WITH HEADER LINE,
gt_bdcmsgcoll TYPE STANDARD TABLE OF bdcmsgcoll WITH HEADER LINE.
DATA: gs_bdcdata TYPE bdcdata .
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv,
gt_event TYPE slis_t_event.
DATA: gs_layout TYPE slis_layout_alv.
************************************************************************
* V A R I A B L E S
************************************************************************
************************************************************************
* R A N G E S
************************************************************************
*ranges:
* gr_vkork for wkbp-vkorg.
************************************************************************
* S E L E C T I O N S C R E E N
************************************************************************
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_bukrs LIKE bkpf-bukrs OBLIGATORY,
p_gjahr LIKE bkpf-gjahr OBLIGATORY.
SELECT-OPTIONS: s_lifnr FOR bsik-lifnr OBLIGATORY,
s_bldat FOR bsik-bldat,
s_budat FOR bsik-budat.
SELECTION-SCREEN: SKIP 1.
PARAMETERS: p_empfb LIKE bsik-empfb OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK b1.
SELECTION-SCREEN: BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS: p_xblnr LIKE bkpf-xblnr OBLIGATORY DEFAULT text-003,
p_bktxt LIKE bkpf-bktxt OBLIGATORY DEFAULT text-003.
SELECTION-SCREEN: END OF BLOCK b2.
************************************************************************
* E V E N T P R O C E S S I N G
************************************************************************
INITIALIZATION.
START-OF-SELECTION.
PERFORM a001_fetch_data.
PERFORM a002_display_report.
END-OF-SELECTION.
TOP-OF-PAGE.
************************************************************************
* S U B R O U T I N E S
************************************************************************
*&---------------------------------------------------------------------*
*& Form A001_FETCH_DATA
*&---------------------------------------------------------------------*
* Fetch Data from Database Based of Selection
*----------------------------------------------------------------------*
FORM a001_fetch_data .
SELECT bukrs
lifnr
gjahr
belnr
budat
bldat
waers
xblnr
blart
shkzg
dmbtr
wrbtr
FROM bsik
INTO TABLE gt_bsik
WHERE bukrs EQ p_bukrs
AND lifnr IN s_lifnr
AND gjahr EQ p_gjahr
AND budat IN s_budat
AND bldat IN s_bldat
AND empfb EQ p_empfb.
IF sy-subrc NE 0.
MESSAGE s146 DISPLAY LIKE 'E'.
* No entries found for the selection
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " A001_FETCH_DATA
*** E N D O F R E P O R T ****************************************
*&---------------------------------------------------------------------*
*& Form A002_DISPLAY_REPORT
*&---------------------------------------------------------------------*
* Display Report
*----------------------------------------------------------------------*
FORM a002_display_report .
DATA: l_repid LIKE sy-repid.
PERFORM b001_build_fieldcat.
* gs_layout-box_fieldname = 'CHECK'.
* gs_layout-no_input = 'X'.
l_repid = sy-repid.
gt_bsik-check_icon = icon_wd_iframe.
MODIFY gt_bsik TRANSPORTING check_icon WHERE NOT bukrs IS INITIAL.
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 = 'B003_PF_STATUS_SET'
i_callback_user_command = 'B004_USER_COMMAND'
* I_STRUCTURE_NAME =
* is_layout = gs_layout
it_fieldcat = gt_fieldcat
* 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
* IR_SALV_LIST_ADAPTER =
* IT_EXCEPT_QINFO =
* I_SUPPRESS_EMPTY_DATA = ABAP_FALSE
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = gt_bsik
* 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. " A002_DISPLAY_REPORT
*&---------------------------------------------------------------------*
*& Form B001_BUILD_FIELDCAT
*&---------------------------------------------------------------------*
* Build Field Catalog for ALV
*----------------------------------------------------------------------*
FORM b001_build_fieldcat .
DATA: ls_field_cat TYPE slis_fieldcat_alv.
CLEAR ls_field_cat.
ls_field_cat-fieldname = 'CHECK_ICON'.
ls_field_cat-hotspot = 'X'.
ls_field_cat-icon = 'X'.
ls_field_cat-outputlen = 2 .
APPEND ls_field_cat TO gt_fieldcat.
PERFORM b002_build_field_catalog USING :
'LIFNR' 'GT_BSIK' 'LIFNR' 'BSIK' '' ,
'BUKRS' 'GT_BSIK' 'BUKRS' 'BSIK' '' ,
'GJAHR' 'GT_BSIK' 'GJAHR' 'BSIK' '' ,
'BELNR' 'GT_BSIK' 'BELNR' 'BSIK' '' ,
'BUDAT' 'GT_BSIK' 'BUDAT' 'BSIK' '' ,
'BLDAT' 'GT_BSIK' 'BLDAT' 'BSIK' '' ,
'XBLNR' 'GT_BSIK' 'XBLNR' 'BSIK' '' ,
'BLART' 'GT_BSIK' 'BLART' 'BSIK' '' ,
'SHKZG' 'GT_BSIK' 'SHKZG' 'BSIK' '' ,
'DMBTR' 'GT_BSIK' 'DMBTR' 'BSIK' '' ,
'WRBTR' 'GT_BSIK' 'WRBTR' 'BSIK' '' ,
'WAERS' 'GT_BSIK' 'WAERS' 'BSIK' '' ,
'BELNR_2' 'GT_BSIK' 'BELNR' 'BSIK' '' ,
'MESSAGE' 'GT_BSIK' 'MESSAGE' 'BAPIRET2' '80'.
ENDFORM. " B001_BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*& Form b002_build_field_catalog
*&---------------------------------------------------------------------*
* Build Field Catalog
*----------------------------------------------------------------------*
FORM b002_build_field_catalog USING "p_col_pos
p_fieldname
p_tabname
p_ref_fieldname
p_ref_tabname
p_outputlen.
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.
ls_field_cat-outputlen = p_outputlen.
APPEND ls_field_cat TO gt_fieldcat.
ENDFORM. " b002_build_field_catalog
*---------------------------------------------------------------------*
* FORM b003_pf_status_set *
*---------------------------------------------------------------------*
* Set PF Status *
*---------------------------------------------------------------------*
FORM b003_pf_status_set USING pt_extab TYPE slis_t_extab.
SET PF-STATUS 'STANDARD'.
ENDFORM. "b003_pf_status_set
*---------------------------------------------------------------------*
* FORM b004_user_command *
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
* User Command *
*---------------------------------------------------------------------*
FORM b004_user_command USING p_ucomm LIKE sy-ucomm
ps_selfield TYPE slis_selfield.
CASE p_ucomm.
WHEN '&PROCS'.
***-----Post Selected Docuemnts----------------*
PERFORM a004_process_invoices.
WHEN '&IC1'.
CASE ps_selfield-fieldname.
WHEN 'CHECK_ICON'.
READ TABLE gt_bsik INDEX ps_selfield-tabindex.
IF sy-subrc EQ 0.
CASE gt_bsik-check_icon.
WHEN icon_checkbox.
gt_bsik-check_icon = icon_wd_iframe.
WHEN icon_wd_iframe.
gt_bsik-check_icon = icon_checkbox.
ENDCASE.
MODIFY gt_bsik INDEX ps_selfield-tabindex.
ENDIF.
ENDCASE.
WHEN '&ALL1'.
gt_bsik-check_icon = icon_checkbox.
MODIFY gt_bsik TRANSPORTING check_icon WHERE belnr_2 IS INITIAL.
WHEN '&SAL1'.
gt_bsik-check_icon = icon_wd_iframe.
MODIFY gt_bsik TRANSPORTING check_icon WHERE belnr_2 IS INITIAL.
ENDCASE.
ps_selfield-refresh = 'X'.
ENDFORM. "b004_user_command
*&---------------------------------------------------------------------*
*& Form a004_PROCESS_INVOICES
*&---------------------------------------------------------------------*
* Process Open Invoices (BDC)
*----------------------------------------------------------------------*
FORM a004_process_invoices .
DATA: l_date(10) TYPE c.
DATA: l_index(2) TYPE c VALUE '00'.
DATA: l_option TYPE ctu_params,
l_belnr_field(20) TYPE c,
l_wrbtr LIKE bsik-wrbtr,
l_wrbtrc(16) TYPE c,
l_waers LIKE bkpf-waers.
CONSTANTS: lc_nodisplay VALUE 'N', " BDC Mode : N Indicates no screen mode
lc_update_sync VALUE 'S', " BDC Update Mode: S indicates synchronous update
lc_tcode(4) TYPE c VALUE 'FB05'.
DATA: lt_final LIKE gt_bsik OCCURS 0 WITH HEADER LINE.
*For setting the screen resolution to default
l_option-updmode = lc_nodisplay.
l_option-defsize = 'X'.
l_option-dismode = lc_update_sync .
*Subroutine to populate final data which need to be passed to bdc.
CLEAR: gt_bdcdata,
gt_bdcmsgcoll.
REFRESH: gt_bdcdata,
gt_bdcmsgcoll.
gt_bsik-check = 'X'.
MODIFY gt_bsik TRANSPORTING check WHERE check_icon EQ icon_checkbox.
gt_bsik-check = space.
MODIFY gt_bsik TRANSPORTING check WHERE check_icon EQ icon_wd_iframe.
lt_final[] = gt_bsik[].
DELETE lt_final WHERE check NE 'X'.
IF NOT lt_final[] IS INITIAL.
LOOP AT lt_final.
IF lt_final-belnr_2 IS NOT INITIAL.
MESSAGE e000 WITH text-004 lt_final-belnr text-005.
* LEAVE LIST-PROCESSING.
ENDIF.
l_wrbtr = l_wrbtr + lt_final-wrbtr.
ENDLOOP.
l_waers = lt_final-waers.
MOVE abs( l_wrbtr ) TO l_wrbtr.
WRITE l_wrbtr TO l_wrbtrc CURRENCY l_waers.
WRITE sy-datum TO l_date.
PERFORM bdc_dynpro USING 'SAPMF05A' '0122'.
PERFORM bdc_field USING :
* BDC_CURSOR RF05A-NEWKO
'BDC_OKCODE' '/00',
'BKPF-BLDAT' l_date,
'BKPF-BLART' 'IC',
'BKPF-BUKRS' p_bukrs,
'BKPF-BUDAT' l_date,
* 'BKPF-MONAT' '6',
'BKPF-WAERS' l_waers,
'BKPF-XBLNR' p_xblnr,
'BKPF-BKTXT' p_bktxt,
* 'FS006-DOCID' '*',
'RF05A-NEWBS' '31',
'RF05A-NEWKO' p_empfb,
'RF05A-XPOS1(02)' ' ' ,
'RF05A-XPOS1(04)' 'X'.
PERFORM bdc_dynpro USING 'SAPMF05A' '0302'.
PERFORM bdc_field USING :
* BDC_CURSOR BSEG-ZLSCH
'BDC_OKCODE' '=PA',
* 'BSEG-HKONT' '21010101',
'BSEG-WRBTR' l_wrbtrc,
* 'BSEG-MWSKZ' '**',
* 'BSEG-ZTERM' 'Z001',
* 'BSEG-ZFBDT' '06/02/2009',
'BSEG-ZLSCH' 'M'.
* 'BSEG-UZAWE' 'EM'.
PERFORM bdc_dynpro USING 'SAPMF05A' '0710' .
PERFORM bdc_field USING :
* BDC_CURSOR RF05A-XPOS1(03)
'BDC_OKCODE' '=PA',
'RF05A-AGBUK' p_bukrs,
'RF05A-AGKOA' 'K',
'RF05A-XNOPS' 'X',
'RF05A-XPOS1(01)' ' ' ,
'RF05A-XPOS1(03)' 'X'.
PERFORM bdc_dynpro USING 'SAPMF05A' '0731'.
PERFORM bdc_field USING :
* BDC_CURSOR RF05A-SEL01(02)
* 'BDC_OKCODE' '=SLK'.
'BDC_OKCODE' '=PA'.
LOOP AT lt_final.
CLEAR l_belnr_field.
l_index = l_index + 1.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = l_index
IMPORTING
output = l_index.
CONCATENATE 'RF05A-SEL01(' l_index ')' INTO l_belnr_field.
PERFORM bdc_field USING :
l_belnr_field lt_final-belnr.
IF l_index = 11.
l_index = 0.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_dynpro USING 'SAPMF05A' '0731'.
ENDIF.
ENDLOOP.
* PERFORM bdc_dynpro USING 'SAPMF05A' '0710'.
* PERFORM bdc_field USING :
** BDC_CURSOR RF05A-XPOS1(03)
* 'BDC_OKCODE' '=PA',
* 'RF05A-AGBUK' '1077',
* 'RF05A-AGKOA' 'K',
* 'RF05A-XNOPS' 'X',
* 'RF05A-XPOS1(01)' '' ,
* 'RF05A-XPOS1(03)' 'X'.
*
* PERFORM bdc_dynpro USING 'SAPMF05A' '0731'.
PERFORM bdc_field USING :
** BDC_CURSOR RF05A-SEL01(01)
'BDC_OKCODE' '=PA'.
PERFORM bdc_dynpro USING 'SAPDF05X' '3100'.
PERFORM bdc_field USING :
'BDC_OKCODE' '=OMX',
'BDC_SUBSCR' 'SAPDF05X 6102PAGE',
* 'BDC_CURSOR DF05B-PSSKT(01)' '',
'RF05A-ABPOS' '1'.
PERFORM bdc_dynpro USING 'SAPDF05X' '3100'.
PERFORM bdc_field USING :
'BDC_OKCODE' '=Z+',
'BDC_SUBSCR' 'SAPDF05X 6102PAGE',
* 'BDC_CURSOR DF05B-PSSKT(01)' '',
'RF05A-ABPOS' '1'.
PERFORM bdc_dynpro USING 'SAPDF05X' '3100'.
PERFORM bdc_field USING :
'BDC_OKCODE' '=BU',
'BDC_SUBSCR' 'SAPDF05X 6102PAGE',
* 'BDC_CURSOR DF05B-PSSKT(01)' ' ',
'RF05A-ABPOS' '1'.
CALL TRANSACTION lc_tcode
USING gt_bdcdata
OPTIONS FROM l_option
MESSAGES INTO gt_bdcmsgcoll.
REFRESH gt_bdcdata[].
DATA: ls_bdcmsgcoll TYPE bdcmsgcoll.
LOOP AT gt_bdcmsgcoll INTO ls_bdcmsgcoll.
*Depending on the success message type for screen number 701(Indicates Document Posted) or error message type
*status field is filled with the message populated via call transaction of FB05 .
IF ls_bdcmsgcoll-msgtyp = 'E' OR
* ( ls_bdcmsgcoll-dynumb = '0701' AND ls_bdcmsgcoll-msgtyp = 'S' ) OR
( ls_bdcmsgcoll-msgid = 'F5' AND ls_bdcmsgcoll-msgnr = 263 ) OR "GL doesn't match
( ls_bdcmsgcoll-msgid = 'F5' AND ls_bdcmsgcoll-msgnr = 170 ) OR "No open item found
( ls_bdcmsgcoll-msgid = 'F5' AND ls_bdcmsgcoll-msgnr = 171 ) OR "No further open item found
( ls_bdcmsgcoll-msgid = 'F5' AND ls_bdcmsgcoll-msgnr = 312 ). "Document Posted
MESSAGE ID ls_bdcmsgcoll-msgid TYPE ls_bdcmsgcoll-msgtyp NUMBER ls_bdcmsgcoll-msgnr
WITH ls_bdcmsgcoll-msgv1
ls_bdcmsgcoll-msgv2
ls_bdcmsgcoll-msgv3
ls_bdcmsgcoll-msgv4 INTO lt_final-message.
ENDIF.
*---- Successfull Posting - Store New Document Number
IF ( ls_bdcmsgcoll-msgid = 'F5' AND ls_bdcmsgcoll-msgnr = 312 ).
lt_final-belnr_2 = ls_bdcmsgcoll-msgv1.
lt_final-check = space.
lt_final-check_icon = icon_okay.
ENDIF.
ENDLOOP.
MODIFY lt_final TRANSPORTING message belnr_2 check check_icon WHERE NOT bukrs IS INITIAL .
LOOP AT gt_bsik.
READ TABLE lt_final WITH KEY bukrs = gt_bsik-bukrs
belnr = gt_bsik-belnr
gjahr = gt_bsik-gjahr.
IF sy-subrc EQ 0.
gt_bsik-message = lt_final-message.
gt_bsik-belnr_2 = lt_final-belnr_2.
gt_bsik-check = lt_final-check.
gt_bsik-check_icon = lt_final-check_icon.
ELSE.
CLEAR gt_bsik-message.
ENDIF.
MODIFY gt_bsik.
ENDLOOP.
ELSE.
MESSAGE e000 WITH text-006.
* LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " a004_PROCESS_INVOICES
**---------------------------------------------------------------------*
**
** Start new screen
**
**---------------------------------------------------------------------*
FORM bdc_dynpro USING program TYPE bdc_prog
dynpro TYPE bdc_dynr.
CLEAR gs_bdcdata.
gs_bdcdata-program = program.
gs_bdcdata-dynpro = dynpro.
gs_bdcdata-dynbegin = 'X'.
APPEND gs_bdcdata TO gt_bdcdata.
ENDFORM. "BDC_DYNPRO
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam
fval .
IF fval <> space.
CLEAR gs_bdcdata.
gs_bdcdata-fnam = fnam.
gs_bdcdata-fval = fval.
APPEND gs_bdcdata TO gt_bdcdata.
ENDIF.
ENDFORM. "BDC_FIELD
Atauceldisc_i Christina Evans https://wakelet.com/wake/z1PjLPkA4TmuokgyQmOl2
ReplyDeletediafurnsifer
racdogQterf_ho1999 Kim Tucker link
ReplyDeletesipittisbpoult
tuneaspecsu Sharon Cook Adobe Photoshop
ReplyDeleteESET NOD32 Smart Security
ScreenHunter Pro
ligangtergder