IDOC Mass Upload tool

YRTRR6N_MASS_FORM - Include program for the subroutines

*&---------------------------------------------------------------------*
*&      Form  INITIALIZE
*&---------------------------------------------------------------------*
*      Initialize variables
*----------------------------------------------------------------------*
FORM initialize .
  REFRESH:  t_idoc,
            t_idoc_temp ,
            t_edid4,
            t_edid4_temp,
            t_edid4t,
            t_display,
            t_field_catalog,
            t_fieldcatalogue,
            t_display_t,
            t_display_temp,
            t_edidd,
            t_fieldcat.
  CLEAR:  w_display_t,
          w_edid4t,
          w_edid4,
          w_e1bpacgl09,
          w_idoc,
          w_idoc1,
          w_display,
          w_tabname,
          w_dref,
          fs_line,
          w_dref1,
          fs_line1.
ENDFORM.                    " INITIALIZE
*&---------------------------------------------------------------------*
*&      Form  FETCH_DATA
*&---------------------------------------------------------------------*
*      Fetch the IDOC related data
*----------------------------------------------------------------------*
FORM fetch_process_data.
  DATA: lw_idoc      TYPE type_idoc,
        lw_idoc_temp TYPE type_idoc,                        "#EC NEEDED
        lv_date      TYPE edi_logdat,
        lv_time      TYPE edi_logtim,
        lt_edidc     TYPE STANDARD TABLE OF edidc.
*--Validation
  PERFORM validate_sel_doc.
*--Fetch data from EDIDC table
  SELECT *
    FROM edidc
    INTO TABLE lt_edidc
    WHERE docnum IN s_idocno
    AND   mestyp = p_msg.
  IF lt_edidc IS NOT INITIAL.
*--Fetch IDOC status data from EDIDS table
    SELECT
      docnum
      logdat
      logtim
      credat
      cretim
      status
      repid
      stacod
      statxt
      segnum
      segfld
      stapa1
      stapa2
      stapa3
      stapa4
      stamid
      stamno
      FROM edids
      INTO TABLE t_idoc
      FOR ALL ENTRIES IN lt_edidc
      WHERE docnum = lt_edidc-docnum
      AND status = c_51
      AND status <> c_53.
  ENDIF.
*--Display error message if no data fetched
  IF t_idoc IS INITIAL.
    MESSAGE s033 DISPLAY LIKE c_e.
    LEAVE LIST-PROCESSING.
  ELSE.
    SORT t_idoc BY docnum.
*--Fetch IDOC data records from EDID4 table
    SELECT
      docnum
      segnum
      segnam
      sdata
      FROM edid4
      INTO TABLE t_edid4
      FOR ALL ENTRIES IN t_idoc
      WHERE docnum = t_idoc-docnum.
  ENDIF.
*--Populate segment name as GL Segment
  REFRESH t_edid4t.
  LOOP AT t_edid4 INTO w_edid4.
    IF w_edid4-segnam    = c_e1bpacgl09.
      w_e1bpacgl09       = w_edid4-sdata.
      w_edid4t-docnum    = w_edid4-docnum.
      w_edid4t-segnum    = w_edid4-segnum.
      w_edid4t-segnam    = w_edid4-segnam.
      w_edid4t-stapa1    = w_e1bpacgl09-gl_account.
      w_edid4t-comp_code = w_e1bpacgl09-comp_code.
      APPEND w_edid4t TO t_edid4t.
      CLEAR: w_edid4t,w_edid4.
    ENDIF.
  ENDLOOP.
  SORT t_idoc BY docnum
                 segnum
                 stapa1
                 stapa2
                 stapa3
                 stapa4 DESCENDING.
  t_idoc_temp[] = t_idoc[].
*--Delete duplicated form the table
  DELETE ADJACENT DUPLICATES FROM t_idoc COMPARING   docnum
                                                     segnum
                                                     stapa1
                                                     stapa2
                                                     stapa3
                                                     stapa4.
  SORT t_edid4 BY docnum
                  segnum.
  SORT t_edid4t BY docnum stapa1.
  LOOP AT t_idoc INTO w_idoc.
*--BAPI call to update the interface start message
    PERFORM fill_bapireturn  USING    c_etype
                                      w_idoc-stamid
                                      w_idoc-stamno
                                      w_idoc-stapa1
                                      w_idoc-stapa2
                                      w_idoc-stapa3
                                      w_idoc-stapa4
                                      c_log00.
  ENDLOOP.
ENDFORM.                    " FETCH_DATA
*&---------------------------------------------------------------------*
*&      Form  VALIDATE_SEL_DOC
*&---------------------------------------------------------------------*
*      Validation for Documnet number on sel screen
*----------------------------------------------------------------------*
FORM validate_sel_doc .
  IF s_idocno IS INITIAL.
    MESSAGE i000 WITH text-023 DISPLAY LIKE c_e.
    LEAVE LIST-PROCESSING.
  ENDIF.
