3

I am trying to write a python code to auto generate TSQL code from a given COBOL code.

To further elaborate the requirement, I am sharing few sample inputs and expected outputs from http://www.ispirer.com/application-conversion/cobol-to-sqlserver-conversion

The python code should be able to convert COBOL’s programs to SQL Server procedure

CREATE PROCEDURE DemoId() AS BEGIN PRINT ‘FIRST DEMO’ END;

Converts WORKING-STORAGE section with declaration variables and records to MS SQL Server

DECLARE WORKING-STORAGE SECTION. 01 MY_STRING_1 PIC X(20). 01 MY_STRING_2 PIC X(30). 01 MY_NUMBER PIC 9(2) VALUE 1.

To:

DECLARE @MY_STRING_1 VARCHAR(20), @MY_STRING_2 VARCHAR(20), @MY_NUMBER INT SET @MY_NUMBER=1

Converts COBOL records to MS SQL Server CLR user-defined type

01 MY_DATA_RECORD. 03 MY_NAME PIC X(20). 03 MY_ADDRESS PIC X(40). 03 MY_ID PIC 9(2).

To:

CREATE TYPE MY_DATA_RECORD AS TABLE (MY_NAME VARCHAR(20), MY_ADDRESS VARCHAR(40),MY_ID INT )

Converts COBOL MOVE TO/COMPUTE statements to SET assignment statements

MOVE 5 TO MY_NUMBER.

To:

SET @MY_NUMBER=5

Converts COBOL control structures to Microsoft SQL Server control statements IF condition ELSE END IF To:

IF condition ELSE END IF; And PERFORN UNTIL condition COBOL statements END-PERFORM To:

WHILE condition sql_statements/sql_block

Converts Screen output (DISPLAY statement) to PRINT statement Converts EXEC SQL/ END-EXEC(select, insert, update, delete, CURSOR statements) statements to MSSQLServer SQL statements (SELECT, INSERT, UPDATE, DELETE, CURSOR statements)

EXEC SQL SELECT cur_date FROM val_date WHERE cur_date < CURRENT END-EXEC.

To:

SELECT cur_date FROM val_date WHERE cur_date < GetDate();

Automatically converts SQL statements in Embedded SQL (EXEC SQL/END-EXEC.) to conform to MSSQLServer T/SQL

Can you help me with a flow chart/ algorithm to approach this task.

kovthe
  • 41
  • 6
  • Unable to understand your question. Please edit it properly – Shivkumar kondi Jan 16 '17 at 06:46
  • 1
    This is a lot harder to do than you appear to think. It is specific case of the general problem of translating one computer langauge to another. See http://stackoverflow.com/questions/3455456/what-kinds-of-patterns-could-i-enforce-on-the-code-to-make-it-easier-to-translat/3460977#3460977 – Ira Baxter Jan 16 '17 at 07:09
  • @IraBaxter I understand this it is tough. I want to start with simple source codes and if things go well plan to add more features. At this point I am just trying to get a understanding of the steps involved or a template to start with. – kovthe Jan 16 '17 at 07:17
  • Things won't go well without serious foundations; read the article at the link. You can't do this a bit here and bit there and produce anything that will work, at best, for the example you have. – Ira Baxter Jan 16 '17 at 09:04
  • 2
    Steps: TAKE A COMPILER CLASS, then build parser for source language, parse source code, build AST, find declared names and determine their type, do flow analysis on code. Then write translation rules that handle the 500 pages of details that you find in the COBOL manual. Run on large code base and test; revise translation rules until it works well enough. With very strong supporting machinery (see my bio; Python isn't this by itself), this takes a team of several skilled engineers about a year to do this. Everybody imagines it is easier. It is not. Sorry. – Ira Baxter Jan 16 '17 at 09:09
  • @IraBaxter Point taken. Thank you for your inputs. – kovthe Jan 16 '17 at 10:40
  • 1
    To go even further than @IraBaxter : if you have to ask how to do a compiler(which is what the problem really is), it means you are not good enough yet to begin the task. – gazzz0x2z Jan 16 '17 at 13:51
  • @gazzz0x2z, Well you are right in guessing that I am not good at writing compilers, but its never too late to learn and start :). Had I known what to do, probably I would not have been asking in forum at first place. When someone asks questions, it clearly implies that he/she is seeking an answer which they don't know. Having understood a forum member's weakness it would be real good if we can help fellow mate to overcome lack of knowledge in whatever ways possible. With due respect, just to comment and say you don't know actually does not help. No bad feelings, but hope you understand. – kovthe Jan 17 '17 at 06:33
  • This isn't a forum, it's a place for helping people with clearly defined individual issues that they've taken some distance themselves. – Alan B Oct 01 '18 at 07:43

0 Answers0