; is the source code - Here is the source code_
Documents
Resources
Learning Center
Upload
Plans & pricing Sign in
Sign Out
Your Federal Quarterly Tax Payments are due April 15th Get Help Now >>

is the source code - Here is the source code_

VIEWS: 164 PAGES: 37

  • pg 1
									REPORT   ZTEST.

TYPES: UPC_YS_API_CHASEL_T TYPE STANDARD TABLE OF
UPC_YS_API_CHASEL.
TYPES: UPC_YS_API_CHAPRO_T TYPE STANDARD TABLE OF
UPC_YS_API_CHAPRO.
TYPES: UPC_YS_API_KYFPRO_T TYPE STANDARD TABLE OF
UPC_YS_API_KYFPRO.

CLASS CL_ABAP_CONV_ROUTINE DEFINITION DEFERRED.

TYPES: BEGIN OF CONVEXIT_LOOKUP_S,
        CONVEXIT TYPE LVC_S_FCAT-CONVEXIT,
        O_CONVEXIT TYPE REF TO CL_ABAP_CONV_ROUTINE,
       END OF CONVEXIT_LOOKUP_S.

TYPES: CONVEXIT_LOOKUP_T TYPE HASHED TABLE OF
CONVEXIT_LOOKUP_S
        WITH UNIQUE KEY CONVEXIT.

TYPES: FIELDCATALOG_UNIQUE TYPE HASHED TABLE OF LVC_S_FCAT
         WITH UNIQUE KEY FIELDNAME.

TYPES: BEGIN OF PLAN_AREA_STRUCT_CACHE,
         PLANNING_AREA TYPE UPC_AREA-AREA,
         FIELDCATALOG TYPE LVC_T_FCAT,
         CHARACTERISTICS TYPE ZUPC_YS_API_CHAPRO_T,
         KEYFIGURES TYPE ZUPC_YS_API_KYFPRO_T,
         TRANSACTION_DATA_TABLE TYPE REF TO DATA,
       END OF PLAN_AREA_STRUCT_CACHE.

TYPES: PLAN_AREA_STRUCT_CACHE_T TYPE SORTED TABLE OF
PLAN_AREA_STRUCT_CACHE WITH UNIQUE KEY PLANNING_AREA.

*----------------------------------------------------------
-----------*
*       CLASS CX_DATE_CONVERSION DEFINITION
*----------------------------------------------------------
-----------*
*
*----------------------------------------------------------
-----------*
CLASS CX_DATE_CONVERSION DEFINITION INHERITING FROM
CX_DYNAMIC_CHECK.
  PUBLIC SECTION.
    DATA: MESSAGE TYPE STRING.
    METHODS CONSTRUCTOR
      IMPORTING MESSAGE TYPE STRING.
ENDCLASS.                   "CX_DATE_CONVERSION DEFINITION

*----------------------------------------------------------
-----------*
*       CLASS CX_DATE_CONVERSION IMPLEMENTATION
*----------------------------------------------------------
-----------*
*
*----------------------------------------------------------
-----------*
CLASS CX_DATE_CONVERSION IMPLEMENTATION.
  METHOD CONSTRUCTOR.
    SUPER->CONSTRUCTOR( ).
    ME->MESSAGE = MESSAGE.
  ENDMETHOD.                   "CONSTRUCTOR
ENDCLASS.                   "CX_DATE_CONVERSION
IMPLEMENTATION

*----------------------------------------------------------
-----------*
*       CLASS CL_ABAP_CONV_ROUTINE DEFINITION
*----------------------------------------------------------
-----------*
*
*----------------------------------------------------------
-----------*
CLASS CL_ABAP_CONV_ROUTINE DEFINITION.
  PUBLIC SECTION.

   METHODS APPLY_CONV_INPUT
     IMPORTING
       INPUT TYPE ANY
     EXPORTING
       OUTPUT TYPE ANY .
   METHODS APPLY_CONV_OUTPUT
     IMPORTING
       INPUT TYPE ANY
     EXPORTING
       OUTPUT TYPE ANY .
   METHODS GET_CONVEXIT
     RETURNING
       VALUE(CONVEXIT) TYPE CONVEXIT .
   METHODS SET_CONVEXIT
     IMPORTING
       VALUE(CONVEXIT) TYPE CONVEXIT .
   METHODS CONSTRUCTOR
     IMPORTING
       CONVEXIT TYPE CONVEXIT OPTIONAL .
 PRIVATE SECTION.

   DATA CONVEXIT TYPE CONVEXIT .

    METHODS GET_INPUT_CONVERSION_EXIT
      RETURNING
        VALUE(FUNCTION_MODULE_NAME) TYPE STRING .
    METHODS GET_OUTPUT_CONVERSION_EXIT
      RETURNING
        VALUE(FUNCTION_MODULE_NAME) TYPE STRING .
ENDCLASS.                   "CL_ABAP_CONV_ROUTINE
DEFINITION

*----------------------------------------------------------
-----------*
*       CLASS CL_ABAP_CONV_ROUTINE IMPLEMENTATION
*----------------------------------------------------------
-----------*
*
*----------------------------------------------------------
-----------*
CLASS CL_ABAP_CONV_ROUTINE IMPLEMENTATION.
  METHOD APPLY_CONV_INPUT .
    DATA: FUNCT_MOD TYPE STRING.

    IF NOT ME->CONVEXIT IS INITIAL.
* Only apply conversion routine if it exits
      CALL METHOD ME->GET_INPUT_CONVERSION_EXIT
        RECEIVING
          FUNCTION_MODULE_NAME = FUNCT_MOD.

      CALL FUNCTION FUNCT_MOD
        EXPORTING
           INPUT = INPUT
        IMPORTING
           OUTPUT = OUTPUT.
    ELSE.
* Can only hope this works
      OUTPUT = INPUT.
    ENDIF.
  ENDMETHOD.                    "APPLY_CONV_INPUT

 METHOD APPLY_CONV_OUTPUT.
   DATA: FUNCT_MOD TYPE STRING.
    IF NOT ME->CONVEXIT IS INITIAL.
* Only apply conversion routine if it exits
      CALL METHOD ME->GET_OUTPUT_CONVERSION_EXIT
        RECEIVING
          FUNCTION_MODULE_NAME = FUNCT_MOD.

      CALL FUNCTION FUNCT_MOD
        EXPORTING
           INPUT = INPUT
        IMPORTING
           OUTPUT = OUTPUT.
    ELSE.
* Can only hope this works
      OUTPUT = INPUT.
    ENDIF.
  ENDMETHOD.                    "APPLY_CONV_OUTPUT

 METHOD CONSTRUCTOR.
   IF CONVEXIT IS SUPPLIED.
     CALL METHOD ME->SET_CONVEXIT
       EXPORTING
          CONVEXIT = CONVEXIT.
   ENDIF.
 ENDMETHOD.                    "CONSTRUCTOR

 METHOD GET_CONVEXIT.
   CONVEXIT = ME->CONVEXIT.
 ENDMETHOD.                     "GET_CONVEXIT

 METHOD SET_CONVEXIT.
   ME->CONVEXIT = CONVEXIT.
 ENDMETHOD.                     "SET_CONVEXIT

  METHOD GET_INPUT_CONVERSION_EXIT.
* Generate standard conversion routines for input
conversion
* This is based on standard SAP ABAP help documentation
    CONCATENATE 'CONVERSION_EXIT_' ME->CONVEXIT
      '_INPUT' INTO FUNCTION_MODULE_NAME.
  ENDMETHOD.                   "GET_INPUT_CONVERSION_EXIT

  METHOD GET_OUTPUT_CONVERSION_EXIT.
* Generate standard conversion routines for output
conversion
* This is based on standard SAP ABAP help documentation
    CONCATENATE 'CONVERSION_EXIT_' ME->CONVEXIT
      '_OUTPUT' INTO FUNCTION_MODULE_NAME.
  ENDMETHOD.                   "GET_OUTPUT_CONVERSION_EXIT
ENDCLASS.                   "CL_ABAP_CONV_ROUTINE
IMPLEMENTATION
*----------------------------------------------------------
-----------*
*       CLASS CL_ABAP_CONV_DECIMAL DEFINITION
*----------------------------------------------------------
-----------*
*
*----------------------------------------------------------
-----------*
CLASS CL_ABAP_CONV_DECIMAL DEFINITION.
  PUBLIC SECTION.

    CLASS-DATA   SAP_DECIMAL_FMT_SPACE TYPE USR01-DCPFM VALUE
' '
READ-ONLY .
    CLASS-DATA   SAP_DECIMAL_FMT_X TYPE USR01-DCPFM VALUE 'X'
READ-ONLY .
    CLASS-DATA   SAP_DECIMAL_FMT_Y TYPE USR01-DCPFM VALUE 'Y'
READ-ONLY .
    CLASS-DATA   USER_DECIMAL_FORMAT TYPE USR01-DCPFM READ-
ONLY .

    CLASS-METHODS CLASS_CONSTRUCTOR .
    CLASS-METHODS CONVERT_DECIMAL_EXT2INT
      IMPORTING
        EXTERNAL_VALUE TYPE STRING
      CHANGING
        INTERNAL_VALUE TYPE P
      RAISING
        CX_SY_CONVERSION_OVERFLOW
        CX_SY_CONVERSION_NO_NUMBER .
    CLASS-METHODS CONVERT_DECIMAL_INT2EXT
      IMPORTING
        INTERNAL_VALUE TYPE P
      CHANGING
        EXTERNAL_VALUE TYPE STRING .
ENDCLASS.                   "CL_ABAP_CONV_DECIMAL
DEFINITION

*----------------------------------------------------------
-----------*
*       CLASS CL_ABAP_CONV_DECIMAL IMPLEMENTATION
*----------------------------------------------------------
-----------*
*
*----------------------------------------------------------
-----------*
CLASS CL_ABAP_CONV_DECIMAL IMPLEMENTATION.
  METHOD CLASS_CONSTRUCTOR .
    SELECT SINGLE DCPFM FROM USR01 INTO USER_DECIMAL_FORMAT
      WHERE BNAME = SY-UNAME.
  ENDMETHOD.                   "CLASS_CONSTRUCTOR
  METHOD CONVERT_DECIMAL_EXT2INT .
* THE GOAL IS TO GET THIS INTO INTERNAL FORMAT WHICH IS
EQUIVALENT TO
* EX. NNNNN.NN
    DATA: NUM_STR TYPE STRING.
    NUM_STR = EXTERNAL_VALUE.
    CONDENSE NUM_STR NO-GAPS.
    CASE USER_DECIMAL_FORMAT.
      WHEN SAP_DECIMAL_FMT_X.
        REPLACE ALL OCCURRENCES OF ',' IN NUM_STR WITH
