Skip to Content
Author's profile photo Former Member

Fetch file from presentation server and execute in “Background”.

Hello Friends,

In this tutorial, I am explaining the concept:–            

Fetch file from presentation server and execute in “Background”.

Program:–

TYPE-POOLS: slis.

flat file structure*****************
TYPES: BEGIN OF ty_data,
          dealer_code
TYPE kunnr,
          plant
TYPE werks,*          text TYPE sgtxt,
          dr_cr_indicator
(2) TYPE c,
          labr_value
TYPE dmbtr,
          claim_mnth
(2) TYPE c,
          claim_yr
(4) TYPE c,
          cr_note_no
(6) TYPE n,
       
END OF ty_data.
DATA : wa_data TYPE ty_data,
       it_data
TYPE TABLE OF ty_data.
DATA : wa_bapi_data TYPE ty_data,
       it_bapi_data
TYPE TABLE OF ty_data.
TYPES: BEGIN OF ty_final,
        claim_mnth
(2) TYPE c,

        claim_yr(4) TYPE c,

        plant TYPE werks

        labr_value TYPE dmbtr,

        cr_note_no(6) TYPE n,
      
END OF ty_final.

***********fetch indexkey table declarion

DATA : exp_data TYPE STANDARD TABLE OF ty_data,
       indxkey
LIKE mcdxsrtfdwa_indx TYPE mcdx.

DATA:it_final TYPE STANDARD TABLE OF ty_final,
      wa_final
TYPE ty_final.
DATAgs_layout TYPE slis_layout_alv,
       gt_fieldcat
TYPE slis_t_fieldcat_alv,
       gt_events
TYPE slis_t_event,
       g_repid
LIKE syrepid,
       ls_fieldcat
TYPE slis_fieldcat_alv,
       w_alv_print
TYPE slis_print_alv.DATA: str.
******************************************************************           SELECTION-SCREEN                  ******************************************************************SELECTION-SCREEN BEGIN OF BLOCK b1  WITH FRAME TITLE text001.SELECTION-SCREEN SKIP 2.PARAMETER p_file TYPE ibipparmspath OBLIGATORY.SELECTION-SCREEN SKIP 2.SELECTION-SCREEN END OF BLOCK b1.
******************************************************************          AT SELECTION-SCREEN                ******************************************************************AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
 
PERFORM file_browse.
 
PERFORM file_upload. ” Files into internal table.
AT SELECTION-SCREEN OUTPUT.
 
DATA: exclude LIKE rsexfcode OCCURS 0 WITH HEADER LINE,
        ls_submit_info
TYPE rssubinfo.
******************************************************************          START-OF-SELECTION                 ******************************************************************START-OF-SELECTION.
 
PERFORM process_data.

  IF it_final[] IS NOT INITIAL.
   
PERFORM alv_display.
   
PERFORM alv_display_fm.
 
ENDIF.

*&———————————————————————**&      Form  FILE_BROWSE*&———————————————————————**       text*———————————————————————-**  –>  p1        text*  <–  p2        text*———————————————————————-*FORM file_browse .
 
CLEAR p_file.
 
CALL FUNCTION ‘F4_FILENAME’
   
IMPORTING
      file_name
= p_file.

ENDFORM.                   

” FILE_BROWSE*&———————————————————————**&     

Form  FILE_UPLOAD*&———————————————————————**       text*———————————————————————-**  –>  p1        text*  <–  p2        text*———————————————————————-*FORM file_upload .
 
DATA ip_file TYPE string.
 
CLEAR ip_file.
 
REFRESH it_data.
  ip_file
= p_file.
 
CALL FUNCTION ‘GUI_UPLOAD’
   
EXPORTING
      filename               
= ip_file
      has_field_separator    
= ‘X’
   
TABLES
      data_tab               
= it_data
   
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.
 
IF sysubrc <> 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
 
ENDIF.

  REFRESH: exp_data.
  exp_data
= it_data.*Index key is group of Report & UserId.
 
CONCATENATE syrepid syuname  INTO indxkey .
 