ENDFORM.                    " VALIDATE_SEL_DOC
*&---------------------------------------------------------------------*
*&      Form  FILL_BAPIRETURN
*&---------------------------------------------------------------------*
*        Error Message
*----------------------------------------------------------------------*
*     -->RV_MSG_TYPE  Variable for message type
*     -->RV_MSG_ID    Variable for message ID
*     -->RV_MSG_NO    Variable for message NO
*     -->RV_MSG_V1    Variable for message1
*     -->RV_MSG_V2    Variable for message2
*     -->RV_MSG_V3    Variable for message3
*     -->RV_MSG_V4    Variable for message4
*     -->RV_LOGNO     Varible for Log Number
*     <--RT_RETURN    Internal table to fill error log
*----------------------------------------------------------------------*
FORM fill_bapireturn  USING     value(rv_msg_type) TYPE bapi_mtype
                                value(rv_msg_id)   TYPE symsgid
                                value(rv_msg_no)   TYPE symsgno
                                value(rv_msg_v1)   TYPE symsgv
                                value(rv_msg_v2)   TYPE symsgv
                                value(rv_msg_v3)   TYPE symsgv
                                value(rv_msg_v4)   TYPE symsgv
                                value(rv_logno)    TYPE balognr.
*--Local data declaration
  DATA : lw_return TYPE bapiret2,
         lw_idoc_temp TYPE type_idoc,
         lv_length   TYPE i,
         lv_flag   TYPE char1.
  CALL FUNCTION 'BALW_BAPIRETURN_GET2'
    EXPORTING
      type   = rv_msg_type
      cl     = rv_msg_id
      number = rv_msg_no
      par1   = rv_msg_v1
      par2   = rv_msg_v2
      par3   = rv_msg_v3
      par4   = rv_msg_v4
      log_no = rv_logno
    IMPORTING
      return = lw_return.
*--Build the final ALV table to be displayed
  w_display-message     = lw_return-message.
  w_display-field_value = w_idoc-stapa1.
  w_display-docnum      = w_idoc-docnum.
*--Get the segment name and segment number
  READ TABLE t_edid4 INTO w_edid4
  WITH KEY docnum = w_idoc-docnum
           segnum = w_idoc-segnum BINARY SEARCH.
  IF sy-subrc = 0.
    w_display-seg_name =  w_edid4-segnam.
    w_display-segnum   =  w_edid4-segnum.
  ENDIF.
  CLEAR: w_edid4.
*--Populate only those entries which have value in segment field
  LOOP AT t_idoc_temp INTO lw_idoc_temp
    WHERE  stapa1 = w_idoc-stapa1 AND
           stapa2 = w_idoc-stapa2 AND
           stapa3 = w_idoc-stapa3 AND
           stapa4 = w_idoc-stapa4 AND
           segfld NE space.
    w_display-field   = lw_idoc_temp-segfld.
  ENDLOOP.
  w_display-segnum  = w_idoc-segnum.
*--Assign field name as profit center if text field contains profit center
  IF w_idoc-statxt CS c_pc OR w_idoc-stapa2 CS c_pc.
    w_display-field = c_pc1.
*--Assign field name as internal order if text field contains internal order
  ELSEIF w_idoc-statxt CS c_io.
    w_display-field = c_io1.
*--Assign field name as WBS if text field contains WBS element
  ELSEIF w_idoc-statxt CS c_wbs.
    w_display-field = c_wbs1.
*--Assign field name as cost center if text field contains cost center
  ELSEIF w_idoc-statxt CS c_cc.
    w_display-field = c_cc1.
*--Assign field name as gl account if text field contains gl account
  ELSEIF w_idoc-statxt CS c_gl_1.
    w_display-field = c_gl.
  ENDIF.
  IF w_idoc-segnum IS INITIAL.
    LOOP AT t_idoc INTO w_idoc1 WHERE statxt = w_idoc-statxt
                                  AND segnum NE space.
      IF w_idoc1 IS NOT INITIAL.
        lv_flag = c_x.
      ENDIF.
    ENDLOOP.
  ENDIF.
  IF w_idoc-statxt CS c_tt OR w_idoc-statxt CS c_fo.
    IF w_idoc-stapa1 NE c_order.
      IF w_idoc-stapa1+0(1) CA c_0123456789.
