*****           Implementation of object type ZGLMAST              *****
INCLUDE <object>.
BEGIN_DATA OBJECT. " Do not change.. DATA is generated
* only private members may be inserted into structure private
DATA:
" begin of private,
"   to declare private attributes remove comments and
"   insert private attributes here ...
" end of private,
  BEGIN OF KEY,
      CHARTOFACCOUNTS LIKE SKA1-KTOPL,
      GLACCOUNT LIKE SKA1-SAKNR,
      COMPANYCODE LIKE SKB1-BUKRS,
  END OF KEY.
END_DATA OBJECT. " Do not change.. DATA is generated

BEGIN_METHOD MAINTAIN CHANGING CONTAINER.
DATA:
      IVSAKNR TYPE SKA1-SAKNR,
      IVWITHREF TYPE SKA1-SAKNR,
      IVKTOPL TYPE SKA1-KTOPL,
      IVBUKRS TYPE SKB1-BUKRS,
      ISCOADATA LIKE ZBAPI_S_COA_DATA,
      ISCCODEDATA LIKE ZBAPI_S_CCODE_DATA,
      ISACCTNAME LIKE GLACCOUNT_NAME_DATA,
      IVKEYWORD TYPE SKAS-SCHLW,
      IVMODE TYPE ZBAPI_S_ACTION-ACTION,
      IVSIMULATE TYPE BAPI1030_GEN-TESTRUN,
      RETURN LIKE BAPIRET2 OCCURS 0.
  SWC_GET_ELEMENT CONTAINER 'IvSaknr' IVSAKNR.
  SWC_GET_ELEMENT CONTAINER 'IvWithRef' IVWITHREF.
  SWC_GET_ELEMENT CONTAINER 'IvKtopl' IVKTOPL.
  IF SY-SUBRC <> 0.
    MOVE '2000' TO IVKTOPL.
  ENDIF.
  SWC_GET_ELEMENT CONTAINER 'IvBukrs' IVBUKRS.
  IF SY-SUBRC <> 0.
    MOVE '1020' TO IVBUKRS.
  ENDIF.
  SWC_GET_ELEMENT CONTAINER 'IsCoaData' ISCOADATA.
  SWC_GET_ELEMENT CONTAINER 'IsCcodeData' ISCCODEDATA.
  SWC_GET_ELEMENT CONTAINER 'IsAcctName' ISACCTNAME.
  SWC_GET_ELEMENT CONTAINER 'IvKeyword' IVKEYWORD.
  SWC_GET_ELEMENT CONTAINER 'IvMode' IVMODE.
  IF SY-SUBRC <> 0.
    MOVE 'I' TO IVMODE.
  ENDIF.
  SWC_GET_ELEMENT CONTAINER 'IvSimulate' IVSIMULATE.
  IF SY-SUBRC <> 0.
    MOVE ABAP_TRUE TO IVSIMULATE.
  ENDIF.
  SWC_GET_TABLE CONTAINER 'Return' RETURN.
  CALL FUNCTION 'ZBAPI_GLACCOUNT_MAINTAIN'
    EXPORTING
      IV_SAKNR = IVSAKNR
      IV_WITH_REF = IVWITHREF
      IV_KTOPL = IVKTOPL
      IV_BUKRS = IVBUKRS
      IS_COA_DATA = ISCOADATA
      IS_CCODE_DATA = ISCCODEDATA
      IS_ACCT_NAME = ISACCTNAME
      IV_KEYWORD = IVKEYWORD
      IV_MODE = IVMODE
      IV_SIMULATE = IVSIMULATE
    TABLES
      RETURN = RETURN
    EXCEPTIONS
      OTHERS = 01.
  CASE SY-SUBRC.
    WHEN 0.            " OK
    WHEN OTHERS.       " to be implemented
  ENDCASE.
  SWC_SET_TABLE CONTAINER 'Return' RETURN.
