Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
RoySayak
Active Participant

1.1 Key word

 

This document refers to the technical aspect of Upload supply pattern table in SAP from excel spreadsheet (*.CSV format) in SAP. The customization made based on the business requirement and business process. This document would give an overview on the technique to create an Automatic program which will populate the custom table for Delivering plant.

 

1.2 Introduction

 

The purpose of this development is to develop an automatic program which will populate the custom Supply pattern table ZCUST_TAB in SAP. This table is used to derive the Delivering Plant based on combination of Country, Material pricing group (IPC) and Material (optional). The table will subsequently feed the CMIR and Sales Orders with Delivering Plant.


Considering the number of records to be uploaded in the custom Supply pattern table ZCUST_TAB for possible combinations of Material pricing group (IPC), Country and Materials, the need is felt by the project to develop a program which will automatically upload the records in SAP from an excel spreadsheet (*.CSV). The spreadsheet (*.CSV) will be populated with the three columns for Material pricing group (IPC), Country and Material.


The spreadsheet (*.CSV) will be given to the program as an input which will subsequently be loaded into SAP upon executing the program.

 

1.3 Design

 

A part of this requirement Delivering Plant will be required in the Presales transactions like Reverse Calculation, Simulation and Price Offer for determination of Internal Logistics Cost (cost of transportation from Manufacturing Plant to Delivering Plant) and Freight Cost and Freight Price (from Delivering Plant to end customer's site).

The determination of Delivering Plant will be based on Country, Material pricing group (IPC) and Material. The standard SAP method of determining the delivering Plant will not apply since IPC is not considered. Hence it is required to create a custom table for maintaining the Delivering Plant based on Country, Material pricing group (IPC) and Material. 

In addition to the Presales transactions, delivering plant will also be required in the CMIR and Sales Order. Hence the material field has been added in the custom table to derive the appropriate plant in the CMIR and Sales Order.

The functionality of deriving the delivering plant will work as follows:

 

1. The custom table ZCUST_TAB will be created with the following fields: Country (LAND1), IPC (KONDM), Material (MATNR), and Delivering Plant (WERKS). These are standard SAP fields and hence their attributes should be same as corresponding fields in standard SAP. F1 and F4 helps should be provided to these fields exactly as standard SAP. Validations should be setup from the values of these fields as per standard SAP. For example, system should check if the material number entered by the user in the table, exist in the delivering plant entered in the same row in the table.

 

2. During Reverse Calculation (Sales Doc type ZRV0), the user exit USEREXIT_SOURCE_DETERMINATION in the program MV45AFZB should be used. This user exit will read the custom table ZCUST_TAB with the values for Country of Ship to (LAND1), IPC (KONDM) and Material (MATNR) to determine the Delivering Plant in ZRV0. In case no entry is found for the combination of Country (LAND1), IPC (KONDM) and Material (MATNR), the user exit should search for an entry based on the Country (LAND1) and IPC (KONDM). The value retrieved from the table should be copied over to the field VBAP-WERKS. The user exit will be fired each time the value of any of these three fields (Country of Ship to (LAND1), IPC (KONDM) and Material (MATNR)) are manually changed in the transaction.

 

3. The values for the condition types ZFT0 (Freight), ZCF0 (Freight Cost) and ZCF1 (Internal Logistics Cost) will be retrieved from the condition records using the Delivering Plant. This should be possible since the field for Delivering Plant exist in the pricing communication structures for Sales Order and Billing.

 

4. The same procedure as explained above will apply for the deriving the value of Delivering Plant in Simulation (Sales Doc Type ZSM0). When a Simulation (Sales Document Type ZSM0) is created by referencing a pre-existing Simulation, system should copy the Delivering Plant from the existing Simulation. Similarly when a Price Offer (Sales Doc Type ZPR0) is created by referencing a pre-existing Simulation or another Price Offer, system should copy the Delivering Plant from the existing Simulation. The copy routine (151 at item level for VBAP) from Simulation to Simulation, Simulation to Price Offer and Price Offer to Price Offer should be enhanced to perform this functionality. In case a Simulation or Price Offer is created without referencing any pre-existing document, system should derive the value from the custom table using the user-exit. In these presales documents, system should use the country of the Ship to Party, IPC and Material to derive the Delivering Plant from the custom table.

 

5. In the CMIR (Sales Doc Type ZINF), the user-exit should derive the delivering plant from the custom table, since no preceding documents exist. System should use the country of the Sold To, IPC and Material for determining the delivering Plant from the custom table.

 

6. In the Sales Order, system should NOT copy the Delivering Plant from the CMIR. The user-exit should retrieve the Delivering plant from the custom table based on the Country of the Ship to party. The existing copy routine (900 at item level for VBAP) from CMIR to Sales Order should be modified so that system does not copy the delivering plant from CMIR.


This automatic program which will populate the custom Supply pattern table ZCUST_TAB in SAP.

If in future, the need is felt to include additional columns in the custom Supply pattern table ZCUST_TAB, the program should be able to upload the data for the additional columns, provided the excel spreadsheet (*.CSV) is populated with the data for the additional columns.

 

The spreadsheet (*.CSV) will be given to the program as an input which will subsequently be loaded into SAP upon executing the program.
The following points need to be considered while designing the program:
1) This program should be executed using a custom transaction code.
2) The program while loading the data will perform the following validations:

    - In case Material number is entered in the spreadsheet (*.CSV) for a particular row,     the program while uploading the row into SAP should validate if the Material belongs     to the IPC and exists in the Delivering Plant, which are entered for that row.