SPACE.
        CONDENSE NUM_STR NO-GAPS.
      WHEN SAP_DECIMAL_FMT_SPACE.
        REPLACE ALL OCCURRENCES OF '.' IN NUM_STR WITH
SPACE.
        CONDENSE NUM_STR NO-GAPS.
        REPLACE ALL OCCURRENCES OF ',' IN NUM_STR WITH '.'.
      WHEN SAP_DECIMAL_FMT_Y.
        REPLACE ALL OCCURRENCES OF ',' IN NUM_STR WITH '.'.
    ENDCASE.
    INTERNAL_VALUE = NUM_STR.
  ENDMETHOD.                   "CONVERT_DECIMAL_EXT2INT
  METHOD CONVERT_DECIMAL_INT2EXT .
* THE GOAL IS TO GET THIS INTO EXTERNAL FORMAT WHICH IS
BASED ON SAP
* USER PROFILE SETTINGS
* CURRENT INPUT FORMAT EQUIVALENT IS EX. NNNNN.NN
    DATA: TEMP(70) TYPE C.
    WRITE INTERNAL_VALUE TO TEMP.
    EXTERNAL_VALUE = TEMP.
  ENDMETHOD.                   "CONVERT_DECIMAL_INT2EXT
ENDCLASS.                   "CL_ABAP_CONV_DECIMAL
IMPLEMENTATION

*----------------------------------------------------------
-----------*
*       CLASS CL_ABAP_CONV_DATE DEFINITION
*----------------------------------------------------------
-----------*
*
*----------------------------------------------------------
-----------*
CLASS CL_ABAP_CONV_DATE DEFINITION.
  PUBLIC SECTION.

    CLASS-DATA   SAP_DATE_FMT_5 TYPE USR01-DATFM VALUE '5'
READ-ONLY .
    CLASS-DATA   SAP_DATE_FMT_6 TYPE USR01-DATFM VALUE '6'
READ-ONLY .
    CLASS-DATA   SAP_DATE_FMT_3 TYPE USR01-DATFM VALUE '3'
READ-ONLY .
    CLASS-DATA   SAP_DATE_FMT_4 TYPE USR01-DATFM VALUE '4'
READ-ONLY .
    CLASS-DATA   SAP_DATE_FMT_1 TYPE USR01-DATFM VALUE '1'
READ-ONLY .
    CLASS-DATA   SAP_DATE_FMT_2 TYPE USR01-DATFM VALUE '2'
READ-ONLY .
    CLASS-DATA   USER_DATE_FORMAT TYPE USR01-DATFM READ-ONLY
.

    CLASS-METHODS CONVERT_DATE_EXT2INT
      IMPORTING
        EXTERNAL_DATE TYPE STRING
      RETURNING
        VALUE(INTERNAL_DATE) TYPE D
      RAISING
        CX_DATE_CONVERSION .
    CLASS-METHODS CONVERT_DATE_INT2EXT
      IMPORTING
        INTERNAL_DATE TYPE D
      RETURNING
        VALUE(EXTERNAL_DATE) TYPE STRING .
    CLASS-METHODS CLASS_CONSTRUCTOR .
ENDCLASS.                    "CL_ABAP_CONV_DATE DEFINITION

*----------------------------------------------------------
-----------*
*       CLASS CL_ABAP_CONV_DATE IMPLEMENTATION
*----------------------------------------------------------
-----------*
*
*----------------------------------------------------------
-----------*
CLASS CL_ABAP_CONV_DATE IMPLEMENTATION.
  METHOD CLASS_CONSTRUCTOR.
    SELECT SINGLE DATFM FROM USR01 INTO USER_DATE_FORMAT
      WHERE BNAME = SY-UNAME.
  ENDMETHOD.                   "CLASS_CONSTRUCTOR
  METHOD CONVERT_DATE_EXT2INT.
* HERE ARE THE CURRENT DATE FORMATS FROM SAP GUI
*1 DD.MM.YYYY
*2 MM/DD/YYYY
*3 MM-DD-YYYY
*4 YYYY.MM.DD
*5 YYYY/MM/DD
*6 YYYY-MM-DD

    DATA: PERMITTED_NUMBERS TYPE STRING VALUE '0123456789'.
    DATA: TEMP_DATE TYPE D.
    DATA: MESSAGE_VALID_NUMERICS TYPE STRING
      VALUE 'Only Numerics (0-9) are acceptable.'.
    DATA: MESSAGE_VALID_FORMAT TYPE STRING
      VALUE 'Invalid date format.'.

    IF STRLEN( EXTERNAL_DATE ) = 10.
      CASE USER_DATE_FORMAT.

        WHEN SAP_DATE_FMT_1.
          IF EXTERNAL_DATE+2(1) = '.' AND
EXTERNAL_DATE+5(1) = '.'.
            TEMP_DATE+0(4) = EXTERNAL_DATE+6(4). " YEAR
            TEMP_DATE+4(2) = EXTERNAL_DATE+3(2). " MONTH
            TEMP_DATE+6(2) = EXTERNAL_DATE+0(2). " DAY
            IF NOT ( TEMP_DATE CO PERMITTED_NUMBERS ).
              RAISE EXCEPTION TYPE CX_DATE_CONVERSION
                 EXPORTING MESSAGE =
MESSAGE_VALID_NUMERICS." ISSUE ERROR
            ENDIF.
          ELSE.
            RAISE EXCEPTION TYPE CX_DATE_CONVERSION
                 EXPORTING MESSAGE = MESSAGE_VALID_FORMAT. "
ISSUE ERROR
          ENDIF.

        WHEN SAP_DATE_FMT_2.
          IF EXTERNAL_DATE+2(1) = '/' AND
EXTERNAL_DATE+5(1) = '/'.
            TEMP_DATE+0(4) = EXTERNAL_DATE+6(4). " YEAR
            TEMP_DATE+4(2) = EXTERNAL_DATE+0(2). " MONTH
            TEMP_DATE+6(2) = EXTERNAL_DATE+3(2). " DAY
            IF NOT ( TEMP_DATE CO PERMITTED_NUMBERS ).
              RAISE EXCEPTION TYPE CX_DATE_CONVERSION
                EXPORTING MESSAGE = MESSAGE_VALID_NUMERICS.
" ISSUE
            ENDIF.
          ELSE.
            RAISE EXCEPTION TYPE CX_DATE_CONVERSION
                 EXPORTING MESSAGE = MESSAGE_VALID_FORMAT. "
ISSUE ERROR
          ENDIF.

        WHEN SAP_DATE_FMT_3.
          IF EXTERNAL_DATE+2(1) = '-' AND
EXTERNAL_DATE+5(1) = '-'.
            TEMP_DATE+0(4) = EXTERNAL_DATE+6(4). " YEAR
            TEMP_DATE+4(2) = EXTERNAL_DATE+0(2). " MONTH
            TEMP_DATE+6(2) = EXTERNAL_DATE+3(2). " DAY
            IF NOT ( TEMP_DATE CO PERMITTED_NUMBERS ).
              RAISE EXCEPTION TYPE CX_DATE_CONVERSION
                 EXPORTING MESSAGE =
MESSAGE_VALID_NUMERICS." ISSUE ERROR
            ENDIF.
          ELSE.
            RAISE EXCEPTION TYPE CX_DATE_CONVERSION
                 EXPORTING MESSAGE = MESSAGE_VALID_FORMAT. "
ISSUE ERROR
          ENDIF.

        WHEN SAP_DATE_FMT_4.
          IF EXTERNAL_DATE+4(1) = '.' AND
EXTERNAL_DATE+7(1) = '.'.
            TEMP_DATE+0(4) = EXTERNAL_DATE+0(4). " YEAR
            TEMP_DATE+4(2) = EXTERNAL_DATE+5(2). " MONTH
            TEMP_DATE+6(2) = EXTERNAL_DATE+8(2). " DAY
            IF NOT ( TEMP_DATE CO PERMITTED_NUMBERS ).
              RAISE EXCEPTION TYPE CX_DATE_CONVERSION
                 EXPORTING MESSAGE =
MESSAGE_VALID_NUMERICS." ISSUE ERROR
            ENDIF.
          ELSE.
            RAISE EXCEPTION TYPE CX_DATE_CONVERSION
                 EXPORTING MESSAGE = MESSAGE_VALID_FORMAT. "
ISSUE ERROR
          ENDIF.

        WHEN SAP_DATE_FMT_5.
          IF EXTERNAL_DATE+4(1) = '/' AND
EXTERNAL_DATE+7(1) = '/'.
            TEMP_DATE+0(4) = EXTERNAL_DATE+0(4). " YEAR
            TEMP_DATE+4(2) = EXTERNAL_DATE+5(2). " MONTH
            TEMP_DATE+6(2) = EXTERNAL_DATE+8(2). " DAY
            IF NOT ( TEMP_DATE CO PERMITTED_NUMBERS ).
              RAISE EXCEPTION TYPE CX_DATE_CONVERSION
                 EXPORTING MESSAGE =
MESSAGE_VALID_NUMERICS." ISSUE ERROR
            ENDIF.
          ELSE.
            RAISE EXCEPTION TYPE CX_DATE_CONVERSION
                 EXPORTING MESSAGE = MESSAGE_VALID_FORMAT. "
ISSUE ERROR
          ENDIF.

        WHEN SAP_DATE_FMT_6.
           IF EXTERNAL_DATE+4(1) = '-' AND
EXTERNAL_DATE+7(1) = '-'.
             TEMP_DATE+0(4) = EXTERNAL_DATE+0(4). " YEAR
             TEMP_DATE+4(2) = EXTERNAL_DATE+5(2). " MONTH
             TEMP_DATE+6(2) = EXTERNAL_DATE+8(2). " DAY
             IF NOT ( TEMP_DATE CO PERMITTED_NUMBERS ).
               RAISE EXCEPTION TYPE CX_DATE_CONVERSION
                  EXPORTING MESSAGE =
MESSAGE_VALID_NUMERICS." ISSUE ERROR
             ENDIF.
           ELSE.
             RAISE EXCEPTION TYPE CX_DATE_CONVERSION
                  EXPORTING MESSAGE = MESSAGE_VALID_FORMAT. "
