Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

CJ20N - project structure and data import

Former Member
0 Kudos

Hello dear SAP specialists,

Does anybody ever created a ABAP program to import project structure and populate it with data?

I'm trying to start with something or get a working program to import some projects with data.

Actually the program should use BAPI_PROJECT_MAINTAIN to create WBS and GUI_UPLOAD to read a text (cvs) file (LSMW can not be used:)

Sincerely,

Me

4 REPLIES 4

Former Member
0 Kudos

Hi,

You first need to have a flat file. Now in your ABAP program you have top create an internal table for you flat file data. Meaning, that the fields in your internal table will be corresponding to you flat file fields. This flat file will be uploaded in the system through GUI_UPLOAD.

Now once you have uploaded the data in the internal table,this data is then passed to the BAPI. You will thoroughly have to see the mapping of data from the internal table to the BAPI,so that no fields are missed. Once you have called this BAPI you will also have to call BAPI_TRANSACTION_COMMIT.

If all these are correctly done and you have all the mandatory data in you flat file then it'll work fine.

If you have any other query let me know.

Regards,

Shraddha

Former Member
0 Kudos

Thank you for the answer,

OK, I'm working at Accounting-Project System-Project-CJ20N(Project Builder)

Project Builder

So,

1. First of all I have to import a project structure from file and it should be correctly processed.

2. Then, with all functions - the structure should be populated, so that the appropriate data should find its place in Project Structure.

right?

Does anybody already did this kind of job?

0 Kudos

Hi,

Exactly!

See you have so many tables in that BAPI, now all the data you have in your flat file you have to map to these tables.

Below is a code...similarly you'll have to do

TYPE-POOLS: truxs.

*----------------------------------------------------------------------
*                           T Y P E S
*----------------------------------------------------------------------

TYPES: BEGIN OF t_master_data,
          MATERIAL                      Type  MATNR ,
          IND_SECTOR                    Type  MBRSH ,
          MATL_TYPE                     Type  MTART ,
          PLANT                         Type  WERKS ,
          STGE_LOC                      Type  LGORT_D ,
          MATL_DESC                     Type  MAKTX ,
          BASE_UOM                      Type  MEINS ,
          MATL_GROUP                    Type  MATKL ,
          DIVISION                      Type  SPART ,
          ITEM_CAT                      Type  MTPOS_MARA  ,
          GROSS_WT                      Type  BRGEW ,
          UNIT_OF_WT                    Type  GEWEI ,
          NET_WEIGHT                    Type  NTGEW ,
          VOLUME                        Type  VOLUM ,
          SIZE_DIM                      Type  GROES ,
          BASIC_MATL                    Type  WRKST ,
          DOCUMENT                      Type  DZEINR  ,
          DOC_VERS                      Type  DZEIVR  ,
          PO_UNIT                       Type  BSTME ,
          PUR_GROUP                     Type  EKGRP ,
          AUTO_P_ORD                    Type  KAUTB ,
          "BATCH_MGMT Type  XCHPF ,
          PUR_VALKEY                    Type  EKWSL ,
          "GR_PR_TIME Type  WEBAZ ,
          COMM_CODE                     Type  STAWN ,
          COUNTRYORI                    Type  HERKL ,
          MRP_TYPE                      Type  DISMM ,
          REORDER_PT                    Type  MINBE ,
          MRP_CTRLER                    Type  DISPO ,
          LOTSIZEKEY                    Type  DISLS ,
          MINLOTSIZE                    Type  BSTMI ,
          MAXLOTSIZE                    Type  BSTMA ,
          FIXED_LOT                     Type  BSTFE ,
          MAX_STOCK                     Type  MABST ,
          ROUND_VAL                     Type  BSTRF ,
          PROC_TYPE                     Type  BESKZ ,
          SPPROCTYPE                    Type  SOBSL ,
          ISS_ST_LOC                    Type  LGPRO ,
          SLOC_EXPRC                    Type  LGFSB ,
          PLND_DELRY                    Type  PLIFZ ,
          GR_PR_TIME                    Type  WEBAZ ,
          SM_KEY                        Type  FHORI ,
          SAFETY_STK                    Type  EISBE ,
          PLNG_PLANT                    Type  PRWRK ,
          AVAILCHECK                    Type  MTVFP ,
          DEP_REQ_ID                    Type  SBDKZ ,
          ISSUE_UNIT                    Type  AUSME ,
          STGE_BIN                      Type  LGPBE ,
          BATCH_MGMT                    Type  XCHPF ,
          STGEPERIOD                    Type  MAXLZ ,
          STGE_PD_UN                    Type  LZEIH ,
          MINREMLIFE                    Type  MHDRZ ,
          SHELF_LIFE                    Type  MHDHB ,
          PERIOD_IND_EXPIRATION_DATE    Type  DATTP ,
          ROUND_UP_RULE_EXPIRATION_DATE Type  RDMHD ,
          STOR_PCT                      Type  MHDLP ,
          QM_AUTHGRP                    Type  QMATAUTH  ,
          QM_PROCMNT                    Type  QMPUR ,
          CTRL_KEY                      Type  SSQSS ,