3) An error log is required to be displayed after each run of the program which will display the records which have failed in the validation.

4) If in future, the need is felt to include additional columns in the custom Supply pattern table ZCUST_TAB, the program should be able to upload the data for the additional columns, provided the excel spreadsheet (*.CSV) is populated with the data for the additional columns.

5) The program should offer ‘Test Run' facility to validate the data.

 

1.4 Development

 

Create custom table for delivery plant ZCUST_TAB with following fields Country (LAND1), Material Pricing Group (KONDM), Material (MATNR) and Plant (WERKS).

 

 

Entry help / check and condition screen

 

 

Now create the automatic program for uploading data into the custom table ZCUST_TAB. Selection screen of the automatic program as below: 

Put the path of the input file. (Path of the spreadsheet in *.CSV format)

 

 

Upload the data into custom table ZCUST_TAB; uncheck the test mode check box in selection screen.

Data uploaded with success message and with error log.

 

 

Check the database table ZCUST_TAB in SE16 transaction whether the data is uploaded or not according to the Success record showing the error log.

Yes! Only one entry is updated into the table.

 

 

Now add a new field TEXT into the table ZCUST_TAB and adjust the table using database utility.

 

 

Activate and adjust the table using Database Utility.

 

 

Update the excel spreadsheet (*.CSV) with respective data and Execute the program again. Its get populated automatically for updated field in the ZCUST_TAB. Check the table entry and Yes! its working..

 

 

 1.5 Complete Code Snippet

 

************************************************************************
* PROGRAM ID : ZAUTO_UPLD_PRG *
* PROGRAM TITLE : Automatic program to upload Custom table *
* AUTHOR : Sayak Roy *
* SUPPLIER : Infosys *
* DATE : 16/12/2008 *
* DESCRIPTION : Automatic program which will populate the *
* table ZCUST_TAB *
************************************************************************

REPORT zauto_upld_prg MESSAGE-ID z_msg.

*--- Data Declaration
INCLUDE zauto_upld_prg_top.

*--- All Form Routines
INCLUDE zauto_upld_prg_f01.

************************************************************************
* I-N-I-T-I-A-L-I-Z-A-T-I-O-N *
************************************************************************
INITIALIZATION.

*--- Initialize the global data
PERFORM clear_global_data.

 

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

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.


************************************************************************
* Subroutine to select the file name *
************************************************************************
PERFORM find_path.

AT SELECTION-SCREEN.
************************************************************************
* Subroutine to check the existence of uploaded file *
************************************************************************
PERFORM check_file_existence.

 

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

************************************************************************
* Finding database table properties *
************************************************************************
PERFORM find_fields.

************************************************************************
* Upload data from Excel file to internal table *
************************************************************************
PERFORM load_data.

************************************************************************
* Populate fields with values *
************************************************************************
PERFORM fill_table.

 

************************************************************************
* E-N-D O-F S-E-L-E-C-T-I-O-N *
************************************************************************

END-OF-SELECTION.


IF p_tst_md EQ space.
PERFORM update_data.
PERFORM show_message.
ELSE.
PERFORM show_message.
ENDIF.

 

