How to write ABAP program to trigger PC based on file in application server

In this post, I will detail on how to write an ABAP program which checks for a specific file in the application server and triggers a process chain. If no file is found, it just displays a message and does not do anything.

Once the program is ready, you need to schedule a job with this program which runs in the background every 30 minutes for example to check the file and trigger the PC.

Continue reading “How to write ABAP program to trigger PC based on file in application server”

How to write ABAP program to Merge multiple files in one file in Application server

In some scenarios, it may happen that business has loaded multiple files in a period for sales for example. All these files should be merged into one consolidation file and loaded once to target instead of loading each file separately.

Also the consolidation file will have a standard name which the infopackage can recognize and pick up rather than changing the infopackage to load multiple files with different names.

Continue reading “How to write ABAP program to Merge multiple files in one file in Application server”

How to write a program to move files in application server to an archive folder

Many times after loading the file from the application server to BW targets, we need to move it in a separate folder such as archive folder to avoid  the same file being repeatedly processed. Also the archive folder will serve as a storage for history of all the files that were already loaded.This helps in referencing them at a later point in time if required.

Continue reading “How to write a program to move files in application server to an archive folder”

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.

Continue reading “How to write infopackage program to pick up a certain file from the application server”

Sample ABAP program for Updating notepad file data to Internal table and Sending it to Application server

*--Structure type

TYPES: BEGIN OF TY_STD,

RONO TYPE C LENGTH 4,

NAME1 TYPE C LENGTH 20,

GEN TYPE C LENGTH 6,

FEES TYPE C LENGTH 10.

END OF TY_STD.




*--Header line and internal table

DATA WKA TYPE TY_STD.

DATA INT_TAB TYPE TABLE OF TY_STD.

*--Application server files are known as "Datasets"

*--here "fname" is the Dataset

DATA FNAME TYPE C LENGTH 40 VALUE "StudentsInfo.txt".

*--Convert notepad file data into internal table

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'C:\Documents and Settings\Administrator\Desktop\students.txt'

HAS FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = INT_TAB.

*--Sending data to Application Server

OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

LOOP AT INT_TAB INTO WKA.

TRANSFER WKA TO FNAME.

ENDLOOP.

CLOSE DATASET FNAME.

Sample ABAP program to create random data in a notepad file

Below is the program in ABAP to prepare a question paper with 20 questions on Arithmetic operations on two numbers.

The program will generate numbers and arithmetic operations randomly.

The program will save these random questions in a .txt file on the local system.

REPORT.

*--Structure type

TYPES: BEGIN OF TYP_NUM,

N1 TYPE I,

OP TYPE C,

N2 TYPE I,

CH TYPE C,

END OF TYP_NUM.

DATA OPT TYPE I.

DATA WA TYPE TYP_NUM.

DATA ITAB TYPE TABLE OF TYP_NUM.

DO 20 TIMES.

CALL FUNCTION 'RANDOM_I4'

EXPORTING

RND_MIN = 10

RND_MAX = 90

IMPORTING

RND_VALUE = WA-N1.

CALL FUNCTION 'RANDOM_I4'

EXPORTING

RND_MIN = 10

RND_MAX = 90

IMPORTING

RND_VALUE = WA-N2.

CALL FUNCTION 'RANDOM_I4'

EXPORTING

RND_MIN = 1

RND_MAX = 4

IMPORTING

RND_VALUE = OPT.

CASE OPT.

WHEN 1.

WA-OP = '+'.

WHEN 2.

WA-OP = '-'.

WHEN 3.

WA-OP = 'x'.

WHEN 4.

WA-OP = '/'.

ENDCASE.

WA-CH = '='.

APPEND WA TO ITAB.

CLEAR WA.

ENDDO.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = 'c:/ques_paper.txt'

TABLES

DATA_TAB = ITAB.