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: 

How to create / change cost estimates with classes

Former Member
0 Kudos

Does anyone know how to use abap classes to create a new cost estimate in R/3? I found CL_COST_ESTIMATE AND CL_COSTING_COMPONENT (and many others) that are supposed to do exactly this , but i can't get them to work.

Thanks.

3 REPLIES 3

0 Kudos

Hello,

I have the same question.

Does anybody have the answer ?

Thank you,

Holger

0 Kudos

Hi,

This is a Sample code to Use the Classess.Follow this and Sure You can do.

Even I did the same..Post for or Reply for further Assistance.

Regards

Bala.M

REPORT  zib_catalog_so4040_csv.

DATA: g_db_catalogue_labels_old TYPE REF TO zicl_db_catalogue_labels,

g_db_catalogue_labels_new TYPE REF TO zicl_db_catalogue_labels,

g_bl_catalogue_labels     TYPE REF TO zicl_bl_catalogue_labels.

DATA: t_ziscat         TYPE TABLE OF ziscat,

r_ziscat         LIKE LINE OF t_ziscat,

t_ziscatso       TYPE TABLE OF ziscatso,

r_ziscatso       LIKE LINE OF t_ziscatso,

t_ziscontact     TYPE TABLE OF ziscontact,

r_ziscontact     LIKE LINE OF t_ziscontact,

t_zisconttodo    TYPE TABLE OF zisconttodo,

r_zisconttodo    LIKE LINE OF t_zisconttodo,

t_zialvlabels    TYPE TABLE OF yialvlabels,

r_zialvlabels    LIKE LINE OF t_zialvlabels,

r_zisretailer    TYPE zisretailer,

r_ziscust        TYPE ziscust,

r_zisaddr        TYPE zisaddr,

r_zistitle       TYPE zistitle,

r_ziscontind     TYPE ziscontind,

r_ziscontcord    TYPE ziscontcord.

DATA: len           TYPE i,

len2          TYPE i,

tit_cust      TYPE i,

tit_rt        TYPE i,

c_058(3)      TYPE c,

c_080(3)      TYPE c,

c_095(3)      TYPE c,

c_130(3)      TYPE c,

c_166(3)      TYPE c,

c_other(3)    TYPE c,

workfld(300)  TYPE c,

t_workfld     LIKE TABLE OF workfld,

t_workfld_rt  LIKE TABLE OF workfld,

label(255),

filename TYPE string,

file_length TYPE i,

ft            TYPE timestampl,

tstamp(21)    TYPE c.

DATA : it_string  TYPE string ,

it_xstring TYPE xstring ,

crlf(2)   TYPE c VALUE cl_abap_char_utilities=>cr_lf,

ht(1)     TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.

DATA : changed_file(4096) TYPE c OCCURS 0,

w_io              TYPE string.

DATA: add_par     TYPE btcxpgpar.
DATA: BEGIN OF lv,

status    TYPE extcmdexex-status,

exitcode  TYPE extcmdexex-exitcode,

exec_prot TYPE TABLE OF btcxpm,

add_text  TYPE zitext255,

END OF lv.
*Final table for Output.
DATA : BEGIN OF it_final OCCURS 0,

panr    TYPE char10,

dnld LIKE  zisaddr-zicntry,

addrz1  TYPE char25,

addrz2  TYPE char40,

addrz3  LIKE zisaddr-zistras,

addrz4  TYPE char40,

addrz5  TYPE char50,

anrp1   TYPE char50,

bcd1    LIKE ziscontcord-zicatcode,

bcd2    LIKE ziscontcord-zicatcode,

bcd3    LIKE ziscontcord-zicatcode,

bcd4    LIKE ziscontcord-zicatcode,

bcd5    LIKE ziscontcord-zicatcode,

END OF it_final.

START-OF-SELECTION.

CREATE OBJECT g_db_catalogue_labels_old.

CREATE OBJECT g_db_catalogue_labels_new.