ISSUE ERROR
           ENDIF.
      ENDCASE.
      INTERNAL_DATE = TEMP_DATE.
    ELSEIF STRLEN( EXTERNAL_DATE ) = 8.
* ASSUME NORMAL DATE FORMAT (YYYYMMDD)
      INTERNAL_DATE = EXTERNAL_DATE.
    ELSE.
      RAISE EXCEPTION TYPE CX_DATE_CONVERSION
        EXPORTING MESSAGE = MESSAGE_VALID_FORMAT. " ISSUE
ERROR
    ENDIF.
  ENDMETHOD.                     "CONVERT_DATE_EXT2INT
  METHOD CONVERT_DATE_INT2EXT.
* HERE ARE THE CURRENT DATE FORMATS FROM SAP GUI
*1   DD.MM.YYYY
*2   MM/DD/YYYY
*3   MM-DD-YYYY
*4   YYYY.MM.DD
*5   YYYY/MM/DD
*6   YYYY-MM-DD
    DATA: EXTERNAL_DATE_TEMP(10) TYPE C.
     WRITE INTERNAL_DATE TO EXTERNAL_DATE_TEMP.
     EXTERNAL_DATE = EXTERNAL_DATE_TEMP.
   ENDMETHOD.                   "CONVERT_DATE_INT2EXT
ENDCLASS.                    "CL_ABAP_CONV_DATE
IMPLEMENTATION
*----------------------------------------------------------
-----------*
*        CLASS CX_SEM_BPS_DATA_ACCESS DEFINITION
*----------------------------------------------------------
-----------*
*
*----------------------------------------------------------
-----------*
CLASS CX_SEM_BPS_DATA_ACCESS DEFINITION INHERITING FROM
CX_DYNAMIC_CHECK
  .
   PUBLIC SECTION.
     DATA: MESSAGE TYPE STRING.
     DATA: RETURN_T TYPE BAPIRET2_T.
     METHODS CONSTRUCTOR
       IMPORTING
         MESSAGE TYPE STRING
         RETURN_T TYPE BAPIRET2_T OPTIONAL.
ENDCLASS.                    "CX_SEM_BPS_DATA_ACCESS
DEFINITION

*----------------------------------------------------------
-----------*
*       CLASS CX_SEM_BPS_DATA_ACCESS IMPLEMENTATION
*----------------------------------------------------------
-----------*
*
*----------------------------------------------------------
-----------*
CLASS CX_SEM_BPS_DATA_ACCESS IMPLEMENTATION.
  METHOD CONSTRUCTOR.
    SUPER->CONSTRUCTOR( ).
    ME->MESSAGE = MESSAGE.
    ME->RETURN_T = RETURN_T.
  ENDMETHOD.                    "CONSTRUCTOR
ENDCLASS.                    "CX_SEM_BPS_DATA_ACCESS
IMPLEMENTATION
*----------------------------------------------------------
-----------*
*       CLASS CL_SEMBPS_DATA_ACCESSOR DEFINITION
*----------------------------------------------------------
-----------*
*
*----------------------------------------------------------
-----------*
CLASS CL_SEMBPS_DATA_ACCESSOR DEFINITION.
  PUBLIC SECTION.
    DATA TRANSACTION_DATA TYPE REF TO DATA .
    CLASS-DATA C_LEVEL TYPE UPC_PLEVEL-PLEVEL VALUE
'ZLABAP' READ-ONLY .
    CLASS-DATA C_LAYOUT TYPE UPP_PARAM-PARAM VALUE 'ZMABAP'
READ-ONLY .
    CLASS-DATA C_ADHOC_PACK TYPE UPC_PACKAGE-PPACKAGE VALUE
'0-ADHOC'
READ-ONLY .
    CLASS-DATA C_MULTIPLAN_AREA TYPE UPC_YS_API_CHAPRO-
CHANM VALUE
'_AREA_____' READ-ONLY .

   METHODS GET_INFOCUBE
     RETURNING
       VALUE(INFOCUBE) TYPE UPC_BW_AREA-INFOCUBE .
   METHODS GET_CHARACTERISTIC_SELECTIONS
     EXPORTING
       CHARACTERISTIC_SELECTION TYPE UPC_YS_API_CHASEL_T .
   METHODS REFRESH
     RAISING
       CX_SEM_BPS_DATA_ACCESS .
   METHODS CONSTRUCTOR
     IMPORTING
       PLANNING_AREA TYPE UPC_AREA-AREA
       IT_FIELDCATALOG TYPE LVC_T_FCAT
       TRANSACTION_DATA_TABLE TYPE REF TO DATA
       CHARACTERISTIC_SELECTION TYPE UPC_YS_API_CHASEL_T
     RAISING
       CX_SEM_BPS_DATA_ACCESS .
   METHODS GET_PLANNING_AREA
     RETURNING
       VALUE(PLANNING_AREA) TYPE UPC_AREA-AREA .
   METHODS GET_CHARACTERISTICS
     EXPORTING
       CHARACTERISTICS TYPE UPC_YS_API_CHAPRO_T .
   METHODS GET_KEYFIGURES
     EXPORTING
       KEYFIGURES TYPE UPC_YS_API_KYFPRO_T .
   METHODS SAVE
     RAISING
       CX_SEM_BPS_DATA_ACCESS .
    PRIVATE SECTION.

      DATA   CONVEXIT_LOOKUP TYPE CONVEXIT_LOOKUP_T .
      DATA   INFOCUBE TYPE UPC_BW_AREA-INFOCUBE .
      DATA   IT_FIELDCATALOG TYPE FIELDCATALOG_UNIQUE .
      DATA   PLANNING_AREA TYPE UPC_AREA-AREA .
      DATA   CHARACTERISTICS TYPE UPC_YS_API_CHAPRO_T .
      DATA   KEYFIGURES TYPE UPC_YS_API_KYFPRO_T .
      DATA   CHARACTERISTIC_SELECTION TYPE UPC_YS_API_CHASEL_T
.
    DATA LAYOUT_COL_SPEC TYPE STANDARD TABLE OF
UPC_YS_API_COL .

      CLASS-METHODS FORCE_ERROR_MESSAGE
        IMPORTING
          MESSAGE TYPE STRING OPTIONAL
          RETURN_STRUCT TYPE BAPIRET2 OPTIONAL
          RETURN_STRUCTS TYPE BAPIRET2_T OPTIONAL
        RAISING
          CX_SEM_BPS_DATA_ACCESS .
      CLASS-METHODS CHECK_MESSAGE
        IMPORTING
          E_SUBRC TYPE SY-SUBRC
          RETURN_STRUCT TYPE BAPIRET2
        RAISING
          CX_SEM_BPS_DATA_ACCESS .
      METHODS SET_CHARACTERISTIC_SELECTION
        IMPORTING
          CHARACTERISTIC_SELECTION TYPE UPC_YS_API_CHASEL_T .
      METHODS SET_PLANNING_AREA
        IMPORTING
          PLANNING_AREA TYPE UPC_AREA-AREA
        RAISING
          CX_SEM_BPS_DATA_ACCESS .
      METHODS VALIDATE_PLANNING_OBJECTS
        RAISING
          CX_SEM_BPS_DATA_ACCESS .
      CLASS-METHODS CHECK_MESSAGES
        IMPORTING
          RETURN_STRUCTS TYPE BAPIRET2_T
          E_SUBRC TYPE SY-SUBRC
        RAISING
          CX_SEM_BPS_DATA_ACCESS .
      METHODS READ_DATA
        RAISING
          CX_SEM_BPS_DATA_ACCESS .
ENDCLASS.                   "CL_SEMBPS_DATA_ACCESSOR
DEFINITION

*----------------------------------------------------------
-----------*
*       CLASS CL_SEMBPS_DATA_ACCESSOR IMPLEMENTATION
*----------------------------------------------------------
-----------*
*
*----------------------------------------------------------
-----------*
CLASS CL_SEMBPS_DATA_ACCESSOR IMPLEMENTATION.
  METHOD CONSTRUCTOR .
    DATA: WA_FIELDCATALOG TYPE LVC_S_FCAT.
    DATA: CONVEXIT_WA TYPE CONVEXIT_LOOKUP_S.

* BUILD CONVERSION EXITS AND FIELDCATALOG
    LOOP AT IT_FIELDCATALOG INTO WA_FIELDCATALOG.
      INSERT WA_FIELDCATALOG INTO TABLE ME-
>IT_FIELDCATALOG[].
      IF NOT WA_FIELDCATALOG-CONVEXIT IS INITIAL.
        CLEAR CONVEXIT_WA.
        CONVEXIT_WA-CONVEXIT = WA_FIELDCATALOG-CONVEXIT.
        CREATE OBJECT CONVEXIT_WA-O_CONVEXIT
             EXPORTING
               CONVEXIT = WA_FIELDCATALOG-CONVEXIT.
        INSERT CONVEXIT_WA INTO TABLE ME->CONVEXIT_LOOKUP.
      ENDIF.
    ENDLOOP.

   CALL METHOD ME->SET_PLANNING_AREA
     EXPORTING
       PLANNING_AREA = PLANNING_AREA.

    CALL METHOD ME->SET_CHARACTERISTIC_SELECTION
      EXPORTING
        CHARACTERISTIC_SELECTION =
CHARACTERISTIC_SELECTION.

* POINT TO TABLE CONTAINING TRANSACTION DATA
    ME->TRANSACTION_DATA = TRANSACTION_DATA_TABLE.

* READ DATA
    CALL METHOD ME->REFRESH.
  ENDMETHOD.                    "CONSTRUCTOR

 METHOD GET_CHARACTERISTICS .
   CHARACTERISTICS[] = ME->CHARACTERISTICS[].
 ENDMETHOD.                   "GET_CHARACTERISTICS

  METHOD GET_CHARACTERISTIC_SELECTIONS.
    CHARACTERISTIC_SELECTION[] = ME-
>CHARACTERISTIC_SELECTION[].
  ENDMETHOD.
