GL_ACCT_MASTER_SAVE - Upload G/L Master SAP Tool.

GL_ACCT_MASTER_SAVE is a standard SAP function module that can be used to create new General Ledger Account Master Record. If there is a requirement to upload G/L Account Master Records, then the below program can be used to achieve the same.



SAMPLE CODE:

*&---------------------------------------------------------------------*
REPORT zfi_create_gl_accounts.

TYPESBEGIN OF gty_upload,
         sno(10),            " Serial No.   
         saknr(10),          " G/L Account   
         bukrs(40),          " Company Code   
         glaccount_type(40)" G/L Account Type   
         ktoks(40),          " Account Group   
         txt20_ml(40),       " Short Description   
         txt50_ml(50),       " Long Description   
         waers(20),          " Account Currency   
         xsalh(20),          " Balance In LC Indicator   
         mwskz(20),          " Tax Category   
         xmwno(40),          " Indicator: Tax code is not a required field   
         mitkz(40),          " Reconciliation Account   
         xopvw(40),          " Indicator: Open Item Management   
         katyp(40),          " Cost element category   
         mgefl(40),          " Record Quantity   
         fstag(40),          " Field Status Group   
         xintb(40),          " Indicator: Is Account only Posted to Automatically?   
         zuawa(40),          " Sort key   
         bilkt(40),          " Group Account Number   
       END OF gty_upload.

DATAgt_upload  TYPE TABLE OF gty_upload,
      gwa_upload TYPE gty_upload.

DATAgt_names    TYPE glaccount_name_table,
      gwa_names   TYPE LINE OF glaccount_name_table,
      gt_keyword  TYPE glaccount_keyword_table,
      gwa_keyword TYPE LINE OF glaccount_keyword_table,
      gt_ccodes   TYPE glaccount_ccode_table,
      gwa_ccodes  TYPE LINE OF glaccount_ccode_table,
      gt_carea    TYPE glaccount_carea_table,
      gwa_carea   TYPE LINE OF glaccount_carea_table,
      gt_coa      TYPE TABLE OF glaccount_coa,
      gwa_coa     TYPE glaccount_coa,
      gt_return   TYPE TABLE OF bapiret2,
      gwa_return  TYPE bapiret2.

TYPESBEGIN OF gty_message,
         saknr   TYPE saknr,       " G/L Account
         bukrs   TYPE bukrs,       " Company Code
         type    TYPE bapi_mtype,  " Message type: S Success, E Error, W Warning, I Info, A Abort
         message TYPE bapi_msg,    " Message Text
       END OF gty_message.

DATAgt_message  TYPE TABLE OF gty_message,
      gwa_message TYPE gty_message.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERSp_file TYPE rlgrap-filename LOWER CASE.
SELECTION-SCREEN END OF BLOCK b1.

**********************************************************************
*SELECTION-SCREEN EVENT
**********************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR  p_file.
  PERFORM get_file_name USING p_file.

START-OF-SELECTION.

  IF p_file IS INITIAL.
    MESSAGE 'Please enter file path to proceed' TYPE 'I'.
    STOP.
  ENDIF.

  PERFORM f_read_input_file.
  PERFORM f_create_gl.
  PERFORM display_log.

*&---------------------------------------------------------------------*
*&      Form  get_file_name
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_P_FILE  text
*----------------------------------------------------------------------*

FORM get_file_name  USING pfile.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  syst-cprog
      dynpro_number syst-dynnr
      field_name    ' '
    IMPORTING
      file_name     pfile.
ENDFORM.                    " get_file_name

*&---------------------------------------------------------------------*
*&      Form  read_input_file
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

FORM f_read_input_file .

  DATA lv_fname   TYPE localfile,
         i_raw_data TYPE truxs_t_text_data.

  MOVE  p_file TO lv_fname.

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_field_seperator    ''
      i_line_header        'X'
      i_tab_raw_data       i_raw_data
      i_filename           lv_fname
    TABLES
      i_tab_converted_data gt_upload
    EXCEPTIONS
      conversion_failed    1
      OTHERS               2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.                    " f_read_input_file
