Zfi Procon Usa Form 1

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 17

*&---------------------------------------------------------------------*

*& Include ZFI_PROCON_USA_FORM


*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Form ZF_MATCH_CODE_BLART
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form zf_match_code_blart changing cv_blart type blart.

types: begin of ty_blart,


blart type blart,
ltext type ltext_003t,
end of ty_blart,

begin of ty_match , "esta tabla nos devuelve la ayuda


shlpname type ddshretval-shlpname,
fieldname type ddshretval-fieldname,
recordpos type ddshretval-recordpos,
fieldval type ddshretval-fieldval,
retfield type ddshretval-retfield,
end of ty_match.

data: lt_blart type standard table of ty_blart,


lt_match type standard table of ty_match,
ls_match type ty_match.

select blart ltext


from t003t
into table lt_blart
where spras eq sy-langu and
( blart eq 'AF' or
blart eq 'AP' ).

call function 'F4IF_INT_TABLE_VALUE_REQUEST'


exporting
retfield = 'BLART'
window_title = text-t01 "'Clase de documento'
value_org = 'S'
tables
value_tab = lt_blart
return_tab = lt_match
exceptions
parameter_error = 1
no_values_found = 2
others = 3.

if sy-subrc eq 0.
read table lt_match into ls_match index 1.
move ls_match-fieldval to cv_blart.
endif.

endform. " ZF_MATCH_CODE_BLART


*&---------------------------------------------------------------------*
*& Form ZF_VALID_SCREEN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form zf_valid_screen .

"Si no se indica ningún documento será obligatorio indicar fecha


"contables y la clase o clases de documento.
if so_belnr is initial and
* ( so_budat IS INITIAL OR so_blart IS INITIAL ). "Coment Z13K 17/07/2019
( so_budat is initial or p_budat is initial ). "Insert Z13K 17/07/2019

message text-e01 type 'E' display like 'W'.


endif.

"Chequeo de la sociedad 20/11/2019 Z13K


authority-check object 'F_BKPF_BUK'
id 'BUKRS' field p_bukrs
id 'ACTVT' field '03'.

if sy-subrc ne 0.
message e030(zdimsg) with p_bukrs.
endif.

endform. " ZF_VALID_SCREEN

*&---------------------------------------------------------------------*
*& Form ZF_BUSCAR_DATOS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form zf_buscar_datos.

select bukrs belnr gjahr monat blart budat bktxt waers xblnr "bldat budat
from bkpf
into corresponding fields of table gt_datos "gt_bkpf
where bukrs eq p_bukrs and
gjahr eq p_gjahr and
budat in so_budat and
blart in so_blart and
* blart EQ p_blart AND
belnr in so_belnr.

* SELECT a~bukrs a~belnr a~gjahr a~blart a~bldat a~budat


* b~GSBER b~kostl b~hkont
* from bkpf as a inner join bseg as b on
* a~BUKRS = b~BUKRS and
* a~BELNR = b~BELNR and
* a~GJAHR = b~GJAHR
* INTO TABLE gt_belnr "gt_bkpf
* WHERE a~bukrs EQ p_bukrs AND
* a~gjahr EQ p_gjahr AND
* a~budat IN so_budat AND
* a~blart EQ p_blart AND
* a~belnr IN so_belnr.

endform. " ZF_BUSCAR_DATOS

*&---------------------------------------------------------------------*
*& Form ZF_COMPLETAR_DOC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form zf_completar_doc .

* TYPES: BEGIN OF ty_cuen_soc_aju,


* bukrs TYPE bukrs,
* hkont TYPE hkont,
* bukrs_aju TYPE bukrs,
* hkont_aju TYPE hkont,
* END OF ty_cuen_soc_aju.
*
* TYPES: BEGIN OF ty_obj_imp,
* bukrs TYPE bukrs,
* gsber TYPE gsber,
* kostl TYPE kostl,
* bukrs_aju TYPE bukrs,
* gsber_aju TYPE gsber,
* kostl_aju TYPE kostl,
* END OF ty_obj_imp.

types: begin of ty_clase_doc,


bukrs type bukrs,
blart type blart,
bukrs_aju type bukrs,
blart_aju type blart,
end of ty_clase_doc.

"DATA: "lt_cuen_soc_aju TYPE STANDARD TABLE OF ty_cuen_soc_aju,


"lt_obj_imp TYPE STANDARD TABLE OF ty_obj_imp,
"ls_clase_doc TYPE ty_clase_doc.
* lt_clase_doc TYPE STANDARD TABLE OF ty_clase_doc.

data: ls_list type ty_list.