*--Add leading zeroes to the Internal order field
        lv_length = STRLEN( w_idoc-stapa1 ).
        lv_length = 10 - lv_length.
        DO lv_length TIMES.
          CONCATENATE c_log00 w_idoc-stapa1 INTO w_idoc-stapa1.
        ENDDO.
        READ TABLE t_edid4t INTO w_edid4t WITH KEY docnum = w_idoc-docnum
                                                   stapa1 = w_idoc-stapa1 BINARY SEARCH.
        IF sy-subrc = 0.
          w_display-seg_name = w_edid4t-segnam.
          w_display-segnum   = w_edid4t-segnum.
        ENDIF.
      ELSEIF ( w_idoc-stapa2 IS NOT INITIAL AND w_idoc-stapa2+0(1) CA c_0123456789 ).
        lv_length = STRLEN( w_idoc-stapa2 ).
        lv_length = 10 - lv_length.
        DO lv_length TIMES.
          CONCATENATE c_log00 w_idoc-stapa2 INTO w_idoc-stapa2.
        ENDDO.
        READ TABLE t_edid4t INTO w_edid4t WITH KEY docnum = w_idoc-docnum
                                                   stapa1 = w_idoc-stapa2 BINARY SEARCH.
        IF sy-subrc = 0.
          w_display-seg_name = w_edid4t-segnam.
          w_display-segnum   = w_edid4t-segnum.
        ENDIF.
      ELSE.
        lv_length = STRLEN( w_idoc-stapa3 ).
        lv_length = 10 - lv_length.
        DO lv_length TIMES.
          CONCATENATE c_log00 w_idoc-stapa3 INTO w_idoc-stapa3.
        ENDDO.
        READ TABLE t_edid4t INTO w_edid4t WITH KEY docnum = w_idoc-docnum
                                                   stapa1 = w_idoc-stapa3 BINARY SEARCH.
        IF sy-subrc = 0.
          w_display-seg_name = w_edid4t-segnam.
          w_display-segnum   = w_edid4t-segnum.
        ENDIF.
      ENDIF.
    ENDIF.
  ELSEIF w_idoc-statxt CS c_bal.
    READ TABLE t_edid4t INTO w_edid4t WITH KEY docnum = w_idoc-docnum
                                               segnum = w_idoc-stapa2. "#EC *
    IF sy-subrc  = 0.
      w_display-seg_name = w_edid4t-segnam.
      w_display-segnum   = w_edid4t-segnum.
    ENDIF.
  ENDIF.
  IF w_display-message NS c_string AND w_display-message NS c_reset
 AND w_display-message NS c_eid    AND w_display-message NS c_save.
    IF lv_flag NE c_x.
*--Append values to the final table
      APPEND w_display TO t_display.
    ENDIF.
  ENDIF.
  CLEAR: w_display ,lw_return.
ENDFORM.                    " FILL_BAPIRETURN
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_OUTPUT_ALV
*&---------------------------------------------------------------------*
*      Display output
*----------------------------------------------------------------------*
FORM prepare_alv .
*--Prepare field Catalog
  PERFORM prepare_field_catalog.
*--Display ALV
  PERFORM display_alv.
ENDFORM.                    " PREPARE_ALV
*&---------------------------------------------------------------------*
*&      Form  PREPARE_FIELD_CATALOG
*&---------------------------------------------------------------------*
*       Preparae field catalog
*----------------------------------------------------------------------*
FORM prepare_field_catalog .
* Local data declarations
  DATA: lw_fieldcat      TYPE slis_fieldcat_alv.
* Prepare catalog
  lw_fieldcat-fieldname = c_box.           " name of field from internal table
  lw_fieldcat-tabname   = c_t_display.     " internal table name
  lw_fieldcat-seltext_m = text-015.
  lw_fieldcat-outputlen = 2.               " output length on screen
  lw_fieldcat-checkbox  = c_x.             " print as checkbox
  lw_fieldcat-edit      = c_x.             " make field open for input
  lw_fieldcat-seltext_l = ' '.             " header information
  APPEND lw_fieldcat TO t_field_catalog.   " append field catalog internal table
  CLEAR lw_fieldcat.
  lw_fieldcat-tabname   = c_t_display.
  lw_fieldcat-fieldname = c_docnum.
  lw_fieldcat-seltext_m = text-009.
  lw_fieldcat-ddictxt   = c_m.
  lw_fieldcat-col_pos   = 1.
  lw_fieldcat-outputlen = 16.
  lw_fieldcat-checkbox  = 1.
  APPEND lw_fieldcat TO t_field_catalog.
  CLEAR lw_fieldcat.
  lw_fieldcat-tabname   = c_t_display.
  lw_fieldcat-fieldname = c_seg_name.
  lw_fieldcat-seltext_m = text-010.
  lw_fieldcat-ddictxt   = c_m.
  lw_fieldcat-col_pos   = 2.
  lw_fieldcat-outputlen = 30.
  APPEND lw_fieldcat TO t_field_catalog.
  CLEAR lw_fieldcat.
  lw_fieldcat-tabname   = c_t_display.
  lw_fieldcat-fieldname = c_segnum.
  lw_fieldcat-seltext_m = text-011.
  lw_fieldcat-ddictxt   = c_m.
  lw_fieldcat-col_pos   = 3.
  lw_fieldcat-outputlen = 6.
  APPEND lw_fieldcat TO t_field_catalog.
  CLEAR lw_fieldcat.
  lw_fieldcat-tabname   = c_t_display.
  lw_fieldcat-fieldname = c_field.
  lw_fieldcat-seltext_m = text-012.
  lw_fieldcat-ddictxt   = c_m.
  lw_fieldcat-col_pos   = 4.
  lw_fieldcat-outputlen = 30.
  APPEND lw_fieldcat TO t_field_catalog.
  CLEAR lw_fieldcat.
  lw_fieldcat-tabname   = c_t_display.
  lw_fieldcat-fieldname = c_message.
  lw_fieldcat-seltext_m = text-013.
  lw_fieldcat-ddictxt   = c_m.
  lw_fieldcat-col_pos   = 5.
  lw_fieldcat-outputlen = 220.
  APPEND lw_fieldcat TO t_field_catalog.
  CLEAR lw_fieldcat.
  lw_fieldcat-tabname   = c_t_display.
  lw_fieldcat-fieldname = c_field_value.
  lw_fieldcat-seltext_m = text-014.
  lw_fieldcat-ddictxt   = c_m.
  lw_fieldcat-col_pos   = 6.
  lw_fieldcat-outputlen = 15.
  APPEND lw_fieldcat TO t_field_catalog.
  CLEAR lw_fieldcat.
