Skip to end of metadata
Go to start of metadata
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
FUNCTION Z_SEM_BPS_EXIT_FILE_LOAD.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(I_AREA) TYPE  UPC_Y_AREA
*"     REFERENCE(I_PLEVEL) TYPE  UPC_Y_PLEVEL
*"     REFERENCE(I_METHOD) TYPE  UPC_Y_METHOD
*"     REFERENCE(I_PARAM) TYPE  UPC_Y_PARAM
*"     REFERENCE(I_PACKAGE) TYPE  UPC_Y_PACKAGE
*"     REFERENCE(IT_EXITP) TYPE  UPF_YT_EXITP
*"     REFERENCE(ITO_CHASEL) TYPE  UPC_YTO_CHASEL
*"     REFERENCE(ITO_CHA) TYPE  UPC_YTO_CHA
*"     REFERENCE(ITO_KYF) TYPE  UPC_YTO_KYF
*"  EXPORTING
*"     REFERENCE(ET_MESG) TYPE  UPC_YT_MESG
*"  CHANGING
*"     REFERENCE(XTH_DATA) TYPE  HASHED TABLE
*"----------------------------------------------------------------------

  DATA: lt_data TYPE yt_data,
        ls_data TYPE ys_data.

  DATA: ls_file TYPE ys_file.

  DATA: ls_chasel TYPE upc_ys_chasel,
        ls_charng TYPE upc_ys_charng.

  FIELD-SYMBOLS: <f> TYPE ANY.

* >>> INSERT: Amount conversion
  DATA:
    ls_mesg       TYPE upc_ys_mesg,
    l_dummy       TYPE c LENGTH 50,
    l_amount      TYPE p LENGTH 16 DECIMALS 5,
    ls_curx       TYPE tcurx,
    lt_curx       TYPE HASHED TABLE OF tcurx WITH UNIQUE KEY currkey.

  FIELD-SYMBOLS:
    <curr>        TYPE c,
    <ratio>       TYPE ANY.

* Get number of decimal places
  SELECT * FROM tcurx INTO TABLE lt_curx.
* <<< INSERT

* Has any data been loaded?
  CHECK NOT gt_file[] IS INITIAL.

* Overwrite existing data or add to existing data?
* Change the IF depending on which alternative you require
  IF 1 = 1.                              " <<<< ADJUST
    REFRESH lt_data.                     " Delete and overwrite existing data
  ELSE.
    lt_data = xth_data.                  " Keep existing data
  ENDIF.

* Map and merge loaded data
  LOOP AT gt_file INTO ls_file.
    CHECK sy-tabix > 1.                  " Skip first line with field names
    CLEAR ls_data.
    MOVE-CORRESPONDING ls_file TO ls_data-s_chas. " Map characteristics
    MOVE-CORRESPONDING ls_file TO ls_data-s_kyfs. " Map key figures

* >>> INSERT: Amount conversion

*   Adjust the field names here and use this code for each amount key figure...
    ASSIGN COMPONENT '0D_REVEN' OF STRUCTURE ls_data-s_kyfs TO <ratio>.
    ASSERT sy-subrc = 0.

    ASSIGN COMPONENT '0CURRENCY' OF STRUCTURE ls_data-s_chas TO <curr>.
    ASSERT sy-subrc = 0.

    READ TABLE lt_curx INTO ls_curx WITH TABLE KEY currkey = <curr>.
    IF sy-subrc = 0.
      CATCH SYSTEM-EXCEPTIONS: arithmetic_errors = 1 OTHERS = 2.
        l_amount = <ratio>.
        l_amount = l_amount * ( 10 ** ( ls_curx-currdec - 2 ) ).
        <ratio> = l_amount.
      ENDCATCH.
      IF sy-subrc <> 0.
        MESSAGE e065(upf) WITH '0D_REVEN' INTO l_dummy.
        MOVE-CORRESPONDING syst TO ls_mesg.
        APPEND ls_mesg TO et_mesg.
      ENDIF.
    ENDIF.
* <<< INSERT

*   Set fixed fields
    LOOP AT ito_chasel INTO ls_chasel.
      READ TABLE ls_chasel-t_charng INTO ls_charng INDEX 1.
      IF sy-subrc = 0 AND ls_charng-option = 'EQ'.
        ASSIGN COMPONENT ls_chasel-chanm OF STRUCTURE ls_data-s_chas TO <f>.
        IF sy-subrc = 0.
          <f> = ls_charng-low.
        ENDIF.
      ENDIF.
    ENDLOOP.

    COLLECT ls_data INTO lt_data.
  ENDLOOP.

* Return loaded data to BPS
  xth_data = lt_data.

* Clear temporary table
  REFRESH gt_file.

ENDFUNCTION.