field-symbols: <lfs_datos> type ty_datos,
<lfs_bseg> type ty_bseg.
"<lfs_list> TYPE ty_list.
sort gt_datos by bukrs belnr gjahr.
loop at gt_datos assigning <lfs_datos>.

clear: <lfs_datos>-bukrs_aju, <lfs_datos>-blart_aju.

perform zf_clase_doc using <lfs_datos>-bukrs


<lfs_datos>-blart
changing <lfs_datos>-bukrs_aju
<lfs_datos>-blart_aju.
* SELECT SINGLE bukrs_aju blart_aju
* "bukrs blart bukrs_aju blart_aju
* FROM zfi_clase_doc
* INTO (<lfs_datos>-bukrs_aju, <lfs_datos>-blart_aju)
** INTO (ls_clase_doc-bukrs, ls_clase_doc-blart, ls_clase_doc-bukrs_aju,
ls_clase_doc-blart_aju)
* WHERE bukrs EQ <lfs_datos>-bukrs AND
* blart EQ <lfs_datos>-blart.

if sy-subrc eq 0.

perform zf_bseg using <lfs_datos>-bukrs


<lfs_datos>-belnr
<lfs_datos>-gjahr
changing <lfs_datos>.
* <lfs_datos>-text.

else. "No se trata porque NO esta en ZFI_CLASE_DOC


"Registro no informado en la tabla: Clases de documento
move: text-t04 to <lfs_datos>-text,
icon_red_light to <lfs_datos>-icon.
move-corresponding <lfs_datos> to ls_list.
append ls_list to gt_list.

endif.
endloop.

*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* IF gt_datos IS NOT INITIAL.
* SELECT bukrs hkont bukrs_aju hkont_aju
* FROM zfi_cuen_soc_aju
* INTO TABLE lt_cuen_soc_aju
* FOR ALL ENTRIES IN gt_belnr
* WHERE bukrs EQ gt_belnr-bukrs AND
* hkont EQ gt_belnr-hkont.
*
* SELECT bukrs gsber kostl bukrs_aju gsber_aju kostl_aju
* FROM zfi_obj_imp_soc
* INTO TABLE lt_obj_imp
* FOR ALL ENTRIES IN gt_belnr
* WHERE bukrs EQ gt_belnr-bukrs AND
* gsber EQ gt_belnr-gsber AND
* kostl EQ gt_belnr-kostl.
*
* SELECT bukrs blart bukrs_aju blart_aju
* FROM zfi_clase_doc
* INTO TABLE lt_clase_doc
* FOR ALL ENTRIES IN gt_datos
* WHERE bukrs EQ gt_datos-bukrs AND
* blart EQ gt_datos-blart.
*
*
* ENDIF.
endform. " ZF_COMPLETAR_DOC
*&---------------------------------------------------------------------*
*& Form ZF_BSEG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_<LFS_DATOS>_BUKRS text
* -->P_<LFS_DATOS>_BELNR text
* -->P_<LFS_DATOS>_GJAHR text
* <--P_<LFS_DATOS>_TEXT text
*----------------------------------------------------------------------*
form zf_bseg using uv_bukrs type bukrs
uv_belnr type belnr_d
uv_gjahr type gjahr
changing ct_datos type ty_datos. "cv_text.

* TYPES: BEGIN OF ty_cuen_soc_aju,


* bukrs TYPE bukrs,
* hkont TYPE hkont,
* bukrs_aju TYPE bukrs,
* hkont_aju TYPE hkont,
* END OF ty_cuen_soc_aju.
*
* TYPES: BEGIN OF ty_obj_imp,
* bukrs TYPE bukrs,
* gsber TYPE gsber,
* kostl TYPE kostl,
* bukrs_aju TYPE bukrs,
* gsber_aju TYPE gsber,
* kostl_aju TYPE kostl,
* END OF ty_obj_imp.

data: ls_list type ty_list.


data: ls_cuen_soc_aju type zfi_cuen_soc_aju.
"ls_obj_imp_soc TYPE zfi_obj_imp_soc.

field-symbols: <lfs_bseg> type ty_bseg,


<lfs_datos> type ty_datos.
"<lfs_list> TYPE ty_list.

types: begin of tyt_cuentas,


hkont type hkont,
end of tyt_cuentas.

data: lt_cuentas type standard table of tyt_cuentas.


* DATA: rg_hkont TYPE RANGE OF hkont.
data: rwa_hkont like line of rg_hkont.
field-symbols: <lf_cuentas> type tyt_cuentas.

* SORT gt_datos BY bukrs belnr gjahr.


"Insert Z13K 17/12/2019
if p_table is not initial.
select hkont
from zfi_cuen_soc_aju
into table lt_cuentas
where bukrs eq uv_bukrs.

move: 'I' to rwa_hkont-sign,