ENDFORM.                    " PREPARE_FIELD_CATALOG
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV
*&---------------------------------------------------------------------*
*       Display ALV
*----------------------------------------------------------------------*
FORM display_alv .
*--Data Declarations
  DATA:    lw_layout    TYPE slis_layout_alv,
           lw_events    TYPE slis_alv_event,
           lt_events    TYPE slis_t_event,
           lt_sort      TYPE slis_t_sortinfo_alv,
           lw_sort      TYPE slis_sortinfo_alv,
           lv_msg       TYPE string.
  IF t_display IS NOT INITIAL.
* Set the col width optimise to 'X'.
    lw_layout-colwidth_optimize = c_x.
    lw_layout-window_titlebar   = text-002.
    lw_layout-box_tabname       = c_t_display.
    lw_layout-box_fieldname     = c_box.
    lw_layout-zebra             = c_x.
* Filling Top of page event attributes
    lw_events-name = slis_ev_top_of_list.
    lw_events-form = c_top_of_page.
    APPEND lw_events TO lt_events.
    CLEAR  lw_events.
* Build the sort info table.
    lw_sort-spos      = 1.
    lw_sort-fieldname = c_docnum.
    lw_sort-up        = c_x.
    lw_sort-tabname   = c_t_display.
    APPEND lw_sort TO lt_sort.
    CLEAR : lw_sort.
    lw_sort-spos      = 2.
    lw_sort-fieldname = c_segnum.
    lw_sort-up        = c_x.
    lw_sort-tabname   = c_t_display.
    APPEND lw_sort TO lt_sort.
    CLEAR : lw_sort.
    lw_sort-spos      = 3.
    lw_sort-fieldname = c_seg_name.
    lw_sort-up        = c_x.
    lw_sort-tabname   = c_t_display.
    APPEND lw_sort TO lt_sort.
    CLEAR : lw_sort.
    DELETE t_display WHERE seg_name IS INITIAL.
*--Call the GRID  Display FM to display the output.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
        i_callback_program       = sy-repid
        i_callback_pf_status_set = c_pf_status_set
        i_callback_user_command  = c_user_command
        i_callback_top_of_page   = c_top_of_page
        is_layout                = lw_layout
        it_fieldcat              = t_field_catalog[]
        it_sort                  = lt_sort
        it_events                = lt_events
      TABLES
        t_outtab                 = t_display
      EXCEPTIONS
        program_error            = 1
        OTHERS                   = 2.                       "#EC *
    CLEAR: lw_layout, lt_sort,lt_events.
  ELSE.
    CONCATENATE text-019 text-020 INTO lv_msg SEPARATED BY space.
    MESSAGE lv_msg TYPE c_i.
  ENDIF.
  CLEAR lv_msg.
ENDFORM.                    " DISPLAY_ALV
*&---------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE
*&---------------------------------------------------------------------*
*      Top of page
*----------------------------------------------------------------------*
FORM top_of_page .
*--ALV Header declarations
  DATA: t_header TYPE slis_t_listheader,
        wa_header TYPE slis_listheader.
*--Title
  wa_header-typ  = c_h.
  wa_header-info = text-002.
  APPEND wa_header TO t_header.
  CLEAR wa_header.
*--Date
  wa_header-typ  = c_s.
  wa_header-key = text-003.
  CONCATENATE  sy-datum+6(2) '.'
               sy-datum+4(2) '.'
               sy-datum(4) INTO wa_header-info.   "todays date
  APPEND wa_header TO t_header.
  CLEAR: wa_header.
*--Time
  wa_header-typ  = c_s.
  wa_header-key  = text-004.
  CONCATENATE sy-uzeit+0(2) ':'
              sy-uzeit+2(2) ':'
              sy-uzeit+4(2) INTO wa_header-info.
  APPEND wa_header TO t_header.
  CLEAR: wa_header.
*--User Name
  wa_header-typ  = c_s.
  wa_header-key  = text-005.
  wa_header-info = sy-uname.
  APPEND wa_header TO t_header.
  CLEAR: wa_header.
*--Call the FM to write the header
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = t_header.
ENDFORM.                    " TOP_OF_PAGE
* FORM f01_alv_event_pf_status_set
*---------------------------------------------------------------------
*
*---------------------------------------------------------------------
FORM pf_status_set USING rt_extab TYPE slis_t_extab.        "#EC NEEDED
  SET PF-STATUS c_z_mass_upload.
ENDFORM. "f01_alv_event_pf_status_set
*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
*      Form to capture user command
*----------------------------------------------------------------------*
*      -->R_UCOMM     TYPE sy-ucomm
*      -->RS_SELFIELD TYPE slis_selfield
*----------------------------------------------------------------------*
FORM user_command USING r_ucomm TYPE sy-ucomm
                        rs_selfield TYPE slis_selfield.     "#EC NEEDED
