How to write infopackage program to pick up a certain file from the application server
We can write a program in the infopackage in BW to pick up a certain file based on its name from the application server and load it. This is required if there are multiple files in the same folder and only a certain file needs to be loaded out of those.
Suppose we have a scenario like this: Business uploads the files for multiple sales division in a folder in the application server – /usr/SAP/DEV/Reports/target_sales.csv.
The file is taget_sales.csv loaded in csv format in the folder /usr/SAP/DEV/Reports on the server of the BW System with system id “DEV”
Create a file data source and give the fields in order as they appear in the file
Define info objects if needed and include in the data source. Save and activate the data source.
Create infopackage, in the extraction tab, Select Adapter as “Load Text-Type file From Application Server”
Leave other settings as default and select the “Change routine icon” as shown by pen mark in the picture
Give a name to your routine and press enter.
Write your program as shown below, leave the default code as it is-
changing p_filename type RSFILENM p_subrc like sy-subrc. *$*$ begin of routine - insert your code only below this line *-* * This routine will be called by the adapter, * when the infopackage is executed. DATA z_filename TYPE rsfilenm. DATA: zdate LIKE sy-datum. zdate = sy-datum. IF sy-sysid EQ 'DEV'. z_filename = '/usr/SAP/DEV/Reports/target_sales.csv'. ENDIF. CONCATENATE z_filename sy-datum '.csv' INTO z_filename. "concatenate step will store the file with name concatenated with system date p_filename = z_filename. *.... P_SUBRC = 0. *$*$ end of routine - insert your code only before this line *-* endform.
Check and Save the program.
Note: Here the file will be saved after processing in the same folder with system date concatenated to its name
If this program needs to be transported to QA and PROD, you can include below code also in the IF statement to include those-
IF sy-sysid EQ 'QA' z_filename = '/usr/SAP/QA/Reports/target_sales.csv'. IF sy-sysid EQ 'PROD' z_filename = '/usr/SAP/PROD/Reports/target_sales.csv'.
Here QA and PROD denote your system ids for test and production systems respectively.
Note that the folder path also changes in QA and PROD.
Request your client’s unix team to create the folders in the systems or ask your client to do so.
Come out of the infopackage and check if the program is reading the file or not by clicking on the “specs” icon shown in picture before.
It should show the file contents.
If it throws error like:
“error in opening the file” etc.
Check whether the file is having correct name, correct format. Also check if all the authorizations are provided for the folder and the file. Authorization part needs to be confirmed by the unix team.