'EQ' to rwa_hkont-option.
loop at lt_cuentas assigning <lf_cuentas>.
move: <lf_cuentas>-hkont to rwa_hkont-low.
append rwa_hkont to rg_hkont.
endloop.
endif.
"Fin Z13K 17/12/2019

select bukrs belnr gjahr buzei gsber kostl hkont


from bseg
into corresponding fields of table gt_bseg
where bukrs eq uv_bukrs and
belnr eq uv_belnr and
gjahr eq uv_gjahr and
hkont in rg_hkont. "Insert Z13K 17/12/2019

* SORT gt_datos BY bukrs belnr gjahr.

loop at gt_bseg assigning <lfs_bseg>.

perform zf_zfi_cuen_soc_aju using <lfs_bseg>-bukrs


<lfs_bseg>-hkont
changing <lfs_bseg>-hkont_aju_b.
* SELECT SINGLE hkont_aju
* FROM zfi_cuen_soc_aju
* INTO <lfs_bseg>-hkont_aju_b
* WHERE bukrs EQ <lfs_bseg>-bukrs AND
* hkont EQ <lfs_bseg>-hkont.

if sy-subrc eq 0.

perform zf_zfi_obj_imp_soc using <lfs_bseg>-bukrs


<lfs_bseg>-gsber
<lfs_bseg>-kostl
<lfs_bseg>-hkont
changing <lfs_bseg>-gsber_aju_b
<lfs_bseg>-kostl_aju_b.

* SELECT SINGLE gsber_aju kostl_aju


* FROM zfi_obj_imp_soc
* INTO (<lfs_bseg>-gsber_aju_b, <lfs_bseg>-kostl_aju_b)
* WHERE bukrs EQ <lfs_bseg>-bukrs AND
* gsber EQ <lfs_bseg>-gsber AND
* kostl EQ <lfs_bseg>-kostl.
if sy-subrc ne 0.
read table gt_datos assigning <lfs_datos> with key bukrs = <lfs_bseg>-bukrs
belnr = <lfs_bseg>-belnr
gjahr = <lfs_bseg>-gjahr
binary search.

if sy-subrc eq 0. "ZFI_CUEN_SOC_AJU
"Registro no informado en la tabla: Objeto de imputación sociedad ajuste
move: text-t03 to <lfs_datos>-text,
icon_red_light to <lfs_datos>-icon.
move-corresponding <lfs_datos> to ls_list.
append ls_list to gt_list.
exit.
endif.
endif.
else.
read table gt_datos assigning <lfs_datos> with key bukrs = <lfs_bseg>-bukrs
belnr = <lfs_bseg>-belnr
gjahr = <lfs_bseg>-gjahr
binary search.

if sy-subrc eq 0. "ZFI_CUEN_SOC_AJU
"Registro no informado en la tabla: Cuentas sociedad ajuste
move: text-t02 to <lfs_datos>-text,
icon_red_light to <lfs_datos>-icon.
move-corresponding <lfs_datos> to ls_list.
append ls_list to gt_list.
exit.
endif.
endif.

endloop.
endform. " ZF_BSEG

*&---------------------------------------------------------------------*
*& Form ZF_ZFI_CUEN_SOC_AJU
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_<LFS_BSEG>_BUKRS text
* -->P_<LFS_BSEG>_HKONT text
* <--P_<LFS_BSEG>_HKONT_AJU_B text
*----------------------------------------------------------------------*
form zf_zfi_cuen_soc_aju using uv_bukrs type bukrs
uv_hkont type hkont
changing cv_hkont_aju_b type hkont.

select single hkont_aju


from zfi_cuen_soc_aju
into cv_hkont_aju_b
where bukrs eq uv_bukrs and
hkont eq uv_hkont.

endform. " ZF_ZFI_CUEN_SOC_AJU

*&---------------------------------------------------------------------*
*& Form ZF_ZFI_OBJ_IMP_SOC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_<LFS_BSEG>_BUKRS text
* -->P_<LFS_BSEG>_GSBER text
* -->P_<LFS_BSEG>_KOSTL text
* <--P_<LFS_BSEG>_GSBER_AJU_B text
* <--P_<LFS_BSEG>_KOSTL_AJU_B text
*----------------------------------------------------------------------*
form zf_zfi_obj_imp_soc using uv_bukrs type bukrs
uv_gsber type gsber
uv_kostl type kostl
uv_hkont type hkont
changing cv_gsber_aju_b type gsber
cv_kostl_aju_b type kostl.

data: lv_hkont type hkont.


move: uv_hkont to lv_hkont.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = lv_hkont
importing
output = lv_hkont.