*--- Type Declarations
TYPE-POOLS: abap.

TYPES: BEGIN OF ty_t005,
land1 TYPE land1, "Country Key
END OF ty_t005,

BEGIN OF ty_t178,
kondm TYPE kondm, "Material Pricing Group
END OF ty_t178,

BEGIN OF ty_mara,
matnr TYPE matnr, "Material Number
END OF ty_mara,

BEGIN OF ty_t001w,
werks TYPE werks_d, "Plant
END OF ty_t001w,

BEGIN OF ty_marc,
matnr TYPE matnr, "Material Number
werks TYPE werks_d, "Plant
END OF ty_marc,

BEGIN OF ty_mvke,
matnr TYPE matnr, "Material Number
kondm TYPE kondm, "Material Pricing Group
END OF ty_mvke.

TYPES: BEGIN OF ty_mestab,
country TYPE land1, "Country Key
ipccode TYPE kondm, "Material Pricing Group
material TYPE matnr, "Material Number
plant TYPE werks_d, "Plant
text TYPE char256, "Message text
END OF ty_mestab.

TYPES: BEGIN OF ty_file,
record(256) TYPE c,
END OF ty_file.


*--- Data Declarations
*--- Work Area Declarations
DATA: wa_t005 TYPE ty_t005,
wa_t178 TYPE ty_t178,
wa_mara TYPE ty_mara,
wa_t001w TYPE ty_t001w,
wa_marc TYPE ty_marc,
wa_mvke TYPE ty_mvke,
wa_mestab TYPE ty_mestab.

*--- Internal Table Declarations
DATA: it_t005 TYPE TABLE OF ty_t005,
it_t178 TYPE TABLE OF ty_t178,
it_mara TYPE TABLE OF ty_mara,
it_t001w TYPE TABLE OF ty_t001w,
it_marc TYPE TABLE OF ty_marc,
it_mvke TYPE TABLE OF ty_mvke,
it_file TYPE STANDARD TABLE OF ty_file,
it_mestab TYPE TABLE OF ty_mestab.


*--- Variable Declaration
DATA: it_final TYPE STANDARD TABLE OF zcust_tab, "Custom table for Delivering Plant
wa_final TYPE zcust_tab.

DATA: it_exload TYPE STANDARD TABLE OF alsmex_tabline,
wa_exload TYPE alsmex_tabline.


*--- Field-Symbols Declarations
FIELD-SYMBOLS: TYPE STANDARD TABLE,
TYPE ANY,
TYPE ANY.


*--- Constant Declarations
CONSTANTS: c_error TYPE char1 VALUE 'E',
c_x TYPE char1 VALUE 'X',
c_ext TYPE char4 VALUE '.csv', ".csv file extension
c_table TYPE string VALUE 'ZCUST_TAB'. "Custom table for Delivering Plant

************************************************************************
*--- Global data definitions for ALV ---*
************************************************************************
DATA: gr_table TYPE REF TO cl_salv_table,
gr_display TYPE REF TO cl_salv_display_settings,
gr_functions TYPE REF TO cl_salv_functions,
gr_columns TYPE REF TO cl_salv_columns_table,
gr_column TYPE REF TO cl_salv_column_table.

 

************************************************************************
*--- Selection Screen Blocks ---*
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
*-------[PARAMETERS]---------*
PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
*-------[PARAMETERS]---------*
PARAMETERS: p_tst_md TYPE char1 AS CHECKBOX DEFAULT c_x.
SELECTION-SCREEN END OF BLOCK b2.

 

 

*&---------------------------------------------------------------------*
*& Form find_path
*&---------------------------------------------------------------------*
* Find path of the Excel file
*----------------------------------------------------------------------*
FORM find_path.

DATA: l_it_filetab TYPE filetable, " File Name
l_wa_filetab TYPE file_table, " File Name
l_v_title TYPE string, " Title
l_v_rc TYPE i.

REFRESH l_it_filetab.
CLEAR : l_v_rc,
l_v_title,
l_wa_filetab.

l_v_title = 'Select File'(010).

*--- Get path for the excel file.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = l_v_title
default_extension = 'csv'
default_filename = '*.csv'
file_filter = '*.csv'
* with_encoding =
initial_directory = 'C:\'
* multiselection =
CHANGING
file_table = l_it_filetab
rc = l_v_rc
* user_action =
* file_encoding =
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.

