report ZFBS1_01
no standard page heading line-size 255.
* Include bdcrecx1_s:
* The call transaction using is called WITH AUTHORITY-CHECK!
* If you have own auth.-chec,ks you can use include bdcrecx1 instead.
*include bdcrecx1_s.
INCLUDE ZFBS1_01_TOP.
INCLUDE ZFBS1_01_SEL.
INCLUDE ZFBS1_01_SUB.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM F4_FILE_NAME.
START-OF-SELECTION.
PERFORM FILE_UPLOAD.
PERFORM HEAD_LINE_DATA.
IF IT_HEAD IS NOT INITIAL.
PERFORM RUN_BDC.
ENDIF.
*&---------------------------------------------------------------------*
*& Include ZFBS1_01_TOP
*&---------------------------------------------------------------------*
TYPES : BEGIN OF ty_data,
srno TYPE char10,
bldat TYPE bkpf-bldat,
blart TYPE bkpf-blart,
bukrs TYPE bkpf-bukrs,
budat TYPE bkpf-budat,
waers TYPE bkpf-waers,
xblnr TYPE bkpf-xblnr,
bktxt TYPE bkpf-bktxt,
stgrd TYPE bkpf-stgrd,
stodt TYPE bkpf-stodt, " HEAD
* DOCID TYPE FS006-DOCID,
* BUZEI TYPE BSEG-BUZEI, "LINEITEM
newbs TYPE rf05a-newbs,
newko TYPE rf05a-newko,
wrbtr TYPE bseg-wrbtr,
mwskz TYPE bseg-mwskz,
xmwst TYPE bkpf-xmwst,
bupla TYPE bseg-bupla,
zuonr TYPE bseg-zuonr,
sgtxt TYPE bseg-sgtxt,
gsber TYPE cobl-gsber,
kostl TYPE cobl-kostl,
aufnr TYPE cobl-aufnr,
prctr TYPE cobl-prctr,
segment TYPE fb_segment,
kdauf TYPE kdauf,
kdpos TYPE kdpos,
werks TYPE bseg-werks,
END OF ty_data.
DATA: it_data TYPE TABLE OF ty_data,
wa_data TYPE ty_data.
*HEADER
TYPES : BEGIN OF ty_head,
srno TYPE i,
bldat TYPE bkpf-bldat,
blart TYPE bkpf-blart,
bukrs TYPE bkpf-bukrs,
budat TYPE bkpf-budat,
waers TYPE bkpf-waers,
xblnr TYPE bkpf-xblnr,
bktxt TYPE bkpf-bktxt,
stgrd TYPE bkpf-stgrd,
stodt TYPE bkpf-stodt, " HEAD
END OF ty_head.
DATA: it_head TYPE TABLE OF ty_head,
wa_head TYPE ty_head.
**LINE ITEM
DATA: BEGIN OF ty_line,
srno TYPE i,
newbs TYPE rf05a-newbs,
newko TYPE rf05a-newko,
wrbtr TYPE bseg-wrbtr,
mwskz TYPE bseg-mwskz,
xmwst TYPE bkpf-xmwst,
bupla TYPE bseg-bupla,
zuonr TYPE bseg-zuonr,
sgtxt TYPE bseg-sgtxt,
gsber TYPE cobl-gsber,
kostl TYPE cobl-kostl,
aufnr TYPE cobl-aufnr,
prctr TYPE cobl-prctr,
segment TYPE fb_segment,
kdauf TYPE kdauf,
kdpos TYPE kdpos,
werks TYPE bseg-werks,
END OF ty_line.
DATA: it_line TYPE TABLE OF ty_data,
w_line TYPE ty_data.
DATA : it_bdcdata TYPE STANDARD TABLE OF bdcdata,
wa_bdcdata TYPE bdcdata.
DATA: it_raw TYPE truxs_t_text_data.
* DATA: V_FILE LIKE RLGRAP-FILENAME.
*&---------------------------------------------------------------------*
*& Include ZFBS1_01_SEL
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-100.
PARAMETERS P_FILE TYPE IBIPPARMS-PATH.
SELECTION-SCREEN END OF BLOCK B1 .
*&---------------------------------------------------------------------*
*& Include ZFBS1_01_SUB
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form F4_FILE_NAME
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM f4_file_name .
* DATA: V_FILE LIKE DYNPREAD-FIELDNAME.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
* DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = 'V_FILE'
IMPORTING
FILE_NAME = P_FILE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FILE_UPLOAD
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM file_upload .
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR = 'X'
I_LINE_HEADER ='X'
i_tab_raw_data = IT_RAW
i_filename = P_FILE
TABLES
i_tab_converted_data = IT_DATA
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form HEAD_LINE_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM head_line_data .
LOOP AT IT_DATA INTO WA_DATA .
* AT NEW SRNO.
WA_HEAD-SRNO = WA_DATA-SRNO.
WA_HEAD-BLDAT = WA_DATA-BLDAT.
WA_HEAD-BLART = WA_DATA-BLART.
WA_HEAD-BUKRS = WA_DATA-BUKRS.
WA_HEAD-BUDAT = WA_DATA-BUDAT.
WA_HEAD-WAERS = WA_DATA-WAERS.
WA_HEAD-XBLNR = WA_DATA-XBLNR.
WA_HEAD-BKTXT = WA_DATA-BKTXT.
WA_HEAD-STGRD = WA_DATA-STGRD.
WA_HEAD-STODT = WA_DATA-STODT.
*APPEND WA_HEAD TO IT_HEAD.
COLLECT WA_HEAD INTO IT_HEAD.
*ENDAT.
W_LINE-SRNO = WA_DATA-SRNO.
W_LINE-NEWBS = WA_DATA-NEWBS.
W_LINE-NEWKO = WA_DATA-NEWKO.
W_LINE-WRBTR = WA_DATA-WRBTR.
W_LINE-MWSKZ = WA_DATA-MWSKZ.
W_LINE-XMWST = WA_DATA-XMWST.
W_LINE-BUPLA = WA_DATA-BUPLA.
W_LINE-ZUONR = WA_DATA-ZUONR.
W_LINE-SGTXT = WA_DATA-SGTXT.
W_LINE-GSBER = WA_DATA-GSBER.
W_LINE-KOSTL = WA_DATA-KOSTL.
W_LINE-AUFNR = WA_DATA-AUFNR.
W_LINE-PRCTR = WA_DATA-PRCTR.
W_LINE-SEGMENT = WA_DATA-SEGMENT.
W_LINE-KDAUF = WA_DATA-KDAUF.
W_LINE-KDPOS = WA_DATA-KDPOS.
W_LINE-WERKS = WA_DATA-WERKS.
APPEND W_LINE TO IT_LINE .
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form RUN_BDC
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM run_bdc .
*perform open_group.
LOOP AT IT_HEAD INTO WA_HEAD.
REFRESH IT_BDCDATA.
* WA_DATA-SRNO = SRNO .
perform bdc_dynpro using 'SAPMF05A' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RF05A-NEWKO'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
CALL FUNCTION 'CONVERT_DATE_FORMAT'
EXPORTING
I_DATE = WA_HEAD-BLDAT
IMPORTING
E_CALC_DATE = WA_HEAD-BLDAT
.
perform bdc_field using 'BKPF-BLDAT'wa_head-bldat.
* '09.02.2023'.
perform bdc_field using 'BKPF-BLART'WA_HEAD-BLART.
* 'SA'.
perform bdc_field using 'BKPF-BUKRS'WA_HEAD-BUKRS.
* '1000'.
CALL FUNCTION 'CONVERT_DATE_FORMAT'
EXPORTING
I_DATE = WA_HEAD-BUDAT
IMPORTING
E_CALC_DATE = WA_HEAD-BUDAT
.
perform bdc_field using 'BKPF-BUDAT'WA_HEAD-BUDAT.
* '09.02.2023'.
perform bdc_field using 'BKPF-WAERS'WA_HEAD-WAERS.
* 'INR'.
perform bdc_field using 'BKPF-XBLNR' WA_HEAD-XBLNR.
* 'Reference-001'.
perform bdc_field using 'BKPF-BKTXT' WA_HEAD-BKTXT.
* 'header Tesxt-001'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = WA_HEAD-STGRD
IMPORTING
OUTPUT = WA_HEAD-STGRD
.
perform bdc_field using 'BKPF-STGRD' WA_HEAD-STGRD.
* '05'.
CALL FUNCTION 'CONVERT_DATE_FORMAT'
EXPORTING
I_DATE = WA_HEAD-STODT
IMPORTING
E_CALC_DATE = WA_HEAD-STODT
.
perform bdc_field using 'BKPF-STODT'WA_HEAD-STODT.
* '01.03.2023'.
perform bdc_field using 'FS006-DOCID' '*'.
PERFORM ITEM_DATA USING wa_head-srno.
CALL TRANSACTION 'FBS1' USING IT_BDCDATA MODE 'A' UPDATE 'A'.
ENDLOOP.
IF sy-subrc EQ 0.
MESSAGE 'SESSION UPDATED SUCESSFUL' TYPE 'I' .
ENDIF.
ENDFORM.
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR WA_BDCDATA.
WA_BDCDATA-PROGRAM = PROGRAM.
WA_BDCDATA-DYNPRO = DYNPRO.
WA_BDCDATA-DYNBEGIN = 'X'.
APPEND WA_BDCDATA TO IT_BDCDATA.
ENDFORM.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> SPACE. "NODATA.
CLEAR WA_BDCDATA.
WA_BDCDATA-FNAM = FNAM.
WA_BDCDATA-FVAL = FVAL.
APPEND WA_BDCDATA TO IT_BDCDATA.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form ITEM_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM item_data USING uv_srno .
LOOP AT IT_LINE INTO W_LINE WHERE SRNO = uv_SRNO .
perform bdc_field using 'RF05A-NEWBS'W_LINE-NEWBS.
* '40'.
perform bdc_field using 'RF05A-NEWKO'W_LINE-NEWKO.
* '43300000'.
perform bdc_dynpro using 'SAPMF05A' '0300'.
perform bdc_field using 'BDC_CURSOR'
'BSEG-SGTXT'.
perform bdc_field using 'BDC_OKCODE'
'=ZK'.
DATA: V_CURR TYPE STRING.
V_CURR = W_LINE-WRBTR.
SHIFT V_CURR LEFT DELETING LEADING SPACE.
*CONDENSE WRBTR.
perform bdc_field using 'BSEG-WRBTR'V_CURR. " WA_DATA-WRBTR.
* '5100'.
perform bdc_field using 'BSEG-MWSKZ'W_LINE-MWSKZ.
* 'V0'.
perform bdc_field using 'BKPF-XMWST'W_LINE-XMWST.
* 'X'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = W_LINE-BUPLA
IMPORTING
OUTPUT = W_LINE-BUPLA
.
perform bdc_field using 'BSEG-BUPLA'W_LINE-BUPLA.
* '0300'.
perform bdc_field using 'BSEG-ZUONR'W_LINE-ZUONR.
* 'Assignment 1'.
perform bdc_field using 'BSEG-SGTXT'W_LINE-SGTXT.
* 'Line text1'
.
perform bdc_field using 'DKACB-FMORE'
'X'.
perform bdc_dynpro using 'SAPLKACB' '0002'.
perform bdc_field using 'BDC_CURSOR'
'COBL-WERKS'.
perform bdc_field using 'BDC_OKCODE'
'=ENTE'.
perform bdc_field using 'COBL-GSBER'W_LINE-GSBER.
* '2400'.
perform bdc_field using 'COBL-KOSTL'W_LINE-KOSTL.
* ''.
perform bdc_field using 'COBL-AUFNR'W_LINE-AUFNR.
* ''.
perform bdc_field using 'COBL-PRCTR'W_LINE-PRCTR.
* '1003'.
perform bdc_field using 'COBL-SEGMENT'W_LINE-SEGMENT.
* '1000'.
perform bdc_field using 'COBL-KDAUF'W_LINE-KDAUF.
* '60000020'.
perform bdc_field using 'COBL-KDPOS'W_LINE-KDPOS.
* '10'.
perform bdc_field using 'COBL-WERKS'W_LINE-WERKS.
* '1003'.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
perform bdc_dynpro using 'SAPMF05A' '0330'.
perform bdc_field using 'BDC_CURSOR'
'RF05A-NEWKO'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
*perform bdc_field using 'RF05A-NEWBS',
* '50'.
*perform bdc_field using 'RF05A-NEWKO'
* '44500000'.
perform bdc_dynpro using 'SAPMF05A' '0300'.
perform bdc_field using 'BDC_CURSOR'
'BSEG-SGTXT'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
*perform bdc_field using 'BSEG-WRBTR'
* '5100'.
*perform bdc_field using 'BSEG-MWSKZ'
* 'V0'.
*perform bdc_field using 'BSEG-BUPLA'
* ''.
*perform bdc_field using 'BSEG-ZUONR'
* 'Assignment2'.
*perform bdc_field using 'BSEG-SGTXT'
* 'Line text 2'.
perform bdc_field using 'DKACB-FMORE'
'X'.
perform bdc_dynpro using 'SAPLKACB' '0002'.
perform bdc_field using 'BDC_CURSOR'
'COBL-WERKS'.
perform bdc_field using 'BDC_OKCODE'
'=ENTE'.
*perform bdc_field using 'COBL-KOSTL'
* 'FINHO00001'.
perform bdc_dynpro using 'SAPMF05A' '0300'.
perform bdc_field using 'BDC_CURSOR'
'BSEG-WRBTR'.
perform bdc_field using 'BDC_OKCODE'
'=BS'.
*perform bdc_field using 'BSEG-WRBTR'
* '5,100.00'.
*perform bdc_field using 'BSEG-MWSKZ'
* 'V0'.
*perform bdc_field using 'BSEG-ZUONR'
* 'Assignment2'.
*perform bdc_field using 'BSEG-SGTXT'
* 'Line text 2'.
perform bdc_field using 'DKACB-FMORE'
'X'.
perform bdc_dynpro using 'SAPLKACB' '0002'.
perform bdc_field using 'BDC_CURSOR'
'COBL-GSBER'.
perform bdc_field using 'BDC_OKCODE'
'=ENTE'.
*perform bdc_field using 'COBL-GSBER'
* '2400'.
*perform bdc_field using 'COBL-KOSTL'
* 'FINHO00001'.
*perform bdc_field using 'COBL-PRCTR'
* '1003'.
*perform bdc_field using 'COBL-SEGMENT'
* '1000'.
perform bdc_dynpro using 'SAPMF05A' '0700'.
perform bdc_field using 'BDC_CURSOR'
'RF05A-NEWBS'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
*perform bdc_field using 'BKPF-XBLNR'
* 'REFERENCE-001'.
*perform bdc_field using 'BKPF-BKTXT'
* 'header Tesxt-001'.
*perform bdc_field using 'BKPF-VATDATE'
* '09.02.2023'.
*perform bdc_transaction using 'FBS1'.
ENDLOOP.
ENDFORM.
OUTPUT: