Google

OOPS IN ABAP

(Advanced Business Application Programming) is a programming language for developing applications for the SAP R/3 system, a widely-installed business application subsystem. The latest version, ABAP Objects, is object-oriented programming. SAP will run applications written using ABAP/4, the earlier ABAP version, as well as applications using ABAP Objects. SAP's original business model for R/3 was developed before the idea of an object-oriented model was widespread. The transition to the object-oriented model reflects an increased customer demand for it. ABAP Objects uses a single inheritance model and full support for object features such as encapsulation, polymorphism, and persistence.

ABAP OBJECTS- OOPS

Object Orientation
A programming technique in which solutions reflect real world objects.Object-oriented techniques have been used exclusively in system design. The ABAP language did not support these techniques earlier.The Object Orientation (OO), also known as the object-oriented paradigm, is a programming model that unites data and functions in objects. Moreover, we should know that the object-oriented enhancement of ABAP is based on the models of Java and C++. It is compatible with external object interfaces such as DCOM and CORBA. The implementation of object-oriented elements in the kernel of the ABAP language has considerably increased response times when you work with ABAP Objects. Some other objects, such as SAP Business Objects and GUI objects, which are already object-oriented by themselves, are also benefiting from being incorporated into ABAP Objects.
What are objects?
An object is an instantiation of a class. E.g. If “Animal” is a class, A cat can be an object of that class. With respect to code, Object refers to a set of services (methods/attributes) and can contain data.
Advantages of Object Orientated approach

  1. Easier to understand when the system is complex
  2. Easy to make changes

what are classes?

A class defines the properties of an object. A class can be instantiated as many number of times.
The classes are templates for objects. An abstract description of an object is the class. You could say it is a set of instructions for building an object. The attributes of objects are defined by the components of the class, which describe the state and behavior of objects.

Classes in abap

Classes in ABAP are either local or global

  1. Global classes are declared in class builder (SE24 )
  2. Local classes are declared within programs
Components of a class
Attributes : The attributes are internal data fields that can have any ABAP data type within a class. The state of an object is determined by the contents of its attributes. One kind of attribute is the reference variable. The reference variables are also very important as they allow you to create and address objects. Reference variables can be defined in classes, which allow you to access objects from within a class.
Attributes can be either instance attributes – specific to each instance of the class ( object ) or static attributes which are common to all instances
Instance Attributes:
The instance-specific state of an object is defined by the contents of instance attributes. They can be declared by using the DATA statement.
Static Attributes:
The contents of static attributes define the state of the class that is valid for all instances of the class. The static attributes exist once for each class. It is declared using the CLASSDATA statement. They are accessible for the entire runtime of the class. All of the objects in a class can access its static attributes. If you change a static attribute in an object, then the change is visible in all other objects of the class.

Methods :The methods are internal procedures that define the behavior of an object in a class. They can access all the attributes of a class. This allows them to change the data content of an object. They also have a "parameter interface," whose role is to help the users by supplying them with values when calling them and receiving values back from them. The private attributes of a class can only be changed by methods in the same class. The definition and parameter interface of a method is similar to that of function modules.
Methods can also be instance methods or static methods
Instance Method
You can declare instance methods by using the METHODS statement. They play a very important role as they can access all of the attributes of a class and can trigger all of the events of the class.
Static Methods
You can declare static methods by using the CLASS-METHODS statement. They are important and can only access static attributes and trigger static events.
Special Methods
Apart from normal methods, there are two special methods which you call using CALL METHOD. These are called CONSTRUCTOR and CLASS _CONSTRUCTOR. They are automatically called when you create an object (Constructor) or when you first access the components of a class (CLASS _CONSTRUCTOR).

Events
Objects or classes can use events to trigger event handler methods in other objects or classes. One method can be called by any number of users in a normal method call. When an event is triggered, any number of event handler methods can be called. Until runtime, the link between the trigger and the handler is not established. The calling program determines the methods that it wants to call in a normal Method call and it must exist. With events, the handler determines the events to which it wants to react. It is not necessary that for every event there has to be a handler method registered.With the help of RAISE EVENT statement, the events of a class can be triggered in the methods of the same class. You can declare a method of the same or a different class as an event handler method for the event of class by using the addition FOR EVENT OF . Events have a similar parameter interface to methods, but only have output parameters. These parameters are passed by the trigger (RAISE EVENT statement) to the event handler method, which receives them as input parameters.Using the SET HANDLER statement, the link between trigger and handler is established dynamically in a program. The trigger and handlers can be objects or classes, depending on whether you have instance or static events and event handler methods. When an event is triggered, the corresponding event handler methods are executed in all registered handling classes.

Encapsulation:
Encapsulation is obtained through the restriction in visibility of attributes / methods attained through the definition of Public, Private and Protected section of a class.
You should take great care in designing the public components and try to declare as few public components as possible when you define a class. Once you have released the class, the public components of global classes may not be changed.Public attributes are visible externally and form a part of the interface between an object and its users. If you want to encapsulate the state of an object fully, then you cannot declare any public attributes. Apart from defining the visibility of an attribute, you can also protect it from changes using the READ-ONLY addition.
Public Section
All of the components declared in the public section are accessible to all users of the class, and to the methods of the class and any classes that inherit from it. The public components of the class form the interface between the class and its users.
Protected Section
All of the components declared in the protected section are accessible to all methods of the class and of classes that inherit from it.
Private Section
Components that you declare in the private section are only visible in the methods of the same class.

Inheritance:Inheritance allows you to derive a class based on an already existing class.
It is done by using the INHERITING FROM addition in the statement:CLASS DEFINITION INHERITING FROM All of the components of the existing class are inherited by the new class . The new class is called the subclass of the class from which it is derived. The original class is called the superclass of the new class. It contains the same components as the superclass if you do not add any new declarations to the subclass. However, in the subclass only the public and protected components of the superclass are visible. The private components of the superclass are not visible though they exist in the subclass. You can declare private components in a subclass that have the same names as private components of the superclass. It is seen that each class works with its own private components. The another point that we note is that methods which a subclass inherits from a superclass use the private attributes of the superclass and not any private components of the subclass with the same names.The subclass is an exact replica of the superclass if the superclass does not have any private visibility section. However, you can add a new component to the subclass because it allows you to turn the subclass into a specialized version of the superclass. If a subclass is itself the superclass of further classes, then you can introduce a new level of specialization.

CLASS DEFINITION INHERITING FROM .
…..
ENDCLASS.
CLASS IMPLEMENTATION.
……
ENDCLASS.

All attributes / methods of super class become the property of the subclass too. Only public and protected attributes / methods are visible in the subclass.

Polymorphism: Identically named methods behave differently in different classes. Polymorphism and inheritance lead to code reuse. when methods with same name perform differently under different circumstances we call it polymorphism.

  • Methods redefined in a subclass is an example for Polymorphism.

Reference variables are defined with reference to a superclass or an interface defined with reference to it can also contain references to any of its subclasses. A reference variable defined with reference to a superclass or an interface implemented by a superclass can contain references to instances of any of its subclasses, since subclasses contain all of the components of all of their superclasses and also convey that the interfaces of methods cannot be changed. In particular, you can define the target variable with reference to the generic class OBJECT.Using the CREATE OBJECT statement, when you create an object and a reference variable typed with reference to a subclass then you can use the TY PE addition to which the reference in the reference variable will point.A reference variable can be used by a static user to address the components visible to it in the superclass to which the reference variable refers. However, any specialization implemented in the subclass cannot be addressed by it.Depending on the position in the inheritance tree at which the referenced object occurs, you can use a single reference variable to call different implementations of the method. This is possible only if you redefine an instance method in one or more subclasses. This concept is called polymorphism, in which different classes can have the same interface and, therefore, be addressed using reference variables with a single type.

Interfaces:
Interfaces are used to define the model of a class.
They also like classes can be either local or global.
Global interfaces are defined through SE24 and local interfaces are defined in program.

BDC TO BAPI

BDC to BAPI
The steps to be followed are :
1. Find out the relevant BAPI (BAPI_SALESORDER_CHANGE for VA02).
[for VA01 use BAPI_SALESORDER_CREATEFROMDAT2]
2. Create a Z program and call the BAPi (same as a Funtion module call).
2. Now, if you see this BAPi, it has
-> Importing structures.
eg: SALESDOCUMENT: this will take the Sales order header data as input.
-> Tables parameters:
eg: ORDER_ITEM_IN: this will take the line item data as input.

Note :
Only specify fields that should be changed
Select these fields by entering an X in the checkboxes
Enter a U in the UPDATEFLAG field
Always specify key fields when changing the data, including in the checkboxes
The configuration is an exception here. If this needs to be changed, you need to complete it again fully.
Maintain quantities and dates in the schedule line data
Possible UPDATEFLAGS:
U = change
D = delete
I = add
Example
1. Delete the whole order
2. Delete order items
3. Change the order
4. Change the configuration

Notes
1. Minimum entry:
You must enter the order number in the SALESDOCUMENT structure.
You must always enter key fields for changes.
You must always specify the update indicator in the ORDER_HEADER_INX.

2. Commit control:
The BAPI does not run a database Commit, which means that the application must trigger the Commit so that the changes are read to the database. To do this, use the BAPI_TRANSACTION_COMMIT BAPI.

For further details... refer to the Function Module documentation for the BAPi.

SAMPLE EXAMPLE FOR BAPI

Example Code