*--Local data Declarations
  DATA : ref_grid               TYPE REF TO cl_gui_alv_grid,
         lv_seg_name            TYPE edi_segnam,
         lv_docnum              TYPE edi_docnum,
         lw_edid4               TYPE type_edid4,
         ls_layout              TYPE  slis_layout_alv,
         l_structure            TYPE REF TO data,
         struc_desc             TYPE REF TO cl_abap_structdescr,
         ls_fieldcatalogue      TYPE slis_fieldcat_alv,
         lw_edid4_temp          TYPE type_edid4_temp,
         lw_layout              TYPE slis_layout_alv,
         lv_msg(100)            TYPE c,
         lt_display_t           TYPE STANDARD TABLE OF type_display,
         lv_tabix               TYPE sy-tabix,
         lw_fieldcat            TYPE slis_fieldcat_alv,
         lt_fieldcat            TYPE slis_t_fieldcat_alv.
*--Field symbols declaration
  FIELD-SYMBOLS :
    <dyn_str>     TYPE ANY,
    <str_comp>    TYPE abap_compdescr.
  IF r_ucomm = c_sall.
    LOOP AT t_display INTO w_display.
      w_display-box = c_x.
      MODIFY t_display INDEX sy-tabix FROM w_display TRANSPORTING box.
      CLEAR: w_display.
    ENDLOOP.
*--Set the col width optimise to 'X'.
    lw_layout-colwidth_optimize = c_x.
    lw_layout-window_titlebar   = text-002.
    lw_layout-box_tabname       = c_t_display.
    lw_layout-box_fieldname     = c_box.
*--Call the GRID  Display FM to display the output.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
        i_callback_program       = sy-repid
        i_callback_pf_status_set = c_pf_status_set
        i_callback_user_command  = c_user_command
        i_callback_top_of_page   = c_top_of_page
        is_layout                = lw_layout
        it_fieldcat              = t_field_catalog[]
      TABLES
        t_outtab                 = t_display
      EXCEPTIONS
        program_error            = 1
        OTHERS                   = 2.                       "#EC *
    LEAVE LIST-PROCESSING.
  ENDIF.
  IF t_display_temp IS NOT INITIAL.
    t_display[] = t_display_temp[].
  ENDIF.
*--Create grid
  IF ref_grid IS INITIAL.
    CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
      IMPORTING
        e_grid = ref_grid.
  ENDIF.
*--Get the changed data from the screen
  IF NOT ref_grid IS INITIAL.
    CALL METHOD ref_grid->check_changed_data.
  ENDIF.
  t_display_temp[] = t_display[].
*--If MASS UPLOAD button is clicked
  IF r_ucomm = c_lfo.
    LOOP AT t_display_temp INTO w_display
      WHERE box = c_x.
      w_display_t        = w_display.
      g_docnum           = w_display-docnum.
      w_display_t-segtyp = w_display-seg_name.
      APPEND w_display_t TO t_display_t.
      lv_docnum   =  w_display-docnum.
      lv_seg_name =  w_display-seg_name.
      CLEAR: w_display_t.
    ENDLOOP.
    CLEAR: lv_seg_name.
    IF t_display_t IS NOT INITIAL.
      lt_display_t[] = t_display_t[].
      SORT lt_display_t[] BY segnum
                             seg_name
                             segtyp.
      DELETE ADJACENT DUPLICATES FROM lt_display_t[] COMPARING segnum
                                                               seg_name
                                                               segtyp.
* IDoc Nummber
      xfc-fieldname = c_docnum.
      xfc-tabname   = c_edidc.
      xfc-datatype  = c_char.
      xfc-inttype   = c_c.
      xfc-intlen    = 16.
      APPEND xfc TO ifc.
* Segment Nummber
      xfc-fieldname = c_segnum.
      xfc-tabname   = c_edidd.
      xfc-datatype  = c_numc.
      xfc-inttype   = c_n.
      xfc-intlen    = 6.
      APPEND xfc TO ifc.
* Segment Name
      xfc-fieldname = c_segnam.
      xfc-tabname   = c_edidd.
      xfc-datatype  = c_char.
      xfc-inttype   = c_c.
      xfc-intlen    = 27.
      APPEND xfc TO ifc.
      REFRESH t_edsappl.
*--Fetch the data from edsappl table based on message type
      SELECT *
        FROM edsappl
        INTO TABLE t_edsappl
        FOR ALL ENTRIES IN lt_display_t
        WHERE segtyp EQ lt_display_t-segtyp.
    ENDIF.
    SORT t_edsappl BY fieldname.
    DELETE ADJACENT DUPLICATES FROM t_edsappl COMPARING fieldname.
*--Populate the field catalogue with message type fetched above
    LOOP AT t_edsappl INTO w_edsappl.
      CLEAR xfc.
      xfc-fieldname = w_edsappl-fieldname.
      xfc-tabname   = w_edsappl-segtyp.
      xfc-datatype  = c_char.
      xfc-inttype   = c_c.
      xfc-intlen    = w_edsappl-expleng.
      APPEND xfc TO ifc.
    ENDLOOP.
    REFRESH tfc.
    tfc[] = ifc[].