*           Type  ART ,
*           Type  AKTIV ,
          VAL_CAT                       Type  BWTTY_D ,
          VAL_CLASS                     Type  BKLAS ,
          PRICE_CTRL                    Type  VPRSV ,
* NEW ADDITION
          STD_PRICE                     Type  STPRS,
          PRICE_UNIT                    Type  PEINH ,
          MOVING_PR                     Type  VERPR ,
          QTY_STRUCT                    Type  CK_EKALREL  ,
          ORIG_GROUP                    Type  HRKFT ,
          ORIG_MAT                      Type  HKMAT ,
          VARIANCE_KEY                  Type  AWSLS ,
          PROFIT_CTR                    Type  PRCTR ,
          LANGU                         Type SPRAS,

       END OF t_master_data.

*----------------------------------------------------------------------
*                  I N T E R N A L   T A B L E S
*----------------------------------------------------------------------

DATA:

*     Internal table of type t_master_data
      ist_master_data TYPE TABLE OF t_master_data,

*     Internal table of type BAPIMATHEAD
      ist_headdata    TYPE TABLE OF BAPIMATHEAD,

*     Internal table of type BAPI_MAKT
      ist_mat_desc    TYPE TABLE OF BAPI_MAKT,

*     Internal table of type BAPI_MAKT
      ist_uom         TYPE TABLE OF BAPI_MARM,

*     Internal table of type BAPI_MAKTX
      ist_uom_x       TYPE TABLE OF BAPI_MARMX.


*----------------------------------------------------------------------
*                   G L O B A L   V A R I A B L E S
*----------------------------------------------------------------------

DATA:
      it_num     TYPE num10,

*     Global variable of type truxs_t_text_data
      it_raw     TYPE truxs_t_text_data.


*----------------------------------------------------------------------
*                       W O R K   A R E A S
*----------------------------------------------------------------------

DATA:

*     Work area of type t_master_data
      wa_master_data                TYPE t_master_data,

*     Work area of type bapimathead
      wa_bapimathead                TYPE BAPIMATHEAD,

*     Work area of type bapi_mara
      wa_client_data                TYPE BAPI_MARA,

*     Work area of type bapi_marax
      wa_client_data_x              TYPE  BAPI_MARAX,

*     Work area of type bapi_marc
      wa_plant_data                 TYPE BAPI_MARC,

*     Work area of type bapi_marcx
      wa_plant_data_x               TYPE BAPI_MARCX,

*     Work area of type bapi_mard
      wa_storage_location_data      TYPE BAPI_MARD,

*     Work area of type bapi_mardx
      wa_storage_location_data_x    TYPE BAPI_MARDX,

*     Work area of type bapi_mbew
      wa_valuation_data             TYPE BAPI_MBEW,

*     Work area of type bapi_mbewx
      wa_valuation_data_x           TYPE BAPI_MBEWX,

*     Work area of type bapi_mard
      wa_mat_desc                   TYPE BAPI_MAKT,

*     Work area of type bapi_marm
      wa_uom                        TYPE BAPI_MARM,