U need to give the step_nr, item_nr, cond_count and cond_type so the correct conditon will be updated. If no condition exists for the given parameters, a new condition will be created.
U can find these parameters for a particular condition type in table KONV.


*&---------------------------------------------------------------------*
*& Form saveTransactionJOCR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM saveTransactionJOCR .
data: salesdocument like BAPIVBELN-VBELN,
order_header_inx like bapisdh1x,
order_header_in like bapisdh1,
return type standard table of bapiret2 with header line,
conditions_in type standard table of bapicond with header line,
conditions_inx type standard table of bapicondx with header line,
logic_switch like BAPISDLS,
step_nr like conditions_in-cond_st_no,
item_nr like conditions_in-itm_number,
cond_count like conditions_in-cond_count,
cond_type like conditions_in-cond_type.

salesdocument = wa_order_information-VBELN.

LOGIC_SWITCH-COND_HANDL = 'X'.

order_header_inx-updateflag = 'U'.

* conditions
clear conditions_in[].
clear conditions_inx[].

clear: step_nr,
item_nr,
cond_count,
cond_type.
step_nr = '710'.
item_nr = '000000'.
cond_count = '01'.
cond_type = 'ZCP2'.

CONDITIONS_IN-ITM_NUMBER = item_nr.
conditions_in-cond_st_no = step_nr.
CONDITIONS_IN-COND_COUNT = cond_count.
CONDITIONS_IN-COND_TYPE = cond_type.
CONDITIONS_IN-COND_VALUE = 666.
CONDITIONS_IN-CURRENCY = 'EUR'.

append conditions_in.

CONDITIONS_INX-ITM_NUMBER = item_nr.
conditions_inx-cond_st_no = step_nr.
CONDITIONS_INX-COND_COUNT = cond_count.
CONDITIONS_INX-COND_TYPE = cond_type.
CONDITIONS_INX-UPDATEFLAG = 'U'.
CONDITIONS_INX-COND_VALUE = 'X'.
CONDITIONS_INX-CURRENCY = 'X'.

append conditions_inx.


CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
SALESDOCUMENT = salesdocument
ORDER_HEADER_IN = order_header_in
ORDER_HEADER_INX = order_header_inx
LOGIC_SWITCH = logic_switch
TABLES
RETURN = return
CONDITIONS_IN = conditions_in
CONDITIONS_INX = conditions_inx
.

if return-type ne 'E'.
commit work and wait.
endif.


ENDFORM. " saveTransactionJOCR

BOR

Business Object Repository ( B O R )
SAP's Business Object Repository gives you an improved way to integrate business processes with external partners -- an increasingly necessary ability in the burgeoning e-marketplace economy.
The age of e has had a profound effect on the IT industry. Not only has it changed our way of life, but it has also forced systems such as SAP to embrace a new era of openness. Marketplace demands for flexible automation of inter-business workflow and intelligent data exchange have forced formerly very proprietary ERP systems to begin helping customers integrate with other companies and with e-marketplaces data formats. For the first time, companies must expose their business processes to the outside world.
In order to achieve this openness, SAP provides a technical infrastructure for the R/3 product, the Business Object Repository (BOR), which provides a simple yet powerful mechanism for external systems to trigger core business processes (such as placing an order) without concern for the underlying data structure. This level of abstraction is beneficial because it decouples R/3 from the external system. Either system is therefore free to change its internal business processes without affecting the other. SAP provides this technical infrastructure using a component-based view of its system. Each component or object provides a view of the data and the business processes that interact with that data. External systems can access this data via BAPI methods, which in turn access the underlying data structures of the system. It is the responsibility of the object and the BAPI to ensure the integrity of the data. This encapsulation of the data not only lends itself to external interfaces, but by using objects from within SAP, you can greatly reduce implementation, testing, and maintenance effort via the promotion of code reuse.
Business Objects
A business object is a problem-domain entity that you model in the SAP system, such as SalesOrder, BillingDocument, and Employee. The BOR stores all the objects in the R/3 system. The repository is a group of all the objects in the R/3 system. If the focus of objects is to model atomic business processes then it can be said that the BOR provides an enterprisewide view of business processes. By designing your ABAP code to fit your business processes you increase the ability of that code to flex when those processes are altered or integrated with external systems. This had made the object-oriented approach, which the BOR provides, essential to developing inter-business or e-business functionality.
Attributes
A business object is primarily represented by its attributes. You perform actions, such as create, update, or delete on the attributes by calling the methods of the object.

Attribute NetValue of Object BUS2032 (SalesOrder).

The majority of attributes are data-dictionary fields (for example, the NetValue attribute is defined by VBAK-NETWR). When you access an attribute of an object, you execute a SQL statement that retrieves the corresponding field in the database.

Definition of attribute NetValue.

You can also define attributes that do not exist in the data dictionary. These attributes are called virtual attributes. For example, a business partner has an attribute called BirthDate that is stored in the data dictionary. You can add a virtual attribute to the BusinessPartner object called Age. The age of a business partner is not stored in the database, but you can calculate it using the current date and the birth date of the business partner. If you implement the ABAP code that calculates Age, every time you access the Age attribute, the code executes and returns the business partners age.

Definition of virtual attribute Age.

This is an excellent example of one of the tools that a component-based approach provides. The external system does not need to concern itself with how to gather the data that it requires. The calling program needs only to access the attribute for the data to be returned. This is how business objects decouple the calling program (whether it be in R/3 or external to R/3) from the internals of R/3.
The BOR lets you define multi-line attributes. These attributes define one-to-many relationships between an object and other fields. These objects can be defined in the data dictionary or can also be virtual attributes.
An attribute that uniquely defines an object in the system is called a key attribute. In the case of a SalesOrder, the key attribute is VBAK-VBELN (the TableName and FieldName). It is not uncommon for an object to have several key fields. An example of this is object is the SalesArea (BUS000603) object type which has SalesOrganization (TVTA-VKORG), DistributionChannel (TVTA-VTWEG) and Division (TVTA-SPARTE) as key fields.
Methods
As mentioned earlier, the methods of an object represent the actions you take with objects attributes. An action in this example would include retrieving the status of one or more sales orders based on specific criteria. Methods are analogous to function modules in that they have importing and exporting parameters as well as exceptions, which you view by selecting a method and clicking on the toolbar button. This allows external systems (or internal developments) to pass and accept parameters from these methods just as if they were using function modules -- allowing external systems to call methods.
In Figure 4, the methods shown with the green LED are BAPIs that are called specifically from external systems. They can, however, be called from within the system itself. The method shown with the stop sign is obsolete, but retained for backward compatibility, and should not be used in new developments.

Methods of SalesOrder.

Delegation and Subtyping
One of the most complex concepts in object-oriented development is that of inheritance. This concept lets you extend core functionality by creating a child of the parent object that inherits all of its attributes and methods. For example, a Manager object is a subtype (child) of the Employee object. The Manager object has all the attributes of an Employee object (such as EmployeeID or Name) but also has some extra attributes (such as CompanyCar or ParkingSpace). SAP has not implemented inheritance in the BOR. However, it has provided subtyping and delegation, which offer an alternative way to extend R/3 functionality.
Subtyping
A subtype of an object is another object whose creation is based upon a parent object (see the preceding manager/employee example). The subtype maintains references to all the attributes and methods of its parent object. This means that any methods and attributes defined on the parent can be executed and accessed on the child object. I have often heard less-experienced developers refer to subtyping as copying the parent object. Although the effects can be similar, in order to achieve an understanding of some of the more advanced concepts, such as interface inheritance, it is important to realize that this is not accurate.
If a subtype object were merely a copy of its parent, then all the code contained within the parent would be physically copied to the child. This is not the case. The subtype simply maintains references to its parents methods and attributes. The real difference is that the subtype lets you redefine these methods and attributes. You can easily add your own business rules to the parent methods by redefining the subtypes method. In the following example, I will show why this distinction is so important.
Subtyping Case Study
As an ABAP developer at Acme Tyres Pty. Ltd., you have been given the task of implementing some security measures for the companys online store. The requirement is simple: The password must be at least six characters long.
Modifying SAP code leads to costly and complicated upgrades due to the modified code being overwritten by the newly delivered SAP code. Therefore, The challenge is finding a way of implementing the business logic without modifying SAP code.
After some investigation, you realize that the method CHANGEPASSWORD (in BAPI) on the object KNA1 (Customer) is called when customers change their passwords. All you need to do is create a subtype of KNA1 and then redefine the CHANGEPASSWORD method adding the ABAP code to ensure that the password is a minimum of six characters long. It is of course not wise to change SAP code even assuming you have the passwords, which can be provided only be SAP. After the method is redefined, you just need to implement the business rules in ABAP.

FIGURE 5 Redefinition of ChangePassword method.

It is imperative that once you redefine the method it still behaves in a similar manner. You are allowed to add extra business logic, but the method must still change the password rather than do something unexpected, like delete a customer. This is particularly important when SAP is being accessed from external systems. The external system will expect a method to provide certain functionality. The developer should take care to ensure that this expectation is met.
Delegation
Now that you have implemented a new CHANGEPASSWORD method, you need to tell the SAP system to use the redefined version of CHANGEPASSWORD and not the version that was delivered on the KNA1 object. This is similar to object-oriented inheritance but the two concepts do have fundamental differences.

Delegation for objects.

By making an entry in the delegation table, you tell R/3 that before executing a method on KNA1, it should first check if that method has been redefined on the subtype. If it has, then the system executes the redefined method . If it hasn't, then the system executes the original method. Figure 7 illustrates this process.

