Skip to Content
0
Apr 20, 2007 at 08:53 AM

Hi Profit center descriptions

391 Views

Hi Experts,

For this design only profit centers under the following level 4 nodes will need to be extracted and sent to PROS SOI7CR0326 , SOI7FU0763 , SOI7FU0764 , SOI7FU0765. All profit centers under these nodes will need to be sent although only level 4, level 6, and level 7 descriptions should be sent for each profit center. I used transaction KCH3 to view the hierarchy below.

I need descriptions for all the profit centers for the above mentioned nodes, please see the code and give me some solution.

    5  SOI_STREAM      Downstream                                                                                
4  SOI4000011      DOWNSTREAM (OIL)                                                        
        4  SOI5000001      DOWNSTREAM REFINING 1 PEER GRP                                          
        4  SOI5000002      DOWNSTREAM REFINING 2 PEER GRP                                          
        4  SOI5000003      DOWNSTREAM COMMERCIAL PEER GRP                                          
        5  SOI5000004      DOWNSTREAM RETAIL PEER GROUP                                                                                
4  SOI6AC0001      ACCELERATOR BUSINESS UNIT                                           
            4  SOI6CR0001      US CONVENIENCE OPERATIONS                                           
            5  SOI6FU0001      US FUELS OPERATING UNIT                                                                                
5  SOI7FU0692      SECONDARY TRANS / PIPELINE                                      
                5  SOI7FU0762      RESTRUCTURING HIERARCHY                                         
                5 <b> SOI7FU0763</b>      US FUELS MARKETING - EAST/GULF COAST         <--           Level 4 Description                                                                                
5  SOI7FU0766      EGC FUELS SUPPLY GEOGRAPHY                                                                                
5  SOI7FU0017      NORTHEAST GEOGRAPHY                                     <--          Level 6 Description
                                                                                18026650   EAST S&H OPPORTUNITY PROJECTS EXPENSE       <--          Level 7 Description                                                                                
5  SOI7FU0033      NEW YORK HARBOR - SUPPLY ENVELOPE                                                                                
5  SOI7FU0034      TERMINALS&SUPPLYPLANTS -NEW YORK HARBOR                                                                                
5  SOI7FU0174      GASOLINE - NEW YORK HARBOR                                                                                
18000063   MA FIELD DISTRIBUTION                           
                                        18000070   WASHINGTON DC-20003 (LPOB)                      
                                        18000361   WILMINGTON DE-19801 (LPOB)                      
                                        18000371   CORAOPOLIS PA-15108 (LPOB)                      
                                        18000396   PHILADELPHIA PA-EXXON (LTOZ)                    
                                        18004753   BROOKLYN TERMINAL 

*-----------------------------------------------------------------*
* This program can be used to export profit center hierarchies or other groups in a level table (format used by RGSIMPH1)
* To actively use this program:
*   - copy it to a local object
*   - adapt DATA_TAB to the data structure in your foreign system
*     (change positions, length of fields, remove TOVALUE if
*      hierarchies contain single values only, ...)
*   - write an export routine for DATA_TAB if you don't want to
*     download it to the presentation server
*
* Example hierarchy that will be exported by this program
*
*    HIER-TOP                      Top node
*      |
*      |---- HIER-010              Node 10
*      |       |
*      |       |---- HIER-011      Node 11
*      |       |       - CC 1      Profit center 1
*      |       |       - CC 2      Profit center 2
*      |       |
*      |        ---- HIER-012      Node 12
*      |               - CC 3      Profit center 3
*      |               - CC 4      Profit center 4
*      |
*       ---- HIER-020              Node 20
*              - CC 5              Profit center 5
*
* The level table  DATA_TAB will look like this:
*
*    Level  Groupname    Fromvalue  Tovalue           Descript
*    0001   HIER-TOP                                  Top node
*    0002   HIER-010                                  Node 10
*    0003   HIER-011                                  Node 11
*    0004                CC 1       CC 1
*    0004                CC 2       CC 2
*    0003   HIER-012                                  Node 12
*    0004                CC 3       CC 3
*    0004                CC 4       CC 4
*    0002   HIER-020                                  Node 20
*    0003                CC 5       CC 5
*-----------------------------------------------------------------------
*  Standard Architecture Data Structures
*----------------------------------------------------------------------
INCLUDE: zbiod001,
         zbiud002,
         zbiud007.
