161 Abap 1.0
161 Abap 1.0
161 Abap 1.0
Costing BOM's can be deleted / * * created with reference to the Production BOM * * * * Created by : Satyam Computer Services Limited. * * * * Created on : June'20,2001 * * * *&---------------------------------------------------------------------* * Modification Log * *&---------------------------------------------------------------------* * Developer Date Transport # Details * * ----------------------------------- -------* * H.S.Ramachandra 20/06/2001 AC4K900486 Initial development* * * ************************************************************************ report y1co_pcacr003 message-id y1co line-size 170 line-count 255 no standard page heading. *&---------------------------------------------------------------------* * include for header/footer data print *&---------------------------------------------------------------------* include y1selection_screen. *
*&---------------------------------------------------------------------* * include for header (top of page) using text element HPCE ESAP SYSTEMS* *&---------------------------------------------------------------------* include y1bc_genaci030. *&---------------------------------------------------------------------* * include for data declartion * *&---------------------------------------------------------------------* include y1co_pcaci003t. *&---------------------------------------------------------------------* * All forms are included in this include *&---------------------------------------------------------------------* include y1co_pcaci003f. *&---------------------------------------------------------------------* * Initialisation for printing default values *&---------------------------------------------------------------------* initialization. * Get the default values perform f_default_values. *&---------------------------------------------------------------------* * Validation for selection screen fields *&---------------------------------------------------------------------* at selection-screen. * validation for company code * *
perform f_validate_bukrs. * validation for controlling area perform f_validate_kokrs. * validation for plant perform f_validate_werks. * validation for material perform f_validate_matnr. * validation for plant specific material status perform f_validate_psmat. * validation for BOM usage perform f_validate_bomusg. * validation for selected company code belong to selected controlling * area perform f_validate_bukrs_kokrs. * validation for selected plant belong to selected company code perform f_validate_bukrs_bwkey. * validation for selected materials belong to selected plant perform f_validate_matnr_werks. * validations based on selection screen input parameter values perform f_validate_selection_screen. * creating help for deletion indicator at selection-screen on help-request for p_delbom. * This perform will add records in the table i_help. i_help will be * having text for perform f_append_help. * This perform will be executed when F1 key is pressed on the Test Run * checkbox. It will show a documentation for the same perform f_document using v_title. at selection-screen on help-request for p_test. * This perform will add records in the table i_help perform f_help_testrun. * This perform will be executed when F1 key is pressed on the Output * with user input checkbox.It will show a documentation for the same perform f_document using v_title. at selection-screen on help-request for p_chkbox. * This perform will add records in the table i_help perform f_help_output. * This perform will be executed when F1 key is pressed on the Output * with user input checkbox. It will show a documentation for the same perform f_document using v_title. at selection-screen on help-request for p_rfirst.
* This perform will add records in the i_help table perform f_help_frdb. * This perform will be executed when F1 key is pressed on the on * First page radio button is clicked perform f_document using v_title. at selection-screen on help-request for p_rlast. * This perform will append records in the i_help table perform f_help_lrdb. * This perform will be executed when F1 key is pressed on the on * last page radio button is clicked perform f_document using v_title. *&---------------------------------------------------------------------* * Selection of records from database *&---------------------------------------------------------------------* start-of-selection. * select materials from table MARC and MARA perform f_get_material. * select related BOMs based on matnr (material) perform f_get_related_bom. * select BOM status by reading table STKO based on i_mast internal table perform f_get_bom_status. * if at all any duplicate record comes into internal table as per the * user defined criteria,then checking for the same if not i_mast_stko[] is initial. * populate the record to user for record selection through checkboxes perform f_get_checkbox. * if duplicate entries are not exist, then population of the records * to user will not be required, hence based on final internal table * bdc process will be done else. * selecting records from table MAST and deleting based on user input * criteria for previous costing BOMs (ie usage 6 which is a default * value) by calling transaction code CS02 perform f_get_prvcstbom. * deleting previous costing BOMs through calling transaction code CS02 perform f_get_bdc_delete_bom. * * * * selecting records from table STAS and STPO based on BOM exist in final internal table i_bdc. After reading these tables, related component etc. will be store in i_bdc and then this data will be used for creating costing BOMs through BDC sort i_bdc by stlnr stlal. perform f_get_cstbom. *
* creating costing BOMs through calling transaction code CS01 perform f_get_bdc_create_bom. * calling tabstrip for report execution, which has three subscreens.
* * * *
individual subscreen is attached to one alv grid,individual alv grid is executing different report. screen 100 is for tabstrip,screen 200 for BOM copying items display screen 300 is for BOM deletion display and screen 400 for error log display call screen 100.
* refreshing internal table perform f_free_memory. endif. * after user press execute icon on display list this process will * trigger. perform from f_get_prvcstom...onwards will be fired in both * the cases ie for duplicate and unique records at user-command. * * * * * this process will collect the information from display list as to user has chosen how many records, and whether they are in valid criteria or not. If selection of records are not appropriate then corresponding error messages will be displayed otherwise the records will be sent to final internal table.
* reading values from output and moving selected 'X' records into an * internal table to check for duplicate/uniqueness of the records perform f_get_exec. * * * * * * * EXPLAINATION as to,why perform prvcstbom ... onwards till call screen 100 has been written twice. Once at user command triggers, codes below that can not be executed. In our case prvcstbom... till call screen 100 should necessarily be fired, irrespective of user gets the selection popup or not. Doing this the selection screen which were populated to the user even if there is no duplicate record, can be avoided
* selecting records from table MAST and deleting based on user input * criteria for previous costing BOMs (ie usage 6 which is a default * value) by calling transaction code CS02 perform f_get_prvcstbom. * deleting previous costing BOMs through calling transaction code CS02 perform f_get_bdc_delete_bom. * * * * selecting records from table STAS and STPO based on BOM exist in final internal table i_bdc. After reading these tables, related component etc. will be store in i_bdc and then this data will be used for creating costing BOMs through BDC sort i_bdc by stlnr stlal. perform f_get_cstbom.
* creating costing BOMs through calling transaction code CS01 perform f_get_bdc_create_bom. * * * * * calling tabstrip for report execution, which has three subscreens. individual subscreen is attached to one alv grid,individual alv grid is executing different report. screen 100 is for tabstrip,screen 200 for BOM Copying items display screen 300 is for BOM deletion display and screen 400 for error log display call screen 100. *
end-of-selection.
************************************************************************ * INCLUDE Y1CO_PCACI003T - for data declaration * ************************************************************************ * Developer Date Transport # * * ----------------------------------* * H.S.Ramachandra 20/06/2001 AC4K900486 * * * ************************************************************************ *&---------------------------------------------------------------------* * Database tables used in the program * *&---------------------------------------------------------------------* tables: mast, marc, mara, tka01, tka02, t001k, csks, t001, t416, t001w. " Material to BOM Link " Plant Data for Material " General Material Data " Controlling Areas " Controlling area assignment " Valuation area " Cost Center Master Data " Company Codes " BOM Usage - Item Statuses " Plants/Branches
*&---------------------------------------------------------------------* * Variables declaration * *&---------------------------------------------------------------------* data: v_gjahr like bseg-gjahr, v_nextqtr(1) type n, v_nxtqtr(1) type c, v_stllt2(2), " Fiscal year " Next Quarter " for concatenate purpose to " reflect v_stllt2 " result of c_1 and v_nextqtr " concatenate will be stored in " this constant " variable for controlling area which will be used at the time of validation using BAPI function module. The importing value will be stored in this variable and will be compared with the controlling area parameter value used in the selection screen
v_kokrs like tka01-kokrs, " " " " " " " " v_counter(2), v_del_counter(2),
" variable for counter which is " used to track duplicate records " variable for counter which is " to be used to track while " running BDC how many records " were successfully deleted " variable for counter which is " to be used to track while " running BDC how many records
v_crt_counter(2),
" were successfully created v_err_counter(2), " variable for counter which is " to be used to track while " running BDC how many errors " occured " variable to track first record " of the internal table which is " to be used to comapre variable " with work area " variable to track first record
v_initial(1),
v_flag(1),
v_matnr like mast-matnr, " variable for material which is " to be initialise with work area " and then to be moved into final " internal table ie i_bdc v_werks like mast-werks, " variable for plant which is to " be initialise with work area " and then to be moved into final " internal table ie i_bdc v_stlnr like mast-stlnr, " variable for BOM which is to be " initialise with work area and " then to be moved into final " internal table ie i_bdc " variable for BOM usage which is " to be initialise with work area " and then to be moved into final " internal table ie i_bdc " " " " v_stlst like stko-stlst, " variable for alternative BOM which is to be initialise with work area and then to be moved into final internal table ie i_bdc
" variable for BOM status which " is to be initialise with work " area and then to be moved into " final internal table ie i_bdc " variable for checkbox for user " selection " " " " " variable to store p_budat1 value in DD.MM.YYYY format to store in internal table which is to be used while running BDC to store valid from date
v_menge(13),
" variable to hold quantity as " character which will be used at " the time of running BDC " name of the the company, which " will be used to print on report
" name of the controlling area " which will be used to print on " report
v_name1 like t001w-name1, " Name of the plant which will " be used to print on report v_error_msgtxt(300), " variable to hold BDC error " message text from function " module
v_msgv1 like balm-msgv1, " variable for error messages " which will hold the error " description v_msgv2 like balm-msgv2, " variable for error messages " which will hold the error " description v_msgv3 like balm-msgv3, " variable for error messages " which will hold the error " description v_msgv4 like balm-msgv4, " variable for error messages " which will hold the error " description v_colname(255), v_colshrt(10), " variable to store the alv grid " record value " variable to store the alv grid " column value , which is used to " correlate to a transaction code
v_msgtxt like arrang_err, " variable to hold list of error " messages with message id, type " class etc. v_title(50), " variable to hold the title, " which is to be populated on " help window " variable to hold the counter " which is to be used for sl.no. " increment for components while " costing BOM creation. " variable to hold the counter " which is to be used for looping " no.of times based on available " components " " " " " v_bdcfld(20). " variable to hold the counter which is to be used for looping no.of times based on BDC run. in BDC run based on one record of internal table, twice BDC has to process
v_cnt(2) type n,
v_cnt1 type i,
v_cnt2 type i,
" variable to hold the values and " sl. no. counter which is
" concatenated into this variable " while BDC run *&---------------------------------------------------------------------* * Constants declaration * *&---------------------------------------------------------------------* constants: c_stlans_1 value '1', c_stlals_01(2) value '01', c_stlnt1_6 value '6', c_stllt1_01(2) value '01', c_stlnt2_6 value '6', c_1 value '1', " " " " " c_stlan_1 value '1', " " " " c_stlan_3 value '3', " " " " c_stlst(2) value '03', " " " " " constant for default value of " source BOM usage " constant for default value of " source alternative BOM " constant for default value of " target BOM usage " constant for default value of " target alternative BOM " constant for default value of " target BOM usage " constant for default dynamic concatenate '1' which will be used as prefix with the quarter obtained from functional module eg.11,12,13,14 alternatives for quarter 1,2,3,4 " constant for bom usage which is to be checked while collecting data from table MAST ref. perform f_get_related_bom.holds value as '1' " constant for bom usage which is to be checked while collecting data from table MAST ref. perform f_get_related_bom.holds value as '3' " constant for bom active status which has to be '03' only. This will be used while transferring active status record to final internal table
c_matnr(5) type c value 'MATNR', " constant for alv grid field " catalog value c_maktx(5) type c value 'MAKTX', " constant for alv grid field " catalog value c_stlan(5) type c value 'STLAN', " constant for alv grid field " catalog value c_stlal(5) type c value 'STLAL', " constant for alv grid field " catalog value c_msgtyp(6) type c value 'MSGTYP', " constant for alv grid field
" cataglog value c_errtyp(8) type c value 'Err.Type', " constant for alv grid field " cataglog value c_msgid(5) type c value 'MSGID', " constant for alv grid field " cataglog value c_errid(6) type c value 'Err.ID', " constant for alv grid field " cataglog value c_msgnr(5) type c value 'MSGNR', " constant for alv grid field " cataglog value c_errno(7) type c value 'Err.No.', " constant for alv grid field " cataglog value c_msgtxt(6) type c value 'MSGTXT', " constant for alv grid field " cataglog value c_x value 'X', " constant which holds the value " X, which is used for checkboxes " validations " used as general constant " wherever EXEC (sy-comm) is reqd " used as general constant " wherever EXIT is required " used as general constant " wherever BACK is required " used as general constant " wherever CANC is required " used as general constant " wherever FC1 is required " used as general constant " wherever FC2 is required " used as general constant " wherever FC3 is required " used as general constant " wherever space is required " used as general constant " wherever E (error) is required " used as general constant " wherever 0 is required " No. of lines skip (used as " general constant wherever 1 is " required) " No.of lines skip " used as general constant
c_exec(4) value 'EXEC', c_exit(4) value 'EXIT', c_back(4) value 'BACK', c_canc(4) value 'CANC', c_fc1(3) value 'FC1', c_fc2(3) value 'FC2', c_fc3(3) value 'FC3', c_space value ' ', c_e value 'E', c_0 value 0, c_001 value 1,
" wherever 3 is required c_4 value 4, c_5 value 5, c_6 value 6, c_7 value 7 type n, c_11(2) value '11', c_12(2) value '12', c_13(2) value '13', c_14(2) value '14', " used as general constant " wherever 4 is required " used as general constant " wherever 5 is required " used as general constant " wherever 6 is required " used as general constant " wherever 7 is required " used as general constant " wherever 11 is required " used as general constant " wherever 12 is required " used as general constant " wherever 13 is required " used as general constant " wherever 14 is required
c_display(7) value 'DISPLAY', " constant for passing as a " parameter to help funtion " module " COPO_POPUP_TO_DISPLAY_TEXTLIST c_dsp(3) value 'DSP', c_01 value '1', " constant for parameter display " constant which will hold value " '1' and is used for displaying " help text in column no.1 " constant which will hold value " '2' and is used for displaying " help text in column no.2 " constant which will hold value " '3' and is used for displaying " help text in column no.3 " constant which will hold value " '4' and is used for displaying " help text in column no.4 " constant for parid (BUK) which " is used to compare with the " login details for company code " existence check " constant for value 'Y' (yes) " its a general declaration which " is to be used for yes wherever " required " constant to hold value 'S' " which is of msgtyp of bdc table
" this is used to check as a " parameter, whether the BDC was " successful or not c_29(2) value '29', " " " " c_030(3) value '030', " " " " c_032(3) value '032', " " " " c_034(3) value '034'. " " " " " constant to hold value '29' which is of msgid of bdc table this is used to check as a parameter, whether the BDC was successful or not " constant to hold value '030' which is of msgid of bdc table this is used to check as a parameter, whether the BDC was successful or not " constant to hold value '032' which is of msgid of bdc table this is used to check as a parameter, whether the BDC was successful or not " constant to hold value '034' which is of msgid of bdc table this is used to check as a parameter, whether the BDC was successful or not
*&---------------------------------------------------------------------* * Declarations for ALV Grid variables and internal tables * *&---------------------------------------------------------------------* * defining screen numbers for tabstrip,0200 will consist costing BOM * creation, 0300 will consist costing BOMs marked for deletion, 0400 * will consist error report data: ok_code(4), * defining three containers for individual screen/report. BOM,BOM1,ERROR * for costing BOM creation, costing BOMs marked for deletion, error * report respectively g_container type scrfname value 'BOM', g_container1 type scrfname value 'BOM1', g_container2 type scrfname value 'ERROR', * defining three grids for individual containers,grid1,grid2,grid3 grid1 type ref to cl_gui_alv_grid, grid2 type ref to cl_gui_alv_grid, grid3 type ref to cl_gui_alv_grid, * defining three custom containers g_custom_container type ref to cl_gui_custom_container, g_custom_container1 type ref to cl_gui_custom_container, g_custom_container2 type ref to cl_gui_custom_container, gs_layout type lvc_s_layo. * defining field catalogs. i_fieldcat1 is used for both costing * BOM creation and deletion, since the layout is same for both the * conditions. i_fieldcat2 holds error layout. gi_tab is used to trap * user selected values from alv grid data: i_fieldcat1 type lvc_t_fcat with header line, i_fieldcat2 type lvc_t_fcat with header line, gi_tab type lvc_t_cell.
* class declaration class class class class class class lcl_event_receiver_200 lcl_event_receiver_300 lcl_event_receiver_400 lcl_event_receiver_500 lcl_event_receiver_600 lcl_event_receiver_700 definition definition definition definition definition definition deferred. deferred. deferred. deferred. deferred. deferred.
to to to to to to
* creating bom as tabstrip control controls: BOM type tabstrip. *&---------------------------------------------------------------------* * Types declaration * *&---------------------------------------------------------------------* types: * for table T001 * structure for company code details begin of t_t001, bukrs like t001-bukrs, " company code butxt like t001-butxt, " name of the the company end of t_t001, * for table TKA01 * structure for controlling area details begin of t_tka01, kokrs like tka01-kokrs, " controlling area bezei like tka01-bezei, " name of the controlling area end of t_tka01, * for table T001W * structure for plant details begin of t_t001w, werks like t001w-werks, name1 like t001w-name1, end of t_t001w,
* for table MARA * structure for general material data, which will be used to validate * whether any source BOM is exist or not, else it will be reorted to * error report begin of t_mara, matnr like mara-matnr, " material number end of t_mara, * for table MAKT * structure for material details begin of t_makt, matnr like makt-matnr,
* for table MAST and STKO jointly (only one field of stko) * structure for selected materials related BOMs and BOM status begin of t_mast_stko, matnr like mast-matnr, " material number werks like mast-werks, " plant stlnr like mast-stlnr, " bill of material stlan like mast-stlan, " BOM usage stlal like mast-stlal, " alternative BOM stlst like stko-stlst, " BOM status end of t_mast_stko, * final internal table which will hold the record to create costing BOMs begin of t_bdc, matnr like mast-matnr, " material number maktx like makt-maktx, " description of the material werks like mast-werks, " plant stlnr like mast-stlnr, " bill of material stlan like mast-stlan, " BOM usage stlal like mast-stlal, " alternative BOM stlst like stko-stlst, " BOM status stlkn like stas-stlkn, " BOM item node number idnrk like stpo-idnrk, " BOM component postp like stpo-postp, " Item category (bill of " material) menge like stpo-menge, " Component quantity mark(1), " mark for deletion indicator end of t_bdc, * internal table which will hold the record to create costing BOMs while * running BDC and also the info. whether the record was successfully * created or not begin of t_bom_created, matnr like mast-matnr, " material number maktx like makt-maktx, " description of the material werks like mast-werks, " plant stlnr like mast-stlnr, " bill of material stlan like mast-stlan, " BOM usage stlal like mast-stlal, " alternative BOM stlst like stko-stlst, " BOM status stlkn like stas-stlkn, " BOM item node number idnrk like stpo-idnrk, " BOM component postp like stpo-postp, " Item category (bill of " material) menge like stpo-menge, " Component quantity mark(1), " mark for creation indicator end of t_bom_created, * for table STKO * structure for BOM status begin of t_stko, stlnr like stko-stlnr, stlal like stko-stlal, stlst like stko-stlst, end of t_stko, * for table MAST * structure for related BOMs begin of t_mast,
matnr like mast-matnr, maktx like makt-maktx, werks like mast-werks, stlan like mast-stlan, stlal like mast-stlal, mark(1), end of t_mast,
" material number " description of the material " plant " BOM usage " alternative BOM " mark for deletion indicator
* for table MAST * structure for related BOMs (to avoid select under loop) begin of t_mast1, matnr like mast-matnr, " material number werks like mast-werks, " plant stlan like mast-stlan, " BOM usage stlnr like mast-stlnr, " Bill of material stlal like mast-stlal, " alternative BOM mark(1), " mark for deletion indicator end of t_mast1, * for table STAS * sturcture for BOMs-Item Selection begin of t_stas, stlnr like stas-stlnr, " Bill of material stlal like stas-stlal, " Alternative BOM stlkn like stas-stlkn, " BOM item node number stasz like stas-stasz, " Internal counter lkenz like stas-lkenz, " Deletion indicator end of t_stas, * for table STPO * sturcture for BOM-Item begin of t_stpo, stlnr like stpo-stlnr, stlkn like stpo-stlkn, stvkn like stpo-stvkn, lkenz like stpo-lkenz, idnrk like stpo-idnrk, postp like stpo-postp,
" Bill of material " BOM item node number " BOM item node number " Deletion indicator " BOM component " Item category (bill of " material) menge like stpo-menge, " Component quantity meins like stpo-meins, " Component unit of measure end of t_stpo, * structure for error recording while running BDC. This is the final * table for errors, from where errors will be printed begin of t_error, tcode like bdcmsgcoll-tcode, " BDC Transaction code dyname like bdcmsgcoll-dyname, " Batch input module name dynumb like bdcmsgcoll-dynumb, " Batch input screen number msgtyp like bdcmsgcoll-msgtyp, " Batch input message type msgspra like bdcmsgcoll-msgspra, " Language ID of a message msgid like bdcmsgcoll-msgid, " Batch input message ID msgnr like bdcmsgcoll-msgnr, " Batch input message number msgv1 like bdcmsgcoll-msgv1, " Variable part of a message msgv2 like bdcmsgcoll-msgv2, " Variable part of a message msgv3 like bdcmsgcoll-msgv3, " Variable part of a message msgv4 like bdcmsgcoll-msgv4, " Variable part of a message env like bdcmsgcoll-env, " Batch input monitoring activity fldname like bdcmsgcoll-fldname, " Field name msgtxt(300), " To hold error messages matnr like mast-matnr, " material number
* Types declaration for internal table i_help types: begin of t_help. include structure tline. " Structure tline types: end of t_help. *&---------------------------------------------------------------------* * Internal tabel declaration * *&---------------------------------------------------------------------* data: i_makt type standard table of t_makt, i_mara type standard table of t_mara, i_mast_stko type standard table of t_mast_stko, i_stko type standard table of t_stko, i_error type standard table of t_error, * * * * * * * * * * final internal table which consist of records,needed to create costing BOMs through BDC. This has the same structure as i_mast_stko. The only difference is i_mast_stko will be having more than one active source BOM for one material and plant combination and this internal table will be popped up to user for appropriate selection through checkboxes and then finaly after all the necessary validations, filtered records will be coming to i_bdc (the final internal table), but in case of only one active source BOM for one material and plant combination the record will directly move to final internal table ie i_bdc
i_bdc type standard table of t_bdc, i_chkbx type standard table of t_mast_stko, i_mast type standard table of t_mast, i_mast1 type standard table of t_mast1, i_stas type standard table of t_stas, i_stpo type standard table of t_stpo, i_bom_created type standard table of t_bom_created, i_bdcdata like bdcdata occurs 0 with header line, * internal table for error recording while running BDC.This table will * hold only one record at a time and then it will be transferred to * to another internal table, and this table will be refreshed i_bdcerror type standard table of t_error with header line, * internal table for error recording while running BDC. This internal * table. Error description etc will be saved in this file and finally * all error 'E' records will be dumped to i_error table for final error * report printout i_bdcerror1 type standard table of t_error with header line, * Internal table for storing the help text for the fields on the * selection screen wherever applicable i_help type standard table of t_help, * internal table to hold bapi return value, it is used to validate * company code return value i_return like bapireturn . *&---------------------------------------------------------------------* * Workarea declaration *
*&---------------------------------------------------------------------* data: wa_makt type t_makt, " material details wa_mara type t_mara, " general material details wa_mast_stko type t_mast_stko, " BOM related material wa_stko type t_stko, " BOM status wa_error type t_error, " error information wa_bdc type t_bdc, " base data for BOM creation wa_chkbx type t_mast_stko, " to keep user selected info. wa_mast type t_mast, " records for deletion of BOMs wa_mast1 type t_mast1, " records to get related BOM wa_stpo type t_stpo, " BOM - Item wa_bom_created type t_bom_created, " Final Internal table wa_bdcerror1 type t_error, " temporary file for error info. * Workarea for storing the help text for the fields on the * selection screen wherever applicable wa_help type t_help. " help text storing *&---------------------------------------------------------------------* * Selection screen details * *&---------------------------------------------------------------------* * selection screen for the frame 1. Text-001 text symbol * contains the frame title which is 'User Input' selection-screen begin of block b1 with frame title text-001. * parameter for company code which has to be picked up from user master * ie from table USR05 selection-screen begin of line. * text-019 (Company Code) selection-screen comment 1(32) text-019. parameter : p_bukrs like t001-bukrs obligatory. selection-screen end of line. * parameter for controlling area which will be coming from functional * module by passing company code selection-screen begin of line. * text-020 (Controlling Area) selection-screen comment 1(32) text-020. parameter : p_kokrs like csks-kokrs obligatory. selection-screen end of line. * Range for material selection-screen begin of line. * text-021 (Material) selection-screen comment 1(29) text-021. select-options : s_matnr for mara-matnr obligatory. selection-screen end of line. * parameter for Plant selection-screen begin of line. * text-022 (Plant) selection-screen comment 1(32) text-022. parameter : p_werks like marc-werks obligatory. selection-screen end of line. * parameter for plant specific material status selection-screen begin of line. * text-023 (Plant specific material status)
selection-screen comment 1(32) text-023. parameter : p_mmsta like marc-mmsta. selection-screen end of line. * parameter for X-plant status selection-screen begin of line. * text-024 (X-plant status) selection-screen comment 1(32) text-024. parameter : p_mstae like mara-mstae. selection-screen end of line. * parameter for source BOM usage selection-screen begin of line. * text-025 (Source BOM Usage) selection-screen comment 1(32) text-025. parameter : p_stlans like mast-stlan obligatory default c_stlans_1. selection-screen end of line. * parameter for source alternative BOM selection-screen begin of line. * text-026 (Source Alternative BOM) selection-screen comment 1(32) text-026. parameter : p_stlals like mast-stlal obligatory default c_stlals_01. selection-screen end of line. selection-screen end of block b1. * selection screen for the frame 2. Text-002 text symbol * contains the frame title which is 'Create Costing BOMs' selection-screen begin of block b2 with frame title text-002. * parameter for target BOM usage selection-screen begin of line. * text-005 (Target BOM Usage) selection-screen comment 1(16) text-005. parameter : p_stlnt1 like mast-stlan obligatory default c_stlnt1_6 modif id dsp. * parameter for target alternative BOM * text-006 (Target Alternative BOM) selection-screen comment 25(23) text-006. parameter : p_stllt1 like mast-stlal obligatory default c_stllt1_01. * calling function module Y1_FINQUARTER_DETERMINE to derive the * next quarter. exporting system date, company code and fiscal year * and importing one digit quarter which can be 1,2,3 or 4 * parameter for valid for quarter * text-007 (Valid for Quarter) selection-screen comment 55(17) text-007. parameter : p_qtr1(1) type n obligatory default v_nextqtr modif id dsp. selection-screen end of line. * parameter for default value current fiscal year selection-screen begin of line. * text-008 (Fiscal Year) selection-screen comment 1(16) text-008. parameter : p_gjahr1 like bkpf-gjahr obligatory default v_gjahr. * parameter for default current system date
* text-009 (Valid from Date) selection-screen comment 25(23) text-009. parameter : p_budat1 like bkpf-budat obligatory default sy-datum. selection-screen end of line. selection-screen end of block b2. * selection screen for the frame 3. Text-003 text symbol * contains the frame title which is 'Create Additional Costing * BOM for volume transfer' selection-screen begin of block b3 with frame title text-003. * parameter for target BOM usage selection-screen begin of line. * text-010 (Target BOM Usage) selection-screen comment 1(16) text-010. parameter : p_stlnt2 like mast-stlan obligatory default c_stlnt2_6 modif id dsp. * parameter for target alternative BOM * text-011 (Target Alternative BOM) selection-screen comment 25(23) text-011. parameter : p_stllt2 like mast-stlal obligatory. * parameter for valid for quarter ie immediate next quarter * text-012 (Valid for Quarter) selection-screen comment 55(17) text-012. parameter : p_qtr2(1) type n obligatory default v_nextqtr modif id dsp. selection-screen end of line. * parameter for default value current fiscal year selection-screen begin of line. * text-013 (Fiscal Year) selection-screen comment 1(16) text-013. parameter : p_gjahr2 like bkpf-gjahr obligatory default v_gjahr modif id dsp. * parameter for default current system date * text-014 (Valid from Date) selection-screen comment 25(23) text-014. * valid from date will be same as valid from date defined earlier in * frame-2. The moment user will make change in that, this date will * also get changed accordingly. Its for display purpose parameter : p_budat2 like p_budat1 default p_budat1 modif id dsp. selection-screen end of line. selection-screen end of block b3. * selection screen for the frame 4. Text-004 text symbol contains the * frame title which is 'Execution Mode' selection-screen begin of block b4 with frame title text-004. * parameter for delete existing BOM parameter : p_delbom as checkbox. * parameter for Test run and default is 'X' parameter : p_test as checkbox default c_x.
selection-screen end of block b4. selection-screen begin of block output with frame title text-001. " User Input * parameters for standard output settings, wherein user selection * parameters have to be printed on first/last page parameters: p_chkbox as checkbox. parameters: p_rfirst radiobutton group radi, p_rlast radiobutton group radi default 'X'. selection-screen end of block output. at selection-screen output. * * * * if fiscal year entered is current fiscal year then calling function module else storing next quarter as 1. p_gjahr1 is the parameter for entered fiscal year and v_gjahr holds the value of current fiscal year. By comparing both current fiscal year can be determined call function 'Y1_FINQUARTER_DETERMINE' exporting i_budat = p_budat1 i_bukrs = p_bukrs i_gjahr = v_gjahr importing e_nextqtr = v_nextqtr e_gjahr = v_gjahr exceptions company_code_doesnt_exists =1 fiscal_yr_variant_doesnt_exist = 2 others = 3. if sy-subrc ne 0. message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif. * next quarter parameter for frame 2 p_qtr1(1) = v_nextqtr. * fiscal year parameter for frame 2 p_gjahr1 = v_gjahr. * next quarter parameter for frame 3 p_qtr2(1) = v_nextqtr. * fiscal year parameter for frame 3 p_gjahr2 = v_gjahr. * variable to hold the value of next quarter (for concatenating purpose) v_nxtqtr = v_nextqtr. * concatenating c_1 (ie 1) and v_nxtqtr (the quarter obtained from FM * say 3). After concatenating it will become '13' which is getting * stored into variable v_stllt2 concatenate c_1 v_nxtqtr into v_stllt2. * initialisation of variable with parameter which will be displayed by * default in the selection screen p_stllt2 = v_stllt2. p_budat2 = p_budat1. * validating screen for parameter display
loop at screen. * looping parameters which are in DSP (ie diaplay) group check screen-group1 = c_DSP. * restricting parameters to display only screen-input = c_0. modify screen. endloop. *&--------------------------------------------------------------------* * class lcl_event_receiver_200 definition * *&--------------------------------------------------------------------* * class definition for double click event * *---------------------------------------------------------------------* class lcl_event_receiver_200 definition. public section. methods: double_click_200 for event double_click of cl_gui_alv_grid importing e_row e_column. endclass. " lcl_event_receiver_200 *&--------------------------------------------------------------------* * class lcl_event_receiver_200 implementation * *&--------------------------------------------------------------------* * class implementation * *---------------------------------------------------------------------* class lcl_event_receiver_200 implementation. method double_click_200. " this method handles the node " double click event of the tree " control instance * trapping the user double click value read table i_bom_created index e_row-index into wa_bom_created. check sy-subrc eq 0. * getting the selected cells value from alv grid and storing into an * internal table gi_tab, which has a complete record call method grid1->get_selected_cells importing et_cell = gi_tab. * reading internal table record 1 and moving into a variable read table gi_tab index 1 into v_colname. * picking matnr from v_colname which has the complete record. * positioning the matnr value from v_column and moving into * a variable vcolshrt move v_colname+0(23) to v_colshrt. * if trapped value is matnr then calling transaction code MM03 else * calling transaction code CS03 if v_colshrt eq c_matnr. set parameter id 'MAT' field wa_bom_created-matnr. call transaction 'MM03' and skip first screen . set parameter id 'MAT' field space. else. * if test indicator is not checked then only process CS03. To pass * parameter values stlal does not have any parameter id, hence passing * through bdcdata and calling transaction code for display purpose if p_test ne c_x. perform bdc_dynpro using 'SAPLCSDI' '0100'. perform bdc_field using 'RC29N-MATNR' wa_bom_created-matnr.
perform bdc_field using 'RC29N-WERKS' wa_bom_created-werks. perform bdc_field using 'RC29N-STLAN' wa_bom_created-stlan. perform bdc_field using 'RC29N-STLAL' wa_bom_created-stlal. perform bdc_field using 'BDC_OKCODE' '/00'. call transaction 'CS03' using i_bdcdata mode c_e. clear i_bdcdata[]. endif. endif. clear gi_tab[]. endmethod. " handle_double_click endclass. " lcl_event_receiver_200 *&--------------------------------------------------------------------* * class lcl_event_receiver_300 definition *&--------------------------------------------------------------------* * class definition for double click event *---------------------------------------------------------------------* class lcl_event_receiver_300 definition. public section. methods: double_click_300 for event double_click of cl_gui_alv_grid importing e_row e_column. endclass. " lcl_event_receiver_300 *&--------------------------------------------------------------------* * class lcl_event_receiver_300 implementation *&--------------------------------------------------------------------* * class implementation * *---------------------------------------------------------------------* class lcl_event_receiver_300 implementation. method double_click_300. " this method handles the node " double click event of the tree " control instance * trapping the user double click value read table i_mast index e_row-index into wa_mast. check sy-subrc eq 0. * *
* getting the selected cells value from alv grid and storing into an * internal table gi_tab, which has a complete record call method grid2->get_selected_cells importing et_cell = gi_tab. * reading internal table record 1 and moving into a variable read table gi_tab index 1 into v_colname. * picking matnr from v_colname which has the complete record. * positioning the matnr value from v_column and moving into a variable * vcolshrt move v_colname+0(23) to v_colshrt. * if trapped value is matnr then calling transaction code MM03 else * calling transaction code CS03 if v_colshrt eq c_matnr. set parameter id 'MAT' field wa_mast-matnr. call transaction 'MM03' and skip first screen . set parameter id 'MAT' field space. else. * if test indicator is checked then only process CS03. To pass
* parameter values stlal does not have any parameter id, hence passing * through bdcdata and calling transaction code for display purpose if p_test eq c_x. perform bdc_dynpro using 'SAPLCSDI' '0100'. perform bdc_field using 'RC29N-MATNR' wa_mast-matnr. perform bdc_field using 'RC29N-WERKS' wa_mast-werks. perform bdc_field using 'RC29N-STLAN' wa_mast-stlan. perform bdc_field using 'RC29N-STLAL' wa_mast-stlal. perform bdc_field using 'BDC_OKCODE' '/00'. call transaction 'CS03' using i_bdcdata mode c_e. clear i_bdcdata[]. endif. endif. clear gi_tab[]. endmethod. " handle_double_click endclass. " lcl_event_receiver_300 *&--------------------------------------------------------------------* * class lcl_event_receiver_400 definition *&--------------------------------------------------------------------* * class definition for double click event *---------------------------------------------------------------------* class lcl_event_receiver_400 definition. public section. methods: double_click_400 for event double_click of cl_gui_alv_grid importing e_row e_column. endclass. " lcl_event_receiver_400 *&--------------------------------------------------------------------* * class lcl_event_receiver_400 implementation *&--------------------------------------------------------------------* * class implementation * *---------------------------------------------------------------------* class lcl_event_receiver_400 implementation. method double_click_400. " this method handles the node " double click event of the tree " control instance * trapping the user double click value read table i_error index e_row-index into wa_error. check sy-subrc eq 0. * *
* getting the selected cells value from alv grid and storing into an * internal table gi_tab, which has a complete record call method grid3->get_selected_cells importing et_cell = gi_tab. * reading internal table record 1 and moving into a variable read table gi_tab index 1 into v_colname. * picking matnr from v_colname which has the complete record. * positioning the matnr value from v_column and moving into a variable * vcolshrt move v_colname+0(23) to v_colshrt. * if trapped value is either message type, message id, message number, * or message text then passing all these values in to a variable * v_msgtxt.
if v_colshrt eq c_msgtyp or v_colshrt eq c_msgid or v_colshrt eq c_msgnr or v_colshrt eq c_msgtxt. v_msgtxt-msgid = wa_error-msgid. v_msgtxt-msgty = wa_error-msgtyp. v_msgtxt-msgno = wa_error-msgnr. v_msgtxt-msgv1 = wa_error-msgv1. v_msgtxt-msgv2 = wa_error-msgv2. v_msgtxt-msgv3 = wa_error-msgv3. v_msgtxt-msgv4 = wa_error-msgv4. * calling function module to populate the performance assistant call function 'MM_ARRANG_DISPLAY_MESSAGE_DOCU' exporting i_error_messages = v_msgtxt i_langu = sy-langu exceptions parameter_error = 1 others = 2. if sy-subrc ne 0. message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif. endif. * calling function module to exclude preceeding zeros, so as to pass * these records to transaction code, wherein preceeding zero with a * material should not be passed call function 'CONVERSION_EXIT_MATN1_OUTPUT' exporting input = wa_error-matnr "material with preceeding zeros importing output = wa_error-matnr. "material with excluding zeros * if trapped value is matnr then calling transaction code MM03 else * calling transaction code CS03 if v_colshrt eq c_matnr. set parameter id 'MAT' field wa_error-matnr. call transaction 'MM03' and skip first screen . set parameter id 'MAT' field space. * if double click value is either usage or alternative then passing * parameter values through bdcdata and calling transaction code CS03 elseif v_colshrt eq c_stlan or v_colshrt eq c_stlal. * checking whether usage and alternative has any value or not. If no * value exist,then not calling CS03 if v_colshrt eq c_stlan and wa_error-stlan ne space or v_colshrt eq c_stlal and wa_error-stlal ne space. perform bdc_dynpro using 'SAPLCSDI' '0100'. perform bdc_field using 'RC29N-MATNR' wa_error-matnr. perform bdc_field using 'RC29N-WERKS' p_werks. perform bdc_field using 'RC29N-STLAN' wa_error-stlan. perform bdc_field using 'RC29N-STLAL' wa_error-stlal. perform bdc_field using 'BDC_OKCODE' '/00'. call transaction 'CS03' using i_bdcdata mode c_e. clear i_bdcdata[]. endif. endif. clear gi_tab[]. endmethod. " handle_double_click
endclass.
" lcl_event_receiver_400
*&---------------------------------------------------------------------* * class lcl_event_receiver definition * *&---------------------------------------------------------------------* * class definition for local event receiver (public class)-500 *----------------------------------------------------------------------* class lcl_event_receiver_500 definition. public section. methods: handle_top_of_list for event print_top_of_list of cl_gui_alv_grid, handle_end_of_list for event print_end_of_list of cl_gui_alv_grid, handle_top_of_page for event print_top_of_page of cl_gui_alv_grid, handle_end_of_report for event print_end_of_list of cl_gui_alv_grid. endclass. " lcl_event_receiver_500
*&---------------------------------------------------------------------* * c_event_receiver (implementation) * *&---------------------------------------------------------------------* * local classes: This class is for printing header and footer* * class c_event_receiver (Implementation)-500 * *&---------------------------------------------------------------------* class lcl_event_receiver_500 implementation. method handle_top_of_list. perform f_print_sel. " Print Selection Criteria endmethod. " handle_top_of_list method handle_end_of_list. perform f_print_sel. " Print Selection Criteria endmethod. " handle_end_of_list method handle_top_of_page. perform page_headings " standard page headings using text-h30. " HPCE ESAP SYSTEMS endmethod. method handle_end_of_report. perform f_end_of_report. " Footer of the Report endmethod. endclass. " lcl_event_receiver_500 *&---------------------------------------------------------------------* * class lcl_event_receiver definition * *&---------------------------------------------------------------------* * class definition for local event receiver (public class)-600 *----------------------------------------------------------------------* class lcl_event_receiver_600 definition. public section. methods: handle_top_of_list for event print_top_of_list of cl_gui_alv_grid, handle_end_of_list for event print_end_of_list of cl_gui_alv_grid, handle_top_of_page for event print_top_of_page of cl_gui_alv_grid, handle_end_of_report for event print_end_of_list of cl_gui_alv_grid.
endclass.
" lcl_event_receiver_600
*&---------------------------------------------------------------------* * c_event_receiver (implementation) * *&---------------------------------------------------------------------* * local classes: This class is for printing header and footer* * class c_event_receiver (Implementation)-600 * *&---------------------------------------------------------------------* class lcl_event_receiver_600 implementation. method handle_top_of_list. perform f_print_sel. " Print Selection Criteria endmethod. " handle_top_of_list method handle_end_of_list. perform f_print_sel. " Print Selection Criteria endmethod. " handle_end_of_list method handle_top_of_page. perform page_headings " standard page headings using text-h30. " HPCE ESAP SYSTEMS endmethod. method handle_end_of_report. perform f_end_of_report. " Footer of the Report endmethod. endclass. " lcl_event_receiver_600 *&---------------------------------------------------------------------* * class lcl_event_receiver definition * *&---------------------------------------------------------------------* * class definition for local event receiver (public class)-700 *----------------------------------------------------------------------* class lcl_event_receiver_700 definition. public section. methods: handle_top_of_list for event print_top_of_list of cl_gui_alv_grid, handle_end_of_list for event print_end_of_list of cl_gui_alv_grid, handle_top_of_page for event print_top_of_page of cl_gui_alv_grid, handle_end_of_report for event print_end_of_list of cl_gui_alv_grid. endclass. " lcl_event_receiver_700
*&---------------------------------------------------------------------* * c_event_receiver (implementation) * *&---------------------------------------------------------------------* * local classes: This class is for printing header and footer* * class c_event_receiver (Implementation)-700 * *&---------------------------------------------------------------------* class lcl_event_receiver_700 implementation. method handle_top_of_list. perform f_print_sel. " Print Selection Criteria endmethod. " handle_top_of_list method handle_end_of_list. perform f_print_sel. " Print Selection Criteria endmethod. " handle_end_of_list method handle_top_of_page.
method handle_end_of_report. perform f_end_of_report. " Footer of the Report endmethod. endclass. " lcl_event_receiver_700 *&--------------------------------------------------------------------* * data definitions for page handling * *&--------------------------------------------------------------------* * Class for page handling - Definition class page_handling definition deferred. * data: page_handler type ref to page_handling. *&--------------------------------------------------------------------* * class page_handling definition * *&--------------------------------------------------------------------* * method to declare top of page as per the standards in alv grid *---------------------------------------------------------------------* class page_handling definition. public section. methods: handle_top_of_page for event print_top_of_page of cl_gui_alv_grid. endclass. " page_handling *&--------------------------------------------------------------------* * class page_handling implementation *&--------------------------------------------------------------------* * Class for page handling - Implementation *---------------------------------------------------------------------* class page_handling implementation. method handle_top_of_page. endmethod. endclass. " page_handling * *
************************************************************************ * INCLUDE Y1CO_PCACI003F - for all subroutines * ************************************************************************ * Developer Date Transport # * * ----------------------------------* * H.S.Ramachandra 20/06/2001 AC4K900486 * * * ************************************************************************ *&---------------------------------------------------------------------* * Form f_default_values * *&---------------------------------------------------------------------* * Get the default company code through login details ie read bname* * (user) and parid (BUK) from USR05 table and get parav * *----------------------------------------------------------------------* form f_default_values. select single parva into p_bukrs from usr05 where bname eq sy-uname and parid eq c_buk. * if default company code could not be selected then flash a warning * message if sy-subrc ne 0. message w004. " Enter valid company code endif. * Get the default controlling area using function module * BAPI_CONTROLLINGAREA_FIND by exporting company code ie * p_bukrs and importing e_nextqtr which will have controlling area call function 'BAPI_CONTROLLINGAREA_FIND' exporting companycodeid = p_bukrs importing controllingareaid = p_kokrs. * if default controlling area could not be selected then flash a warning * message if p_kokrs is initial. message w000. " Enter valid Controlling Area endif. endform. " f_default_values *&---------------------------------------------------------------------* * Form f_validate_bukrs * *&---------------------------------------------------------------------* * Checking for company code existance by using function module BAPI_* * COMPANYCODE_EXISTENCECHK. taking result to internal table i_return* * and checking if return type is E, then flashing error message* *----------------------------------------------------------------------* form f_validate_bukrs. * calling function module "BAPI_COMPANYCODE_EXISTENCECHK" for validating * company code call function 'BAPI_COMPANYCODE_EXISTENCECHK' exporting companycodeid = p_bukrs importing return = i_return. * checking for return type E, if its an error,then flashing an error
* message if i_return-type eq c_e. set cursor field 'P_BUKRS'. " cursor positioing back to the " same option message e085 with p_bukrs. " Company Code &1 does not exist endif. * authority check for company code using object F_T011_BUK authority-check object 'F_T011_BUK' * passing parameter of company code id 'BUKRS' field p_bukrs * passing activity 02 (ie change) id 'ACTVT' field '02'. * if not authorised then flashing an error message if sy-subrc ne 0. set cursor field 'P_BUKRS'. " cursor positioing back to the " same option message e098 with p_bukrs. " No Authorisation for Company " Code & endif. authority-check object 'F_T011_BUK' * passing parameter of company code id 'BUKRS' field p_bukrs * passing activity 03 (ie display) id 'ACTVT' field '03'. * if not authorised then flashing an error message if sy-subrc ne 0. set cursor field 'P_BUKRS'. " cursor positioing back to the " same option message e098 with p_bukrs. " No Authorisation for Company " Code & endif. endform. " f_validate_bukrs *&---------------------------------------------------------------------* * Form f_validate_kokrs * *&---------------------------------------------------------------------* * Validation of controlling area * *----------------------------------------------------------------------* form f_validate_kokrs. * calling function module "BAPI_CONTROLLINGAREA_FIND" for validating * controlling area. p_bukrs is has the value of company code and * v_kokrs is having value of controlling area. select kokrs into tka01-kokrs from tka01 up to 1 rows where kokrs eq p_kokrs. endselect. * if could not get any value then flashing an error message if sy-subrc ne 0. set cursor field 'P_KOKRS'. " cursor positioing back to the " same option message e089 with p_kokrs. " Controlling " maintained endif. area & not
call function 'BAPI_CONTROLLINGAREA_FIND' exporting companycodeid = p_bukrs importing controllingareaid = v_kokrs. * comparing the parameter controlling area with the retrieved * controlling area from BAPI function module (which have to be same) * if not then flashing an error message if p_kokrs ne v_kokrs. set cursor field 'P_KOKRS'. " cursor positioing back to the " same option message e086 with p_bukrs p_kokrs. endif. " Company Code & does not belong " to Controlling Area &
* authority check for controlling area using object K_CKBS authority-check object 'K_CKBS' * passing parameter of controlling area id 'KOKRS' field p_kokrs * passing activity 01 (ie create) id 'ACTVT' field '01'. * if not authorised then flashing an error message if sy-subrc ne 0. set cursor field 'P_KOKRS'. " cursor positioing back to the " same option message e097 with p_kokrs. " No Authorisation " Controlling Area & endif. authority-check object 'K_CKBS' * passing parameter of controlling area id 'KOKRS' field p_kokrs * passing activity 02 (ie change) id 'ACTVT' field '02'. * if not authorised then flashing an error message if sy-subrc ne 0. set cursor field 'P_KOKRS'. " cursor positioing back to the " same option message e097 with p_kokrs. " No Authorisation " Controlling Area & endif. authority-check object 'K_CKBS' * passing parameter of controlling area id 'KOKRS' field p_kokrs * passing activity 03 (ie display) id 'ACTVT' field '03'. * if not authorised then flashing an error message if sy-subrc ne 0. set cursor field 'P_KOKRS'. " cursor positioing back to the " same option message e097 with p_kokrs. " No Authorisation for for for
" Controlling Area & endif. endform. " f_validate_kokrs *&---------------------------------------------------------------------* * Form f_validate_werks * *&---------------------------------------------------------------------* * Validation of plant * *----------------------------------------------------------------------* form f_validate_werks. * selecting data from table T001W to search for the plant as mentioned * in the input selection parameter select werks into t001w-werks from t001w up to 1 rows where werks eq p_werks. endselect. * If no records exist then flasing an error message if sy-subrc ne 0. set cursor field 'P_WERKS'. " cursor positioing back to the " same option message e091 with p_werks. endif. " Plant & does not exist
* authority check for plant using object C_STUE_WRK authority-check object 'C_STUE_WRK' * passing activity 01 (ie create) id 'ACTVT' field '01' * passing parameter of plant id 'CSWRK' field p_werks. * if not authorised then flashing an error message if sy-subrc ne 0. set cursor field 'P_WERKS'. " cursor positioing back to the " same option message e099 with p_werks. " Plant & endif. " No Authorisation for
authority-check object 'C_STUE_WRK' * passing activity 02 (ie change) id 'ACTVT' field '02' * passing parameter of plant id 'CSWRK' field p_werks. * if not authorised then flashing an error message if sy-subrc ne 0. set cursor field 'P_WERKS'. " cursor positioing back to the " same option message e099 with p_werks. " Plant & endif. " No Authorisation for
authority-check object 'C_STUE_WRK' * passing activity 03 (ie display) id 'ACTVT' field '03' * passing parameter of plant id 'CSWRK' field p_werks.
* if not authorised then flashing an error message if sy-subrc ne 0. set cursor field 'P_WERKS'. " cursor positioing back to the " same option message e099 with p_werks. " No Authorisation " Plant & endif. endform. " f_validate_werks for
*&---------------------------------------------------------------------* * Form f_validate_matnr * *&---------------------------------------------------------------------* * Validation of material * *----------------------------------------------------------------------* form f_validate_matnr. * selecting data from table MARA to search for the material as mentioned * in the input selection parameter select matnr into mara-matnr from mara up to 1 rows where matnr in s_matnr. endselect. * If no records exist then flasing an error message if sy-subrc ne 0. set cursor field 'S_MATNR'. " cursor positioing back to the " same option message e090 with s_matnr-low. " Material & does not exist endif. endform. " f_validate_matnr *&---------------------------------------------------------------------* * Form f_validate_psmat * *&---------------------------------------------------------------------* * Validation of plant specific material status * *----------------------------------------------------------------------* form f_validate_psmat. * selecting data from table MARC to search for the plant specific * material status as mentioned in the input selection parameter select mmsta into marc-mmsta from marc up to 1 rows where mmsta eq p_mmsta. endselect. * If no records exist then flasing an error message if sy-subrc ne 0. set cursor field 'P_MMSTA'. " cursor positioing back to the " same option message e092 with p_mmsta. " Plant specific material status " & is invalid endif. endform. " f_validate_psmat *&---------------------------------------------------------------------* * Form f_validate_bomusg *&---------------------------------------------------------------------* *
* Validation of BOM usage * *----------------------------------------------------------------------* form f_validate_bomusg. * selecting data from table T416 to search for the BOM usage as * mentioned in the input selection parameter select stlan into t416-stlan from t416 up to 1 rows where stlan eq p_stlans. endselect. * If no records exist then flasing an error message if sy-subrc ne 0. set cursor field 'P_STLANS'. " cursor positioing back to the " same option message e094 with p_stlans. " BOM usage & is invalid endif. endform. " f_validate_bomusg *&---------------------------------------------------------------------* * Form f_validate_bukrs_kokrs * *&---------------------------------------------------------------------* * Validation for company code to cntrolling area linkage* * This process will check whether the company code belongs to the* * selected controlling are or not * *----------------------------------------------------------------------* form f_validate_bukrs_kokrs. * selecting company code and controlling area from TKA02 table and * validating with the input parameter value for the existance of * company code and controlling area linkage select bukrs kokrs into (tka02-bukrs,tka02-kokrs) from tka02 up to 1 rows where bukrs eq p_bukrs and kokrs eq p_kokrs. endselect. * if linkage not found then flashing an error message if sy-subrc ne 0. set cursor field 'P_BUKRS'. " cursor positioing back to the " same option message e016 with p_kokrs p_bukrs." Controlling Area &1 does not " exist with company code &2 endif. endform. " f_validate_bukrs_kokrs *&---------------------------------------------------------------------* * Form f_validate_bukrs_bwkey * *&---------------------------------------------------------------------* * Validation for selected plant belong to selected company code* * linkage * *----------------------------------------------------------------------* form f_validate_bukrs_bwkey. * selecting company code and valuation area from T001K table and * validating with the input parameter value for the existance of * company code and plant(valuation area) linkage select bwkey bukrs into (t001k-bwkey,t001k-bukrs) from t001k
up to 1 rows where bwkey eq p_werks and bukrs eq p_bukrs. endselect. * if linkage not found then flashing an error message if sy-subrc ne 0. Set cursor field 'P_BUKRS'. " cursor positioing back to the " same option message e087 with " Plant & does not belong to p_werks p_bukrs. " Company Code & endif. endform. " f_validate_bukrs_bwkey *&---------------------------------------------------------------------* * Form f_validate_matnr_werks * *&---------------------------------------------------------------------* * Validation for selected materials belong to selected plant * *----------------------------------------------------------------------* form f_validate_matnr_werks. * selecting material and plant from MARC table and validating with the * input parameter value for the existance of material and plant linkage select matnr werks into (marc-matnr,marc-werks) from marc up to 1 rows where matnr in s_matnr and werks eq p_werks. endselect. * if linkage not found then flashing an error message if sy-subrc ne 0. set cursor field 'P_WERKS'. " cursor positioing back to the " same option message e088 with s_matnr-low p_werks. endif. endform. " Material & does not belong to " Plant & " f_validate_matnr_werks
*&---------------------------------------------------------------------* * Form f_validate_selection_screen * *&---------------------------------------------------------------------* * validations based on selection screen input parameter values * *----------------------------------------------------------------------* form f_validate_selection_screen. * In the selection screen, both input parameter values of BOM usage * should be different, if not an error message is being flashed if p_stlans eq p_stlnt1. set cursor field 'P_STLANS'. " cursor positioing back to the " same option message e024. endif. " Incorrect BOM usage
* if user changes the first target BOM alternative (ie target BOM * alternative mentioned in the create costing BOMs selection block) * then a warning message is being displayed if p_stllt1 eq c_11 or p_stllt1 eq c_12 or p_stllt1 eq c_13 or p_stllt1 eq c_14.
set cursor field 'P_STLLT1'. " cursor positioing back to the " same option message e096 with p_stllt1. " Alternative & Should not be " Used here endif. * this is initial counter if user changes first alternative BOM, later * if user changes again then message should not be flashed if v_flag ne c_x. if p_stllt1 ne c_stllt1_01. set cursor field 'P_STLLT1'. " cursor positioing back to the " same option message w058 with c_stllt1_01. " You are changing the BOM " alternative from & v_flag = c_x. endif. endif. * if user changes second target BOM alternative (ie target BOM * alternative mentioned in the create additional costing BOMs for * volume transfer selection block) then a warning message has to be * displayed * if first target alternative is equal to second target alternative * then flashing an error message if p_stllt1 eq p_stllt2. set cursor field 'P_STLLT2'. " cursor positioing back to the " same option message e064. endif. if p_stllt2 ne v_stllt2. * By default c_stlnt2_6 will be having '11'/'12'/'13'/'14' based on the * result of function module, but its changable. If users try to change * the same then warning message is being displayed message w063. " Recommended Use is 11 for Q1,12 " for Q2,13 for Q3 and 14 for Q4 endif. * if entered fiscal year is not a current one then storing 1 as next qtr * c_001 has value 1 if p_gjahr1 ne v_gjahr. v_nextqtr = c_001. endif. endform. " f_validate_selection_screen *&---------------------------------------------------------------------* * Form f_get_material * *&---------------------------------------------------------------------* * Selecting materials from table MARC & MARA and moving into* * internal table i_makt based on material range specified in input* * This even will be triggered only when either plant specific* * material status (p_mmsta) or X-plant status (p_mstae) are not* * blank and moving into internal table i_makt. * *----------------------------------------------------------------------* form f_get_material. * checking whether plant specific material status (p_mmsta) or " First Target alternative and " second target alternative can " not be same
* X-plant status (p_mstae) are not blank if p_mmsta ne space or p_mstae ne space. * selecting material from table MARC and moving into internal table select matnr into wa_makt-matnr from marc where matnr in s_matnr and werks eq p_werks and mmsta eq p_mmsta. append wa_makt to i_makt. endselect. * selecting material from table MARA and moving into internal table select matnr into wa_makt-matnr from mara where matnr in s_matnr and mstae eq p_mstae. append wa_makt to i_makt. endselect. endif. endform. " f_get_material *&---------------------------------------------------------------------* * Form f_get_related_bom * *&---------------------------------------------------------------------* * This process will fetch the related BOMs based on matnr.* * If plant specific material status or X-plant status is blank* * then internal table i_makt which is created, will be used as * * base to select the related BOM records, else from table MAST* * only matnr and related BOM will be selected as per the input* *----------------------------------------------------------------------* form f_get_related_bom. * checking whether plant specific material status (p_mmsta) or * X-plant status (p_mstae) are not blank if p_mmsta ne space or p_mstae ne space. * * * * if any one of the field is entered, then considering i_makt as a base to look for related BOM available in table MAST.The selection criteria is the material range, specific plant and BOM usage 1(c_stlan_1) or 3(c_stlan_3)
* dumping all records of table MAST into an internal table and checking * for source usage 1 or 3 select matnr werks stlan stlnr stlal into corresponding fields of wa_mast1 from mast. append wa_mast1 to i_mast1. endselect. sort i_mast1 by matnr werks stlan stlnr stlal. * collecting all the records which have source usage 1 or 3 loop at i_makt into wa_makt. loop at i_mast1 into wa_mast1 where matnr eq wa_makt-matnr and werks eq p_werks and ( stlan eq c_stlan_1 or stlan eq c_stlan_3 ). move:wa_mast1-matnr to wa_mast_stko-matnr, wa_mast1-werks to wa_mast_stko-werks, wa_mast1-stlan to wa_mast_stko-stlan, wa_mast1-stlnr to wa_mast_stko-stlnr,
wa_mast1-stlal to wa_mast_stko-stlal. append wa_mast_stko to i_mast_stko. endloop. endloop. else. * * * * if none of the field is entered, then selecting material as per the user input, and collecting related BOM available in table MAST. The selection criteria is the material range, specific plant and BOM usage 1(c_stlan_1) or 3(c_stlan_3) select matnr werks stlan stlnr stlal into (wa_mast_stko-matnr,wa_mast_stko-werks,wa_mast_stko-stlan, wa_mast_stko-stlnr,wa_mast_stko-stlal) from mast where matnr in s_matnr and werks eq p_werks and ( stlan eq c_stlan_1 or stlan eq c_stlan_3 ). append wa_mast_stko to i_mast_stko. endselect. endif. selecting material based on the input selection range and dumping in a table i_mast1. This table will be used to retrieve the information about which are the material, specified in input selection screen does not have source usage 1 or 3, or material itself is not exist in case of error sending those materials in error report. select matnr into table i_mara from mara where matnr in s_matnr. sort i_mast_stko by matnr. loop at i_mara into wa_mara. read table i_mast_stko into wa_mast_stko with key matnr = wa_mara-matnr binary search. if sy-subrc ne 0. wa_bdcerror1-matnr = wa_mara-matnr. wa_bdcerror1-msgtyp = 'E'. wa_bdcerror1-msgid = 'Y1CO'. wa_bdcerror1-msgnr = '080'. wa_bdcerror1-msgv1 = wa_mara-matnr. append wa_bdcerror1 to i_bdcerror1. endif. endloop. * indexing internal table by material number, plant, BOM,BOM usage, BOM * alternative sort i_mast_stko by matnr werks stlnr stlan stlal. endform. " f_get_related_bom *&---------------------------------------------------------------------* * Form f_get_bom_status * *&---------------------------------------------------------------------* * This form will give the BOM status based on the records in i_mast.* * From table STKO BOM status (stlnr) * *----------------------------------------------------------------------* form f_get_bom_status. * selecting all records of BOM header table and dumping into internal * table. This will be used for searching BOM status based on BOM * available in the internal table i_mast_stko select stlnr stlal stlst into
* * * * *
(wa_stko-stlnr,wa_stko-stlal,wa_stko-stlst) from stko. append wa_stko to i_stko. endselect. * indexing internal table by BOM,BOM alternative sort i_stko by stlnr stlal. * considering i_mast_stko as base table to look for BOM status in i_stko loop at i_mast_stko into wa_mast_stko. * reading the i_stko table comparing BOM (stlnr) and BOM usage in * both the tables and recording BOM status read table i_stko into wa_stko with key stlnr = wa_mast_stko-stlnr stlal = wa_mast_stko-stlal. * if search is succesfull, then storing the activity status and updating * the internal table if sy-subrc eq 0. wa_mast_stko-stlst = wa_stko-stlst. * if BOM status is '03' then only updating the internal table else * not considering the record for further processing and deleting * the same.c_stlst is constant having value as '03' if wa_mast_stko-stlst = c_stlst. modify i_mast_stko from wa_mast_stko. else. wa_bdcerror1-matnr = wa_mast_stko-matnr. wa_bdcerror1-stlan = wa_mast_stko-stlan. wa_bdcerror1-stlal = wa_mast_stko-stlal. wa_bdcerror1-msgtyp = 'E'. wa_bdcerror1-msgid = 'Y1CO'. wa_bdcerror1-msgnr = '081'. wa_bdcerror1-msgv1 = wa_mast_stko-matnr. append wa_bdcerror1 to i_bdcerror1. delete i_mast_stko. endif. endif. endloop. * * * * * * * Now i_mast_stko is having BOM status '03' only and taking this table as a base, uniqueness of the record will be checked.If its a unique record,then the record will be moved from i_mast_stko to i_bdc (final internal table, else it will remain in i_mast_stko so that it will be poppedup for the user selection through checkboxes. Once user selects the correct record, through chekboxes the filtered records come to final internal table ie i_bdc
* initialising counter before start of the loop. v_counter = c_0. v_initial = c_0. * looping at internal table which has both duplicate and unique records. * now in this loop moving unique records to final internal table i_bdc loop at i_mast_stko into wa_mast_stko. * storing values in variable from work area in case of first record of * internal table if v_initial eq c_0. * c_001 holds value as 1
v_initial = c_001. v_matnr = wa_mast_stko-matnr. v_werks = wa_mast_stko-werks. v_stlnr = wa_mast_stko-stlnr. v_stlan = wa_mast_stko-stlan. v_stlal = wa_mast_stko-stlal. v_stlst = wa_mast_stko-stlst. endif. * checking whether variable value and work area are equal/different * if both the values are equal then leaving those records in the same * internal table ie i_mast_stko if v_matnr eq wa_mast_stko-matnr and v_werks eq wa_mast_stko-werks. else. * if both the values are different then checking for counter. if counter * is 1,ie if there is only unique record for matnr,werks,stlnr,stlan * then only moving variable value to work area of final internal table * and append the record in i_bdc if v_counter eq c_001. wa_bdc-matnr = v_matnr. wa_bdc-werks = v_werks. wa_bdc-stlnr = v_stlnr. wa_bdc-stlan = v_stlan. wa_bdc-stlal = v_stlal. wa_bdc-stlst = v_stlst. append wa_bdc to i_bdc. clear wa_bdc. endif. * re-initialise of the counter,c_0 holds value as 0 v_counter = c_0. endif. * initialising values of work area to variable v_matnr = wa_mast_stko-matnr. v_werks = wa_mast_stko-werks. v_stlnr = wa_mast_stko-stlnr. v_stlan = wa_mast_stko-stlan. v_stlal = wa_mast_stko-stlal. v_stlst = wa_mast_stko-stlst. * counter incriment,c_001 holds value 1 v_counter = v_counter + c_001. * * * * checking end of file. if record pointer is on the last record, then checking whether its a duplicate one or a unique one. if it is a unique ie counter is 1, then only updating the internal table else leaving the last record in i_mast_stko at last. if v_counter eq c_001. wa_bdc-matnr = v_matnr. wa_bdc-werks = v_werks. wa_bdc-stlnr = v_stlnr. wa_bdc-stlan = v_stlan. wa_bdc-stlal = v_stlal. wa_bdc-stlst = v_stlst. append wa_bdc to i_bdc. clear wa_bdc. endif. * re-initialise of the counter, c_0 holds value 0 v_counter = c_0.
endat. endloop. * * * * * * now i_bdc is having unique records, whereas i_mast_stko still has duplicate as well as unique records both. Taking a base of i_bdc internal table corresponding unique records from i_mast_stko table has to be deleted so that only duplicate records remain in that, then the same table will be populated to user for selection through checkboxes sort i_bdc by matnr werks stlnr stlan stlal stlst. loop at i_bdc into wa_bdc. delete i_mast_stko where matnr eq wa_bdc-matnr and werks eq wa_bdc-werks and stlnr eq wa_bdc-stlnr and stlan eq wa_bdc-stlan and stlal eq wa_bdc-stlal and stlst eq wa_bdc-stlst. endloop. endform. " f_get_bom_status *&---------------------------------------------------------------------* * Form f_get_checkbox * *&---------------------------------------------------------------------* * This process will select filtered record for BDC run to create* * costing BOMs. From internal table i_mast_stko wherein duplicate* * records are exist, is to be populated to the user and user should be* * allowed to choose only one combination, ie one material and one* * plant. By default one combination will be selected. Error has to be* * flashed if no records or duplicate records are selected. * *----------------------------------------------------------------------* form f_get_checkbox. * initialisation of counters,c_0 holds value 0 v_counter = c_0. v_initial = c_0. * screen header uline :/1(56). format color 1. write :/1 sy-vline, 5 sy-vline, 6(18) text-021, 28 sy-vline, 29(5) text-022, 34 sy-vline, 35(5) text-027, 40 sy-vline, 41(12) text-028, 56 sy-vline. uline :/1(56). format color 3. * * * * * * * * * *
When the duplicate records (ie same material plant combination) are exist in the internal table then it has to be populated to the user and by default the selected material, plant,usage and alternative as per the input selection parameter should be ticked. If in the list no usage / alternateive exist as per the input parameters, then those entries will remain unticked and will be diaplayed as it is. Here comparing usage and alternative of work area with the input selection parameters. Plant and Material has not been consiedred for comparision since same material & plant will never have combination of same usage and alternative,
loop at i_mast_stko into wa_mast_stko. v_chkbx = c_space. if wa_mast_stko-stlan eq p_stlans and wa_mast_stko-stlal eq p_stlals. v_chkbx = c_x. write :/1 sy-vline, v_chkbx as checkbox. else. write :/1 sy-vline, v_chkbx as checkbox. endif. * writing other line items write : 5 sy-vline, 6(18) wa_mast_stko-matnr, 28 sy-vline, 29(5) wa_mast_stko-werks, 34 sy-vline, 35(5) wa_mast_stko-stlan, 40 sy-vline, 41(12) wa_mast_stko-stlal, 56 sy-vline. endloop. uline :/1(56). * created GUI for execution set pf-status '1000'. set titlebar '1000'. endform. " f_get_checkbox *&---------------------------------------------------------------------* * Form f_get_prvcstbom * *&---------------------------------------------------------------------* * This process will select records for deleting all the existing* * previous costing BOMs from table MAST * *----------------------------------------------------------------------* form f_get_prvcstbom. * if test mode is not selected * if p_test ne c_x. * if deletion indicator is not selected if p_delbom eq c_x. * * * * selecting data from MAST and dumping into an internal table when deletion indicator is not selected then selecting records for a plant usage(6),alternative(1/11/12/13/14 etc) as per user input,irrespective of material range input select matnr werks stlan stlal from mast into (wa_mast-matnr,wa_mast-werks, wa_mast-stlan,wa_mast-stlal) where werks eq p_werks and ( stlan eq p_stlnt1 and stlal eq p_stllt1 or stlan eq p_stlnt2 and stlal eq p_stllt2 ).
* calling function module to exclude preceeding zeros, so as to pass * these records for BDC creation,wherein preceeding zero with a material * should not be passed
if wa_mast-matnr ne space. call function 'CONVERSION_EXIT_MATN1_OUTPUT' exporting input = wa_mast-matnr "material with preceeding zeros importing output = wa_mast-matnr."material with excluding zeros endif. * adding records into internal table which is to be used for deletion * through BDC append wa_mast to i_mast. endselect. else. * * * * selecting data from MAST and dumping into an internal table when deletion indicator is not selected then selecting records for a plant usage(6),alternative (1/11/12/13/14 etc) as per user input,within the material range input select matnr werks stlan stlal from mast into (wa_mast-matnr,wa_mast-werks, wa_mast-stlan,wa_mast-stlal) where matnr in s_matnr and werks eq p_werks and ( stlan eq p_stlnt1 and stlal eq p_stllt1 or stlan eq p_stlnt2 and stlal eq p_stllt2 ).
* calling function module to exclude preceeding zeros, so as to pass * these records for BDC creation,wherein preceeding zero with a material * should not be passed if wa_mast-matnr ne space. call function 'CONVERSION_EXIT_MATN1_OUTPUT' exporting input = wa_mast-matnr "material with preceeding zeros importing output = wa_mast-matnr."material with excluding zeros endif. append wa_mast to i_mast. endselect. endif. * endif. * * * * * * * material description will be stored in the internal table i_makt which is used earlier, should have to be refreshed, since earlier only material codes were added into this internal table, since records were coming from table MARC and MARA into it and MARC does'nt have material description, hence deletion of records from internal table is necessary here, moreover the same records cannot be used,since here the data selection is different from the earlier data selected refresh i_makt[].
* pushing records into internal table select matnr maktx into (wa_makt-matnr,wa_makt-maktx) from makt where spras eq sy-langu. * calling function module to exclude preceeding zeros, so as to pass * these records for BDC creation,wherein preceeding zero with a material * should not be passed
if wa_makt-matnr ne space. call function 'CONVERSION_EXIT_MATN1_OUTPUT' exporting input = wa_makt-matnr " material with preceeding zeros importing output = wa_makt-matnr." material with excluding zeros endif. append wa_makt to i_makt. endselect. sort i_makt by matnr. * to store the material description, once again looping through internal * table and reading material master internal table and searching for * material description loop at i_mast into wa_mast. read table i_makt into wa_makt with key matnr = wa_mast-matnr binary search. if sy-subrc eq 0. wa_mast-maktx = wa_makt-maktx. endif. * modifying the internal table with material description modify i_mast from wa_mast. endloop. endform. " f_get_prvcstbom *&---------------------------------------------------------------------* * Form f_get_bdc_delete_bom * *&---------------------------------------------------------------------* * This process will run a BDC to delete existing costing BOMs *----------------------------------------------------------------------* form f_get_bdc_delete_bom.
* looping through internal table mast which has the records for * executing BDC for deletion. if test indicator is checked then * deletion BDC will be ignored,c_x holds value as 'X' if p_test ne c_x. v_del_counter = c_0. loop at i_mast into wa_mast. perform bdc_dynpro using 'SAPLCSDI' '0100'. perform bdc_field using 'BDC_CURSOR' 'RC29N-STLAL'. perform bdc_field using 'BDC_OKCODE' '/00'. perform bdc_field using 'RC29N-MATNR' wa_mast-matnr. perform bdc_field using 'RC29N-WERKS' wa_mast-werks. perform bdc_field using 'RC29N-STLAN' wa_mast-stlan. perform bdc_field using 'RC29N-STLAL' wa_mast-stlal. * valid from date is of date field, but to run BDC it should be of a * character type hence concatenating into a variable v_sy_date and * passing to BDC concatenate p_budat1+6(2) '.' p_budat1+4(2) '.' p_budat1(4) into v_sy_date.
perform bdc_field
using 'RC29N-DATUV' v_sy_date. perform bdc_dynpro using 'SAPLCSDI' '0150'. perform bdc_field using 'BDC_CURSOR' 'RC29P-POSNR(01)'. perform bdc_field using 'BDC_OKCODE' '=FCLO'. * calling transaction code for deletion in background (N) and pushing * all messages into i_bdcerror table call transaction 'CS02' using i_bdcdata mode 'N' update 'S' messages into i_bdcerror. * moving material,bom usage,bom alternative to i_bdcerror internal table * so that it will be used to populate in the error report as per layout loop at i_bdcerror. i_bdcerror-matnr = wa_mast-matnr. i_bdcerror-stlan = wa_mast-stlan. i_bdcerror-stlal = wa_mast-stlal. modify i_bdcerror index sy-tabix. endloop. * * * * * * * * * * * * * appending records into an internal table, since i_bdcerror will be refreshed. while running BDC if any execution error comes then, only message type, message id, message number etc. goes into internal table but as per the error report layout, respective material,BOM usage,BOM alternative should also be saved with the error, hence it is stored in i_bdcerror, moreover there may be more than one error while BDC run hence looping into i_bdcerror and saving material,BOM usage, BOM alternative in all those records. append lines of i_bdcerror to i_bdcerror1. reading i_bdcerror table,for successfull deletion.if msgtyp is S,msgid is 29 and msgnr is 034,then only it is considered as successful. c_s holds value as 'S',c_29 holds value as '29',c_034 holds value as '034' 29-034 has the description as Alternative & in the BOM for material & deleted read table i_bdcerror with key msgtyp = c_s msgid = c_29 msgnr = c_034. if bdc is successful then pass 'Y' in mark field else checking for next possibility ie for 29-032 which has the description BOM for for material & deleted. if still it unsuccessful then deleting the record else passing 'Y' to mark field so as to indicate that the bdc for deletion of record is successful. c_y holds the value Y,which indicates yes if sy-subrc eq 0. wa_mast-mark = c_y.
* * * * * *
* increasing deletion counter, which needs to be printed on report,as to * as to how many reocrds were deleted,c_001 holds value 1 v_del_counter = v_del_counter + c_001. * modifying the record with the marked deletion modify i_mast from wa_mast. else. read table i_bdcerror with key msgtyp = c_s msgid = c_29 msgnr = c_032. if sy-subrc eq 0.
wa_mast-mark = c_y. * increasing deletion counter,which needs to be printed on report as to * how many reocrds were deleted v_del_counter = v_del_counter + c_001. * modifying the record with the marked deletion modify i_mast from wa_mast. else. delete i_mast. endif. endif. * clearing/refreshing internal tables to be used for next loop refresh i_bdcdata. clear i_bdcdata. refresh i_bdcerror. clear i_bdcerror. endloop. endif. * looping into i_bdcerror which has all the messages stored in, and have * no description for those errors, hence calling function to store * message description loop at i_bdcerror1 into wa_bdcerror1. v_msgv1 = wa_bdcerror1-msgv1. v_msgv2 = wa_bdcerror1-msgv2. v_msgv3 = wa_bdcerror1-msgv3. v_msgv4 = wa_bdcerror1-msgv4. call function 'MESSAGE_PREPARE' exporting msg_id = wa_bdcerror1-msgid msg_no = wa_bdcerror1-msgnr msg_var1 = v_msgv1 msg_var2 = v_msgv2 msg_var3 = v_msgv3 msg_var4 = v_msgv4 importing msg_text = v_error_msgtxt exceptions function_not_completed =1 message_not_found =2 others = 3. if sy-subrc ne 0. message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif. * moving i_bdcerror record to i_error internal table move-corresponding wa_bdcerror1 to wa_error. * store message description which has got from functional module into * error internal table's work area wa_error-msgtxt = v_error_msgtxt. * finally appending record into error table if wa_error-msgtyp eq c_e. append wa_error to i_error. endif. clear wa_error. endloop. clear i_bdcerror1. refresh i_bdcerror1. endform. " f_get_bdc_delete_bom
*&---------------------------------------------------------------------* * Form f_get_cstbom * *&---------------------------------------------------------------------* * This process will select records which has to be used for costing* * BOMs creation through BDC * *----------------------------------------------------------------------* form f_get_cstbom. * selecting records from stlkn to internal table select stlnr stlal stlkn stasz lkenz into table i_stas from stas for all entries in i_bdc where stlnr eq i_bdc-stlnr and stlal eq i_bdc-stlal. sort i_stas descending by stlkn stasz. * deleting duplicate records based on BOM,BOM alternative,Item node delete adjacent duplicates from i_stas comparing stlnr stlal stlkn. * deleting where deletion indicator is 'X' delete i_stas where lkenz eq c_x. * selecting records from stlnr to internal table select stlnr stlkn stvkn lkenz idnrk postp menge meins into table i_stpo from stpo for all entries in i_stas where stlnr eq i_stas-stlnr and stvkn eq i_stas-stlkn and lkenz eq space. sort i_stpo by stlnr stlkn. * deleting duplicate records based on BOM and Item node delete adjacent duplicates from i_stpo comparing stlnr stlkn. * looping into final internal table bdc, and comparing reading * BOM(stlnr) from i_bdc to i_stas. loop at i_bdc into wa_bdc. * calling function module to exclude preceeding zeros, so as to pass * these records for BDC creation,wherein preceeding zero with a material * and item node should not be passed call function 'CONVERSION_EXIT_MATN1_OUTPUT' exporting input = wa_bdc-matnr importing output = wa_bdc-matnr. * taking all the fields into internal table i_bdc modify i_bdc from wa_bdc. clear wa_bdc. endloop. * looping into internal table for storing material description loop at i_bdc into wa_bdc. read table i_makt into wa_makt with key matnr = wa_bdc-matnr binary search. if sy-subrc eq 0. wa_bdc-maktx = wa_makt-maktx. endif. modify i_bdc from wa_bdc. endloop. sort i_bdc by matnr werks stlnr stlan stlal.
endform.
" f_get_cstbom
*&---------------------------------------------------------------------* * Form f_get_bdc_create_bom * *&---------------------------------------------------------------------* * This process will create costing BOMs through BDC * *----------------------------------------------------------------------* form f_get_bdc_create_bom. * looping through internal table i_bdc which has the records for * executing BDC of costing BOM creation. i_bdc is having BOMs and * corresponding components are there in i_stpo. if text mode in not X * then only calling transaction code CS01 if p_test ne c_x. * initialising costing bom creation counter v_crt_counter = c_0. loop at i_bdc into wa_bdc. perform f_get_bdc_create_twice. endloop. else. * moving all records from internal table bdc to bom_created loop at i_bdc into wa_bdc. move-corresponding wa_bdc to wa_bom_created. * adding records (BOM),which can be created through BDC run.For one line * item of the internal table creating two records ( Ex- 6 (p_stlnt1)* 1(p_stllt1) & 6(p_stlnt2)- 13(p_stllt2) combination) wa_bom_created-stlan = p_stlnt1. wa_bom_created-stlal = p_stllt1. append wa_bom_created to i_bom_created. wa_bom_created-stlan = p_stlnt2. wa_bom_created-stlal = p_stllt2. append wa_bom_created to i_bom_created. endloop. endif. * looping into i_bdcerror which has all the messages stored in, and have * no description for those errors, hence calling function to store * message description loop at i_bdcerror1 into wa_bdcerror1. v_msgv1 = wa_bdcerror1-msgv1. v_msgv2 = wa_bdcerror1-msgv2. v_msgv3 = wa_bdcerror1-msgv3. v_msgv4 = wa_bdcerror1-msgv4. call function 'MESSAGE_PREPARE' exporting msg_id = wa_bdcerror1-msgid msg_no = wa_bdcerror1-msgnr msg_var1 = v_msgv1 msg_var2 = v_msgv2 msg_var3 = v_msgv3 msg_var4 = v_msgv4 importing msg_text = v_error_msgtxt exceptions function_not_completed = 1 message_not_found = 2 others = 3 . if sy-subrc ne 0.
message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif. * moving i_bdcerror record to i_error internal table move-corresponding wa_bdcerror1 to wa_error. * store message description which has got from functional module into * error internal table's work area wa_error-msgtxt = v_error_msgtxt. * finally appending record into error table if wa_error-msgtyp eq c_e. append wa_error to i_error. endif. clear wa_error. endloop. * counting number of erros created and storing into variable * v_err_counter which is used to print on report describe table i_error lines v_err_counter. endform. " f_get_bdc_create_bom *&---------------------------------------------------------------------* * Form f_get_exec * *&---------------------------------------------------------------------* * This process will filter the user selected records and will dump into* * final internal table after necessary validations * *----------------------------------------------------------------------* form f_get_exec. case sy-ucomm. when c_exec. refresh i_chkbx[]. * after user selection pushing records into final internal table. * retrieving the number of records in the internal table describe table i_mast_stko lines v_counter. sort i_mast_stko by matnr werks stlan stlal. * when user presses execute then clearing v_chkbx variable which holds * the value 'X' v_chkbx = space. * incrementing counter by 3 because the first three lines of the output * will be the report header, hence it has to be ignored v_counter = v_counter + c_3. * looping the internal table based on the number of lines displayed * on the screen do v_counter times. * reading the individual line and getting whether checkbox is ticked * or not read line sy-index field value v_chkbx. * if checkbox is ticked then moving screen values to an internal table * 2(18) - 2 is column position and 18 is the length of the field if v_chkbx = c_x. move sy-lisel+5(18) to wa_chkbx-matnr. move sy-lisel+28(4) to wa_chkbx-werks. move sy-lisel+34(1) to wa_chkbx-stlan. move sy-lisel+40(2) to wa_chkbx-stlal. * calling functional module to add preceeding zeros to material call function 'CONVERSION_EXIT_NUMCV_INPUT' exporting input = wa_chkbx-matnr importing output = v_matnr.
wa_chkbx-matnr = v_matnr. * calling functional module to add preceeding zeros to alternative call function 'CONVERSION_EXIT_NUMCV_INPUT' exporting input = wa_chkbx-stlal importing output = v_stlal. * storing the value which has got from functional module to work area * of the internal table wa_chkbx-stlal = v_stlal. * searching for BOM, since in the output BOM is not displayed,hence * through the previous internal table based on the display output fields * again reading back the BOM and storing read table i_mast_stko into wa_mast_stko with key matnr = wa_chkbx-matnr werks = wa_chkbx-werks stlan = wa_chkbx-stlan stlal = wa_chkbx-stlal. if sy-subrc eq 0. wa_chkbx-stlnr = wa_mast_stko-stlnr. else. wa_chkbx-stlnr = c_space. endif. append wa_chkbx to i_chkbx. clear wa_chkbx. endif. enddo. if internal table is blank, means user has not even selected a single record, then flashing an error message if i_chkbx[] is initial. message e082. " Atleast one record should be " selected for material plant " combination endif. indexing the table and finding for duplicate entries with the material and plant combination sort i_chkbx by matnr werks stlan stlal.
* *
* *
* if at all any duplicate entry gets deleted then clearing the internal * table and flashing error message. This process is to check whether * user has selected any duplicate selections delete adjacent duplicates from i_chkbx comparing matnr werks. if sy-subrc eq 0. refresh i_chkbx[]. message e083.
" Select only one record for " material plant combination
else. * if after user selection there are some unique entries in the internal * table then moving them into the final internal table ie i_bdc loop at i_chkbx into wa_chkbx. move-corresponding wa_chkbx to wa_bdc. append wa_bdc to i_bdc. clear wa_bdc. endloop. endif.
endcase. endform. " f_get_exec *&---------------------------------------------------------------------* * Form bdc_dynpro * *&---------------------------------------------------------------------* * Start new screen (generated automatically through BDC) *----------------------------------------------------------------------* form bdc_dynpro using program dynpro. clear i_bdcdata. i_bdcdata-program = program. i_bdcdata-dynpro = dynpro. i_bdcdata-dynbegin = c_x. append i_bdcdata. endform. " bdc_dynpro *&---------------------------------------------------------------------* * Form bdc_field * *&---------------------------------------------------------------------* * Insert field (generated automatically through BDC) *----------------------------------------------------------------------* form bdc_field using fnam fval. clear i_bdcdata. i_bdcdata-fnam = fnam. i_bdcdata-fval = fval. append i_bdcdata. endform. " bdc_field
*&---------------------------------------------------------------------* * Module STATUS_0200 OUTPUT * *&---------------------------------------------------------------------* * defining alv grids, field catalogs descriptions for the report of* * costing BOM creation * *----------------------------------------------------------------------* module status_0200 output. perform f_get_master_info. sort i_bdc by matnr. * To build the field catalog for the grid. perform f_build_grid1_fieldcat. * checking whether g_custom_container is empty if g_custom_container is initial. create object g_custom_container * g_container name is defined as BOM exporting container_name = g_container. * first grid is defined as grid1 create object grid1 exporting i_parent = g_custom_container. call method grid1->set_table_for_first_display exporting is_layout = gs_layout changing * passing final internal table from which bdc has been created it_outtab = i_bom_created[] * reference of field catalog is being passed, which will create * columns on alv grid it_fieldcatalog = i_fieldcat1[]
exceptions invalid_parameter_combination = 1 program_error =2 too_many_lines =3 others = 4. if sy-subrc ne 0. message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif. create object event_receiver_200. set handler event_receiver_200->double_click_200 for grid1. call method cl_gui_control=>set_focus exporting control = grid1. endif. * event receiver for top of page/end of list * if event_receiver_600 is initial. create object event_receiver_600. if p_chkbox eq c_x. if p_rfirst eq c_x. create object page_handler. set handler event_receiver_600->handle_top_of_list for grid1. else. set handler event_receiver_600->handle_end_of_list for grid1. endif. endif. set handler event_receiver_600->handle_end_of_report for grid1. set handler event_receiver_600->handle_top_of_page for grid1. * endif. endmodule. " status_0200 output
*&---------------------------------------------------------------------* * Form f_build_grid1_fieldcat * *&---------------------------------------------------------------------* * definig field catalog for alv grid. For tabstrip 1 & 2 field catalog* * are same * *----------------------------------------------------------------------* form f_build_grid1_fieldcat. refresh i_fieldcat1. clear i_fieldcat1. * field catalog for material i_fieldcat1-fieldname = c_matnr. i_fieldcat1-scrtext_l = text-021. " Material i_fieldcat1-ref_field = c_matnr. i_fieldcat1-col_pos = c_001. append i_fieldcat1. clear i_fieldcat1. * field catalog for material description i_fieldcat1-fieldname = c_maktx. i_fieldcat1-scrtext_l = text-032. " Description i_fieldcat1-ref_field = c_maktx. i_fieldcat1-col_pos = c_2. append i_fieldcat1. clear i_fieldcat1. * field catalog for BOM usage i_fieldcat1-fieldname = c_stlan. i_fieldcat1-scrtext_l = text-031. i_fieldcat1-ref_field = c_stlan.
" Usage
i_fieldcat1-col_pos = c_3. append i_fieldcat1. clear i_fieldcat1. * field catalog for BOM alternative i_fieldcat1-fieldname = c_stlal. i_fieldcat1-scrtext_l = text-030. " Alternative i_fieldcat1-ref_field = c_stlal. i_fieldcat1-col_pos = c_4. append i_fieldcat1. clear i_fieldcat1. endform. " f_build_grid1_fieldcat *&---------------------------------------------------------------------* * Module STATUS_0100 OUTPUT * *&---------------------------------------------------------------------* * for tabstrip control pf status and title bar are being specified * *----------------------------------------------------------------------* module status_0100 output. set pf-status '0100'. set titlebar '100'. endmodule. " status_0100 output *&---------------------------------------------------------------------* * Module USER_COMMAND_0100 INPUT * *&---------------------------------------------------------------------* * checking ok code active tab and based on that tabstrip is being* * displayed * *----------------------------------------------------------------------* module user_command_0100 input. case ok_code. when c_fc1 or c_fc2 or c_fc3. bom-activetab = ok_code. endcase. endmodule. " user_command_0100 input *&---------------------------------------------------------------------* * Module STATUS_0300 OUTPUT * *&---------------------------------------------------------------------* * defining alv grids, field catalogs descriptions for the report of* * costing BOM creation * *----------------------------------------------------------------------* module status_0300 output. perform f_get_master_info. sort i_bdc by matnr. * To build the field catalog for the grid. perform f_build_grid1_fieldcat. * checking for custom container whether empty if g_custom_container1 is initial. create object g_custom_container1 * g_container name is defined as BOM1 exporting container_name = g_container1. create object grid2 exporting i_parent = g_custom_container1. call method grid2->set_table_for_first_display exporting is_layout = gs_layout changing * passing final internal table from which bdc has been created
it_outtab = i_mast[] * reference of field catalog is being passed, which will create * columns on alv grid it_fieldcatalog = i_fieldcat1[] exceptions invalid_parameter_combination = 1 program_error =2 too_many_lines =3 others = 4. if sy-subrc ne 0. message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif. create object event_receiver_300. set handler event_receiver_300->double_click_300 for grid2. call method cl_gui_control=>set_focus exporting control = grid2. endif. if event_receiver_500 is initial. create object event_receiver_500. if p_chkbox eq c_x. if p_rfirst eq c_x. set handler event_receiver_500->handle_top_of_list for grid2. else. set handler event_receiver_500->handle_end_of_list for grid2. endif. endif. set handler event_receiver_500->handle_end_of_report for grid2. set handler event_receiver_500->handle_top_of_page for grid2. endif. endmodule. " status_0300 output *&---------------------------------------------------------------------* * Module STATUS_0400 OUTPUT * *&---------------------------------------------------------------------* * defining alv grids, field catalogs descriptions for the report of* * costing BOM creation * *----------------------------------------------------------------------* module status_0400 output. * To build the field catalog for the grid. perform f_build_grid2_fieldcat. * check whether custom container is empty if g_custom_container2 is initial. create object g_custom_container2 * g_container name is defined as BOM1 exporting container_name = g_container2. create object grid3 exporting i_parent = g_custom_container2. call method grid3->set_table_for_first_display exporting is_layout = gs_layout changing * passing final internal table from which bdc has been created it_outtab = i_error[] * reference of field catalog is being passed, which will create * columns on alv grid it_fieldcatalog = i_fieldcat2[] exceptions invalid_parameter_combination = 1
=2 =3 = 4.
if sy-subrc ne 0. message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif. create object event_receiver_400. set handler event_receiver_400->double_click_400 for grid3. call method cl_gui_control=>set_focus exporting control = grid3. endif. if event_receiver_700 is initial. create object event_receiver_700. if p_chkbox eq c_x. if p_rfirst eq c_x. set handler event_receiver_700->handle_top_of_list for grid3. else. set handler event_receiver_700->handle_end_of_list for grid3. endif. endif. set handler event_receiver_700->handle_end_of_report for grid3. set handler event_receiver_700->handle_top_of_page for grid3. endif. endmodule. " status_0400 output *&---------------------------------------------------------------------* * Form f_build_grid2_fieldcat *&---------------------------------------------------------------------* * definig field catalog for alv grid for tabstrip 3 *----------------------------------------------------------------------* form f_build_grid2_fieldcat. refresh i_fieldcat2. clear i_fieldcat2. * field catalog for material i_fieldcat2-fieldname = c_matnr. i_fieldcat2-scrtext_l = text-021. " Material i_fieldcat2-ref_field = c_matnr. i_fieldcat2-col_pos = c_001. append i_fieldcat2. clear i_fieldcat2. * field catalog for BOM usage i_fieldcat2-fieldname = c_stlan. i_fieldcat2-scrtext_l = text-031. i_fieldcat2-ref_field = c_stlan. i_fieldcat2-col_pos = c_2. append i_fieldcat2. clear i_fieldcat2.
" Usage
* field catalog for BOM alternative i_fieldcat2-fieldname = c_stlal. i_fieldcat2-scrtext_l = text-030. " Alternative i_fieldcat2-ref_field = c_stlal. i_fieldcat2-col_pos = c_3. append i_fieldcat2. clear i_fieldcat2. * field catalog for error message type (ie either E/W/I etc)
i_fieldcat2-fieldname = c_msgtyp. i_fieldcat2-scrtext_l = c_errtyp. " Message type i_fieldcat2-ref_field = c_msgtyp. i_fieldcat2-col_pos = c_4. append i_fieldcat2. clear i_fieldcat2. * field catalog for error ID ie message class i_fieldcat2-fieldname = c_msgid. i_fieldcat2-scrtext_l = c_errid. " Message ID i_fieldcat2-ref_field = c_msgid. i_fieldcat2-col_pos = c_5. append i_fieldcat2. clear i_fieldcat2. * field catalog for error message number i_fieldcat2-fieldname = c_msgnr. i_fieldcat2-scrtext_l = c_errno. " Message number i_fieldcat2-ref_field = c_msgnr. i_fieldcat2-col_pos = c_6. append i_fieldcat2. clear i_fieldcat2. * field catalog for error message text i_fieldcat2-fieldname = c_msgtxt. i_fieldcat2-scrtext_l = text-029. " Message text i_fieldcat2-ref_field = c_msgtxt. i_fieldcat2-col_pos = c_7. append i_fieldcat2. clear i_fieldcat2. endform. " f_build_grid2_fieldcat *&---------------------------------------------------------------------* * Form f_end_of_report * *&---------------------------------------------------------------------* * Footer of the Report * *----------------------------------------------------------------------* form f_end_of_report. uline. skip c_2. write: /2 text-f02. " For Internal use only skip c_2. write: /2 text-f01. " End of report.
endform. " f_end_of_report *&---------------------------------------------------------------------* * Form f_append_help * *&---------------------------------------------------------------------* * This process will add text into internal table i_help, through text* * elements.When user will press F1 on deletion indicator,this text will* * be displayed * *----------------------------------------------------------------------* form f_append_help. * clearing work area clear wa_help. * cleaning internal table refresh i_help. * text storing in internal table's field tdline
wa_help-tdline = text-015. " Delete Existing Costing BOM " with usage 6 and alternative * text will be saved on column number 1,c_01 carries value '1', which * refers to the column where text is being written wa_help-tdformat = c_01. * finally appending record into the internal table append wa_help to i_help. * clearing work area clear wa_help. * the same step is followed for c_02 & c_03 (ie for column 2 & 3) wa_help-tdline = text-016. " (as per selection screen) " regardless of the material " range wa_help-tdformat = c_02. append wa_help to i_help. clear wa_help. wa_help-tdline = text-018. " given but, under the given " plant and create new costing " BOM wa_help-tdformat = c_03. append wa_help to i_help. clear wa_help. wa_help-tdline = text-033. " for the given range of " materials and plant in the " selection screen wa_help-tdformat = c_04. append wa_help to i_help. clear wa_help. * defining title for the help text,which will display,about the help * topic v_title = text-017. " Delete Existing BOM endform. " f_append_help *&---------------------------------------------------------------------* * Form f_help_testrun * *&---------------------------------------------------------------------* * To append the text in the table i_help for Test run box* * documentation for this form is same as f_append_help * *----------------------------------------------------------------------* form f_help_testrun. clear wa_help. refresh i_help. wa_help-tdline = text-046. " If you set this indicator, then " the program will be wa_help-tdformat = c_01. append wa_help to i_help. clear wa_help. wa_help-tdline = text-047. " started in test mode.In this " mode,the system wa_help-tdformat = c_02. append wa_help to i_help.
clear wa_help. wa_help-tdline = text-048. " does not make any changes to " the database wa_help-tdformat = c_03. append wa_help to i_help. clear wa_help. wa_help-tdline = text-049. " or to the archive but all " checks are carried out wa_help-tdformat = c_04. append wa_help to i_help. clear wa_help. v_title = text-050. endform. " Test Run " f_help_testrun
*&---------------------------------------------------------------------* * Form f_help_output * *&---------------------------------------------------------------------* * To append the text in the table i_help for output checkbox* * documentation for this form is same as f_append_help * *----------------------------------------------------------------------* form f_help_output. clear wa_help. refresh i_help. wa_help-tdline = text-034. " If the 'Output with user input' " checkbox is checked, the wa_help-tdformat = c_01. append wa_help to i_help. clear wa_help. wa_help-tdline = text-035. " selection screen parameters " entered by the user will be wa_help-tdformat = c_02. append wa_help to i_help. clear wa_help. wa_help-tdline = text-036. " displayed in the report " depending on the Radio buttons wa_help-tdformat = c_03. append wa_help to i_help. clear wa_help. wa_help-tdline = text-037. wa_help-tdformat = c_04. append wa_help to i_help. clear wa_help. v_title = text-038. endform. " selected
*&---------------------------------------------------------------------* * Form f_help_frdb * *&---------------------------------------------------------------------* * To append records to i_help table for on first page radio button* * documentation for this form is same as f_append_help * *----------------------------------------------------------------------*
form f_help_frdb. clear wa_help. refresh i_help. wa_help-tdline = text-039. " If the Radio button 'On first " first page'is selected then the wa_help-tdformat = c_01. append wa_help to i_help. clear wa_help. wa_help-tdline = text-040. " selection screen parameters " will be displayed on the wa_help-tdformat = c_02. append wa_help to i_help. clear wa_help. wa_help-tdline = text-041. wa_help-tdformat = c_03. append wa_help to i_help. clear wa_help. v_title = text-042. endform. " first page of the report
*&---------------------------------------------------------------------* * Form f_help_lrdb * *&---------------------------------------------------------------------* * For appending records in internal table i_help for on last page* * button clicked. documentation for this form is same as f_append_help* *----------------------------------------------------------------------* form f_help_lrdb. clear wa_help. refresh i_help. wa_help-tdline = text-043. " If the Radio button 'On last " last page' is selected then " the wa_help-tdformat = c_01. append wa_help to i_help. clear wa_help. wa_help-tdline = text-040. " selection screen parameters " will be displayed on the wa_help-tdformat = c_02. append wa_help to i_help. clear wa_help. wa_help-tdline = text-044. wa_help-tdformat = c_03. append wa_help to i_help. clear wa_help. v_title = text-045. endform. " last page of the report
*&---------------------------------------------------------------------* * To display the documentation for the button clicked *----------------------------------------------------------------------* * --> p_v_title * *----------------------------------------------------------------------* form f_document using p_v_title. call function 'COPO_POPUP_TO_DISPLAY_TEXTLIST' exporting task = c_display titel = p_v_title tables text_table = i_help. endform. " f_document *&---------------------------------------------------------------------* * Module exit input * *&---------------------------------------------------------------------* * This process will sent back the control to previous screen *----------------------------------------------------------------------* module exit input. case ok_code. when c_exit. clear ok_code. leave to screen 0. when c_back. clear ok_code. leave to screen 0. when c_canc. clear ok_code. leave to screen 0. when others. endcase. endmodule. " exit input *&---------------------------------------------------------------------* * Form f_free_memory * *&---------------------------------------------------------------------* * clearing all internal tables * *----------------------------------------------------------------------* form f_free_memory. free i_makt. " material details free i_mast_stko. " BOM related material free i_stko. " BOM status free i_error. " error information free i_bdc. " base data for BOM creation free i_chkbx. " to keep user selected info. free i_mast. " records for deletion of BOMs free i_stas. " item nodes selection free i_stpo. " components selection free i_bom_created. " final internal table free i_bdcdata. " bdc internal table free i_bdcerror. " error table for BDC free i_bdcerror1. " error table for BDC free i_help. " help table free i_return. " bapi return value endform. " f_free_memory
*&---------------------------------------------------------------------* * Form f_get_master_info * *&---------------------------------------------------------------------* * This process will collect data from all the master table which will* * be used used for description printing in report *
*----------------------------------------------------------------------* form f_get_master_info. * Get description for Company code select butxt from t001 into t001-butxt up to 1 rows where bukrs eq p_bukrs. endselect. if sy-subrc eq 0. v_butxt = t001-butxt. endif. * Get description for Controlling Area. select bezei from tka01 into tka01-bezei up to 1 rows where kokrs eq p_kokrs. endselect. if sy-subrc eq 0. v_bezei = tka01-bezei. endif. * Get description for Plant. select name1 from t001w into t001w-name1 up to 1 rows where werks eq p_werks. endselect. if sy-subrc eq 0. v_name1 = t001w-name1. endif. endform. " f_get_master_info *&---------------------------------------------------------------------* * Form f_get_bdc_create_twice * *&---------------------------------------------------------------------* * This process will create two records running through BDC, based on* * single record exist, in the internal table. It will be looping twice* *----------------------------------------------------------------------* form f_get_bdc_create_twice. v_cnt2 = c_0. do c_2 times. v_cnt2 = v_cnt2 + c_001. clear v_cnt. clear v_cnt1. perform bdc_dynpro using 'SAPLCSDI' '0100'. perform bdc_field perform bdc_field perform bdc_field using 'BDC_CURSOR' 'RC29N-STLAL'. using 'BDC_OKCODE' '/00'. using 'RC29N-MATNR' wa_bdc-matnr.
perform bdc_field
* while creation, user parameter of "create costing BOMs" for BOM usage * has been taken if v_cnt2 eq c_001. wa_bdc-stlan = p_stlnt1. else. wa_bdc-stlan = p_stlnt2. endif. perform bdc_field using 'RC29N-STLAN' wa_bdc-stlan. * while creation, user parameter of "create additional costing BOMs for * volume transfer" BOM usage has been taken if v_cnt2 eq c_001. wa_bdc-stlal = p_stllt1. else. wa_bdc-stlal = p_stllt2. endif. perform bdc_field using 'RC29N-STLAL' wa_bdc-stlal. * valid from date is of date field, but to run BDC it should be of a * character type hence concatenating into a variable v_sy_date and * passing to BDC concatenate p_budat1+6(2) '.' p_budat1+4(2) '.' p_budat1(4) into v_sy_date. perform bdc_field using 'RC29N-DATUV' v_sy_date. using 'SAPLCSDI' '0110'.
perform bdc_dynpro perform bdc_field perform bdc_field '1'. perform bdc_field '1'. perform bdc_field
using 'BDC_OKCODE' '/00'. using 'RC29K-BMENG' using 'RC29K-STLST' using 'BDC_CURSOR' 'RC29K-EXSTL'. using 'SAPLCSDI' '0111'.
perform bdc_field * * * * *
i_stpo internal table has components corresponds to BOM, hence looping through this, components will be pushed. v_cnt is counter for sl. no. v_cnt1 is counter to enter further screen of those components. if line number is more than seven then page up will be triggerd for new entry generation. v_bdcfld is used to have values and sl.no.ref. loop at i_stpo into wa_stpo where stlnr eq wa_bdc-stlnr. v_cnt1 = v_cnt1 + c_001. v_cnt = v_cnt + c_001. concatenate 'RC29P-AUSKZ(' v_cnt ')' into v_bdcfld. perform bdc_field using v_bdcfld 'X'. call function 'CONVERSION_EXIT_MATN1_OUTPUT' exporting input = wa_stpo-idnrk importing output = wa_stpo-idnrk. concatenate 'RC29P-IDNRK(' v_cnt ')' into v_bdcfld. perform bdc_field using v_bdcfld wa_stpo-idnrk. move wa_stpo-menge to v_menge. concatenate 'RC29P-MENGE(' v_cnt ')' into v_bdcfld. perform bdc_field using v_bdcfld v_menge. concatenate 'RC29P-MEINS(' v_cnt ')' into v_bdcfld. perform bdc_field using v_bdcfld wa_stpo-meins. concatenate 'RC29P-POSTP(' v_cnt ')' into v_bdcfld. perform bdc_field using v_bdcfld wa_stpo-postp. if v_cnt gt c_7. clear v_cnt. perform bdc_field using 'BDC_OKCODE' 'P+'. endif. endloop. do v_cnt1 times. perform bdc_dynpro perform bdc_field perform bdc_field using 'SAPLCSDI' '0130'.
* calling transaction code for deletion in background (N) and pushing * all messages into i_bdcerror table call transaction 'CS01' using i_bdcdata mode 'N' update 'S' messages into i_bdcerror. * this part is described in perform f_get_bdc_delete_bom loop at i_bdcerror. i_bdcerror-matnr = wa_bdc-matnr. i_bdcerror-stlan = wa_bdc-stlan. i_bdcerror-stlal = wa_bdc-stlal. modify i_bdcerror index sy-tabix. endloop. * this part is described in perform f_get_bdc_delete_bom append lines of i_bdcerror to i_bdcerror1. read table i_bdcerror with key msgtyp = c_s msgid = c_29 msgnr = c_030. * if bdc is successful then pass 'Y' in mark field,so as to indicate * that the bdc for creation of record is successful if sy-subrc eq 0. * increasing creation counter,which needs to be printed on report as to * how many reocrds were created v_crt_counter = v_crt_counter + c_001. * moving all records from internal table bdc to bom_created move-corresponding wa_bdc to wa_bom_created. * moving marked as 'Y' and transferring to internal table bom_created wa_bom_created-mark = c_y. * adding records which have successful bom creation, this is the final * table/records for printing output append wa_bom_created to i_bom_created. endif. refresh i_bdcdata. clear i_bdcdata. refresh i_bdcerror. clear i_bdcerror. clear v_cnt. clear v_cnt1. if v_cnt2 eq c_2. clear wa_bdc. clear wa_bom_created. endif. enddo. * as per the process, based on one record of internal table i_bdc, two * records have to be created one with "creating costing BOMs" BOM usage
* * * * *
and alterative (say 6-1) combination and the other with "create additional costing BOMs for volume transfer" BOM usage and alternative combination (say 6-13), hence in the same loop executing same BDC twice. Description is not mentioned in the second step, since it is same as step no. 1 " f_get_bdc_create_twice
endform.