Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
Introduction:

In this blog post, we’ll come to know that posting and downloading of production versions of material XL Data.

Posting the XL data into SAP was done using a Start immediately Update Function module CM_FV_PROD_VERS_DB_UPDATE from presentation layer and dumping the XL data from SAP into Presentation layer was done using a normal function module GUI_DOWNLOAD.

 

PROCEDURE:

Step 1:

Go to Transaction SE38.

Enter the name of the program and click on create button as shown below.



The below Screen will appear give the program type as executable.

Click on save button





 

Step 2:

Designed a selection screen for Uploading, Downloading and ALV Output Functionalities.



When we Un-Check the Upload check box it will work for download and if we check the check box it will work for upload.

Check Upload Check-Box:



Uncheck Upload Check-Box:          

Value request and help request logic was handled to load the XL data from Presentation layer. Enabling and disabling the Selection screen fields are handled at selection-screen output event.

Step 3:

When the upload check box is Unchecked, data displayed in ALV format for download using REUSE_ALV_GRID_DISPLAY Function module.

Pass the filled field-catalogs, PF Status Event, User-command event to ALV Function module to display the output.



Test Case:

Input:



Execute the report it will display the ALV output.

Output:

In the application tool bar you will find the download button to download data into Presentation layer in XL Format.

Step 4 :

If we press the download button an XL File got downloaded into presentation layer.



Note: Please maintain .XLS at the end of the file name.

Dumped XL Data:



Step 5 :

If checkbox was checked to load the XL data from presentation layer to SAP.

Presentation layer XL Data:

Test Case:

Selection screen :



Execute the report it will update the Production data into SAP.



Function module used to arrange the XL Data is ALSM_EXCEL_TO_INTERNAL_TABLE .



Function module used to update the production vertions data into sap Table MKAL is CM_FV_PROD_VERS_DB_UPDATE in UPDATE TASK Mode.



Step 6 :

Please find the logic to dump and posting the production versions data.

TYPE-POOLS slis.
**-- Types Declaration
TYPES: BEGIN OF ty_mkal,            " internal table as per flat file strucre
werks TYPE mkal-werks,     " Plant
matnr TYPE mkal-matnr,     " Material Number
verid TYPE mkal-verid,     " Production Version
text1 TYPE mkal-text1,     " Short text on the production version
adatu TYPE mkal-adatu,     " Valid-from date of production version
bdatu TYPE mkal-bdatu,     " Run-time end: production version
bstmi TYPE mkal-bstmi,     " Lower value of the lot-size interval
bstma TYPE mkal-bstma,     " Upper value of the lot-size interval
stlal TYPE mkal-stlal,     " Alternative BOM
stlan TYPE mkal-stlan,     " BOM Usage
plnnr TYPE mkal-plnnr,     " Key for Task List Group
alnal TYPE mkal-alnal,     " Group Counter
plnty TYPE mkal-plnty,     " Task List Type
END OF ty_mkal,
BEGIN OF ty_mkal1.
INCLUDE STRUCTURE mkal.

TYPES END OF ty_mkal1.

TYPES : BEGIN OF ty_fname,
fname(20) TYPE c,
END OF ty_fname.

**-- Global Variables
DATA : v1      TYPE mkal-werks,
v2      TYPE mkal-matnr,
lv_file TYPE string,
r_comm  TYPE string,
v_matnr TYPE matnr,
v_werks TYPE werks_d.

**-- Work Areas & Inernal Tables
DATA : it_mkal        TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE,
ls_fieldcat    TYPE slis_fieldcat_alv,
t_fieldcatelog TYPE TABLE OF slis_fieldcat_alv,
it_it_mkal_i   TYPE STANDARD TABLE OF ty_mkal1,
wa_it_mkal_i   LIKE LINE OF it_it_mkal_i,
it_m_aend      TYPE STANDARD TABLE OF mkal_aend WITH HEADER LINE,
it_mkal2       TYPE TABLE OF ty_mkal WITH HEADER LINE,
wa_mkal2       TYPE ty_mkal,
ls_fname       TYPE ty_fname,
lt_fname       TYPE STANDARD TABLE OF ty_fname,
c              TYPE slis_selfield,
a              TYPE slis_t_extab,
it_event       TYPE slis_t_event,
wa_event       LIKE LINE OF it_event.
**-- Selection screen Design
SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE  TEXT-001.
SELECT-OPTIONS :s_plant FOR v1 MODIF ID m1,
s_matnr FOR v2 MODIF ID m1.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS p_upload AS CHECKBOX USER-COMMAND uc DEFAULT 'X'.
SELECTION-SCREEN COMMENT 3(7) TEXT-002.
PARAMETERS p_file TYPE ibipparms-path MODIF ID m2 .
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK a.

