SAP GOS document download

作者:郑德鼎 约 6 分钟阅读 更新日期:2024-02-22 2 年前更新 标签:工具, 技术
目录

SAP Attachments Mass Extraction for Sales Documents (ABAP)

SAP4TECH » SAP Attachments Mass Extraction for Sales Documents (ABAP)

ABAP TUTORIALS

SAP Attachments Mass Extraction for Sales Documents (ABAP)

July 13, 2015  John

SAP Attachment: The following ABAP program sample is optimized to Mass extraction of SAP Attachments (GOS) for Sales Documents.

SAP Mass Attachments Extraction using ABAP.

The same ABAP Code can be user to mass extract Attachment for

FI Documents

PM Notifications

MM Material

The original post is SAP GOS Attachment Technical

Table of Contents

SAP Attachment : Miscellaneous Tips

Search Help for Directory Selection

The method cl_gui_frontend_services=>directory_browse offers to select a folder from presentation server ( local ).

The result SELECTED_FOLDER is the full path for a local directory.

Check if a file exists on presentation Server

The method cl_gui_frontend_services=>file_exist checks if a file exists locally ( on presentation server).

The result is initial if the file dosn’t exist.

Jump to the new ABAP Programming, check the following book: Mastering SAP ABAP: A complete guide to developing fast, durable, and maintainable ABAP programs in SAP

SAP Functions Modules Used for SAP Attachment

Here the list of the main SAP Function Modules & Methods used below in order to extract and to download Attachment

cl_gui_frontend_services=>directory_browse

This standard Method cl_gui_frontend_services=>directory_browse will retrieve list of local (desktop) folder.

In the most of cases, it is used to select a folder at presentation server as help search for local Directory Search .

cl_gui_frontend_services=>file_exist

This method cl_gui_frontend_services=>file_exist checks if a file exists already .

SO_OBJECT_DOWNLOAD

SO_OBJECT_DOWNLOAD function module will create a file from internal table in SAP to a given pathname.

ABAP Code for SAP Attachment Mass extraction

Let’s start with the Data declaration we need to Extract Attachment

The second step is to define the Select Screen

The last step is the extraction of SAP Attachments

ABAP

Generic export / import GOS attachments of business objects

FollowRSS feedLike

9 Likes 14,843 Views 5 Comments

Sometimes we have to copy legacy data from a SAP system to another one, and some types of data are less easy to copy than some others.

GOS attachments are stored on the SAP system. They can be added/managed from the Generic Object Services (GOS) dropdown menu.

GOS attachments are not so easy to copy. The purpose of this program is to allow the download of attachments from a source SAP sytem into binary files. The selection of attachments is done through the list of Business Objects corresponding to the selection.

Based on the Business Object type (like in transaction SWO1) the program retrieves the corresponding table and proposes a dynamic screen with all fields in this table. The user is able to specify selection parameters for this table.

For each found record in the table, the program checks the list of attachment and for each attachment it creates a binary file. The attributes of the attachment are stored directly into the file name by a concatenation using a special separator.

On the target SAP system, the program allows to upload the files and save them as attachments. The selection is based on the files names, this is a good solution to avoid uploading all files if they are not to be selected. The original file name is extracted from the concatenation.

The program demonstrates several technics

how to handle dynamic selection based on dynamic criteria

how to upload a list of files from a directory

how to read/save GOS attachments

Here is the code and text elements are below

REPORT zbc_gos_export_import LINE-SIZE 180.

*&---------------------------------------------------------------------*

*& REPORT ZBC_GOS_EXPORT_IMPORT

*&---------------------------------------------------------------------*

*& Author : François Henrotte

*&

*& Purpose : This program is used to

*& - extract and export selected attachments to local files

*& - import and create attachments from local files

*&---------------------------------------------------------------------*

• System fields for dynamic selection

INCLUDE rsdbcom4.
INCLUDE rsdbc1xx.
INCLUDE rssocons.

***

• Constants

***

CONSTANTS: gc_separator TYPE char4 VALUE '(&&)', "#EC NOTEXT

gc_sep_lengt TYPE i VALUE 4.

