SAP ABAP - Upload G/L Account (FS00) Custom Program
Gui Status
Download template Here
TYPES:
BEGIN OF ty_excel,
bukrs TYPE bukrs,
saknr TYPE saknr,
glacc_type TYPE char1,
ktoks TYPE ska1-ktoks,
txt20 TYPE txt20,
txt50 TYPE txt50,
waers TYPE waers,
kdfsl TYPE skb1-kdfsl,
bewgp TYPE skb1-bewgp,
mwskz TYPE skb1-mwskz,
xmwno TYPE skb1-xmwno,
mitkz TYPE skb1-mitkz,
altkt TYPE skb1-altkt,
infky TYPE skb1-infky,
togru TYPE skb1-togru,
zuawa TYPE skb1-zuawa,
fstag TYPE skb1-fstag,
xintb TYPE skb1-xintb,
xnkon TYPE skb1-xnkon,
xmitk TYPE skb1-xmitk,
fdlev TYPE skb1-fdlev,
xgkon TYPE skb1-xgkon,
hbkid TYPE skb1-hbkid,
hktid TYPE skb1-hktid,
END OF ty_excel,
BEGIN OF ty_data,
icons LIKE icon-id,
snote TYPE char255,
ccell TYPE lvc_t_scol,
cstyl TYPE lvc_t_styl,
cline TYPE char4,
bukrs TYPE bukrs,
saknr TYPE saknr,
glacc_type TYPE char1,
ktoks TYPE ska1-ktoks,
txt20 TYPE txt20,
txt50 TYPE txt50,
waers TYPE waers,
kdfsl TYPE skb1-kdfsl,
bewgp TYPE skb1-bewgp,
mwskz TYPE skb1-mwskz,
xmwno TYPE skb1-xmwno,
mitkz TYPE skb1-mitkz,
altkt TYPE skb1-altkt,
infky TYPE skb1-infky,
togru TYPE skb1-togru,
zuawa TYPE skb1-zuawa,
fstag TYPE skb1-fstag,
xintb TYPE skb1-xintb,
xnkon TYPE skb1-xnkon,
xmitk TYPE skb1-xmitk,
fdlev TYPE skb1-fdlev,
xgkon TYPE skb1-xgkon,
hbkid TYPE skb1-hbkid,
hktid TYPE skb1-hktid,
END OF ty_data,
BEGIN OF zstab,
field TYPE char10,
END OF zstab.
DATA:
lt_excel TYPE TABLE OF ty_excel,
ls_excel TYPE ty_excel,
lt_data TYPE TABLE OF ty_data,
ls_data TYPE ty_data,
stab TYPE TABLE OF zstab,
itab TYPE TABLE OF alsmex_tabline WITH HEADER LINE.
DATA:
ob_container TYPE REF TO cl_gui_custom_container,
ob_grid TYPE REF TO cl_gui_alv_grid,
lt_fieldcat TYPE lvc_t_fcat,
ls_fieldcat LIKE LINE OF lt_fieldcat,
is_lyout TYPE lvc_s_layo,
lt_message TYPE TABLE OF bdcmsgcoll,
ls_message LIKE LINE OF lt_message,
ld_mode TYPE c VALUE 'N'.
DATA:
zz_pid TYPE char80.
DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
* messages of call transaction
DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
* error session opened (' ' or 'X')
DATA: e_group_opened.
* message texts
TABLES: t100.
"Selection Screen
SELECTION-SCREEN BEGIN OF SCREEN 101 AS SUBSCREEN.
PARAMETERS:
* p_bukrs TYPE bukrs OBLIGATORY,
filename TYPE localfile MEMORY ID zfile,
p_line TYPE i DEFAULT 3,
p_total TYPE i.
SELECTION-SCREEN END OF SCREEN 101 .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.
* MESSAGE 'Tes' TYPE 'I' DISPLAY LIKE 'S'.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
static = 'X'
mask = '*.xls'
CHANGING
file_name = filename.
AT SELECTION-SCREEN OUTPUT.
GET PARAMETER ID 'ZFILE' FIELD zz_pid.
LOOP AT SCREEN.
IF lt_data IS NOT INITIAL AND
( screen-name CS 'P_LINE' OR screen-name CS 'P_BUKRS' OR screen-name CS 'FILENAME').
screen-input = 0.
ELSE.
screen-input = 1.
ENDIF.
IF screen-name CS 'P_TOTAL'.
screen-input = 0.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
START-OF-SELECTION.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
REFRESH stab.
IF lt_data IS INITIAL.
APPEND 'POST' TO stab.
APPEND 'CLRD' TO stab.
ELSE.
APPEND 'READ' TO stab.
ENDIF.
SET PF-STATUS 'PF100' EXCLUDING stab.
SET TITLEBAR 'TL100' WITH 'Upload G/L Account Master'.
PERFORM initial_screen.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK' OR 'EXIT' OR 'CNCL'.
LEAVE PROGRAM.
WHEN 'READ'.
CLEAR p_total.
PERFORM read_excel USING filename '1' p_line '70' '65536'.
DESCRIBE TABLE lt_data LINES p_total.
WHEN 'CLRD'.
REFRESH : lt_data, lt_excel.
WHEN 'POST'.
PERFORM create_gl.
ENDCASE.
ENDMODULE.
FORM initial_screen.
IF ob_container IS INITIAL.
CREATE OBJECT ob_container
EXPORTING
container_name = 'CONTAINER'.
CREATE OBJECT ob_grid
EXPORTING
i_parent = ob_container.
ENDIF.
PERFORM set_fieldcat.
PERFORM set_lyout.
PERFORM alv_displ_out.
CALL METHOD ob_grid->refresh_table_display.
ENDFORM.
FORM set_fieldcat.
REFRESH lt_fieldcat.
PERFORM :
append_fieldcat USING 'ICONS' 'Status' 'CHAR' '' '' '5' '' 'X' 'LT_DATA' '1',
append_fieldcat USING 'SNOTE' 'Message' 'CHAR' '' '' '40' '' 'X' 'LT_DATA' '1'.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'YSFC001'
CHANGING
ct_fieldcat = lt_fieldcat.
ENDFORM.
FORM append_fieldcat USING p_fname p_fdesc p_dtype p_qfield p_cfield p_olen p_sum p_key p_tabname p_act.
DATA irows TYPE i.
CLEAR irows.
DESCRIBE TABLE lt_fieldcat LINES irows.
irows = irows + 1.
CLEAR ls_fieldcat.
IF p_fname = 'ICONS'.
ls_fieldcat-icon = 'X'.
ls_fieldcat-just = 'C'.
ENDIF.
ls_fieldcat-col_pos = irows.
ls_fieldcat-key = p_key.
ls_fieldcat-fieldname = p_fname.
ls_fieldcat-scrtext_l = p_fdesc.
ls_fieldcat-scrtext_m = p_fdesc.
ls_fieldcat-scrtext_s = p_fdesc.
ls_fieldcat-datatype = p_dtype.
ls_fieldcat-qfieldname = p_qfield.
ls_fieldcat-cfieldname = p_cfield.
ls_fieldcat-outputlen = p_olen.
ls_fieldcat-do_sum = p_sum.
ls_fieldcat-tabname = p_tabname.
APPEND ls_fieldcat TO lt_fieldcat.
ENDFORM.
FORM set_lyout .
CLEAR is_lyout.
is_lyout-zebra = 'X'.
is_lyout-cwidth_opt = 'X'.
is_lyout-box_fname = 'ZBOX'.
* is_lyout-no_rowins = 'X'.
is_lyout-stylefname = 'CSTYL'.
is_lyout-info_fname = 'CLINE'.
is_lyout-ctab_fname = 'CCELL'.
ENDFORM.
FORM alv_displ_out.
CALL METHOD ob_grid->set_table_for_first_display
EXPORTING
* is_variant = is_varnt "DISVARIANT
i_save = 'A' "CHAR1 - X:Global - U:User - A:All - Space:No
i_default = 'X' "CHAR1 - X:Allowed - Space:not
is_layout = is_lyout "LVC_S_LAYO
* is_print = is_print "LVC_S_PRNT
* it_toolbar_excluding = it_excld "UI_FUNCTIONS
CHANGING
it_outtab = lt_data
it_fieldcatalog = lt_fieldcat "LVC_T_FCAT
* it_sort = it_sort "LVC_T_SORT
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
ENDFORM.
FORM read_excel USING p_file p_bcol p_brow p_ecol p_erow.
* CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = p_bcol
i_begin_row = p_brow
i_end_col = p_ecol
i_end_row = p_erow
TABLES
intern = itab[]
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
DATA lv_index TYPE i.
FIELD-SYMBOLS <fs>.
LOOP AT itab.
MOVE itab-col TO lv_index.
ASSIGN COMPONENT lv_index OF STRUCTURE ls_excel TO <fs>.
MOVE itab-value TO <fs>.
AT END OF row.
CLEAR ls_data.
* ls_data-icons = '@08@'.
MOVE-CORRESPONDING ls_excel TO ls_data.
SELECT SINGLE saknr FROM skb1
INTO @DATA(ls_check)
WHERE saknr = @ls_data-saknr AND bukrs = @ls_data-bukrs.
IF ls_check IS NOT INITIAL.
ls_data-icons = '@0A@'.
ls_data-snote = |G/L Account { ls_data-saknr } already exists in company code { ls_data-bukrs }|.
ELSE.
ls_data-icons = '@08@'.
ENDIF.
CLEAR ls_check.
APPEND ls_data TO lt_data.
CLEAR ls_excel.
ENDAT.
ENDLOOP.
ENDFORM.
FORM create_gl.
CLEAR ls_data.
LOOP AT lt_data INTO ls_data WHERE icons = '@08@'.
REFRESH bdcdata[].
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ACC_CRE'.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_KEY-SAKNR'.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_KEY-SAKNR'
ls_data-saknr.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_KEY-BUKRS'
ls_data-bukrs.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=GLACC_TYPE'.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'
ls_data-glacc_type.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=2102_GROUP'.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_COA-KTOKS'.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'
ls_data-glacc_type.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-KTOKS'
ls_data-ktoks.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTER'.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'
ls_data-glacc_type.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-KTOKS'
ls_data-ktoks.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_COA-TXT50_ML'.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-TXT20_ML'
ls_data-txt20.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-TXT50_ML'
ls_data-txt50.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=TAB02'.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-GLACCOUNT_TYPE'
ls_data-glacc_type.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-KTOKS'
ls_data-ktoks.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-TXT20_ML'
ls_data-txt20.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_COA-TXT50_ML'
ls_data-txt50.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=TAB03'.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_CCODE-MITKZ'.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-WAERS'
ls_data-waers.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-ZUAWA'
'001'.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTER'.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-FSTAG'
ls_data-fstag.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-XGKON'
ls_data-xgkon.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_CCODE-ZINRT'.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-ZINRT'
''.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=TAB04'.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_CCODE-FSTAG'.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-FSTAG'
ls_data-fstag.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_CCODE-XGKON'
ls_data-xgkon.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=TAB05'.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_COA-LANGU_KW(01)'.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=TAB06'.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_KEY-SAKNR'.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=SAVE'.
PERFORM bdc_field USING 'BDC_CURSOR'
'EENO_DYNP-ZEILE(01)'.
PERFORM bdc_dynpro USING 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=BACK'.
PERFORM bdc_field USING 'BDC_CURSOR'
'GLACCOUNT_SCREEN_KEY-SAKNR'.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_KEY-SAKNR'
ls_data-saknr.
PERFORM bdc_field USING 'GLACCOUNT_SCREEN_KEY-BUKRS'
ls_data-bukrs.
REFRESH lt_message.
CALL TRANSACTION 'FS00' USING bdcdata[]
MODE ld_mode
UPDATE 'S'
MESSAGES INTO lt_message.
READ TABLE lt_message ASSIGNING FIELD-SYMBOL(<fs_mssg>)
WITH KEY msgtyp = 'E'.
IF sy-subrc = 0.
ls_data-snote = |{ <fs_mssg>-msgv1 } { <fs_mssg>-msgv2 } { <fs_mssg>-msgv3 } { <fs_mssg>-msgv4 }|.
ls_data-icons = '@F1@'.
ELSE.
ls_data-snote = |G/L Account { ls_data-saknr } Created!|.
ls_data-icons = '@5Y@'.
ENDIF.
MODIFY lt_Data FROM ls_data
TRANSPORTING icons snote
WHERE bukrs = ls_data-bukrs AND saknr = ls_data-saknr.
CLEAR ls_data.
ENDLOOP.
ENDFORM.
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
ENDFORM.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
APPEND bdcdata.
ENDFORM.
Comments
Post a Comment