CREATE OBJECT g_bl_catalogue_labels.

PERFORM get_labels USING '4040'.

IF NOT t_zialvlabels IS INITIAL.

SELECT * FROM ziscatso

INTO TABLE t_ziscatso

WHERE zisonr EQ '4040'.

SELECT * FROM ziscat

INTO TABLE t_ziscat

FOR ALL ENTRIES IN t_ziscatso

WHERE zicatcode EQ t_ziscatso-zicatcode.

READ TABLE t_ziscatso INTO r_ziscatso INDEX 1.

LOOP AT t_zialvlabels INTO r_zialvlabels.

IF tit_cust IS INITIAL.

ADD 1 TO tit_cust.

PERFORM first_line.

ENDIF.

PERFORM label_line.

ENDLOOP.

ENDIF.

IF NOT t_zialvlabels IS INITIAL.

PERFORM file_transfer USING '4040'.

ENDIF.

CLEAR: t_zialvlabels,r_zialvlabels,t_ziscatso,t_ziscat,

t_workfld,t_workfld_rt,tit_cust.
*&---------------------------------------------------------------------*
*&      Form  get_labels
*&---------------------------------------------------------------------*
FORM get_labels  USING value(p_sonr).

DATA: type          TYPE zitypeofcontact VALUE '07',

print         TYPE zinolblprt VALUE '',

date          TYPE zidate,

zilbldate     TYPE zilbldate,

t_row         TYPE TABLE OF char72,

r_row         TYPE char72,

p_select      TYPE char72.

CLEAR: t_row, r_row, len.

IF p_sonr = '4040'.

p_select = 'AND ZISONR = 4040'.

ENDIF.

r_row = 'ZITYPEOFCONTACT = TYPE'.

APPEND r_row TO t_row.

r_row = p_select.

APPEND r_row TO t_row.

r_row = 'AND ZINOLBLPRT EQ PRINT'.

APPEND r_row TO t_row.

r_row = 'AND ZILBLDATE EQ DATE'.

APPEND r_row TO t_row.

SELECT * FROM ziscontact

INTO CORRESPONDING FIELDS OF r_zialvlabels

WHERE (t_row).

* Contact-Index

SELECT SINGLE * FROM ziscontind INTO r_ziscontind

WHERE ziteckey = r_zialvlabels-ziteckey.

IF sy-subrc NE 0.

CONTINUE.

ENDIF.

* customer / retailer

CASE r_ziscontind-zidbreference.
*....Customer

WHEN 'CU'.

SELECT SINGLE * FROM ziscust INTO r_ziscust

WHERE zicustnr = r_ziscontind-zicontactkey.

IF sy-subrc NE 0.

CONTINUE.

ENDIF.

MOVE-CORRESPONDING r_ziscust TO r_zialvlabels.

WHEN OTHERS.

CONTINUE.

ENDCASE.
* Adresse

SELECT SINGLE * FROM zisaddr INTO r_zisaddr

WHERE ziaddrctg = r_ziscontind-zidbreference

AND ziaddrkey = r_zialvlabels-ziaddrkey.

IF sy-subrc NE 0.

CONTINUE.

ENDIF.

MOVE-CORRESPONDING r_zisaddr TO r_zialvlabels.
* Anrede

SELECT SINGLE * FROM zistitle INTO r_zistitle

WHERE zilangu = r_zialvlabels-zilang

AND zititle = r_zialvlabels-zititle.

IF sy-subrc = 0.

MOVE-CORRESPONDING r_zistitle TO r_zialvlabels.

ENDIF.
* Catalogue

SELECT * FROM ziscontcord INTO r_ziscontcord

WHERE ziteckey = r_zialvlabels-ziteckey.

IF NOT r_zialvlabels-zicat_all IS INITIAL.

len = len + 1.

r_zialvlabels-zicat_all+len = '/'.

ENDIF.

