Application Development and Automation 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: 
Read only

idoc

Former Member
0 Likes
778

Is it posible to transfer data using IDOCs into SAP from:

1. an excel or text file on my presentation server and;

2. a file on my application server.

If posible may you please show how best i can do it

7 REPLIES 7
Read only

Former Member
0 Likes
712

yes u can .....

if u r question is to generate idocs form a flat file form application or presentation server...i can send u the code...

Read only

0 Likes
712

i just need to know how to transfer data from a flat file from either presentation or application server into SAP

Read only

0 Likes
712

Hi Willard,

From Presentatio server,

you just need to use the function module GUI_UPLOAD to upload the data into sap.

From Application Server,

YOu need to use the statemets OPEN DATASET/READ DATASET/CLOSE DATASET to upload the data.

eG:

DATA:

dsn(20) TYPE C VALUE '/usr/test.dat',

rec(80) TYPE C.

OPEN DATASET dsn FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc <> 0.

EXIT.

ENDIF.

READ DATASET dsn INTO rec.

WHILE sy-subrc <> 0.

WRITE / rec. READ DATASET dsn INTO rec.

ENDWHILE.

CLOSE DATASET dsn.

alternatively you can use teh transaction CG3Z and CG3Y for moving data from application server to presentaton and vice versa.

Read only

0 Likes
712

Hello Willard

Function modules GUI_UPLOAD and GUI_DOWNLOAD are obsolete with respect to <b>Unicode</b>. Instead use the corresponding <i>static</i> methods GUI_UPLOAD and GUI_DOWNLOAD of class <b>CL_GUI_FRONTEND_SERVICES</b>.

Regards

Uwe

Read only

Former Member
0 Likes
712

here is the sample code

REPORT Z_NV_ORDERS_251.

TABLES: e1edk01,

e1edk14,

e1edk03,

e1edka1,

e1edk02,

e1edp01,

e1edp19.

PARAMETERS: p_load(01) DEFAULT 'A' OBLIGATORY,

*this isto upload data from the application server

p0_filex LIKE filename-fileextern LOWER CASE

DEFAULT '/PDIS/NAVMAN/INBOX/',

*this is to upload data from presentation layer

p1_filex LIKE RLGRAP-FILENAME,

*logical system

p0_logsy LIKE tbdls-logsys.

PARAMETERS: pi_auart LIKE vbak-auart MEMORY ID aat

DEFAULT 'ZNTA'(aat).

DATA: BEGIN OF sun OCCURS 0,

dummy(600) TYPE c,

END OF sun.

DATA: wa1 like LINE OF sun.

DATA:file type string.

DATA: BEGIN OF protocol OCCURS 0.

INCLUDE STRUCTURE btcxpm.

DATA: END OF protocol.

DATA: name LIKE sxpgcolist-name,

path LIKE sxpgcolist-parameters.

DATA: itab LIKE sun OCCURS 0.

data: begin of stab occurs 0,

f1(10),

f2(35),

f3(10),

f4(18),

f5(10),

f6(10),

f7(10),

f8(10),

f9(10),

f10(10),

end of stab.

data: stab_wa like stab.

DATA: zf_docnum LIKE sy-tfill.

DATA: BEGIN OF it_edidc OCCURS 0,

xx LIKE edi_dc,

END OF it_edidc.

DATA: BEGIN OF it_edidd OCCURS 0,

xx LIKE edi_dd,

END OF it_edidd.

INITIALIZATION.

CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'

IMPORTING

own_logical_system = p0_logsy

EXCEPTIONS

OTHERS = 9.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno

DISPLAY LIKE sy-msgty

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

START-OF-SELECTION.

IF NOT p0_filex IS INITIAL OR

NOT p1_filex IS INITIAL .

IF p_load = 'A'.

PERFORM get_files.

LOOP AT protocol.

CHECK protocol-message CS '.CSV' AND

protocol-message CS 'FTP.TPL'.

IF p0_logsy(3) = 'GP7'.

CONCATENATE path protocol-message+60 INTO p0_filex.

ELSE.

CONCATENATE path protocol-message+58 INTO p0_filex.

ENDIF.

OPEN DATASET p0_filex

FOR INPUT

IN TEXT MODE ENCODING DEFAULT.

if sy-subrc = 0.

do.

READ DATASET p0_filex INTO wa1.

IF sy-subrc <> 0.

EXIT.

ENDIF.

append wa1 to itab.

enddo.

endif.

break garvl55.

close dataset p0_filex.

DELETE DATASET p0_filex.

endloop.

elseif p_load = 'W'.

file = p1_filex.

CALL FUNCTION 'UPLOAD'

EXPORTING

FILENAME = p1_filex