if ( lv_hkont+2(1) eq '6' or lv_hkont+2(1) eq '7' ).

select single gsber_aju kostl_aju


from zfi_obj_imp_soc
into (cv_gsber_aju_b, cv_kostl_aju_b)
where bukrs eq uv_bukrs and
gsber eq uv_gsber and
kostl eq uv_kostl.
else.

select single gsber_aju


from zfi_obj_imp_soc
into cv_gsber_aju_b
where bukrs eq uv_bukrs and
gsber eq uv_gsber.
* kostl EQ uv_kostl.
endif.

endform. " ZF_ZFI_OBJ_IMP_SOC

*&---------------------------------------------------------------------*
*& Form ZF_CREATE_DOC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form zf_create_doc .

data: ls_header type bapiache09.

data: lt_bapiacgl09 type table of bapiacgl09,


ls_bapiacgl09 type bapiacgl09.
data: lt_currency type table of bapiaccr09,
ls_currency type bapiaccr09.
data: lt_extension1 type table of bapiacextc,
ls_extension1 type bapiacextc.

data: ls_doc type bapiache09.


data: lt_return type table of bapiret2.
data: ls_return type bapiret2.

field-symbols: <lfs_datos> type ty_datos,


<lfs_bseg> type ty_bseg,
<lfs_list> type ty_list.

data: lt_bkpf type table of bkpf,


ls_bkpf type bkpf.

data: lt_bseg type standard table of bseg,


ls_bseg type bseg.
data: ls_list type ty_list.

data: lt_doc_ajus type standard table of zfi_doc_ajus_cre,


lt_doc_ins type standard table of zfi_doc_ajus_cre,
ls_doc_ajus type zfi_doc_ajus_cre.

if gt_datos is not initial.

select bukrs belnr gjahr


from zfi_doc_ajus_cre
into corresponding fields of table lt_doc_ajus
for all entries in gt_datos
where bukrs eq gt_datos-bukrs and
belnr eq gt_datos-belnr and
gjahr eq gt_datos-gjahr.

sort lt_doc_ajus by bukrs belnr gjahr.


endif.

loop at gt_datos assigning <lfs_datos> where text is initial.

read table lt_doc_ajus transporting no fields with key bukrs = <lfs_datos>-


bukrs
belnr = <lfs_datos>-
belnr
gjahr = <lfs_datos>-
gjahr
binary search.

if sy-subrc eq 0.
* Documento ya replicado
move: icon_yellow_light to <lfs_datos>-icon,
text-t08 to <lfs_datos>-text.
move-corresponding <lfs_datos> to ls_list.
append ls_list to gt_list.
else.
clear: ls_header, ls_doc, ls_doc_ajus.
refresh: lt_bapiacgl09, lt_currency, lt_return, lt_bseg.

call function 'FI_DOCUMENT_READ'


exporting
i_bukrs = <lfs_datos>-bukrs "'50'
i_belnr = <lfs_datos>-belnr "'18000076'
i_gjahr = <lfs_datos>-gjahr "'2016'
tables
* t_abuz = abuz
* t_acchd = acchd "
* t_accit = accit "
* t_acccr = acccr "
t_bkpf = lt_bkpf
t_bseg = lt_bseg
exceptions
wrong_input = 1
not_found = 2
others = 3.

if sy-subrc <> 0.
* Implement suitable error handling here
endif.

if p_table is not initial.


delete lt_bseg where hkont not in rg_hkont.
endif.

*--------------------------------------------------------------------*
* Cabecera
*--------------------------------------------------------------------*
read table lt_bkpf index 1 into ls_bkpf.

move: 'BKPFF' to ls_header-obj_type.


call function 'OWN_LOGICAL_SYSTEM_GET'
importing
own_logical_system = ls_header-obj_sys.

move: "'BKPFF' TO ls_header-obj_type,