*--Prevent dynamic internal table creation from erroring out by doing a adjacent delete on repeating fields
    SORT tfc BY fieldname.
    DELETE ADJACENT DUPLICATES FROM tfc COMPARING fieldname.
    LOOP AT ifc INTO xfc.
      CLEAR lv_tabix.
      lv_tabix = sy-tabix.
      READ TABLE tfc TRANSPORTING NO FIELDS
           WITH KEY fieldname = xfc-fieldname
                    tabname   = xfc-tabname.
      IF sy-subrc NE 0.
        DELETE ifc INDEX lv_tabix.
      ENDIF.
    ENDLOOP.
*--Create dynamic internal table and assign to Field symbol
    CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog = ifc
      IMPORTING
        ep_table        = dy_table.
*--Create dynamic internal table and assign to Field symbol
    CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog = ifc
      IMPORTING
        ep_table        = dy_table1.
    ASSIGN dy_table->* TO <dyn_table>.
    ASSIGN dy_table1->* TO <t_itab_temp>.
* Create dynamic work area and assign to FS
    CREATE DATA dy_line LIKE LINE OF <dyn_table>.
    ASSIGN dy_line->* TO <dyn_wa>.
    CREATE DATA dy_line1 LIKE LINE OF <t_itab_temp>.
    ASSIGN dy_line1->* TO <dyn_wa>.
    SORT t_display_t BY docnum seg_name segnum.
    DELETE ADJACENT DUPLICATES FROM t_display_t COMPARING docnum seg_name segnum.
    LOOP AT t_display_t INTO w_display_t.
*--Create dynamic work area and assign to FS
      CREATE DATA segment_line TYPE (w_display_t-seg_name).
      ASSIGN segment_line->* TO <segment_wa>.
*--Get data from EDIDC table
      READ TABLE t_edid4 INTO lw_edid4
      WITH KEY docnum = w_display_t-docnum
               segnam = w_display_t-seg_name
               segnum = w_display_t-segnum.
      IF sy-subrc = 0.
        lw_edid4_temp-docnum = lw_edid4-docnum.
        lw_edid4_temp-segnum = lw_edid4-segnum.
        lw_edid4_temp-segnam = lw_edid4-segnam.
        lw_edid4_temp-sdata  = lw_edid4-sdata.
        <segment_wa>         = lw_edid4-sdata.
        MOVE-CORRESPONDING lw_edid4 TO <dyn_wa>.
        APPEND lw_edid4_temp TO t_edid4_temp.
        CLEAR: lw_edid4_temp.
      ENDIF.
      CLEAR: w_display_t.
      MOVE-CORRESPONDING <segment_wa> TO  <dyn_wa>.
      APPEND <dyn_wa> TO <dyn_table>.
    ENDLOOP.
*--Populate the field haeder for ALV
    LOOP AT ifc INTO xfc.
      MOVE-CORRESPONDING xfc TO lw_fieldcat.
      MOVE xfc-fieldname TO lw_fieldcat-seltext_l.
      MOVE xfc-fieldname TO lw_fieldcat-seltext_m.
      APPEND lw_fieldcat TO lt_fieldcat.
    ENDLOOP.
    ls_layout-edit              = c_x. " Set ALV as editable
    ls_layout-colwidth_optimize = c_x. " Optimize column width
    SORT <dyn_table>.
    DELETE ADJACENT DUPLICATES FROM <dyn_table> COMPARING ALL FIELDS.
*--Call the GRID  Display FM to display the output.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
        i_callback_program       = sy-repid
        i_callback_pf_status_set = c_pf_status_set1
        i_callback_user_command  = c_user_command1
        i_callback_top_of_page   = c_top_of_page
        it_fieldcat              = lt_fieldcat
        is_layout                = ls_layout
      TABLES
        t_outtab                 = <dyn_table>
      EXCEPTIONS
        program_error            = 1
        OTHERS                   = 2.                       "#EC *
  ELSEIF r_ucomm = c_nfo .
*--If the UPDATE button is clicked display error message
    CONCATENATE text-026 text-021 INTO lv_msg SEPARATED BY space.
    MESSAGE lv_msg TYPE c_e DISPLAY LIKE c_i.
  ENDIF.
  CLEAR lv_msg.
*--Refresh the GRID
  CALL METHOD ref_grid->refresh_table_display.
ENDFORM.                    "user_command
*&---------------------------------------------------------------------*
* FORM f01_alv_event_pf_status_set
*---------------------------------------------------------------------
FORM pf_status_set1 USING rt_extab TYPE slis_t_extab.       "#EC NEEDED
  SET PF-STATUS c_z_mass_upload.
ENDFORM. "f01_alv_event_pf_status_set
*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
*       Capture User Command
*----------------------------------------------------------------------*
*      -->R_UCOMM     TYPE sy-ucomm
*      -->RS_SELFIELD TYPE slis_selfield
*----------------------------------------------------------------------*
FORM user_command1 USING r_ucomm TYPE sy-ucomm
                         rs_selfield TYPE slis_selfield.    "#EC NEEDED