FILETYPE = 'ASC'

TABLES

DATA_TAB = iTAB

EXCEPTIONS

CONVERSION_ERROR = 1

INVALID_TABLE_WIDTH = 2

INVALID_TYPE = 3

NO_BATCH = 4

UNKNOWN_ERROR = 5

GUI_REFUSE_FILETRANSFER = 6

OTHERS = 7.

  • CALL FUNCTION 'GUI_UPLOAD'

  • EXPORTING

  • filename = file

  • filetype = 'CSV'

  • TABLES

  • data_tab = itab

  • 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.

endif.

endif.

loop at itab into wa1.

split wa1 at '|' into stab-f1 stab-f2 stab-f3

stab-f4 stab-f5 stab-f6

stab-f7 stab-f8 stab-f9

stab-f10.

append stab.

endloop.

data: wa like stab.

if stab is not initial.

loop at stab into stab_wa.

if stab_wa-f1 cs 'Pack Num'.

else.

wa = stab_wa.

CLEAR it_edidd.

it_edidd-xx-docnum = zf_docnum.

it_edidd-xx-segnum = '000001'.

at new f1.

PERFORM idoc_control.

CLEAR it_edidd.

it_edidd-xx-docnum = zf_docnum.

it_edidd-xx-segnum = '000001'.

  • creating segement 'E1EDK01'

it_edidd-xx-segnam = 'E1EDK01'.

CLEAR e1edk01.

e1edk01-BSART = 'EDI'.

e1edk01-belnr = stab_wa-f1.

it_edidd-xx-sdata = e1edk01.

APPEND it_edidd.

  • end of segement 'E1EDK01'

*creating segement 'E1EDK014'

it_edidd-xx-segnam = 'E1EDK14'.

CLEAR e1edk14.

e1edk14-qualf = '006'.

e1edk14-orgid = '00'.

it_edidd-xx-sdata = e1edk14.

APPEND it_edidd.

it_edidd-xx-segnam = 'E1EDK14'.

CLEAR e1edk14.

e1edk14-qualf = '007'.

e1edk14-orgid = '01'.

it_edidd-xx-sdata = e1edk14.

APPEND it_edidd.

it_edidd-xx-segnam = 'E1EDK14'.

CLEAR e1edk14.

e1edk14-qualf = '008'.

e1edk14-orgid = '5100'.

it_edidd-xx-sdata = e1edk14.

APPEND it_edidd.

it_edidd-xx-segnam = 'E1EDK14'.

CLEAR e1edk14.

e1edk14-qualf = '012'.

e1edk14-orgid = pi_auart.

it_edidd-xx-sdata = e1edk14.

APPEND it_edidd.

it_edidd-xx-segnam = 'E1EDK14'.

CLEAR e1edk14.

e1edk14-qualf = '019'.

e1edk14-orgid = 'EDI'.

it_edidd-xx-sdata = e1edk14.

APPEND it_edidd.

*end of segement 'E1EDK14'

*creating segement 'E1EDK03'

  • data:date(10) type c.

  • it_edidd-xx-segnam = 'E1EDK03'.

  • clear e1edk03.

  • e1edk03-IDDAT = '002'.

  • concatenate wa-f90(4) wa-f95(2) wa-f9+8(2) into date.

  • e1edk03-datum = date.

  • it_edidd-xx-sdata = e1edk03.

  • APPEND it_edidd.

*end of segement 'E1EDK03'

*creating segement 'E1EDKA1'

data con(15) type c.

it_edidd-xx-segnam = 'E1EDKA1'.

clear e1edka1.

e1edka1-PARVW = 'AG'.

e1edka1-partn = wa-f6.

it_edidd-xx-sdata = e1edka1.

APPEND it_edidd.

it_edidd-xx-segnam = 'E1EDKA1'.

clear e1edka1.

e1edka1-PARVW = 'RE'.

e1edka1-partn = wa-f6.

it_edidd-xx-sdata = e1edka1.

APPEND it_edidd.

it_edidd-xx-segnam = 'E1EDKA1'.

clear e1edka1.

e1edka1-PARVW = 'WE'.

concatenate wa-f6 wa-f7 into con.

e1edka1-partn = con.

it_edidd-xx-sdata = e1edka1.

APPEND it_edidd.

*end of segmant e1edka1.

  • creating segement 'E1EDK02'

it_edidd-xx-segnam = 'E1EDK02'.

clear e1edk02.

e1edk02-qualf = '001'.

e1edk02-belnr = wa-f2.

it_edidd-xx-sdata = e1edk02.

APPEND it_edidd.

endat.

*end os segement E1EDK02

it_edidd-xx-segnam = 'E1EDP01'.

clear e1edp01.