CONCATENATE r_zialvlabels-zicat_all r_ziscontcord-zicatcode

INTO r_zialvlabels-zicat_all SEPARATED BY ' '.

len = STRLEN( r_zialvlabels-zicat_all ).

ENDSELECT.

APPEND r_zialvlabels TO t_zialvlabels.

CLEAR r_zialvlabels.

ENDSELECT.

ENDFORM.                    " get_labels
*&---------------------------------------------------------------------*
*&      Form  first_line
*&---------------------------------------------------------------------*
FORM first_line.

CLEAR: len, workfld.

workfld = 'PANR;DNLD;ADDRZ1;ADDRZ2;ADDRZ3;ADDRZ4;ADDRZ5;ANRP1;BCD1;BCD2;BCD3;BCD4;BCD5'.

len = STRLEN( workfld ).
*  LOOP AT t_ziscat INTO r_ziscat
*    WHERE ziactflg = 'X'.
*    CONCATENATE r_ziscat-zicatdesign ';'
*           INTO workfld+len(61).
*    len = STRLEN( workfld ).
*  ENDLOOP.

APPEND workfld TO t_workfld.

ENDFORM.                    " first_line
*&---------------------------------------------------------------------*
*&      Form  label_line
*&---------------------------------------------------------------------*
FORM label_line.

DATA:  cat1 TYPE string,

cat2 TYPE string,

cat3 TYPE string,

cat4 TYPE string,

cat5 TYPE string,

wcat TYPE string.

CLEAR: len,len2,workfld.

CONCATENATE r_zialvlabels-zicustnr ';'

INTO workfld+len(32).

len = STRLEN( workfld ).

CONCATENATE r_zialvlabels-zicntry ';'

INTO workfld+len(4).

len = STRLEN( workfld ).

CONCATENATE r_zialvlabels-zititle_medi ';'

INTO workfld+len(32).

len = STRLEN( workfld ).

CONCATENATE r_zialvlabels-zinamev ' ' r_zialvlabels-ziname1 ';'

INTO workfld+len(41) SEPARATED BY space.

len = STRLEN( workfld ).

CONCATENATE r_zialvlabels-zistras ';'

INTO workfld+len(41).

len = STRLEN( workfld ).

CONCATENATE '                       ' ';'

INTO workfld+len(41).

len = STRLEN( workfld ).

CONCATENATE r_zialvlabels-zizip ' ' r_zialvlabels-ziort  ';'

INTO workfld+len(31).

len = STRLEN( workfld ).

CASE r_zialvlabels-zititle.

WHEN '0001'.

CONCATENATE 'Geachte heer ' r_zialvlabels-ziname1 ';'

INTO workfld+len(41) SEPARATED BY space.

len = STRLEN( workfld ).

WHEN '0002'.

CONCATENATE 'Geachte Mevrouw  ' r_zialvlabels-ziname1 ';'

INTO workfld+len(41) SEPARATED BY space.

len = STRLEN( workfld ).

WHEN OTHERS.

CONCATENATE 'Geachte dames en Heren  ' ';'

INTO workfld+len(41) SEPARATED BY space.

len = STRLEN( workfld ).

ENDCASE.

CLEAR: c_058,c_080,c_095,c_130,c_166,c_130.

CONDENSE r_zialvlabels-zicat_all NO-GAPS.

SPLIT r_zialvlabels-zicat_all AT '/'

INTO: cat1 cat2 cat3 cat4 cat5.

*  PERFORM cat_detail USING cat1.
*  PERFORM cat_detail USING cat2.
*  PERFORM cat_detail USING cat3.
*  PERFORM cat_detail USING cat4.
*  PERFORM cat_detail USING cat5.

*  CONCATENATE c_058 ';' c_080 ';' c_095 ';' c_130 ';' c_166
*    INTO wcat.

CONCATENATE cat1 ';' cat2 ';' cat3 ';' cat4 ';' cat5