"GET_CHARACTERISTIC_SELECTIONS

 METHOD GET_INFOCUBE .
   INFOCUBE = ME->INFOCUBE.
 ENDMETHOD.                   "GET_INFOCUBE

 METHOD GET_KEYFIGURES .
   KEYFIGURES[] = ME->KEYFIGURES[].
 ENDMETHOD.                   "GET_KEYFIGURES

 METHOD GET_PLANNING_AREA .
   PLANNING_AREA = ME->PLANNING_AREA.
 ENDMETHOD.                   "GET_PLANNING_AREA

 METHOD REFRESH.
   CALL METHOD ME->READ_DATA.
 ENDMETHOD.                   "REFRESH

  METHOD SAVE .
    DATA: E_SUBRC TYPE SY-SUBRC.
    DATA: ES_RETURN TYPE BAPIRET2.
    DATA: CHARACTERISTICS_WA TYPE UPC_YS_API_CHAPRO.
    DATA: WA_REF TYPE REF TO DATA.
    DATA: ITK_ROW TYPE TABLE OF UPC_YS_API_ROW.
    DATA: ITK_ROW_WA TYPE UPC_YS_API_ROW.
    DATA: LAYOUT_COL_SPEC_WA TYPE UPC_YS_API_COL.
    DATA: ITK_DATA TYPE TABLE OF UPC_YS_API_DATA.
    DATA: ITK_DATA_WA TYPE UPC_YS_API_DATA.
    DATA: ETK_RETURN TYPE TABLE OF BAPIRET2.
    DATA: WA_FIELDCATALOG TYPE LVC_S_FCAT.
    DATA: CONVERSION_EXIT TYPE STRING.
    DATA: KEYFIG TYPE STRING.
    DATA: DATE_CHAR TYPE STRING.
    DATA: MESSAGE TYPE STRING.
    CONSTANTS: FIND_FIELD_ERR TYPE STRING VALUE 'Unable to
find field'.

   FIELD-SYMBOLS: <TD_FIELD> TYPE ANY.
   FIELD-SYMBOLS: <TD_WA> TYPE ANY.
   FIELD-SYMBOLS: <TD_TAB> TYPE STANDARD TABLE.
   ASSIGN ME->TRANSACTION_DATA->* TO <TD_TAB>.
   CREATE DATA WA_REF LIKE LINE OF <TD_TAB>.
   ASSIGN WA_REF->* TO <TD_WA>.

   CLEAR <TD_WA>.

    DATA: ROWC TYPE I.
    ROWC = 1.
    LOOP AT <TD_TAB> INTO <TD_WA>.
* FILL CHARACTERISTIC DATA
      LOOP AT ME->CHARACTERISTICS INTO CHARACTERISTICS_WA.
        ASSIGN COMPONENT CHARACTERISTICS_WA-CHANM OF
STRUCTURE <TD_WA>
          TO <TD_FIELD>.
        IF SY-SUBRC = 0.
          ITK_ROW_WA-ROW = ROWC.
          ITK_ROW_WA-CHANM = CHARACTERISTICS_WA-CHANM.

          CLEAR ITK_ROW_WA-CHAVLEXT.
* APPLY OUTPUT CONVERSION EXIT FOR SAP EXTERNAL TYPE
* ONLY APPLIES WHEN VALUE IS NOT UNASSIGNED ('#') MEANING
INITIAL(ABAP)
* FOR EXTERNAL CONVERSION UNASSIGED ('#') IS JUST A BLANK
          IF NOT <TD_FIELD> IS INITIAL.
            READ TABLE ME->IT_FIELDCATALOG INTO
WA_FIELDCATALOG
              WITH TABLE KEY FIELDNAME = ITK_ROW_WA-CHANM.
            IF SY-SUBRC = 0 AND NOT WA_FIELDCATALOG-
CONVEXIT IS INITIAL.
              DATA: CONVEXIT_WA TYPE CONVEXIT_LOOKUP_S.
              READ TABLE ME->CONVEXIT_LOOKUP INTO
CONVEXIT_WA
                WITH TABLE KEY CONVEXIT = WA_FIELDCATALOG-
CONVEXIT.
              CALL METHOD CONVEXIT_WA-O_CONVEXIT-
>APPLY_CONV_OUTPUT
                EXPORTING
                   INPUT = <TD_FIELD>
                IMPORTING
                   OUTPUT = <TD_FIELD>.
              ITK_ROW_WA-CHAVLEXT = <TD_FIELD>.
            ELSEIF SY-SUBRC = 0 AND WA_FIELDCATALOG-INTTYPE
= 'D'.
* APPLY DATE CONVERSION TO EXTERNAL FORMAT BASED ON USER
PROFILE
               CALL METHOD
CL_ABAP_CONV_DATE=>CONVERT_DATE_INT2EXT
                 EXPORTING
                   INTERNAL_DATE = <TD_FIELD>
                 RECEIVING
                   EXTERNAL_DATE = DATE_CHAR.
               ITK_ROW_WA-CHAVLEXT = DATE_CHAR.
            ELSE.
               ITK_ROW_WA-CHAVLEXT = <TD_FIELD>.
            ENDIF.
          ENDIF.
          APPEND ITK_ROW_WA TO ITK_ROW.
        ELSE.
* FAILURE TO FIND THE FIELD IN THE POINTER WILL RESULT IN
* TRANSACTION DATA INTEGRITY ISSUES, WE SHOULD ERROR OUT
          CONCATENATE FIND_FIELD_ERR CHARACTERISTICS_WA-
CHANM
        INTO MESSAGE.
          CALL METHOD
CL_SEMBPS_DATA_ACCESSOR=>FORCE_ERROR_MESSAGE
            EXPORTING
               MESSAGE = MESSAGE.
        ENDIF.
      ENDLOOP.

* FILL KEY FIGURE DATA
      LOOP AT ME->LAYOUT_COL_SPEC INTO LAYOUT_COL_SPEC_WA.
        ASSIGN COMPONENT LAYOUT_COL_SPEC_WA-CHAVLEXT
          OF STRUCTURE <TD_WA> TO <TD_FIELD>.
        IF SY-SUBRC = 0.
          ITK_DATA_WA-ROW = ROWC.
          ITK_DATA_WA-COL = LAYOUT_COL_SPEC_WA-COL.

          READ TABLE ME->IT_FIELDCATALOG INTO
WA_FIELDCATALOG
            WITH TABLE KEY FIELDNAME = LAYOUT_COL_SPEC_WA-
CHAVLEXT.
          IF WA_FIELDCATALOG-INTTYPE = 'P'.
* MUST CONVERT TO EXTERNAL FORMAT FOR DECIMALS
            CALL METHOD
CL_ABAP_CONV_DECIMAL=>CONVERT_DECIMAL_INT2EXT
              EXPORTING
                INTERNAL_VALUE = <TD_FIELD>
              CHANGING
                EXTERNAL_VALUE = KEYFIG.
          ELSEIF WA_FIELDCATALOG-INTTYPE = 'F'
            OR WA_FIELDCATALOG-INTTYPE = 'I'.
             KEYFIG = <TD_FIELD>.
          ENDIF.
          ITK_DATA_WA-VALUE = KEYFIG.
          APPEND ITK_DATA_WA TO ITK_DATA.
        ELSE.
* FAILURE TO FIND THE FIELD IN THE POINTER WILL RESULT IN
* TRANSACTION DATA INTEGRITY ISSUES, WE SHOULD ERROR OUT
          CONCATENATE FIND_FIELD_ERR LAYOUT_COL_SPEC_WA-
CHAVLEXT
             INTO MESSAGE.
          CALL METHOD
CL_SEMBPS_DATA_ACCESSOR=>FORCE_ERROR_MESSAGE
             EXPORTING
               MESSAGE = MESSAGE.
        ENDIF.
      ENDLOOP.
      ROWC = ROWC + 1.
    ENDLOOP.

* SET ADHOC PACKAGE SELECTIONS
    CALL FUNCTION 'API_SEMBPS_ADHOCPACKAGE_SET'
      EXPORTING
        I_AREA     = ME->PLANNING_AREA
        I_PLEVEL   = CL_SEMBPS_DATA_ACCESSOR=>C_LEVEL
      IMPORTING
        E_SUBRC    = E_SUBRC
        ES_RETURN = ES_RETURN
      TABLES
        ITK_CHASEL = CHARACTERISTIC_SELECTION.

* THROW EXCEPTIONS IF NECESSARY
    CALL METHOD CL_SEMBPS_DATA_ACCESSOR=>CHECK_MESSAGE
      EXPORTING
        E_SUBRC       = E_SUBRC
        RETURN_STRUCT = ES_RETURN.

   CALL FUNCTION 'API_SEMBPS_SETDATA'
     EXPORTING
       I_AREA     = ME->PLANNING_AREA
       I_PLEVEL   = CL_SEMBPS_DATA_ACCESSOR=>C_LEVEL
       I_PACKAGE = CL_SEMBPS_DATA_ACCESSOR=>C_ADHOC_PACK
       I_LAYOUT   = CL_SEMBPS_DATA_ACCESSOR=>C_LAYOUT
     IMPORTING
       E_SUBRC    = E_SUBRC
     TABLES
       ITK_ROW    = ITK_ROW
       ITK_DATA   = ITK_DATA
       ETK_RETURN = ETK_RETURN.

* THROW EXCEPTIONS IF NECESSARY
    CALL METHOD CL_SEMBPS_DATA_ACCESSOR=>CHECK_MESSAGES
      EXPORTING
        E_SUBRC        = E_SUBRC
        RETURN_STRUCTS = ETK_RETURN.

* SAVE THE DATA INTO THE CUBE
    CALL FUNCTION 'API_SEMBPS_POST'
      IMPORTING
        E_SUBRC   = E_SUBRC
        ES_RETURN = ES_RETURN.

   CALL METHOD CL_SEMBPS_DATA_ACCESSOR=>CHECK_MESSAGE
     EXPORTING
       E_SUBRC       = E_SUBRC
       RETURN_STRUCT = ES_RETURN.

* CLEAR SEM BPS DATA BUFFER AS WEIRD BEHAVIOR MAY OCCUR IF
* NOT CLEARED WHETHER IF SUCCESSFUL OR NOT
    CALL FUNCTION 'API_SEMBPS_REFRESH'
      IMPORTING
        E_SUBRC   = E_SUBRC
        ES_RETURN = ES_RETURN.

   CALL METHOD CL_SEMBPS_DATA_ACCESSOR=>CHECK_MESSAGE
     EXPORTING
       E_SUBRC       = E_SUBRC
       RETURN_STRUCT = ES_RETURN.
 ENDMETHOD.                    "SAVE

 METHOD CHECK_MESSAGE .
   DATA: RETURN_T TYPE BAPIRET2_T.
   APPEND RETURN_STRUCT TO RETURN_T.
   CALL METHOD CL_SEMBPS_DATA_ACCESSOR=>CHECK_MESSAGES
     EXPORTING
       RETURN_STRUCTS = RETURN_T
       E_SUBRC        = E_SUBRC.
 ENDMETHOD.                   "CHECK_MESSAGE

  METHOD CHECK_MESSAGES .
    IF E_SUBRC <> 0.
      DATA: MESSAGE TYPE STRING.
      DATA: RETURN TYPE BAPIRET2.
      READ TABLE RETURN_STRUCTS INTO RETURN WITH KEY TYPE =
