Report Program to Upload the Material BOM
Scenario :
Uploading the Material BOM into SAP System from external file which may be either Text File ( *.TXT) or Excel File (*.XLS or *.XLSX).It is to be noted that the required file can be uploaded from both the presentation and application server.
So, in this document I have drafted the report program coding with necessary comments for better understandability.
List of subroutines used:
Function Module Name | Usage |
F4_FILENAME | Open up the file browser in Presentation Server and retrieve the user chosen file name. |
F4_DXFILENAME_TOPRECURSION | Open up the file browser in Application Server. |
SO_SPLIT_FILE_AND_PATH | Split up the file name and directory name |
TEXT_CONVERT_XLS_TO_SAP | Upload the contents in XLS file into Internal Table |
GUI_UPLOAD | Upload the contents in TEXT file into Internal Table |
BAPI_MATERIAL_BOM_GROUP_CREATE | BAPI to create Material BOM |
Z_ERPSDFM_STATUS_REPORT | Custom Function Module to display the summary report in ALV Format. |
BAPI_TRANSACTION_COMMIT | Committing the changes into Database. |
Method Name | Usage |
cl_gui_frontend_services=>directory_exist | Directory Existence Check |
cl_gui_frontend_services=>file_exist | File Existence Check |
Process Flow:
1) Upload the Header and Item file.
2) Read the contents in the header file, and item file. The key for both the files must be Material Number.
3) Fill up the necessary internal tables used as Exporting Parameter in BAPI_MATERIAL_BOM_GROUP_CREATE.
4) After SY_SUBRC check up, using the custom function module the Summary report is displayed in ALV Format.
Coding:
********** ***************************Main Program********** *********************
INCLUDE z_gsesdpi_bom_upload_top.
INCLUDE z_gsesdpi_bom_upload_logic.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR h_file.
IF r_app = 'X'.
PERFORM get_filename_app CHANGING dgv_filename.
h_file = dgv_filename.
ELSE.
PERFORM : get_filename CHANGING h_file.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR i_file.
IF r_app = 'X'.
PERFORM get_filename_app CHANGING dgv_filename.
i_file = dgv_filename.
ELSE.
PERFORM : get_filename CHANGING i_file.
dgv_item_filename = i_file.
ENDIF.
START-OF-SELECTION.
* Subroutines to check the filenames.
PERFORM : file_name_mandatory_check,
file_ext_check USING h_file,
file_ext_check USING i_file.
IF r_app <> 'X'.
PERFORM : file_name_validate USING h_file,
file_name_validate USING i_file.
ENDIF.
* Subroutines for uploading the contents of external files into internal tbl
dgv_header_filename = h_file.
PERFORM file_upload USING dgv_header_filename
dgw_header_file
CHANGING dgmst_header_file.
dgv_item_filename = i_file.
PERFORM file_upload USING dgv_item_filename
dgw_item_file
CHANGING dgmst_item_file.
* Subroutines for filling the BAPI fields and executing the same.
PERFORM : fill_bapi_details,
display_alv.
********** ***************************Top Include********** *********************
*** Type Pool declaration
TYPE-POOLS : slis ,
truxs.
TYPES : BEGIN OF dgmss_header_file,
*** BOMGROUP Table Fields ****
identifier TYPE matnr,
bom_group_identification TYPE cs_bgr_id,
technical_type TYPE tetyp_d,
bom_usage TYPE stlan,
bom_group TYPE exstl,
created_in_plant TYPE wrkan,
auth_group TYPE stlbe,
ltxt_lang TYPE c LENGTH 1,
langu_iso TYPE laiso,
bom_text TYPE cstext,
*** MATERIAL RELATIONS Table Fields ***
plant TYPE werks_d,
alternative_bom TYPE stalt,
lot_size_from TYPE c LENGTH 17,
lot_size_to TYPE c LENGTH 17,
material_external TYPE mgv_material_external,
material_guid TYPE mgv_material_guid,
material_version TYPE mgv_material_version,
*** VARIANTS Table Fields ***
bom_status TYPE c LENGTH 2,
deletion_ind TYPE loknz,
base_qty TYPE c LENGTH 17,
base_unit TYPE c LENGTH 3,
base_unit_iso TYPE isocd_unit,
lab_design TYPE labor,
alt_text TYPE stktx,
valid_from_date TYPE c LENGTH 10,
change_no TYPE aennr,
function TYPE cs_function,
*** TEXTS Table ***
format_col TYPE tdformat,
text_line TYPE tdline,
END OF dgmss_header_file,
*** ITEM Table
BEGIN OF dgmss_item_file,
identifier TYPE matnr,
item_id TYPE cs_itmid,
item_no TYPE sposn,
item_cat TYPE postp,
res_item_cat TYPE potpr,
sort_string TYPE sortp,
component TYPE idnrk,
document_type TYPE dokar,
document_number TYPE doknr,
document_version TYPE dokvr,
document_part TYPE doktl_d,
class_type TYPE klassenart,
class_num TYPE klasse_d,
reqd_comp TYPE clobk,
sel_cond TYPE cs_kzclb,
multselect TYPE clmult,
ltxt_lang TYPE c LENGTH 1,
langu_iso TYPE laiso,
item_text1 TYPE potx1,
item_text2 TYPE potx2,
comp_qty TYPE c LENGTH 18,
comp_unit TYPE c LENGTH 3,
comp_unit_iso TYPE isocd_unit,
fixed_qty TYPE fmnge,
vsi_no TYPE c LENGTH 17,
vsi_size1 TYPE c LENGTH 17,
vsi_size2 TYPE c LENGTH 17,
vsi_size3 TYPE c LENGTH 17,
vsi_size_unit TYPE c LENGTH 3,
vsi_size_unit_iso TYPE isocd_unit,
vsi_qty TYPE c LENGTH 17,
vsi_formula TYPE rform,
comp_scrap TYPE c LENGTH 6,
opr_scrap TYPE c LENGTH 6,
net_scrap_ind TYPE netau,
spare_part TYPE erskz,
mat_provision TYPE beikz,
eng_rel TYPE sanko,
prod_rel TYPE sanfe,
pm_rel TYPE sanin,
pm_assembly TYPE stkkz,
cost_rel TYPE cs_sanka,
sales_rel TYPE rvrel,
bulk_mat TYPE schgt,
pur_group TYPE ekgrp,
purch_org TYPE ekorg,
delivery_days TYPE c LENGTH 3,
vendor_no TYPE lifnr,
gr_pr_time TYPE c LENGTH 3,
price TYPE c LENGTH 14,
currency TYPE c LENGTH 5,
currency_iso TYPE isocd,
price_unit TYPE c LENGTH 6,
rec_allowed TYPE rekrs,
lead_time_offset TYPE c LENGTH 4,
distr_key_for_comp_consumption TYPE sa_verti,
purity TYPE c LENGTH 6,
co_product TYPE kzkup,
iss_st_loc TYPE cslgo,
alt_item_strategy TYPE cs_alpst,
alt_item_prio TYPE c LENGTH 2,
alt_item_group TYPE cs_alpgr,
usage_prob TYPE c LENGTH 3,
cost_element TYPE sakto,
follow_up_group TYPE cs_nfgrp,
discon_group TYPE cs_nfeag,
supplyarea TYPE prvbe,
spproctype TYPE cs_sobsl,
expl_type TYPE cs_dispo,
lead_time_offset_opr TYPE c LENGTH 4,
lead_time_offset_opr_unit TYPE c LENGTH 3,
lead_time_offset_opr_unit_iso TYPE isocd_unit,
ref_point TYPE cn_rfpnt,
valid_from_date TYPE c LENGTH 10,
change_no TYPE aennr,
component_external TYPE mgv_component_external,
component_guid TYPE mgv_component_guid,
component_version TYPE mgv_component_version,
END OF dgmss_item_file.
DATA : dgmss_commit_return TYPE bapiret2.
*** Table Declaration
DATA : dgmst_bomgroup TYPE TABLE OF bapi1080_bgr_c,
dgmst_variants TYPE TABLE OF bapi1080_bom_c,
dgmst_items TYPE TABLE OF bapi1080_itm_c,
dgmst_material TYPE TABLE OF bapi1080_mbm_c,
dgmst_itemassignments TYPE TABLE OF bapi1080_rel_itm_bom_c,
dgmst_texts TYPE TABLE OF bapi1080_txt_c,
dgmst_return TYPE TABLE OF bapiret2,
dgmst_header_file TYPE TABLE OF dgmss_header_file,
dgmst_item_file TYPE TABLE OF dgmss_item_file,
dgmst_output TYPE ZERPSDTTOUTPUT,
dgmst_conv_tab TYPE truxs_t_text_data.
*** Work Area Declaration
DATA : dgw_header_file LIKE LINE OF dgmst_header_file,
dgw_item_file LIKE LINE OF dgmst_item_file,
dgw_bomgroup LIKE LINE OF dgmst_bomgroup,
dgw_variants LIKE LINE OF dgmst_variants,
dgw_items LIKE LINE OF dgmst_items,
dgw_material LIKE LINE OF dgmst_material,
dgw_itemassignments LIKE LINE OF dgmst_itemassignments,
dgw_texts LIKE LINE OF dgmst_texts,
dgw_return LIKE LINE OF dgmst_return,
dgw_output LIKE LINE OF dgmst_output,
dgw_cellcolor TYPE lvc_s_scol.
*** Selection Screen Declaration
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-014.
SELECTION-SCREEN SKIP.
PARAMETERS : h_file TYPE rlgrap-filename.
SELECTION-SCREEN SKIP.
PARAMETERS : i_file TYPE rlgrap-filename.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK blk1.
SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-013.
SELECTION-SCREEN SKIP.
PARAMETERS r_app RADIOBUTTON GROUP grp USER-COMMAND DU.
PARAMETERS r_pre RADIOBUTTON GROUP grp DEFAULT 'X'.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK blk2.
*** Data declaration
DATA : dgv_filename TYPE dxfields-longpath,
dgv_header_filename TYPE string,
dgv_item_filename TYPE string,
dgv_sno TYPE ZREC_COUNT,
dgv_total_rec TYPE ZREC_COUNT,
dgv_error_rec TYPE ZREC_COUNT,
dgv_xls_pos TYPE sy-fdpos,
dgv_xlsx_pos TYPE sy-fdpos,
dgv_txt_pos TYPE sy-fdpos,
dgv_xls_check TYPE c LENGTH 1.
*** Constants Declaration
CONSTANTS : dgk_obj_type_bgr TYPE string VALUE 'BGR',
dgk_obj_type_bom TYPE string VALUE 'BOM',
dgk_obj_type_itm TYPE string VALUE 'ITM',
dgk_obj_id_bgr TYPE string VALUE 'ID_BGR',
dgk_obj_id_itm TYPE string VALUE 'ID_ITEM',
dgk_obj_id_bom TYPE string VALUE 'ID_BOM',
dgk_sno TYPE string VALUE 'SNO',
dgk_matnr TYPE string VALUE 'MATNR',
dgk_bom TYPE string VALUE 'BOM',
dgk_status TYPE string VALUE 'STATUS',
dgk_description TYPE string VALUE 'DESCRIPTION',
dgk_xls TYPE string VALUE '.xls',
dgk_xlsx TYPE string VALUE '.xlsx',
dgk_txt TYPE string VALUE '.txt'.
***************************************Logic***************************************
FORM file_name_mandatory_check.
* Checking whether the given input file is empty and displaying appropriate error message
IF h_file IS INITIAL.
MESSAGE s011.
STOP.
ENDIF.
IF i_file IS INITIAL.
MESSAGE s012.
STOP.
ENDIF.
ENDFORM. "file_name_mandatory_check
*&---------------------------------------------------------------------*
*& Form get_filename
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->S_FILENAME text
*----------------------------------------------------------------------*
FORM get_filename CHANGING s_filename TYPE rlgrap-filename.
* Function Module used to open up the file browser in presentation server.
* and retrieve the user choosen file name.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = sy-repid
dynpro_number = syst-dynnr
IMPORTING
file_name = s_filename.
ENDFORM. "get_filename
*&---------------------------------------------------------------------*
*& Form file_ext_check
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->S_FILENAME text
*----------------------------------------------------------------------*
FORM file_ext_check USING s_filename TYPE rlgrap-filename.
SEARCH s_filename FOR dgk_txt. " Searching the file name for string '.txt'.
MOVE sy-fdpos TO dgv_txt_pos. " Moving the position of the found string to a variable
SEARCH s_filename FOR dgk_xls. " Searching the file name for string '.xls'.
MOVE sy-fdpos TO dgv_xls_pos.
SEARCH s_filename FOR dgk_xlsx." Searching the file name for string '.xlsx'.
MOVE sy-fdpos TO dgv_xlsx_pos.
IF dgv_txt_pos = 0 AND " Neither 'txt' nor 'xls' files have been choosen.
dgv_xls_pos = 0 AND
dgv_xlsx_pos = 0.
MESSAGE s010.
STOP.
ENDIF.
IF dgv_xls_pos <> 0 OR dgv_xlsx_pos <> 0. " if 'xls' or 'xlsx' file has been choosen.
MOVE 'X' TO dgv_xls_check.
ENDIF.
ENDFORM. "file_ext_check
*&---------------------------------------------------------------------*
*& Form get_filename_app
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->S_FILENAME text
*----------------------------------------------------------------------*
FORM get_filename_app CHANGING s_filename TYPE dxfields-longpath.
* Function Module to open up the file browser for application server.
CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
EXPORTING
i_location_flag = 'A'
* I_SERVER = '?'
* I_PATH =
filemask = '*.*'
* FILEOPERATION = 'R'
IMPORTING
* O_LOCATION_FLAG =
* O_SERVER = dlv_o_server
o_path = s_filename
* ABEND_FLAG =
EXCEPTIONS
rfc_error = 1
error_with_gui = 2
OTHERS = 3
.
ENDFORM. "get_filename_app
*&---------------------------------------------------------------------*
*& Form file_name_validate
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM file_name_validate USING s_filename.
DATA : dlv_filename TYPE string,
dlv_dirname TYPE string,
dlv_result TYPE c LENGTH 1.
* Function Module to split up the file name and directory name.
CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
EXPORTING
full_name = s_filename
IMPORTING
stripped_name = dlv_filename
file_path = dlv_dirname
EXCEPTIONS
x_error = 1
OTHERS = 2.
IF sy-subrc = 0.
* Directory existence check
CALL METHOD cl_gui_frontend_services=>directory_exist
EXPORTING
directory = dlv_dirname
RECEIVING
result = dlv_result
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
IF dlv_result IS INITIAL.
MESSAGE s008.
STOP.
ENDIF.
* File Existence Check
CLEAR dlv_result.
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = dlv_filename
RECEIVING
result = dlv_result
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
IF dlv_result IS INITIAL.
MESSAGE s009.
STOP.
ENDIF.
ENDIF.
ENDFORM. "file_name_validate
*&---------------------------------------------------------------------*
*& Form file_upload
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM file_upload USING dlv_filename
value(dlw_tab)
CHANGING dlmst_tab TYPE STANDARD TABLE .
IF r_app = 'X'. " If the Application Server Radio Button has been choosen.
OPEN DATASET dlv_filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 8. " File not found in application server.
MESSAGE s009.
STOP.
ELSEIF sy-subrc = 0.
DO.
READ DATASET dlv_filename INTO dlw_tab.
IF sy-subrc = 0.
APPEND dlw_tab TO dlmst_tab.
CLEAR dlw_tab.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET h_file.
ELSEIF dgv_xls_check = 'X'. " If 'XLS' file has been choosen.
DATA dlv_filename_xls TYPE rlgrap-filename.
dlv_filename_xls = dlv_filename.
* Function module to upload the contents in XLS file into an internal table.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_tab_raw_data = dgmst_conv_tab
i_filename = dlv_filename_xls
TABLES
i_tab_converted_data = dlmst_tab
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
ELSE.
* Function module to upload the contents in TXT file into an internal table.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = dlv_filename
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = dlmst_tab
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.
ENDIF.
ENDFORM. "file_upload
*&---------------------------------------------------------------------*
*& Form fill_bapi_details
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM fill_bapi_details.
SORT dgmst_item_file BY identifier.
LOOP AT dgmst_item_file INTO dgw_item_file. " Looping the item file
AT NEW identifier. " At new Identifier, record has to be read from Header file.
READ TABLE dgmst_header_file INTO dgw_header_file WITH KEY identifier = dgw_item_file-identifier BINARY SEARCH.
IF sy-subrc = 0.
PERFORM fill_data.
ENDIF.
ENDAT.
MOVE-CORRESPONDING dgw_item_file TO dgw_items.
MOVE : dgw_header_file-bom_group_identification TO dgw_items-bom_group_identification,
dgk_obj_type_itm TO dgw_items-object_type,
dgk_obj_id_itm TO dgw_items-object_id.
APPEND dgw_items TO dgmst_items.
CLEAR dgw_items.
AT END OF identifier.
PERFORM : call_bapi,
refresh_tables.
ENDAT.
ENDLOOP.
ENDFORM. "fill_bapi_details
*&---------------------------------------------------------------------*
*& Form fill_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM fill_data.
* Filling BOMGROUP Table
MOVE : dgw_header_file-bom_group_identification TO dgw_bomgroup-bom_group_identification,
dgk_obj_type_bgr TO dgw_bomgroup-object_type,
dgk_obj_id_bgr TO dgw_bomgroup-object_id,
dgw_header_file-technical_type TO dgw_bomgroup-technical_type,
dgw_header_file-bom_usage TO dgw_bomgroup-bom_usage,
dgw_header_file-bom_group TO dgw_bomgroup-bom_group,
dgw_header_file-created_in_plant TO dgw_bomgroup-created_in_plant,
dgw_header_file-auth_group TO dgw_bomgroup-auth_group,
dgw_header_file-ltxt_lang TO dgw_bomgroup-ltxt_lang,
dgw_header_file-langu_iso TO dgw_bomgroup-langu_iso,
dgw_header_file-bom_text TO dgw_bomgroup-bom_text.
APPEND dgw_bomgroup TO dgmst_bomgroup.
CLEAR dgw_bomgroup.
*******
* Filling Material Relations Table
MOVE : dgw_header_file-bom_group_identification TO dgw_material-bom_group_identification,
dgw_header_file-identifier TO dgw_material-material,
dgw_header_file-plant TO dgw_material-plant,
dgw_header_file-bom_usage TO dgw_material-bom_usage,
dgw_header_file-alternative_bom TO dgw_material-alternative_bom,
dgw_header_file-lot_size_from TO dgw_material-lot_size_from,
dgw_header_file-lot_size_to TO dgw_material-lot_size_to,
dgw_header_file-material_external TO dgw_material-material_external,
dgw_header_file-material_guid TO dgw_material-material_guid,
dgw_header_file-material_version TO dgw_material-material_version.
APPEND dgw_material TO dgmst_material.
CLEAR dgw_material.
*******
* Filling Variants Table
MOVE : dgw_header_file-bom_group_identification TO dgw_variants-bom_group_identification,
dgk_obj_type_bom TO dgw_variants-object_type,
dgk_obj_id_bom TO dgw_variants-object_id,
dgw_header_file-alternative_bom TO dgw_variants-alternative_bom,
dgw_header_file-bom_status TO dgw_variants-bom_status,
dgw_header_file-deletion_ind TO dgw_variants-deletion_ind,
dgw_header_file-base_qty TO dgw_variants-base_qty,
dgw_header_file-base_unit TO dgw_variants-base_unit,
dgw_header_file-base_unit_iso TO dgw_variants-base_unit_iso,
dgw_header_file-lab_design TO dgw_variants-lab_design,
dgw_header_file-alt_text TO dgw_variants-alt_text,
dgw_header_file-change_no TO dgw_variants-change_no,
dgw_header_file-function TO dgw_variants-function.
IF dgw_header_file-valid_from_date = ' '.
MOVE sy-datum TO dgw_variants-valid_from_date.
ELSE.
MOVE dgw_header_file-valid_from_date TO dgw_variants-valid_from_date.
ENDIF.
APPEND dgw_variants TO dgmst_variants.
CLEAR dgw_variants.
*******
* Filling Texts Table
IF dgw_header_file-text_line IS NOT INITIAL.
MOVE : dgw_header_file-bom_group_identification TO dgw_texts-bom_group_identification,
dgk_obj_type_bgr TO dgw_texts-object_type,
dgk_obj_id_bgr TO dgw_texts-object_id,
dgw_header_file-format_col TO dgw_texts-format_col,
dgw_header_file-text_line TO dgw_texts-text_line.
APPEND dgw_texts TO dgmst_texts.
CLEAR dgw_texts.
ENDIF.
*******
* Filling Item Assignments Table
MOVE : dgw_header_file-bom_group_identification TO dgw_itemassignments-bom_group_identification,
dgk_obj_type_itm TO dgw_itemassignments-sub_object_type,
dgk_obj_id_itm TO dgw_itemassignments-sub_object_id,
dgk_obj_type_bom TO dgw_itemassignments-super_object_type,
dgk_obj_id_bom TO dgw_itemassignments-super_object_id,
dgw_header_file-change_no TO dgw_itemassignments-change_no,
dgw_header_file-function TO dgw_itemassignments-function.
IF dgw_header_file-valid_from_date = ' '.
MOVE sy-datum TO dgw_itemassignments-valid_from_date.
ELSE.
MOVE dgw_header_file-valid_from_date TO dgw_itemassignments-valid_from_date.
ENDIF.
APPEND dgw_itemassignments TO dgmst_itemassignments.
CLEAR dgw_itemassignments.
*******
ENDFORM. "fill_data
*&---------------------------------------------------------------------*
*& Form call_bapi
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM call_bapi.
DESCRIBE TABLE dgmst_header_file LINES dgv_total_rec. " Total number of records in header file.
CALL FUNCTION 'BAPI_MATERIAL_BOM_GROUP_CREATE' " BAPI to create the Material BOM.
EXPORTING
all_error = 'X'
TABLES
bomgroup = dgmst_bomgroup
variants = dgmst_variants
items = dgmst_items
materialrelations = dgmst_material
itemassignments = dgmst_itemassignments
texts = dgmst_texts
return = dgmst_return.
ADD 1 TO dgv_sno. " Incrementing the counter variable.
MOVE : dgv_sno TO dgw_output-sno,
dgw_header_file-identifier TO dgw_output-input_1.
* Looping the return table, to fetch the error messages.
LOOP AT dgmst_return INTO dgw_return.
MOVE dgw_return-message TO dgw_output-description.
IF dgw_return-type EQ 'I'.
MOVE : text-010 TO dgw_output-status, " 'SUCCESS' is moved to status field.
dgw_return-message_v2 TO dgw_output-input_2. " BOM Number is moved to BOM field.
ELSEIF dgw_return-type EQ 'E'.
ADD 1 TO dgv_error_rec.
MOVE : text-011 TO dgw_output-status, " 'ERROR' is moved to status field.
dgk_status TO dgw_cellcolor-fname, " Field name which is to be colored is moved.
'6' TO dgw_cellcolor-color-col. " Color Code 6 - RED.
APPEND dgw_cellcolor TO dgw_output-cellcolor.
CLEAR dgw_cellcolor.
ELSE.
CONTINUE.
ENDIF.
APPEND dgw_output TO dgmst_output.
CLEAR dgw_output.
PERFORM transaction_commit.
ENDLOOP.
ENDFORM. "call_bapi
*&---------------------------------------------------------------------*
*& Form display_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM display_alv.
* Custom Function Module to display the Summary report in ALV format.
CALL FUNCTION 'Z_ERPSDFM_STATUS_REPORT'
EXPORTING
total_rec = dgv_total_rec
error_rec = dgv_error_rec
input_1 = 'Material Number'
input_2 = 'BOM'
CHANGING
output = dgmst_output
EXCEPTIONS
empty_output = 1
OTHERS = 2.
IF sy-subrc = 1.
MESSAGE s007.
STOP.
ENDIF.
ENDFORM. "display_alv
*&---------------------------------------------------------------------*
*& Form refresh_tables
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM refresh_tables.
REFRESH : dgmst_bomgroup,
dgmst_material,
dgmst_variants,
dgmst_texts,
dgmst_itemassignments,
dgmst_items,
dgmst_return.
ENDFORM. "refresh_tables
*&---------------------------------------------------------------------*
*& Form transaction_commit
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM transaction_commit.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
IMPORTING
return = dgmss_commit_return.
IF dgmss_commit_return-type = 'E'.
MESSAGE a001.
ENDIF.
ENDFORM. "transaction_commit
Output:
There are lot more standard coding to display in Standard SAP ALV Report Summary format, but still the custom function module for displaying the report summary in ALV format has been given. Please find the details of it in the attachments.
NOTE: Sample Input files have been attached. But,please prepare the header and item input file with file structure based on the structure declaration in the top include corresponding to both Header and Item file.