DATA: c_text_write(5) TYPE c VALUE 'Write'.

TABLES: CEPC,
        CEPCT.

*------------------------ Data ---------------------------------*
DATA: I_CEPCT  LIKE CEPCT OCCURS 0 WITH HEADER LINE,
      WA_CEPCT LIKE CEPCT,
      I_CEPC   LIKE CEPC OCCURS 0 WITH HEADER LINE,
      WA_CEPC  LIKE CEPC.

DATA: W_OBJECTID LIKE CDHDR-OBJECTID,
      W_LEVEL_CODE(30) TYPE C,
      W_LEVEL_NAME(50) TYPE C,
      W_LEVEL_CODE1(30) TYPE C,
      W_LEVEL_NAME1(50) TYPE C.

DATA: BEGIN OF I_PROFIT OCCURS 10,
  ID(15)                TYPE C,
  CODE(10)                 TYPE C,
  NAME(20)                 TYPE C,
  DESC(40)                 TYPE C,
  HIER_LVL1_CODE(30)       TYPE C,
  HIER_LVL1_NAME(50)       TYPE C,
  HIER_LVL2_CODE(30)       TYPE C,
  HIER_LVL2_NAME(50)       TYPE C,
  HIER_LVL3_CODE(30)       TYPE C,
  HIER_LVL3_NAME(50)       TYPE C,
  HIER_LVL4_CODE(30)       TYPE C,
  HIER_LVL4_NAME(50)       TYPE C,
  HIER_LVL5_CODE(30)       TYPE C,
  HIER_LVL5_NAME(50)       TYPE C,
  HIER_LVL6_CODE(30)       TYPE C,
  HIER_LVL6_NAME(50)       TYPE C,
  HIER_LVL7_CODE(30)       TYPE C,
  HIER_LVL7_NAME(50)       TYPE C,
  HIER_LVL8_CODE(30)       TYPE C,
  HIER_LVL8_NAME(50)       TYPE C,
  HIER_LVL9_CODE(30)       TYPE C,
  HIER_LVL9_NAME(50)       TYPE C,
  HIER_LVL10_CODE(30)      TYPE C,
  HIER_LVL10_NAME(50)      TYPE C,
  HIER_LVL11_CODE(30)      TYPE C,
  HIER_LVL11_NAME(50)      TYPE C,
  CREATED_BY(15)                         TYPE C,
  CREATED_DATE(10)                       TYPE C,
  LAST_UPDATED_BY(15)                    TYPE C,
  LAST_UPDATED_DATE(10)                  TYPE C,
  BATCH_ID(15)                           TYPE C,
  STAGE2_DIM_ID(15)        TYPE C,
  SOURCE_SYSTEM_ID(20)                   TYPE C,
  ALT_ACCOUNT_SET_HIERARCHY_IND(1)       TYPE C,
END OF I_PROFIT.

