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 - SFTP path

rangerlet_mesee
Participant
0 Likes
2,399

We need to place the IDOC file generated (preferably in XML format) into an SFTP path without PI/XI interface involved. Can someone brief on the steps involved for this ?

We need to place the IDOC file generated (preferably in XML format) into an SFTP path without PI/XI interface involved. Can someone brief on the steps involved for this ?

3 REPLIES 3
Read only

thkolz
Contributor
0 Likes
2,276

Run WE21 Create XML file port

Run WE20 to create Partner Profile

Please note that in my example we use a Z message type for INVOIC02, but you can also use the standard message type for that.

Read only

thkolz
Contributor
2,276

Sorry, just saw now that you want to transfer the file to an SFTP server.
This I haven't done so far, but I'd propose you to use a ABAP-PI port with a custom function module (see screenshot).

The function module should look like this:

FUNCTION zbp_send_to_ods .
*"----------------------------------------------------------------------
*"*"Local Interface:
*" TABLES
*" I_EDIDC STRUCTURE EDIDC
*"----------------------------------------------------------------------

*--------------------------------------------------------------------*
* COPY from FM template OWN_FUNCTION
*--------------------------------------------------------------------*

TABLES: edidc.

DATA: BEGIN OF i_edidd OCCURS 0.
INCLUDE STRUCTURE edidd.
DATA: END OF i_edidd.

DATA: error(1).



LOOP AT i_edidc.

CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_PROCESS'
EXPORTING
* DB_READ_OPTION = DB_READ
document_number = i_edidc-docnum
* ENQUEUE_OPTION = SYNCHRONOUS
IMPORTING
idoc_control = edidc
EXCEPTIONS
document_foreign_lock = 1
document_not_exist = 2
document_number_invalid = 3
document_is_already_open = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

CLEAR i_edidd.
REFRESH i_edidd.

CALL FUNCTION 'EDI_SEGMENTS_GET_ALL'
EXPORTING
document_number = i_edidc-docnum
TABLES
idoc_containers = i_edidd
EXCEPTIONS
document_number_invalid = 1
end_of_document = 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.

error = 'N'.
* Verarbeitungsschritt und error auf 'Y' für Fehler


*--------------------------------------------------------------------*
* -> OWN LOGIC!
*--------------------------------------------------------------------*
* Send IDoc to ODS
*--------------------------------------------------------------------*

DATA(v_success) = zcl_bp_idoc_enhance=>send_idoc_to_ods(
EXPORTING
i_mestyp = edidc-mestyp
i_idoc = i_edidc-docnum " IDoc number
i_action = v_action
).

IF v_success EQ abap_true.
error = 'N'.
ELSE.
error = 'Y'.
ENDIF.
*--------------------------------------------------------------------*
* <- OWN LOGIC!
*--------------------------------------------------------------------*

* Status schreiben positiv für error = 'N', negativ für error = 'Y'
CLEAR edi_ds.
edi_ds-docnum = i_edidc-docnum.
edi_ds-tabnam = 'EDI_DS'.
edi_ds-logdat = sy-datum.
edi_ds-logtim = sy-uzeit.
edi_ds-repid = 'ZBP_SEND_TO_ODS'. "Modified!
IF error = 'Y'.
edi_ds-status = '20'.
edi_ds-stamqu = 'SAP'.
* edi_ds-stamid = Fehlernummern-ID
* edi_ds-stamno = Fehlernummer
* edi_ds-stapa1 = 1. Parameter
* edi_ds-stapa2 = 2. Parameter
* edi_ds-stapa3 = 3. Parameter
* edi_ds-stapa4 = 4. Parameter

CALL FUNCTION 'EDI_DOCUMENT_STATUS_SET'
EXPORTING
document_number = i_edidc-docnum
idoc_status = edi_ds
* IMPORTING
* IDOC_CONTROL =
EXCEPTIONS
document_number_invalid = 1
other_fields_invalid = 2
status_invalid = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'IDOC_ERROR_WORKFLOW_START'
EXPORTING
docnum = i_edidc-docnum
eventcode = 'EDIO'
* MESS = ' '
EXCEPTIONS
no_entry_in_tede5 = 1
error_in_start_workflow = 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.
ELSE.
edi_ds-status = '18'.
edi_ds-stamqu = 'SAP'.
* edi_ds-stamid = Fehlernummern-ID
* edi_ds-stamno = Fehlernummer
* edi_ds-stapa1 = 1. Parameter
* edi_ds-stapa2 = 2. Parameter
* edi_ds-stapa3 = 3. Parameter
* edi_ds-stapa4 = 4. Parameter

CALL FUNCTION 'EDI_DOCUMENT_STATUS_SET'
EXPORTING
document_number = i_edidc-docnum
idoc_status = edi_ds
* IMPORTING
* IDOC_CONTROL =
EXCEPTIONS
document_number_invalid = 1
other_fields_invalid = 2
status_invalid = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.

CALL FUNCTION 'EDI_DOCUMENT_CLOSE_PROCESS'
EXPORTING
document_number = i_edidc-docnum
* BACKGROUND = NO_BACKGROUND
* NO_DEQUEUE = ' '
* IMPORTING
* IDOC_CONTROL =
EXCEPTIONS
document_not_open = 1
failure_in_db_write = 2
parameter_error = 3
status_set_missing = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

ENDLOOP.
ENDFUNCTION.
Read only

Sandra_Rossi
Active Contributor
0 Likes
2,276

The answer is easier to read if you embed the screenshot in the middle of the text, instead of a hyperlink at the (far) bottom.