Generic Object Services
Generic Object Services
com/irj/sdn/gos
Generic Object Services (GOS) Toolbar Part 1 : Add New Option in the Toolbar
Eloborates the option to add a new Menu Entry in the GOS toolbar
Generic Object Services (GOS) Toolbar offers the functions which are common to many SAP
applications. This powerful toolbar provides much functionality like create attachments, notes, mails; send
mails; list attachments and many more. You can find more functionality on Generic Object Services at
SAP Help on Generic Object Services.
Sometimes, we need to add some new toolbar entries to facilitate the business requirement. For example,
in the Generic object toolbar add the new option like "Document List" which is generic to all business
objects and of course we need to handle that. In this post, we will see the steps and rules to be followed
to add a new Entry in the toolbar. In the next, post we will see how we can handle the added menu option
to fulfill our custom requirement.
To be more specific in explaining the requirement, we will take a business requirement to add a new
menu "Sales Orders List" for the GOS toolbar for Customer Master. At first we will see how we can just
bring this menu option at very last position. Like:
To bring the new entry (menu option) in this GOS toolbar, we need to maintain that in the
table SGOSATTR. This table can be maintained using SM30.
Class for Gen. Services: This is the driver class when we select the object service (menu
option) from the GOS toolbar. For time being we will keep this as the
CL_GOS_SRV_ATTACHMENT_LIST.
Service Type: We will select 1 because we want Single entry menu option on the GOS toolbar.
There are options to create a main menu entry and submenus under that main menu by selecting
proper service type.
Next Service: We will clear the value in this since we want our button at very last level. This next
service field must be set when we need to put the custom option in between other options.
Control: We will select this, since we want to generate our output in the Custom Container.
Commit Work: We will not select this option because we don’t want to commit the work.
Along with creating a new entry this way, we need to set this service as next service of the previous
service. In this case, our new service will come just under the "Help for object services" we need to
modify that service like this:
By selecting this option Sales Orders list from the GOS toolbar, we will see the attachment list being
generated by the class CL_GOS_SRV_ATTACHMENT_LIST:
NOTE: You might see the option grayed out if you don’t have any attachment created for that particular
customer. To create: Select the Create.. > Create Attachment. Select any file from your PC to add as
attachment.
To be able to bring that option in between of others, we need to play around with the Next Service value
of the buttons. For example, I want to put my button just under the "Attachment List" option and above
"Private Note".
For this we need to:
1.Set the new option as the next Service for the "Attachment List"
2.Set the “Private Note” as the next service for the new option
3.Remove the next service from the option which will come at last. This is very important.
After following these steps, the toolbar options will look like:
In the next post, we will see how we can use our custom class to generate our fully customized code i.e.
Instead of the class CL_GOS_SRV_ATTACHMENT_LIST, we will use custom class ZCL_SO_LIST.
Generic Object Services (GOS) Toolbar Part 2 : Handle added Service in the Toolbar
Describes the way to handle the added service in the Generic Object service Toolbar
As discussed in the post Generic Object Services (GOS) Toolbar Part 1 : Add New Option in the Toolbar,
today we will see how to call our custom business logic in the added new Service in GOS Toolbar. To be
able to process custom logic in the GOS toolbar service, we need to inherit out service class from the
GOS generic service class CL_GOS_SERVICE and put our logic in the inherited class.
Steps to follow:
1. Inherit a class from the CL_GOS_SERVICE:
2. Maintain the Entry in the Table SGOSATTR as discussed in the Generic Object Services (GOS)
Toolbar Part 1 : Add New Option in the Toolbar:
3. Redefine the Method EXECUTE to process our custom business logic. Redefine the Method and
activate it. For demo purpose, we will not implement any logic in this but you can create a ALV or kind of
list as we get in the Attachement List.
Now, when we access the GOS toolbar, you will see the option “Sales Order List”.
By accessing this option, you will get the empty screen like this:
You may have noticed that this Option is coming in all the GOS toolbars i.e. Toolbar in XD02 and XK02
and so on. To restrict the GOS toolbar service to only particular transaction, we need to redefine the
method CHECK_STATUS.
Generic Object Services (GOS) Toolbar Part 3 : Add toolbar in Custom Program
Shows the code for how to add Generic Object service Toolbar in the Z program
Today, we will see how to get the GOS toolbar in the custom Report.
GOS toolbar works on the Business Object. To be able get GOS toolbar, we need to have a Business
Object and Business Object Key. For example, to get the GOS toolbar for the customer, we need
Business object KNA1 and customer number as the key. So, if we want to have a GOS toolbar in our
custom transaction than we need to have a key before generating that. This is the reason; we don’t have
the GOS toolbar option in the standard SAP Create transactions like: XD01, VA01, MM01 and so on.
This test program will provide us the GOS toolbar for the Customer in our custom program (Z program).
This will provide us all the functionality of the GOS toolbar which are available in the XD02, XD03
transaction.
Now, we will get the GOS toolbar which will look like this:
We will use the static method READ_LINKS from the class CL_BINARY_RELATION. We have to pass
what kind of the objects we want to get back from the all the attachements like Notes, Attachment,
External document etc.
This code will show how to get the NOTES attachments from the GOS toolbar.
The same way we can select attachements by adding the relation option ATTA.
Like:
Code Snippet to get the GOS attachments
la_relat-sign = 'I'.
la_relat-option = 'EQ'.
la_relat-low = 'ATTA'. "Attachements
APPEND la_relat TO lt_relat.
Generic Object Services (GOS) Toolbar Part 5 : Get Note attachment contents
Shows how to get the contents of the NOTE attachements
Today, we will see how to get the contents of the NOTE attachements.
Sometimes, we need to give the options for the attachement List when we design the some application
with GOS toolbar. We will use the static method READ_LINKS from the class CL_BINARY_RELATION.
Now, run the above program to get the attached NOTE contents.
Generic Object Services (GOS) Toolbar Part 6 : Copy Attachments between objects
Copy GOS attachment from one object to another object
Sometimes it is required to copy the attachments from one object to another object. For example, we
want to attach the customer's purchase order to Sales Order and Billing document once the billing
document is generated.
To copy the attachments between the objects, we can use the utility method COPY_LINKED_OBJECTS
of the class CL_GOS_SERVICE_TOOLS. We need to tell the method using IT_SERVICE_SELECTION,
which service needs to be performed i.e. for the attachment copy, we need to perform the "Attachment
Create" service. We also let the method know the the source and target.
Here is the Code snippet which copies the attachments between Customers.
Today, we'll see the another concept: Relationship browser. Relationships option is available in the GOS
Toolbar at GOS toolbar > Relationships.
This browser could display different linked objects like Sales Documents, Inbound IDOCs, Outbound
IDOcs etc.
Now lets see how to add this Relationships in this relationship browser. For this purpose, we can use
method CREATE_LINK of the class CL_BINARY_RELATION or the FM BINARY_RELATION_CREATE.
Method CREATE_LINK is an advanced version to create the Link which would be displayed in the
Relationship browser. Since the method CREATE_LINK is an improved version to create the links, it
doesn't support all the object models. For the remaining of the object models, we need to use the FM
BINARY_RELATION_CREATE. So, the question is how to know when to use FM.
When the relation model is not supported by the method CREATE_LINK, it raises the exception
CX_OBL_MODEL_ERROR. So, we'll call the method CREATE_LINK inside the TRY ... CATCH ...
ENDTRY block.
This Code Snippet shows how to use the method to create links in the relationship browser.
Code Snippet
After successful program run, it will display the relationship in the browser of the Order.