'E'.
      IF SY-SUBRC <> 0.
        READ TABLE RETURN_STRUCTS INTO RETURN WITH KEY TYPE
= 'A'.
      ENDIF.
      MESSAGE = RETURN-MESSAGE.
      RAISE EXCEPTION TYPE CX_SEM_BPS_DATA_ACCESS
        EXPORTING
           MESSAGE = MESSAGE
           RETURN_T = RETURN_STRUCTS.
    ENDIF.
  ENDMETHOD.                    "CHECK_MESSAGES

 METHOD FORCE_ERROR_MESSAGE.
   DATA: RC TYPE SY-SUBRC VALUE 4.
   IF MESSAGE IS SUPPLIED.
     DATA: RETURN TYPE BAPIRET2.
     RETURN-TYPE = 'E'.
     RETURN-MESSAGE = MESSAGE.
     CALL METHOD CL_SEMBPS_DATA_ACCESSOR=>CHECK_MESSAGE
       EXPORTING
          RETURN_STRUCT = RETURN
          E_SUBRC       = RC.
   ENDIF.
   IF RETURN_STRUCT IS SUPPLIED.
     CALL METHOD CL_SEMBPS_DATA_ACCESSOR=>CHECK_MESSAGE
       EXPORTING
          RETURN_STRUCT = RETURN_STRUCT
          E_SUBRC       = RC.
   ENDIF.
   IF RETURN_STRUCTS IS SUPPLIED.
     CALL METHOD CL_SEMBPS_DATA_ACCESSOR=>CHECK_MESSAGES
       EXPORTING
          RETURN_STRUCTS = RETURN_STRUCTS
          E_SUBRC        = RC.
   ENDIF.
 ENDMETHOD.                    "FORCE_ERROR_MESSAGE

 METHOD READ_DATA .
   DATA: CHAR_DATA TYPE TABLE OF UPC_YS_API_ROW.
   DATA: KEYFIG_DATA TYPE TABLE OF UPC_YS_API_DATA.
   DATA: ETK_ROW_WA TYPE UPC_YS_API_ROW.
   DATA: ETK_COL TYPE TABLE OF UPC_YS_API_COL.
   DATA: ETK_RETURN TYPE TABLE OF BAPIRET2.
   DATA: KEYFIGURES_WA TYPE UPC_YS_API_KYFPRO.
   DATA: E_SUBRC TYPE SY-SUBRC.
   DATA: ES_RETURN TYPE BAPIRET2.
   DATA: ETK_COL_WA TYPE UPC_YS_API_COL.
    DATA: WA_REF TYPE REF TO DATA.
    DATA: HAS_DATA TYPE BOOLEAN.
    DATA: KEYFIG_DATA_WA TYPE UPC_YS_API_DATA.
    DATA: LINE1 TYPE I.
    DATA: LINE2 TYPE I.
    DATA: MESSAGE TYPE STRING.
    CONSTANTS: FIND_FIELD_ERR TYPE STRING VALUE 'Unable to
find field '.

   FIELD-SYMBOLS: <TD_FIELD> TYPE ANY.
   FIELD-SYMBOLS: <TD_WA> TYPE ANY.
   FIELD-SYMBOLS: <TD_TAB> TYPE STANDARD TABLE.

   CALL FUNCTION 'API_SEMBPS_ADHOCPACKAGE_SET'
     EXPORTING
       I_AREA     = ME->PLANNING_AREA
       I_PLEVEL   = CL_SEMBPS_DATA_ACCESSOR=>C_LEVEL
     IMPORTING
       E_SUBRC    = E_SUBRC
       ES_RETURN = ES_RETURN
     TABLES
       ITK_CHASEL = ME->CHARACTERISTIC_SELECTION.

   CALL METHOD CL_SEMBPS_DATA_ACCESSOR=>CHECK_MESSAGE
     EXPORTING
       E_SUBRC       = E_SUBRC
       RETURN_STRUCT = ES_RETURN.

   CALL FUNCTION 'API_SEMBPS_GETDATA'
     EXPORTING
       I_AREA      = ME->PLANNING_AREA
       I_PLEVEL    = CL_SEMBPS_DATA_ACCESSOR=>C_LEVEL
       I_PACKAGE   = CL_SEMBPS_DATA_ACCESSOR=>C_ADHOC_PACK
       I_LAYOUT    = CL_SEMBPS_DATA_ACCESSOR=>C_LAYOUT
       I_READ_ONLY = 'X'
     IMPORTING
       E_SUBRC     = E_SUBRC
     TABLES
       ETK_ROW     = CHAR_DATA
       ETK_COL     = ETK_COL
       ETK_DATA    = KEYFIG_DATA
       ETK_RETURN = ETK_RETURN.

   CALL METHOD CL_SEMBPS_DATA_ACCESSOR=>CHECK_MESSAGES
     EXPORTING
       E_SUBRC        = E_SUBRC
       RETURN_STRUCTS = ETK_RETURN.
* SET LAYOUT COLUMN SPECIFICATION
    ME->LAYOUT_COL_SPEC[] = ETK_COL[].

* CHECK TO SEE IF THE COLUMN SPEC CONTAINS ALL KEY FIGURES
REQUIRED
* THIS WOULD GUARANTEE THAT ALL THE KEY FIGURES PRESENT IN
THE CUBE
* ARE ALSO IN THE LAYOUT
    DESCRIBE TABLE ME->KEYFIGURES LINES LINE1.
    DESCRIBE TABLE ME->LAYOUT_COL_SPEC LINES LINE2.
    IF LINE1 <> LINE2.
      LOOP AT ME->KEYFIGURES INTO KEYFIGURES_WA.
        READ TABLE ME->LAYOUT_COL_SPEC
           WITH KEY CHAVLEXT = KEYFIGURES_WA-KYFNM
           TRANSPORTING NO FIELDS.
        IF SY-SUBRC <> 0.
           CLEAR ES_RETURN.
           ES_RETURN-TYPE = 4.
           CONCATENATE 'Layout '
CL_SEMBPS_DATA_ACCESSOR=>C_LAYOUT
             ' is missing keyfigure: ' KEYFIGURES_WA-KYFNM
             INTO ES_RETURN-MESSAGE.
           APPEND ES_RETURN TO ETK_RETURN.
        ENDIF.
      ENDLOOP.
      CALL METHOD
CL_SEMBPS_DATA_ACCESSOR=>FORCE_ERROR_MESSAGE
        EXPORTING
           RETURN_STRUCTS = ETK_RETURN.
    ENDIF.

* CLEAR TRANSACTION DATA IF ANY
    ASSIGN TRANSACTION_DATA->* TO <TD_TAB>.
    REFRESH <TD_TAB>.

   CREATE DATA WA_REF LIKE LINE OF <TD_TAB>.
   ASSIGN WA_REF->* TO <TD_WA>.

   DATA:   PREV_ROWID TYPE UPC_YS_API_ROW-ROW VALUE 1.
   DATA:   WA_FIELDCATALOG TYPE LVC_S_FCAT.
   DATA:   CONVERSION_EXIT TYPE STRING.
   DATA:   DECIMAL_CONV TYPE STRING.
   DATA:   DATE_CONV TYPE STRING.
   CLEAR   <TD_WA>.

* SORT DATA
   SORT KEYFIG_DATA BY ROW.
   SORT ETK_COL BY COL.
   SORT CHAR_DATA BY ROW.

* INSERT ALL CHARACTERISTIC ROWS
    LOOP AT CHAR_DATA INTO ETK_ROW_WA.
      IF ETK_ROW_WA-CHANM IS NOT INITIAL.
        IF ETK_ROW_WA-ROW <> PREV_ROWID.
          CLEAR HAS_DATA.
          PREV_ROWID = ETK_ROW_WA-ROW.
          APPEND <TD_WA> TO <TD_TAB>.
          CLEAR <TD_WA>.
        ENDIF.
        HAS_DATA = 'X'.
        ASSIGN COMPONENT ETK_ROW_WA-CHANM OF STRUCTURE
          <TD_WA> TO <TD_FIELD>.
        IF SY-SUBRC = 0.
          CLEAR <TD_FIELD>.
          IF ETK_ROW_WA-CHAVLEXT <> '#'.
* APPLY INPUT CONVERSION EXIT FOR SAP INTERNAL DATA
ELEMENTS
* ONLY APPLIES WHEN VALUE IS NOT UNASSIGNED ('#')
            READ TABLE ME->IT_FIELDCATALOG INTO
WA_FIELDCATALOG
               WITH TABLE KEY FIELDNAME = ETK_ROW_WA-CHANM.
            IF SY-SUBRC = 0 AND NOT WA_FIELDCATALOG-
CONVEXIT IS INITIAL.
               <TD_FIELD> = ETK_ROW_WA-CHAVLEXT.
* APPLY INPUT CONVERSION EXIT IF ANY, CHECK INFOOBJECT RSD1
TRANSACTION
               DATA: CONVEXIT_WA TYPE CONVEXIT_LOOKUP_S.
               READ TABLE ME->CONVEXIT_LOOKUP INTO
CONVEXIT_WA
                 WITH TABLE KEY CONVEXIT = WA_FIELDCATALOG-
CONVEXIT.
               CALL METHOD CONVEXIT_WA-O_CONVEXIT-
>APPLY_CONV_INPUT
                 EXPORTING
                    INPUT = <TD_FIELD>
                 IMPORTING
                    OUTPUT = <TD_FIELD>.
            ELSEIF SY-SUBRC = 0 AND WA_FIELDCATALOG-INTTYPE
= 'D'.
* APPLY DATE CONVERSION AS THERE IS NO COVERSION EXIT FOR
DATES DUE TO
* SAPGUI DISPLAY FORMATS BASED ON USER PROFILES
               TRY.
                    DATE_CONV = ETK_ROW_WA-CHAVLEXT.
                    CALL METHOD
CL_ABAP_CONV_DATE=>CONVERT_DATE_EXT2INT
                      EXPORTING
                        EXTERNAL_DATE = DATE_CONV
                      RECEIVING
                        INTERNAL_DATE = <TD_FIELD>.
                  CATCH CX_DATE_CONVERSION .