IF sy-subrc IS INITIAL.
*--- Get the filename into parameter on selection screen.
READ TABLE l_it_filetab INTO l_wa_filetab INDEX 1.
IF sy-subrc IS INITIAL.
p_file = l_wa_filetab-filename. "File
ENDIF.
ENDIF.

ENDFORM. " find_path


*&---------------------------------------------------------------------*
*& Form check_file_existence
*&---------------------------------------------------------------------*
* Check existence of the input file
*----------------------------------------------------------------------*
FORM check_file_existence.

DATA: l_f_filechk TYPE char1, "File Check
l_v_file TYPE draw-filep. "File Name

CLEAR: l_v_file.
l_v_file = p_file.

IF p_file IS NOT INITIAL.
CALL FUNCTION 'CV120_DOC_FILE_EXISTENCE_CHECK'
EXPORTING
pf_file = l_v_file
IMPORTING
pfx_exist = l_f_filechk
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc IS NOT INITIAL
OR l_f_filechk NE c_x.
MESSAGE e169. "Invalid file name
CLEAR: l_f_filechk.
ELSEIF l_v_file NS c_ext. ".csv file extension
MESSAGE e170. "File Name should have .csv extension
ENDIF.
ENDIF.

ENDFORM. " check_file_existence


*&---------------------------------------------------------------------*
*& Form load_data
*&---------------------------------------------------------------------*
* Upload data from Excel to internal table
*----------------------------------------------------------------------*
FORM load_data.

DATA : l_v_filename TYPE string,
l_v_index TYPE sy-tabix,
l_v_temp TYPE sy-tabix,
l_it_table TYPE STANDARD TABLE OF ty_file,
l_wa_table TYPE ty_file,
wa_file TYPE ty_file.

* Upload data into internal table
l_v_filename = p_file.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_v_filename
filetype = 'ASC'
TABLES
data_tab = it_file
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
DELETE it_file INDEX 1.
LOOP AT it_file INTO wa_file .
l_v_index = sy-tabix.
REPLACE ALL OCCURRENCES OF ';' IN wa_file-record WITH ','.
CONCATENATE sy-mandt wa_file-record INTO wa_file-record SEPARATED BY ','.
TRANSLATE wa_file-record TO UPPER CASE .
SPLIT wa_file-record AT ',' INTO TABLE l_it_table.
LOOP AT l_it_table INTO l_wa_table.
l_v_temp = sy-tabix.
ASSIGN COMPONENT l_v_temp
OF STRUCTURE TO .
IF sy-subrc NE 0.
EXIT.
ELSE.
= l_wa_table-record.
ENDIF.
ENDLOOP.
APPEND TO .
CLEAR : l_v_temp,
l_it_table,
l_wa_table.
MODIFY it_file FROM wa_file INDEX l_v_index.
ENDLOOP.
ENDIF.

ENDFORM. " load_data


*&---------------------------------------------------------------------*
*& Form find_fields
*&---------------------------------------------------------------------*
* Create dynamic internal table and dynamic work area
*----------------------------------------------------------------------*
FORM find_fields.

DATA: l_dy_table TYPE REF TO data,
l_dy_line TYPE REF TO data,
l_xfc TYPE lvc_s_fcat,
l_ifc TYPE lvc_t_fcat.

DATA: l_idetails TYPE abap_compdescr_tab,
l_xdetails TYPE abap_compdescr.

DATA: ref_table_des TYPE REF TO cl_abap_structdescr.

*--- Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( c_table ).
l_idetails[] = ref_table_des->components[].

LOOP AT l_idetails INTO l_xdetails.
CLEAR l_xfc.
l_xfc-ref_table = c_table.
l_xfc-ref_field = l_xdetails-name.
l_xfc-fieldname = l_xdetails-name .
l_xfc-datatype = l_xdetails-type_kind.
l_xfc-inttype = l_xdetails-type_kind.
l_xfc-intlen = l_xdetails-length.
l_xfc-decimals = l_xdetails-decimals.
APPEND l_xfc TO l_ifc.
ENDLOOP.

*--- Create dynamic internal table and assign to FS.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = l_ifc
IMPORTING
ep_table = l_dy_table.

ASSIGN l_dy_table->* TO .