*Structure required by Essbase. Str_PC1.TXT
DATA: BEGIN OF I_STR_PC1 OCCURS 10,
  HIER_LVL1_CODE(30)       TYPE C,
  FILLER1(1)                TYPE C VALUE '|',
  HIER_LVL1_NAME(50)       TYPE C,
  FILLER2(1)                TYPE C VALUE '|',
  HIER_LVL2_CODE(30)       TYPE C,
  FILLER3(1)                TYPE C VALUE '|',
  HIER_LVL2_NAME(50)       TYPE C,
  FILLER4(1)                TYPE C VALUE '|',
  HIER_LVL3_CODE(30)       TYPE C,
  FILLER5(1)                TYPE C VALUE '|',
  HIER_LVL3_NAME(50)       TYPE C,
  FILLER6(1)                TYPE C VALUE '|',
  HIER_LVL4_CODE(30)       TYPE C,
  FILLER7(1)                TYPE C VALUE '|',
  HIER_LVL4_NAME(50)       TYPE C,
  FILLER8(1)                TYPE C VALUE '|',
  HIER_LVL5_CODE(30)       TYPE C,
  FILLER9(1)                TYPE C VALUE '|',
  HIER_LVL5_NAME(50)       TYPE C,
  FILLER10(1)                TYPE C VALUE '|',
  HIER_LVL6_CODE(30)       TYPE C,
  FILLER11(1)                TYPE C VALUE '|',
  HIER_LVL6_NAME(50)       TYPE C,
  FILLER12(1)                TYPE C VALUE '|',
  HIER_LVL7_CODE(30)       TYPE C,
  FILLER13(1)                TYPE C VALUE '|',
  HIER_LVL7_NAME(50)       TYPE C,
  FILLER14(1)                TYPE C VALUE '|',
  HIER_LVL8_CODE(30)       TYPE C,
  FILLER15(1)                TYPE C VALUE '|',
  HIER_LVL8_NAME(50)       TYPE C,
  FILLER16(1)                TYPE C VALUE '|',
  HIER_LVL9_CODE(30)       TYPE C,
  FILLER17(1)                TYPE C VALUE '|',
  HIER_LVL9_NAME(50)       TYPE C,
  FILLER18(1)                TYPE C VALUE '|',
  HIER_LVL10_CODE(30)      TYPE C,
  FILLER19(1)                TYPE C VALUE '|',
  HIER_LVL10_NAME(50)      TYPE C,
  FILLER20(1)                TYPE C VALUE '|',
  HIER_LVL11_CODE(30)      TYPE C,
  FILLER21(1)                TYPE C VALUE '|',
  HIER_LVL11_NAME(50)      TYPE C,
  FILLER22(1)                TYPE C VALUE '|',
  CODE(10)                 TYPE C,
  FILLER23(1)                TYPE C VALUE '|',
  DESC(40)                 TYPE C,
  FILLER24(1)                TYPE C VALUE '|',
  NAME(20)                 TYPE C,
  FILLER25(1)                TYPE C VALUE '|',
END OF I_STR_PC1.

*Variable declaration
DATA: CTR(2) TYPE C,
      INC TYPE I,
      W_CTR1(2) TYPE C,
      W_INC1 TYPE I.

DATA: w_file_prft LIKE w_prc_files.

*Field symbols.
  FIELD-SYMBOLS: <CD1>,
                 <NM1>.

* External level table will be using the following structure
DATA: BEGIN OF data_tab OCCURS 0,
        level(4)      TYPE n,          "level in hierarchy
        groupname     LIKE grpdynp-name_coall, "name of node
        fromvalue     LIKE setvalues-from,  "From-Value of interval
        tovalue       LIKE setvalues-to,    "To-Value of interval
        descript      LIKE sethier-descript,"description of this entry
      END OF data_tab.

*Constants
CONSTANTS: c_setclass LIKE sethier-setclass VALUE '01++'.

*------------------------ SelectionScreen--------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
* Parameters
PARAMETERS: g_setid   LIKE sethier-setid OBLIGATORY MEMORY ID gse.
SELECTION-SCREEN END OF BLOCK B1.

* Tables to read sets
DATA: sethier   LIKE sethier OCCURS 0 WITH HEADER LINE,  "hierar. nodes
      setvalues LIKE setvalues OCCURS 0 WITH HEADER LINE, "hier. values
      g_setval_index LIKE sy-tabix,    "index for setvalues,
      g_int     TYPE i,
      g_rc      TYPE c,
      g_old_file LIKE lgrwo-exp_file.

*------------------------ AT Selection screen----------------------*
AT SELECTION-SCREEN.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR g_setid.
* Value request for group name
  CALL FUNCTION 'G_RW_SET_SELECT'
       EXPORTING
            class           = c_setclass
            set             = g_setid
            typelist        = 'BS'
            show_field_name = ' '
            show_table_name = ' '
       IMPORTING
            setid           = g_setid
            set_name        = g_setid.


*peform to read profit center hierarchy
PERFORM READ_SETHIER.

*perform to change the output format to flat file format
PERFORM PROFIT_CENTER_HIER.

*Fill remaining details from profit center master tables
PERFORM FILL_PRCTR_DETAILS.

*perform to download the details
PERFORM F_WRITE_TO_FILE.

FORM READ_SETHIER.
* Preparations: check authority to read sets
    CALL FUNCTION 'G_SET_OR_GROUP_AUTHORITY'
         EXPORTING
              i_setid = g_setid
              i_actvt = '03'.