*&---------------------------------------------------------------------*
*& Form F_CREATE_GL
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM f_create_gl .
  LOOP AT gt_upload INTO gwa_upload.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  gwa_upload-saknr
      IMPORTING
        output gwa_upload-saknr.

    gwa_coa-keyy-saknr gwa_upload-saknr.
    gwa_coa-keyy-ktopl '1000'.
    gwa_coa-data-ktoks gwa_upload-ktoks.
    gwa_coa-data-gvtyp 'X'.
    gwa_coa-data-glaccount_type gwa_upload-glaccount_type.
    gwa_coa-info-erdat sy-datum.
    gwa_coa-info-ernam sy-uname.
    gwa_coa-action 'I'.
    APPEND gwa_coa TO gt_coa.

    gwa_names-keyy-saknr gwa_upload-saknr.
    gwa_names-keyy-ktopl '1000'.
    gwa_names-keyy-spras 'E'.
    gwa_names-data-txt20 gwa_upload-txt20_ml.
    gwa_names-data-txt50 gwa_upload-txt50_ml.
    gwa_names-action 'I'.
    APPEND gwa_names TO gt_names.

    gwa_ccodes-keyy-saknr gwa_upload-saknr.
    gwa_ccodes-keyy-bukrs gwa_upload-bukrs.
    gwa_ccodes-data-waers gwa_upload-waers.
    gwa_ccodes-data-xsalh gwa_upload-xsalh.
    gwa_ccodes-data-mwskz gwa_upload-mwskz.
    gwa_ccodes-data-xmwno gwa_upload-xmwno.
    gwa_ccodes-data-mitkz gwa_upload-mitkz.
    gwa_ccodes-data-xopvw gwa_upload-xopvw.
    gwa_ccodes-data-fstag gwa_upload-fstag.     " Field Status Group
    gwa_ccodes-data-xintb gwa_upload-xintb.     " Indicator: Is Account only Posted to Automatically?
    gwa_ccodes-data-zuawa gwa_upload-zuawa.     " Sort key
    gwa_ccodes-action 'I'.
    APPEND gwa_ccodes TO gt_ccodes.

    IF gwa_upload-glaccount_type NE 'X' AND gwa_upload-glaccount_type NE 'N'.
      gwa_carea-keyy-saknr gwa_upload-saknr.
      gwa_carea-keyy-kokrs '1000'.
      gwa_carea-data-mgefl gwa_upload-mgefl.

      "cost element restriction for gl account type other than P and S RR 22062017"
      IF gwa_upload-glaccount_type 'P' ."OR gwa_upload-glaccount_type = 'S'.
        gwa_carea-data-katyp gwa_upload-katyp.
      ENDIF.
      "cost element restriction for gl account type other than P and S RR 22062017"
      gwa_carea-keyy-saknr gwa_upload-saknr.
      gwa_carea-keyy-kokrs '1000'.
      gwa_carea-fromto-datab '20010101'.            " sy-datum.
      gwa_carea-fromto-datbi '99991231'.            " Valid To Date
      gwa_carea-action 'I'.
      APPEND gwa_carea TO gt_carea.

      gwa_coa-keyy-ktopl '1000'.
      gwa_coa-keyy-saknr gwa_upload-saknr.
      gwa_coa-data-bilkt gwa_upload-bilkt.
      APPEND gwa_coa TO gt_coa.
    ENDIF.
    CALL FUNCTION 'GL_ACCT_MASTER_SAVE'
      TABLES
        account_names  gt_names
        account_ccodes gt_ccodes
        account_careas gt_carea
        return         gt_return
      CHANGING
        account_coa    gwa_coa.

    READ TABLE gt_return INTO gwa_return WITH KEY type 'E'.
    IF sy-subrc 0.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait 'X'.
    ENDIF.

    IF gt_return IS NOT INITIAL.
      LOOP AT gt_return INTO gwa_return.
        gwa_message-saknr gwa_upload-saknr.
        gwa_message-bukrs gwa_upload-bukrs.
        gwa_message-type gwa_return-type.
        gwa_message-message gwa_return-message.
        APPEND gwa_message TO gt_message.
        CLEARgwa_message.
      ENDLOOP.
    ELSE.
      gwa_message-saknr gwa_upload-saknr.
      gwa_message-bukrs gwa_upload-bukrs.
      gwa_message-type 'S'.
      gwa_message-message 'Created'.
      APPEND gwa_message TO gt_message.
      CLEARgwa_message.
    ENDIF.

    REFRESHgt_namesgt_ccodesgt_careagt_returngt_coa.
    CLEARgwa_namesgwa_ccodesgwa_careagwa_returngwa_coa.
  ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_LOG
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM display_log .
  CALL FUNCTION 'ZDISPLAY_ALV'
    EXPORTING
      i_title   'Upload Log'
      i_program sy-repid
    TABLES
      t_alv     gt_message.
ENDFORM.

Comments

Also Read...