INTO wcat.

CONDENSE wcat NO-GAPS.

len2 = STRLEN( wcat ).

len  = STRLEN( workfld ).

workfld+len(len2) = wcat.

APPEND workfld TO t_workfld.

ENDFORM.                    " label_line
*&---------------------------------------------------------------------*
*&      Form  Cat_detail
*&---------------------------------------------------------------------*
FORM cat_detail  USING    p_cat.

CASE p_cat.

WHEN '058'.

c_058 = '058'.

WHEN '080'.

c_080 = '080'.

WHEN '095'.

c_095 = '095'.

WHEN '130'.

c_130 = '130'.

WHEN '166'.

c_166 = '166'.

WHEN OTHERS.

c_other = p_cat.

ENDCASE.

ENDFORM.                    " Cat_detail

*&---------------------------------------------------------------------*
*&      Form  file_transfer
*&---------------------------------------------------------------------*
FORM file_transfer  USING value(p_zisonr).

LOOP AT t_workfld INTO workfld.

SPLIT workfld AT ';'

INTO   it_final-panr

it_final-dnld

it_final-addrz1

it_final-addrz2

it_final-addrz3

it_final-addrz4

it_final-addrz5

it_final-anrp1

it_final-bcd1

it_final-bcd2

it_final-bcd3

it_final-bcd4

it_final-bcd5.

APPEND it_final.

ENDLOOP.

IF sy-sysid = 'IHP'.

PERFORM save_to_ftp.

ELSE.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING
*   BIN_FILESIZE                    =

filename                       = 'H:Catalougeorders_SO_4040.XLS'

filetype                        = 'ASC'
*     append                          = 'X'

write_field_separator           = ';'

IMPORTING

filelength                      = file_length

TABLES

data_tab                       = it_final

EXCEPTIONS

file_write_error                = 1

no_batch                        = 2

gui_refuse_filetransfer         = 3

invalid_type                    = 4

no_authority                    = 5

unknown_error                   = 6

header_not_allowed              = 7

separator_not_allowed           = 8

filesize_not_allowed            = 9

header_too_long                 = 10

dp_error_create                 = 11

dp_error_send                   = 12

dp_error_write                  = 13

unknown_dp_error                = 14

access_denied                   = 15

dp_out_of_memory                = 16

disk_full                       = 17

dp_timeout                      = 18

file_not_found                  = 19

dataprovider_exception          = 20

control_flush_error             = 21

OTHERS                          = 22

.

IF sy-subrc <> 0.

MESSAGE s000(zi_maint1_msg) WITH 'Fehler FTP Catalog' add_par sy-subrc.

ENDIF.

ENDIF.

PERFORM processing_save.

ENDFORM.                    " file_transfer
*&---------------------------------------------------------------------*
*&      Form  ftp_catalog
*&---------------------------------------------------------------------*
FORM ftp_catalog .

CLEAR lv.

*  CALL FUNCTION 'SXPG_CALL_SYSTEM'
*    EXPORTING
*      commandname                = 'ZI_FTP_CATALOG'
*      additional_parameters      = add_par
*    IMPORTING
*      status                     = lv-status
*      exitcode                   = lv-exitcode
*    TABLES
*      exec_protocol              = lv-exec_prot
*    EXCEPTIONS
*      no_permission              = 1
*      command_not_found          = 2
*      parameters_too_long        = 3
*      security_risk              = 4
*      wrong_check_call_interface = 5
*      program_start_error        = 6
*      program_termination_error  = 7
*      x_error                    = 8
*      parameter_expected         = 9
*      too_many_parameters        = 10
*      illegal_command            = 11
*      OTHERS                     = 12.

IF sy-subrc <> 0.

MESSAGE s000(zi_maint1_msg) WITH 'Fehler FTP Catalog' add_par sy-subrc.

ELSE.

IF lv-exec_prot IS INITIAL.