AT SELECTION-SCREEN.
SELECT SINGLE matnr
werks FROM mkal
INTO ( v_matnr , v_werks )
WHERE matnr IN s_matnr
AND werks IN s_plant.
IF sy-subrc NE 0.
MESSAGE TEXT-004 TYPE 'E'.
ENDIF.

AT SELECTION-SCREEN OUTPUT.
IF p_upload IS NOT INITIAL.
LOOP AT SCREEN.
IF screen-group1 = 'M1'.
screen-input = 0.
MODIFY SCREEN.
ELSEIF screen-group1 = 'M2'.
screen-input = 1.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ELSE.
LOOP AT SCREEN.
IF screen-group1 = 'M1'.
screen-input = 1.
MODIFY SCREEN.
ELSEIF screen-group1 = 'M2'.
screen-input = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. " f4 help for file input
PERFORM file_help.
*
AT SELECTION-SCREEN ON HELP-REQUEST FOR p_file. " F1 help for file input
MESSAGE 'Please press f4 to upload the file' TYPE 'I'.

START-OF-SELECTION.

IF p_upload IS INITIAL.
IF ( s_plant-low IS NOT INITIAL OR s_plant-high IS NOT INITIAL ) AND
( s_matnr-low IS NOT INITIAL OR s_matnr-high IS NOT INITIAL ).

SELECT matnr
werks
verid
bdatu
adatu
stlal
stlan
plnnr
alnal
text1
bstmi
bstma
plnty FROM mkal INTO CORRESPONDING FIELDS OF TABLE it_mkal2 WHERE werks IN                                                                                                              s_plant AND matnr IN s_matnr.

IF sy-subrc NE 0.
MESSAGE TEXT-003 TYPE 'E'.
ELSE.
*       Filling of Fieldcatalog
ls_fieldcat-col_pos  = 1.
ls_fieldcat-fieldname = 'WERKS'.
ls_fieldcat-tabname = 'IT_MKAL2'.
ls_fieldcat-seltext_m = 'PLANT'.
APPEND ls_fieldcat TO t_fieldcatelog.
ls_fname-fname = ls_fieldcat-seltext_m.
APPEND ls_fname TO lt_fname.
CLEAR: ls_fieldcat,ls_fname.

ls_fieldcat-col_pos  = 2.
ls_fieldcat-fieldname = 'MATNR'.
ls_fieldcat-tabname = 'IT_MKAL2'.
ls_fieldcat-seltext_m = 'MATERIAL'.
APPEND ls_fieldcat TO t_fieldcatelog.
ls_fname-fname = ls_fieldcat-seltext_m .
APPEND ls_fname TO lt_fname.
CLEAR: ls_fieldcat,ls_fname.

ls_fieldcat-col_pos  = 3.
ls_fieldcat-fieldname = 'VERID'.
ls_fieldcat-tabname = 'IT_MKAL2'.
ls_fieldcat-seltext_m = 'VESION ID'.
APPEND ls_fieldcat TO t_fieldcatelog.
ls_fname-fname = ls_fieldcat-seltext_m .
APPEND ls_fname TO lt_fname.
CLEAR: ls_fieldcat,ls_fname.

ls_fieldcat-col_pos  = 4.
ls_fieldcat-fieldname = 'TEXTL'.
ls_fieldcat-tabname = 'IT_MKAL2'.
ls_fieldcat-seltext_m = 'TEXT'.
APPEND ls_fieldcat TO t_fieldcatelog.
ls_fname-fname = ls_fieldcat-seltext_m .
APPEND ls_fname TO lt_fname.
CLEAR: ls_fieldcat,ls_fname.

ls_fieldcat-col_pos  = 5.
ls_fieldcat-fieldname = 'ADATU'.
ls_fieldcat-tabname = 'IT_MKAL2'.
ls_fieldcat-seltext_m = 'VALID FROM'.
APPEND ls_fieldcat TO t_fieldcatelog.
ls_fname-fname = ls_fieldcat-seltext_m .
APPEND ls_fname TO lt_fname.
CLEAR: ls_fieldcat,ls_fname.

ls_fieldcat-col_pos  = 6.
ls_fieldcat-fieldname = 'BDATU'.
ls_fieldcat-tabname = 'IT_MKAL2'.
ls_fieldcat-seltext_m = 'VALID TO'.
APPEND ls_fieldcat TO t_fieldcatelog.
ls_fname-fname =  ls_fieldcat-seltext_m.
APPEND ls_fname TO lt_fname.
CLEAR: ls_fieldcat,ls_fname.