*--- Create dynamic work area and assign to FS.
CREATE DATA l_dy_line LIKE LINE OF .
ASSIGN l_dy_line->* TO .

ENDFORM. " find_fields


*&---------------------------------------------------------------------*
*& Form fill_table
*&---------------------------------------------------------------------*
* Fill final internal table dynamically and check field validation
*----------------------------------------------------------------------*
FORM fill_table.

DATA: l_wf_row TYPE i VALUE 1,
l_wf_col TYPE i VALUE 1,
l_wa_final TYPE zcust_tab,
l_v_length TYPE i,
l_v_temp TYPE i.

DATA: l_v_kondm TYPE kondm,
l_v_index TYPE sy-tabix.

DATA: l_v_flg TYPE char1,
l_v_val TYPE i.

FIELD-SYMBOLS: TYPE alsmex_tabline.

*--- Fetch data from the internal table containing the records from the
*--- excel sheet with corresponding row and column information and fill
*--- the dynamic internal table with that data.

*--- Fetch the data for validation of the records in the internal table
*--- from the database.

IF IS NOT INITIAL.
it_final = .
IF it_final IS NOT INITIAL.
SORT it_final BY land1 kondm matnr.
DELETE ADJACENT DUPLICATES FROM it_final.
*--- Fetch Country Key.
SELECT land1
FROM t005
INTO TABLE it_t005
FOR ALL ENTRIES IN it_final
WHERE land1 = it_final-land1.
*--- Fetch Material Pricing Group.
SELECT kondm
FROM t178
INTO TABLE it_t178
FOR ALL ENTRIES IN it_final
WHERE kondm = it_final-kondm.
*--- Fetch Material Number.
SELECT matnr
FROM mara
INTO TABLE it_mara
FOR ALL ENTRIES IN it_final
WHERE matnr = it_final-matnr.
*--- Fetch Plant.
SELECT werks
FROM t001w
INTO TABLE it_t001w
FOR ALL ENTRIES IN it_final
WHERE werks = it_final-werks.
*--- Fetch Material Number and Plant combination to validate the
*--- records from the dynamic internal table.
SELECT matnr
werks
FROM marc
INTO TABLE it_marc
FOR ALL ENTRIES IN it_final
WHERE matnr = it_final-matnr
AND werks = it_final-werks.
IF sy-subrc IS INITIAL.
SORT it_marc BY matnr werks.
*--- Fetch Material Number and Material Pricing Group to validate
*--- the records of the internal table.
SELECT matnr
kondm
FROM mvke
INTO TABLE it_mvke
FOR ALL ENTRIES IN it_marc
WHERE matnr = it_marc-matnr.
ENDIF.
ENDIF.
ENDIF.

* Sort master data tables
SORT it_t005 BY land1.
SORT it_t178 BY kondm.
SORT it_t001w BY werks.
SORT it_mara BY matnr.

*--- Validate the record from the dynamic internal table by comparing
*--- the corresponding entries from the master table of the respective
*--- fields, if the data is not found delete the corresponding invalid
*--- entry before updating in the database and maintain an error log
*--- for deleted entries.

IF it_final[] IS NOT INITIAL.
LOOP AT it_final INTO wa_final.
l_v_index = sy-tabix.
CLEAR: wa_t005.
READ TABLE it_t005
INTO wa_t005
WITH KEY land1 = wa_final-land1.
IF sy-subrc IS NOT INITIAL
AND wa_t005 IS INITIAL.
DELETE it_final INDEX l_v_index.
l_v_flg = c_x.
wa_mestab-country = wa_final-land1.
wa_mestab-ipccode = wa_final-kondm.
wa_mestab-material = wa_final-matnr.
wa_mestab-plant = wa_final-werks.
CONCATENATE text-005 wa_mestab-text "Not a valid Country
INTO wa_mestab-text
SEPARATED BY ','.
CLEAR: wa_t005.
ENDIF.

CLEAR wa_t178.
READ TABLE it_t178
INTO wa_t178
WITH KEY kondm = wa_final-kondm.
IF sy-subrc IS NOT INITIAL
AND wa_t178 IS INITIAL.
wa_mestab-country = wa_final-land1.
wa_mestab-ipccode = wa_final-kondm.
wa_mestab-material = wa_final-matnr.
wa_mestab-plant = wa_final-werks.
CONCATENATE text-006 wa_mestab-text "Not a valid IPC code
INTO wa_mestab-text
SEPARATED BY ','.
IF l_v_flg IS INITIAL.
DELETE it_final INDEX l_v_index.
l_v_flg = c_x.
ENDIF.
CLEAR: wa_t178.
ENDIF.