* THERE SHOULD BE NO DATE CONVERSION ERROR.
               ENDTRY.
             ELSE.
               <TD_FIELD> = ETK_ROW_WA-CHAVLEXT.
             ENDIF.
           ENDIF.
        ELSE.
* FAILURE TO FIND THE FIELD IN THE POINTER WILL RESULT IN
* TRANSACTION DATA INTEGRITY ISSUES, WE SHOULD ERROR OUT
           CONCATENATE FIND_FIELD_ERR ETK_ROW_WA-CHANM
             INTO MESSAGE.
           CALL METHOD
CL_SEMBPS_DATA_ACCESSOR=>FORCE_ERROR_MESSAGE
             EXPORTING
               MESSAGE = MESSAGE.
        ENDIF.
      ENDIF.
    ENDLOOP.
* APPEND THE LAST ROW
    IF HAS_DATA IS NOT INITIAL.
      APPEND <TD_WA> TO <TD_TAB>.
    ENDIF.

* INSERT ALL KEY FIGURES
    LOOP AT KEYFIG_DATA INTO KEYFIG_DATA_WA.
      READ TABLE <TD_TAB> INTO <TD_WA> INDEX
KEYFIG_DATA_WA-ROW.
      IF SY-SUBRC <> 0.
* SUMMARY LINE WHICH INDICATES COMPLETION
        EXIT.
      ENDIF.
* AVAILABLE KEY FIGURES
      READ TABLE ETK_COL INTO ETK_COL_WA
        INDEX KEYFIG_DATA_WA-COL.
      ASSIGN COMPONENT ETK_COL_WA-CHAVLEXT OF STRUCTURE
        <TD_WA> TO <TD_FIELD>.
      IF SY-SUBRC = 0.
        READ TABLE ME->IT_FIELDCATALOG INTO WA_FIELDCATALOG
          WITH TABLE KEY FIELDNAME = ETK_COL_WA-CHAVLEXT.
        IF WA_FIELDCATALOG-INTTYPE = 'P'.
          DECIMAL_CONV = KEYFIG_DATA_WA-VALUE.
          CALL METHOD
CL_ABAP_CONV_DECIMAL=>CONVERT_DECIMAL_EXT2INT
             EXPORTING
               EXTERNAL_VALUE = DECIMAL_CONV
             CHANGING
               INTERNAL_VALUE = <TD_FIELD>.
        ELSEIF WA_FIELDCATALOG-INTTYPE = 'F' OR
          WA_FIELDCATALOG-INTTYPE = 'I'.
          <TD_FIELD> = KEYFIG_DATA_WA-VALUE.
        ENDIF.
        MODIFY <TD_TAB> INDEX KEYFIG_DATA_WA-ROW FROM
<TD_WA>
          TRANSPORTING (ETK_COL_WA-CHAVLEXT) .
      ELSE.
* FAILURE TO FIND THE FIELD IN THE POINTER WILL RESULT IN
* TRANSACTION DATA INTEGRITY ISSUES, WE SHOULD ERROR OUT
        CONCATENATE FIND_FIELD_ERR ETK_ROW_WA-CHANM
          INTO MESSAGE.
        CALL METHOD
CL_SEMBPS_DATA_ACCESSOR=>FORCE_ERROR_MESSAGE
          EXPORTING
             MESSAGE = MESSAGE.
      ENDIF.
    ENDLOOP.
  ENDMETHOD.                    "READ_DATA

  METHOD SET_CHARACTERISTIC_SELECTION.
    DATA: CHARACTERISTIC_SELECTION_WA TYPE
UPC_YS_API_CHASEL.
    DATA: WA_FIELDCATALOG TYPE LVC_S_FCAT.
    DATA: CONV_EXIT TYPE STRING.
    DATA: DATE_CONV TYPE STRING.
    DATA: TEMP_DATE TYPE D.

* basically convert the selection criteria to external
values and hold
* copy of that
    REFRESH ME->CHARACTERISTIC_SELECTION.

    LOOP AT CHARACTERISTIC_SELECTION INTO
CHARACTERISTIC_SELECTION_WA.
      READ TABLE ME->IT_FIELDCATALOG INTO WA_FIELDCATALOG
        WITH TABLE KEY FIELDNAME =
CHARACTERISTIC_SELECTION_WA-CHANM.
      IF SY-SUBRC = 0.
        IF NOT WA_FIELDCATALOG-CONVEXIT IS INITIAL.
          DATA: CONVEXIT_WA TYPE CONVEXIT_LOOKUP_S.
          READ TABLE ME->CONVEXIT_LOOKUP INTO CONVEXIT_WA
             WITH TABLE KEY CONVEXIT = WA_FIELDCATALOG-
CONVEXIT.
          CALL METHOD CONVEXIT_WA-O_CONVEXIT-
>APPLY_CONV_OUTPUT
             EXPORTING
               INPUT = CHARACTERISTIC_SELECTION_WA-LOW
             IMPORTING
               OUTPUT = CHARACTERISTIC_SELECTION_WA-LOW.
          CALL METHOD CONVEXIT_WA-O_CONVEXIT-
>APPLY_CONV_OUTPUT
             EXPORTING
               INPUT = CHARACTERISTIC_SELECTION_WA-HIGH
             IMPORTING
               OUTPUT = CHARACTERISTIC_SELECTION_WA-HIGH.
        ELSEIF WA_FIELDCATALOG-INTTYPE = 'D'.
* DATE TYPE CONVERSION BASED ON SAP GUI
          IF NOT CHARACTERISTIC_SELECTION_WA-LOW IS
INITIAL.
             TEMP_DATE = CHARACTERISTIC_SELECTION_WA-LOW.
             CALL METHOD
CL_ABAP_CONV_DATE=>CONVERT_DATE_INT2EXT
               EXPORTING
                 INTERNAL_DATE = TEMP_DATE
               RECEIVING
                 EXTERNAL_DATE = DATE_CONV.
             CHARACTERISTIC_SELECTION_WA-LOW = DATE_CONV.
          ENDIF.
          IF NOT CHARACTERISTIC_SELECTION_WA-HIGH IS
INITIAL.
             TEMP_DATE = CHARACTERISTIC_SELECTION_WA-HIGH.
             CALL METHOD
CL_ABAP_CONV_DATE=>CONVERT_DATE_INT2EXT
               EXPORTING
                 INTERNAL_DATE = TEMP_DATE
               RECEIVING
                 EXTERNAL_DATE = DATE_CONV.
             CHARACTERISTIC_SELECTION_WA-HIGH = DATE_CONV.
          ENDIF.
        ENDIF.
        APPEND CHARACTERISTIC_SELECTION_WA TO
ME->CHARACTERISTIC_SELECTION.
      ENDIF.
    ENDLOOP.
  ENDMETHOD.
"SET_CHARACTERISTIC_SELECTION

 METHOD SET_PLANNING_AREA.
   DATA: ES_RETURN TYPE BAPIRET2.
   DATA: E_SUBRC TYPE SY-SUBRC.

* CHECK TO SEE OF PLANNING AREA IS A MULTI-PLANNING AREA
    CALL FUNCTION 'API_SEMBPS_AREA_GETDETAIL'
      EXPORTING
        I_AREA     = PLANNING_AREA
      IMPORTING
        E_SUBRC    = E_SUBRC
        ES_RETURN = ES_RETURN
      TABLES
        ETK_CHAPRO = ME->CHARACTERISTICS
        ETK_KYFPRO = ME->KEYFIGURES.

   CALL METHOD CL_SEMBPS_DATA_ACCESSOR=>CHECK_MESSAGE
     EXPORTING
       E_SUBRC       = E_SUBRC
       RETURN_STRUCT = ES_RETURN.

   ME->PLANNING_AREA = PLANNING_AREA.

* FIND THE INFOCUBE RELATED TO THE PLANNING AREA
    SELECT SINGLE INFOCUBE FROM UPC_BW_AREA INTO ME-
>INFOCUBE
      WHERE AREA = PLANNING_AREA.

   CALL METHOD ME->VALIDATE_PLANNING_OBJECTS.
 ENDMETHOD.                   "SET_PLANNING_AREA

 METHOD VALIDATE_PLANNING_OBJECTS.
   DATA: E_SUBRC TYPE SY-SUBRC.
   DATA: ES_RETURN TYPE BAPIRET2.
   DATA: ES_RETURN_T TYPE TABLE OF BAPIRET2.
   DATA: ETK_CHA TYPE TABLE OF UPC_YS_API_PLEVEL_CHA.
   DATA: ETK_CHA_WA TYPE UPC_YS_API_PLEVEL_CHA.
   DATA: CHARACTERISTIC_WA TYPE UPC_YS_API_CHAPRO.
   DATA: KEYFIGURES_WA TYPE UPC_YS_API_KYFPRO.
   DATA: ETK_CHASEL TYPE TABLE OF UPC_YS_API_CHASEL.
   DATA: ETK_KYF TYPE TABLE OF UPC_YS_KYF.
   DATA: ETK_RETURN TYPE TABLE OF BAPIRET2.
   DATA: LINES1 TYPE I.
   DATA: LINES2 TYPE I.
    DATA: E_LEADCOL_COMPL TYPE UPC_YS_API_INFO-
LEADCOL_COMPL.
    DATA: ETK_HEAD_INFO TYPE TABLE OF UPC_YS_API_HEAD_INFO.
    DATA: ETK_ROW_INFO TYPE TABLE OF UPC_YS_API_ROW_INFO.
    DATA: ETK_COL_INFO TYPE TABLE OF UPC_YS_API_COL_INFO.

* CHECK TO SEE IF ITS A MULTI-PLANNING AREA
    READ TABLE ME->CHARACTERISTICS TRANSPORTING NO FIELDS
      WITH KEY CHANM =
CL_SEMBPS_DATA_ACCESSOR=>C_MULTIPLAN_AREA.
* MULTI-PLANNING AREAS SHOULD NOT BE ACCEPTABLE TO THIS AS
IT LEADS
* TO REFERENCING OF PLANNING AREAS IN ITS
LEVEL/PACKAGES/LAYOUTS WHICH
* IS HARDER TO MAINTAIN
    IF SY-SUBRC = 0.
      REFRESH ME->CHARACTERISTICS.
      REFRESH ME->KEYFIGURES.
      CLEAR ES_RETURN.
      ES_RETURN-TYPE = 'E'.
      ES_RETURN-MESSAGE = 'DO NOT USE MULTI-PLANNING
AREAS'.
      APPEND ES_RETURN TO ES_RETURN_T.
      CALL METHOD