ls_fieldcat-col_pos  = 7.
ls_fieldcat-fieldname = 'BSTMI'.
ls_fieldcat-tabname = 'IT_MKAL2'.
ls_fieldcat-seltext_m = 'LOWER LOT SIZE'.
APPEND ls_fieldcat TO t_fieldcatelog.
ls_fname-fname = ls_fieldcat-seltext_m .
APPEND ls_fname TO lt_fname.
CLEAR: ls_fieldcat,ls_fname.

ls_fieldcat-col_pos  = 8.
ls_fieldcat-fieldname = 'BSTMA'.
ls_fieldcat-tabname = 'IT_MKAL2'.
ls_fieldcat-seltext_m = 'UPPER LOT SIZE'.
APPEND ls_fieldcat TO t_fieldcatelog.
ls_fname-fname = ls_fieldcat-seltext_m .
APPEND ls_fname TO lt_fname.
CLEAR: ls_fieldcat,ls_fname.

ls_fieldcat-col_pos  = 9.
ls_fieldcat-fieldname = 'STLAL'.
ls_fieldcat-tabname = 'IT_MKAL2'.
ls_fieldcat-seltext_m = 'ALT BOM'.
APPEND ls_fieldcat TO t_fieldcatelog.
ls_fname-fname = ls_fieldcat-seltext_m .
APPEND ls_fname TO lt_fname.
CLEAR: ls_fieldcat,ls_fname.

ls_fieldcat-col_pos  = 10.
ls_fieldcat-fieldname = 'STLAN'.
ls_fieldcat-tabname = 'IT_MKAL2'.
ls_fieldcat-seltext_m = 'BOM'.
APPEND ls_fieldcat TO t_fieldcatelog.
ls_fname-fname = ls_fieldcat-seltext_m .
APPEND ls_fname TO lt_fname.
CLEAR: ls_fieldcat,ls_fname.

ls_fieldcat-col_pos  = 11.
ls_fieldcat-fieldname = 'PLNNR'.
ls_fieldcat-tabname = 'IT_MKAL2'.
ls_fieldcat-seltext_m = 'GROUP KEY'.
APPEND ls_fieldcat TO t_fieldcatelog.
ls_fname-fname = ls_fieldcat-seltext_m .
APPEND ls_fname TO lt_fname.
CLEAR: ls_fieldcat,ls_fname.

ls_fieldcat-col_pos  = 12.
ls_fieldcat-fieldname = 'ALNAL'.
ls_fieldcat-tabname = 'IT_MKAL2'.
ls_fieldcat-seltext_m = 'GROUP COUNTER '.
APPEND ls_fieldcat TO t_fieldcatelog.
ls_fname-fname = ls_fieldcat-seltext_m .
APPEND ls_fname TO lt_fname.
CLEAR: ls_fieldcat,ls_fname.

ls_fieldcat-col_pos  = 13.
ls_fieldcat-fieldname = 'PLNTY'.
ls_fieldcat-tabname = 'IT_MKAL2'.
ls_fieldcat-seltext_m = 'TASK LIST TYPE'.
APPEND ls_fieldcat TO t_fieldcatelog.
ls_fname-fname = ls_fieldcat-seltext_m .
APPEND ls_fname TO lt_fname.
CLEAR: ls_fieldcat,ls_fname.

wa_event-name = 'PF_STATUS_SET'.
wa_event-form = 'ZGUI'.

PERFORM zgui USING a.
APPEND wa_event TO it_event.

wa_event-name = 'USER_COMMAND'.
wa_event-form = 'UC'.

PERFORM uc USING sy-ucomm  c.
APPEND wa_event TO it_event.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_structure_name   = 'WA_MKAL'
it_fieldcat        = t_fieldcatelog[]
it_events          = it_event
TABLES
t_outtab           = it_mkal2
EXCEPTIONS
program_error      = 1
OTHERS             = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.                             " SET_PF_STATUS
ENDIF.
ENDIF.

ELSE.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename                = p_file
i_begin_col             = 1
i_begin_row             = 1
i_end_col               = 13
i_end_row               = 99
TABLES
intern                  = it_mkal
EXCEPTIONS
inconsistent_parameters = 1
upload_ole              = 2
OTHERS                  = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
FIELD-SYMBOLS : <fs>.
DATA l_index TYPE i.
IF  it_mkal[] IS INITIAL.
MESSAGE 'No data uploaded!' TYPE 'E'.
EXIT.
ELSE.
SORT  it_mkal BY row col.
LOOP AT it_mkal.
MOVE  it_mkal-col TO l_index.
ASSIGN COMPONENT l_index OF STRUCTURE it_mkal2 TO <fs>.
IF sy-subrc = 0. " Incase there are more xls columns than fields
MOVE it_mkal-value TO <fs>.
ENDIF.
AT END OF row.
APPEND it_mkal2.
CLEAR  it_mkal2.
ENDAT.
ENDLOOP.
ENDIF.