IF add_par NE 'labels_at_rt.csv so4040'.

PERFORM processing_save.

ENDIF.

ELSE.

LOOP AT lv-exec_prot INTO lv-add_text.

MESSAGE s000(zi_maint1_msg)

WITH 'Fehler FTP Catalog' add_par lv-add_text.

ENDLOOP.

ENDIF.

ENDIF.

ENDFORM.                    " ftp_catalog
*&---------------------------------------------------------------------*
*&      Form  processing_save
*&---------------------------------------------------------------------*
FORM processing_save .

DATA: runstatus  TYPE sy-ucomm.

DATA: detailnr   TYPE sy-dynnr VALUE '0900'.

DATA BEGIN OF wa_message.

INCLUDE STRUCTURE zimessage.

DATA END OF wa_message.

CLEAR wa_message.

* Contact-Daten aufgrund der gewählten Labels einholen.

CALL METHOD g_db_catalogue_labels_old->get_update_data

EXPORTING

t_zialvlabels = t_zialvlabels.

CALL METHOD g_db_catalogue_labels_old->get_contact

IMPORTING

t_ziscontact = t_ziscontact.

CALL METHOD g_db_catalogue_labels_old->get_todo

IMPORTING

t_zisconttodo = t_zisconttodo.

* Label-Erstelldatum laden / geänderte Daten in Instance zurückschreiben

LOOP AT t_ziscontact INTO r_ziscontact.

r_ziscontact-zilbldate = sy-datum.

MODIFY t_ziscontact FROM r_ziscontact INDEX sy-tabix.

ENDLOOP.

CALL METHOD g_db_catalogue_labels_new->set_contact

EXPORTING

t_ziscontact = t_ziscontact.

CLEAR t_zisconttodo.

CALL METHOD g_db_catalogue_labels_new->set_todo

EXPORTING

t_zisconttodo = t_zisconttodo.

* UPDATING: ALL DATA

CALL METHOD g_bl_catalogue_labels->bl_save

EXPORTING

g_db_catalogue_labels_new = g_db_catalogue_labels_new

g_db_catalogue_labels_old = g_db_catalogue_labels_old

w_modus                   = runstatus

w_dynnr                   = detailnr

IMPORTING

r_message                 = wa_message.

IF wa_message-num EQ 600.

IF r_ziscatso-zisonr EQ '4040'.

MESSAGE s000(zi_maint1_msg)

WITH 'Contacts SO 4040 erfolgreich geändert'.

ENDIF.

ELSE.

IF r_ziscatso-zisonr EQ '4040'.

MESSAGE s000(zi_maint1_msg)

WITH 'Contacts SO 4040 update fehlgeschlagen'.

ENDIF.

ENDIF.
ENDFORM.                    " processing_save
*&---------------------------------------------------------------------*
*&      Form  save_to_ftp
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM save_to_ftp .

TYPES : local_string(512) TYPE c.

DATA: zip           TYPE REF TO cl_abap_zip,

w_iox         TYPE xstring,

result        TYPE xstring,

w_path        TYPE zipath,

w_filename    TYPE zifilename,

wa_zispsfiles TYPE zispsfiles,

w_str         TYPE string,

l_fileput     TYPE string,

l_dirput      TYPE string,

w_data        TYPE string,

w_xmlxstring  TYPE xstring,

pwd(30)       TYPE c,

login(30)     TYPE c,

direction(90) TYPE c,

key           TYPE i VALUE 26101957,

slen          TYPE i,

handle        TYPE i,

cmdindex      TYPE i,

creturn(1)    TYPE n,

commandlist   TYPE TABLE OF local_string,

local_res     TYPE TABLE OF local_string,

v_feff        TYPE abap_byte_order_mark,

wa_feff       TYPE c,

w_id(30)      TYPE c,

wc_lang(2)    TYPE c,

w_ext(7)      TYPE c,

ft            TYPE timestampl,

tstamp(21)    TYPE c,

