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: 

Reading filepath from database Table

Former Member
0 Kudos

Dear Experts:-

I have a requirement where I have to upload photo of employee  from a shared server path to SAP IT0002.

Now My problem is i don't want to hard-code the path in the code because client is saying it may change the path later on. How to handle path setup?

what i think is to put the filepath in database table then reading the path from the table.So please how can i do this in abap code????

show me the way.

appreciating your Help.

Best Regards,

HaHu

1 ACCEPTED SOLUTION

venkateswaran_k
Active Contributor
0 Kudos

Hi

Use a Z-table to store the Path

Say  Path value is stored as you specified.

In the initialization  (INITIALIZATION) event of your program

select the value from that ztable and assign that value to the variable SALFILE-LONGNAME

Remove teh default from your program.

DATA: FILEPATH LIKE SALFILE-LONGNAME VALUE 'd:\abaptest\yuri123\'.

Regards,

Venkat

11 REPLIES 11

FredericGirod
Active Contributor
0 Kudos

Hi HaHu,

have a look to the transaction FILE

(you will find a lot of doc about this)

and the function to read the file directory is FILENAME_GET

regards

Fred

0 Kudos

Dear Frederic G,

the code below works for my reqirment but what i want is just by avoiding the hardcode path( 'd:\abaptest\yuri123\'.) and putting the path in a database table then accessing it through code.

am not sure if it is clear for u.
REPORT  YPHOTO_UP.
*
*DATA: BEGIN OF FILETAB OCCURS 1.
*
*        INCLUDE STRUCTURE SALFLDIR.
*
*DATA: END OF FILETAB.
data: filetab like table of SALFLDIR with header line.
DATA: SAPOBJID LIKE SAPB-SAPOBJID,
       SAPPFAD LIKE SAPB-SAPPFAD.

DATA: FILENAME LIKE  SALFLDIR ,
       FILEEXT(10) TYPE C ,
       LEN TYPE I ,
       PICFILENAME TYPE STRING.

DATA: FILEPATH LIKE SALFILE-LONGNAME VALUE 'd:\abaptest\yuri123\'.
DATA WA type zerror1.
*DATA: FILEPATH1 LIKE SALFILE-LONGNAME VALUE 'd:\abaptest\yuri\'.


CALL FUNCTION 'RZL_READ_DIR_LOCAL'
   EXPORTING
     NAME           = FILEPATH
   TABLES
     FILE_TBL       = FILETAB[]
   EXCEPTIONS
     ARGUMENT_ERROR = 1
     NOT_FOUND      = 2
     OTHERS         = 3.

loop at filetab.
     if filetab-name+0(1) ne '.'.

     SPLIT FILETAB-NAME AT '.' INTO FILENAME FILEEXT.
       LEN = STRLEN( FILENAME ) .
       IF LEN <> 8 AND FILEEXT EQ 'jpg' and FILEEXT ne 'db'.

*        or FILEEXT EQ 'jpg'.
*      MESSAGE :  e000(oo) WITH 'Employee id is not correct'.
*        WRITE : / 'Upload fail','Employee id ',FILETAB-NAME+0(8),'is not valid'.
*
*      ELSE.

         WA-error_id = filetab-name.

         WA-error_msg = 'is not valid Employee Id'.
         wa-error_date = SY-DATLO.
         wa-error_time = SY-UZEIT .
modify zerror1 from wa.

*INSERT INTO zerror1 VALUES wa.

else.
         CONCATENATE FILEPATH '\' FILETAB-NAME INTO SAPPFAD.
         CONCATENATE FILETAB-NAME+0(8) '0002' INTO SAPOBJID.

   CALL FUNCTION 'ARCHIV_CREATE_FILE'
     EXPORTING
       AR_OBJECT               = 'HRICOLFOTO'
       OBJECT_ID               = SAPOBJID
       SAP_OBJECT              = 'PREL'
       DOC_TYPE                = 'JPG'
       PATH                    = SAPPFAD
     EXCEPTIONS
       ERROR_CONECTIONTABLE    = 1
       ERROR_PARAMETER         = 2
       ERROR_ARCHIV            = 3
       ERROR_UPLOAD            = 4
       ERROR_KERNEL            = 5
       NO_ENTRY_POSSIBLE       = 6
       ERROR_COMUNICATIONTABLE = 7
       OTHERS                  = 8.
   IF SY-SUBRC <> 0.
     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*    WRITE : / 'Upload ',SAPPFAD,'Employee id ',FILETAB-NAME+0(8),'Successfully'.
   ELSE.
*    WRITE : / 'Upload ',SAPPFAD,'Employee id ',FILETAB-NAME+0(8),'Successfully'.
   ENDIF.
   ENDIF.
*ENDLOOP.
*          DO WHAT EVER YOU WANT HERE
   ENDIF.

   ENDLOOP.

     CALL FUNCTION 'ZDELETE_DIRECTORY_FILES'
       EXPORTING
         DIRFILEPATH       = 'd:\abaptest\yuri123\'.

0 Kudos

Have a look to the documentation of SAPhttp://help.sap.com/saphelp_nw70/helpdata/en/8d/3e4ec2462a11d189000000e8323d3a/content.htm

File will allow you to create a logical directory, and link this logical directory to a physical directory.

example : logical directory sap_dir    physical directory : /usr/sap/

you could add into this variables to change the directory path. for examples you could change for each server

physical directory /home/SID_SYSTEM/usr/sap ...

you need administrator to create the directory

but you could manage the FILE yourself.

regards

Fred

p291102
Active Contributor
0 Kudos

use the transcation code AL11  and use open dataset concept for reading the file from the application server.

Former Member
0 Kudos

Dear Hahu,

My understanding is that you want to upload this photo to the app server in SAP.

If my understanding is correct then you can do it using the Logical Path concept.

Ask you basis consultant to map your folder's physical path to a logical path in FILE transaction.

This is a 2 step process. First they have to create the Logical File Path and then assign that to a physical path. Both steps are performed in 'FILE' only.

You can use a select on 'PATH' Table and get the physical path from the logical file path in your program and use it.

If the location of the folder needs to be changed then the physical path can to be changed in 'FILE' transaction.

0 Kudos

dear Aashrith HG,

No!!!

rather i want to upload photos of employee into SAP IT 0002 from a shared folder.

but currently it works when i give the file directory or path as a hard-code.or as a default that is

DATA: FILEPATH LIKE SALFILE-LONGNAME VALUE 'd:\abaptest\yuri123\'.

but now i want to put the file path(d:\abaptest\yuri123\) in a data base table and then accessing the directory by giving the table field that holds the path.

am not sure if it is clear again???

0 Kudos

Dear Hahu,

Instead of using the below line,


DATA: FILEPATH LIKE SALFILE-LONGNAME VALUE 'd:\abaptest\yuri123\'.

Just get the logical path created and mapped to physical path in 'FILE' transaction.

Example : Logical path : 'zaatest' mapped to physical path 'd:\abaptest\yuri123\'.

Once done,

Use a select on 'PATH' Table using 'zaatest'(logical file path) to get the physical path ('d:\abaptest\yuri123\')  into a variable and then use that variable in your program.

Former Member
0 Kudos

i have the following code.

It works good but by giving the hard-code.

but my requirement is Avoiding the Hard-code path and reading it the path from database table.

REPORT  YPHOTO_UP.
*
*DATA: BEGIN OF FILETAB OCCURS 1.
*
*        INCLUDE STRUCTURE SALFLDIR.
*
*DATA: END OF FILETAB.
data: filetab like table of SALFLDIR with header line.
DATA: SAPOBJID LIKE SAPB-SAPOBJID,
       SAPPFAD LIKE SAPB-SAPPFAD.

DATA: FILENAME LIKE  SALFLDIR ,
       FILEEXT(10) TYPE C ,
       LEN TYPE I ,
       PICFILENAME TYPE STRING.

DATA: FILEPATH LIKE SALFILE-LONGNAME VALUE 'd:\abaptest\yuri123\'.
DATA WA type zerror1.
*DATA: FILEPATH1 LIKE SALFILE-LONGNAME VALUE 'd:\abaptest\yuri\'.


CALL FUNCTION 'RZL_READ_DIR_LOCAL'
   EXPORTING
     NAME           = FILEPATH
   TABLES
     FILE_TBL       = FILETAB[]
   EXCEPTIONS
     ARGUMENT_ERROR = 1
     NOT_FOUND      = 2
     OTHERS         = 3.

loop at filetab.
     if filetab-name+0(1) ne '.'.

     SPLIT FILETAB-NAME AT '.' INTO FILENAME FILEEXT.
       LEN = STRLEN( FILENAME ) .
       IF LEN <> 8 AND FILEEXT EQ 'jpg' and FILEEXT ne 'db'.

*        or FILEEXT EQ 'jpg'.
*      MESSAGE :  e000(oo) WITH 'Employee id is not correct'.
*        WRITE : / 'Upload fail','Employee id ',FILETAB-NAME+0(8),'is not valid'.
*
*      ELSE.

         WA-error_id = filetab-name.

         WA-error_msg = 'is not valid Employee Id'.
         wa-error_date = SY-DATLO.
         wa-error_time = SY-UZEIT .
modify zerror1 from wa.

*INSERT INTO zerror1 VALUES wa.

else.
         CONCATENATE FILEPATH '\' FILETAB-NAME INTO SAPPFAD.
         CONCATENATE FILETAB-NAME+0(8) '0002' INTO SAPOBJID.

   CALL FUNCTION 'ARCHIV_CREATE_FILE'
     EXPORTING
       AR_OBJECT               = 'HRICOLFOTO'
       OBJECT_ID               = SAPOBJID
       SAP_OBJECT              = 'PREL'
       DOC_TYPE                = 'JPG'
       PATH                    = SAPPFAD
     EXCEPTIONS
       ERROR_CONECTIONTABLE    = 1
       ERROR_PARAMETER         = 2
       ERROR_ARCHIV            = 3
       ERROR_UPLOAD            = 4
       ERROR_KERNEL            = 5
       NO_ENTRY_POSSIBLE       = 6
       ERROR_COMUNICATIONTABLE = 7
       OTHERS                  = 8.
   IF SY-SUBRC <> 0.
     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*    WRITE : / 'Upload ',SAPPFAD,'Employee id ',FILETAB-NAME+0(8),'Successfully'.
   ELSE.
*    WRITE : / 'Upload ',SAPPFAD,'Employee id ',FILETAB-NAME+0(8),'Successfully'.
   ENDIF.
   ENDIF.
*ENDLOOP.
*          DO WHAT EVER YOU WANT HERE
   ENDIF.

   ENDLOOP.

     CALL FUNCTION 'ZDELETE_DIRECTORY_FILES'
       EXPORTING
         DIRFILEPATH       = 'd:\abaptest\yuri123\'.

venkateswaran_k
Active Contributor
0 Kudos

Hi

Use a Z-table to store the Path

Say  Path value is stored as you specified.

In the initialization  (INITIALIZATION) event of your program

select the value from that ztable and assign that value to the variable SALFILE-LONGNAME

Remove teh default from your program.

DATA: FILEPATH LIKE SALFILE-LONGNAME VALUE 'd:\abaptest\yuri123\'.

Regards,

Venkat

0 Kudos

thank you Dear Venkateswaran K.

raymond_giuseppi
Active Contributor
0 Kudos

Some solutions

  • z-table
  • data in TVARVC table
  • stored in a program variant
  • mapped thru transaction FILE
  • etc.

Regards,

Raymond