REPORT zhr_position_update .
TYPES : BEGIN OF ty_final ,
pl_ver TYPE string,
pos_no TYPE string,
begda TYPE char10,
endda TYPE char10,
cty_grp TYPE string,
ps_typ TYPE string,
ps_area TYPE string,
esg TYPE string,
ps_grp TYPE string,
ps_lvl TYPE string,
END OF ty_final .
TYPES : BEGIN OF ty_Msg ,
pos_no TYPE string,
begda TYPE char10,
endda TYPE char10,
wsrule TYPE char4,
END OF ty_msg.
TYPES : BEGIN OF ty_msg_n ,
s_no TYPE I ,
pos_no TYPE string,
type TYPE char40,
message TYPE t100-text,
END OF ty_msg_n .
TYPES : BEGIN OF ty_str .
INCLUDE STRUCTURE bdcmsgcoll .
TYPES : pos_no TYPE string,
END OF ty_str .
DATA : gt_msg TYPE TABLE OF ty_msg_n,
gs_msg TYPE ty_msg_n.
DATA :gt_fieldcat TYPE slis_t_fieldcat_alv,
gt_listheader TYPE slis_t_listheader,
gt_alv_event TYPE slis_t_event,
gt_sort TYPE slis_t_sortinfo_alv,
gs_fieldcat TYPE slis_fieldcat_alv,
gs_listheader TYPE slis_listheader,
gs_alv_event LIKE LINE OF gt_alv_event,
gs_layout TYPE slis_layout_alv,
gs_sort TYPE slis_sortinfo_alv.
DATA : gt_final TYPE TABLE OF ty_final,
gs_final TYPE ty_final.
DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
DATA : v_file TYPE rlgrap-filename .
DATA : it_tab TYPE STANDARD TABLE OF alsmex_tabline,
wa_tab TYPE alsmex_tabline,LV_dATE TYPE CHAR10 .
DATA mode TYPE c.
DATA : GS_HRP1005 TYPE HRP1005,s_no TYPE I .
DATA it_msg TYPE STANDARD TABLE OF ty_str WITH HEADER LINE .
SELECTION-SCREEN : BEGIN OF BLOCK b WITH FRAME TITLE text-001 .
PARAMETERS : p_file LIKE rlgrap-filename .
SELECTION-SCREEN : END OF BLOCK b .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
START-OF-SELECTION.
MODE = 'N' .
PERFORM get_excel .
PERFORM bdc .
PERFORM fieldcat .
PERFORM display .
FORM get_excel .
v_file = p_file.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = v_file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '256'
i_end_row = '65536'
TABLES
intern = it_tab
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
* IMPLEMENT SUITABLE ERROR HANDLING HERE
ENDIF.
IF it_tab[] IS NOT INITIAL .
LOOP AT it_tab INTO wa_tab .
CASE wa_tab-col .
WHEN '0001' .
gs_final-pl_ver = wa_tab-value .
WHEN '0002' .
gs_final-pos_no = wa_tab-value .
WHEN '0003' .
gs_final-begda = wa_tab-value .
WHEN '0004' .
gs_final-endda = wa_tab-value .
WHEN '0005' .
gs_final-cty_grp = wa_tab-value .
WHEN '0006' .
gs_final-ps_typ = wa_tab-value .
WHEN '0007' .
gs_final-ps_area = wa_tab-value .
WHEN '0008' .
gs_final-esg = wa_tab-value .
WHEN '0009' .
gs_final-ps_grp = wa_tab-value .
WHEN '0010' .
gs_final-ps_lvl = wa_tab-value .
ENDCASE .
AT END OF row .
APPEND gs_final TO gt_final.
ENDAT .
CLEAR : wa_tab .
ENDLOOP .
ENDIF .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form BDC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM bdc .
IF gt_final[] IS NOT INITIAL .
LOOP AT gt_final INTO gs_final .
CLEAR : LV_dATE .
*CLEAR : PPHDR , PM0D1 .
s_no = s_no + 1 .
SELECT SINGLE * FROM HRP1005 INTO GS_HRP1005 WHERE OBJID = GS_FINAL-POS_NO .
IF SY-SUBRC EQ 0 .
GS_MSG-S_NO = S_NO .
gs_msg-pos_no = gs_final-pos_no .
gs_msg-type = 'E' ." it_msg_temp-msgtyp .
gs_msg-message = 'Position Alreadily Exist' ." w_textout.
APPEND gs_msg TO gt_msg .
CLEAR : GS_MSG .
CONTINUE .
ELSE .
ENDIF .
perform bdc_dynpro using 'SAPMH5A0' '5100'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'PPHDR-PLVAR'
'01'.
perform bdc_field using 'PM0D1-SEARK'
GS_FINAL-POS_NO."'50000705'.
perform bdc_field using 'BDC_CURSOR'
'PPHDR-ENDDA'.
perform bdc_field using 'PM0D1-TIMR6'
'X'.
perform bdc_field using 'PPHDR-BEGDA'
GS_FINAL-BEGDA."'01.01.2000'.
perform bdc_field using 'PPHDR-ENDDA'
GS_FINAL-ENDDA."'31.12.9999'.
perform bdc_dynpro using 'SAPMH5A0' '5100'.
perform bdc_field using 'BDC_OKCODE'
'=INSE'.
perform bdc_field using 'PPHDR-PLVAR'
'01'.
perform bdc_field using 'PM0D1-SEARK'
GS_fINAL-POS_NO."'50000705'.
perform bdc_field using 'BDC_CURSOR'
'TT_T777T-ITEXT(05)'.
perform bdc_field using 'PM0D1-TIMR6'
'X'.
perform bdc_field using 'PPHDR-BEGDA'
GS_FINAL-BEGDA."'01.01.2000'.
perform bdc_field using 'PPHDR-ENDDA'
GS_FINAL-ENDDA."'31.12.9999'.
perform bdc_field using 'MARKFELD(05)'
'X'.
perform bdc_dynpro using 'MP100500' '2000'.
perform bdc_field using 'BDC_CURSOR'
'P1005-BEGDA'.
perform bdc_field using 'BDC_OKCODE'
'=TRF'.
perform bdc_field using 'P1005-BEGDA'
GS_FINAL-BEGDA."'01.01.2000'.
perform bdc_field using 'P1005-ENDDA'
GS_FINAL-ENDDA."'31.12.9999'.
perform bdc_dynpro using 'MP100500' '2000'.
perform bdc_field using 'BDC_OKCODE'
'=UPD'.
perform bdc_field using 'P1005-BEGDA'
GS_FINAL-BEGDA."'01.01.2000'.
perform bdc_field using 'P1005-ENDDA'
GS_FINAL-ENDDA."'31.12.9999'.
perform bdc_field using 'BDC_CURSOR'
'Q1005-INDDA'.
perform bdc_field using 'Q1005-MOLGA'
GS_FINAL-cty_grp."'40'.
perform bdc_field using 'Q1005-TRFAR'
GS_FINAL-PS_TYP."."'22'.
perform bdc_field using 'Q1005-TRFGB'
GS_FINAL-ps_area."'CA'.
perform bdc_field using 'Q1005-TRFKZ'
GS_fINAL-ESG."'3'.
perform bdc_field using 'Q1005-TRFG1'
GS_fINAL-PS_GRP."'A2'.
perform bdc_field using 'Q1005-TRFS1'
GS_fINAL-PS_LVL.":'01'.
CONCATENATE SY-DATUM+6(2) '.' SY-DATUM+4(2) '.' SY-DATUM+0(4) INTO LV_DATE .
perform bdc_field using 'Q1005-INDDA'
LV_DATE."'12.09.2015'.
perform bdc_dynpro using 'SAPMH5A0' '5100'.
perform bdc_field using 'BDC_OKCODE'
'=BACK'.
perform bdc_field using 'PPHDR-PLVAR'
'01'.
perform bdc_field using 'PM0D1-SEARK'
GS_fINAL-POS_NO."'50000705'.
CALL TRANSACTION 'PO13' USING bdcdata
MODE mode
UPDATE 'N'
MESSAGES INTO it_msg . .
CLEAR : BDCDATA[] .
IF sy-subrc EQ 0 .
GS_MSG-S_NO = S_NO .
gs_msg-pos_no = gs_final-pos_no.
gs_msg-type = 'S' ."it_msg_temp-msgtyp .
gs_msg-message = 'Position Created Successfully' . "w_textout.
APPEND gs_msg TO gt_msg .
CLEAR : gs_msg .
ELSE .
GS_MSG-S_NO = S_NO .
gs_msg-pos_no = it_msg-pos_no.
gs_msg-type = 'E' ." it_msg_temp-msgtyp .
gs_msg-message = 'Position Not Created' ." w_textout.
APPEND gs_msg TO gt_msg .
CLEAR : gs_msg .
ENDIF .
CLEAR : gs_final .
ENDLOOP .
ENDIF .
ENDFORM.
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
ENDFORM.
FORM bdc_field USING fnam fval.
* IF FVAL <> NODATA.
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
APPEND bdcdata.
* ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
* I_BACKGROUND_ID = 'ALV_BACKGROUND'
* I_CALLBACK_USER_COMMAND = 'USER_COMMAND_LINE'
i_grid_title = 'Postion Upload to PO13 T Code'
it_fieldcat = gt_fieldcat
is_layout = gs_layout
* I_DEFAULT = 'X'
* I_SAVE = 'X'
* IT_EVENTS = GT_ALV_EVENT
TABLES
t_outtab = gt_msg.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fieldcat .
PERFORM build_layout USING '1' 'S_NO' 'GT_MSG' 'Serial Number' .
PERFORM build_layout USING '2' 'POS_NO' 'GT_MSG' 'Employee Number' .
PERFORM build_layout USING '3' 'TYPE' 'GT_MSG' 'Message Type'.
PERFORM build_layout USING '4' 'MESSAGE' 'GT_MSG' 'Message'.
gs_layout-colwidth_optimize = 'X' .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0612 text
* -->P_0613 text
* -->P_0614 text
* -->P_0615 text
*----------------------------------------------------------------------*
FORM build_layout USING VALUE(p_0612)
VALUE(p_0613)
VALUE(p_0614)
VALUE(p_0615).
gs_fieldcat-col_pos = p_0612.
gs_fieldcat-fieldname = p_0613.
gs_fieldcat-tabname = p_0614.
gs_fieldcat-reptext_ddic = p_0615.
APPEND gs_fieldcat TO gt_fieldcat .
CLEAR : gs_fieldcat.
ENDFORM.
No comments:
Post a Comment