* 'RFBU' TO ls_header-bus_act,
ls_bkpf-glvor to ls_header-bus_act,
sy-uname to ls_header-username, "<lfs_datos>-USNAM to ls_header-
USERNAME, ------>Mapear<------
<lfs_datos>-bktxt to ls_header-header_txt,
* <lfs_datos>-bukrs TO ls_header-comp_code,"------>Mapear<------
<lfs_datos>-bukrs_aju to ls_header-comp_code,"------>Mapear<------
******* sy-datum TO ls_header-doc_date, "------>Mapear<------ Fecha de
documento en documento Coment Z13K 17/07/2019
ls_bkpf-bldat to ls_header-doc_date, "------>Mapear<------ Fecha de
documento en documento Insert Z13K 17/07/2019
* sy-datum TO ls_header-pstng_date, "------>Mapear<------ Fecha de
contabilización
p_budat to ls_header-pstng_date, "------>Mapear<------ Fecha de
contabilización Insert Z13K 17/07/2019
******* sy-datum TO ls_header-trans_date, "------>Mapear<------ Fecha de
conversión Coment Z13K 17/07/2019
ls_bkpf-wwert to ls_header-trans_date, "------>Mapear<------ Fecha de
conversión Insert Z13K 17/07/2019
<lfs_datos>-gjahr to ls_header-fisc_year,
* ls_bkpf-monat TO ls_header-fis_period, "Coment Z13K 17/07/2019
p_budat+4(2) to ls_header-fis_period, "Insert Z13K 17/07/2019
* sy-datum+4(2) TO ls_header-fis_period,
* <lfs_datos>-blart TO ls_header-doc_type, "------>Mapear<------
<lfs_datos>-blart_aju to ls_header-doc_type, "------>Mapear<------
<lfs_datos>-xblnr to ls_header-ref_doc_no.

move p_budat+4(2) to <lfs_datos>-monat. "Insert Z13K 17/07/2019

* MOVE: ls_bkpf-monat TO <lfs_datos>-monat,


* ls_bkpf-xblnr TO ls_header-ref_doc_no.
*--------------------------------------------------------------------*
* Posiciones
*--------------------------------------------------------------------*
perform zf_bapiacgl09 using lt_bseg
<lfs_datos>
ls_header-fis_period "Insert Z13K 17/07/2019
* <lfs_datos>-waers
* <lfs_datos>-blart
* <lfs_datos>-monat
changing lt_bapiacgl09 "ls_bapiacgl09
lt_currency "ls_currency.
lt_extension1.

* APPEND ls_bapiacgl09 TO lt_bapiacgl09.


* APPEND ls_currency TO lt_currency.

call function 'BAPI_ACC_DOCUMENT_POST'


exporting
documentheader = ls_header
* CUSTOMERCPD =
* CONTRACTHEADER =
** IMPORTING
** obj_type = ls_doc-obj_type
** obj_key = ls_doc-obj_key
** obj_sys = ls_doc-obj_sys
tables
accountgl = lt_bapiacgl09 "original
* ACCOUNTRECEIVABLE = lt_BAPIACAR09
* ACCOUNTPAYABLE =
* ACCOUNTTAX =
currencyamount = lt_currency
* CRITERIA =
* VALUEFIELD =
extension1 = lt_extension1
return = lt_return
* PAYMENTCARD =
* CONTRACTITEM =
* EXTENSION2 =
* REALESTATE =
* ACCOUNTWT =
.

sort lt_return by type id number.

call function 'BAPI_TRANSACTION_COMMIT'.

read table lt_return into ls_return with key id = 'RW'


number = '605' binary search.

if sy-subrc eq 0.
"Documento creado
concatenate text-t05
ls_return-message_v2(10) "Documento
ls_return-message_v2+10(4) "Sociedad
ls_return-message_v2+14(4) "Año
into <lfs_datos>-text separated by space.

move: icon_green_light to <lfs_datos>-icon.


* MOVE: icon_green_light TO ls_list-icon,
* <lfs_datos>-text TO ls_list-text.
"Registramos el documento en la tabla ZFI_DOC_AJUS_CRE
move: <lfs_datos>-bukrs to ls_doc_ajus-bukrs,
<lfs_datos>-belnr to ls_doc_ajus-belnr,
<lfs_datos>-gjahr to ls_doc_ajus-gjahr,
ls_return-message_v2(10) to ls_doc_ajus-belnr_cre,
ls_return-message_v2+10(4) to ls_doc_ajus-bukrs_cre,
ls_return-message_v2+14(4) to ls_doc_ajus-gjahr_cre.

append ls_doc_ajus to lt_doc_ins.


* INSERT INTO zfi_doc_ajus_cre VALUES ls_doc_ajus.

else.

read table lt_return into ls_return with key type = 'E' binary search.

if sy-subrc eq 0.
call function 'FORMAT_MESSAGE'
exporting
id = ls_return-id
lang = sy-langu
no = ls_return-number
v1 = ls_return-message_v1
v2 = ls_return-message_v2
v3 = ls_return-message_v3
v4 = ls_return-message_v4
importing
msg = <lfs_datos>-text.

move: icon_red_light to <lfs_datos>-icon.


* MOVE: "icon_red_light TO ls_list-icon,
* <lfs_datos>-text TO ls_list-text.
endif.

endif.

* REFRESH: lt_return.

move-corresponding <lfs_datos> to ls_list.


append ls_list to gt_list.

endif.
endloop.

if lt_doc_ins is not initial.


insert zfi_doc_ajus_cre from table lt_doc_ins.
endif.