" populate fields of struture and append to itab
LOOP AT it_mkal2.
wa_it_mkal_i-mandt = sy-mandt.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input  = it_mkal2-matnr
IMPORTING
output = it_mkal2-matnr.
MOVE-CORRESPONDING it_mkal2 TO wa_it_mkal_i.
APPEND wa_it_mkal_i TO it_it_mkal_i.
CLEAR : wa_it_mkal_i.
ENDLOOP.

LOOP AT  it_mkal2.
it_m_aend-matnr = it_mkal2-matnr.
it_m_aend-werks = it_mkal2-werks.
it_m_aend-verid = it_mkal2-verid.
it_m_aend-zaehl = '0001'.
APPEND it_m_aend.
CLEAR it_m_aend.
ENDLOOP.

IF it_it_mkal_i IS NOT INITIAL.
CALL FUNCTION 'CM_FV_PROD_VERS_DB_UPDATE' IN UPDATE TASK
TABLES
it_mkal_i = it_it_mkal_i.
COMMIT WORK AND WAIT.
IF sy-subrc EQ 0.
WRITE:2 TEXT-005.
ENDIF.
ENDIF.
ENDIF.

FORM file_help .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name  = syst-cprog
dynpro_number = syst-dynnr
field_name    = 'P_FILE'
IMPORTING
file_name     = p_file.
ENDFORM.                    " FILE_HELP
*&---------------------------------------------------------------------*
*&      Form  ZGUI
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_A  text
*----------------------------------------------------------------------*
FORM zgui  USING    p_a TYPE slis_t_extab.
SET PF-STATUS 'STAT'.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  UC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_SY_UCOMM  text
*      -->P_SLIS_SELFIELD  text
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  UC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_SY_UCOMM  text
*      -->P_C  text
*----------------------------------------------------------------------*
FORM uc  USING   a LIKE sy-ucomm
b TYPE  slis_selfield.

IF a = 'DOWN'.
DATA p_fname TYPE ibipparms-path.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name  = syst-cprog
dynpro_number = syst-dynnr
field_name    = 'P_FNAME'
IMPORTING
file_name     = p_fname.
DATA p_name TYPE string.
p_name = p_fname.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
*       BIN_FILESIZE            =
filename                = p_name
filetype                = 'ASC'
append                  = 'X'
write_field_separator   = 'X'
*       HEADER                  = '00'
*       TRUNC_TRAILING_BLANKS   = ' '
*       WRITE_LF                = 'X'
*       COL_SELECT              = ' '
*       COL_SELECT_MASK         = ' '
*       DAT_MODE                = ' '
*       CONFIRM_OVERWRITE       = ' '
*       NO_AUTH_CHECK           = ' '
*       CODEPAGE                = ' '
*       IGNORE_CERR             = ABAP_TRUE
*       REPLACEMENT             = '#'
*       WRITE_BOM               = ' '
*       TRUNC_TRAILING_BLANKS_EOL       = 'X'
*       WK1_N_FORMAT            = ' '
*       WK1_N_SIZE              = ' '
*       WK1_T_FORMAT            = ' '
*       WK1_T_SIZE              = ' '
*       WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE
*       SHOW_TRANSFER_STATUS    = ABAP_TRUE
*       VIRUS_SCAN_PROFILE      = '/SCET/GUI_DOWNLOAD'
* IMPORTING
*       FILELENGTH              =
TABLES
data_tab                = it_mkal2
fieldnames              = lt_fname
EXCEPTIONS
file_write_error        = 1
no_batch                = 2
gui_refuse_filetransfer = 3
invalid_type            = 4
no_authority            = 5
unknown_error           = 6
header_not_allowed      = 7
separator_not_allowed   = 8
filesize_not_allowed    = 9
header_too_long         = 10
dp_error_create         = 11
dp_error_send           = 12
dp_error_write          = 13
unknown_dp_error        = 14
access_denied           = 15
dp_out_of_memory        = 16
disk_full               = 17
dp_timeout              = 18
file_not_found          = 19
dataprovider_exception  = 20

control_flush_error = 21
OTHERS = 22.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

ENDIF.

ENDFORM.

 

Conclusion:

Using this report we can update Productions Versions of material table data with XL Data using 'CM_FV_PROD_VERS_DB_UPDATE' Function module and download the updated XL Data to Presentation layer.

Thanks for reading.

Hope this post would be helpful.

 
16 Comments
Labels in this area