*--Data Declarations
  DATA : ref_grid        TYPE REF TO cl_gui_alv_grid,
         lw_final        TYPE edidd,
         lw_edid4_temp   TYPE type_edid4_temp,
         lv_index        TYPE i VALUE 0,
         io_find(50)     TYPE c,
         io_replace(50)  TYPE c,
         lv_msg(100)     TYPE c,
         lw_sdata        TYPE REF TO data.
  FIELD-SYMBOLS : <w_itab> TYPE ANY,
                  <wa_sdata>.
  IF <t_itab_temp> IS INITIAL.
    <t_itab_temp> = <dyn_table>.
  ENDIF.
*--If the UPDATE button is clicked
  IF r_ucomm = c_nfo.
    IF ref_grid IS INITIAL.
      CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
        IMPORTING
          e_grid = ref_grid.
    ENDIF.
*--Get the changed data from the screen
    IF NOT ref_grid IS INITIAL.
      CALL METHOD ref_grid->check_changed_data.
    ENDIF.
*--Modify EDIDD table with the changed data by the user
    LOOP AT <dyn_table> ASSIGNING <w_itab>.
      lv_index = lv_index + 1.
      READ TABLE t_edid4_temp INTO lw_edid4_temp INDEX lv_index.
      IF sy-subrc = 0 .
*--Function call to open the IDOC for editing
        doc_num = lw_edid4_temp-docnum.
        CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_EDIT'
          EXPORTING
            document_number               = doc_num
            already_open                  = c_n
          TABLES
            idoc_data                     = t_edidd
          EXCEPTIONS
            document_foreign_lock         = 1
            document_not_exist            = 2
            document_not_open             = 3
            status_is_unable_for_changing = 4
            OTHERS                        = 5.
        IF sy-subrc <> 0.                                   "#EC NEEDED
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
        READ TABLE t_edidd TRANSPORTING NO FIELDS
                WITH KEY docnum = lw_edid4_temp-docnum
                         segnam = lw_edid4_temp-segnam      "#EC *
                         segnum = lw_edid4_temp-segnum.
        IF sy-subrc = 0.
* Create dynamic work area and assign to FS
          CREATE DATA lw_sdata TYPE (lw_edid4_temp-segnam).
          ASSIGN lw_sdata->* TO <wa_sdata>.
          MOVE-CORRESPONDING <w_itab> TO <wa_sdata>.
          lw_final-sdata = <wa_sdata>.
          MODIFY t_edidd FROM lw_final TRANSPORTING sdata
                              WHERE segnam = lw_edid4_temp-segnam
                              AND   segnum = lw_edid4_temp-segnum.
        ENDIF.
      ENDIF.
      CLEAR: lw_final,lw_edid4_temp.
*--Save the edited data in the IDOC segment
      PERFORM save_edit_data.
    ENDLOOP.
    CLEAR: lv_index.
*--Display Success message
    MESSAGE i000 WITH text-018.
    CALL SCREEN 1101.
*--Find and Replace
  ELSEIF r_ucomm = c_fnr.
    CALL SCREEN 1100 STARTING AT 10 10.
*--If the MASS UPLOAD button is clicked display error message
  ELSEIF r_ucomm = c_lfo .
    CONCATENATE text-026 text-022 INTO lv_msg SEPARATED BY space.
    MESSAGE lv_msg TYPE c_e DISPLAY LIKE c_i.
  ENDIF.
  CLEAR lv_msg.
ENDFORM.                    "user_command1
*&---------------------------------------------------------------------*
*&      Form  SAVE_EDIT_DATA
*&---------------------------------------------------------------------*
*      Save the edited data by the user
*----------------------------------------------------------------------*
FORM save_edit_data .
*--Local data declarations
  DATA: lv_docnum TYPE edidc-docnum.
*--Function call to update the changes in the IDOC
  CALL FUNCTION 'EDI_CHANGE_DATA_SEGMENTS'
    TABLES
      idoc_changed_data_range = t_edidd.                    "#EC NEEDED
*--Function call to close the IDOC for editing
  CALL FUNCTION 'EDI_DOCUMENT_CLOSE_EDIT'
    EXPORTING
      document_number = doc_num
      do_commit       = c_x
      do_update       = c_x.                                "#EC NEEDED
ENDFORM.                    " SAVE_EDIT_DATA
*&---------------------------------------------------------------------*
*&      Module  STATUS_1100  OUTPUT
*&---------------------------------------------------------------------*
*       PBO for screen 1100
*----------------------------------------------------------------------*
MODULE status_1100 OUTPUT.
  SET PF-STATUS 'STATUS_1100'.
  SET TITLEBAR '1100'.
ENDMODULE.                 " STATUS_1100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_1100  INPUT
*&---------------------------------------------------------------------*
*       PAI for screen 1100
*----------------------------------------------------------------------*
MODULE user_command_1100 INPUT.
  ok_code = sy-ucomm.