endform. " ZF_CREATE_DOC

*&---------------------------------------------------------------------*
*& Form ZF_BAPIACGL09
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LT_BSEG text
* <--P_LS_BAPIACGL09 text
* <--P_LS_CURRENCY text
*----------------------------------------------------------------------*
form zf_bapiacgl09 using ut_bseg type bseg_t
us_datos type ty_datos
uv_monat type monat
changing ct_bapiacgl09 type bapiacgl09_tab "BAPIACAR09_TAB
ct_currency type bapiaccr09_tab
ct_extension1 type bapiacextc_tab.

data: ls_bapiacgl09 type bapiacgl09,


ls_currency type bapiaccr09,
ls_bseg type bseg.
data: ls_bseg_aju type ty_bseg.

data: ls_extension1 type bapiacextc.


field-symbols: <lfs_bseg> type bseg.

sort gt_bseg by bukrs belnr buzei gjahr.

* LOOP AT ut_bseg INTO ls_bseg.


loop at ut_bseg assigning <lfs_bseg>.

read table gt_bseg into ls_bseg_aju with key bukrs = <lfs_bseg>-bukrs


belnr = <lfs_bseg>-belnr
buzei = <lfs_bseg>-buzei
gjahr = <lfs_bseg>-gjahr
binary search.

move: <lfs_bseg>-buzei to ls_bapiacgl09-itemno_acc,


* <lfs_bseg>-hkont TO ls_bapiacgl09-gl_account, "------>Mapear<------
ls_bseg_aju-hkont_aju_b to ls_bapiacgl09-gl_account, "------
>Mapear<------
<lfs_bseg>-sgtxt to ls_bapiacgl09-item_text,
* <lfs_bseg>-belnr TO ls_bapiacgl09-ac_doc_no, "Parece q no hace falta
<lfs_bseg>-xref1 to ls_bapiacgl09-ref_key_1,
<lfs_bseg>-xref2 to ls_bapiacgl09-ref_key_2,
<lfs_bseg>-xref3 to ls_bapiacgl09-ref_key_3,
* ls_bseg-kostl TO ls_bapiacgl09-costcenter, "------>Mapear<------
ls_bseg_aju-kostl_aju_b to ls_bapiacgl09-costcenter, "------
>Mapear<------
* <lfs_bseg>-koart TO ls_bapiacgl09-acct_type, "Comentado Z13K 17/07/2019
us_datos-blart to ls_bapiacgl09-doc_type, "----
us_datos-bukrs_aju to ls_bapiacgl09-comp_code,
* ls_bseg_aju-bukrs TO ls_bapiacgl09-comp_code,
* ls_bseg-gsber TO ls_bapiacgl09-bus_area, "------>Mapear<------
ls_bseg_aju-gsber_aju_b to ls_bapiacgl09-bus_area, "------>Mapear<------
<lfs_bseg>-fkber to ls_bapiacgl09-func_area,
<lfs_bseg>-werks to ls_bapiacgl09-plant,
* us_datos-monat TO ls_bapiacgl09-fis_period, "Coment Z13K 17/07/2019
uv_monat to ls_bapiacgl09-fis_period, "Insert Z132K 17/07/2019
<lfs_bseg>-gjahr to ls_bapiacgl09-fisc_year,
<lfs_bseg>-valut to ls_bapiacgl09-value_date,
<lfs_bseg>-kunnr to ls_bapiacgl09-customer,
<lfs_bseg>-xskrl to ls_bapiacgl09-cshdis_ind,
<lfs_bseg>-lifnr to ls_bapiacgl09-vendor_no,
<lfs_bseg>-zuonr to ls_bapiacgl09-alloc_nmbr,
<lfs_bseg>-mwskz to ls_bapiacgl09-tax_code,
<lfs_bseg>-txjcd to ls_bapiacgl09-taxjurcode,
<lfs_bseg>-kstrg to ls_bapiacgl09-costobject,
* <lfs_bseg>-kostl TO ls_bapiacgl09-costcenter,
<lfs_bseg>-lstar to ls_bapiacgl09-acttype,
**** <lfs_bseg>-prctr TO ls_bapiacgl09-profit_ctr,
**** <lfs_bseg>-prctr TO ls_bapiacgl09-part_prctr,
<lfs_bseg>-nplnr to ls_bapiacgl09-network,
<lfs_bseg>-aufnr to ls_bapiacgl09-orderid,
<lfs_bseg>-geber to ls_bapiacgl09-fund,
<lfs_bseg>-fistl to ls_bapiacgl09-funds_ctr,
<lfs_bseg>-fipos to ls_bapiacgl09-cmmt_item,
<lfs_bseg>-prznr to ls_bapiacgl09-co_busproc,
**** <lfs_bseg>-anln1 TO ls_bapiacgl09-asset_no,
**** <lfs_bseg>-anln2 TO ls_bapiacgl09-sub_number,
<lfs_bseg>-menge to ls_bapiacgl09-quantity,
<lfs_bseg>-meins to ls_bapiacgl09-base_uom_iso,
<lfs_bseg>-erfmg to ls_bapiacgl09-entry_qnt,
<lfs_bseg>-erfme to ls_bapiacgl09-entry_uom,
<lfs_bseg>-matnr to ls_bapiacgl09-material,
<lfs_bseg>-hrkft to ls_bapiacgl09-orig_group,
<lfs_bseg>-vptnr to ls_bapiacgl09-part_acct,
<lfs_bseg>-pargb to ls_bapiacgl09-tr_part_ba,
<lfs_bseg>-vbund to ls_bapiacgl09-trade_id,
<lfs_bseg>-bwkey to ls_bapiacgl09-val_area,
<lfs_bseg>-bwtar to ls_bapiacgl09-val_type,
<lfs_bseg>-ebeln to ls_bapiacgl09-po_number,
<lfs_bseg>-ebelp to ls_bapiacgl09-po_item,
<lfs_bseg>-projn to ls_bapiacgl09-itm_number,
<lfs_bseg>-fkber to ls_bapiacgl09-func_area_long,
<lfs_bseg>-grant_nbr to ls_bapiacgl09-grant_nbr,
<lfs_bseg>-bewar to ls_bapiacgl09-cs_trans_t,
<lfs_bseg>-measure to ls_bapiacgl09-measure,
<lfs_bseg>-segment to ls_bapiacgl09-segment,
<lfs_bseg>-psegment to ls_bapiacgl09-partner_segment,
<lfs_bseg>-kblnr to ls_bapiacgl09-res_doc,
<lfs_bseg>-kblpos to ls_bapiacgl09-res_item,
<lfs_bseg>-perop_beg to ls_bapiacgl09-billing_period_start_date,
<lfs_bseg>-perop_end to ls_bapiacgl09-billing_period_end_date,
<lfs_bseg>-ppa_ex_ind to ls_bapiacgl09-ppa_ex_ind,
<lfs_bseg>-fastpay to ls_bapiacgl09-fastpay,
<lfs_bseg>-budget_pd to ls_bapiacgl09-budget_period,
<lfs_bseg>-pbudget_pd to ls_bapiacgl09-partner_budget_period,
<lfs_bseg>-pgeber to ls_bapiacgl09-partner_fund,
<lfs_bseg>-taxps to ls_bapiacgl09-itemno_tax.