CLEAR wa_t001w.
READ TABLE it_t001w
INTO wa_t001w
WITH KEY werks = wa_final-werks.
IF sy-subrc IS NOT INITIAL
AND wa_t001w IS INITIAL.
wa_mestab-country = wa_final-land1.
wa_mestab-ipccode = wa_final-kondm.
wa_mestab-material = wa_final-matnr.
wa_mestab-plant = wa_final-werks.
CONCATENATE text-008 wa_mestab-text "Not a valid Plant
INTO wa_mestab-text
SEPARATED BY ','.
IF l_v_flg IS INITIAL.
DELETE it_final INDEX l_v_index.
l_v_flg = c_x.
ENDIF.
CLEAR: wa_t001w.
ENDIF.

CLEAR wa_mara.
READ TABLE it_mara
INTO wa_mara
WITH KEY matnr = wa_final-matnr.
IF sy-subrc IS NOT INITIAL
AND wa_mara IS INITIAL.
IF wa_final-matnr IS INITIAL.
IF wa_mestab IS NOT INITIAL.
l_v_val = STRLEN( wa_mestab-text ).
l_v_val = l_v_val - 1.
wa_mestab-text = wa_mestab-text+0(l_v_val).
APPEND wa_mestab TO it_mestab.
CLEAR: wa_final,
wa_mara,
wa_mestab,
l_v_index,
l_v_flg.
CONTINUE.
ENDIF.
ELSE.
wa_mestab-country = wa_final-land1.
wa_mestab-ipccode = wa_final-kondm.
wa_mestab-material = wa_final-matnr.
wa_mestab-plant = wa_final-werks.
CONCATENATE text-007 wa_mestab-text "Not a valid Material
INTO wa_mestab-text
SEPARATED BY ','.
IF l_v_flg IS INITIAL.
DELETE it_final INDEX l_v_index.
l_v_flg = c_x.
ENDIF.
ENDIF.
ENDIF.

*--- Check whether the Material Number is blank or not.
IF wa_final-matnr IS NOT INITIAL.
*--- Validate Material Number and Plant combination in the internal table.
CLEAR wa_marc.
READ TABLE it_marc
INTO wa_marc
WITH KEY matnr = wa_final-matnr
werks = wa_final-werks
BINARY SEARCH.
IF sy-subrc IS INITIAL.
*--- Validate Material Number and Material Pricing Group combination in
*--- the internal table.
CLEAR wa_mvke.
READ TABLE it_mvke
INTO wa_mvke
WITH KEY matnr = wa_marc-matnr
kondm = wa_final-kondm
BINARY SEARCH.
IF sy-subrc IS NOT INITIAL
AND wa_mvke IS INITIAL.
wa_mestab-country = wa_final-land1.
wa_mestab-ipccode = wa_final-kondm.
wa_mestab-material = wa_final-matnr.
wa_mestab-plant = wa_final-werks.
CONCATENATE text-003 wa_mestab-text "Material does not belong to IPC
INTO wa_mestab-text
SEPARATED BY ','.
IF l_v_flg IS INITIAL.
DELETE it_final INDEX l_v_index.
l_v_flg = c_x.
ENDIF.
ENDIF.
ELSE.
wa_mestab-country = wa_final-land1.
wa_mestab-ipccode = wa_final-kondm.
wa_mestab-material = wa_final-matnr.
wa_mestab-plant = wa_final-werks.
CONCATENATE text-004 wa_mestab-text "Material does not exist in Plant
INTO wa_mestab-text
SEPARATED BY ','.
IF l_v_flg IS INITIAL.
DELETE it_final INDEX l_v_index.
l_v_flg = c_x.
ENDIF.
ENDIF.
ENDIF.

IF wa_mestab IS NOT INITIAL.
l_v_val = STRLEN( wa_mestab-text ).
l_v_val = l_v_val - 1.
wa_mestab-text = wa_mestab-text+0(l_v_val).
APPEND wa_mestab TO it_mestab.
ENDIF.