*     Work area of type bapi_marmx
      wa_uom_x                      TYPE BAPI_MARMX,

*     Work area of type mbapi_mpgd
      wa_planning_data              TYPE BAPI_MPGD,

*     Work area of type mbapi_mpgdx
      wa_planning_data_x            TYPE BAPI_MPGDX,

*     Work area of type mbapi_mpgd
      wa_return                     TYPE BAPIRET2.


*----------------------------------------------------------------------
*                          P A R A M E T E R S
*----------------------------------------------------------------------
PARAMETERS:

*     Parameter of type rlgrap-filename
      p_file TYPE  rlgrap-filename.


***********************************************************************
*               A T   S E L E C T I O N   S C R E E N
***********************************************************************

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name = 'P_FILE'
    IMPORTING
      file_name  = p_file.

***********************************************************************
*                S T A R T - O F - S E L E C T I O N.
***********************************************************************

START-OF-SELECTION.

* To upload data from flat file

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_line_header        = 'X'
      i_tab_raw_data       = it_raw       " WORK TABLE
      i_filename           = p_file
    TABLES
      i_tab_converted_data = ist_master_data[]  "ACTUAL DATA
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.

  IF sy-subrc = 0.

    LOOP AT ist_master_data INTO wa_master_data.

      it_num = wa_master_data-PROFIT_CTR.
      wa_master_data-PROFIT_CTR = it_num.

      MOVE-CORRESPONDING wa_master_data to wa_bapimathead.

      MOVE-CORRESPONDING wa_master_data to wa_client_data.

      wa_client_data_x-MATL_GROUP = 'X'.
      wa_client_data_x-BASE_UOM = 'X'.
      wa_client_data_x-PO_UNIT = 'X'.
      wa_client_data_x-DOCUMENT = 'X'.
      wa_client_data_x-SIZE_DIM = 'X'.
      wa_client_data_x-BASIC_MATL = 'X'.
      wa_client_data_x-PUR_VALKEY = 'X'.
      wa_client_data_x-NET_WEIGHT = 'X'.
      wa_client_data_x-UNIT_OF_WT = 'X'.
      wa_client_data_x-DIVISION = 'X'.
      wa_client_data_x-BATCH_MGMT = 'X'.
      wa_client_data_x-QM_PROCMNT = 'X'.
      wa_client_data_x-MINREMLIFE = 'X'.
      wa_client_data_x-SHELF_LIFE = 'X'.
      wa_client_data_x-STOR_PCT = 'X'.
      wa_client_data_x-ROUND_UP_RULE_EXPIRATION_DATE = 'X'.
      wa_client_data_x-PERIOD_IND_EXPIRATION_DATE = 'X'.
      wa_client_data_x-ITEM_CAT = 'X'.


      MOVE-CORRESPONDING wa_master_data to wa_plant_data.

      wa_plant_data_x-PLANT  = wa_master_data-plant.
      wa_plant_data_x-PUR_GROUP = 'X'.
      wa_plant_data_x-ISSUE_UNIT = 'X'.
      wa_plant_data_x-MRP_TYPE = 'X'.
      wa_plant_data_x-MRP_CTRLER = 'X'.
      wa_plant_data_x-PLND_DELRY = 'X'.
      wa_plant_data_x-GR_PR_TIME = 'X'.
      wa_plant_data_x-LOTSIZEKEY = 'X'.
      wa_plant_data_x-PROC_TYPE = 'X'.
      wa_plant_data_x-SPPROCTYPE = 'X'.
      wa_plant_data_x-SAFETY_STK = 'X'.
      wa_plant_data_x-MINLOTSIZE = 'X'.
      wa_plant_data_x-MAXLOTSIZE = 'X'.
      wa_plant_data_x-FIXED_LOT = 'X'.
      wa_plant_data_x-ROUND_VAL = 'X'.
      wa_plant_data_x-MAX_STOCK = 'X'.
      wa_plant_data_x-DEP_REQ_ID = 'X'.
      wa_plant_data_x-SM_KEY = 'X'.
      wa_plant_data_x-STGEPERIOD = 'X'.
      wa_plant_data_x-STGE_PD_UN = 'X'.
      wa_plant_data_x-CTRL_KEY = 'X'.
      wa_plant_data_x-BATCH_MGMT = 'X'.
      wa_plant_data_x-AVAILCHECK = 'X'.
      wa_plant_data_x-AUTO_P_ORD = 'X'.
      wa_plant_data_x-COMM_CODE = 'X'.
      wa_plant_data_x-COUNTRYORI = 'X'.
      wa_plant_data_x-PROFIT_CTR = 'X'.
      wa_plant_data_x-ISS_ST_LOC = 'X'.
      wa_plant_data_x-VARIANCE_KEY = 'X'.
      wa_plant_data_x-SLOC_EXPRC = 'X'.
      wa_plant_data_x-QM_AUTHGRP = 'X'.

      MOVE-CORRESPONDING wa_master_data to wa_planning_data.
      wa_planning_data_x-PLANT = wa_master_data-plant.
      wa_planning_data_x-PLNG_PLANT = 'X'.

      MOVE-CORRESPONDING wa_master_data to wa_storage_location_data.
      wa_storage_location_data_X-PLANT = wa_master_data-plant.
      wa_storage_location_data_X-STGE_LOC = wa_master_data-stge_loc.
      wa_storage_location_data_X-STGE_BIN = 'X'.

      MOVE-CORRESPONDING wa_master_data to wa_valuation_data.
      wa_valuation_data-VAL_AREA = '1000'.
      wa_valuation_data_X-VAL_AREA = '1000'.
      wa_valuation_data_X-PRICE_CTRL = 'X'.
      wa_valuation_data_X-MOVING_PR  = 'X'.
      wa_valuation_data_X-PRICE_UNIT = 'X'.
      wa_valuation_data_X-STD_PRICE = 'X'.
      wa_valuation_data_X-VAL_CLASS = 'X'.
      wa_valuation_data_X-ORIG_GROUP = 'X'.
      wa_valuation_data_X-QTY_STRUCT = 'X'.
      wa_valuation_data_X-ORIG_MAT = 'X'.

      MOVE-CORRESPONDING wa_master_data to wa_mat_desc.
      APPEND wa_mat_desc to ist_mat_desc.


      IF wa_master_data-PRICE_CTRL = 'S' AND wa_master_data-STD_PRICE IS INITIAL.
        WRITE:/ 'Standard Price not maintained for material ',wa_master_data-MATERIAL.
      ELSE.


        CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
          EXPORTING
            HEADDATA             = wa_bapimathead
            CLIENTDATA           = wa_client_data
            CLIENTDATAX          = wa_client_data_x
            PLANTDATA            = wa_plant_data
            PLANTDATAX           = wa_plant_data_X
            PLANNINGDATA         = wa_planning_data
            PLANNINGDATAX        = wa_planning_data_x
            STORAGELOCATIONDATA  = wa_storage_location_data
            STORAGELOCATIONDATAX = wa_storage_location_data_x
            VALUATIONDATA        = wa_valuation_data
            VALUATIONDATAX       = wa_valuation_data_x
          IMPORTING
            RETURN               = wa_return
          TABLES
            MATERIALDESCRIPTION  = ist_mat_desc.

        Write:/ wa_return-message.

        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
        Clear: wa_bapimathead
         ,wa_client_data
         ,wa_client_data_x
         ,wa_plant_data
        ,wa_plant_data_X
        ,wa_planning_data
         ,wa_planning_data_x
        ,wa_storage_location_data
         ,wa_storage_location_data_x
         ,wa_valuation_data
       ,wa_valuation_data_x.

      ENDIF.


      REFRESH ist_mat_desc.


    ENDLOOP.

  ELSE.

    Write:/ text-001.

  ENDIF.

In the above code note how i have taken the same names for the fields in internal table as they are in the BAPI so that the mapping of data becomes easier, since i use MOVE CORRESPONDING.

Regards,

Shraddha

Edited by: shraddha85 on Jan 31, 2011 9:49 AM

Former Member
0 Kudos

Thank you for answering,

I'm working on something else right now and I don't know if I will work again on that question.

Thanks again