CL_SEMBPS_DATA_ACCESSOR=>FORCE_ERROR_MESSAGE
        EXPORTING
           RETURN_STRUCTS = ES_RETURN_T.
    ENDIF.

* CHECK THE PLANNING LEVEL
    CALL FUNCTION 'API_SEMBPS_PLEVEL_GETDETAIL'
      EXPORTING
        I_AREA     = ME->PLANNING_AREA
        I_PLEVEL   = CL_SEMBPS_DATA_ACCESSOR=>C_LEVEL
      IMPORTING
        E_SUBRC    = E_SUBRC
        ES_RETURN = ES_RETURN
      TABLES
        ETK_CHA    = ETK_CHA
        ETK_CHASEL = ETK_CHASEL
        ETK_KYF    = ETK_KYF.

   CALL METHOD CL_SEMBPS_DATA_ACCESSOR=>CHECK_MESSAGE
     EXPORTING
       E_SUBRC       = E_SUBRC
       RETURN_STRUCT = ES_RETURN.
* CHECK TO SEE IF THE SAME NUMBER OF CHARACTERISTICS EXISTS
IN LEVEL
    DESCRIBE TABLE ME->CHARACTERISTICS LINES LINES1.
    DESCRIBE TABLE ETK_CHA LINES LINES2.

    IF LINES1 <> LINES2.
* ERROR OUT THE MISSING CHARACTERISTICS FROM THE PLANNING
LEVEL
      LOOP AT ME->CHARACTERISTICS INTO CHARACTERISTIC_WA.
        READ TABLE ETK_CHA WITH KEY CHANM =
CHARACTERISTIC_WA-CHANM
           TRANSPORTING NO FIELDS.
        IF SY-SUBRC <> 0.
           CLEAR ES_RETURN.
           ES_RETURN-TYPE = 'E'.
           CONCATENATE 'Missing characteristic '
CHARACTERISTIC_WA-CHANM
             ' from planning level '
CL_SEMBPS_DATA_ACCESSOR=>C_LEVEL
             INTO ES_RETURN-MESSAGE.
           APPEND ES_RETURN TO ES_RETURN_T.
        ENDIF.
      ENDLOOP.
    ENDIF.

* CHECK TO SEE IF EVERY CHARACTERISTIC IS AVAIABLE FOR
SELECTION IN
* PACKAGE
    READ TABLE ETK_CHA WITH KEY PACKSEL = SPACE
TRANSPORTING NO FIELDS.

    IF SY-SUBRC = 0.
* ERROR OUT THE CHARACTERISTICS THAT ARE NOT AVAILABLE FOR
PACKAGE
* SELECTIONS
      LOOP AT ETK_CHA INTO ETK_CHA_WA WHERE PACKSEL =
SPACE.
        CLEAR ES_RETURN.
        ES_RETURN-TYPE = 'E'.
        CONCATENATE 'Characteristic ' ETK_CHA_WA-CHANM
           ' needs to be available for selection in planning
level '
           CL_SEMBPS_DATA_ACCESSOR=>C_LEVEL INTO ES_RETURN-
MESSAGE.
        APPEND ES_RETURN TO ES_RETURN_T.
      ENDLOOP.
    ENDIF.
* CHECK TO SEE IF THE SAME NUMBER OF KEYFIGURES EXISTS IN
LEVEL
    DESCRIBE TABLE ME->KEYFIGURES LINES LINES1.
    DESCRIBE TABLE ETK_KYF LINES LINES2.

    IF LINES1 <> LINES2.
* ERROR OUT THE MISSING KEYFIGURES FROM THE PLANNING LEVEL
      LOOP AT ME->KEYFIGURES INTO KEYFIGURES_WA.
        READ TABLE ETK_KYF WITH KEY KYFNM = KEYFIGURES_WA-
KYFNM
           TRANSPORTING NO FIELDS.
        IF SY-SUBRC <> 0.
           CLEAR ES_RETURN.
           ES_RETURN-TYPE = 'E'.
           CONCATENATE 'Missing keyfigure ' KEYFIGURES_WA-
KYFNM
             ' from planning level '
CL_SEMBPS_DATA_ACCESSOR=>C_LEVEL
             INTO ES_RETURN-MESSAGE.
           APPEND ES_RETURN TO ES_RETURN_T.
        ENDIF.
      ENDLOOP.
    ENDIF.

* CHECK THE PLANNING LAYOUT
    CALL FUNCTION 'API_SEMBPS_LAYOUT_GETDETAIL'
      EXPORTING
        I_AREA          = ME->PLANNING_AREA
        I_PLEVEL        = CL_SEMBPS_DATA_ACCESSOR=>C_LEVEL
        I_LAYOUT        = CL_SEMBPS_DATA_ACCESSOR=>C_LAYOUT
      IMPORTING
        E_SUBRC         = E_SUBRC
        E_LEADCOL_COMPL = E_LEADCOL_COMPL
      TABLES
        ETK_HEAD_INFO   = ETK_HEAD_INFO
        ETK_ROW_INFO    = ETK_ROW_INFO
        ETK_COL_INFO    = ETK_COL_INFO
        ETK_RETURN      = ETK_RETURN.

   CALL METHOD CL_SEMBPS_DATA_ACCESSOR=>CHECK_MESSAGES
     EXPORTING
       E_SUBRC        = E_SUBRC
       RETURN_STRUCTS = ETK_RETURN.

* MAKE SURE THAT HEADER AREA IS EMPTY AS ALL THE DATA READ
IS IN LEAD
* COLUMNS ONLY
    IF NOT ETK_HEAD_INFO[] IS INITIAL.
      CLEAR ES_RETURN.
      ES_RETURN-TYPE = 'E'.
      CONCATENATE 'Header area must be empty in layout '
        CL_SEMBPS_DATA_ACCESSOR=>C_LAYOUT
        INTO ES_RETURN-MESSAGE.
      APPEND ES_RETURN TO ES_RETURN_T.
    ENDIF.

* MAKE SURE THAT LAYOUT TYPE IS KEY FIGURES IN DATA COLUMNS
    IF NOT E_LEADCOL_COMPL IS INITIAL.
      CLEAR ES_RETURN.
      ES_RETURN-TYPE = 'E'.
      CONCATENATE 'Layout '
CL_SEMBPS_DATA_ACCESSOR=>C_LAYOUT
        ' must be of type "Key Figs in data columns"'
        INTO ES_RETURN-MESSAGE.
      APPEND ES_RETURN TO ES_RETURN_T.
    ENDIF.

* CHECK FOR THE SAME NUMBER OF CHARACTERISTICS IN LEAD
COLUMNS OF LAYOUT
* AND IN PLANNING AREA
    DESCRIBE TABLE ME->CHARACTERISTICS LINES LINES1.
    DESCRIBE TABLE ETK_ROW_INFO LINES LINES2.

    IF LINES1 <> LINES2.
* ERROR OUT THE MISSING CHARACTERISTICS FROM THE PLANNING
LEVEL
      LOOP AT ME->CHARACTERISTICS INTO CHARACTERISTIC_WA.
        READ TABLE ETK_ROW_INFO WITH KEY CHANM =
CHARACTERISTIC_WA-CHANM
           TRANSPORTING NO FIELDS.
        IF SY-SUBRC <> 0.
           CLEAR ES_RETURN.
           ES_RETURN-TYPE = 'E'.
           CONCATENATE 'Missing characteristic '
CHARACTERISTIC_WA-CHANM
             ' from planning layout '
CL_SEMBPS_DATA_ACCESSOR=>C_LAYOUT
             INTO ES_RETURN-MESSAGE.
           APPEND ES_RETURN TO ES_RETURN_T.
        ENDIF.
      ENDLOOP.
    ENDIF.
* IF MESSAGES ARE AVAILBLE FROM CUSTOM CHECKS THROW
EXCEPTION
    IF NOT ES_RETURN_T[] IS INITIAL.
      CALL METHOD
CL_SEMBPS_DATA_ACCESSOR=>FORCE_ERROR_MESSAGE
        EXPORTING
           RETURN_STRUCTS = ES_RETURN_T.
    ENDIF.
  ENDMETHOD.                    "VALIDATE_PLANNING_OBJECTS

ENDCLASS.                   "CL_SEMBPS_DATA_ACCESSOR
IMPLEMENTATION

*----------------------------------------------------------
-----------*
*       CLASS CL_SEMBPS_DATA_ACCESS_FACTORY DEFINITION
*----------------------------------------------------------
-----------*
*
*----------------------------------------------------------
-----------*
CLASS CL_SEMBPS_DATA_ACCESS_FACTORY DEFINITION.
  PUBLIC SECTION.

    CLASS-METHODS CREATE_DATA_ACCESSOR
      IMPORTING
        PLAN_AREA TYPE UPC_AREA-AREA
        CHARACTERISTIC_SELECTION TYPE UPC_YS_API_CHASEL_T
        DDIC_STRUCTURE_NAME TYPE DD02L-TABNAME OPTIONAL
      EXPORTING
        O_DATA_ACCESSOR TYPE REF TO CL_SEMBPS_DATA_ACCESSOR
      CHANGING
        TRANSACTION_DATA_TABLE TYPE STANDARD TABLE OPTIONAL
      RAISING
        CX_SEM_BPS_DATA_ACCESS .
    CLASS-METHODS GET_PLANNING_AREA_SPECS
      IMPORTING
        PLANNING_AREA TYPE UPC_AREA-AREA
      EXPORTING
        TRANSACTION_DATA_STRUCT TYPE REF TO DATA
        KEYFIGURES TYPE UPC_YS_API_KYFPRO_T
        FIELDCATALOG TYPE LVC_T_FCAT
        CHARACTERISTICS TYPE UPC_YS_API_CHAPRO_T
      RAISING
        CX_SEM_BPS_DATA_ACCESS .

  PRIVATE SECTION.
    CLASS-DATA PLAN_AREA_CACHE TYPE
PLAN_AREA_STRUCT_CACHE_T .

    CLASS-METHODS CREATE_DYNAMIC_STRUCTURE
      IMPORTING
        PLANNING_AREA TYPE UPC_AREA-AREA
      EXPORTING
        TRANSACTION_DATA_STRUCT TYPE REF TO DATA
        KEYFIGURES TYPE UPC_YS_API_KYFPRO_T
        FIELDCATALOG TYPE LVC_T_FCAT
        CHARACTERISTICS TYPE UPC_YS_API_CHAPRO_T
      RAISING
        CX_SEM_BPS_DATA_ACCESS .