*--- Clear all the Work Areas and local variables.
CLEAR: wa_final,
wa_t005,
wa_t178,
wa_t001w,
wa_mara,
wa_marc,
wa_mvke,
wa_mestab,
l_v_index,
l_v_flg,
l_v_val.
ENDLOOP.
ENDIF.

ENDFORM. " fill_table


*&---------------------------------------------------------------------*
*& Form update_data
*&---------------------------------------------------------------------*
* Updation of table ZCUST_TAB
*----------------------------------------------------------------------*
FORM update_data.

SORT it_final BY land1 kondm matnr.
*--- Before updation check whether the internal table is initial or not.
IF it_final[] IS NOT INITIAL.
MODIFY zcust_tab FROM TABLE it_final.
COMMIT WORK.
IF sy-subrc IS INITIAL.
MESSAGE s117. "Data Uploaded Successfully
ENDIF.
ELSE.
MESSAGE s012 DISPLAY LIKE c_error. "No Data Found
ENDIF.

ENDFORM. " update_data


*&---------------------------------------------------------------------*
*& Form show_message
*&---------------------------------------------------------------------*
* Display the ALV Message Output
*----------------------------------------------------------------------*
FORM show_message.

DATA : l_v_total TYPE i, "Total number of records
l_v_error TYPE i, "Total number of error recors
l_v_text TYPE string,
l_v_text1 TYPE string,
l_v_text2 TYPE string,
l_v_success TYPE i. "Total number of successful records

DATA: o_l_label TYPE REF TO cl_salv_form_label, "#EC NEEDED
o_l_text TYPE REF TO cl_salv_form_text,
o_grid TYPE REF TO cl_salv_form_layout_grid.

CREATE OBJECT o_grid.
CREATE OBJECT o_l_label.

DESCRIBE TABLE it_file LINES l_v_total.
DESCRIBE TABLE it_final LINES l_v_success.

*--- Get error records
l_v_error = l_v_total - l_v_success.
l_v_text = l_v_success.
CONCATENATE text-013 ':' l_v_text INTO l_v_text SEPARATED BY space.
l_v_text1 = l_v_error .
CONCATENATE text-014 ':' l_v_text1 INTO l_v_text1 SEPARATED BY space.
l_v_text2 = l_v_total .
CONCATENATE text-015 ':' l_v_text2 INTO l_v_text2 SEPARATED BY space.
IF it_mestab[] IS NOT INITIAL.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = it_mestab."it_finalmes.

CATCH cx_salv_msg. "#EC NO_HANDLER
ENDTRY.

*--- Create first line for heading
IF l_v_text1 IS NOT INITIAL.
o_l_label = o_grid->create_label(
text = l_v_text1
row = 1
column = 1 ).
ENDIF.

*--- Create second line
IF l_v_text IS NOT INITIAL.
o_l_text = o_grid->create_text(
text = l_v_text
row = 2
column = 1 ).
ENDIF.

*--- Create third line
IF l_v_text2 IS NOT INITIAL.
o_l_text = o_grid->create_text(
text = l_v_text2
row = 3
column = 1 ).
ENDIF.
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
gr_display = gr_table->get_display_settings( ).
IF p_tst_md NE space.
gr_display->set_list_header( text-009 ). "Test run results : Error Records
ELSE.
gr_display->set_list_header( text-012 ). "Error Records
ENDIF.

gr_columns = gr_table->get_columns( ).
gr_column ?= gr_columns->get_column( 'TEXT' ).
gr_column->set_long_text( text-011 ). "Invalid Records in file

*--- Display Table
gr_table->set_top_of_list( o_grid ).
gr_table->display( ).
ELSEIF p_tst_md NE space.
MESSAGE i173. "No Invalid records in file
ENDIF.

ENDFORM. " show_message


*&---------------------------------------------------------------------*
*& Form clear_global_data
*&---------------------------------------------------------------------*
* Refresh global internal tables and Clear the global work areas
*----------------------------------------------------------------------*
FORM clear_global_data.

*--- Internal Tables
REFRESH: it_t005,
it_t178,
it_mara,
it_t001w,
it_marc,
it_mvke,
it_mestab.

*--- Work Areas
CLEAR: wa_t005,
wa_t178,
wa_mara,
wa_t001w,
wa_marc,
wa_mvke,
wa_mestab.

ENDFORM. " clear_global_data

1 Comment