* Read set
  REFRESH: sethier, setvalues.
  CALL FUNCTION 'G_SET_TREE_IMPORT'
       EXPORTING
            no_rw_info    = 'X'
            setid         = g_setid
       TABLES
            set_hierarchy = sethier
            set_values    = setvalues.

* Copy set into DATA_TAB
  REFRESH data_tab.
  g_setval_index = 1.
  LOOP AT sethier.
    CLEAR data_tab.
    data_tab-level = sethier-level.
    data_tab-groupname = sethier-shortname.
    data_tab-descript = sethier-descript.
    APPEND data_tab.
    CHECK sethier-vcount > 0.
    CLEAR data_tab.
    data_tab-level = sethier-level + 1.
    g_int = g_setval_index + sethier-vcount - 1.
    LOOP AT setvalues FROM g_setval_index TO g_int.
      data_tab-fromvalue = setvalues-from.
      data_tab-tovalue = setvalues-to.
      data_tab-descript = setvalues-descript.
      APPEND data_tab.
    ENDLOOP.
    g_setval_index = g_int + 1.
  ENDLOOP.

ENDFORM.

FORM PROFIT_CENTER_HIER.
* Use DATA_TAB table here to get to the heirarchies.

 LOOP AT DATA_TAB.

     W_INC1 = DATA_TAB-LEVEL.
     W_CTR1 = W_INC1.

     IF DATA_TAB-LEVEL = '0000' .
        CONTINUE.
     ENDIF.

    IF NOT DATA_TAB-GROUPNAME IS INITIAL.
      CONCATENATE 'I_PROFIT-HIER_LVL' W_CTR1 '_CODE' INTO W_LEVEL_CODE1.
      ASSIGN  (W_LEVEL_CODE1) TO <CD1>.
      <CD1> = DATA_TAB-GROUPNAME.

      CONCATENATE 'I_PROFIT-HIER_LVL' W_CTR1 '_NAME' INTO W_LEVEL_NAME1.
      ASSIGN (W_LEVEL_NAME1) TO <NM1>.
      <NM1> = DATA_TAB-DESCRIPT.

     ELSEIF NOT ( DATA_TAB-FROMVALUE IS INITIAL OR
                       DATA_TAB-TOVALUE IS INITIAL ) AND
                        DATA_TAB-LEVEL NE '0001' .
          MOVE DATA_TAB-FROMVALUE TO I_PROFIT-CODE.
          PERFORM CLEAR_ABOVE_LEVEL USING W_CTR1.
          APPEND I_PROFIT.
          CONTINUE.
     ENDIF.
ENDLOOP.

ENDFORM.

*---------------------------------------------------------------------*
*       FORM GET_FILE_NAME                                            *
*---------------------------------------------------------------------*
*       Value help for export/import file name                        *
*---------------------------------------------------------------------*
FORM get_file_name CHANGING p_outfile LIKE lgrwo-exp_file.

  DATA: path             LIKE lgrwo-exp_file,
        len              TYPE i,
        separator(1)     TYPE c,
        window_system(4) TYPE c.

  FIELD-SYMBOLS <last_char>.

* get presentation server operating system for file name separator
  CALL FUNCTION 'WS_QUERY'
       EXPORTING
            query  = 'WS'
       IMPORTING
            return = window_system.
  IF window_system = 'MC'.             "Mac OS
    separator = ':'.
  ELSE.                                "Windoze
    separator = ''.
  ENDIF.

* get path name
  path = p_outfile.
  SHIFT path RIGHT DELETING TRAILING space.
  DESCRIBE FIELD path LENGTH len.
  len = len - 1.
  ASSIGN path+len(1) TO <last_char>.
  WHILE <last_char> <> separator AND
        path <> space.
    SHIFT path RIGHT.
  ENDWHILE.
  SHIFT path LEFT DELETING LEADING space.

* get file name
  WHILE p_outfile CS separator.
    SHIFT p_outfile UP TO separator.
    SHIFT p_outfile.
  ENDWHILE.