CONSTANTS: gc_def_path TYPE text40 VALUE 'C:\temp\', "#EC NOTEXT

gc_def_file TYPE text40 VALUE 'GOS*.*'. "#EC NOTEXT

***

• Types definition

***

TYPES: BEGIN OF ty_attach,

bor_id TYPE sibfboriid,

filen TYPE string,

bdata TYPE solix_tab,

END OF ty_attach,

tt_attach TYPE TABLE OF ty_attach.

***

• Data definition

***

DATA: wt_keyfields TYPE TABLE OF rpyboke,

ws_keyfields TYPE rpyboke,

w_title TYPE sy-title,

w_key TYPE sibfboriid.

DATA: ws_x030l TYPE x030l.
DATA: w_selid TYPE rsdynsel-selid,

wt_tables TYPE TABLE OF rsdstabs,

ws_tables TYPE rsdstabs,

ws_where TYPE rsds_where,

w_active TYPE i,

w_dbcnt TYPE i.

DATA: ws_varidyn TYPE rsvaridyn.
DATA: wt_attach TYPE tt_attach,

ws_attach TYPE ty_attach,

ws_bdata TYPE solix.

DATA: wt_sfile TYPE TABLE OF eps2fili,

ws_sfile TYPE eps2fili,

wt_files TYPE TABLE OF file_info,

ws_files TYPE file_info,

w_path TYPE string,

w_file TYPE string,

w_mess TYPE string,

w_fileid TYPE string,

w_where TYPE string,

w_index TYPE numc2,

w_count TYPE i.

DATA: ob_table TYPE REF TO data.

FIELD-SYMBOLS: <wt_table> TYPE STANDARD TABLE,

<w_field> TYPE any.

***

• Selection screen

***

SELECTION-SCREEN: BEGIN OF BLOCK obj WITH FRAME TITLE text-obj.
PARAMETERS: p_objtyp TYPE swo_objtyp OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK obj.
SELECTION-SCREEN: BEGIN OF BLOCK b01 WITH FRAME TITLE text-b01.
PARAMETERS: p_exp RADIOBUTTON GROUP pro DEFAULT 'X'.
PARAMETERS: p_imp RADIOBUTTON GROUP pro.
SELECTION-SCREEN: SKIP,

BEGIN OF LINE.

SELECTION-SCREEN: COMMENT (30) seltab FOR FIELD p_table,

POSITION 33.

PARAMETERS: p_table TYPE tabname.
SELECTION-SCREEN: PUSHBUTTON 65(4) selopt USER-COMMAND sel,

COMMENT 71(6) selcnt,

END OF LINE.
SELECTION-SCREEN: END OF BLOCK b01.
SELECTION-SCREEN: BEGIN OF BLOCK b03 WITH FRAME TITLE text-b03.
PARAMETERS: p_locl TYPE xflag AS CHECKBOX.
SELECTION-SCREEN: SKIP.
PARAMETERS: p_path TYPE string VISIBLE LENGTH 80 DEFAULT gc_def_path LOWER CASE,

p_file TYPE string VISIBLE LENGTH 80 DEFAULT gc_def_file LOWER CASE.

SELECTION-SCREEN: END OF BLOCK b03.

***

• Initialization

***

INITIALIZATION.

MOVE '@4G@' TO selopt.

MOVE %_p_table_%_app_%-text TO seltab.

IF sy-slset IS NOT INITIAL.

SUPPRESS DIALOG.

ENDIF.

***

• PBO

***

AT SELECTION-SCREEN OUTPUT.

IF w_active IS INITIAL.

CLEAR: selcnt.

ELSE.

WRITE w_active TO selcnt LEFT-JUSTIFIED.

ENDIF.
LOOP AT SCREEN.
IF screen-name = 'P_TABLE'.

screen-input = 0.

MODIFY SCREEN.
ENDIF.
ENDLOOP.

***

• PAI

***

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_objtyp.

CALL FUNCTION 'RS_HELP_HANDLING'

EXPORTING

dynpfield = 'P_OBJTYP'

dynpname = '1000'

object = 'SOBJ'