Execution flow for methods with delegation.

This delegation is powerful because it lets you implement your own business logic without modifying any SAP code. As long as the objects are properly delegated, your method will be executed.
Responsibility
So far I have shown you two major components of an object, its attributes and methods. The difficulty in SAP is that it has traditionally been a data-driven, procedural-development approach. The BOR is not well understood by developers and managers and thus it is shunned by those that stand to gain the most from it. If managers and developers alike would take a formalized approach to development using business objects, significant savings in the development, testing, and maintenance phases would be achieved. This is due to the high level of re-use that business objects encourage.
Having said this, when a powerful tool is put into the hands of an inexperienced person, chaos can (and usually does) ensue. If object-oriented design principals are not adhered to, then the resulting code has poor reusability and maintainability. Although an in-depth discussion of design issues is beyond the scope of this article, I will introduce in the following section one of the more fundamental design aspects of BOR programming: Responsibility.
When you are given the task of creating a method or attribute on an object, one of the most important questions you should ask is, Does this attribute or method belong on this object? This question is fundamental to an object-oriented design and the answer can make a world of difference. Answering this question incorrectly has detrimental effects on the development effort resulting in methods and attributes strewn across myriad objects, with no coherent structure. If the methods and attributes were strewn across several objects, it would be more difficult to provide a uniform interface to external systems. If an external system wants to execute a particular business process in R/3, it may need to access several business objects, thus increasing coupling and reducing the layer of abstraction between R/3 and the external system.
Lets take, for example, the requirement to be able to update a sales order. This is a common requirement and one that SAP usually implements for you. For the sake of the example, lets assume that SAP has not implemented this method. You will need to implement your own UPDATE method on one of the business objects. The question here is: Which object? This question is what I term as defining responsibility. Which object is responsible for having the UPDATE method on it? As shown in Figure 4, the answer in this cases is BUS2032 (SalesOrder). If you put it on any other object then you run the risk of no one else knowing of its existence. Next time there is a requirement to update a sales order, the developer will develop an additional method. You would then have two separate pieces of code that implement the same functionality. This duplication doubles development, testing, and maintenance requirements. On large projects, this can become a real problem and a maintenance and testing nightmare.
SAP recognizes the challenges facing developers in the e-business era. It is aware that if it wants to take R/3 to the next phase, it needs to continue evolving the ABAP language and ensure that powerful development tools are available to SAP developers.
Rising to the challenge, SAP has begun developing extensions to the ABAP language called ABAP objects (see "Introducing ABAP Objects," in the IntelligentERP feature archive for an excellent introductory article to ABAP objects by Jürgen Heymann and Horst Keller). These extensions will provide ABAP developers with a full range of object-oriented tools. Eventually, these new extensions will make BOR obsolete. However, the use of object-oriented development is sure to be an integral part of future SAP developments, regardless of where the world of e takes us.

BAPI

BAPI stands for Business Application Programming Interface.

There are 5 different steps in BAPI.
- Create BAPI Structure
- Create BAPI Function Module or API Method.
- Create BAPI object
- Release BAPI Function Module.
- Release BAPI object.

Step1. Creating BAPI Structure:
- Go to .
- Select Data Type & Enter a name.
- Click on Create.
- Note: Always BAPI should be in a development class with request number (Not Local Object).
- Select Structure & hit ENTER.
- Enter the fields from your database. Make sure that the first field is the Primary Key Field.
- Then SAVE & ACTIVATE.

Step 2. Creating BAPI module:
- Enter TR.CODE .
- Before entering any thing, from the present screen that you are in, select the menu
Goto -> Function Groups -> Create Group.
Enter a name (Note: This name Must start with ZBAPI)
Let this screen be as it is and open another window and there, enter TR.CODE screen and enter a name and hit . Then enter the group name that you just created and activated.
NOTE: When you release a function module the respective group will be attached to that particular application. It cannot be used for any other application. NEVER include an already existing group that is attached to another module.

Now click on the first Tab that says [ATTRIBUTES] and select the radio button that says remote-enabled module since we will be accessing this from any external system.

Then click on the second tab that says [IMPORT].

Enter a PARAMETER NAME, TYPE and the structure you created in the first step. Also select the check box ‘Pa’. All remotely enabled functional modules MUST be Pa enabled, where Pa means ‘Passed by Value’ and if you don’t select ‘Pa’, then that means it will be passed by reference..

Then click on tab that says [EXPORT].

Enter the following as is in the first three fields

RETURN TYPE BAPIRETURN (These 3 field values are always same)
Here also select ‘Pa’ meaning Pass by value.

Note: BAPIRETURN contains structure with message fields.

Then SAVE and ACTIVATE.

Step 3. Creating BAPI object:
- Enter Tr.Code (Note. It is letter ‘O’ and not Zero).
- Enter a name and then click on create. Enter details.
NOTE: Make sure that that Object Type and Program name are SAME.
- Enter Application ‘M’, if you are using standard table Mara. If you are using your own database then select ‘Z’ at the bottom.
- Then hit .
- Now we have to add ‘Methods’. High light METHODS and then select the following from the menu:
Goto Utilities -> API Methods -> Add Methods.
- Enter function Module name and hit .
- Select the second FORWARD ARROW button (>)to go to next step.
- Check if every thing looks ok and again click on FORWARD ARROW button (>).
- Then select ‘YES’ and click on .
- Now on a different screen goto TR.CODE . Enter Function Module name and select from the top menu Function Module -> Release -> Release.
- Goback to TR.CODE .

Here select the menu combination shown below in the same order.
- Edit -> Change Release Status -> Object Type Component -> To Implemented.
- Edit -> Change Release Status -> Object Type Component -> To Released.
- Edit -> Change Release Status -> Object Type -> To Implemented.
- Edit -> Change Release Status -> Object Type -> To Released.
- Then click on .
- Then click on Generate Button (4th button from left hand side looks like spinning wheel).
- Then Click on the button that says ‘PROGRAM’ to see the source code.

To check if this is present in work flow goto TR.CODE .
Here it shows business object repository.
- First click on the middle button and then select “ALL” and hit ENTER.
- Goto tab [ALPHABETICAL] and look for the object that you created. This shows that the BAPI object has been created successfully.

REPORT FOR CUSTMOR BALANCE

REPORT zfi_rept_cust_balanceamt NO STANDARD PAGE HEADING
MESSAGE-ID zivs.

TABLES : t001, tvkbt, bsid, bsad, knb1,bkpf,knc1,sscrfields,T009.

selection-screen begin of block b1 with frame title text-000.
PARAMETERS : ccode LIKE bsid-bukrs,
date LIKE bsid-budat,
cust LIKE knb1-kunnr.
selection-screen end of block b1.

DATA : BEGIN OF i_customers OCCURS 0,
kunnr LIKE knb1-kunnr, "customer no
END OF i_customers.

DATA : BEGIN OF i_custopnbal OCCURS 0,
budat LIKE bsid-budat, "posting date
kunnr LIKE bsid-kunnr, "customer no
wrbtr LIKE bsid-wrbtr, "amount in document
shkzg LIKE bsid-shkzg, "debit/credit indicator
END OF i_custopnbal.

DATA: fdate LIKE bsid-budat,
ldate LIKE bsid-budat,
month LIKE T009-ANZBP,
monat like bkpf-monat,
year LIKE bkpf-gjahr,
tramount LIKE knc1-um01s,
opamt LIKE bsid-wrbtr ,
opind ,
clamt LIKE bsid-wrbtr,
clind ,
optot LIKE bsid-wrbtr ,
optoti,
trtot LIKE bsid-wrbtr ,
trtoti,
cltot LIKE bsid-wrbtr ,
cltoti,
opgtot LIKE bsid-wrbtr,
opgtoti,
trgtot LIKE bsid-wrbtr,
trgtoti,
clgtot LIKE bsid-wrbtr,
clgtoti,
no type i value 1.


selection-screen: function key 1.

initialization.
move 'Data1' to sscrfields-functxt_01.

at selection-screen.

if sscrfields-ucomm = 'FC01'.
ccode = 'DATT'.
date = '20040910'.
cust = '0000500001'.
endif.


SELECT SINGLE * FROM t001 WHERE bukrs = ccode.

IF sy-subrc <> 0.
MESSAGE e000.
ENDIF.

IF date > sy-datum.
MESSAGE e002.
ENDIF.



START-OF-SELECTION.

CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
EXPORTING
day_in = date
IMPORTING
last_day_of_month = ldate.

fdate = date.
fdate+6(2) = '01'.


SELECT kunnr FROM knb1 INTO TABLE i_customers
WHERE bukrs = ccode.


LOOP AT i_customers.

SELECT budat kunnr wrbtr shkzg FROM bsid
APPENDING
CORRESPONDING FIELDS OF TABLE i_custopnbal
WHERE bukrs = ccode AND
kunnr = cust AND
budat BETWEEN fdate AND ldate.

ENDLOOP.
* IF SY-SUBRC <> 0.
* WRITE:/15(30) 'NO DATA IS HERE WITH UR INPUT',/35 'ENTER ANOTHER ONE'
.
* ENDIF.
SORT i_custopnbal BY budat.

CALL FUNCTION 'FTI_FISCAL_YEAR_MONTH_GET'
EXPORTING
i_bukrs = ccode
i_budat = date
IMPORTING
e_gjahr = year
e_monat = monat.

month = monat.