* get file name
  CALL FUNCTION 'WS_FILENAME_GET'
       EXPORTING
            def_filename = p_outfile
            def_path     = path
            mask         = ',*.*,*.*.'
            mode         = 'S'
       IMPORTING
            filename     = p_outfile
       EXCEPTIONS
            OTHERS       = 0.

ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  CLEAR_ABOVE_LEVEL
*&---------------------------------------------------------------------*
FORM CLEAR_ABOVE_LEVEL USING   P_LEVEL.

*Field symbols.
  FIELD-SYMBOLS: <CD>,
                 <NM>.

*Clear code and name from upper level hierarchies when profit center
* is found in the lower level hierarchies.
    WHILE P_LEVEL <= 10.

     CONCATENATE 'I_PROFIT-HIER_LVL' P_LEVEL '_CODE' INTO W_LEVEL_CODE.
      ASSIGN  (W_LEVEL_CODE) TO <CD>.
      CLEAR <CD>.

     CONCATENATE 'I_PROFIT-HIER_LVL' P_LEVEL '_NAME' INTO W_LEVEL_NAME.
      ASSIGN  (W_LEVEL_NAME) TO <NM>.
      CLEAR <NM>.

      P_LEVEL = P_LEVEL + 1.

    ENDWHILE.

    CLEAR: P_LEVEL,
           W_LEVEL_CODE,
           W_LEVEL_NAME.

ENDFORM.                    " CLEAR_ABOVE_LEVEL
*&---------------------------------------------------------------------*
*&      Form  FILL_PRCTR_DETAILS
*&---------------------------------------------------------------------*
FORM FILL_PRCTR_DETAILS.

DATA: CTR TYPE I.

*Select description from CEPCT table
  SELECT * FROM CEPCT INTO TABLE I_CEPCT WHERE SPRAS EQ 'EN'.

  SELECT * FROM CEPC INTO  TABLE I_CEPC.

   SORT I_CEPC DESCENDING BY PRCTR DATBI.
   DELETE ADJACENT DUPLICATES FROM I_CEPC COMPARING PRCTR.

   SORT I_CEPC.
   SORT I_PROFIT BY CODE.

LOOP AT I_PROFIT.
   CLEAR: WA_CEPC,
          WA_CEPCT,
          W_OBJECTID.

   CTR = CTR + 1.

     READ TABLE I_CEPC INTO WA_CEPC WITH KEY PRCTR = I_PROFIT-CODE.

     READ TABLE I_CEPCT INTO WA_CEPCT WITH KEY PRCTR = WA_CEPC-PRCTR
                                               DATBI = WA_CEPC-DATBI.

          MOVE: CTR             TO I_PROFIT-ID,
                WA_CEPCT-KTEXT  TO I_PROFIT-NAME,
                WA_CEPCT-LTEXT  TO I_PROFIT-DESC.

    CONCATENATE '0002' I_PROFIT-CODE INTO W_OBJECTID.

       MOVE-CORRESPONDING I_PROFIT TO I_STR_PC1.
       APPEND I_STR_PC1.
ENDLOOP.
FREE I_PROFIT.
ENDFORM.                    " FILL_PRCTR_DETAILS

*&---------------------------------------------------------------------*
*&      Form  F_DOWNLOAD
*&---------------------------------------------------------------------*

FORM F_DOWNLOAD.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  F_WRITE_TO_FILE
*&---------------------------------------------------------------------*
FORM F_WRITE_TO_FILE.

LOOP AT I_STR_PC1.

    PERFORM WRITE_FILE USING I_STR_PC1
                                   w_file_prft-PRC_FILE..
 ENDLOOP.

ENDFORM.                    " F_WRITE_TO_FILE

FORM WRITE_FILE USING W_RECORD W_PRC_FILE.

  DATA: W_RECORD_LEN TYPE I.

*-----------------------------------------------------------------------
*  Retreive the actual length of the record to be written
*-----------------------------------------------------------------------
  DESCRIBE FIELD W_RECORD LENGTH W_RECORD_LEN.

  TRANSFER W_RECORD TO W_PRC_FILE LENGTH W_RECORD_LEN.

  IF SY-SUBRC NE 0.
    MESSAGE ID 'ZZ' TYPE 'A' NUMBER '001'
         WITH C_TEXT_WRITE  W_PRC_FILE.
  ENDIF.

  CLEAR W_RECORD.
ENDFORM.

Thanks & Regards,

Poorna.