Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

problem while uploading ztable

Former Member
0 Kudos

Hi all,

i have a flat file at appl server and now i my requirement is ,i have to update the content into ztable which is not having all the fields which are thr in the file, file is saperated by # or |.

need help to do this.

thanks

sameera

7 REPLIES 7

Former Member
0 Kudos

Hi Sameer,

U can use the function module GUI_UPLOAD and for the separator thers a parameter in the FM : HAS_FIELD_SEPARATOR, here u can mention which separator u r using.

Hope this hels u.

Regards,

Ramya

Former Member
0 Kudos

HI,

this is a sample program. Check this out.

report z_aru_banks1.

----


*TABLES

----


***My Ztable

tables: zcust_master2.

----


*INTERNAL TABLES

----


data: begin of itab1 occurs 0,

zcustid like zcust_master2-zcustid,

zcustname like zcust_master2-zcustname,

zaddr like zcust_master2-zaddr,

zcity like zcust_master2-zcity,

zstate like zcust_master2-zstate,

zcountry like zcust_master2-zcountry,

zphone like zcust_master2-zphone,

zemail like zcust_master2-zemail,

zfax like zcust_master2-zfax,

zstat like zcust_master2-zstat,

end of itab1.

----


*DATA DECLARATION

----


data: str(1000).

data : sr_dir type dxfields-longpath

value 'E:\usr\sap\ECC\SYS\gen\dbg'. "Application Server path

data: file1 like dxfields-longpath.

----


*CONSTANTS DECLARATION

----


constants: con_tab value cl_abap_char_utilities=>horizontal_tab.

----


*CALLING FUNCTION MODULE 'F4_DXFILENAME_TOPRECURSION'

----


***F4 help for application Server File

call function 'F4_DXFILENAME_TOPRECURSION'

exporting

i_location_flag = 'A'

i_server = ''

i_path = sr_dir

filemask = '.'

fileoperation = 'R'

importing

o_path = file1

exceptions

rfc_error = 1

error_with_gui = 2

others = 3

.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

----


*OPEN DATASET

----


open dataset file1 for input in text mode encoding default.

do.

read dataset file1 into str.

if sy-subrc ne 0.

exit.

else.

split str at con_tab into itab1-zcustid itab1-zcustname itab1-zaddr itab1-zcity itab1-zstate itab1-zcountry

itab1-zphone itab1-zemail itab1-zfax itab1-zstat.

append itab1.

insert zcust_master2 from itab1. "uploading data into ztable

endif.

enddo.

----


*CLOSE DATASET

----


close dataset file1.

Thanks and regards,

Arunsri

Former Member
0 Kudos

Hi!

you can use OPEN DATA SET and GUI_UPLOAD syntax to your program. Hope this will help you!

Cheers,

Mark

Former Member
0 Kudos

Hi ,

Follow the below mentioned procedure and you have to use open data set and close data set.


 OPEN DATASET (Path name ) FOR INPUT  IN TEXT MODE  ENCODING  DEFAULT .  
IF SY-SUBRC <> 0.
  GIVE A ERROR MESSAGE As you required
The above piece of code will check whether the directory in the application server exists or not.

after checking the existence of the path.

  DO.
    READ DATASET (Path name) INTO (Internal table)
    IF SY-SUBRC NE 0.
      CLOSE DATASET (Path name).
      EXIT.
    ENDIF.
    APPEND (Internal table).
  ENDDO.

The things what i have marked with bracket are your specific path name internal table name..while implementing in your give ur appropriate table name and path name with out brackets.

moving data's into internal table

If you look at the file the data's would be organised under some naming conventions like 'ERT' 'TRY' and so..

So for this u can do like this
    LOOP AT INTERNAL TABLE.
      CASE INTERNAL TABLE(3).
        WHEN 'ERT'.
          PERFORM ERT_DATA_MOVE.
        WHEN 'TRY'.
          PERFORM TRY_DATA_MOVE.
      ENDCASE.
    ENDLOOP.
  So based upon ur requirement you can format the contents in the internal table.

Thanks and Regards,

Arun Joseph

Former Member
0 Kudos

Hi Sameera,

You can try the following.

OPEN DATASET f_name FOR INPUT IN TEXT MODE ENCODING DEFAULT.

  • f_name is your file name on application server

DO.

READ DATASET f_name INTO w_data1.

  • read the contents of your file into string type variable 'w_data1'

IF sy-subrc NE 0.

EXIT.

ENDIF.

SPLIT w_data1 AT w_char INTO fs_bkpf-bukrs

fs_bkpf-gjahr

fs_bkpf-blart

fs_bkpf-bldat

fs_bkpf-budat

fs_bkpf-monat

fs_bkpf-cpudt.

  • Split the moved data at the field seperator 'w_char'. In your case # . Move them into a field string which has the same structure of you file.

APPEND fs_bkpf TO t_bkpf.

  • append this into a table

ENDDO.

CLOSE DATASET f_name.

Hope this helps you.

Regards,

Chandra Sekhar

Former Member
0 Kudos

hi

ur flat file structure and internal table structure must be same.

better if possible make another flat file from existing one which will have all fields that ur z-table have. and upload it to intenal table and then WRITE INSERT /UPDATE query to update z-table from ITAB.

OR

define ITAB with same structure as ur FLAT FILE have -


> Then uploade data to internal TABLE -


> then USE ASSIGNMENT OPERATOR for fields u want to update in Z-TABLE .

it may help u .

reward if helpful.

Former Member
0 Kudos

Hi,

Use this statement to open a application server file.Here p_inpfile is the file name of application server.

OPEN DATASET p_inpfile FOR INPUT IN TEXT MODE ENCODING DEFAULT.

DO.

CLEAR : wf_string,fs_0315.

*This statement is used to read the flat file fields**

READ DATASET p_inpfile INTO wf_string.

IF sy-subrc NE 0.

EXIT.

ELSE.

CLEAR fs_0315.

**here is the solution for your pblm. it will replace all the occurances of # with null string**

REPLACE ALL OCCURRENCES OF '#' IN wf_string WITH ' '.

*Here u r splitting those string fields and placed in to a internal table*

SPLIT wf_string AT c_htab INTO fs_0315-begda

fs_0315-endda

fs_0315-pernr

fs_0315-lifnr

fs_0315-ebeln

fs_0315-ebelp

fs_0315-zzkonnr

fs_0315-zzndebi.

APPEND fs_0315 TO int_0315.

ENDIF.

ENDDO.

Hope it will solve your pblm.

Regards,

Sakthi