progname = 'ZBC_GOS_EXPORT_IMPORT'

suppress_selection_screen = 'X'

variant = 'SAP&STANDARD'

EXCEPTIONS

OTHERS = 0.

AT SELECTION-SCREEN.

IF ws_x030l-tabname IS INITIAL

OR ws_x030l-tabname NE p_table.

PERFORM f_init_table.

ENDIF.
IF w_selid IS INITIAL.

PERFORM f_init_selections.

ENDIF.
IF sy-ucomm = 'SEL'.

• Display free selection dialog

CONCATENATE 'Selection in table'(sit) p_table

INTO w_title SEPARATED BY space.

CALL FUNCTION 'FREE_SELECTIONS_DIALOG'

EXPORTING

selection_id = w_selid

title = w_title

status = 1

as_window = 'X'

IMPORTING

expressions = dyn_sel-texpr

field_ranges = dyn_sel-trange

number_of_active_fields = w_active

TABLES

fields_tab = dyns_fields

EXCEPTIONS

OTHERS = 1.

IF sy-subrc EQ 0.

REFRESH gl_varidyn.

LOOP AT dyns_fields.

MOVE-CORRESPONDING dyns_fields TO ws_varidyn.

APPEND ws_varidyn TO gl_varidyn.
ENDLOOP.
ENDIF.
ENDIF.

***

• Start of selection

***

START-OF-SELECTION.

FORMAT RESET.

CLEAR w_path.

IF p_path(1) = '/'.

w_path = p_path.

IF w_path NP '*/'.

CONCATENATE w_path '/' INTO w_path.

ENDIF.

ELSEIF p_path(1) = '\'.

w_path = p_path.

IF w_path NP '*\'.

CONCATENATE w_path '\' INTO w_path.

ENDIF.

ELSE.

SELECT SINGLE dirname

FROM user_dir

INTO w_path

WHERE aliass = p_path.

IF sy-subrc NE 0.
SELECT SINGLE pathextern

FROM path

INTO w_path

WHERE pathintern EQ p_path

AND filesys EQ sy-opsys.

ENDIF.
IF w_path(1) = '/'.
IF w_path NP '*/'.

CONCATENATE w_path '/' INTO w_path.

ENDIF.

ELSEIF w_path(1) = '\'.

IF w_path NP '*\'.

CONCATENATE w_path '\' INTO w_path.

ENDIF.

ELSEIF w_path IS NOT INITIAL.

MESSAGE e002(rc).

ENDIF.
ENDIF.
IF w_path IS INITIAL.

MESSAGE e024(sg) WITH p_path sy-opsys.

ENDIF.

PERFORM f_create_table USING p_table.

PERFORM f_select_table.

IF p_exp IS NOT INITIAL.
LOOP AT <wt_table> ASSIGNING FIELD-SYMBOL(<ws_struc>).

CLEAR w_key.

LOOP AT wt_keyfields INTO ws_keyfields

WHERE refstruct = p_table.

ASSIGN COMPONENT ws_keyfields-reffield OF STRUCTURE <ws_struc> TO <w_field>.

CHECK sy-subrc = 0.

CONCATENATE w_key <w_field>

INTO w_key RESPECTING BLANKS.

ENDLOOP.

• Retrieve the contents of attachments

PERFORM f_read_attachments USING w_key

CHANGING wt_attach.

CLEAR w_index.

LOOP AT wt_attach INTO ws_attach.

CONCATENATE w_path p_file INTO w_file.

ADD 1 TO w_index.

CONCATENATE '' ws_attach-bor_id w_index ws_attach-filen

INTO w_fileid SEPARATED BY gc_separator.

REPLACE '.*' WITH space INTO w_file.

REPLACE '*' WITH w_fileid INTO w_file.

IF p_locl IS INITIAL.

...

郑德鼎

关于作者:郑德鼎

企业信息化与 SAP 技术顾问,长期专注 SAP ABAP、FI/CO、MM、SD 等模块的技术分享与实战经验总结。查看更多介绍

来源说明:本文内容由「SAP GOS document download.docx」整理生成,仅用于内部技术分享与学习交流。