How to ‘Close PO’ programmatically using 4GL Script

By | December 29, 2020

In Sage X3, User have option to close Purchase order manually by using “close order” button on Purchase order screen. But one of our client has requested to automate this process on certain event so that user doesn’t have to take of this manually. To achieve this we have come up with some customization on PO screen where we did the 4GL code. Using the standard subprogram from standard script, we able to do it successfully. Lets look at the subprogram code.

New stuff: Restriction on Purchase Invoice Creation



Here is the meaning of each parameter value,

WPOHNUM: Purchase order number
WMSGFLG: It is Integer value which indicates error message
0: No error Message
1: error on screen (Call ERROR)
3: Message in trace
WRET: (Return Code) It Contains an integer value.

By calling above subprogram we can close the Purchase order.

Through above syntax we can close the purchase order by calling TRTPOHCLE subprogram from standard script with proper parameters.


Here we have created one Purchase order as shown in below screenshot which is showing closed order status “No” means PO is not closed yet.

Purchase Order screen- Closed Status
Purchase Order screen- Closed Status “No”

Now, call the Subprogram with appropriate parameter as mentioned in below script screenshot to close PO.


After execution of script, Purchase order got closed as shown in below screenshot.

Purchase Order screen- Closed Status
Purchase Order screen- Closed Status “Yes”

In this way, any programmer who knows the 4GL scripting can do this customization easily.

About Us

Greytrix – a globally recognized and one of the oldest Sage Development Partner is a one-stop solution provider for Sage ERP and Sage CRM organizational needs. Being acknowledged and rewarded for multi-man years of experience, we bring complete end-to-end assistance for your technical consultations, product customizations, data migration, system integrations, third-party add-on development and implementation competence. 

Greytrix caters to a wide range of Sage X3, a Sage Business Cloud Solution, offerings. Our unique GUMU™ integrations include Sage X3 for Sage, Dynamics 365 CRM and Magento eCommerce along with Implementation and Technical Support worldwide for Sage X3. Currently we are Sage X3 Implementation Partner in East Africa, Middle East, Australia, Asia, US, UK. We also offer best-in-class Sage X3 customization and development services, integrated applications such as POS | WMS | Payment Gateway | Shipping System | Business Intelligence | eCommerce and have developed add-ons such as Catch – Weight  and Letter of Credit and India Legislation for Sage X3 to Sage business partners, end users and Sage PSG worldwide. Greytrix Sales Commission App for Sage X3 simplifies commission calculations and postings on sales transactions.

The GUMU™ Cloud framework by Greytrix forms the backbone of cloud integrations that are managed in real-time for processing and execution of application programs at the click of a button.

Greytrix is a recognized Sage champion ISV Partner for GUMU™ Sage X3 – Sage CRM integration also listed on Sage Marketplace; GUMU™ integration for Sage X3 – Salesforce is a 5-star rated app listed on Salesforce AppExchange and GUMU™ integration for Dynamics 365 CRM – Sage ERP listed on Microsoft AppSource.

For more information on Sage X3 Integration and Services, please contact us at, We would like to hear from you.