e1edp01-posex = stab_wa-f3.

e1edp01-matnr = stab_wa-f4.

e1edp01-menge = stab_wa-f5.

e1edp01-vprei = stab_wa-f8.

e1edp01-curcy = stab_wa-f9.

it_edidd-xx-sdata = e1edp01.

APPEND it_edidd.

PERFORM e1edp19.

endif.

endloop.

endif.

DESCRIBE TABLE stab LINES zf_docnum.

IF zf_docnum IS INITIAL.

ELSE.

CALL FUNCTION 'INBOUND_IDOC_PROCESS'

TABLES

idoc_control = it_edidc

idoc_data = it_edidd.

ENDIF.

IF sy-subrc <> 0.

ROLLBACK WORK.

MESSAGE i001(00) DISPLAY LIKE 'E'

WITH zf_docnum

' IDoc(s) NICHT verbucht'(nok).

ELSE.

COMMIT WORK AND WAIT.

IF sy-subrc = 0.

MESSAGE i001(00) with ' IDoc(s) verbucht'(aok).

perform delete_files.

ELSE.

MESSAGE i001(00) DISPLAY LIKE 'E'

WITH zf_docnum

' IDoc(s) NICHT verbucht'(nok).

ENDIF.

ENDIF.

end-of-selection.

&----


*& Form idoc_control

&----


FORM idoc_control.

CLEAR it_edidc.

zf_docnum = zf_docnum + 1.

it_edidc-xx-docnum = zf_docnum.

it_edidc-xx-rcvprt = 'LS'.

it_edidc-xx-rcvprn = p0_logsy.

it_edidc-xx-sndprt = 'LS'.

it_edidc-xx-sndprn = p0_logsy.

it_edidc-xx-mestyp = 'ORDERS'.

it_edidc-xx-idoctyp = 'ORDERS05'.

APPEND it_edidc.

ENDFORM. "idoc_control

&----


*& Form e1edp19

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM e1edp19 .

it_edidd-xx-segnam = 'E1EDP19'.

CLEAR e1edp19.

e1edp19-qualf = '002'.

e1edp19-idtnr = stab_wa-f4.

it_edidd-xx-sdata = e1edp19.

APPEND it_edidd.

ENDFORM. " e1edp19

&----


*& Form get_files

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_files .

name = 'ZDIR'.

path = p0_filex.

CALL FUNCTION 'SXPG_CALL_SYSTEM'

EXPORTING

commandname = name

additional_parameters = path

TABLES

exec_protocol = protocol

EXCEPTIONS

no_permission = 1

command_not_found = 2

parameters_too_long = 3

security_risk = 4

wrong_check_call_interface = 5

program_start_error = 6

program_termination_error = 7

x_error = 8

parameter_expected = 9

too_many_parameters = 10

illegal_command = 11

OTHERS = 12.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " get_files

&----


*& Form delete_files

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM delete_files .

name = 'ZARC_NAV_ORD_IN'.

path = p0_filex.

CALL FUNCTION 'SXPG_CALL_SYSTEM'

EXPORTING

COMMANDNAME = name

ADDITIONAL_PARAMETERS = path

  • IMPORTING

  • STATUS =

  • EXITCODE =

TABLES

EXEC_PROTOCOL = protocol

  • EXCEPTIONS

  • NO_PERMISSION = 1

  • COMMAND_NOT_FOUND = 2

  • PARAMETERS_TOO_LONG = 3

  • SECURITY_RISK = 4

  • WRONG_CHECK_CALL_INTERFACE = 5

  • PROGRAM_START_ERROR = 6

  • PROGRAM_TERMINATION_ERROR = 7

  • X_ERROR = 8

  • PARAMETER_EXPECTED = 9

  • TOO_MANY_PARAMETERS = 10

  • ILLEGAL_COMMAND = 11

  • OTHERS = 12

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

path = p0_filex.

ENDFORM. " delete_files

Read only

Former Member
0 Likes
712

Hello,

You can not generate an IDOC from a flat file lying either on presentation/application server. There is a smart work around possible but it is not practical. I can explain you that...First you need to load the files into SAP and need to post them into the system and then can generate IDOCS. But this is abnormal that, when you can post into SAP directly by uploading why do you need to generate an IDOC.

This is the reason why it is not practical. There won't be any situation that you need to generate IDOCS from a flat file. Probably if you need more clarification then do let us know you problem in detail along with the data transfer routes so that we can better advice you.

Regards,

Sunil

Read only

Former Member
0 Likes
712

Hi,

The Idoc data is stored in tables

EDID4

EDIDC

EDIDS

you can read the data from these tables put in an internal table

Use gui_download Fm to download the Idoc data

Thanks

Sunil