SAP ABAP - Create Characteristic With Excel File Upload
Excel Template
Main Program
*&---------------------------------------------------------------------*
*& Report ZCREATE_CHAR
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZCREATE_CHAR.
INCLUDE ZCREATE_CHAR1.
INCLUDE ZCREATE_CHAR2.
INCLUDE ZCREATE_CHAR3.
START-OF-SELECTION.
call SCREEN 100.
ABAP Code
------------------------------------------------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Report ZCREATE_CHAR
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZCREATE_CHAR.
INCLUDE ZCREATE_CHAR1.
INCLUDE ZCREATE_CHAR2.
INCLUDE ZCREATE_CHAR3.
START-OF-SELECTION.
call SCREEN 100.
Include ZCREATE_CHAR1
*&---------------------------------------------------------------------*
*& Include ZCREATE_CHAR1
*&---------------------------------------------------------------------*
TYPES :
BEGIN OF ZPRINT,
ICONS LIKE ICON-ID,
CCELL TYPE LVC_T_SCOL,
CSTYL TYPE LVC_T_STYL,
CLINE TYPE CHAR4,
SNOTE TYPE STRING,
ATNAM TYPE CHAR50,
ATBEZ TYPE CHAR30,
ATUDF TYPE CHAR18,
CHARNUMBER TYPE CHAR2,
DECPLACES TYPE CHAR2,
MEINS TYPE CHAR5,
MEINS_ISO TYPE CHAR5.
TYPES :
END OF ZPRINT,
BEGIN OF T_RECORD,
* Z TYPE CHAR1,
ATNAM TYPE CHAR50,
ATBEZ TYPE CHAR30,
ATUDF TYPE CHAR18,
CHARNUMBER TYPE CHAR2,
DECPLACES TYPE CHAR2,
MEINS TYPE CHAR5,
MEINS_ISO TYPE CHAR5,
END OF T_RECORD.
DATA:
ITAB LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE,
IT_PRINT TYPE TABLE OF ZPRINT,
WA_PRINT TYPE ZPRINT,
VI_ITAB TYPE I.
TYPES:
ZRECRD TYPE T_RECORD.
DATA: IT_RECRD TYPE TABLE OF ZRECRD,
WA_RECRD TYPE ZRECRD.
DATA: ZZ_PID TYPE CHAR80,
VC_MSG TYPE STRING, "String for Message
VC_STR TYPE STRING, "String for Popup
VC_PPP TYPE CHAR4, "Popup ID
VC_ANS TYPE CHAR1, "Answer
VI_TDO TYPE I, "Timer
VI_TCN TYPE I, "Timer Counter
VI_TOT TYPE I, "Counter Load
VI_CLD TYPE I, "Counter Load
VI_ROW TYPE I, "Row in Excel for Upload
VI_ERR TYPE I, "Error
VI_LCK TYPE I, "Lock Table
OK_CODE TYPE SY-UCOMM.
DATA: VI_FCLEN TYPE I,
VS_FCFLD TYPE STRING.
DATA: OB_CUST TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
OB_GRID TYPE REF TO CL_GUI_ALV_GRID,
OB_TIMER TYPE REF TO CL_GUI_TIMER.
DATA: IT_COLOR TYPE TABLE OF LVC_S_SCOL,
WA_COLOR TYPE LVC_S_SCOL.
DATA: VI_COLOR TYPE I.
DATA: IS_VARNT LIKE DISVARIANT,
IS_LYOUT TYPE LVC_S_LAYO,
IS_PRINT TYPE LVC_S_PRNT.
DATA: IT_EXCLD TYPE UI_FUNCTIONS. "----- For Toolbar Exclude ALV -----
DATA: WA_STYLE TYPE LVC_S_STYL. "----- For Style ALV -----
DATA: IT_FCATL TYPE LVC_T_FCAT, "----- For Field Catalog 1 ALV -----
WA_FCATL LIKE LINE OF IT_FCATL.
DATA: IT_SORT TYPE LVC_T_SORT,
WA_SORT LIKE LINE OF IT_SORT.
TYPES:
BEGIN OF ZSTAB,
FIELD TYPE CHAR10,
END OF ZSTAB.
DATA: STAB TYPE TABLE OF ZSTAB.
*& Include ZCREATE_CHAR1
*&---------------------------------------------------------------------*
TYPES :
BEGIN OF ZPRINT,
ICONS LIKE ICON-ID,
CCELL TYPE LVC_T_SCOL,
CSTYL TYPE LVC_T_STYL,
CLINE TYPE CHAR4,
SNOTE TYPE STRING,
ATNAM TYPE CHAR50,
ATBEZ TYPE CHAR30,
ATUDF TYPE CHAR18,
CHARNUMBER TYPE CHAR2,
DECPLACES TYPE CHAR2,
MEINS TYPE CHAR5,
MEINS_ISO TYPE CHAR5.
TYPES :
END OF ZPRINT,
BEGIN OF T_RECORD,
* Z TYPE CHAR1,
ATNAM TYPE CHAR50,
ATBEZ TYPE CHAR30,
ATUDF TYPE CHAR18,
CHARNUMBER TYPE CHAR2,
DECPLACES TYPE CHAR2,
MEINS TYPE CHAR5,
MEINS_ISO TYPE CHAR5,
END OF T_RECORD.
DATA:
ITAB LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE,
IT_PRINT TYPE TABLE OF ZPRINT,
WA_PRINT TYPE ZPRINT,
VI_ITAB TYPE I.
TYPES:
ZRECRD TYPE T_RECORD.
DATA: IT_RECRD TYPE TABLE OF ZRECRD,
WA_RECRD TYPE ZRECRD.
DATA: ZZ_PID TYPE CHAR80,
VC_MSG TYPE STRING, "String for Message
VC_STR TYPE STRING, "String for Popup
VC_PPP TYPE CHAR4, "Popup ID
VC_ANS TYPE CHAR1, "Answer
VI_TDO TYPE I, "Timer
VI_TCN TYPE I, "Timer Counter
VI_TOT TYPE I, "Counter Load
VI_CLD TYPE I, "Counter Load
VI_ROW TYPE I, "Row in Excel for Upload
VI_ERR TYPE I, "Error
VI_LCK TYPE I, "Lock Table
OK_CODE TYPE SY-UCOMM.
DATA: VI_FCLEN TYPE I,
VS_FCFLD TYPE STRING.
DATA: OB_CUST TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
OB_GRID TYPE REF TO CL_GUI_ALV_GRID,
OB_TIMER TYPE REF TO CL_GUI_TIMER.
DATA: IT_COLOR TYPE TABLE OF LVC_S_SCOL,
WA_COLOR TYPE LVC_S_SCOL.
DATA: VI_COLOR TYPE I.
DATA: IS_VARNT LIKE DISVARIANT,
IS_LYOUT TYPE LVC_S_LAYO,
IS_PRINT TYPE LVC_S_PRNT.
DATA: IT_EXCLD TYPE UI_FUNCTIONS. "----- For Toolbar Exclude ALV -----
DATA: WA_STYLE TYPE LVC_S_STYL. "----- For Style ALV -----
DATA: IT_FCATL TYPE LVC_T_FCAT, "----- For Field Catalog 1 ALV -----
WA_FCATL LIKE LINE OF IT_FCATL.
DATA: IT_SORT TYPE LVC_T_SORT,
WA_SORT LIKE LINE OF IT_SORT.
TYPES:
BEGIN OF ZSTAB,
FIELD TYPE CHAR10,
END OF ZSTAB.
DATA: STAB TYPE TABLE OF ZSTAB.
Include ZCREATE_CHAR2
*&---------------------------------------------------------------------*
*& Include ZCREATE_CHAR2
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF SCREEN 101 AS SUBSCREEN.
PARAMETERS:
FILENAME TYPE LOCALFILE,
P_LINE TYPE I DEFAULT 2.
SELECTION-SCREEN END OF SCREEN 101 .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILENAME.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
STATIC = 'X'
MASK = '*.xls'
CHANGING
FILE_NAME = FILENAME.
AT SELECTION-SCREEN OUTPUT.
* GET PARAMETER ID 'ZMM01' FIELD ZZ_PID.
* IF ZZ_PID IS INITIAL.
* SET PARAMETER ID 'ZMM01' FIELD 'D:\SAP\Test Upload MM01.xlsx'.
* ENDIF.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
REFRESH STAB.
IF IT_PRINT IS INITIAL.
APPEND 'POST' TO STAB.
APPEND 'SCLR' TO STAB.
ELSE.
APPEND 'READ' TO STAB.
ENDIF.
SET PF-STATUS 'PFSTATUS' EXCLUDING STAB.
SET TITLEBAR 'TITLE'.
PERFORM INITIAL_FORM.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'BACK' OR 'EXIT' OR 'CNCL'.
LEAVE PROGRAM.
WHEN 'READ'.
REFRESH IT_PRINT.
PERFORM READ_UPLOD_XLS USING FILENAME '1' P_LINE '200' '32000'.
PERFORM PARSG_TXT USING 1.
WHEN 'SCLR'.
REFRESH IT_PRINT.
WHEN 'POST'.
READ TABLE IT_PRINT WITH KEY ICONS = '@0A@' TRANSPORTING NO FIELDS.
IF SY-SUBRC = 0.
MESSAGE 'Please check your data' TYPE 'S' DISPLAY LIKE 'E'.
ELSE.
DATA :
CHARACTDETAIL TYPE BAPICHARACTDETAIL,
CHARACTDESCR TYPE TABLE OF BAPICHARACTDESCR WITH HEADER LINE,
ITRETURN TYPE TABLE OF BAPIRET2,
LSRETURN TYPE BAPIRET2.
CLEAR WA_PRINT.
LOOP AT IT_PRINT INTO WA_PRINT.
CLEAR CHARACTDETAIL.
CHARACTDETAIL-CHARACT_NAME = WA_PRINT-ATNAM.
CHARACTDETAIL-DATA_TYPE = WA_PRINT-ATUDF.
CHARACTDETAIL-LENGTH = WA_PRINT-CHARNUMBER.
CHARACTDETAIL-DECIMALS = WA_PRINT-DECPLACES.
CHARACTDETAIL-CASE_SENSITIV = 'X'.
CHARACTDETAIL-STATUS = '1'.
CHARACTDETAIL-ADDITIONAL_VALUES = '1'.
CHARACTDETAIL-UNIT_OF_MEASUREMENT = WA_PRINT-MEINS.
CHARACTDETAIL-UNIT_OF_MEASUREMENT_ISO = WA_PRINT-MEINS_ISO.
REFRESH CHARACTDESCR.
CLEAR CHARACTDESCR.
CHARACTDESCR-LANGUAGE_INT = 'EN'.
CHARACTDESCR-LANGUAGE_ISO = 'EN'.
CHARACTDESCR-DESCRIPTION = WA_PRINT-ATBEZ.
APPEND CHARACTDESCR.
CALL FUNCTION 'BAPI_CHARACT_CREATE'
EXPORTING
CHARACTDETAIL = CHARACTDETAIL
TABLES
CHARACTDESCR = CHARACTDESCR[]
RETURN = ITRETURN.
CLEAR LSRETURN.
READ TABLE ITRETURN INTO LSRETURN WITH KEY TYPE = 'E'.
IF SY-SUBRC = 0.
WA_PRINT-ICONS = '@F1@'.
WA_PRINT-SNOTE = LSRETURN-MESSAGE.
MODIFY IT_PRINT FROM WA_PRINT TRANSPORTING ICONS SNOTE WHERE ATNAM = WA_PRINT-ATNAM.
ELSE.
WA_PRINT-ICONS = '@5Y@'.
WA_PRINT-SNOTE = 'Characteristic created'.
MODIFY IT_PRINT FROM WA_PRINT TRANSPORTING ICONS SNOTE WHERE ATNAM = WA_PRINT-ATNAM.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ENDIF.
CLEAR WA_PRINT.
ENDLOOP.
ENDIF.
ENDCASE.
ENDMODULE.
FORM READ_UPLOD_XLS USING P_FILE P_BCOL TYPE I P_BROW TYPE I P_ECOL TYPE I P_EROW TYPE I.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = P_BCOL
I_BEGIN_ROW = P_BROW
I_END_COL = P_ECOL
I_END_ROW = P_EROW
TABLES
INTERN = ITAB[]
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
VC_MSG = SY-SUBRC.
CONDENSE VC_MSG.
CONCATENATE 'Error' VC_MSG 'Problem Uploading Excel Spreadsheet' INTO VC_MSG SEPARATED BY ' '.
MESSAGE VC_MSG TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
ENDFORM.
FORM PARSG_TXT USING P_SET.
* DATA ZMMC001 TYPE TABLE OF ZMMSC001_1 WITH HEADER LINE.
DATA LV_INDEX TYPE I.
FIELD-SYMBOLS <FS>.
IF P_SET = 0.
ELSEIF P_SET = 1.
REFRESH IT_RECRD.
SORT ITAB BY ROW COL.
CLEAR WA_RECRD.
LOOP AT ITAB.
MOVE ITAB-COL TO LV_INDEX.
ASSIGN COMPONENT LV_INDEX OF STRUCTURE WA_RECRD TO <FS>.
MOVE ITAB-VALUE TO <FS>.
AT END OF ROW.
APPEND WA_RECRD TO IT_RECRD.
CLEAR WA_PRINT.
MOVE-CORRESPONDING WA_RECRD TO WA_PRINT.
PERFORM F_VALIDATION.
APPEND WA_PRINT TO IT_PRINT.
CLEAR WA_RECRD.
ENDAT.
ENDLOOP.
ENDIF.
ENDFORM.
FORM F_VALIDATION.
REFRESH IT_COLOR.
DATA WA_T006A TYPE T006A.
DATA WA_CABN TYPE CABN.
PERFORM TO_TRAFC_SET USING '@08@' 'ZZ' 1.
"Check Existing Characteristic
CLEAR WA_CABN.
SELECT SINGLE * FROM CABN INTO WA_CABN WHERE ATNAM = WA_PRINT-ATNAM.
IF WA_CABN IS NOT INITIAL.
PERFORM TO_TRAFC_SET USING '@0A@' 'ABCDEFGKLPQSVXZ' 1.
PERFORM ALV_COLOR_SET USING 'ATNAM' '6' '1' '1'.
WA_PRINT-SNOTE = 'Characteristic already exists'.
ENDIF.
"Check UOM
CLEAR WA_T006A.
SELECT SINGLE * FROM T006A INTO WA_T006A
WHERE MSEH3 = WA_PRINT-MEINS AND SPRAS = 'EN'.
IF WA_T006A IS INITIAL.
PERFORM TO_TRAFC_SET USING '@0A@' 'ABCDEFGKLPQSVXZ' 1.
PERFORM ALV_COLOR_SET USING 'MEINS' '6' '1' '1'.
PERFORM ALV_COLOR_SET USING 'MEINS_ISO' '6' '1' '1'.
ENDIF.
ENDFORM.
FORM TO_TRAFC_SET USING P_ICN P_SET P_ALL.
IF ( P_ALL = 1 AND WA_PRINT-ICONS <> '@02@' ) OR P_ALL = 9.
WA_PRINT-ICONS = P_ICN.
ENDIF.
ENDFORM. " TO_TRAFC_SET
*& Include ZCREATE_CHAR2
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF SCREEN 101 AS SUBSCREEN.
PARAMETERS:
FILENAME TYPE LOCALFILE,
P_LINE TYPE I DEFAULT 2.
SELECTION-SCREEN END OF SCREEN 101 .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILENAME.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
STATIC = 'X'
MASK = '*.xls'
CHANGING
FILE_NAME = FILENAME.
AT SELECTION-SCREEN OUTPUT.
* GET PARAMETER ID 'ZMM01' FIELD ZZ_PID.
* IF ZZ_PID IS INITIAL.
* SET PARAMETER ID 'ZMM01' FIELD 'D:\SAP\Test Upload MM01.xlsx'.
* ENDIF.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
REFRESH STAB.
IF IT_PRINT IS INITIAL.
APPEND 'POST' TO STAB.
APPEND 'SCLR' TO STAB.
ELSE.
APPEND 'READ' TO STAB.
ENDIF.
SET PF-STATUS 'PFSTATUS' EXCLUDING STAB.
SET TITLEBAR 'TITLE'.
PERFORM INITIAL_FORM.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'BACK' OR 'EXIT' OR 'CNCL'.
LEAVE PROGRAM.
WHEN 'READ'.
REFRESH IT_PRINT.
PERFORM READ_UPLOD_XLS USING FILENAME '1' P_LINE '200' '32000'.
PERFORM PARSG_TXT USING 1.
WHEN 'SCLR'.
REFRESH IT_PRINT.
WHEN 'POST'.
READ TABLE IT_PRINT WITH KEY ICONS = '@0A@' TRANSPORTING NO FIELDS.
IF SY-SUBRC = 0.
MESSAGE 'Please check your data' TYPE 'S' DISPLAY LIKE 'E'.
ELSE.
DATA :
CHARACTDETAIL TYPE BAPICHARACTDETAIL,
CHARACTDESCR TYPE TABLE OF BAPICHARACTDESCR WITH HEADER LINE,
ITRETURN TYPE TABLE OF BAPIRET2,
LSRETURN TYPE BAPIRET2.
CLEAR WA_PRINT.
LOOP AT IT_PRINT INTO WA_PRINT.
CLEAR CHARACTDETAIL.
CHARACTDETAIL-CHARACT_NAME = WA_PRINT-ATNAM.
CHARACTDETAIL-DATA_TYPE = WA_PRINT-ATUDF.
CHARACTDETAIL-LENGTH = WA_PRINT-CHARNUMBER.
CHARACTDETAIL-DECIMALS = WA_PRINT-DECPLACES.
CHARACTDETAIL-CASE_SENSITIV = 'X'.
CHARACTDETAIL-STATUS = '1'.
CHARACTDETAIL-ADDITIONAL_VALUES = '1'.
CHARACTDETAIL-UNIT_OF_MEASUREMENT = WA_PRINT-MEINS.
CHARACTDETAIL-UNIT_OF_MEASUREMENT_ISO = WA_PRINT-MEINS_ISO.
REFRESH CHARACTDESCR.
CLEAR CHARACTDESCR.
CHARACTDESCR-LANGUAGE_INT = 'EN'.
CHARACTDESCR-LANGUAGE_ISO = 'EN'.
CHARACTDESCR-DESCRIPTION = WA_PRINT-ATBEZ.
APPEND CHARACTDESCR.
CALL FUNCTION 'BAPI_CHARACT_CREATE'
EXPORTING
CHARACTDETAIL = CHARACTDETAIL
TABLES
CHARACTDESCR = CHARACTDESCR[]
RETURN = ITRETURN.
CLEAR LSRETURN.
READ TABLE ITRETURN INTO LSRETURN WITH KEY TYPE = 'E'.
IF SY-SUBRC = 0.
WA_PRINT-ICONS = '@F1@'.
WA_PRINT-SNOTE = LSRETURN-MESSAGE.
MODIFY IT_PRINT FROM WA_PRINT TRANSPORTING ICONS SNOTE WHERE ATNAM = WA_PRINT-ATNAM.
ELSE.
WA_PRINT-ICONS = '@5Y@'.
WA_PRINT-SNOTE = 'Characteristic created'.
MODIFY IT_PRINT FROM WA_PRINT TRANSPORTING ICONS SNOTE WHERE ATNAM = WA_PRINT-ATNAM.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ENDIF.
CLEAR WA_PRINT.
ENDLOOP.
ENDIF.
ENDCASE.
ENDMODULE.
FORM READ_UPLOD_XLS USING P_FILE P_BCOL TYPE I P_BROW TYPE I P_ECOL TYPE I P_EROW TYPE I.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = P_BCOL
I_BEGIN_ROW = P_BROW
I_END_COL = P_ECOL
I_END_ROW = P_EROW
TABLES
INTERN = ITAB[]
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
VC_MSG = SY-SUBRC.
CONDENSE VC_MSG.
CONCATENATE 'Error' VC_MSG 'Problem Uploading Excel Spreadsheet' INTO VC_MSG SEPARATED BY ' '.
MESSAGE VC_MSG TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
ENDFORM.
FORM PARSG_TXT USING P_SET.
* DATA ZMMC001 TYPE TABLE OF ZMMSC001_1 WITH HEADER LINE.
DATA LV_INDEX TYPE I.
FIELD-SYMBOLS <FS>.
IF P_SET = 0.
ELSEIF P_SET = 1.
REFRESH IT_RECRD.
SORT ITAB BY ROW COL.
CLEAR WA_RECRD.
LOOP AT ITAB.
MOVE ITAB-COL TO LV_INDEX.
ASSIGN COMPONENT LV_INDEX OF STRUCTURE WA_RECRD TO <FS>.
MOVE ITAB-VALUE TO <FS>.
AT END OF ROW.
APPEND WA_RECRD TO IT_RECRD.
CLEAR WA_PRINT.
MOVE-CORRESPONDING WA_RECRD TO WA_PRINT.
PERFORM F_VALIDATION.
APPEND WA_PRINT TO IT_PRINT.
CLEAR WA_RECRD.
ENDAT.
ENDLOOP.
ENDIF.
ENDFORM.
FORM F_VALIDATION.
REFRESH IT_COLOR.
DATA WA_T006A TYPE T006A.
DATA WA_CABN TYPE CABN.
PERFORM TO_TRAFC_SET USING '@08@' 'ZZ' 1.
"Check Existing Characteristic
CLEAR WA_CABN.
SELECT SINGLE * FROM CABN INTO WA_CABN WHERE ATNAM = WA_PRINT-ATNAM.
IF WA_CABN IS NOT INITIAL.
PERFORM TO_TRAFC_SET USING '@0A@' 'ABCDEFGKLPQSVXZ' 1.
PERFORM ALV_COLOR_SET USING 'ATNAM' '6' '1' '1'.
WA_PRINT-SNOTE = 'Characteristic already exists'.
ENDIF.
"Check UOM
CLEAR WA_T006A.
SELECT SINGLE * FROM T006A INTO WA_T006A
WHERE MSEH3 = WA_PRINT-MEINS AND SPRAS = 'EN'.
IF WA_T006A IS INITIAL.
PERFORM TO_TRAFC_SET USING '@0A@' 'ABCDEFGKLPQSVXZ' 1.
PERFORM ALV_COLOR_SET USING 'MEINS' '6' '1' '1'.
PERFORM ALV_COLOR_SET USING 'MEINS_ISO' '6' '1' '1'.
ENDIF.
ENDFORM.
FORM TO_TRAFC_SET USING P_ICN P_SET P_ALL.
IF ( P_ALL = 1 AND WA_PRINT-ICONS <> '@02@' ) OR P_ALL = 9.
WA_PRINT-ICONS = P_ICN.
ENDIF.
ENDFORM. " TO_TRAFC_SET
Include ZCREATE_CHAR3
*&---------------------------------------------------------------------*
*& Include ZCREATE_CHAR3
*&---------------------------------------------------------------------*
FORM initial_form.
CHECK ok_code <> 'EXIT'.
IF ob_cust IS INITIAL.
CREATE OBJECT ob_cust
EXPORTING
container_name = 'CONTAINER'.
CREATE OBJECT ob_grid
EXPORTING
i_parent = ob_cust.
* create object g_event_receiver.
ENDIF.
PERFORM set_varnt.
PERFORM set_lyout.
PERFORM set_fieldcat.
PERFORM set_excld CHANGING it_excld.
PERFORM alv_displ_out.
* set handler :
* g_event_receiver->handle_double_click for OB_GRID.
CALL METHOD ob_grid->refresh_table_display.
CALL METHOD ob_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
ENDFORM.
FORM set_fieldcat.
REFRESH it_fcatl.
PERFORM alv_field_cat "NOUT ICON NSUM DSUM EDIT
USING :
' XX ' 1 5 'ICONS' '' '' '' '' 'Status' '',
' ' 2 30 'ATNAM' '' '' '' '' 'Characteristic' 'CHAR',
' ' 2 20 'ATBEZ' '' '' '' '' 'Description' 'CHAR',
' ' 2 20 'ATUDF' '' '' '' '' 'Data Type' 'CHAR',
' ' 2 20 'CHARNUMBER' '' '' '' '' 'Number of Char' 'NUMC',
' ' 2 20 'DECPLACES' '' '' '' '' 'Decimal Places' 'NUMC',
' ' 2 20 'MEINS' '' '' '' '' 'Unit of Measure' 'CHAR',
' ' 2 20 'MEINS_ISO' '' '' '' '' 'Unit of Measure ISO' 'CHAR',
' ' 999 30 'SNOTE' '' '' '' '' 'Notes' ''.
ENDFORM.
FORM set_varnt .
CLEAR is_varnt.
is_varnt-report = sy-repid.
is_varnt-username = sy-uname.
ENDFORM.
*----------------------------------------------------------------------*
FORM set_lyout .
CLEAR is_lyout.
is_lyout-zebra = 'X'.
is_lyout-cwidth_opt = 'X'.
is_lyout-no_rowins = 'X'.
is_lyout-stylefname = 'CSTYL'.
is_lyout-info_fname = 'CLINE'.
is_lyout-ctab_fname = 'CCELL'.
ENDFORM.
FORM set_excld CHANGING pt_exclude TYPE ui_functions.
DATA ls_exclude TYPE ui_func.
ls_exclude = cl_gui_alv_grid=>mc_fc_check.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_refresh.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_sum.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_subtot.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_print.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_graph.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_info.
APPEND ls_exclude TO pt_exclude.
ENDFORM.
FORM alv_displ_out.
CALL METHOD ob_grid->set_table_for_first_display
EXPORTING
is_variant = is_varnt "DISVARIANT
i_save = 'A' "CHAR1 - X:Global - U:User - A:All - Space:No
i_default = 'X' "CHAR1 - X:Allowed - Space:not
is_layout = is_lyout "LVC_S_LAYO
is_print = is_print "LVC_S_PRNT
it_toolbar_excluding = it_excld "UI_FUNCTIONS
CHANGING
it_outtab = it_print
it_fieldcatalog = it_fcatl "LVC_T_FCAT
it_sort = it_sort "LVC_T_SORT
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
ENDFORM.
FORM alv_color_set USING p_fld p_col p_int p_inv.
IF it_color IS INITIAL.
MOVE p_fld TO wa_color-fname.
MOVE p_col TO wa_color-color-col.
MOVE p_int TO wa_color-color-int.
MOVE p_inv TO wa_color-color-inv.
APPEND wa_color TO it_color.
wa_print-ccell[] = it_color[].
ELSE.
CLEAR: vi_color, wa_color.
LOOP AT it_color INTO wa_color WHERE fname = p_fld.
vi_color = vi_color + 1.
MOVE p_fld TO wa_color-fname.
MOVE p_col TO wa_color-color-col.
MOVE p_int TO wa_color-color-int.
MOVE p_inv TO wa_color-color-inv.
MODIFY it_color FROM wa_color.
EXIT.
CLEAR wa_color.
ENDLOOP.
IF vi_color IS INITIAL.
MOVE p_fld TO wa_color-fname.
MOVE p_col TO wa_color-color-col.
MOVE p_int TO wa_color-color-int.
MOVE p_inv TO wa_color-color-inv.
APPEND wa_color TO it_color.
ENDIF.
wa_print-ccell[] = it_color[].
ENDIF.
ENDFORM.
*----------------------------------------------------------------------*
FORM alv_field_cat USING p_fset p_cpos p_olen p_fild p_rtab p_rfld p_ftyp p_qcif p_text p_dtype.
CLEAR wa_fcatl.
wa_fcatl-icon = p_fset+1(1).
IF p_olen > 2.
wa_fcatl-outputlen = p_olen. "06
ENDIF.
vs_fcfld = p_fild.
TRANSLATE vs_fcfld TO UPPER CASE.
wa_fcatl-fieldname = vs_fcfld. "07
vs_fcfld = p_rfld.
TRANSLATE vs_fcfld TO UPPER CASE.
wa_fcatl-ref_field = vs_fcfld. "09
vs_fcfld = p_rtab.
TRANSLATE vs_fcfld TO UPPER CASE.
wa_fcatl-ref_table = vs_fcfld. "08
vs_fcfld = p_qcif.
TRANSLATE vs_fcfld TO UPPER CASE.
vi_fclen = strlen( p_text ).
IF vi_fclen > 10.
wa_fcatl-scrtext_l = p_text.
ELSE.
wa_fcatl-scrtext_m = p_text.
wa_fcatl-scrtext_s = p_text.
ENDIF.
wa_fcatl-datatype = p_dtype.
wa_fcatl-col_pos = p_cpos.
APPEND wa_fcatl TO it_fcatl.
ENDFORM.
*& Include ZCREATE_CHAR3
*&---------------------------------------------------------------------*
FORM initial_form.
CHECK ok_code <> 'EXIT'.
IF ob_cust IS INITIAL.
CREATE OBJECT ob_cust
EXPORTING
container_name = 'CONTAINER'.
CREATE OBJECT ob_grid
EXPORTING
i_parent = ob_cust.
* create object g_event_receiver.
ENDIF.
PERFORM set_varnt.
PERFORM set_lyout.
PERFORM set_fieldcat.
PERFORM set_excld CHANGING it_excld.
PERFORM alv_displ_out.
* set handler :
* g_event_receiver->handle_double_click for OB_GRID.
CALL METHOD ob_grid->refresh_table_display.
CALL METHOD ob_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
ENDFORM.
FORM set_fieldcat.
REFRESH it_fcatl.
PERFORM alv_field_cat "NOUT ICON NSUM DSUM EDIT
USING :
' XX ' 1 5 'ICONS' '' '' '' '' 'Status' '',
' ' 2 30 'ATNAM' '' '' '' '' 'Characteristic' 'CHAR',
' ' 2 20 'ATBEZ' '' '' '' '' 'Description' 'CHAR',
' ' 2 20 'ATUDF' '' '' '' '' 'Data Type' 'CHAR',
' ' 2 20 'CHARNUMBER' '' '' '' '' 'Number of Char' 'NUMC',
' ' 2 20 'DECPLACES' '' '' '' '' 'Decimal Places' 'NUMC',
' ' 2 20 'MEINS' '' '' '' '' 'Unit of Measure' 'CHAR',
' ' 2 20 'MEINS_ISO' '' '' '' '' 'Unit of Measure ISO' 'CHAR',
' ' 999 30 'SNOTE' '' '' '' '' 'Notes' ''.
ENDFORM.
FORM set_varnt .
CLEAR is_varnt.
is_varnt-report = sy-repid.
is_varnt-username = sy-uname.
ENDFORM.
*----------------------------------------------------------------------*
FORM set_lyout .
CLEAR is_lyout.
is_lyout-zebra = 'X'.
is_lyout-cwidth_opt = 'X'.
is_lyout-no_rowins = 'X'.
is_lyout-stylefname = 'CSTYL'.
is_lyout-info_fname = 'CLINE'.
is_lyout-ctab_fname = 'CCELL'.
ENDFORM.
FORM set_excld CHANGING pt_exclude TYPE ui_functions.
DATA ls_exclude TYPE ui_func.
ls_exclude = cl_gui_alv_grid=>mc_fc_check.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_refresh.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_sum.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_subtot.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_print.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_graph.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_info.
APPEND ls_exclude TO pt_exclude.
ENDFORM.
FORM alv_displ_out.
CALL METHOD ob_grid->set_table_for_first_display
EXPORTING
is_variant = is_varnt "DISVARIANT
i_save = 'A' "CHAR1 - X:Global - U:User - A:All - Space:No
i_default = 'X' "CHAR1 - X:Allowed - Space:not
is_layout = is_lyout "LVC_S_LAYO
is_print = is_print "LVC_S_PRNT
it_toolbar_excluding = it_excld "UI_FUNCTIONS
CHANGING
it_outtab = it_print
it_fieldcatalog = it_fcatl "LVC_T_FCAT
it_sort = it_sort "LVC_T_SORT
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
ENDFORM.
FORM alv_color_set USING p_fld p_col p_int p_inv.
IF it_color IS INITIAL.
MOVE p_fld TO wa_color-fname.
MOVE p_col TO wa_color-color-col.
MOVE p_int TO wa_color-color-int.
MOVE p_inv TO wa_color-color-inv.
APPEND wa_color TO it_color.
wa_print-ccell[] = it_color[].
ELSE.
CLEAR: vi_color, wa_color.
LOOP AT it_color INTO wa_color WHERE fname = p_fld.
vi_color = vi_color + 1.
MOVE p_fld TO wa_color-fname.
MOVE p_col TO wa_color-color-col.
MOVE p_int TO wa_color-color-int.
MOVE p_inv TO wa_color-color-inv.
MODIFY it_color FROM wa_color.
EXIT.
CLEAR wa_color.
ENDLOOP.
IF vi_color IS INITIAL.
MOVE p_fld TO wa_color-fname.
MOVE p_col TO wa_color-color-col.
MOVE p_int TO wa_color-color-int.
MOVE p_inv TO wa_color-color-inv.
APPEND wa_color TO it_color.
ENDIF.
wa_print-ccell[] = it_color[].
ENDIF.
ENDFORM.
*----------------------------------------------------------------------*
FORM alv_field_cat USING p_fset p_cpos p_olen p_fild p_rtab p_rfld p_ftyp p_qcif p_text p_dtype.
CLEAR wa_fcatl.
wa_fcatl-icon = p_fset+1(1).
IF p_olen > 2.
wa_fcatl-outputlen = p_olen. "06
ENDIF.
vs_fcfld = p_fild.
TRANSLATE vs_fcfld TO UPPER CASE.
wa_fcatl-fieldname = vs_fcfld. "07
vs_fcfld = p_rfld.
TRANSLATE vs_fcfld TO UPPER CASE.
wa_fcatl-ref_field = vs_fcfld. "09
vs_fcfld = p_rtab.
TRANSLATE vs_fcfld TO UPPER CASE.
wa_fcatl-ref_table = vs_fcfld. "08
vs_fcfld = p_qcif.
TRANSLATE vs_fcfld TO UPPER CASE.
vi_fclen = strlen( p_text ).
IF vi_fclen > 10.
wa_fcatl-scrtext_l = p_text.
ELSE.
wa_fcatl-scrtext_m = p_text.
wa_fcatl-scrtext_s = p_text.
ENDIF.
wa_fcatl-datatype = p_dtype.
wa_fcatl-col_pos = p_cpos.
APPEND wa_fcatl TO it_fcatl.
ENDFORM.
Screen Flow Logic
Screen Layout
2. Container
Run Abap
Upload result
Comments
Post a Comment