Modernization Hub

Embedded Statements

SQL, DL/I
Enhanced Definition

Embedded statements refer to database manipulation language (DML) or data definition language (DDL) statements, such as SQL for DB2 or DL/I calls for IMS, that are directly coded within an application program written in a host language like COBOL, PL/I, or C/C++. This technique allows application logic to interact seamlessly with a database system without requiring external calls to separate database access modules for every operation.

Key Characteristics

    • Host Language Integration: Embedded statements are written directly within the application's source code, often delimited by special keywords (e.g., EXEC SQL...END-EXEC for DB2, CALL 'CBLTDLI' for IMS DL/I).
    • Precompilation Requirement: Before compilation, a specialized precompiler (e.g., DB2 precompiler, IMS DL/I preprocessor) processes the source code. It converts the embedded statements into standard host language call statements that the compiler can understand.
    • Host Variables: Application program variables (host variables) are used to pass data between the application and the database, allowing dynamic input to and output from embedded statements.
    • Status Communication: A dedicated communication area (e.g., SQLCA for DB2, PCB for IMS) is used by the database system to return status codes, error messages, and warning information to the application program after each embedded statement execution.
    • Static vs. Dynamic SQL: Embedded SQL can be static (fully defined and optimized at precompile/bind time) or dynamic (constructed and prepared at runtime, offering flexibility but often with performance and security considerations).

Use Cases

    • Batch Processing: COBOL batch programs frequently use embedded SQL or DL/I to process large volumes of data, perform bulk updates, generate reports, or migrate data in DB2 or IMS databases.
    • Online Transaction Processing (OLTP): CICS applications written in COBOL or PL/I utilize embedded SQL or DL/I to perform real-time queries, updates, and inserts against DB2 or IMS databases, supporting critical business transactions.
    • Data Utility Programs: Custom utility programs for database maintenance, data cleanup, auditing, or specialized data extraction often embed SQL or DL/I calls to interact directly with the database.
    • Application Development: Developers embed database logic directly into their application code, simplifying the development process by keeping database interactions close to the business logic that uses the data.

Related Concepts

Embedded statements are fundamental to how application programs written in host languages like COBOL or PL/I interact with DB2 relational databases or IMS DB hierarchical databases on z/OS. The precompiler is a critical component that translates these statements into host language calls, which are then compiled by the standard compiler. For DB2, the output of the precompiler (a DBRM) is used by the BIND process to create an application package or plan, which is essential for execution. These programs often run in CICS online regions or as batch jobs orchestrated by JCL.

Best Practices:
  • Robust Error Handling: Always check the SQLCA or PCB status codes after every embedded statement execution and implement appropriate error recovery or logging mechanisms.
  • Host Variable Type Matching: Ensure that the data types and lengths of host variables precisely match the corresponding database column definitions to prevent data truncation, conversion errors, or unexpected behavior.
  • Transaction Management: Explicitly manage transactions using COMMIT and ROLLBACK statements to ensure data integrity and consistency, especially in update-intensive applications.
  • Performance Optimization: For embedded SQL, strive to write efficient queries, utilize appropriate indexes, avoid full table scans, and consider static SQL over dynamic SQL when possible for better performance and security.
  • Security Considerations: Be cautious with dynamic SQL, as it can introduce SQL injection vulnerabilities if input is not properly validated and sanitized. Use authorization IDs and roles effectively.
  • Code Readability and Maintainability: Keep embedded statements clear, concise, and well-commented. Modularize database access logic where appropriate to improve code organization.

Related Vendors

ABA

3 products

ASE

3 products

Tone Software

14 products

IBM

646 products

Applied Software

7 products

Trax Softworks

3 products

Related Categories

Operating System

154 products

Automation

222 products

Databases

211 products

Transactions

29 products