CALL FUNCTION 'CUSTOMER_BALANCE'
EXPORTING
anzbp = '012'
bukrs = ccode
gjahr = year
kunnr = cust
monat = month
periv = 'V3'
xh12mon = ' '
xh6mon = ' '
IMPORTING
uml01 = tramount.
opamt = tramount.

LOOP AT i_custopnbal.

AT NEW budat.
FORMAT COLOR COL_GROUP INVERSE..
WRITE :/, / 'DATE:' , i_custopnbal-budat,
' CUSTMOER NO: ', i_customers-kunnr ,
'COMPANY CODE:', ccode.
FORMAT RESET.
FORMAT COLOR 3.
WRITE : /5 'S.NO' , 10 ' OPENING BAL', 30 'D/C',
35 ' TRANS AMT ', 60 'D/C',
65 ' CLOSING AMT ', 85 'D/C'.
FORMAT RESET.
ENDAT.

PERFORM sub1 USING opamt opind.

IF i_custopnbal-shkzg = 'S'.
clamt = opamt + i_custopnbal-wrbtr.
ELSE .
clamt = opamt - i_custopnbal-wrbtr.
ENDIF.

PERFORM sub1 USING clamt clind .

FORMAT COLOR 2.
WRITE :/5 no,10 opamt NO-SIGN,30 opind,
35 i_custopnbal-wrbtr,60 i_custopnbal-shkzg,
65 clamt NO-SIGN,85 clind.
FORMAT RESET.

PERFORM sub2 USING optot opamt .
PERFORM sub1 USING optot optoti.
PERFORM sub2 USING trtot i_custopnbal-wrbtr .
PERFORM sub1 USING trtot trtoti.
PERFORM sub2 USING cltot clamt .
PERFORM sub1 USING cltot cltoti.

PERFORM sub2 USING opgtot opamt .
PERFORM sub1 USING opgtot opgtoti.
PERFORM sub2 USING trgtot i_custopnbal-wrbtr .
PERFORM sub1 USING trgtot trgtoti.
PERFORM sub2 USING clgtot clamt .
PERFORM sub1 USING clgtot clgtoti.

opamt = clamt.


AT END OF budat.
FORMAT COLOR 4.
WRITE:/'SUBTOTAL:',10 optot NO-SIGN, 30 optoti,
34 trtot NO-SIGN, 60 trtoti,
65 cltot NO-SIGN, 85 cltoti .
CLEAR :optot,trtot,cltot.
FORMAT RESET.
ENDAT.
AT LAST.
FORMAT COLOR 5.
WRITE:/'GRANDTOT:',10 opgtot NO-SIGN, 30 opgtoti,
34 trgtot NO-SIGN, 60 trgtoti,
65 clgtot NO-SIGN, 85 clgtoti .
FORMAT RESET.
ENDAT.

ENDLOOP.
*&---------------------------------------------------------------------*
*& Form SUB1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_CLAMT text
* -->P_CLIND text
*----------------------------------------------------------------------*
FORM sub1 USING p_clamt
p_clind.


IF p_clamt > 0.
p_clind = 'S'.
ELSEIF p_clamt < 0.
p_clind = 'H'.
ELSE.
p_clind = '-' .
ENDIF.

ENDFORM. " SUB1
*&---------------------------------------------------------------------*
*& Form SUB2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_OPTOT text
* -->P_OPAMT text
* -->P_OPIND text
*----------------------------------------------------------------------*
FORM sub2 USING p_optot
p_opamt.

p_optot = p_optot + p_opamt .

ENDFORM. " SUB2

REPORT TO LIST OUT THE DELIVERY PERFORMANCE OF VENDORS WITH RESPECT TO THE GOODS RECEIVED.

REPORT Z_RNR_MM_VPR .

************************************************************************

*VENDER PERFORMANCE REPORT:

*GENERATED A REPORT TO LIST OUT THE DELIVERY PERFORMANCE OF VENDORS WITH

*RESPECT TO THE GOODS RECEIVED.

*

*IT GIVES DETAILS OF PURCHASE ORDER ITEMS

*SCHEDULE LINES, SCHEDULED QUANTITY, ITEMS DELIVERED DATES, DELIVERED

*QUANTITY AND CALCULATES THE DIFFERENCE BETWEEN SCHEDULED AND DELIVERED

*DATES.

*

*IT TAKES VENDOR, PURCHASE ORGANIZATION AND PURCHASE GROUP AS

*SELECTION PARAMETERS.

*

*GENERATES THE OUTPUT CONTAINING VENDOR, PURCHASE ORDER NO.,

*MATERIAL NO., SCHEDULED DATE, SCHEDULED QUANTITY, DELIVERED

*DATE DELIVERED QUANTITY AND PERFORMANCE.

*

************************************************************************

TABLES : EKKO, "Purchasing Document Header

EKPO, "Purchasing Document Item

EKET, "Scheduling Agreement Schedule Lines

MSEG, "Document Segment: Material

MKPF. "Header: Material Document

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-MUR.

SELECT-OPTIONS : EKORG FOR EKKO-EKORG, "PURCHASE ORGANISATION

EKGRP FOR EKKO-EKGRP, "PURCHASING GROUP

LIFNR FOR EKKO-LIFNR. "VENDOR NUMBER

SELECTION-SCREEN END OF BLOCK B1.

DATA : BEGIN OF ITAB OCCURS 0,

LIFNR LIKE EKKO-LIFNR, "VENDOR NO.

EBELN LIKE EKKO-EBELN, "PURCHASE ORDER

TEST LIKE EKKO-TEST, "ITEM NO

MATNR LIKE EKPO-MATNR, "MATERIAL NO.

SLFDT LIKE EKET-SLFDT, "SCHEDULED DATE

MENGE LIKE EKET-MENGE, "SCHEDULED QUANTITY

WEMNG LIKE EKET-WEMNG, "RECEIVED QUANTITY

ETENR LIKE EKET-ETENR, "Delivery schedule line counter

BLDAT LIKE MKPF-BLDAT, "RECEIVED DATE

MBLNR LIKE MKPF-MBLNR, "GOODS RECEIPT DOC. NO.

MJAHR LIKE MSEG-MJAHR, "Material doc. year

END OF ITAB.

DATA : JTAB LIKE ITAB OCCURS 0 WITH HEADER LINE.

**************START-OF-SELECTION.

START-OF-SELECTION.

SELECT

KO~LIFNR KO~EBELN KO~TEST

PO~MATNR

INTO CORRESPONDING FIELDS OF TABLE ITAB FROM

EKKO AS KO INNER JOIN EKPO AS PO ON

KO~EBELN = PO~EBELN AND

KO~TEST = PO~EBELP WHERE

KO~EKORG IN EKORG AND

KO~EKGRP IN EKGRP AND

KO~LIFNR IN LIFNR.

LOOP AT ITAB.

SELECT * FROM EKET

WHERE EBELN = ITAB-EBELN.

MOVE : EKET-EBELN TO JTAB-EBELN,

EKET-EBELP TO JTAB-TEST,

EKET-ETENR TO JTAB-ETENR,

EKET-SLFDT TO JTAB-SLFDT,

EKET-MENGE TO JTAB-MENGE,

EKET-WEMNG TO JTAB-WEMNG,

ITAB-LIFNR TO JTAB-LIFNR,

ITAB-MATNR TO JTAB-MATNR.

APPEND JTAB.

CLEAR JTAB.

ENDSELECT.

IF SY-SUBRC <> 0.

DELETE ITAB.

ENDIF.

ENDLOOP.

LOOP AT JTAB.

SELECT * FROM MSEG

WHERE EBELN = JTAB-EBELN AND

EBELP = JTAB-TEST AND

LIFNR = JTAB-LIFNR AND

MATNR = JTAB-MATNR.

MOVE : MSEG-MBLNR TO JTAB-MBLNR,

MSEG-MJAHR TO JTAB-MJAHR.

MODIFY JTAB.

ENDSELECT.

ENDLOOP.

LOOP AT JTAB.

SELECT * FROM MKPF

WHERE MBLNR = JTAB-MBLNR AND

MJAHR = JTAB-MJAHR.

MOVE: MKPF-BLDAT TO JTAB-BLDAT.

MODIFY JTAB.

ENDSELECT.

ENDLOOP.

WRITE : /5 'JTAB-LIFNR', 25 'JTAB-MATNR', 45 'JTAB-SLFDT',

67 'JTAB-MENGE', 80 'JTAB-BLDAT', 105 'JTAB-WEMNG'.

SORT JTAB BY LIFNR MATNR EBELN.

LOOP AT JTAB.

DELETE JTAB WHERE LIFNR = ' ' OR

MATNR = ' ' OR

EBELN = ' ' OR

SLFDT = ' ' OR

MENGE = ' '.

ENDLOOP.

LOOP AT JTAB.

WRITE : /,/5 JTAB-LIFNR, 25 JTAB-MATNR, 45 JTAB-SLFDT,

60 JTAB-MENGE, 80 JTAB-BLDAT, 100 JTAB-WEMNG.

ENDLOOP.

REPORT FOR INITIAL LOAD OF STOCKS

REPORT ZMCH0049 LINE-SIZE 170.
*
* Initial load of stocks.
*-------------------------
TABLES : MARA,
MARC,
MARD,
MCHB,
MCHA,
MSLB,
T9F1T.