"Insert Z13K 17/07/2019


if <lfs_bseg>-bschl eq '70' or
<lfs_bseg>-bschl eq '75'.
move: 'S' to ls_bapiacgl09-acct_type.
else.
move: <lfs_bseg>-koart to ls_bapiacgl09-acct_type.
endif.

append ls_bapiacgl09 to ct_bapiacgl09.

*--------------------------------------------------------------------*
* Extension1 para añadir BSCHL y ANBWA
*--------------------------------------------------------------------*
ls_extension1-field1 = ls_bapiacgl09-itemno_acc.

case <lfs_bseg>-bschl.
when'40' or '70'.
concatenate 'BSCHL' '40' into ls_extension1-field2.
when '50' or '75'.
concatenate 'BSCHL' '50' into ls_extension1-field2.
endcase.

if <lfs_bseg>-anbwa is not initial.


concatenate 'ANBWA' <lfs_bseg>-anbwa into ls_extension1-field3.
endif.

append ls_extension1 to ct_extension1.


*--------------------------------------------------------------------*
* Posicion de la moneda
*--------------------------------------------------------------------*
move: <lfs_bseg>-buzei to ls_currency-itemno_acc,
us_datos-waers to ls_currency-currency.

if <lfs_bseg>-shkzg eq 'S'.
ls_currency-amt_doccur = <lfs_bseg>-wrbtr.
elseif <lfs_bseg>-shkzg eq 'H'.
ls_currency-amt_doccur = <lfs_bseg>-wrbtr * -1.
else.
" nothing to do with default case
endif.

append ls_currency to ct_currency.

* move: ls_bseg-zterm to ls_bapiacar09-pmnttrms,


* ls_bseg-zlsch to ls_bapiacar09-pymt_meth.
* move: ls_bseg-buzei to ls_bapiacar09-itemno_acc,
* ls_bseg-hkont to ls_bapiacar09-gl_account,
* ls_bseg-kunnr to ls_bapiacar09-customer,
* ls_bseg-gsber to ls_bapiacar09-bus_area.
*append ls_bapiacar09 to lt_bapiacar09.
endloop.
endform. " ZF_BAPIACGL09