ENDCLASS.                   "CL_SEMBPS_DATA_ACCESS_FACTORY
DEFINITION

*----------------------------------------------------------
-----------*
*       CLASS CL_SEMBPS_DATA_ACCESS_FACTORY IMPLEMENTATION
*----------------------------------------------------------
-----------*
*
*----------------------------------------------------------
-----------*
CLASS CL_SEMBPS_DATA_ACCESS_FACTORY IMPLEMENTATION.
  METHOD CREATE_DATA_ACCESSOR.
    DATA: TRANSACTION_DATA_STRUCT TYPE REF TO DATA.
    DATA: FIELDCATALOG TYPE LVC_T_FCAT.

    IF TRANSACTION_DATA_TABLE IS SUPPLIED
      AND DDIC_STRUCTURE_NAME IS SUPPLIED AND
      NOT DDIC_STRUCTURE_NAME IS INITIAL.
* RETRIEVE FIELD CATALOG OF THE DDIC STRUCTURE TO PROVIDE
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          I_STRUCTURE_NAME        = DDIC_STRUCTURE_NAME
        CHANGING
          CT_FIELDCAT             = FIELDCATALOG
        EXCEPTIONS
          INCONSISTENT_INTERFACE = 1
          PROGRAM_ERROR           = 2
          OTHERS                  = 3.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      GET REFERENCE OF TRANSACTION_DATA_TABLE INTO
TRANSACTION_DATA_STRUCT.

    ELSE.

* GENERATE INTERNAL TABLE AND ITS FIELD CATALOG DYNAMICALLY
      CALL METHOD
CL_SEMBPS_DATA_ACCESS_FACTORY=>GET_PLANNING_AREA_SPECS
        EXPORTING
           PLANNING_AREA           = PLAN_AREA
        IMPORTING
           TRANSACTION_DATA_STRUCT = TRANSACTION_DATA_STRUCT
           FIELDCATALOG            = FIELDCATALOG.
    ENDIF.

* CREATE DATA ACCESSOR
    CREATE OBJECT O_DATA_ACCESSOR
      EXPORTING
        PLANNING_AREA = PLAN_AREA
        IT_FIELDCATALOG = FIELDCATALOG
        TRANSACTION_DATA_TABLE = TRANSACTION_DATA_STRUCT
        CHARACTERISTIC_SELECTION =
CHARACTERISTIC_SELECTION.

  ENDMETHOD.                   "CREATE_DATA_ACCESSOR

  METHOD GET_PLANNING_AREA_SPECS.
    DATA: PLAN_AREA_CACHE_WA TYPE PLAN_AREA_STRUCT_CACHE.
    FIELD-SYMBOLS: <TD_TAB_DEFINITION> TYPE STANDARD TABLE.

    READ TABLE PLAN_AREA_CACHE
      WITH TABLE KEY PLANNING_AREA = PLANNING_AREA
      INTO PLAN_AREA_CACHE_WA.

* CREATE INTERNAL TABLE REFLECTING THE PLANNING AREA AND
CACHE IT
* TO AVOID TOO MANY CALLS TO CREATION OF DYNAMIC INTERNAL
TABLES
* SAP HAS RESTRICTED DEVELOPERS FROM CREATING
    IF SY-SUBRC <> 0.
      CLEAR PLAN_AREA_CACHE_WA.
      CALL METHOD
CL_SEMBPS_DATA_ACCESS_FACTORY=>CREATE_DYNAMIC_STRUCTURE
        EXPORTING
          PLANNING_AREA           = PLANNING_AREA
        IMPORTING
          TRANSACTION_DATA_STRUCT =
PLAN_AREA_CACHE_WA-TRANSACTION_DATA_TABLE
          KEYFIGURES              = PLAN_AREA_CACHE_WA-
KEYFIGURES
          FIELDCATALOG            = PLAN_AREA_CACHE_WA-
FIELDCATALOG
          CHARACTERISTICS         = PLAN_AREA_CACHE_WA-
CHARACTERISTICS.

     PLAN_AREA_CACHE_WA-PLANNING_AREA = PLANNING_AREA.

     INSERT PLAN_AREA_CACHE_WA INTO TABLE PLAN_AREA_CACHE.
   ENDIF.

   FIELDCATALOG[] = PLAN_AREA_CACHE_WA-FIELDCATALOG.

    CHARACTERISTICS[] = PLAN_AREA_CACHE_WA-
CHARACTERISTICS[].

   KEYFIGURES[] = PLAN_AREA_CACHE_WA-KEYFIGURES[].

   ASSIGN PLAN_AREA_CACHE_WA-TRANSACTION_DATA_TABLE->*
     TO <TD_TAB_DEFINITION>.

* CREATE A NEW REFERENCE
    CREATE DATA TRANSACTION_DATA_STRUCT LIKE
      <TD_TAB_DEFINITION>.
  ENDMETHOD.                   "GET_PLANNING_AREA_SPECS

 METHOD CREATE_DYNAMIC_STRUCTURE.
   DATA: ES_RETURN TYPE BAPIRET2.
   DATA: E_SUBRC TYPE SY-SUBRC.
   DATA: MESSAGE TYPE STRING.

   CALL FUNCTION 'API_SEMBPS_AREA_GETDETAIL'
     EXPORTING
       I_AREA     = PLANNING_AREA
     IMPORTING
       E_SUBRC    = E_SUBRC
       ES_RETURN = ES_RETURN
     TABLES
       ETK_CHAPRO = CHARACTERISTICS
       ETK_KYFPRO = KEYFIGURES.

   IF E_SUBRC <> 0.
     MESSAGE = ES_RETURN-MESSAGE.
     RAISE EXCEPTION TYPE CX_SEM_BPS_DATA_ACCESS
       EXPORTING MESSAGE = MESSAGE.
   ENDIF.

    READ TABLE CHARACTERISTICS TRANSPORTING NO FIELDS
      WITH KEY CHANM =
CL_SEMBPS_DATA_ACCESSOR=>C_MULTIPLAN_AREA.

   IF SY-SUBRC = 0.
     MESSAGE = 'DO NOT USE MULTI-PLANNING AREAS'.
     RAISE EXCEPTION TYPE CX_SEM_BPS_DATA_ACCESS
       EXPORTING MESSAGE = MESSAGE.
   ENDIF.

   DATA:   CHAR_WA TYPE UPC_YS_API_CHAPRO.
   DATA:   KEYFIG_WA TYPE UPC_YS_API_KYFPRO.
   DATA:   WA_FIELDCATALOG TYPE LVC_S_FCAT.
   DATA:   RETURN TYPE BAPIRET2.
   DATA:   DETAILS TYPE BAPI6108.

* CHARACTERISTIC FIELDCATALOG
    LOOP AT CHARACTERISTICS INTO CHAR_WA.
      WA_FIELDCATALOG-INTTYPE = CHAR_WA-INTTP.
      WA_FIELDCATALOG-FIELDNAME = CHAR_WA-CHANM.
      WA_FIELDCATALOG-DATATYPE = CHAR_WA-DATATP.
      WA_FIELDCATALOG-INTLEN = CHAR_WA-INTLEN.
      WA_FIELDCATALOG-DECIMALS = CHAR_WA-DECIMALS.
      WA_FIELDCATALOG-OUTPUTLEN = CHAR_WA-OUTPUTLEN.
      CALL FUNCTION 'BAPI_IOBJ_GETDETAIL'
        EXPORTING
          INFOOBJECT = CHAR_WA-CHANM
        IMPORTING
          DETAILS    = DETAILS
          RETURN     = RETURN.
      IF RETURN-TYPE = 'E'.
        MESSAGE = RETURN-MESSAGE.
        RAISE EXCEPTION TYPE CX_SEM_BPS_DATA_ACCESS
          EXPORTING MESSAGE = MESSAGE.
      ENDIF.
      WA_FIELDCATALOG-CONVEXIT = DETAILS-CONVEXIT.
      APPEND WA_FIELDCATALOG TO FIELDCATALOG.
    ENDLOOP.

* KEYFIGURE FIELDCATALOG
    LOOP AT KEYFIGURES INTO KEYFIG_WA.
      WA_FIELDCATALOG-INTTYPE = KEYFIG_WA-INTTP.
      WA_FIELDCATALOG-FIELDNAME = KEYFIG_WA-KYFNM.
      WA_FIELDCATALOG-DATATYPE = KEYFIG_WA-DATATP.
     WA_FIELDCATALOG-INTLEN = KEYFIG_WA-DIGITS.
     WA_FIELDCATALOG-DECIMALS = KEYFIG_WA-DECIMALS.
     WA_FIELDCATALOG-DD_OUTLEN = KEYFIG_WA-OUTPUTLEN.
     CALL FUNCTION 'BAPI_IOBJ_GETDETAIL'
       EXPORTING
         INFOOBJECT = KEYFIG_WA-KYFNM
       IMPORTING
         DETAILS    = DETAILS
         RETURN     = RETURN.
     IF RETURN-TYPE = 'E'.
       MESSAGE = RETURN-MESSAGE.
       RAISE EXCEPTION TYPE CX_SEM_BPS_DATA_ACCESS
         EXPORTING MESSAGE = MESSAGE.
     ENDIF.
     WA_FIELDCATALOG-CONVEXIT = DETAILS-CONVEXIT.
     APPEND WA_FIELDCATALOG TO FIELDCATALOG.
   ENDLOOP.

* AVOID TOO MANY CALLS TO THIS FUNCTION MODULE
    IF NOT FIELDCATALOG[] IS INITIAL.
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
           IT_FIELDCATALOG           = FIELDCATALOG
        IMPORTING
           EP_TABLE                  =
TRANSACTION_DATA_STRUCT
        EXCEPTIONS
           GENERATE_SUBPOOL_DIR_FULL = 1
           OTHERS                    = 2.
      CASE SY-SUBRC.
        WHEN 1.
           RAISE EXCEPTION TYPE CX_SEM_BPS_DATA_ACCESS
EXPORTING
               MESSAGE = 'Dynamic table creation failure on
subpool'.
        WHEN 2.
           RAISE EXCEPTION TYPE CX_SEM_BPS_DATA_ACCESS
EXPORTING
               MESSAGE = 'Dynamic table creation failure'.
      ENDCASE.
    ENDIF.
  ENDMETHOD.                    "CREATE_DYNAMIC_STRUCTURE
ENDCLASS.            "CL_SEMBPS_DATA_ACCESS_FACTORY
IMPLEMENTATION

								
To top