DATA :BEGIN OF A1,
PREMB(12),
PROC(2),
SISO(4),
MAGA(4),
CLOT(12),
NISU(1),
NIAF(1),
AFFE(5) TYPE P,
GRAD(5) TYPE P,
SANA(5) TYPE P,
FAMI(3),
ENTI(4),
DADE(6),
PLAC(7),
POID(3) TYPE P,
FAFF(1),
FGRA(1),
FSOR(1),
TARE(3) TYPE P DECIMALS 2,
GRA1(3),
NUCO(5),
NUEX(2),
FILLER(60),
END OF A1.

DATA : BEGIN OF K1-RECORD.
INCLUDE STRUCTURE BMSEG.
DATA : END OF K1-RECORD.

DATA : BEGIN OF TAB_APIN OCCURS 10000,
PREMB(12),
MATNR LIKE MARD-MATNR,
WERKS LIKE MARD-WERKS,
LGORT LIKE MARD-LGORT,
CHARG LIKE MCHA-CHARG,
LICHA LIKE MCHA-LICHA, "apin translation
LICHS LIKE MCHA-LICHA, "sap data
GRAD(5) TYPE P, "apin gradé
SANA(5) TYPE P, "apin sous analyse
SUBC(5) TYPE P, "apin subcontracting
LABST(5) TYPE P, "sap unresticted use
INSME(5) TYPE P, "sap inspection
LBLAB(5) TYPE P, "sap subcontracting
FLAG(1) TYPE C,
NISU(1) TYPE C,
VENDOR LIKE LFA1-LIFNR,
END OF TAB_APIN.

DATA: BEGIN OF TBDCDATA OCCURS 200. "Dynpro table
INCLUDE STRUCTURE BDCDATA.
DATA: END OF TBDCDATA.

DATA: W1-MATNR LIKE MARD-MATNR,
W1-WERKS LIKE MARD-WERKS,
WS-PREMB(12),
W1-LGORT LIKE MARD-LGORT,
W1-CHARG LIKE MCHA-CHARG,
W1-LICHA LIKE MCHA-LICHA,
W-LICHA LIKE MCHA-LICHA,
W1-BWART LIKE BMSEG-BWART,
W1-ERFMG(5) TYPE P,
TOT-MVT(5) TYPE P.
DATA: W1-CTRREC(5) TYPE P VALUE 0,
CTR_TRX TYPE I VALUE 0,
CTR_LOTS TYPE I,
WTRAV(20),
WKEY(14),
W-VENDOR LIKE LFA1-LIFNR,
SW_ERROR(1),
CTR_OK TYPE I VALUE 0,
CTR_KO TYPE I VALUE 0,
SW_PRINT_ULINE(1) VALUE 'N'.
PARAMETERS:
P_FILE_M(40) DEFAULT 'APSAO.DAMVTS.EXTRACT.IL3', "APIN UNLOAD
P_NODE_M(8) DEFAULT 'BXLESSY1',
P_FILE_U(40) DEFAULT 'il_mvts.bin' LOWER CASE, "unix file created
P_FILE_2(40) DEFAULT '/usr/sap/trans02/userdata/il_mvts.bin'
LOWER CASE, "unix file to treat
P_FILE_3(40) DEFAULT '/usr/sap/trans02/userdata/il_mvts.out'
LOWER CASE, "unix file mvts
P_CODE_U(8) DEFAULT '3', "security code
PARM_DEL DEFAULT ' ' AS CHECKBOX, "delete mvs file
PARM_TRF DEFAULT 'X' AS CHECKBOX, "transfert file ?
PARM_GEN DEFAULT 'X' AS CHECKBOX, "generate mvts ?
P_MAXREC TYPE I DEFAULT 99999,
P_REASAP(1) DEFAULT ' ' .
SELECT-OPTIONS : MATNR FOR W1-MATNR,
CHARG FOR W1-CHARG,
PROC FOR A1-PROC,
WERKS FOR MARC-WERKS,
LGORT FOR W1-LGORT.

START-OF-SELECTION.

IF PARM_GEN = 'X'.
PERFORM INITIALISATION_SBDC.
ENDIF.
CLEAR TAB_APIN.
IF PARM_TRF = 'X'.
PERFORM TRANSFER_FILE.
ENDIF.
IF SY-SUBRC NE 0. EXIT. ENDIF.
PERFORM OPEN_FILE.
IF SY-SUBRC NE 0.
WRITE : / 'open file not ok'.
EXIT.
ENDIF.
DO.
READ DATASET P_FILE_2 INTO A1.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
TRANSLATE A1 FROM CODE PAGE '0100' TO CODE PAGE '1100'.
IF PROC.
MOVE A1-PREMB TO WKEY.
REPLACE 'GG' WITH '__' INTO WKEY.
MOVE 'YY' TO WKEY+12.
SELECT * FROM MARA WHERE WRKST = WKEY.
IF SY-SUBRC = 0.
PERFORM TRANSLATION_APIN_SAP.
IF MATNR AND CHARG AND LGORT AND SW_ERROR = SPACE.

PERFORM LOAD_TABLE_WITH_APIN_DATA.
ENDIF.
ENDIF.
ENDSELECT.
IF SY-SUBRC <> 0.
IF A1-PREMB CS 'GG'.
MOVE A1-PREMB TO WKEY.
ELSE.
REPLACE ' ' WITH '__' INTO A1-PREMB.
MOVE A1-PREMB TO WKEY.
ENDIF.
MOVE 'YY' TO WKEY+12.
SELECT * FROM MARA WHERE WRKST = WKEY.
IF SY-SUBRC = 0.
PERFORM TRANSLATION_APIN_SAP.
IF MATNR AND CHARG AND LGORT AND SW_ERROR = SPACE.
PERFORM LOAD_TABLE_WITH_APIN_DATA.
ENDIF.
ENDIF.
ENDSELECT.
ENDIF.
ENDIF.
ENDDO.
FORMAT INTENSIFIED OFF.
WRITE : / 'APIN MVTS read ', W1-CTRREC.
SORT TAB_APIN BY MATNR WERKS LGORT CHARG.
IF P_REASAP = 'N'.
PERFORM LOAD_TABLE_WITH_SAP_DATA.
ENDIF.
* SORT TAB_APIN BY MATNR WERKS LGORT CHARG.
SORT TAB_APIN BY MATNR WERKS CHARG LGORT.
LOOP AT TAB_APIN.
AT NEW PREMB.
IF SW_PRINT_ULINE = 'Y'.
ULINE.
SW_PRINT_ULINE = 'N'.
ENDIF.
ENDAT.
IF TAB_APIN-GRAD <> TAB_APIN-LABST OR
TAB_APIN-SANA <> TAB_APIN-INSME OR
TAB_APIN-SUBC <> TAB_APIN-LBLAB OR
TAB_APIN-LICHA <> TAB_APIN-LICHS.
TOT-MVT = TAB_APIN-GRAD + TAB_APIN-SANA + TAB_APIN-SUBC
- TAB_APIN-LABST - TAB_APIN-INSME - TAB_APIN-LBLAB.
MOVE TAB_APIN-LICHA TO W-LICHA.
IF TAB_APIN-FLAG = 'I'.
MOVE SPACE TO W-LICHA.
ENDIF.
IF TOT-MVT <> 0.
MOVE '?' TO TAB_APIN-FLAG.
ENDIF.
WRITE:/ TAB_APIN-MATNR+12(6),
TAB_APIN-PREMB,
TAB_APIN-WERKS,
TAB_APIN-LGORT,
TAB_APIN-CHARG,
W-LICHA(5),
TAB_APIN-LICHS(5),
TAB_APIN-GRAD,TAB_APIN-SANA,TAB_APIN-SUBC,
TAB_APIN-LABST DECIMALS 0,
TAB_APIN-INSME DECIMALS 0,
TAB_APIN-LBLAB DECIMALS 0,
TAB_APIN-FLAG.
CTR_KO = CTR_KO + 1.
SW_PRINT_ULINE = 'Y'.
ELSE.
CTR_OK = CTR_OK + 1.
ENDIF.

PERFORM GENERATION_MOUVEMENTS.
ADD 1 TO CTR_TRX.
ENDLOOP.

PERFORM CLOSE_FILE.
ULINE.
WRITE : / 'Nbre Transactions',CTR_TRX.
WRITE : 'Ok batches ', CTR_OK,' Differences ',CTR_KO.
IF PARM_GEN = 'X'.
PERFORM CLOSE_SBDC.
ENDIF.
*---------------------------------------------------------------------*
* FORM TRANSLATION *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM TRANSLATION_APIN_SAP.
MOVE SPACE TO SW_ERROR.
MOVE: SPACE TO W1-CHARG,
SPACE TO W1-LGORT,
SPACE TO W1-LICHA,
SPACE TO W1-MATNR,
SPACE TO W1-WERKS.