EXPORT exp_data FROM exp_data
 
TO DATABASE mcdx(zbFROM wa_indx ID indxkey.
ENDFORM.                    “file_upload*&———————————————————————**&      Form  PROCESS_DATA*&———————————————————————**       text*———————————————————————-*FORM process_data .
 
IF sybatch EQ ‘X’.
   
REFRESH it_data.
   
CONCATENATE syrepid syuname  INTO indxkey .
   
IMPORT exp_data = exp_data  FROM DATABASE mcdx(zb) ID indxkey.
    it_data
= exp_data.
 
ENDIF.
 
IF it_data IS NOT INITIAL.
   
LOOP AT it_data INTO wa_data.
    wa_final
claim_mnth = wa_dataclaim_mnth.
    wa_final
claim_yr   wa_dataclaim_yr.
    wa_final
plant      wa_dataplant.
    wa_final
labr_value   wa_datalabr_value.
    wa_final
cr_note_no       = wa_datacr_note_no.
   
APPEND wa_final to it_final.
   
ENDLOOP.
 
ELSE.
   
MESSAGE:‘No entry found’ TYPE ‘E’.
 
ENDIF.ENDFORM.                    ” FILE_UPLOAD*&———————————————————————**&      Form  ALV_DISPLAY*&———————————————————————**       text*———————————————————————-**  –>  p1        text*  <–  p2        text*———————————————————————-*FORM alv_display ” ankita
 
DATA: col_pos TYPE i.
  col_pos
= 0.

  ls_fieldcatfieldname = ‘CLAIM_MNTH’.
  ls_fieldcat
tabname   = ‘IT_FINAL’.
  ls_fieldcat
seltext_l = ‘Credit month’.
  ls_fieldcat
col_pos     = col_pos.

  APPEND ls_fieldcat TO gt_fieldcat.
 
CLEAR ls_fieldcat.
  col_pos
= col_pos + 1.

  ls_fieldcatfieldname = ‘CLAIM_YR’.
  ls_fieldcat
tabname   = ‘IT_FINAL’.
  ls_fieldcat
seltext_l = ‘Credit year’.
  ls_fieldcat
col_pos     = col_pos.

  APPEND ls_fieldcat TO gt_fieldcat.
 
CLEAR ls_fieldcat.
  col_pos
= col_pos + 1.

  ls_fieldcatfieldname = ‘PLANT’.
  ls_fieldcat
tabname   = ‘IT_FINAL’.
  ls_fieldcat
seltext_l = ‘Plant’.
  ls_fieldcat
col_pos     = col_pos.

  APPEND ls_fieldcat TO gt_fieldcat.
 
CLEAR ls_fieldcat.

  ls_fieldcatfieldname = ‘CR_NOTE_NO’.
  ls_fieldcat
tabname   = ‘IT_FINAL’.
  ls_fieldcat
seltext_l = ‘credit Not NO’.
  ls_fieldcat
col_pos     = col_pos.

  APPEND ls_fieldcat TO gt_fieldcat.
 
CLEAR ls_fieldcat.
ENDFORM.                    ” ALV_DISPLAY*&———————————————————————**&      Form  ALV_DISPLAY_FM*&———————————————————————**       text*———————————————————————-**  –>  p1        text*  <–  p2        text*———————————————————————-*FORM alv_display_fm . ” ankita
  g_repid
= syrepid.

  CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
   
EXPORTING
      i_callback_program
= g_repid
      it_fieldcat       
= gt_fieldcat[]
      i_save            
= ‘X’
   
TABLES
      t_outtab          
= it_final[]
   
EXCEPTIONS
      program_error     
= 1
     
OTHERS             = 2.
 
IF sysubrc <> 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
 
ENDIF.
ENDFORM.                    ” ALV_DISPLAY_FM

Assigned tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Thomas Zloch
      Thomas Zloch

      I can only see code (with some "mature" ingredients...), where are you explaining the concept?

      Thomas

      Author's profile photo Matthew Billingham
      Matthew Billingham

      It's hard to read because the formatting needs attention.