REPORT zupload_debitor.
DATA : BEGIN OF debitor,
id TYPE num5,
bukrs LIKE rf02d-bukrs,
ktokd LIKE rf02d-ktokd,
name1 LIKE kna1-name1,
sortl LIKE kna1-sortl,
stras LIKE kna1-stras,
ort01 LIKE kna1-ort01,
pstlz LIKE kna1-pstlz,
land1 LIKE kna1-land1,
spras TYPE char2,
telf1 LIKE kna1-telf1,
stcd1 LIKE kna1-stcd1,
stcd2 LIKE kna1-stcd2,
stkzn LIKE kna1-stkzn,
stkzu LIKE kna1-stkzu,
stceg LIKE kna1-stceg,
banks LIKE knbk-banks,
bankl LIKE knbk-bankl,
bankn LIKE knbk-bankn,
akont LIKE knb1-akont,
zuawa LIKE knb1-zuawa,
fdgrv LIKE knb1-fdgrv,
zterm LIKE knb1-zterm,
xzver LIKE knb1-xzver,
zhals LIKE knb1-zahls,
zwels LIKE knb1-zwels,
hbkid LIKE knb1-hbkid,
zgrup LIKE knb1-zgrup,
END OF debitor.
DATA: BEGIN OF zbanka,
id TYPE num5,
banks LIKE knbk-banks,
bankl LIKE knbk-bankl,
bankn LIKE knbk-bankn,
END OF zbanka.
* Declararea tabelei bcdata
DATA: BEGIN OF bdcdata OCCURS 100.
INCLUDE STRUCTURE bdcdata.
DATA: END OF bdcdata.
DATA: BEGIN OF messtab OCCURS 10.
INCLUDE STRUCTURE bdcmsgcoll.
DATA: END OF messtab.
* Declaram o tablita interna cu aceasi structura ca debitor.
DATA: it_debit LIKE debitor OCCURS 0 WITH HEADER LINE.
DATA: it_zbank LIKE zbanka OCCURS 0 WITH HEADER LINE.
PARAMETERS: filenam TYPE rlgrap-filename OBLIGATORY.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR filenam.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
mask = '*.xls , *.xlsx'
CHANGING
file_name = filenam.
IF sy-subrc <> 0.
ENDIF.
AT SELECTION-SCREEN.
CASE sy-ucomm.
WHEN 'ONLI'.
CALL FUNCTION 'ZPP_EXCEL_UPLOAD_TO_INTTAB' " <---
EXPORTING
p_filename = filenam
start_row = 3
TABLES
p_tab = it_debit.
** ---- bloc programmi
sort it_debit ascending by id. "<-- sortarea tablitei it_debit dupa ID
PERFORM dobavlenie. "<--- dobavlenie bankov v vnutreniuiu tablitu it_zbank
DATA: a TYPE num5, wa TYPE char14,wu TYPE char14, wi TYPE char14, b TYPE num5,i TYPE num,z TYPE num, y TYPE num,
contr TYPE i,
contr1 TYPE i.
z = 1.y = 1.
LOOP AT it_debit.
a = it_debit-id.
IF b <> it_debit-id.
contr = 0.
ENDIF.
b = it_debit-id.
IF a = it_debit-id AND contr = 0.
contr1 = 0.
LOOP AT it_debit.
IF a = it_debit-id AND contr1 = 0.
CLEAR bdcdata. REFRESH bdcdata.
CLEAR i.
PERFORM : bdc_dynpro USING 'SAPMF02D' '0100',
bdc_field USING 'BDC_CURSOR' 'RF02D-KTOKD',
bdc_field USING 'BDC_OKCODE' '/00',
bdc_field USING 'RF02D-BUKRS' it_debit-bukrs,
bdc_field USING 'RF02D-KTOKD' it_debit-ktokd.
PERFORM : bdc_dynpro USING 'SAPMF02D' '0110',
bdc_field USING 'BDC_CURSOR' 'KNA1-TELF1',
bdc_field USING 'BDC_OKCODE' '/00',
bdc_field USING 'KNA1-NAME1' it_debit-name1,
bdc_field USING 'KNA1-SORTL' it_debit-sortl,
bdc_field USING 'KNA1-STRAS' it_debit-stras,
bdc_field USING 'KNA1-ORT01' it_debit-ort01,
bdc_field USING 'KNA1-PSTLZ' it_debit-pstlz,
bdc_field USING 'KNA1-LAND1' it_debit-land1,
bdc_field USING 'KNA1-SPRAS' it_debit-spras,
bdc_field USING 'KNA1-TELF1' it_debit-telf1.
PERFORM : bdc_dynpro USING 'SAPMF02D' '0120',
bdc_field USING 'BDC_CURSOR' 'KNA1-STCEG',
bdc_field USING 'BDC_OKCODE' '/00',
bdc_field USING 'KNA1-STCD1' it_debit-stcd1,
bdc_field USING 'KNA1-STCD2' it_debit-stcd2,
bdc_field USING 'KNA1-STKZN' it_debit-stkzn,
bdc_field USING 'KNA1-STKZU' it_debit-stkzu,
bdc_field USING 'KNA1-STCEG' it_debit-stceg.
PERFORM : bdc_dynpro USING 'SAPMF02D' '0125',
bdc_field USING 'BDC_CURSOR' 'KNA1-NIELS',
bdc_field USING 'BDC_OKCODE' '/00'.
clear: wa , i.
ADD 1 TO i.
PERFORM : bdc_dynpro USING 'SAPMF02D' '0130'.
CONCATENATE 'KNBK-BANKS(' i ')' INTO wa.
perform bdc_field USING 'BDC_OKCODE' '=ENTR'.
perform bdc_field USING 'BDC_CURSOR' wa.
clear i.
LOOP AT it_zbank. "<--- Dobavlenie Bankov v bdcData
IF it_zbank-id = a.
CLEAR: wa.
ADD 1 TO i.
CONCATENATE 'KNBK-BANKS(' i ')' INTO wa.
PERFORM bdc_field USING wa it_zbank-banks.
CONCATENATE 'KNBK-BANKL(' i ')' INTO wa.
PERFORM bdc_field USING wa it_zbank-bankl.
CONCATENATE 'KNBK-BANKN(' i ')' INTO wa.
PERFORM bdc_field USING wa it_zbank-bankn.
ENDIF.
ENDLOOP.
loop at it_zbank.
IF it_zbank-id = a.
ADD 1 TO i.
ENDIF.
ENDLOOP.
PERFORM : bdc_dynpro USING 'SAPMF02D' '0130'.
CONCATENATE 'KNBK-BANKN(' i ')' INTO wa.
perform bdc_field USING 'BDC_OKCODE' '=ENTR'. clear i.
PERFORM : bdc_dynpro USING 'SAPMF02D' '0340',
bdc_field USING 'BDC_CURSOR' 'KNVA-ABLAD(01)',
bdc_field USING 'BDC_OKCODE' '=ENTR'.
PERFORM : bdc_dynpro USING 'SAPMF02D' '0370',
bdc_field USING 'BDC_CURSOR' 'KNEX-LNDEX(01)'.
PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'.
PERFORM : bdc_dynpro USING 'SAPMF02D' '0360',
bdc_field USING 'BDC_CURSOR' 'KNVK-NAMEV(01)',
bdc_field USING 'BDC_OKCODE' '=ENTR'.
PERFORM : bdc_dynpro USING 'SAPMF02D' '0210',
bdc_field USING 'BDC_CURSOR' 'KNB1-FDGRV',
bdc_field USING 'BDC_OKCODE' '/00',
bdc_field USING 'KNB1-AKONT' it_debit-akont,
bdc_field USING 'KNB1-ZUAWA' it_debit-zuawa,
bdc_field USING 'KNB1-FDGRV' it_debit-fdgrv.
PERFORM : bdc_dynpro USING 'SAPMF02D' '0215',
bdc_field USING 'BDC_CURSOR' 'KNB1-ZGRUP',
bdc_field USING 'BDC_OKCODE' '/00',
bdc_field USING 'KNB1-ZTERM' it_debit-zterm,
bdc_field USING 'KNB1-XZVER' it_debit-xzver,
bdc_field USING 'KNB1-ZWELS' it_debit-zwels,
bdc_field USING 'KNB1-ZAHLS' it_debit-zhals,
bdc_field USING 'KNB1-HBKID' it_debit-hbkid,
bdc_field USING 'KNB1-ZGRUP' it_debit-zgrup.
PERFORM : bdc_dynpro USING 'SAPMF02D' '0220',
bdc_field USING 'BDC_CURSOR' 'KNB5-MAHNA',
bdc_field USING 'BDC_OKCODE' '/00'.
PERFORM : bdc_dynpro USING 'SAPMF02D' '0230',
bdc_field USING 'BDC_CURSOR' 'KNB1-VRSNR',
bdc_field USING 'BDC_OKCODE' '=ENTR'.
contr1 = 1.
ENDIF.
ENDLOOP.
contr = 1.
CALL TRANSACTION 'XD01' USING bdcdata MODE 'N' UPDATE 'S' MESSAGES INTO messtab.
LOOP AT messtab.
WRITE: / messtab-tcode,
messtab-dyname,
messtab-dynumb,
messtab-msgtyp,
messtab-msgspra,
messtab-msgid,
messtab-msgnr.
ENDLOOP.
ENDIF.
ENDLOOP.
ENDCASE.
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
bdcdata-program = program. " Имя программы
bdcdata-dynpro = dynpro. " Номер экрана
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
ENDFORM. "bdc_dynpro
FORM bdc_field USING fnam fval.
CLEAR bdcdata.
bdcdata-fnam = fnam. " Имя поля
bdcdata-fval = fval. " Значание поля
APPEND bdcdata.
ENDFORM. "bdc_field
FORM dobavlenie. "< --- dobavlenie bankov v vnutreniuiu tablitu it_zbank
DATA: i TYPE i,
b TYPE i.
LOOP AT it_debit.
ADD 1 TO i.
MOVE it_debit-id TO it_zbank-id.
MOVE it_debit-banks TO it_zbank-banks.
MOVE it_debit-bankl TO it_zbank-bankl.
MOVE it_debit-bankn TO it_zbank-bankn.
b = i + 1.
INSERT it_zbank INDEX b.
APPEND it_zbank.
ENDLOOP.
ENDFORM. "dobavlenie
All times are GMT + 4 Hours Goto page Previous1, 2
Page 2 of 2
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.