CALL FUNCTION 'Z_PRODUCT_DETERMINATION'
EXPORTING
IN_APINENTI = A1-ENTI
IN_APINLOCA = A1-PLAC
IN_APINLOTN = A1-CLOT
IN_APINMAGA = A1-MAGA
IN_APINPROD = A1-PREMB
IN_APINSITE = A1-SISO
IN_CHARG = ' '
IN_DIREC = 'SAP '
IN_LGORT = ' '
IN_LICHA = ' '
IN_MATNR = ' '
IN_WERKS = ' '
IN_LIFNR = ' '
IN_EXACT = 'X'
IMPORTING
* OUT_APINENTI =
* OUT_APINLOCA =
* OUT_APINLOTN =
* OUT_APINMAGA =
* OUT_APINPROD =
* OUT_APINSITE =
OUT_CHARG = W1-CHARG
OUT_LGORT = W1-LGORT
OUT_LICHA = W1-LICHA
OUT_MATNR = W1-MATNR
OUT_WERKS = W1-WERKS
OUT_LIFNR = W-VENDOR
EXCEPTIONS
APIN_PRODUCT_CODE_NOT_FOUND = 01
INVALID_DIRECTION = 02
PLANT_STOR_LOC_NOT_FOUND = 03
SAP_BATCH_NUMBER_NOT_FOUND = 04
SAP_MATERIAL_CODE_MANDATORY = 05
SAP_MATERIAL_CODE_NOT_FOUND = 06
SITE_MAGASIN_NOT_FOUND = 07
PRODUCT_LINE_NOT_FOUND = 08.
IF SY-SUBRC <> 0.
MOVE 'E' TO SW_ERROR.
WRITE : / 'Z_PRODUCT_DETERMINATION Error ',SY-SUBRC,'for',
A1-SISO,A1-MAGA,A1-PREMB,A1-CLOT.
ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
* FORM GENERATION_MOUVEMENTS *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM GENERATION_MOUVEMENTS.
* generation mvts 561/562
IF TAB_APIN-GRAD <> TAB_APIN-LABST.
MOVE SPACE TO W-VENDOR.
W1-ERFMG = TAB_APIN-GRAD - TAB_APIN-LABST.
IF W1-ERFMG > 0.
MOVE '561' TO W1-BWART. "mvt : GR to unrestriced use
WRITE: '(',W1-BWART , W1-ERFMG,')'.
ENDIF.
IF W1-ERFMG < 0.
W1-ERFMG = W1-ERFMG * -1.
MOVE '562' TO W1-BWART. "mvt : gr to unrestriced use rev
WRITE: '(',W1-BWART , W1-ERFMG,')'.
ENDIF.
IF PARM_GEN = 'X'.
PERFORM GENERATE_MVTS.
ENDIF.
ENDIF.

* generation mvts 563/564
IF TAB_APIN-SANA <> TAB_APIN-INSME.
MOVE SPACE TO W-VENDOR.
W1-ERFMG = TAB_APIN-SANA - TAB_APIN-INSME.
IF W1-ERFMG > 0.
MOVE '563' TO W1-BWART. "mvt : GR to qual inspect
WRITE: '(',W1-BWART , W1-ERFMG,')'.
ENDIF.
IF W1-ERFMG < 0.
W1-ERFMG = W1-ERFMG * -1.
MOVE '564' TO W1-BWART. "mvt : GR to qual inspect rev
WRITE: '(',W1-BWART , W1-ERFMG,')'.
ENDIF.
IF PARM_GEN = 'X'.
PERFORM GENERATE_MVTS.
ENDIF.
ENDIF.
* generation mvts 561/562 type O
IF TAB_APIN-SUBC <> TAB_APIN-LBLAB.
MOVE TAB_APIN-VENDOR TO W-VENDOR.
W1-ERFMG = TAB_APIN-SUBC - TAB_APIN-LBLAB.
IF W1-ERFMG > 0.
MOVE '561' TO W1-BWART. "mvt : GR to unrestriced use
WRITE: '(',W1-BWART,'O', W1-ERFMG,TAB_APIN-VENDOR,')'.
ENDIF.
IF W1-ERFMG < 0.
W1-ERFMG = W1-ERFMG * -1.
MOVE '562' TO W1-BWART. "mvt : gr to unrestriced use rev
WRITE: '(',W1-BWART,'O', W1-ERFMG,TAB_APIN-VENDOR,')'.
ENDIF.
IF PARM_GEN = 'X'.
PERFORM GENERATE_MVTS.
ENDIF.
ENDIF.
* generation info vendor batch.
IF TAB_APIN-LICHA <> TAB_APIN-LICHS.
WRITE '(Ven.b)'.
IF PARM_GEN = 'X'.
PERFORM GENERATE_SBDC.
PERFORM GENERATE_SBDC_TRANSACTION.
ENDIF.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM LOAD_TABLE_WITH_APIN_DATA *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM LOAD_TABLE_WITH_APIN_DATA.
CLEAR TAB_APIN.
MOVE A1-PREMB TO TAB_APIN-PREMB.
REPLACE 'GG' WITH '__' INTO TAB_APIN-PREMB.
MOVE W1-MATNR TO TAB_APIN-MATNR.
MOVE W1-WERKS TO TAB_APIN-WERKS.
MOVE W1-LGORT TO TAB_APIN-LGORT.
MOVE W1-CHARG TO TAB_APIN-CHARG.
MOVE W1-LICHA TO TAB_APIN-LICHA.
* REPLACE 'GG' WITH ' ' INTO TAB_APIN-LICHA. "dt0103
MOVE A1-NISU TO TAB_APIN-NISU.
* Determination subcontracting.
MOVE SPACE TO W-VENDOR.
MOVE A1-SISO TO WTRAV.
MOVE A1-MAGA TO WTRAV+4.
SELECT * FROM T9F1T
WHERE BUKRS = '0100'
AND ID = 'VENDOR'
AND FKT = WTRAV.
MOVE T9F1T-ARG TO W-VENDOR.
ENDSELECT.
IF W-VENDOR = SPACE. " pas de subcontracting
IF A1-NISU = 'M'.
MOVE SPACE TO TAB_APIN-LICHA.
MOVE SPACE TO TAB_APIN-CHARG.
MOVE A1-GRAD TO TAB_APIN-GRAD.
MOVE A1-SANA TO TAB_APIN-SANA.
ENDIF.
IF A1-NISU = 'L'.
MOVE A1-GRAD TO TAB_APIN-GRAD.
MOVE A1-SANA TO TAB_APIN-SANA.
ENDIF.
IF A1-NISU = 'E'.
IF A1-FGRA = 'Y' AND A1-FSOR = ' '.
MOVE A1-POID TO TAB_APIN-GRAD.
MOVE 0 TO TAB_APIN-SANA.
ENDIF.
IF A1-FGRA = 'N' AND A1-FSOR = ' '.
MOVE 0 TO TAB_APIN-GRAD.
MOVE A1-POID TO TAB_APIN-SANA.
ENDIF.
IF A1-FGRA <> 'Y' AND A1-FGRA <> 'N'.
WRITE : / 'error flag gradé', A1-FGRA,A1-PREMB,A1-CLOT,
A1-ENTI.
ENDIF.
IF A1-FSOR = 'Y'.
MOVE 0 TO TAB_APIN-GRAD.
MOVE 0 TO TAB_APIN-SANA.
ENDIF.
ENDIF.
ELSE.
MOVE W-VENDOR TO TAB_APIN-VENDOR. " si subcontracting
MOVE A1-MAGA TO TAB_APIN-LGORT.
IF A1-NISU = 'M'.
MOVE SPACE TO TAB_APIN-CHARG.
MOVE A1-GRAD TO TAB_APIN-SUBC.
ADD A1-SANA TO TAB_APIN-SUBC.
ENDIF.
IF A1-NISU = 'L'.
MOVE A1-GRAD TO TAB_APIN-SUBC.
ADD A1-SANA TO TAB_APIN-SUBC.
ENDIF.
IF A1-NISU = 'E'.
IF A1-FGRA = 'Y' AND A1-FSOR = ' '.
MOVE A1-POID TO TAB_APIN-SUBC.
ENDIF.
IF A1-FGRA = 'N' AND A1-FSOR = ' '.
MOVE A1-POID TO TAB_APIN-SUBC.
ENDIF.
IF A1-FGRA <> 'Y' AND A1-FGRA <> 'N'.
WRITE : / 'error flag gradé', A1-FGRA,A1-PREMB,A1-CLOT,
A1-ENTI.
ENDIF.
IF A1-FSOR = 'Y'.
MOVE 0 TO TAB_APIN-GRAD.
MOVE 0 TO TAB_APIN-SANA.
ENDIF.
ENDIF.
ENDIF.
IF TAB_APIN-GRAD < 0 OR TAB_APIN-SANA < 0.
WRITE : / 'error stock < 0',A1-PREMB,A1-SISO,A1-MAGA,A1-CLOT.
ELSE.
IF TAB_APIN-GRAD <> 0 OR TAB_APIN-SANA <> 0 OR TAB_APIN-SUBC <> 0.
APPEND TAB_APIN.
ENDIF.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM LOAD_TABLE_WITH_SAP_DATAS *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM LOAD_TABLE_WITH_SAP_DATA.

SELECT * FROM MARA.
MOVE MARA-MATNR TO W1-MATNR.
IF MATNR.
IF MARA-WRKST+12(2) = 'YY'.
SELECT * FROM MARC
WHERE MATNR = MARA-MATNR.
IF WERKS.
IF MARC-XCHPF = 'X'.
PERFORM SAP_EXTRACT_LOTS.
PERFORM EXTRACT_SAP_SUBCONTRACTING.
ELSE.
PERFORM SAP_EXTRACT_STOR_LOC.
PERFORM EXTRACT_SAP_SUBCONTRACTING.
ENDIF.
ENDIF.
ENDSELECT.
ENDIF.
ENDIF.
ENDSELECT.
ENDFORM.
*---------------------------------------------------------------------*
* FORM SAP_EXTRACT_LOTS *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM SAP_EXTRACT_LOTS.
SELECT * FROM MARD
WHERE MATNR = MARA-MATNR
AND WERKS = MARC-WERKS.
SELECT * FROM MCHB
WHERE MATNR = MARA-MATNR
AND WERKS = MARC-WERKS
AND LGORT = MARD-LGORT.
MOVE MCHB-CHARG TO W1-CHARG.
IF CHARG AND LGORT.
SELECT SINGLE * FROM MCHA
WHERE MATNR = MARA-MATNR
AND WERKS = MARC-WERKS
AND CHARG = MCHB-CHARG.
* IF MCHA-LICHA = 'GG'. "dt0103
* MOVE SPACE TO MCHA-LICHA. "dt0103
* ENDIF. "dt0103
IF MARC-WERKS = '7120'.
IF MCHB-CHARG+7(1) = 'T' OR MCHB-CHARG+7(1) = 'R'
OR MCHB-CHARG+7(2) = 'CO' OR MCHB-CHARG+7(2) = 'SC'.
MOVE SPACE TO MCHA-LICHA.
ENDIF. "dt
ENDIF. "dt
CLEAR TAB_APIN.

