10-24-2006 4:26 PM
Hi,
I need to create projects by using transaction cj20n, I tried to find any standard sap project/bapi/idoc that I can use in my LSMW to create the project, but could not find.
Has anyone aware of any standard SAP technique to use in LSMW for creating the project by transaction CJ20N. I am just trying not to create custom recording for the conversion.
Thanks,
10-24-2006 4:31 PM
I have a program for inserting WBS by Batch-input.
report Z_PS_BI_0001
no standard page heading
line-size 80.
*------------------------------- TABLES -------------------------------*
tables : proj , " Définition de projet
prps , " Elément d'OTP - données de base
jest , " Statut individuel par objet
tj02t . " Textes de statuts système
*-------------------------------- DATA --------------------------------*
types : begin of type_prps ,
pspnr like prps-pspnr ,
objnr like prps-objnr ,
posid like prps-posid ,
psphi like prps-psphi ,
pspid like proj-pspid ,
end of type_prps.
data itab_prps type sorted table of type_prps
with unique key pspnr
with header line
initial size 30000.
data : bdc_tab type standard table of bdcdata
with header line .
*------------------------ OPTIONS DE SELECTION ------------------------*
selection-screen begin of block b1 with frame title text-t01.
parameters : p_nom(12) type c
default 'Z_'
obligatory ,
p_kokrs like proj-vkokr
obligatory,
p_bukrs like bsis-bukrs
obligatory .
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-t02.
select-options : s_pspnr for proj-pspnr ,
s_posid for prps-posid .
selection-screen end of block b2.
*-------------------------------- MAIN --------------------------------*
start-of-selection.
* Recherche des données.
perform p_recherche_donnees.
* Création du dossier batch-input
perform p_creation_dossier.
* Edition du compte rendu d'execution.
perform p_edition.
end-of-selection.
*----------------------------------------------------------------------*
* Procédure P_RECHERCHE_DONNEES. *
*----------------------------------------------------------------------*
* Recherche des données nécessaires au programme. *
*----------------------------------------------------------------------*
form p_recherche_donnees.
types : begin of type_prhi ,
posnr like prhi-posnr ,
up like prhi-up ,
end of type_prhi.
data itab_prhi type sorted table of type_prhi
with non-unique key up
with header line
initial size 30000.
data : begin of itab_otp occurs 100 ,
pspnr like prps-pspnr , " OTP
pspn like proj-pspnr , " Projet
posid like prps-posid , " Texte OTP
objnr like prps-objnr , " Objet
end of itab_otp.
data : begin of itab_tmp_otp_1 occurs 100 ,
posnr like prhi-posnr ,
up like prhi-up ,
end of itab_tmp_otp_1.
data : begin of itab_tmp_otp_2 occurs 100 ,
pspnr like itab_otp-pspnr ,
end of itab_tmp_otp_2.
data : v_ligne(9) type n.
* Liste tout les elements d'OTP de niveau 2 pour les projets
* selectionnees.
select b~pspnr a~pspnr b~posid b~objnr
into table itab_otp
from proj as a
inner join prps as b
on b~psphi eq a~pspnr
where a~pspnr in s_pspnr
and a~profl eq '0000010'
and a~vkokr eq p_kokrs
and b~posid in s_posid
and b~stufe eq '2'
and b~pkokr eq p_kokrs.
* Tri de la table
sort itab_otp.
* Chargement de la pseudo PRHI
select posnr up
into corresponding fields of table itab_prhi
from prhi
client specified
where mandt eq sy-mandt
and up ne space.
* Extrait la liste des OTP a rechercher.
append lines of itab_otp to itab_tmp_otp_2.
* Tri
sort itab_tmp_otp_2.
* Créé la liste des OTPs dépendant des OTPs de niveaux 2.
loop at itab_tmp_otp_2.
loop at itab_prhi
where up = itab_tmp_otp_2-pspnr.
move : itab_prhi-posnr to itab_tmp_otp_1-posnr ,
itab_prhi-up to itab_tmp_otp_1-up ,
itab_prhi-posnr to itab_tmp_otp_2-pspnr .
append : itab_tmp_otp_1, itab_tmp_otp_2.
endloop.
delete itab_tmp_otp_2.
endloop.
* Recherche si plus petit niveau.
loop at itab_tmp_otp_1.
read table itab_prhi
with key up = itab_tmp_otp_1-posnr.
if sy-subrc eq space.
delete itab_tmp_otp_1.
endif.
endloop.
sort itab_tmp_otp_1 by posnr.
* Recherche de l'objet pour chacun des OTPs trouvés.
loop at itab_tmp_otp_1.
select single objnr posid psphi
into (itab_prps-objnr, itab_prps-posid, itab_prps-psphi)
from prps
where pspnr eq itab_tmp_otp_1-posnr.
if sy-subrc eq space.
move itab_tmp_otp_1-posnr to itab_prps-pspnr.
append itab_prps.
endif.
endloop.
* Recherche si les OTPs ont bien le statut Budget seul.
loop at itab_prps.
select single *
from jest
where objnr eq itab_prps-objnr
and stat eq 'E0002'
and inact eq ' '.
if sy-subrc ne space.
delete itab_prps.
endif.
endloop.
* Recherche texte projet.
loop at itab_prps.
select single pspid
into itab_prps-pspid
from proj
where pspnr eq itab_prps-psphi.
if sy-subrc eq space.
modify itab_prps.
endif.
endloop.
* Compte le nombre de ligne à traiter.
describe table itab_prps lines v_ligne.
if v_ligne eq space.
write : /1 'Aucune donnée à traiter.'.
stop.
endif.
endform. " P_RECHERCHE_DONNEES.
*----------------------------------------------------------------------*
* Procédure P_CREATION_DOSSIER. *
*----------------------------------------------------------------------*
* Création du dossier batch-input. *
*----------------------------------------------------------------------*
form p_creation_dossier.
data : v_estat type j_estat.
* Recherche de la position du statut Budget seul.
select min( estat )
into v_estat
from tj30t
where stsma eq '00000001'
and spras eq sy-langu.
if v_estat ne 'E0002'.
write : /1 'Customizing statut modifié ! Programme inutilisable !'.
stop.
endif.
* Ouverture du dossier batch-input.
perform open_bdc using p_nom.
* Boucle sur la table des données.
loop at itab_prps.
* Ecran de saisie Projet / OTP
perform bdc_dynpro using 'SAPLCJWB'
'0100'.
perform bdc_field using 'BDC_OKCODE'
'=LETB'.
perform bdc_field using '*PROJ-PSPID'
itab_prps-pspid.
perform bdc_field using '*PRPS-POSID'
itab_prps-posid.
* Sélectionne la première ligne et demande les statuts utilisateurs.
perform bdc_dynpro using 'SAPLCJWB'
'0901'.
perform bdc_field using 'BDC_OKCODE'
'=STAT'.
perform bdc_field using 'RCJ_MARKL-MARK(01)'
'X'.
* Déselectionne la zone Budget/Seul
perform bdc_dynpro using 'SAPLBSVA'
'0300'.
perform bdc_field using 'BDC_OKCODE'
'=BACK'.
perform bdc_field using 'J_STMAINT-ANWSO(01)'
' '.
* Enregistre et sort.
perform bdc_dynpro using 'SAPLCJWB'
'0901'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
* Enregistrement de la transaction.
perform insert_bdc using 'CJ02'.
endloop.
* Fermeture du dossier batch-input.
perform close_bdc.
endform. " P_CREATION_DOSSIER
*----------------------------------------------------------------------*
* Procédure P_EDITION. *
*----------------------------------------------------------------------*
* Edition du compte rendu d'éxecution. *
*----------------------------------------------------------------------*
form p_edition.
write : /1 'Compte rendu de la création du dossier Batch-Input.'.
skip 2.
write : /1 'Dossier Batch-Input' ,
p_nom ,
'créé avec succés.'.
skip 4.
write : /1 'Liste des OTPs que le Batch-Input devrait modifier.'.
loop at itab_prps.
write : /5 itab_prps-posid.
endloop.
endform. " P_EDITION.
*----------------------------------------------------------------------*
* Form OPEN_BDC *
*----------------------------------------------------------------------*
* Ouverture du dossier Batch-Input. *
*----------------------------------------------------------------------*
form open_bdc using v_nom_dossier.
call function 'BDC_OPEN_GROUP'
exporting
client = sy-mandt " Numéro de mandant
group = v_nom_dossier " Nom dossier batch
keep = 'X' " Code
user = sy-uname " Nom utilisateur
exceptions
client_invalid = 1
destination_invalid = 2
group_invalid = 3
group_is_locked = 4
holddate_invalid = 5
internal_error = 6
queue_error = 7
running = 8
system_lock_error = 9
user_invalid = 10
others = 11.
if sy-subrc ne 0.
write : /1 'Impossible de créer le dossier batch-input.' ,
/1 'Erreur :' , sy-subrc.
stop.
endif.
refresh bdc_tab.
clear bdc_tab.
exit.
endform. " OPEN_BDC
*----------------------------------------------------------------------*
* Form CLOSE_BDC *
*----------------------------------------------------------------------*
* Fermeture du dossier BTCI *
*----------------------------------------------------------------------*
form close_bdc.
call function 'BDC_CLOSE_GROUP'
exceptions
not_open = 1
queue_error = 2
others = 3.
if sy-subrc ne 0.
write : /1 'Impossible de fermer le dossier batch-input.' ,
/1 'Erreur :' , sy-subrc.
endif.
endform. " CLOSE_BDC
*----------------------------------------------------------------------*
* Form BDC_DYNPRO *
*----------------------------------------------------------------------*
* Alimentation de la ligne d'entête de BDCTAB *
*----------------------------------------------------------------------*
form bdc_dynpro using value(progname)
value(dynpronr).
* Efface la header-line.
clear bdc_tab.
* Insertion des valeurs.
bdc_tab-program = progname.
bdc_tab-dynpro = dynpronr.
bdc_tab-dynbegin = 'X'.
* Enregistrement des valeurs.
append bdc_tab.
endform. " BDC_DYNPRO
*----------------------------------------------------------------------*
* Form BDC_FIELD *
*----------------------------------------------------------------------*
* Traitement des enregistrements de la structure BDCTAB *
*----------------------------------------------------------------------*
* --> FIELDNAME Nom du champ *
* --> FIELDVALUE Valeur du champ *
*----------------------------------------------------------------------*
form bdc_field using value(fieldname) value(fieldvalue).
* Efface la header-line.
clear bdc_tab.
* Insertion des valeurs.
bdc_tab-fnam = fieldname.
bdc_tab-fval = fieldvalue.
* Enregistrement des valeurs.
append bdc_tab.
endform. " BDC_FIELD
*----------------------------------------------------------------------*
* Form BDC_CURSOR *
*----------------------------------------------------------------------*
* Positionnement du curseur sur un champ particulier *
*----------------------------------------------------------------------*
form bdc_cursor using value(fieldname) value(fieldvalue).
* Efface la header-line.
clear bdc_tab.
* Insertion des valeurs.
bdc_tab-fnam = fieldname.
bdc_tab-fval = fieldvalue.
* Enregistrement des valeurs.
append bdc_tab.
endform. " BDC_CURSOR
*----------------------------------------------------------------------*
* Form INSERT_BDC *
*----------------------------------------------------------------------*
* Insertion dans le dossier BTCI *
*----------------------------------------------------------------------*
* Attention : la transaction est codée en dur *
*----------------------------------------------------------------------*
form insert_bdc using t_code.
call function 'BDC_INSERT'
exporting
tcode = t_code
tables
dynprotab = bdc_tab
exceptions
internal_error = 1
not_open = 2
queue_error = 3
tcode_invalid = 4
printing_invalid = 5
posting_invalid = 6
others = 7.
if sy-subrc ne 0.
write : /1 text-003 ,
/1 'Erreur :' , sy-subrc.
endif.
refresh bdc_tab.
clear bdc_tab.
endform. " INSERT_BDC
comment in french
10-24-2006 4:34 PM
10-24-2006 5:10 PM
Hi Ravi,
If I will use this BAPI in my LSMW, In maintain object attributes step, what should I input for Business Object, Method, Message type, and Basic Type.
Thanks,
10-24-2006 5:20 PM
Hi,
Use the FMs in the following order
BAPI_PS_INITIALIZATION
BAPI_BUS2001_SET_STATUS
BAPI_PS_PRECOMMIT
BAPI_TRANSACTION_COMMIT with wait.
Madhavi