w_dataset     TYPE zifilename.

LOOP AT it_final.

CONCATENATE w_io

it_final-panr ht

it_final-dnld ht

it_final-addrz1 ht

it_final-addrz2 ht

it_final-addrz3 ht

it_final-addrz4 ht

it_final-addrz5 ht

it_final-anrp1 ht

it_final-bcd1 ht

it_final-bcd2 ht

it_final-bcd3 ht

it_final-bcd4 ht

it_final-bcd5 ht

crlf

INTO w_io.

ENDLOOP.

CALL FUNCTION 'ECATT_CONV_STRING_TO_XSTRING'

EXPORTING

im_string   = w_io

im_encoding = 'UTF-8'

IMPORTING

ex_xstring  = w_iox

ex_len      = file_length.

CLEAR: w_path, w_filename, creturn.

v_feff = cl_abap_char_utilities=>byte_order_mark_big.

GET TIME STAMP FIELD ft.

tstamp = ft.

TRANSLATE tstamp USING '*_'.

TRANSLATE tstamp USING '._'.

filename = 'Catalougeorders_SO_4040'.

w_ext = 'xls'.

result = w_iox.

CONCATENATE filename tstamp '.' INTO w_str.

CONCATENATE filename tstamp '.' w_ext INTO l_fileput.

CONCATENATE 'put ' l_fileput INTO l_fileput SEPARATED BY space.

CONCATENATE 'lcd ' w_path INTO l_dirput SEPARATED BY space.

CONCATENATE w_path filename tstamp '.' w_ext INTO w_str.

w_dataset = w_str.

OPEN DATASET w_str FOR OUTPUT IN BINARY MODE.

TRANSFER result TO w_str.

CLOSE DATASET w_str.

CLEAR: result, w_iox.

"----- ftp ftp ftp ftp ftp ---------------------------------------

pwd       = '8537hsds'.

direction = 'ftp.nicoud.nl'.

login     = 'USER2'.

slen = STRLEN( pwd ).

CALL FUNCTION 'HTTP_SCRAMBLE'

EXPORTING

SOURCE      = pwd

sourcelen   = slen

key         = key

IMPORTING

destination = pwd.

CALL FUNCTION 'FTP_CONNECT'

EXPORTING

user            = login

password        = pwd

host            = direction

rfc_destination = 'SAPFTPA'

IMPORTING

handle          = handle

EXCEPTIONS

not_connected   = 1.

creturn = sy-subrc.

CONCATENATE 'put' w_str INTO w_str SEPARATED BY space.
*  if wa_zispsfiles-ziext = 'csv'.
*    if wa_zispsfiles-zipath = 'old'.
*      append 'cd ServiceFiles' to commandlist.
*    else.
*      append 'cd ServiceFiles/_V3' to commandlist.
*    endif.
*  endif.

APPEND l_dirput              TO commandlist.

APPEND 'binary'              TO commandlist.

APPEND l_fileput             TO commandlist.
*  append 'quit'                to commandlist.

CALL FUNCTION 'FTP_COMMAND_LIST'

EXPORTING

handle        = handle

IMPORTING

command_index = cmdindex

TABLES

data          = local_res

commands      = commandlist

EXCEPTIONS

command_error = 1

tcpip_error   = 2

data_error    = 3.

IF creturn = 0.

creturn = sy-subrc.

ENDIF.

CALL FUNCTION 'FTP_DISCONNECT'

EXPORTING

handle = handle.

IF creturn = 0.

creturn = sy-subrc.

ENDIF.

IF creturn = 0 .

DELETE DATASET w_dataset.

ENDIF.

ENDFORM.

0 Kudos

Hello Bala,

thank you for your answer.

But I can't see, how I can use your program code for my purpuse : I have to create a program that makes a cost estimation (such as the transaction CKW1) and I was wondering if I could use the class CL_COST_ESTIMATE.

Best regards,

Holger