END_METHOD.

BEGIN_METHOD ASSIGNFSV CHANGING CONTAINER.
DATA:
      IVVERSN TYPE T011-VERSN,
      IVKTOPL TYPE SKA1-KTOPL,
      IVSAKNR TYPE SKA1-SAKNR,
      IVERGSL TYPE RF011P-ERGSL,
      IVCOMMIT TYPE BAPI_COMMIT_WORK-COMMIT_WORK,
      IVWAIT TYPE BAPITA-WAIT,
      EVOK TYPE BOOLE-BOOLE.
  SWC_GET_ELEMENT CONTAINER 'IvVersn' IVVERSN.
  IF SY-SUBRC <> 0.
    MOVE '1020' TO IVVERSN.
  ENDIF.
  SWC_GET_ELEMENT CONTAINER 'IvKtopl' IVKTOPL.
  IF SY-SUBRC <> 0.
    MOVE '1000' TO IVKTOPL.
  ENDIF.
  SWC_GET_ELEMENT CONTAINER 'IvSaknr' IVSAKNR.
  SWC_GET_ELEMENT CONTAINER 'IvErgsl' IVERGSL.
  SWC_GET_ELEMENT CONTAINER 'IvCommit' IVCOMMIT.
  IF SY-SUBRC <> 0.
    MOVE ABAP_TRUE TO IVCOMMIT.
  ENDIF.
  SWC_GET_ELEMENT CONTAINER 'IvWait' IVWAIT.
  IF SY-SUBRC <> 0.
    MOVE ABAP_TRUE TO IVWAIT.
  ENDIF.
  CALL FUNCTION 'ZFI_GL_ASSIGN_FSV'
    EXPORTING
      IV_VERSN = IVVERSN
      IV_KTOPL = IVKTOPL
      IV_SAKNR = IVSAKNR
      IV_ERGSL = IVERGSL
      IV_COMMIT = IVCOMMIT
      IV_WAIT = IVWAIT
    IMPORTING
      EV_OK = EVOK
    EXCEPTIONS
      EX_NO_AUTHORITY = 9001
      EX_GL_NO_EXIST = 9002
      EX_LOAD_ERROR = 9003
      EX_READ_ERROR = 9004
      EX_LOCK_ERROR = 9005
      EX_SAVE_ERROR = 9006
      OTHERS = 01.
  CASE SY-SUBRC.
    WHEN 0.            " OK
    WHEN 9001.         " EX_NO_AUTHORITY
      EXIT_RETURN 9001 sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    WHEN 9002.         " EX_GL_NO_EXIST
      EXIT_RETURN 9002 sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    WHEN 9003.         " EX_LOAD_ERROR
      EXIT_RETURN 9003 sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    WHEN 9004.         " EX_READ_ERROR
      EXIT_RETURN 9004 sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    WHEN 9005.         " EX_LOCK_ERROR
      EXIT_RETURN 9005 sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    WHEN 9006.         " EX_SAVE_ERROR
      EXIT_RETURN 9006 sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    WHEN OTHERS.       " to be implemented
  ENDCASE.
  SWC_SET_ELEMENT CONTAINER 'EvOk' EVOK.
END_METHOD.

BEGIN_METHOD EXISTENCECHECK CHANGING CONTAINER.
DATA:
      RETURN LIKE BAPIRETURN.
  CALL FUNCTION 'BAPI_GL_ACC_EXISTENCECHECK'
    EXPORTING
      COMPANYCODE = OBJECT-KEY-COMPANYCODE
      GLACCT = object-key-glaccount
    IMPORTING
      RETURN = RETURN
    EXCEPTIONS
      OTHERS = 01.
  CASE SY-SUBRC.
    WHEN 0.            " OK
    WHEN OTHERS.       " to be implemented
  ENDCASE.
  SWC_SET_ELEMENT CONTAINER 'Return' RETURN.
END_METHOD.

