Programma per Richiamare un RFC FM in parallelo e che elabora un TOT di pacchetti
************************************************************************
* Descrizione: Programma Azzeramento chiavi ammortamenti dei cespiti*
* relativi alla Flotta 2015 di *
************************************************************************
REPORT zf15_aa_azzera_chiavi.
************************************************************************
* Programma: ZF15_AA_AZZERA_CHIAVI_TOP *
* Descrizione: Programma Azzeramento chiavi ammortamenti dei cespiti*
* relativi alla Flotta 2015 di *
************************************************************************
**---------- Dichiarazione Dati Globali ------------**
TYPE-POOLS: slis, icon.
TYPES : BEGIN OF type_cespite,
anln1 LIKE anla-anln1,
anln2 TYPE anla-anln2,
anlkl TYPE anla-anlkl,
afabe TYPE anlb-afabe,
afasl TYPE anlb-afasl,
END OF type_cespite.
TYPES : BEGIN OF type_errori,
id type c LENGTH 5,
cespite TYPE anla-anln1,
secondario type anla-anln2,
descrizione(255) TYPE c,
END OF type_errori.
DATA: gs_cespite TYPE type_cespite,
gt_anla TYPE STANDARD TABLE OF anla,
gt_anlbza type STANDARD TABLE OF anlbza,
gs_anla type anla,
gt_elaborazione TYPE STANDARD TABLE OF ZST_ERRORI,
gt_log_finale TYPE STANDARD TABLE OF ZST_ERRORI,
gwa_elaborazione TYPE ZST_ERRORI,
gt_afabe TYPE STANDARD TABLE OF anlb,
gv_count TYPE i,
gt_anla_temp TYPE STANDARD TABLE OF anla.
**---------- Dichiarazione Costanti ------------**
CONSTANTS: gc_x(1) TYPE c VALUE 'X',
gc_err(3) type c VALUE 'ERR',
gc_ok(3) type c VALUE 'OK'.
*======================================================================*
* DATA ALV *
*======================================================================*
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv,
alv_layout TYPE slis_layout_alv.
*************************************************************************
* Programma: ZF15_AA_AZZERA_CHIAVI_SEL *
* Descrizione: Programma Azzeramento chiavi ammortamenti dei cespiti*
* relativi alla Flotta 2015 di *
************************************************************************
**---------- Dichiarazione Parametri di Selezione ------------**
SELECTION-SCREEN BEGIN OF BLOCK 2 WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP.
PARAMETERS p_bukrs type bukrs OBLIGATORY.
SELECT-OPTIONS: s_anln1 FOR gs_cespite-anln1,
s_anln2 FOR gs_cespite-anln2,
s_anlkl FOR gs_cespite-anlkl OBLIGATORY,
s_afabe FOR gs_cespite-afabe.
PARAMETERS: p_afasl type afasl OBLIGATORY,
p_nr_job type i OBLIGATORY.
SELECTION-SCREEN END OF BLOCK 2.
************************************************************************
* Programma: ZF15_AA_AZZERA_CHIAVI_FUN *
* Descrizione: Programma Azzeramento chiavi ammortamenti dei cespiti*
* relativi alla Flotta 2015 di *
************************************************************************
*&---------------------------------------------------------------------*
*& Form ESTRAI_DATI
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM estrai_dati .
DATA: gs_afabe TYPE anlb.
LOOP AT s_afabe.
CLEAR: gs_afabe.
gs_afabe-afabe = s_afabe-low.
APPEND gs_afabe TO gt_afabe.
ENDLOOP.
* Estraggo i Cespiti che rientrano nei parametri di selezione
SELECT * FROM anla
INTO TABLE gt_anla
WHERE bukrs = p_bukrs
AND anln1 IN s_anln1
AND anln2 IN s_anln2
AND anlkl IN s_anlkl.
IF NOT gt_anla[] IS INITIAL.
SELECT * FROM anlbza
INTO TABLE gt_anlbza
FOR ALL ENTRIES IN gt_anla
WHERE bukrs = gt_anla-bukrs
AND anln1 = gt_anla-anln1
AND anln2 = gt_anla-anln2
AND afabe IN s_afabe
AND bdatu = '99991231'.
ENDIF.
ENDFORM. " ESTRAI_DATI
*&---------------------------------------------------------------------*
*& Form CLEAR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM clear.
CLEAR: gt_anla, gt_anlbza,
gt_elaborazione, gt_afabe,
gt_log_finale.
REFRESH: gt_anla, gt_anlbza,
gt_elaborazione, gt_afabe,
gt_log_finale.
ENDFORM. " CLEAR
*&---------------------------------------------------------------------*
*& Form FREE_DATI
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM free_dati .
FREE: gt_anla, gt_anlbza,
gt_elaborazione, gt_afabe,
gt_log_finale.
ENDFORM. " FREE_DATI
*&---------------------------------------------------------------------*
*& Form ELABORA_CESPITI
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM elabora_cespiti .
DATA: lv_nr_pacc TYPE i,
dimens_pacch TYPE i,
nr_rec_gt_anla TYPE i,
pa_pacc TYPE i,
pa_resto TYPE i,
lv_ind_iniz TYPE i,
lv_ind_fin TYPE i,
lv_name TYPE c LENGTH 20,
lv_nr_pacc_char TYPE c LENGTH 7.
FIELD-SYMBOLS:
<lfs_anla> TYPE anla.
FIELD-SYMBOLS:
<lfs_log> TYPE zst_errori.
dimens_pacch = 5000. "5000.
DESCRIBE TABLE gt_anla LINES nr_rec_gt_anla.
IF nr_rec_gt_anla > dimens_pacch.
pa_pacc = nr_rec_gt_anla / dimens_pacch.
pa_resto = nr_rec_gt_anla MOD dimens_pacch.
IF pa_resto > 0.
pa_pacc = pa_pacc + 1.
ENDIF.
ELSE.
pa_pacc = 1.
ENDIF.
lv_nr_pacc = 1.
gv_count = 0.
lv_ind_iniz = 1.
DO pa_pacc TIMES.
* Elaboro al massimo 10 mini job alla volta
IF ( lv_nr_pacc - gv_count ) = p_nr_job.
WAIT UNTIL gv_count = lv_nr_pacc.
COMMIT WORK AND WAIT.
ENDIF.
lv_ind_fin = dimens_pacch * lv_nr_pacc.
REFRESH: gt_anla_temp.
CLEAR: gt_anla_temp.
UNASSIGN <lfs_anla>.
LOOP AT gt_anla ASSIGNING <lfs_anla> FROM lv_ind_iniz TO lv_ind_fin .
APPEND <lfs_anla> TO gt_anla_temp.
ENDLOOP.
lv_nr_pacc_char = lv_nr_pacc.
CONCATENATE 'AZZERA_CHIAVI' lv_nr_pacc_char INTO lv_name.
CONDENSE lv_name NO-GAPS.
* Chiamare il FM che è dichiarato di tipo
* RFC.
CALL FUNCTION 'ZCHANGE_SINGLE_ASSET'
STARTING NEW TASK lv_name
DESTINATION IN GROUP DEFAULT
PERFORMING form_elab ON END OF TASK
EXPORTING
pi_afasl = p_afasl
TABLES
ti_anla = gt_anla_temp
ti_anlbza = gt_anlbza
ti_afabe = gt_afabe
ti_errori = gt_elaborazione
EXCEPTIONS
system_failure = 1
communication_failure = 2
OTHERS = 3.
lv_ind_iniz = lv_ind_iniz + dimens_pacch.
ADD 1 TO lv_nr_pacc.
FREE: gt_anla_temp.
ENDDO.
WAIT UNTIL gv_count = pa_pacc.
IF NOT gt_log_finale[] IS INITIAL.
SORT gt_log_finale BY id cespite secondario.
ULINE AT (300).
WRITE : / sy-vline, "Vertical Line
2 'ESITO',
10 'CESPITE',
25 'SECONDARIO',
40 'DESCRIZIONE',
300 sy-vline.
ULINE AT (300).
UNASSIGN <lfs_log>.
LOOP AT gt_log_finale ASSIGNING <lfs_log>.
WRITE : / sy-vline, "Vertical Line
2 <lfs_log>-id,
10 <lfs_log>-cespite,
25 <lfs_log>-secondario,
40 <lfs_log>-descrizione,
300 sy-vline.
ENDLOOP.
ULINE AT (300).
ENDIF.
ENDFORM. " ELABORA_CESPITI
*&---------------------------------------------------------------------*
*& Form FORM_ELAB
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM form_elab USING name.
RECEIVE RESULTS FROM FUNCTION 'ZCHANGE_SINGLE_ASSET'
TABLES
ti_errori = gt_elaborazione.
EXCEPTIONS
system_failure = 1
communication_failure = 2
OTHERS = 3.
IF NOT gt_elaborazione[] IS INITIAL.
APPEND LINES OF gt_elaborazione TO gt_log_finale.
ENDIF.
CALL FUNCTION 'DEQUEUE_ALL'.
gv_count = gv_count + 1.
ENDFORM. " FORM_ELAB
**---------- INITIALIZATION ------------**
INITIALIZATION.
p_bukrs = 'SOCIETA'.
p_nr_job = 10.
* Valorizzazione Classe
* con i seguenti valori di default
* da '24100000' a '24399999'
s_anlkl-low = '24100000'.
s_anlkl-high = '24399999'.
s_anlkl-option = 'BT'.
s_anlkl-sign = 'I'.
APPEND s_anlkl.
CLEAR s_anlkl.
* Valorizzazione Area di Valorizzazione
* con i seguenti valori di default
* '01', '02' e '20'
s_afabe-low = '01'.
s_afabe-option = 'EQ'.
s_afabe-sign = 'I'.
APPEND s_afabe.
CLEAR s_afabe.
s_afabe-low = '02'.
s_afabe-option = 'EQ'.
s_afabe-sign = 'I'.
APPEND s_afabe.
CLEAR s_afabe.
s_afabe-low = '20'.
s_afabe-option = 'EQ'.
s_afabe-sign = 'I'.
APPEND s_afabe.
CLEAR s_afabe.
* Valorizzazione Chiave contabile
* con il seguente valore di default
* '0000'
p_afasl = '0000'.
**---------- START SELECTION SCREEN ------------**
START-OF-SELECTION.
PERFORM clear.
PERFORM estrai_dati.
IF NOT gt_anla[] IS INITIAL.
SORT gt_anla BY anln1 anln2.
PERFORM elabora_cespiti.
ELSE.
MESSAGE s001(zf15_aa_azz_chiavi).
ENDIF.
PERFORM free_dati.
END-OF-SELECTION.
*********************************************
*********************************************
*********************************************
QUESTA FUNZIONE DEVE ESSERE TI TIPO RFC
FUNCTION zchange_single_asset.
*"----------------------------------------------------------------------
*"*"Interfaccia locale:
*" IMPORTING
*" VALUE(PI_AFASL) TYPE AFASL
*" TABLES
*" TI_ANLA STRUCTURE ANLA
*" TI_ANLBZA STRUCTURE ANLBZA
*" TI_AFABE STRUCTURE ANLB
*" TI_ERRORI STRUCTURE ZST_ERRORI
*" EXCEPTIONS
*" SYSTEM_FAILURE
*" COMMUNICATION_FAILURE
*" OTHERS
*"----------------------------------------------------------------------
DATA: lv_anla TYPE anla,
lv_descr(255) TYPE c.
DATA: ls_return TYPE bapiret2,
lt_deprnareas TYPE STANDARD TABLE OF bapi1022_dep_areas,
lt_deprareasx TYPE STANDARD TABLE OF bapi1022_dep_areasx,
ls_deprnareas TYPE bapi1022_dep_areas,
ls_deprareasx TYPE bapi1022_dep_areasx,
ls_afabe TYPE anlb,
ls_errori TYPE zst_errori.
FIELD-SYMBOLS:
<lfs_anla> TYPE anla,
<lfs_anlbza> TYPE anlbza.
**---------- Dichiarazione Costanti ------------**
CONSTANTS: gc_x(1) TYPE c VALUE 'X',
gc_err(3) TYPE c VALUE 'ERR',
gc_ok(3) TYPE c VALUE 'OK'.
UNASSIGN <lfs_anla>.
CLEAR: ls_return,
lt_deprnareas,
lt_deprareasx,
ls_afabe.
CLEAR: ti_errori.
REFRESH:ti_errori.
LOOP AT ti_anla ASSIGNING <lfs_anla>.
CLEAR: ls_errori.
REFRESH: lt_deprnareas, lt_deprareasx.
lv_anla = <lfs_anla>.
LOOP AT ti_afabe INTO ls_afabe.
CLEAR: ls_deprnareas, ls_deprareasx.
UNASSIGN <lfs_anlbza>.
READ TABLE ti_anlbza ASSIGNING <lfs_anlbza>
WITH KEY bukrs = lv_anla-bukrs
anln1 = lv_anla-anln1
anln2 = lv_anla-anln2
afabe = ls_afabe-afabe
bdatu = '99991231'.
IF sy-subrc = 0.
ls_deprnareas-dep_key = pi_afasl.
ls_deprnareas-from_date = <lfs_anlbza>-adatu.
ls_deprnareas-to_date = <lfs_anlbza>-bdatu.
MOVE ls_afabe-afabe TO: ls_deprnareas-area,
ls_deprareasx-area.
MOVE gc_x TO:
ls_deprareasx-dep_key,
ls_deprareasx-from_date,
ls_deprareasx-to_date.
APPEND ls_deprnareas TO lt_deprnareas.
APPEND ls_deprareasx TO lt_deprareasx.
ELSE.
ls_deprnareas-dep_key = pi_afasl.
MOVE ls_afabe-afabe TO: ls_deprnareas-area,
ls_deprareasx-area.
MOVE gc_x TO:
ls_deprareasx-dep_key.
APPEND ls_deprnareas TO lt_deprnareas.
APPEND ls_deprareasx TO lt_deprareasx.
ENDIF.
ENDLOOP.
IF NOT lt_deprnareas[] IS INITIAL.
CALL FUNCTION 'BAPI_FIXEDASSET_CHANGE'
EXPORTING
companycode = lv_anla-bukrs
asset = lv_anla-anln1
subnumber = lv_anla-anln2
IMPORTING
return = ls_return
TABLES
depreciationareas = lt_deprnareas
depreciationareasx = lt_deprareasx.
MOVE ls_return-message TO lv_descr.
IF ls_return-type = 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ls_errori-id = gc_ok.
ls_errori-cespite = lv_anla-anln1.
ls_errori-secondario = lv_anla-anln2.
ls_errori-descrizione = lv_descr.
APPEND ls_errori TO ti_errori.
ELSE.
ls_errori-id = gc_err.
ls_errori-cespite = lv_anla-anln1.
ls_errori-secondario = lv_anla-anln2.
ls_errori-descrizione = lv_descr.
APPEND ls_errori TO ti_errori.
ENDIF.
ELSE.
ls_errori-id = gc_err.
ls_errori-cespite = lv_anla-anln1.
ls_errori-secondario = lv_anla-anln2.
ls_errori-descrizione = text-006.
APPEND ls_errori TO ti_errori.
ENDIF.
ENDLOOP.
COMMIT WORK AND WAIT.
FREE: lt_deprnareas, lt_deprareasx.
ENDFUNCTION.
EBOOK: le mie guide sono visualizzabili cliccando sui link:
1. SAP EWM (Extended Warehouse Management)
3. SAP VIM (Vendor Invoice Management)
1. SAP EWM (Extended Warehouse Management)
3. SAP VIM (Vendor Invoice Management)
SE MI CONTATTATE IN PRIVATO, PAGATE LA META' DEL PREZZO DI AMAZON, E POTETE SCEGLIERE IL FORMATO WORD o PDF.
>>> RECENSIONI DEI LIBRI su Amazon Kindle <<<
Ebook: SAP CDS: https://www.amazon.it/dp/B0B9BD1RN3#customerReviews
Ebook: SAP MM: https://www.amazon.it/dp/B0C3MKD9BR#customerReviews
Ebook: SAP MII: https://www.amazon.it/dp/B0C4392MY9#customerReviews
Ebook: SAP VIM: https://www.amazon.it/dp/B0C6FBK8QN#customerReviews
Ebook: SAP MM: https://www.amazon.it/dp/B0C3MKD9BR#customerReviews
Ebook: SAP MII: https://www.amazon.it/dp/B0C4392MY9#customerReviews
Ebook: SAP VIM: https://www.amazon.it/dp/B0C6FBK8QN#customerReviews
Ebook: SAP EWM: https://www.amazon.it/dp/B0CL6TXP1V#customerReviews
Nessun commento:
Posta un commento