*--If user clicks on replace
  IF io_find IS NOT INITIAL.
    IF ok_code = c_repl.
      REPLACE ALL OCCURRENCES OF io_find  IN TABLE <dyn_table> WITH
      io_replace .
      IF ref_grid IS INITIAL.
        CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
          IMPORTING
            e_grid = ref_grid.
      ENDIF.
*--Get the changed data from the screen
      IF NOT ref_grid IS INITIAL.
        CALL METHOD ref_grid->check_changed_data.
      ENDIF.
*--Refresh the table
      CALL METHOD ref_grid->refresh_table_display.
      CLEAR: io_find, io_replace.
      SET SCREEN 0.
      LEAVE SCREEN.
*--If user clicks on cancel
    ELSEIF ok_code = c_canc.
      CLEAR: io_find, io_replace.
      SET SCREEN 0.
      LEAVE SCREEN.
    ENDIF.
  ELSE.
    SET SCREEN 0.
    LEAVE SCREEN.
  ENDIF.
ENDMODULE.                 " USER_COMMAND_1100  INPUT
*&---------------------------------------------------------------------*
*&      Module  STATUS_1101  OUTPUT
*&---------------------------------------------------------------------*
*      PBO for screen 1101
*----------------------------------------------------------------------*
MODULE status_1101 OUTPUT.
  SET PF-STATUS c_z_output.
  SET TITLEBAR c_z01.
*--Data Declarations
  DATA : struc_desc             TYPE REF TO cl_abap_structdescr,
         lw_fieldcatalogue      TYPE lvc_s_fcat,
         lw_edid4_temp          TYPE type_edid4_temp,
         lw_layout              TYPE slis_layout_alv,
         l_structure            TYPE REF TO data,
         ls_layout              TYPE lvc_s_layo,
         lt_fieldcat            TYPE lvc_t_fcat.
*--Field symbols declaration
  FIELD-SYMBOLS :
    <dyn_str>     TYPE ANY,
    <str_comp>    TYPE abap_compdescr.
*--Create container to display Old Values
  CREATE OBJECT g_custom_container
    EXPORTING
      container_name = g_container.
  CREATE OBJECT g_grid
    EXPORTING
      i_parent = g_custom_container.
*--Create container to display New Values
  CREATE OBJECT g_custom_container_new
    EXPORTING
      container_name = g_container_new.
  CREATE OBJECT g_grid_new
    EXPORTING
      i_parent = g_custom_container_new.
  LOOP AT ifc INTO xfc.
    MOVE xfc-fieldname TO xfc-scrtext_l.
    MODIFY ifc FROM xfc TRANSPORTING scrtext_l.
  ENDLOOP.
*--Display ALV for Old Values
  ls_layout-grid_title = text-024. " Old Values
  CALL METHOD g_grid->set_table_for_first_display
    EXPORTING
      is_layout       = ls_layout
    CHANGING
      it_fieldcatalog = ifc
      it_outtab       = <t_itab_temp>.
  CLEAR: ls_layout.
*--Display ALV for New Values
  ls_layout-grid_title = text-025. " New Values
  CALL METHOD g_grid_new->set_table_for_first_display
    EXPORTING
      is_layout       = ls_layout
    CHANGING
      it_fieldcatalog = ifc
      it_outtab       = <dyn_table>.
  REFRESH: <dyn_table>, <t_itab_temp>.
ENDMODULE.                 " STATUS_1101  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_1101  INPUT
*&---------------------------------------------------------------------*
*      PAI for screen 1101
*----------------------------------------------------------------------*
MODULE user_command_1101 INPUT.
  ok_code = sy-ucomm.
*--If user clicks on BACK button
  IF ok_code = c_back.
    SET SCREEN 0.
    LEAVE SCREEN.
  ENDIF.
ENDMODULE.                 " USER_COMMAND_1101  INPUT
*&---------------------------------------------------------------------*
*&      Form  CHECK_AUTHORITY_IDOC
*&---------------------------------------------------------------------*
*       Authorization for IDOC number
*----------------------------------------------------------------------*
FORM check_authority_idoc .
*--Data declaration
  DATA: lt_edidc        TYPE STANDARD TABLE OF edidc,
        lw_edidc        TYPE edidc,
        lv_message(100) TYPE c.
*--Select control data from EDIDC table
  SELECT *
    FROM edidc
    INTO TABLE lt_edidc
    WHERE docnum IN s_idocno.
  LOOP AT lt_edidc INTO lw_edidc.
*--Authorization object
    AUTHORITY-CHECK OBJECT 'S_IDOCMONI'
             ID 'ACTVT'   FIELD c_change
             ID 'EDI_DIR' FIELD c_*
             ID 'EDI_MES' FIELD lw_edidc-mestyp
             ID 'EDI_PRN' FIELD c_*
             ID 'EDI_PRT' FIELD c_*
             ID 'EDI_TCD' DUMMY.
    IF sy-subrc NE 0.
      CONCATENATE text-027 text-028 INTO lv_message.
      MESSAGE e001 WITH lv_message lw_edidc-mestyp.
    ENDIF.
    CLEAR: lw_edidc, lv_message.
  ENDLOOP.
ENDFORM.                    " CHECK_AUTHORITY_IDOC

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image