MOVE MARA-WRKST TO TAB_APIN-PREMB.
REPLACE 'GG' WITH '__' INTO TAB_APIN-PREMB.
MOVE MARA-MATNR TO TAB_APIN-MATNR.
MOVE MARC-WERKS TO TAB_APIN-WERKS.
MOVE MARD-LGORT TO TAB_APIN-LGORT.
MOVE MCHB-CHARG TO TAB_APIN-CHARG.
MOVE SPACE TO TAB_APIN-LICHA.
MOVE SPACE TO TAB_APIN-LICHS.
READ TABLE TAB_APIN.
IF SY-SUBRC = 0.
IF TAB_APIN-NISU = 'M'.
WRITE: / TAB_APIN-MATNR,TAB_APIN-WERKS, 'Gestion par lots?'.
ENDIF.
MOVE MCHA-LICHA TO TAB_APIN-LICHS.
ADD MCHB-CLABS TO TAB_APIN-LABST.
ADD MCHB-CINSM TO TAB_APIN-INSME.
MODIFY TAB_APIN INDEX SY-TABIX.
ELSE.
MOVE MCHA-LICHA TO TAB_APIN-LICHA.
MOVE MCHA-LICHA TO TAB_APIN-LICHS.
MOVE MCHB-CLABS TO TAB_APIN-LABST.
MOVE MCHB-CINSM TO TAB_APIN-INSME.
MOVE 'I' TO TAB_APIN-FLAG.
INSERT TAB_APIN INDEX 1.
ENDIF.
ENDIF.
ENDSELECT.
ENDSELECT.
ENDFORM.
*---------------------------------------------------------------------*
* FORM EXTRACT_SAP_SUBCONTRACTING *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM EXTRACT_SAP_SUBCONTRACTING.
SELECT * FROM MSLB
WHERE MATNR = MARA-MATNR
AND WERKS = MARC-WERKS.
MOVE MSLB-CHARG TO W1-CHARG.
MOVE MSLB-LIFNR TO WTRAV.
MOVE MARC-WERKS TO WTRAV+11.
IF CHARG.
SELECT SINGLE * FROM T9F1T
WHERE BUKRS = '0100'
AND ID = 'VENDOR'
AND ARG = WTRAV.
IF SY-SUBRC <> 0.
MOVE '????????' TO T9F1T-FKT.
ENDIF.
SELECT SINGLE * FROM MCHA
WHERE MATNR = MARA-MATNR
AND WERKS = MARC-WERKS
AND CHARG = MSLB-CHARG.
CLEAR TAB_APIN.
MOVE MARA-WRKST TO TAB_APIN-PREMB.
MOVE MARA-MATNR TO TAB_APIN-MATNR.
MOVE MARC-WERKS TO TAB_APIN-WERKS.
MOVE T9F1T-FKT+4(4) TO TAB_APIN-LGORT.
MOVE MSLB-CHARG TO TAB_APIN-CHARG.
MOVE SPACE TO TAB_APIN-LICHA.
MOVE SPACE TO TAB_APIN-LICHS.
MOVE MSLB-LIFNR TO TAB_APIN-VENDOR.
READ TABLE TAB_APIN.
IF SY-SUBRC = 0.
IF TAB_APIN-NISU = 'M'.
WRITE: / TAB_APIN-MATNR,TAB_APIN-WERKS, 'Gestion par lots?'.
ENDIF.
MOVE MCHA-LICHA TO TAB_APIN-LICHS.
* ADD MCHB-CLABS TO TAB_APIN-LABST.
ADD MSLB-LBLAB TO TAB_APIN-LBLAB.
MODIFY TAB_APIN INDEX SY-TABIX.
ELSE.
MOVE MCHA-LICHA TO TAB_APIN-LICHA.
MOVE MCHA-LICHA TO TAB_APIN-LICHS.
* MOVE MCHB-CLABS TO TAB_APIN-LABST.
MOVE MSLB-LBLAB TO TAB_APIN-LBLAB.
MOVE 'I' TO TAB_APIN-FLAG.
INSERT TAB_APIN INDEX 1.
ENDIF.
ENDIF.
ENDSELECT.
ENDFORM.
*---------------------------------------------------------------------*
* FORM SAP_EXTRACT_STOR_LOC. *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM SAP_EXTRACT_STOR_LOC.
SELECT * FROM MARD
WHERE MATNR = MARA-MATNR
AND WERKS = MARC-WERKS.
CLEAR TAB_APIN.
MOVE MARA-WRKST TO TAB_APIN-PREMB.
MOVE MARA-MATNR TO TAB_APIN-MATNR.
MOVE MARC-WERKS TO TAB_APIN-WERKS.
MOVE MARD-LGORT TO TAB_APIN-LGORT.
MOVE SPACE TO TAB_APIN-CHARG.
MOVE SPACE TO TAB_APIN-LICHA.
READ TABLE TAB_APIN.

IF TAB_APIN-NISU = 'E' OR TAB_APIN-NISU = 'L'.
WRITE: / TAB_APIN-MATNR,TAB_APIN-WERKS, 'Gestion par maga?'.
ENDIF.
MOVE MARD-LABST TO TAB_APIN-LABST.
MOVE MARD-INSME TO TAB_APIN-INSME.
IF SY-SUBRC = 0.
MODIFY TAB_APIN INDEX SY-TABIX.
ELSE.
MOVE 'I' TO TAB_APIN-FLAG.
INSERT TAB_APIN INDEX 1.
ENDIF.

ENDSELECT.
ENDFORM.
*---------------------------------------------------------------------*
* FORM GENERATE_MVTS *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM GENERATE_MVTS.
MOVE SPACE TO K1-RECORD.
MOVE '0100APMVTIL1' TO K1-RECORD-MAPPE.
MOVE 'MB1A' TO K1-RECORD-TCODE.
MOVE SY-DATUM TO K1-RECORD-BLDAT.
MOVE SY-DATUM TO K1-RECORD-BUDAT.
* MOVE '/' TO K1-RECORD-XBLNR.
MOVE 'Initial Load' TO K1-RECORD-BKTXT.
* MOVE '/' TO K1-RECORD-FRBNR.
* MOVE '/' TO K1-RECORD-WEVER.
* MOVE '/' TO K1-RECORD-LDEST.
MOVE W1-BWART TO K1-RECORD-BWART.
MOVE TAB_APIN-MATNR+12(6) TO K1-RECORD-MATNR.
MOVE TAB_APIN-WERKS TO K1-RECORD-WERKS.
IF W-VENDOR = SPACE.
MOVE TAB_APIN-LGORT TO K1-RECORD-LGORT.
ELSE.
MOVE SPACE TO K1-RECORD-LGORT.
ENDIF.
MOVE TAB_APIN-CHARG TO K1-RECORD-CHARG.
* MOVE '/' TO K1-RECORD-INSMK.
* MOVE '/' TO K1-RECORD-ZUSCH.
* MOVE '/' TO K1-RECORD-SOBKZ.
IF W-VENDOR <> SPACE.
MOVE W-VENDOR TO K1-RECORD-LIFNR.
MOVE 'O' TO K1-RECORD-SOBKZ.
ENDIF.
* MOVE '/' TO K1-RECORD-LIFNR.
* MOVE '/' TO K1-RECORD-KUNNR.
* MOVE '/' TO K1-RECORD-KDAUF.
* MOVE '/' TO K1-RECORD-KDPOS.
* MOVE '/' TO K1-RECORD-KDEIN.
* MOVE '/' TO K1-RECORD-PLPLA.
UNPACK W1-ERFMG TO K1-RECORD-ERFMG.
MOVE 'KG' TO K1-RECORD-ERFME.
* MOVE '/' TO K1-RECORD-BPMNG.
* MOVE '/' TO K1-RECORD-BPRME.
* MOVE '/' TO K1-RECORD-EBELN.
* MOVE '/' TO K1-RECORD-EBELP.
* MOVE '/' TO K1-RECORD-ELIKZ.
* MOVE '/' TO K1-RECORD-SGTXT.
* MOVE '/' TO K1-RECORD-EQUNR.
* MOVE '/' TO K1-RECORD-WEMPF.
* MOVE '/' TO K1-RECORD-ABLAD.
* MOVE '/' TO K1-RECORD-KOKRS.
* MOVE '/' TO K1-RECORD-PARGB.
* MOVE '/' TO K1-RECORD-PARBU.
* MOVE 'PE01' TO K1-RECORD-KOSTL.
* MOVE '/' TO K1-RECORD-PROJN.
* MOVE '/' TO K1-RECORD-AUFNR.
* MOVE '/' TO K1-RECORD-ANLN1.
* MOVE '/' TO K1-RECORD-ANLN2.
* MOVE '/' TO K1-RECORD-RSNUM.
* MOVE '/' TO K1-RECORD-RSPOS.
* MOVE '/' TO K1-RECORD-KZEAR.
* MOVE '/' TO K1-RECORD-UMMAT.
* MOVE '/' TO K1-RECORD-UMWRK.
* MOVE '/' TO K1-RECORD-UMLGO.
* MOVE '/' TO K1-RECORD-UMCHA.
* MOVE '/' TO K1-RECORD-UMZUS.
* MOVE '/' TO K1-RECORD-UMBAR.
* MOVE '/' TO K1-RECORD-UMSOK.
* MOVE '/' TO K1-RECORD-WEANZ.
* MOVE '/' TO K1-RECORD-GRUND.
* MOVE '/' TO K1-RECORD-KONTO.
MOVE ' ' TO K1-RECORD-EXWRT.
* MOVE '/' TO K1-RECORD-XZGVH.
* MOVE '/' TO K1-RECORD-LGTYP.
* MOVE '/' TO K1-RECORD-LGPLA.
* MOVE '/' TO K1-RECORD-GSBER.
* MOVE '/' TO K1-RECORD-KSTRG.
* MOVE '/' TO K1-RECORD-PAOBJNR.
* MOVE '/' TO K1-RECORD-PRCTR.
* MOVE '/' TO K1-RECORD-PS_PSP_PNR.
* MOVE '/' TO K1-RECORD-NPLNR.
* MOVE '/' TO K1-RECORD-AUFPL.
* MOVE '/' TO K1-RECORD-APLZL.
* MOVE '/' TO K1-RECORD-AUFPS.
* MOVE '/' TO K1-RECORD-VPTNR.
* MOVE '/' TO K1-RECORD-FIPOS.
TRANSFER K1-RECORD TO P_FILE_3.
ENDFORM.
*---------------------------------------------------------------------*
* FORM TRANSFER_FILE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM TRANSFER_FILE.
* Check existence of a file on IBM mainframe
WRITE:/ 'Step1 : Check MVS file existence'.