*&---------------------------------------------------------------------*
*& Form ZF_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form zf_display .

data : lr_alv type ref to cl_salv_table,


lr_columns type ref to cl_salv_columns_table,
lr_column type ref to cl_salv_column_table.

* DATA: alv_columns TYPE REF TO cl_salv_columns_table.


* DATA: alv_column TYPE REF TO cl_salv_column_table.

try.
cl_salv_table=>factory(
importing
r_salv_table = lr_alv
changing
t_table = gt_list ).
catch cx_salv_msg.
exit.
endtry.

lr_columns = lr_alv->get_columns( ).
* gr_columns = gr_table->get_columns( ).

** TRY.
lr_column ?= lr_columns->get_column( 'ICON' ). "Exception Column
lr_column->set_medium_text( 'Status' ).
lr_column->set_long_text( 'Status' ).
lr_column->set_short_text( 'Status' ).
lr_columns->set_optimize( abap_true ).
** CATCH cx_salv_not_found. "#EC NO_HANDLER
** ENDTRY.

** TRY.
lr_column ?= lr_columns->get_column( 'TEXT' ). "Exception Column
lr_column->set_medium_text( text-t06 ). "( 'Descripción' ).
lr_column->set_long_text( text-t06 ). "( 'Descripción' ).
lr_column->set_short_text( text-t07 ). "( 'Descrip.' ).
lr_columns->set_optimize( abap_true ).
** CATCH cx_salv_not_found. "#EC NO_HANDLER
** ENDTRY.

*-- Set headers


* TRY.
* lr_columns ?= lr_columns->get_column( 'ICON' ).
* lr_column->set_SHORT_text( 'Status' ).
* lr_column->set_visible( abap_false ).
* CATCH cx_salv_not_found. "#EC NO_HANDLER
* ENDTRY.

* alv_columns = lr_alv->get_columns( ).
* alv_column ?= alv_columns->get_column( 'STATUS' ).
** alv_column->set_SHORT_text( 'Status' ).
* alv_column->set_visible( abap_false ).

* TRY.
* lr_column ?= lr_columns->get_column( 'BUKRS_AJU' ).
* lr_columns->set_MEDIUM_text( 'Soci. Ajus.' ).
* CATCH cx_salv_not_found. "#EC NO_HANDLER
* ENDTRY.
*
* TRY.
* lr_column ?= lr_columns->get_column( 'HKONT_AJU' ).
* lr_columns->set_MEDIUM_text( 'Cuenta Ajus.' ).
* CATCH cx_salv_not_found. "#EC NO_HANDLER
* ENDTRY.
*
* TRY.
* lr_column ?= lr_columns->get_column( 'GSBER_AJU' ).
* lr_columns->set_MEDIUM_text( 'División Ajus.' ).
* CATCH cx_salv_not_found. "#EC NO_HANDLER
* ENDTRY.
*
* TRY.
* lr_column ?= lr_columns->get_column( 'KOSTL_AJU' ).
* lr_columns->set_MEDIUM_text( 'Cent. coste Ajus.' ).
* CATCH cx_salv_not_found. "#EC NO_HANDLER
* ENDTRY.
*
* TRY.
* lr_column ?= lr_columns->get_column( 'BLART_AJU' ).
* lr_columns->set_MEDIUM_text( 'Clase Doc. Ajus.' ).
*
* CATCH cx_salv_not_found. "#EC NO_HANDLER
*ENDTRY.
* kostl_aju TYPE kostl,
* BLART_aju TYPE BLART,
lr_alv->display( ). "display ALV

endform. " ZF_DISPLAY

*&---------------------------------------------------------------------*
*& Form ZF_CLASE_DOC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_<LFS_DATOS>_BUKRS text
* -->P_<LFS_DATOS>_BLART text
* <--P_<LFS_DATOS>_BUKRS_AJU text
* <--P_<LFS_DATOS>_BLART_AJU text
*----------------------------------------------------------------------*
form zf_clase_doc using uv_bukrs type bukrs
uv_blart type blart
changing cv_bukrs_aju type bukrs
cv_blart_aju type blart.

select single bukrs_aju blart_aju


"bukrs blart bukrs_aju blart_aju
from zfi_clase_doc
into (cv_bukrs_aju, cv_blart_aju)
* INTO (ls_clase_doc-bukrs, ls_clase_doc-blart, ls_clase_doc-bukrs_aju,
ls_clase_doc-blart_aju)
where bukrs eq uv_bukrs and
blart eq uv_blart.
endform. " ZF_CLASE_DOC

You might also like