CALL FUNCTION 'ZFILE_EXTMVS'
EXPORTING
INPUT_FILE = P_FILE_M
MVS_NODE = P_NODE_M
TEST_MODE = SPACE
EXCEPTIONS
FILE_NOT_FOUND = 01
INVALID_NAME_MVS = 02
NOT_AUTHORISED = 03
OTHER_PROBLEM = 04.

CASE SY-SUBRC.
WHEN 1.
WRITE:/ 'Step1 : File MVS not found : ', P_FILE_M.
WHEN 2.
WRITE:/ 'Step1 : Invalid MVS file name : ', P_FILE_M.
WHEN 3.
WRITE:/ 'Step1 : User not authorized to check file ', P_FILE_M.
WHEN OTHERS.
ENDCASE.

WRITE:/ 'Step1 : rc = ', SY-SUBRC.
CHECK SY-SUBRC = 0.

* Transfer file from IBM mainframe to RISC 6000 mainframe
WRITE:/ 'Step2 : Transfer MVS file to UNIX'.

CALL FUNCTION 'ZTR_MVS_UNIX'
EXPORTING
INPUT_FILE = P_FILE_M
MVS_NODE = P_NODE_M
OUTPUT_FILE = P_FILE_U
SECURITY_CODE = P_CODE_U
TEST_MODE = SPACE
EXCEPTIONS
BAD_SECURITY_CODE = 01
FILE_NOT_FOUND_MVS = 02
FILE_NOT_FOUND_UNIX = 03
INVALID_NAME_MVS = 04
NOT_AUTHORISED = 05
OTHER_PROBLEM = 06.

CASE SY-SUBRC.
WHEN 1.
WRITE:/ 'Step2 : Bad security code : ', P_CODE_U.
WHEN 2.
WRITE:/ 'Step2 : File MVS not found : ', P_FILE_M.
WHEN 3.
WRITE:/ 'Step2 : File UNIX not found ', P_FILE_U.
WHEN 4.
WRITE:/ 'Step2 : Invalid MVS file name : ', P_FILE_M.
WHEN 5.
WRITE:/ 'Step2 : User not authorized to copy file ', P_FILE_M.
WHEN OTHERS.
ENDCASE.

WRITE:/ 'Step2 : rc = ', SY-SUBRC.
CHECK SY-SUBRC = 0.

* Delete IBM file
IF PARM_DEL = 'X'.
WRITE:/ 'Step3 : Delete MVS file'.

CALL FUNCTION 'ZFILE_DELMVS'
EXPORTING
INPUT_FILE = P_FILE_M
MVS_NODE = P_NODE_M
TEST_MODE = SPACE
EXCEPTIONS
FILE_NOT_FOUND = 01
INVALID_NAME_MVS = 02
NOT_AUTHORISED = 03
OTHER_PROBLEM = 04.

CASE SY-SUBRC.
WHEN 1.
WRITE:/ 'Step3 : File MVS not found : ', P_FILE_M.
WHEN 2.
WRITE:/ 'Step3 : Invalid MVS file name : ', P_FILE_M.
WHEN 3.
WRITE:/ 'Step3 : User not authorized to delete file ', P_FILE_M.
WHEN OTHERS.
ENDCASE.

WRITE:/ 'Step3 : rc = ', SY-SUBRC.
CHECK SY-SUBRC = 0.
ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
* FORM OPEN_FILE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM OPEN_FILE.

OPEN DATASET P_FILE_2 FOR INPUT IN BINARY MODE.
IF SY-SUBRC NE 0.
WRITE:/ 'Step4 : rc = ', SY-SUBRC.
WRITE:/ 'Unable to open dataset : ', P_FILE_2.
ENDIF.
OPEN DATASET P_FILE_3 FOR OUTPUT IN TEXT MODE.

ENDFORM.

*---------------------------------------------------------------------*
* FORM CLOSE_FILE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM CLOSE_FILE.

CLOSE DATASET P_FILE_2.
CLOSE DATASET P_FILE_3.

ENDFORM.

*---------------------------------------------------------------------*
* FORM INITIALISATION_SBDC *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM INITIALISATION_SBDC.

CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = '0100APMVTIL2'
KEEP = ' '
USER = SY-UNAME
EXCEPTIONS
CLIENT_INVALID = 01
DESTINATION_INVALID = 02
GROUP_INVALID = 03
HOLDDATE_INVALID = 04
INTERNAL_ERROR = 05
QUEUE_ERROR = 06
RUNNING = 07
USER_INVALID = 08.

ENDFORM.

*---------------------------------------------------------------------*
* FORM GENERATE_SBDC_TRANSACTION *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM GENERATE_SBDC_TRANSACTION.
*----------------------------------------------------------------------
MOVE SPACE TO K1-RECORD.
MOVE '0100APMVTIL1' TO K1-RECORD-MAPPE.
MOVE 'MSC1' TO K1-RECORD-TCODE.
MOVE TAB_APIN-MATNR TO K1-RECORD-MATNR.
MOVE TAB_APIN-CHARG TO K1-RECORD-CHARG.
MOVE TAB_APIN-WERKS TO K1-RECORD-WERKS.
MOVE TAB_APIN-LICHA TO K1-RECORD-BKTXT.
TRANSFER K1-RECORD TO P_FILE_3.
*----------------------------------------------------------------------
*
* CALL FUNCTION 'BDC_INSERT'
* EXPORTING
* TCODE = 'ZSC2'
* TABLES
* DYNPROTAB = TBDCDATA
* EXCEPTIONS
* INTERNAL_ERROR = 01
* NOT_OPEN = 02
* QUEUE_ERROR = 03
* TCODE_INVALID = 04.
*
ENDFORM.

*---------------------------------------------------------------------*
* FORM GENERATE_SBDC *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM GENERATE_SBDC.
REFRESH TBDCDATA.
CLEAR TBDCDATA.
TBDCDATA-PROGRAM = 'SAPMM03S'.
TBDCDATA-DYNPRO = '0105'.
TBDCDATA-DYNBEGIN = 'X'.
APPEND TBDCDATA.

CLEAR TBDCDATA.
TBDCDATA-FNAM = 'RM03S-MATNR'.
TBDCDATA-FVAL = TAB_APIN-MATNR+12(6).
APPEND TBDCDATA.

CLEAR TBDCDATA.
TBDCDATA-FNAM = 'RM03S-WERKS'.
TBDCDATA-FVAL = TAB_APIN-WERKS.
APPEND TBDCDATA.

CLEAR TBDCDATA.
TBDCDATA-FNAM = 'RM03S-CHARG'.
TBDCDATA-FVAL = TAB_APIN-CHARG.
APPEND TBDCDATA.



CLEAR TBDCDATA.
TBDCDATA-PROGRAM = 'SAPMM03S'.
TBDCDATA-DYNPRO = '0200'.
TBDCDATA-DYNBEGIN = 'X'.
APPEND TBDCDATA.

CLEAR TBDCDATA.
TBDCDATA-FNAM = 'MCHA-LICHA'.
TBDCDATA-FVAL = TAB_APIN-LICHA.
APPEND TBDCDATA.

CLEAR TBDCDATA.
TBDCDATA-FNAM = 'BDC_OKCODE'.
TBDCDATA-FVAL = 'BU'.
APPEND TBDCDATA.

ENDFORM.
*---------------------------------------------------------------------*
* FORM CLOSE_SBDC *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM CLOSE_SBDC.

CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 01
QUEUE_ERROR = 02.
ENDFORM.